Skip to content

fix: ban nonhero units for hero choosing #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ All other information should be explored by reading the source code!
- [2023/3/24 00:22] feat: support `GetItemInSlot(slot)` to return a sandboxed item.([#24](https://github.com/Escapingbug/dotaxctf/pull/24), reporter: AAA剑圣)
- [2023/3/27 00:22] feat: support getting game time by `GetGameTime()`.([#28](https://github.com/Escapingbug/dotaxctf/pull/28), reporter: Syclover)
- [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)
- [2023/3/28 09:11] fix: ban nonhero units for hero choosing.([#31](https://github.com/Escapingbug/dotaxctf/pull/31))
15 changes: 13 additions & 2 deletions rounds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ function Rounds:Init()
scores = {},
choices = {},
}

self.default_hero = "npc_dota_hero_bloodseeker"
self.default_action = "return {}"
end

function Rounds:InitGameMode()
Expand Down Expand Up @@ -299,7 +302,7 @@ function Rounds:NextRound(scripts)
end

Rounds:CleanupLivingHerosAndClearUnits()
Rounds:ChooseHeros(scripts["chooser_scripts"], scripts["attributes"])
Rounds:ChooseHeros(scripts["chooser_scripts"], scripts["attributes"], scripts["bot_scripts"])
Timers:CreateTimer(
Config.round_begin_delay,
function ()
Expand All @@ -319,7 +322,7 @@ function Rounds:InitCandidateHero(hero, attr)
hero:ModifyAgility(attr.agility or 0)
end

function Rounds:ChooseHeros(chooser_scripts, attributes)
function Rounds:ChooseHeros(chooser_scripts, attributes, bot_scripts)
-- TODO: add hero chooser fetch flag so that game only starts
-- when hero is added
print("[xctf Rounds:ChooseHeros()]" .. "choosing heros")
Expand Down Expand Up @@ -360,7 +363,15 @@ function Rounds:ChooseHeros(chooser_scripts, attributes)
local hero_name = Sandbox:RunChooseHero(chooser)
local player_id = self.candidate_to_player[candidate_id]
local player_owner = PlayerResource:GetPlayer(player_id)

-- ban non-hero unit
if string.sub(hero_name, 1, 14) ~= "npc_dota_hero_" then
print("[xctf Rounds:ChooseHeros()]" .. "found non-hero unit, using default hero instead")
hero_name = self.default_hero
bot_scripts[candidate_id] = self.default_action
end
print("[xctf Rounds:ChooseHeros()]" .. "player owner: " .. tostring(player_owner) .. "team id " .. tostring(cur_team_id))

local candidate_hero = CreateUnitByName(
hero_name,
hero_locations[cur_id],
Expand Down