Mostly fixed battle stuff

This commit is contained in:
2026-01-18 11:19:26 -06:00
parent 6f3f613f56
commit 73104560e8
5 changed files with 104 additions and 29 deletions

View File

@@ -77,3 +77,27 @@ func getPositionOfFighter(fighter:BattleFighter) -> BattlePosition:
assert(false) assert(false)
return BattlePosition.LEFT_TOP_BACK return BattlePosition.LEFT_TOP_BACK
func getEnemyPositions() -> Array[BattlePosition]:
# Not sure if I'm going to have pincer attacks so for now just do it based on
# the fighter positions.
var positions:Array[BattlePosition] = []
for pos in BattlePosition.values():
var fighter = getFighterAtPosition(pos)
if fighter == null:
continue
if fighter.team != BattleFighter.FighterTeam.ENEMY:
continue
positions.append(pos)
return positions
func getAllyPositions() -> Array[BattlePosition]:
var positions:Array[BattlePosition] = []
for pos in BattlePosition.values():
var fighter = getFighterAtPosition(pos)
if fighter == null:
continue
if fighter.team != BattleFighter.FighterTeam.ALLY:
continue
positions.append(pos)
return positions

View File

@@ -33,12 +33,34 @@ func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
if action == ActionBox.Action.BACK: if action == ActionBox.Action.BACK:
decisions.pop_back() decisions.pop_back()
actionBox.visible = false actionBox.visible = false
break # Get target for attack
elif action == ActionBox.Action.ATTACK: elif action == ActionBox.Action.ATTACK:
var targets = await _getTargets(fighter, fighter.movePrimary) var targets = await _getTargets(fighter, fighter.movePrimary)
decision = BattleDecision.new(
# Get cursor fighter.movePrimary,
fighter,
targets
)
# Get Magic move and targets
elif action == ActionBox.Action.MAGIC:
var magicMove = await _getMagicMove(fighter)
if magicMove != null:
var targets = await _getTargets(fighter, magicMove)
decision = BattleDecision.new(
magicMove,
fighter,
targets
)
# Get Item use and targets
elif action == ActionBox.Action.ITEM:
var itemMove = await _getItemUse(fighter)
if itemMove != null:
var targets = await _getTargets(fighter, itemMove)
decision = BattleDecision.new(
itemMove,
fighter,
targets
)
if decision != null: if decision != null:
decisions.append(decision) decisions.append(decision)
@@ -46,36 +68,58 @@ func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
# Return the made decision # Return the made decision
return decisions return decisions
func _getInitialTargetPosition(
fighter:BattleFighter,
move:BattleAction,
possiblePositions:Array[BattleSingleton.BattlePosition],
) -> BattleSingleton.BattlePosition:
# Find ally in possible positions
if move.preferAlly:
for pos in possiblePositions:
var targetFighter = BATTLE.getFighterAtPosition(pos)
if targetFighter != null and targetFighter.team == fighter.team:
return pos
# Otherwise, prefer to target enemy
for pos in possiblePositions:
var targetFighter = BATTLE.getFighterAtPosition(pos)
if targetFighter != null and targetFighter.team != fighter.team:
return pos
# If still noting found, just return first possible position
if possiblePositions.size() > 0:
return possiblePositions[0]
# Fallback (should not happen)
assert(false)
return BATTLE.BattlePosition.LEFT_TOP_BACK
func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighter]: func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighter]:
assert(fighter != null)
assert(move != null)
# Determine possible targets and whether to blink or not # Determine possible targets and whether to blink or not
var possiblePositions:Array[BattleSingleton.BattlePosition] = [ var possiblePositions:Array[BattleSingleton.BattlePosition] = []
BattleSingleton.BattlePosition.RIGHT_TOP_FRONT,
BattleSingleton.BattlePosition.RIGHT_MIDDLE_FRONT, if move.canTargetEnemy:
BattleSingleton.BattlePosition.RIGHT_BOTTOM_FRONT possiblePositions.append_array(BATTLE.getEnemyPositions())
] if move.canTargetAlly:
possiblePositions.append_array(BATTLE.getAllyPositions())
# Should not be possible to have no possible targets here # Should not be possible to have no possible targets here
assert(possiblePositions.size() > 0) assert(possiblePositions.size() > 0)
var activePositions:Array[BattleSingleton.BattlePosition] = [] var activePositions:Array[BattleSingleton.BattlePosition] = [
var selectedPositions:Array[BattleSingleton.BattlePosition] = [] _getInitialTargetPosition(fighter, move, possiblePositions)
]
# If there's only one possible target, auto-select it # This is where output will be stored.
if possiblePositions.size() == 1: var selectedPositions:Array[BattleSingleton.BattlePosition] = []
selectedPositions.append(possiblePositions[0])
# Here we wait for a selection to be confirmed. # Here we wait for a selection to be confirmed.
while selectedPositions.size() == 0: while selectedPositions.size() == 0:
var blink = activePositions.size() > 1 var blink = activePositions.size() > 1
activePositions.clear()
# activePositions.append(possiblePositions[0]) # For now, just single target
# Sake of testing just showing all blinking
blink = true
for pos in possiblePositions:
activePositions.append(pos)
# Show cursors # Show cursors
for cursor in cursorScenes.get_children(): for cursor in cursorScenes.get_children():
if !(cursor is BattleCursorIcon): if !(cursor is BattleCursorIcon):
@@ -91,7 +135,7 @@ func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighte
# TODO: Allow movement here, wait for selection, etc. # TODO: Allow movement here, wait for selection, etc.
# Wait 1 second for now and select all possible targets # Wait 1 second for now and select all possible targets
await get_tree().create_timer(1.0).timeout await get_tree().create_timer(1.0).timeout
selectedPositions = possiblePositions # selectedPositions = possiblePositions
# By this point selection has been made, hide all cursors # By this point selection has been made, hide all cursors
for cursor in cursorScenes.get_children(): for cursor in cursorScenes.get_children():
@@ -110,6 +154,12 @@ func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighte
assert(targets.size() > 0) assert(targets.size() > 0)
return targets return targets
func _getMagicMove(fighter:BattleFighter) -> BattleAction:
return null
func _getItemUse(fighter:BattleFighter) -> BattleAction:
return null
func getFighterSceneAtPosition(pos:BattleSingleton.BattlePosition) -> BattleFighterScene: func getFighterSceneAtPosition(pos:BattleSingleton.BattlePosition) -> BattleFighterScene:
for fighterScene in battleFighterScenes.get_children(): for fighterScene in battleFighterScenes.get_children():
if !(fighterScene is BattleFighterScene): if !(fighterScene is BattleFighterScene):

