Combat.gd 869 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. extends Node
  2. signal combat_finished(winner, loser)
  3. func initialize(combat_combatants):
  4. for combatant in combat_combatants:
  5. combatant = combatant.instance()
  6. if combatant is Combatant:
  7. $Combatants.add_combatant(combatant)
  8. combatant.get_node("Health").connect("dead", self, "_on_combatant_death", [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)