Tales-of-PKMN/game/battle/target_resolver.gd
2026-10-18 11:32:51 +02:00

68 lines
2.6 KiB
GDScript

class_name TargetResolver
extends RefCounted
#convertit MoveData.target (valeurs PokeAPI) + le choix du joueur en liste d'emplacements.
const SELECTABLE : Array[String] = ["selected-pokemon", "selected-pokemon-me-first", "specific-move", "ally", "user-or-ally"]
static func get_target_type(move : MoveData) -> String:
return move.target if move.target != "" else "selected-pokemon"
static func get_selectable_targets(battle : Battle, actor : BattleSlot, move : MoveData) -> Array[BattleSlot]:
#emplacements parmi lesquels le joueur peut choisir (ordre : par camp puis par position)
var result : Array[BattleSlot] = []
match get_target_type(move):
"ally":
result = battle.get_allies(actor)
"user-or-ally":
result = battle.get_allies(actor)
result.append(actor)
_:
for s in battle.get_active_slots():
if s != actor: result.append(s)
return result
static func needs_selection(battle : Battle, actor : BattleSlot, move : MoveData) -> bool:
#une etape "choisir la cible" n'est utile que s'il y a vraiment un choix
return SELECTABLE.has(get_target_type(move)) and get_selectable_targets(battle, actor, move).size() > 1
static func resolve(battle : Battle, actor : BattleSlot, move : MoveData, chosen : BattleSlot) -> Array[BattleSlot]:
#liste finale des cibles au moment ou la capacite est utilisee (cible K.O. entre-temps : redirigee)
var opponents : Array[BattleSlot] = battle.get_opponents(actor)
var allies : Array[BattleSlot] = battle.get_allies(actor)
var result : Array[BattleSlot] = []
match get_target_type(move):
"user":
result.append(actor)
"all-opponents":
result = opponents
"random-opponent":
if !opponents.is_empty(): result.append(battle.random_pick(opponents))
"all-other-pokemon":
result.append_array(opponents)
result.append_array(allies)
"all-pokemon", "entire-field":
result.append_array(opponents)
result.append_array(allies)
result.append(actor)
"all-allies", "user-and-allies":
result = allies
result.append(actor)
"ally", "user-or-ally":
if chosen != null and chosen.is_active() and (allies.has(chosen) or chosen == actor):
result.append(chosen)
elif !allies.is_empty():
result.append(battle.random_pick(allies))
elif get_target_type(move) == "user-or-ally":
result.append(actor)
"users-field", "opponents-field", "fainting-pokemon":
pass #effets de terrain : plus tard
_:
#cible choisie ; si elle est K.O. ou absente, redirection vers un adversaire au hasard
if chosen != null and chosen != actor and chosen.is_active():
result.append(chosen)
elif !opponents.is_empty():
result.append(battle.random_pick(opponents))
return result