@@ -43,6 +43,19 @@ function Duels:Init ()
43
43
Duels :CheckDuelStatus (keys )
44
44
end )
45
45
46
+ GameEvents :OnPlayerReconnect (function (keys )
47
+ local playerID = keys .playerID
48
+ if playerID then
49
+ local hero = PlayerResource :GetSelectedHeroEntity (playerID )
50
+ if not Duels .currentDuel then
51
+ hero :SetRespawnsDisabled (false )
52
+ if not hero :IsAlive () then
53
+ hero :RespawnHero (false , false , false )
54
+ end
55
+ end
56
+ end
57
+ end )
58
+
46
59
Timers :CreateTimer (1 , function ()
47
60
Duels :StartDuel ()
48
61
end )
@@ -180,8 +193,11 @@ function Duels:ActuallyStartDuel ()
180
193
goodGuy .duelNumber = 1
181
194
badGuy .duelNumber = 1
182
195
183
- FindClearSpaceForUnit (goodHero , spawn1 , true )
184
- FindClearSpaceForUnit (badHero , spawn2 , true )
196
+ self :SafeTeleport (goodHero , spawn1 , 150 )
197
+ self :SafeTeleport (badHero , spawn2 , 150 )
198
+ -- FindClearSpaceForUnit(goodHero, spawn1, true)
199
+ -- FindClearSpaceForUnit(badHero, spawn2, true)
200
+
185
201
186
202
Duels .zone1 .addPlayer (goodGuy .id )
187
203
Duels .zone1 .addPlayer (badGuy .id )
@@ -326,15 +342,15 @@ function Duels:ResetPlayerState (hero)
326
342
hero :SetMana (hero :GetMaxMana ())
327
343
328
344
-- Reset cooldown for abilities
329
- for abilityIndex = 0 ,hero :GetAbilityCount () - 1 do
345
+ for abilityIndex = 0 , hero :GetAbilityCount () - 1 do
330
346
local ability = hero :GetAbilityByIndex (abilityIndex )
331
347
if ability ~= nil then
332
348
ability :EndCooldown ()
333
349
end
334
350
end
335
351
336
352
-- Reset cooldown for items
337
- for i = 0 , 5 do
353
+ for i = DOTA_ITEM_SLOT_1 , DOTA_ITEM_SLOT_6 do
338
354
local item = hero :GetItemInSlot (i )
339
355
if item then
340
356
item :EndCooldown ()
@@ -348,6 +364,7 @@ function Duels:SavePlayerState (hero)
348
364
abilityCount = hero :GetAbilityCount (),
349
365
abilities = {},
350
366
items = {},
367
+ modifiers = {},
351
368
hp = hero :GetHealth (),
352
369
mana = hero :GetMana ()
353
370
}
@@ -370,15 +387,14 @@ function Duels:SavePlayerState (hero)
370
387
end
371
388
end
372
389
373
- for itemIndex = 0 , 5 do
390
+ for itemIndex = DOTA_ITEM_SLOT_1 , DOTA_ITEM_SLOT_6 do
374
391
local item = hero :GetItemInSlot (itemIndex )
375
392
if item ~= nil then
376
393
state .items [itemIndex ] = {
377
394
cooldown = item :GetCooldownTimeRemaining ()
378
395
}
379
396
end
380
397
end
381
-
382
398
return state
383
399
end
384
400
@@ -389,7 +405,7 @@ function Duels:RestorePlayerState (hero, state)
389
405
end
390
406
hero :SetMana (state .mana )
391
407
392
- for abilityIndex = 0 ,hero :GetAbilityCount ()- 1 do
408
+ for abilityIndex = 0 , hero :GetAbilityCount () - 1 do
393
409
local ability = hero :GetAbilityByIndex (abilityIndex )
394
410
if ability ~= nil then
395
411
if state .abilities [abilityIndex ] == nil then
@@ -401,7 +417,7 @@ function Duels:RestorePlayerState (hero, state)
401
417
end
402
418
end
403
419
404
- for itemIndex = 0 , 5 do
420
+ for itemIndex = DOTA_ITEM_SLOT_1 , DOTA_ITEM_SLOT_6 do
405
421
local item = hero :GetItemInSlot (itemIndex )
406
422
if item ~= nil and state .items [itemIndex ] then
407
423
item :StartCooldown (state .items [itemIndex ].cooldown )
@@ -430,3 +446,13 @@ function Duels:AllPlayers (state, cb)
430
446
end
431
447
end
432
448
end
449
+
450
+ function Duels :SafeTeleport (unit , location , maxDistance )
451
+ FindClearSpaceForUnit (unit , location , true )
452
+ local distance = (location - unit :GetAbsOrigin ()):Length2D ()
453
+ if distance > maxDistance then
454
+ Timers :CreateTimer (0.1 , function ()
455
+ self :SafeTeleport (unit , location , maxDistance )
456
+ end )
457
+ end
458
+ end
0 commit comments