Combatant.gd 699 B

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