Skip to content

Commit 0931fba

Browse files
authored
Change the way we handle bad heroes, respawning, and zone control padding/margin (#432)
1 parent d064f0f commit 0931fba

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

game/scripts/vscripts/components/duels/duels.lua

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,24 @@ function Duels:ActuallyStartDuel ()
111111
local player = PlayerResource:GetPlayer(playerId)
112112
if player ~= nil then
113113
DebugPrint ('Players team ' .. player:GetTeam())
114-
if player:GetTeam() == 3 then
115-
badPlayers[badPlayerIndex] = Duels:SavePlayerState(player:GetAssignedHero())
116-
badPlayers[badPlayerIndex].id = playerId
117-
-- used to generate keynames like badEnd1
118-
-- not used in dota apis
119-
badPlayers[badPlayerIndex].team = 'bad'
120-
badPlayerIndex = badPlayerIndex + 1
121-
122-
elseif player:GetTeam() == 2 then
123-
goodPlayers[goodPlayerIndex] = Duels:SavePlayerState(player:GetAssignedHero())
124-
goodPlayers[goodPlayerIndex].id = playerId
125-
goodPlayers[goodPlayerIndex].team = 'good'
126-
goodPlayerIndex = goodPlayerIndex + 1
114+
if player:GetAssignedHero() then
115+
if player:GetTeam() == 3 then
116+
badPlayers[badPlayerIndex] = Duels:SavePlayerState(player:GetAssignedHero())
117+
badPlayers[badPlayerIndex].id = playerId
118+
-- used to generate keynames like badEnd1
119+
-- not used in dota apis
120+
badPlayers[badPlayerIndex].team = 'bad'
121+
badPlayerIndex = badPlayerIndex + 1
122+
123+
elseif player:GetTeam() == 2 then
124+
goodPlayers[goodPlayerIndex] = Duels:SavePlayerState(player:GetAssignedHero())
125+
goodPlayers[goodPlayerIndex].id = playerId
126+
goodPlayers[goodPlayerIndex].team = 'good'
127+
goodPlayerIndex = goodPlayerIndex + 1
128+
end
129+
130+
Duels:ResetPlayerState(player:GetAssignedHero())
127131
end
128-
129-
Duels:ResetPlayerState(player:GetAssignedHero())
130132
end
131133
end
132134

@@ -270,8 +272,14 @@ function Duels:EndDuel ()
270272
Duels.zone1.removePlayer(playerId)
271273
Duels.zone2.removePlayer(playerId)
272274
local player = PlayerResource:GetPlayer(playerId)
273-
if player ~= nil then
274-
player:GetAssignedHero():SetRespawnsDisabled(false)
275+
if player ~= nil and player:GetAssignedHero() then
276+
local hero = player:GetAssignedHero()
277+
if hero then
278+
hero:SetRespawnsDisabled(false)
279+
if not hero:IsAlive() then
280+
hero:RespawnHero(false,false,false)
281+
end
282+
end
275283
end
276284
end
277285

@@ -304,7 +312,7 @@ function Duels:ResetPlayerState (hero)
304312
hero:SetMana(hero:GetMaxMana())
305313

306314
-- Reset cooldown for abilities
307-
for abilityIndex = 0,hero:GetAbilityCount() do
315+
for abilityIndex = 0,hero:GetAbilityCount() - 1 do
308316
local ability = hero:GetAbilityByIndex(abilityIndex)
309317
if ability ~= nil then
310318
ability:EndCooldown()

game/scripts/vscripts/components/zonecontrol/zones.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function ZoneControl:CreateEmptyState (options)
5959
return {
6060
isZoneControlState = true,
6161
mode = options.mode,
62-
players = options.players
62+
players = options.players,
63+
padding = options.padding or 100,
64+
margin = options.margin or 100
6365
}
6466
end
6567

@@ -272,19 +274,19 @@ function ZoneControl:EnforceRulesOnEntity (state, playerId, entity)
272274
-- we're snapping to an X wall
273275
if xDistance > 0 then
274276
-- we're snapping to the right wall
275-
origin = Vector(state.bounds.Maxs.x + bounds.Maxs.x + 20 + state.origin.x, origin.y, origin.z)
277+
origin = Vector(state.bounds.Maxs.x + bounds.Maxs.x + state.margin + state.origin.x, origin.y, origin.z)
276278
else
277279
-- we're snapping to the left wall
278-
origin = Vector(state.bounds.Mins.x + bounds.Mins.x - 20 + state.origin.x, origin.y, origin.z)
280+
origin = Vector(state.bounds.Mins.x + bounds.Mins.x - state.margin + state.origin.x, origin.y, origin.z)
279281
end
280282
else
281283
-- we're snapping to a Y wall
282284
if yDistance > 0 then
283285
-- we're snapping to the top wall
284-
origin = Vector(origin.x, state.bounds.Maxs.y + bounds.Maxs.y + 20 + state.origin.y, origin.z)
286+
origin = Vector(origin.x, state.bounds.Maxs.y + bounds.Maxs.y + state.margin + state.origin.y, origin.z)
285287
else
286288
-- we're snapping to the bottom wall
287-
origin = Vector(origin.x, state.bounds.Mins.y + bounds.Mins.y - 20 + state.origin.y, origin.z)
289+
origin = Vector(origin.x, state.bounds.Mins.y + bounds.Mins.y - state.margin + state.origin.y, origin.z)
288290
end
289291
end
290292
end
@@ -293,10 +295,10 @@ function ZoneControl:EnforceRulesOnEntity (state, playerId, entity)
293295
DebugPrint('Player is not touching, but should be!')
294296
local x = origin.x
295297
local y = origin.y
296-
local topWall = state.origin.y + state.bounds.Maxs.y
297-
local rightWall = state.origin.x + state.bounds.Maxs.x
298-
local bottomWall = state.origin.y + state.bounds.Mins.y
299-
local leftWall = state.origin.x + state.bounds.Mins.x
298+
local topWall = state.origin.y + state.bounds.Maxs.y - state.padding
299+
local rightWall = state.origin.x + state.bounds.Maxs.x + state.padding
300+
local bottomWall = state.origin.y + state.bounds.Mins.y + state.padding
301+
local leftWall = state.origin.x + state.bounds.Mins.x - state.padding
300302

301303
if x > rightWall then
302304
x = rightWall

0 commit comments

Comments
 (0)