Skip to content

Commit 766372b

Browse files
authored
Merge branch 'master' into clear-item
2 parents dc8f816 + cecfd83 commit 766372b

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@ All other information should be explored by reading the source code!
6363
- [2023/3/21 22:00] feat: support getting hero's candidate id.([#21](https://github.com/Escapingbug/dotaxctf/pull/21))
6464
- [2023/3/23 13:30] fix: remove non-hero units after round ends.([#23](https://github.com/Escapingbug/dotaxctf/pull/23), reporter: AAA剑圣)
6565
- [2023/3/24 00:22] feat: support `GetItemInSlot(slot)` to return a sandboxed item.([#24](https://github.com/Escapingbug/dotaxctf/pull/24), reporter: AAA剑圣)
66+
- [2023/3/27 00:22] feat: support getting game time by `GetGameTime()`.([#28](https://github.com/Escapingbug/dotaxctf/pull/28), reporter: Syclover)
67+
- [2023/3/27 23:53] fix: use `npc:GetEntityIndex()` and `npc:GetTeam()` to avoid unexpect behaviors.([#27](https://github.com/Escapingbug/dotaxctf/pull/27), reporter: 114@x1ct34m)
68+
- [2023/3/28 09:11] fix: ban nonhero units for hero choosing.([#31](https://github.com/Escapingbug/dotaxctf/pull/31))
6669
- [2023/3/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30))

rounds.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ function Rounds:Init()
123123
scores = {},
124124
choices = {},
125125
}
126+
127+
self.default_hero = "npc_dota_hero_bloodseeker"
128+
self.default_action = "return {}"
126129
end
127130

128131
function Rounds:InitGameMode()
@@ -299,7 +302,7 @@ function Rounds:NextRound(scripts)
299302
end
300303

301304
Rounds:CleanupLivingHerosAndClearUnits()
302-
Rounds:ChooseHeros(scripts["chooser_scripts"], scripts["attributes"])
305+
Rounds:ChooseHeros(scripts["chooser_scripts"], scripts["attributes"], scripts["bot_scripts"])
303306
Timers:CreateTimer(
304307
Config.round_begin_delay,
305308
function ()
@@ -319,7 +322,7 @@ function Rounds:InitCandidateHero(hero, attr)
319322
hero:ModifyAgility(attr.agility or 0)
320323
end
321324

322-
function Rounds:ChooseHeros(chooser_scripts, attributes)
325+
function Rounds:ChooseHeros(chooser_scripts, attributes, bot_scripts)
323326
-- TODO: add hero chooser fetch flag so that game only starts
324327
-- when hero is added
325328
print("[xctf Rounds:ChooseHeros()]" .. "choosing heros")
@@ -360,7 +363,15 @@ function Rounds:ChooseHeros(chooser_scripts, attributes)
360363
local hero_name = Sandbox:RunChooseHero(chooser)
361364
local player_id = self.candidate_to_player[candidate_id]
362365
local player_owner = PlayerResource:GetPlayer(player_id)
366+
367+
-- ban non-hero unit
368+
if string.sub(hero_name, 1, 14) ~= "npc_dota_hero_" then
369+
print("[xctf Rounds:ChooseHeros()]" .. "found non-hero unit, using default hero instead")
370+
hero_name = self.default_hero
371+
bot_scripts[candidate_id] = self.default_action
372+
end
363373
print("[xctf Rounds:ChooseHeros()]" .. "player owner: " .. tostring(player_owner) .. "team id " .. tostring(cur_team_id))
374+
364375
local candidate_hero = CreateUnitByName(
365376
hero_name,
366377
hero_locations[cur_id],
@@ -412,7 +423,7 @@ function Rounds:PrepareBeginRound()
412423
local round_index = self.round_count / Config.total_rounds_count
413424
round_index = math.min(round_index, 1) -- make sure it is not greater than 1
414425
for _, team in pairs(data.teams) do
415-
self.scores_this_round[team.team_id] = team.score
426+
self.scores_this_round[team.team_id] = 0
416427
chooser_scripts[team.team_id] = from_base64(team.select)
417428
bot_scripts[team.team_id] = from_base64(team.act)
418429
local rank_index = (Config.candidate_count - team.rank) / (Config.candidate_count - 1)

sandbox.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ function Sandbox:RunAction(act_func, entity, ctx)
7575
return new_ctx
7676
end
7777

78+
function GetGameTime()
79+
return GameRules:GetGameTime()
80+
end
81+
7882
function Sandbox:SandboxPublicAPI()
7983
local api = {
8084
Vector = Vector,
8185
QAngle = QAngle,
86+
GetGameTime = GetGameTime,
8287
print = print, -- TODO: remove this
8388
}
8489
return api
@@ -163,7 +168,7 @@ function Sandbox:SandboxBaseNPC(npc, readonly)
163168
find_order
164169
)
165170
local units = FindUnitsInRadius(
166-
self:GetTeam(),
171+
npc:GetTeam(),
167172
location,
168173
nil, -- cacheUnit
169174
radius,
@@ -206,7 +211,7 @@ function Sandbox:SandboxBaseNPC(npc, readonly)
206211
return
207212
end
208213
ExecuteOrderFromTable{
209-
UnitIndex = self:GetEntityIndex(),
214+
UnitIndex = npc:GetEntityIndex(),
210215
OrderType = order_type,
211216
TargetIndex = target_index,
212217
AbilityIndex = ability_index,
@@ -263,15 +268,15 @@ function Sandbox:SandboxAbility(ability)
263268
GetAOERadius = copy_method(ability, "GetAOERadius"),
264269
GetBehavior = copy_method(ability, "GetBehavior"),
265270
GetChannelledManaCostPerSecond
266-
= copy_method(ability, "GetChannelledManaCostPerSecond"),
271+
= copy_method(ability, "GetChannelledManaCostPerSecond"),
267272
GetChannelTime = copy_method(ability, "GetChannelTime"),
268273
GetCooldownTimeRemaining = copy_method(ability, "GetCooldownTimeRemaining"),
269274
GetCurrentAbilityCharges = copy_method(ability, "GetCurrentAbilityCharges"),
270275
GetEffectiveCastRange = copy_method(ability, "GetEffectiveCastRange"), -- TODO: fix args
271276
GetEffectiveCooldown = copy_method(ability, "GetEffectiveCooldown"),
272277
GetLevel = copy_method(ability, "GetLevel"),
273278
GetLevelSpecialValueNoOverride
274-
= copy_method(ability, "GetLevelSpecialValueNoOverride"),
279+
= copy_method(ability, "GetLevelSpecialValueNoOverride"),
275280
GetManaCost = copy_method(ability, "GetManaCost"),
276281
GetSpecialValueFor = copy_method(ability, "GetSpecialValueFor"),
277282
GetToggleState = copy_method(ability, "GetToggleState"),

0 commit comments

Comments
 (0)