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)
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:
decisions.pop_back()
actionBox.visible = false
break
# Get target for attack
elif action == ActionBox.Action.ATTACK:
var targets = await _getTargets(fighter, fighter.movePrimary)
# Get cursor
decision = BattleDecision.new(
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:
decisions.append(decision)
@@ -46,36 +68,58 @@ func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
# Return the made decision
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]:
assert(fighter != null)
assert(move != null)
# Determine possible targets and whether to blink or not
var possiblePositions:Array[BattleSingleton.BattlePosition] = [
BattleSingleton.BattlePosition.RIGHT_TOP_FRONT,
BattleSingleton.BattlePosition.RIGHT_MIDDLE_FRONT,
BattleSingleton.BattlePosition.RIGHT_BOTTOM_FRONT
]
var possiblePositions:Array[BattleSingleton.BattlePosition] = []
if move.canTargetEnemy:
possiblePositions.append_array(BATTLE.getEnemyPositions())
if move.canTargetAlly:
possiblePositions.append_array(BATTLE.getAllyPositions())
# Should not be possible to have no possible targets here
assert(possiblePositions.size() > 0)
var activePositions:Array[BattleSingleton.BattlePosition] = []
var selectedPositions:Array[BattleSingleton.BattlePosition] = []
var activePositions:Array[BattleSingleton.BattlePosition] = [
_getInitialTargetPosition(fighter, move, possiblePositions)
]
# If there's only one possible target, auto-select it
if possiblePositions.size() == 1:
selectedPositions.append(possiblePositions[0])
# This is where output will be stored.
var selectedPositions:Array[BattleSingleton.BattlePosition] = []
# Here we wait for a selection to be confirmed.
while selectedPositions.size() == 0:
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
for cursor in cursorScenes.get_children():
if !(cursor is BattleCursorIcon):
@@ -91,7 +135,7 @@ func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighte
# TODO: Allow movement here, wait for selection, etc.
# Wait 1 second for now and select all possible targets
await get_tree().create_timer(1.0).timeout
selectedPositions = possiblePositions
# selectedPositions = possiblePositions
# By this point selection has been made, hide all cursors
for cursor in cursorScenes.get_children():
@@ -110,6 +154,12 @@ func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighte
assert(targets.size() > 0)
return targets
func _getMagicMove(fighter:BattleFighter) -> BattleAction:
return null
func _getItemUse(fighter:BattleFighter) -> BattleAction:
return null
func getFighterSceneAtPosition(pos:BattleSingleton.BattlePosition) -> BattleFighterScene:
for fighterScene in battleFighterScenes.get_children():
if !(fighterScene is BattleFighterScene):

View File

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

View File

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

View File

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