Skip to content

Commit

Permalink
status in turn change
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitaiMazliah committed Jan 9, 2024
1 parent 4053e55 commit fc36445
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
5 changes: 5 additions & 0 deletions scripts/agents/agent_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func end_turn() -> void:
await execute_all_effect_for_time(self, Effect.EffectTime.OnTurnEnd)
turn_ended.emit()

func turn_changed() -> void:
for status: AgentStatus in statuses:
if status.has_method('on_turn_changed'):
status.on_turn_changed()

func take_damage(damage: int) -> void:
current_health -= damage
print(name, " took ", damage, " and left with current_health ", current_health)
Expand Down
10 changes: 1 addition & 9 deletions scripts/agents/statuses/poison_status.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ extends AgentStatus
class_name PoisonStatus

@export var damage_per_turn: int
@export var turn_changed_event_channel: VoidEventChannel

func on_status_given(agent: Agent2D):
super.on_status_given(agent)
turn_changed_event_channel.event_raised.connect(_on_turn_changed)

func on_status_ended(agent: Agent2D):
turn_changed_event_channel.event_raised.disconnect(_on_turn_changed)

func _on_turn_changed():
func on_turn_changed():
_agent.take_damage(damage_per_turn)
4 changes: 2 additions & 2 deletions scripts/turn_queue.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class_name TurnQueue

@export var victory_event_channel: VoidEventChannel
@export var defeat_event_channel: VoidEventChannel
@export var turn_changed_event_channel: VoidEventChannel
@export var turn_time_in_secs : float = 10
@export var turn_label : Label
@export var turn_countdown_progress_bar: ProgressBar
Expand Down Expand Up @@ -65,7 +64,6 @@ func _start_turn():
turn_label.modulate.a = 1
turn_label.text = _active_agent.name + "'s turns"
get_tree().create_timer(1).timeout.connect(_fade_label)
turn_changed_event_channel.raise_event()
_active_agent.start_turn()
timer.start()
_countdown_timers = [
Expand All @@ -79,6 +77,8 @@ func _start_turn():
func _end_turn() -> void:
print("Ending turn of ", _active_agent_index, " ", _active_agent)
await _active_agent.end_turn()
for agent: Agent2D in agents:
agent.turn_changed()
await _kill_dead_agents()
_start_turn()

Expand Down

0 comments on commit fc36445

Please sign in to comment.