Skip to content

Commit aa6ef33

Browse files
authored
Merge pull request #30 from Escapingbug/clear-item
2 parents cecfd83 + 766372b commit aa6ef33

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ All other information should be explored by reading the source code!
6666
- [2023/3/27 00:22] feat: support getting game time by `GetGameTime()`.([#28](https://github.com/Escapingbug/dotaxctf/pull/28), reporter: Syclover)
6767
- [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)
6868
- [2023/3/28 09:11] fix: ban nonhero units for hero choosing.([#31](https://github.com/Escapingbug/dotaxctf/pull/31))
69+
- [2023/3/28 09:16] feat: clean up items when round ends.([#30](https://github.com/Escapingbug/dotaxctf/pull/30))

commands.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ end
2929
function Commands:FullRestart()
3030
Timers:RemoveTimer("round_periodic_timer")
3131
Timers:RemoveTimer("round_limit_timer")
32+
Sandbox:CleanUpItems()
3233
Rounds.restarting = true
3334
Rounds:InitFromServerAndBeginGame()
3435
end
3536

3637
function Commands:RoundRestart()
3738
Timers:RemoveTimer("round_periodic_timer")
3839
Timers:RemoveTimer("round_limit_timer")
40+
Sandbox:CleanUpItems()
3941
Rounds:PrepareBeginRound()
4042
end
4143

rounds.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ function Rounds:BeginRound(bot_scripts)
537537
Timers:RemoveTimer("round_periodic_timer")
538538
Rounds:RoundEndedScoring()
539539
Rounds:FlushScoresAndRunNextRound()
540+
Sandbox:CleanUpItems()
540541
end
541542
}
542543
)
@@ -551,6 +552,7 @@ function Rounds:BeginRound(bot_scripts)
551552
Timers:RemoveTimer("round_limit_timer")
552553
Rounds:RoundEndedScoring()
553554
Rounds:FlushScoresAndRunNextRound()
555+
Sandbox:CleanUpItems()
554556
return
555557
else
556558
return 1

sandbox.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function Sandbox:Init()
1515
self.public_api = self:SandboxPublicAPI()
1616
self.default_hero = "npc_dota_hero_axe"
1717
self.init = true
18+
self.items = {}
1819
end
1920

2021
function Sandbox:SetupGameInfo(game_info)
@@ -240,6 +241,7 @@ function Sandbox:SandboxBaseNPC(npc, readonly)
240241
-- we only use unreliable gold
241242
npc:SetGold(gold_left, false)
242243
npc:AddItem(item)
244+
table.insert(Sandbox.items, item)
243245
return true
244246
end
245247

@@ -330,6 +332,18 @@ function Sandbox:SandboxItem(item)
330332
return sandboxed
331333
end
332334

335+
function Sandbox:CleanUpItems()
336+
for _, item in ipairs(self.items) do
337+
item:RemoveSelf()
338+
end
339+
self.items = {}
340+
341+
local total = GameRules:NumDroppedItems()
342+
for _ = 1, total do
343+
GameRules:GetDroppedItem(0):RemoveSelf()
344+
end
345+
end
346+
333347
if not Sandbox.init then Sandbox:Init() end
334348

335349
GameRules.Sandbox = Sandbox

0 commit comments

Comments
 (0)