combatant.gd 743 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class_name Combatant
  2. extends Node
  3. signal turn_finished
  4. @export var damage: int = 1
  5. @export var defense: int = 1
  6. var active = false: set = set_active
  7. func set_active(value):
  8. active = value
  9. set_process(value)
  10. set_process_input(value)
  11. if not active:
  12. return
  13. if $Health.armor >= $Health.base_armor + defense:
  14. $Health.armor = $Health.base_armor
  15. func attack(target):
  16. target.take_damage(damage)
  17. emit_signal("turn_finished")
  18. func consume(item):
  19. item.use(self)
  20. emit_signal("turn_finished")
  21. func defend():
  22. $Health.armor += defense
  23. emit_signal("turn_finished")
  24. func flee():
  25. emit_signal("turn_finished")
  26. func take_damage(damage_to_take):
  27. $Health.take_damage(damage_to_take)
  28. $Sprite2D/AnimationPlayer.play("take_damage")