Skip to content

fix: clean up items when round ends #30

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 3 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 @@ -66,3 +66,4 @@ All other information should be explored by reading the source code!
- [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))
- [2023/3/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30))
2 changes: 2 additions & 0 deletions commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ end
function Commands:FullRestart()
Timers:RemoveTimer("round_periodic_timer")
Timers:RemoveTimer("round_limit_timer")
Sandbox:CleanUpItems()
Rounds.restarting = true
Rounds:InitFromServerAndBeginGame()
end

function Commands:RoundRestart()
Timers:RemoveTimer("round_periodic_timer")
Timers:RemoveTimer("round_limit_timer")
Sandbox:CleanUpItems()
Rounds:PrepareBeginRound()
end

Expand Down
2 changes: 2 additions & 0 deletions rounds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ function Rounds:BeginRound(bot_scripts)
Timers:RemoveTimer("round_periodic_timer")
Rounds:RoundEndedScoring()
Rounds:FlushScoresAndRunNextRound()
Sandbox:CleanUpItems()
end
}
)
Expand All @@ -551,6 +552,7 @@ function Rounds:BeginRound(bot_scripts)
Timers:RemoveTimer("round_limit_timer")
Rounds:RoundEndedScoring()
Rounds:FlushScoresAndRunNextRound()
Sandbox:CleanUpItems()
return
else
return 1
Expand Down
14 changes: 14 additions & 0 deletions sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function Sandbox:Init()
self.public_api = self:SandboxPublicAPI()
self.default_hero = "npc_dota_hero_axe"
self.init = true
self.items = {}
end

function Sandbox:SetupGameInfo(game_info)
Expand Down Expand Up @@ -240,6 +241,7 @@ function Sandbox:SandboxBaseNPC(npc, readonly)
-- we only use unreliable gold
npc:SetGold(gold_left, false)
npc:AddItem(item)
table.insert(Sandbox.items, item)
return true
end

Expand Down Expand Up @@ -330,6 +332,18 @@ function Sandbox:SandboxItem(item)
return sandboxed
end

function Sandbox:CleanUpItems()
for _, item in ipairs(self.items) do
item:RemoveSelf()
end
self.items = {}

local total = GameRules:NumDroppedItems()
for _ = 1, total do
GameRules:GetDroppedItem(0):RemoveSelf()
end
end

if not Sandbox.init then Sandbox:Init() end

GameRules.Sandbox = Sandbox