GabzGlobal.gd 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. extends NpcScript
  2. # Mission parameters
  3. var rewardExp : int = 1000
  4. var rewardGP : int = 10000
  5. # Wave parameters
  6. var monstersPool : Array = []
  7. const checkDelay : float = 2.0
  8. const waveDelay : float = 300.0
  9. const maxWave : int = 10
  10. const spawnCenter : Vector2i = Vector2i(54 * 32, 67 * 32)
  11. const spawnRadius : Vector2i = Vector2i(200, 200)
  12. const startFightDelay : float = 10.0
  13. # Local variables
  14. var waveTimer : Timer = null
  15. var waveCount : int = 0
  16. var originalPlayerCount : int = 0
  17. #
  18. func OnStart():
  19. for mobID in DB.EntitiesDB:
  20. var mob : EntityData = DB.EntitiesDB[mobID]
  21. if !!(mob._behaviour & AICommons.Behaviour.AGGRESSIVE) and !(mob._behaviour & AICommons.Behaviour.IMMOBILE):
  22. monstersPool.append(mob)
  23. func OnCancel():
  24. ClearTimer(waveTimer)
  25. Reset()
  26. if IsTriggering():
  27. Trigger()
  28. KillMonsters()
  29. var ownInstance : WorldInstance = WorldAgent.GetInstanceFromAgent(own)
  30. for player in ownInstance.players:
  31. Callback.ClearOneShot(player.tree_exiting)
  32. Callback.ClearOneShot(player.agent_killed)
  33. func OnTrigger():
  34. AddTimer(npc, startFightDelay, StartFight)
  35. #
  36. func StartFight():
  37. Reset()
  38. originalPlayerCount = AlivePlayerCount()
  39. waveTimer = AddTimer(npc, waveDelay, TimeoutWave)
  40. NextWave()
  41. func NextWave():
  42. waveCount += 1
  43. Notification("Wave %d." % waveCount)
  44. if waveCount > maxWave:
  45. Reward()
  46. else:
  47. SpawnMonsters()
  48. waveTimer.start(waveDelay)
  49. AddTimer(npc, checkDelay, CheckWave, "CheckTimer")
  50. func Reset():
  51. waveTimer = null
  52. waveCount = 0
  53. originalPlayerCount = 0
  54. func Reward():
  55. Notification("Congrats, you won")
  56. AddExp(rewardExp)
  57. AddGP(rewardGP)
  58. Reset()
  59. if IsTriggering():
  60. Trigger()
  61. func SpawnMonsters():
  62. var isStuck : bool = false
  63. var remainingPoints : int = (5 * waveCount) + ceili(originalPlayerCount * 0.7)
  64. monstersPool.shuffle()
  65. while(remainingPoints > 0 and not isStuck):
  66. isStuck = true
  67. for mob in monstersPool:
  68. var mobPoint : int = mob._stats["Level"] if "Level" in mob._stats else 1
  69. if mobPoint > 0 and mobPoint <= remainingPoints:
  70. var spawnAmount : int = randi_range(1, int(remainingPoints / floor(mobPoint)))
  71. remainingPoints -= mobPoint * spawnAmount
  72. Spawn(mob._id, spawnAmount, spawnCenter, spawnRadius)
  73. func CheckWave():
  74. if not IsTriggering():
  75. return
  76. if AlivePlayerCount() == 0:
  77. OnCancel()
  78. else:
  79. var mobCount : int = AliveMonsterCount()
  80. if mobCount > 0:
  81. if mobCount > 1:
  82. Notification("%d kaore corrupted beings are still around." % mobCount)
  83. else:
  84. Notification("One kaore corrupted being left to kill.")
  85. AddTimer(npc, checkDelay, CheckWave, "CheckTimer")
  86. else:
  87. NextWave()
  88. func TimeoutWave():
  89. Notification("You were not able to clear the corruption in time.")
  90. OnCancel()