From 3bbfd4c52d3dbdbd8efb9dcf222491ec4133f32f Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Mon, 27 Mar 2023 23:45:58 +0800 Subject: [PATCH 1/2] fix: clean up items when round ends --- commands.lua | 2 ++ rounds.lua | 2 ++ sandbox.lua | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/commands.lua b/commands.lua index 99d3a50..a1f9f45 100644 --- a/commands.lua +++ b/commands.lua @@ -29,6 +29,7 @@ end function Commands:FullRestart() Timers:RemoveTimer("round_periodic_timer") Timers:RemoveTimer("round_limit_timer") + Sandbox:CleanUpItems() Rounds.restarting = true Rounds:InitFromServerAndBeginGame() end @@ -36,6 +37,7 @@ end function Commands:RoundRestart() Timers:RemoveTimer("round_periodic_timer") Timers:RemoveTimer("round_limit_timer") + Sandbox:CleanUpItems() Rounds:PrepareBeginRound() end diff --git a/rounds.lua b/rounds.lua index 8eaf37f..005d818 100644 --- a/rounds.lua +++ b/rounds.lua @@ -526,6 +526,7 @@ function Rounds:BeginRound(bot_scripts) Timers:RemoveTimer("round_periodic_timer") Rounds:RoundEndedScoring() Rounds:FlushScoresAndRunNextRound() + Sandbox:CleanUpItems() end } ) @@ -540,6 +541,7 @@ function Rounds:BeginRound(bot_scripts) Timers:RemoveTimer("round_limit_timer") Rounds:RoundEndedScoring() Rounds:FlushScoresAndRunNextRound() + Sandbox:CleanUpItems() return else return 1 diff --git a/sandbox.lua b/sandbox.lua index 24b3295..4b236c1 100644 --- a/sandbox.lua +++ b/sandbox.lua @@ -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) @@ -235,6 +236,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 @@ -325,6 +327,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 From dc8f816e5121e2e53eb66402fdef2f3567441f84 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Tue, 28 Mar 2023 09:17:06 +0800 Subject: [PATCH 2/2] doc: add changelog to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e27a5d6..c2e6ac5 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,4 @@ All other information should be explored by reading the source code! - [2023/3/21 22:00] feat: support getting hero's candidate id.([#21](https://github.com/Escapingbug/dotaxctf/pull/21)) - [2023/3/23 13:30] fix: remove non-hero units after round ends.([#23](https://github.com/Escapingbug/dotaxctf/pull/23), reporter: AAA剑圣) - [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/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30))