This commit is contained in:
horoli
2026-02-04 01:44:38 +09:00
parent e020e44d8f
commit 3b9fa47f0a
7 changed files with 126 additions and 100 deletions
+42 -17
View File
@@ -15,6 +15,13 @@ import 'shop_provider.dart';
import '../game/logic.dart';
class TurnEffectResult {
final bool canAct;
final bool effectTriggered;
TurnEffectResult({required this.canAct, required this.effectTriggered});
}
class EnemyIntent {
final EnemyActionType type;
final int value;
@@ -225,8 +232,9 @@ class BattleProvider with ChangeNotifier {
/// Handle player's action choice
Future<void> playerAction(ActionType type, RiskLevel risk) async {
if (!isPlayerTurn || player.isDead || enemy.isDead || showRewardPopup)
if (!isPlayerTurn || player.isDead || enemy.isDead || showRewardPopup) {
return;
}
// 0. Ensure Pre-emptive Enemy Defense is applied (if not already via animation)
applyPendingEnemyDefense();
@@ -245,14 +253,19 @@ class BattleProvider with ChangeNotifier {
notifyListeners();
// 2. Process Start-of-Turn Effects (Stun, Bleed)
bool canAct = _processStartTurnEffects(player);
TurnEffectResult turnEffect = _processStartTurnEffects(player);
if (player.isDead) {
await _onDefeat();
return;
}
if (!canAct) {
// If a visual effect occurred (bleed, stun), wait a bit before action
if (turnEffect.effectTriggered) {
await Future.delayed(const Duration(milliseconds: 800));
}
if (!turnEffect.canAct) {
_endPlayerTurn(); // Skip turn if stunned
return;
}
@@ -474,11 +487,12 @@ class BattleProvider with ChangeNotifier {
}
/// Check Status Effects at Start of Turn
bool _processStartTurnEffects(Character character) {
TurnEffectResult _processStartTurnEffects(Character character) {
final result = CombatCalculator.processStartTurnEffects(character);
int totalBleed = result['bleedDamage'];
bool isStunned = result['isStunned'];
bool effectTriggered = false;
// 1. Bleed Damage
if (totalBleed > 0) {
@@ -496,14 +510,19 @@ class BattleProvider with ChangeNotifier {
type: DamageType.bleed,
),
);
effectTriggered = true;
}
// 2. Stun Check
if (isStunned) {
_addLog("${character.name} is stunned!");
effectTriggered = true;
}
return !isStunned;
return TurnEffectResult(
canAct: !isStunned,
effectTriggered: effectTriggered,
);
}
// --- Turn Management Phases ---
@@ -522,14 +541,19 @@ class BattleProvider with ChangeNotifier {
}
// Process Start-of-Turn Effects
bool canAct = _processStartTurnEffects(enemy);
TurnEffectResult turnEffect = _processStartTurnEffects(enemy);
if (enemy.isDead) {
_onVictory();
return;
}
if (canAct && currentEnemyIntent != null) {
// If a visual effect occurred (bleed, stun), wait a bit before action
if (turnEffect.effectTriggered) {
await Future.delayed(const Duration(milliseconds: 800));
}
if (turnEffect.canAct && currentEnemyIntent != null) {
final intent = currentEnemyIntent!;
if (intent.type == EnemyActionType.defend) {
@@ -617,7 +641,7 @@ class BattleProvider with ChangeNotifier {
return;
}
}
} else if (!canAct) {
} else if (!turnEffect.canAct) {
// If cannot act (stunned)
_addLog("Enemy is stunned and cannot act!");
int tid = _turnTransactionId;
@@ -674,10 +698,11 @@ class BattleProvider with ChangeNotifier {
_addLog("Choose a reward.");
ItemTier currentTier = ItemTier.tier1;
if (stage > GameConfig.tier2StageMax)
if (stage > GameConfig.tier2StageMax) {
currentTier = ItemTier.tier3;
else if (stage > GameConfig.tier1StageMax)
} else if (stage > GameConfig.tier1StageMax) {
currentTier = ItemTier.tier2;
}
rewardOptions = [];
@@ -910,16 +935,12 @@ class BattleProvider with ChangeNotifier {
if (canAttack && canDefend) {
// Both options available: Use configured probability
isAttack = _random.nextDouble() < BattleConfig.enemyAttackChance;
} else if (canAttack) {
// Must attack
isAttack = true;
} else if (canDefend) {
// Must defend
isAttack = false;
} else {
// Both forbidden (Rare case, effectively stunned but not via Stun status)
// Default to Defend as a fallback, outcomes will be handled by stats/luck
isAttack = false;
// Must attack (default) or both forbidden (defaults to attack currently)
isAttack = true;
}
// Decide Risk Level
@@ -1113,7 +1134,11 @@ class BattleProvider with ChangeNotifier {
}
/// Tries to applyStatus effects from attacker's equipment to the target.
void _tryApplyStatusEffects(Character attacker, Character target, int damageToHp) {
void _tryApplyStatusEffects(
Character attacker,
Character target,
int damageToHp,
) {
List<StatusEffect> effectsToApply = CombatCalculator.getAppliedEffects(
attacker,
random: _random, // Pass injected random