diff --git a/README.md b/README.md index 98378fb..d970d64 100644 --- a/README.md +++ b/README.md @@ -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)) 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 ffa0986..9394ae6 100644 --- a/rounds.lua +++ b/rounds.lua @@ -537,6 +537,7 @@ function Rounds:BeginRound(bot_scripts) Timers:RemoveTimer("round_periodic_timer") Rounds:RoundEndedScoring() Rounds:FlushScoresAndRunNextRound() + Sandbox:CleanUpItems() end } ) @@ -551,6 +552,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 74fbafd..e891f85 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) @@ -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 @@ -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