68 lines
1.9 KiB
GDScript
68 lines
1.9 KiB
GDScript
class_name BattleScene extends Node3D
|
|
|
|
@export var actionBox:ActionBox = null
|
|
@export var battleCursor:BattleCursor = null
|
|
@export var battleFighterScenes:Node
|
|
|
|
signal neverEmitted
|
|
|
|
func _init() ->void:
|
|
BATTLE.battleScene = self
|
|
BATTLE.battleStarted.connect(onBattleStarted)
|
|
|
|
func onBattleStarted() -> void:
|
|
pass
|
|
|
|
func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
|
|
var decisions:Array[BattleDecision] = []
|
|
|
|
while fighters.size() > decisions.size():
|
|
var fighter = fighters[decisions.size()]
|
|
var decision:BattleDecision = null
|
|
|
|
# Simulate walking forward animation like in Final Fantasy
|
|
await get_tree().create_timer(0.5).timeout
|
|
|
|
# Until decision made...
|
|
while decision == null:
|
|
# Get the selected action
|
|
actionBox.visible = true
|
|
var action = await self.actionBox.getAction(fighter)
|
|
|
|
# Go back to previous fighter
|
|
if action == ActionBox.Action.BACK:
|
|
decisions.pop_back()
|
|
actionBox.visible = false
|
|
break
|
|
elif action == ActionBox.Action.ATTACK:
|
|
var targets = await _getTargets(fighter, fighter.movePrimary)
|
|
|
|
# Get cursor
|
|
|
|
|
|
if decision != null:
|
|
decisions.append(decision)
|
|
|
|
# Return the made decision
|
|
return decisions
|
|
|
|
func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighter]:
|
|
print("Determining target")
|
|
|
|
battleCursor.visible = true
|
|
var positions:Array[BattleSingleton.BattlePosition] = []
|
|
for pos in BATTLE.BattlePosition.values():
|
|
positions.append(pos)
|
|
battleCursor.setCursors(self, positions)
|
|
|
|
await neverEmitted
|
|
return []
|
|
|
|
func getFighterSceneAtPosition(pos:BattleSingleton.BattlePosition) -> BattleFighterScene:
|
|
for fighterScene in battleFighterScenes.get_children():
|
|
if !(fighterScene is BattleFighterScene):
|
|
continue
|
|
if fighterScene.battlePosition == pos:
|
|
return fighterScene
|
|
return null
|