diff --git a/godot/combat/CombatAction.gd b/godot/combat/CombatAction.gd index 3996db3d072779f99886231844aa557f78af49e3..f5e435d18426d00c0d2a8fbf111067526fe8d078 100644 --- a/godot/combat/CombatAction.gd +++ b/godot/combat/CombatAction.gd @@ -23,9 +23,10 @@ func initialize(p_targets : Array, p_allys : Array, p_actor : Battler) -> void: actor = p_actor initialized = true -func execute() -> void: +func execute(): assert(initialized) print("%s missing overwrite of the execute method" % name) + return false func attack_routine(): actor.attack(target) @@ -41,6 +42,7 @@ func select_target_routine(): var interface = actor.get_tree().get_nodes_in_group("interface")[0] target = yield(interface.select_target(targets), "completed") interface.action_list.hide() + return target func use_skill_routine(): if skill_to_use.success_chance == 1.0: @@ -50,5 +52,4 @@ func use_skill_routine(): if rand_range(0, 1.0) < skill_to_use.success_chance: actor.use_skill(target, skill_to_use) yield(actor.get_tree().create_timer(1.0), "timeout") - - + \ No newline at end of file diff --git a/godot/combat/CombatArena.gd b/godot/combat/CombatArena.gd index b1d8d76c8b7031237f0081a2a5a9e964f4517f08..459d1127afcdfda0bd7d916fa274abf8d89700b8 100644 --- a/godot/combat/CombatArena.gd +++ b/godot/combat/CombatArena.gd @@ -109,7 +109,6 @@ func play_turn(): # Temp random target selection for the monsters action = get_active_battler().actions.get_child(0) action.target = battler.choose_target(targets) - yield(turn_queue.play_turn(action), "completed") battler.selected = false else: diff --git a/godot/combat/battlers/actions/Attack.gd b/godot/combat/battlers/actions/Attack.gd index a36e376fb8b572a7cd895fd631cdec933449af8a..595cacf3db17f101f420268480f939c79ab95773 100644 --- a/godot/combat/battlers/actions/Attack.gd +++ b/godot/combat/battlers/actions/Attack.gd @@ -5,7 +5,10 @@ func execute(): print("TODO: ATTACK -> at some point we should define the attack commands based on the equiped items\n" + "ie: if you have a bow you should not move to the target!") if actor.party_member: - yield(select_target_routine(), "completed") + var target = yield(select_target_routine(), "completed") + if target == null: + return false yield(move_to_target_routine(), "completed") yield(attack_routine(), "completed") yield(return_to_start_position_routine(), "completed") + return true diff --git a/godot/combat/battlers/actions/SkillAction.gd b/godot/combat/battlers/actions/SkillAction.gd index 849f9fcb0386a1135a2c5a64c6df17b7fdd0d710..8fbd05dec2b5b87211e99ff3f67a3c48d1d380db 100644 --- a/godot/combat/battlers/actions/SkillAction.gd +++ b/godot/combat/battlers/actions/SkillAction.gd @@ -8,7 +8,10 @@ func execute(): assert(initialized) if actor.party_member: print("TODO: SKILL -> if skill can target all enemies this command should be changed to SelectAllCommand") - yield(select_target_routine(), "completed") + var target = yield(select_target_routine(), "completed") + if target == null: + return false yield(move_to_target_routine(), "completed") yield(use_skill_routine(), "completed") yield(return_to_start_position_routine(), "completed") + return true diff --git a/godot/combat/interface/SelectArrow.gd b/godot/combat/interface/SelectArrow.gd index c095bdffb0938028898687bad4941e84f3e92b1f..3790346f865901304e259511467511f572259cce 100644 --- a/godot/combat/interface/SelectArrow.gd +++ b/godot/combat/interface/SelectArrow.gd @@ -43,6 +43,9 @@ func _gui_input(event): if event.is_action_pressed("ui_accept"): emit_signal("target_selected", target_active) get_tree().set_input_as_handled() + elif event.is_action_pressed("ui_cancel"): + emit_signal("target_selected", null) + get_tree().set_input_as_handled() var index = targets.find(target_active) if event.is_action_pressed("ui_down"): diff --git a/godot/combat/turn_queue/TurnQueue.gd b/godot/combat/turn_queue/TurnQueue.gd index 4f2e56512d746e65a82d43f298316d94a49cf1d2..e4b2c03898d76c76ae0139d3c3647d644b881e32 100644 --- a/godot/combat/turn_queue/TurnQueue.gd +++ b/godot/combat/turn_queue/TurnQueue.gd @@ -3,6 +3,7 @@ extends YSort class_name TurnQueue onready var active_battler : Battler +var last_action_canceled : bool = false func initialize(): var battlers = get_battlers() @@ -12,13 +13,17 @@ func initialize(): active_battler = get_child(0) func play_turn(action : CombatAction): - yield(active_battler.skin.move_forward(), "completed") + if not last_action_canceled: + yield(active_battler.skin.move_forward(), "completed") if active_battler.party_member: action.initialize(get_monsters(), get_party(), active_battler) else: action.initialize(get_party(), get_monsters(), active_battler) - yield(action.execute(), "completed") - + var hit_target = yield(action.execute(), "completed") + if not hit_target: + last_action_canceled = true + return + last_action_canceled = false var new_index : int = (active_battler.get_index() + 1) % get_child_count() active_battler = get_child(new_index)