combat.gd 887 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. extends Node
  2. signal combat_finished(winner, loser)
  3. func initialize(combat_combatants):
  4. for combatant in combat_combatants:
  5. combatant = combatant.instantiate()
  6. if combatant is Combatant:
  7. $Combatants.add_combatant(combatant)
  8. combatant.get_node("Health").connect("dead", Callable(self, "_on_combatant_death").bind(combatant))
  9. else:
  10. combatant.queue_free()
  11. $UI.initialize()
  12. $TurnQueue.initialize()
  13. func clear_combat():
  14. for n in $Combatants.get_children():
  15. n.queue_free()
  16. for n in $UI/Combatants.get_children():
  17. n.queue_free()
  18. func finish_combat(winner, loser):
  19. emit_signal("combat_finished", winner, loser)
  20. func _on_combatant_death(combatant):
  21. var winner
  22. if not combatant.name == "Player":
  23. winner = $Combatants/Player
  24. else:
  25. for n in $Combatants.get_children():
  26. if not n.name == "Player":
  27. winner = n
  28. break
  29. finish_combat(winner, combatant)