@@ -7,10 +7,11 @@ DUEL_IS_STARTING = 21
7
7
8
8
Duels = Duels or {}
9
9
local zoneNames = {
10
- " duel_1" ,
11
- " duel_2" ,
10
+ " duel_1" , -- small arena
11
+ " duel_2" , -- small arena
12
12
" duel_3" ,
13
13
" duel_4" ,
14
+ " duel_5" ,
14
15
}
15
16
16
17
local DuelPreparingEvent = Event ()
@@ -23,7 +24,6 @@ Duels.onEnd = DuelEndEvent.listen
23
24
24
25
function Duels :Init ()
25
26
DebugPrint (' Init duels' )
26
-
27
27
self .currentDuel = nil
28
28
iter (zoneNames ):foreach (partial (self .RegisterZone , self ))
29
29
@@ -247,7 +247,7 @@ function Duels:StartDuel(options)
247
247
end )
248
248
end
249
249
250
- function Duels :ActuallyStartDuel (options )
250
+ function Duels :SplitDuelPlayers (options )
251
251
-- respawn everyone
252
252
local goodPlayerIndex = 1
253
253
local badPlayerIndex = 1
@@ -318,125 +318,95 @@ function Duels:ActuallyStartDuel(options)
318
318
Notifications :TopToAll ({text = " #duel_not_enough_players" , duration = 2.0 })
319
319
self .currentDuel = nil
320
320
Music :PlayBackground (1 , 7 )
321
- return
321
+ return nil
322
322
end
323
-
324
323
Music :SetMusic (13 )
325
324
326
325
local playerSplitOffset = RandomInt (0 , maxPlayers )
327
326
if options .players then
328
327
playerSplitOffset = math.min (options .players , maxPlayers )
329
328
end
330
- -- local playerSplitOffset = maxPlayers
331
- local spawnLocations = RandomInt (0 , 1 ) == 1
332
- local arenaChoice = RandomInt (0 , 1 ) == 1
333
- local duel_1 = ' duel_1'
334
- local duel_2 = ' duel_2'
335
- if arenaChoice then
336
- duel_1 = ' duel_3'
337
- end
338
- local spawn1 = Entities :FindByName (nil , duel_1 .. ' _spawn_1' ):GetAbsOrigin ()
339
- local spawn2 = Entities :FindByName (nil , duel_1 .. ' _spawn_2' ):GetAbsOrigin ()
340
329
341
- if spawnLocations then
342
- local tmp = spawn1
343
- spawn1 = spawn2
344
- spawn2 = tmp
330
+ if playerSplitOffset > maxPlayers / 2.0 then
331
+ playerSplitOffset = maxPlayers - playerSplitOffset
345
332
end
346
333
347
- for playerNumber = 1 ,playerSplitOffset do
348
- DebugPrint (' Adding player number ' .. playerNumber )
349
- local goodGuy = self :GetUnassignedPlayer (goodPlayers , goodPlayerIndex )
350
- local badGuy = self :GetUnassignedPlayer (badPlayers , badPlayerIndex )
351
- local goodPlayer = PlayerResource :GetPlayer (goodGuy .id )
352
- local badPlayer = PlayerResource :GetPlayer (badGuy .id )
353
- local goodHero = goodPlayer :GetAssignedHero ()
354
- local badHero = badPlayer :GetAssignedHero ()
334
+ if options .isFinalDuel then
335
+ playerSplitOffset = 0
336
+ end
355
337
356
- goodGuy .duelNumber = 1
357
- badGuy .duelNumber = 1
338
+ return
339
+ {
340
+ MaxPlayers = maxPlayers ,
341
+ PlayerSplitOffset = playerSplitOffset ,
342
+ GoodPlayers = goodPlayers ,
343
+ BadPlayers = badPlayers ,
344
+ GoodPlayerIndex = goodPlayerIndex ,
345
+ BadPlayerIndex = badPlayerIndex ,
346
+ }
347
+ end
358
348
359
- SafeTeleportAll (goodHero , spawn1 , 150 )
360
- SafeTeleportAll (badHero , spawn2 , 150 )
349
+ function Duels :ActuallyStartDuel (options )
350
+ local split = self :SplitDuelPlayers (options )
351
+ if split == nil then
352
+ return
353
+ end
361
354
362
- if arenaChoice then
363
- self .zones [3 ].addPlayer (goodGuy .id )
364
- self .zones [3 ].addPlayer (badGuy .id )
365
- else
366
- self .zones [1 ].addPlayer (goodGuy .id )
367
- self .zones [1 ].addPlayer (badGuy .id )
368
- end
355
+ DebugPrint (" Duel Player Split" )
356
+ DebugPrint (split .PlayerSplitOffset )
369
357
370
- MoveCameraToPlayer ( goodHero )
371
- MoveCameraToPlayer ( badHero )
358
+ local bigArenaIndex = RandomInt ( 3 , 5 )
359
+ local smallArenaIndex = RandomInt ( 1 , 2 )
372
360
373
- -- stop player action
374
- goodHero :Stop ()
375
- badHero :Stop ()
361
+ self :SpawnPlayersOnArenas (split , smallArenaIndex , bigArenaIndex )
362
+ self :PreparePlayersToStartDuel (options , split )
376
363
377
- -- disable respawn
378
- goodHero :SetRespawnsDisabled (true )
379
- badHero :SetRespawnsDisabled (true )
380
- end
364
+ end
381
365
382
- spawnLocations = RandomInt (0 , 1 ) == 1
383
- arenaChoice = RandomInt (0 , 1 ) == 1
384
- if arenaChoice then
385
- duel_2 = ' duel_4'
386
- end
366
+ function Duels :SpawnPlayerOnArena (playerSplit , arenaIndex , duelNumber )
387
367
388
- spawn1 = Entities :FindByName (nil , duel_2 .. ' _spawn_1' ):GetAbsOrigin ()
389
- spawn2 = Entities :FindByName (nil , duel_2 .. ' _spawn_2' ):GetAbsOrigin ()
368
+ local spawn1 = Entities :FindByName (nil , ' duel_ ' .. tostring ( arenaIndex ) .. ' _spawn_1' ):GetAbsOrigin ()
369
+ local spawn2 = Entities :FindByName (nil , ' duel_ ' .. tostring ( arenaIndex ) .. ' _spawn_2' ):GetAbsOrigin ()
390
370
391
- if spawnLocations then
392
- local tmp = spawn1
393
- spawn1 = spawn2
394
- spawn2 = tmp
395
- end
371
+ local goodGuy = self :GetUnassignedPlayer (playerSplit .GoodPlayers , playerSplit .GoodPlayerIndex )
372
+ local badGuy = self :GetUnassignedPlayer (playerSplit .BadPlayers , playerSplit .BadPlayerIndex )
373
+ local goodPlayer = PlayerResource :GetPlayer (goodGuy .id )
374
+ local badPlayer = PlayerResource :GetPlayer (badGuy .id )
375
+ local goodHero = goodPlayer :GetAssignedHero ()
376
+ local badHero = badPlayer :GetAssignedHero ()
396
377
397
- for playerNumber = playerSplitOffset + 1 ,maxPlayers do
398
- DebugPrint (' Adding player number ' .. playerNumber )
399
- local goodGuy = self :GetUnassignedPlayer (goodPlayers , goodPlayerIndex )
400
- local badGuy = self :GetUnassignedPlayer (badPlayers , badPlayerIndex )
401
- local goodPlayer = PlayerResource :GetPlayer (goodGuy .id )
402
- local badPlayer = PlayerResource :GetPlayer (badGuy .id )
403
- local goodHero = goodPlayer :GetAssignedHero ()
404
- local badHero = badPlayer :GetAssignedHero ()
405
378
406
- goodGuy .duelNumber = 2
407
- badGuy .duelNumber = 2
379
+ DebugPrint (' Spawning Hero ' .. goodHero :GetUnitName () .. ' and ' .. badHero :GetUnitName () .. ' on Arena ' .. tostring (arenaIndex ) .. ' duelNumber ' .. tostring (duelNumber ) )
380
+ goodGuy .duelNumber = duelNumber
381
+ badGuy .duelNumber = duelNumber
408
382
409
- SafeTeleportAll (goodHero , spawn1 , 150 )
410
- SafeTeleportAll (badHero , spawn2 , 150 )
383
+ SafeTeleportAll (goodHero , spawn1 , 150 )
384
+ SafeTeleportAll (badHero , spawn2 , 150 )
411
385
412
- if arenaChoice then
413
- self .zones [4 ].addPlayer (goodGuy .id )
414
- self .zones [4 ].addPlayer (badGuy .id )
415
- else
416
- self .zones [2 ].addPlayer (goodGuy .id )
417
- self .zones [2 ].addPlayer (badGuy .id )
418
- end
386
+ self .zones [arenaIndex ].addPlayer (goodGuy .id )
387
+ self .zones [arenaIndex ].addPlayer (badGuy .id )
419
388
420
- MoveCameraToPlayer (goodHero )
421
- MoveCameraToPlayer (badHero )
389
+ MoveCameraToPlayer (goodHero )
390
+ MoveCameraToPlayer (badHero )
422
391
423
- -- stop player action
424
- goodHero :Stop ()
425
- badHero :Stop ()
392
+ -- stop player action
393
+ goodHero :Stop ()
394
+ badHero :Stop ()
426
395
427
- -- disable respawn
428
- goodHero :SetRespawnsDisabled (true )
429
- badHero :SetRespawnsDisabled (true )
430
- end
396
+ -- disable respawn
397
+ goodHero :SetRespawnsDisabled (true )
398
+ badHero :SetRespawnsDisabled (true )
399
+ end
431
400
432
- for _ ,player in ipairs (badPlayers ) do
401
+ function Duels :PreparePlayersToStartDuel (options , playerSplit )
402
+ for _ ,player in ipairs (playerSplit .BadPlayers ) do
433
403
if player .assigned == nil then
434
404
local hero = PlayerResource :GetSelectedHeroEntity (player .id )
435
405
hero :Stop ()
436
406
hero :AddNewModifier (nil , nil , " modifier_out_of_duel" , nil )
437
407
end
438
408
end
439
- for _ ,player in ipairs (goodPlayers ) do
409
+ for _ ,player in ipairs (playerSplit . GoodPlayers ) do
440
410
if player .assigned == nil then
441
411
local hero = PlayerResource :GetSelectedHeroEntity (player .id )
442
412
hero :Stop ()
@@ -445,17 +415,21 @@ function Duels:ActuallyStartDuel(options)
445
415
end
446
416
447
417
self .currentDuel = {
448
- goodLiving1 = playerSplitOffset ,
449
- badLiving1 = playerSplitOffset ,
450
- goodLiving2 = maxPlayers - playerSplitOffset ,
451
- badLiving2 = maxPlayers - playerSplitOffset ,
452
- duelEnd1 = playerSplitOffset == 0 ,
453
- duelEnd2 = maxPlayers == playerSplitOffset ,
454
- badPlayers = badPlayers ,
455
- goodPlayers = goodPlayers ,
456
- badPlayerIndex = badPlayerIndex ,
457
- goodPlayerIndex = goodPlayerIndex
418
+ goodLiving1 = playerSplit . PlayerSplitOffset ,
419
+ badLiving1 = playerSplit . PlayerSplitOffset ,
420
+ goodLiving2 = playerSplit . MaxPlayers - playerSplit . PlayerSplitOffset ,
421
+ badLiving2 = playerSplit . MaxPlayers - playerSplit . PlayerSplitOffset ,
422
+ duelEnd1 = playerSplit . PlayerSplitOffset == 0 ,
423
+ duelEnd2 = playerSplit . MaxPlayers == playerSplit . PlayerSplitOffset ,
424
+ badPlayers = playerSplit . BadPlayers ,
425
+ goodPlayers = playerSplit . GoodPlayers ,
426
+ badPlayerIndex = playerSplit . BadPlayerIndex ,
427
+ goodPlayerIndex = playerSplit . GoodPlayerIndex
458
428
}
429
+
430
+ DebugPrint (" Duel Info" )
431
+ DebugPrintTable (self .currentDuel )
432
+
459
433
DuelStartEvent .broadcast (self .currentDuel )
460
434
461
435
if options .timeout == nil then
@@ -472,6 +446,20 @@ function Duels:ActuallyStartDuel(options)
472
446
end
473
447
end
474
448
449
+ function Duels :SpawnPlayersOnArenas (playerSplit , arenaIndex1 , arenaIndex2 )
450
+
451
+ -- Smaller Arena
452
+ for playerNumber = 1 , playerSplit .PlayerSplitOffset do
453
+ self :SpawnPlayerOnArena (playerSplit , arenaIndex1 , 1 )
454
+ end
455
+
456
+ -- Bigger Arena
457
+ for playerNumber = playerSplit .PlayerSplitOffset + 1 , playerSplit .MaxPlayers do
458
+ self :SpawnPlayerOnArena (playerSplit , arenaIndex2 , 2 )
459
+ end
460
+
461
+ end
462
+
475
463
function Duels :GetUnassignedPlayer (group , max )
476
464
while true do
477
465
local playerIndex = RandomInt (1 , max )
0 commit comments