View File

@@ -1,5 +1,6 @@
class_name BattleAction class_name BattleAction
var handle:String
var speedModifier:float var speedModifier:float
var canTargetMultiple:bool var canTargetMultiple:bool
var canTargetEnemy:bool var canTargetEnemy:bool
@@ -7,6 +8,7 @@ var canTargetAlly:bool
var preferAlly:bool var preferAlly:bool
func _init(params:Dictionary) -> void: func _init(params:Dictionary) -> void:
self.handle = params["handle"]
self.speedModifier = params.get("speedModifier", 1.0) self.speedModifier = params.get("speedModifier", 1.0)
self.canTargetMultiple = params.get("canTargetMultiple", false) self.canTargetMultiple = params.get("canTargetMultiple", false)
self.canTargetEnemy = params.get("canTargetEnemy", true) self.canTargetEnemy = params.get("canTargetEnemy", true)

View File

@@ -13,4 +13,4 @@ func getPriority() -> float:
return 1.0 return 1.0
func execute(cutscene:Cutscene) -> void: func execute(cutscene:Cutscene) -> void:
pass pass

View File

@@ -12,7 +12,6 @@ enum BattleMoveResult {
CRIT, CRIT,
} }
var name:String
var power:int var power:int
var mpCost:int var mpCost:int
var accuracy:float var accuracy:float
@@ -20,7 +19,7 @@ var moveType:MoveType
var fieldUse:bool var fieldUse:bool
func _init(params:Dictionary) -> void: func _init(params:Dictionary) -> void:
self.name = params.get("name", "Unknown Move") super(params)
self.power = params.get("power", 0) self.power = params.get("power", 0)
self.mpCost = params.get("mpCost", 0) self.mpCost = params.get("mpCost", 0)
self.speedModifier = params.get("speedModifier", 1.0) self.speedModifier = params.get("speedModifier", 1.0)
@@ -67,14 +66,14 @@ func canFighterUse(fighter:BattleFighter) -> bool:
# Moves # Moves
static var MOVE_PUNCH = BattleMove.new({ static var MOVE_PUNCH = BattleMove.new({
"name": "Punch", "handle": "punch",
"power": 15, "power": 15,
"accuracy": 0.95, "accuracy": 0.95,
"moveType": MoveType.PHYSICAL "moveType": MoveType.PHYSICAL
}) })
static var MOVE_FIRE1 = BattleMove.new({ static var MOVE_FIRE1 = BattleMove.new({
"name": "Fire", "handle": "fire1",
"power": 25, "power": 25,
"mpCost": 5, "mpCost": 5,
"accuracy": 0.9, "accuracy": 0.9,
@@ -83,7 +82,7 @@ static var MOVE_FIRE1 = BattleMove.new({
}) })
static var MOVE_HEAL1 = BattleMove.new({ static var MOVE_HEAL1 = BattleMove.new({
"name": "Heal", "handle": "heal1",
"power": -20, "power": -20,
"mpCost": 8, "mpCost": 8,
"accuracy": 1.0, "accuracy": 1.0,