Refactor: Slim down BattleProvider and extract logic services. Restore original animations and positioning.
This commit is contained in:
parent
0e0748540e
commit
83ea191ca2
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
|
|
@ -97,4 +97,26 @@ class BattleConfig {
|
||||||
return sizeSafe;
|
return sizeSafe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getFeedbackText(BattleFeedbackType type) {
|
||||||
|
switch (type) {
|
||||||
|
case BattleFeedbackType.miss:
|
||||||
|
return "MISS";
|
||||||
|
case BattleFeedbackType.failed:
|
||||||
|
return "FAILED";
|
||||||
|
case BattleFeedbackType.dodge:
|
||||||
|
return "DODGE";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Color getFeedbackColor(BattleFeedbackType type) {
|
||||||
|
switch (type) {
|
||||||
|
case BattleFeedbackType.miss:
|
||||||
|
return Colors.redAccent; // Or use ThemeConfig.missText if preferred
|
||||||
|
case BattleFeedbackType.failed:
|
||||||
|
return Colors.orangeAccent; // Or use ThemeConfig.failedText
|
||||||
|
case BattleFeedbackType.dodge:
|
||||||
|
return Colors.greenAccent; // Or use ThemeConfig.statLuckColor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class GameConfig {
|
||||||
static const int restStageInterval = 8;
|
static const int restStageInterval = 8;
|
||||||
static const int tier1StageMax = 12;
|
static const int tier1StageMax = 12;
|
||||||
static const int tier2StageMax = 24;
|
static const int tier2StageMax = 24;
|
||||||
|
static const int maxStage = 36;
|
||||||
|
|
||||||
// Battle
|
// Battle
|
||||||
static const double stageHealRatio = 0.1;
|
static const double stageHealRatio = 0.1;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ enum StatusEffectType {
|
||||||
bleed, // Takes damage at start/end of turn
|
bleed, // Takes damage at start/end of turn
|
||||||
defenseForbidden, // Cannot use Defend action
|
defenseForbidden, // Cannot use Defend action
|
||||||
disarmed, // Attack strength reduced (e.g., 10%)
|
disarmed, // Attack strength reduced (e.g., 10%)
|
||||||
attackUp, // New: Increases Attack Power
|
attackUp,
|
||||||
|
heal, // New: Increases Attack Power
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 공격 실패 시 이펙트 피드백 타입 정의
|
/// 공격 실패 시 이펙트 피드백 타입 정의
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
export 'logic/battle_log_manager.dart';
|
export 'logic/battle_log_manager.dart';
|
||||||
export 'logic/combat_calculator.dart';
|
export 'logic/combat_calculator.dart';
|
||||||
export 'logic/loot_generator.dart';
|
export 'logic/loot_generator.dart';
|
||||||
|
export 'logic/enemy_ai_service.dart';
|
||||||
|
export 'logic/stage_manager.dart';
|
||||||
|
export 'logic/effect_event_factory.dart';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
import 'dart:math';
|
||||||
|
import '../enums.dart';
|
||||||
|
import '../models.dart';
|
||||||
|
|
||||||
|
class EffectEventFactory {
|
||||||
|
/// Generates a unique ID for events.
|
||||||
|
static String _generateId(Random random) {
|
||||||
|
return DateTime.now().millisecondsSinceEpoch.toString() +
|
||||||
|
random.nextInt(1000).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a successful attack event.
|
||||||
|
static EffectEvent createAttackEvent({
|
||||||
|
required Character attacker,
|
||||||
|
required Character target,
|
||||||
|
required EffectTarget effectTarget,
|
||||||
|
required RiskLevel risk,
|
||||||
|
required int damage,
|
||||||
|
required Random random,
|
||||||
|
}) {
|
||||||
|
return EffectEvent(
|
||||||
|
id: _generateId(random),
|
||||||
|
type: ActionType.attack,
|
||||||
|
risk: risk,
|
||||||
|
target: effectTarget,
|
||||||
|
feedbackType: null,
|
||||||
|
attacker: attacker,
|
||||||
|
targetEntity: target,
|
||||||
|
damageValue: damage,
|
||||||
|
isSuccess: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a dodge event.
|
||||||
|
static EffectEvent createDodgeEvent({
|
||||||
|
required Character attacker,
|
||||||
|
required Character target,
|
||||||
|
required EffectTarget effectTarget,
|
||||||
|
required RiskLevel risk,
|
||||||
|
required Random random,
|
||||||
|
}) {
|
||||||
|
return EffectEvent(
|
||||||
|
id: _generateId(random),
|
||||||
|
type: ActionType.attack,
|
||||||
|
risk: risk,
|
||||||
|
target: effectTarget,
|
||||||
|
feedbackType: BattleFeedbackType.dodge,
|
||||||
|
attacker: attacker,
|
||||||
|
targetEntity: target,
|
||||||
|
damageValue: 0,
|
||||||
|
isSuccess: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a miss or failure event.
|
||||||
|
static EffectEvent createFailureEvent({
|
||||||
|
required Character attacker,
|
||||||
|
required Character target,
|
||||||
|
required EffectTarget effectTarget,
|
||||||
|
required ActionType type,
|
||||||
|
required RiskLevel risk,
|
||||||
|
required Random random,
|
||||||
|
}) {
|
||||||
|
BattleFeedbackType feedbackType = (type == ActionType.attack)
|
||||||
|
? BattleFeedbackType.miss
|
||||||
|
: BattleFeedbackType.failed;
|
||||||
|
|
||||||
|
return EffectEvent(
|
||||||
|
id: _generateId(random),
|
||||||
|
type: type,
|
||||||
|
risk: risk,
|
||||||
|
target: effectTarget,
|
||||||
|
feedbackType: feedbackType,
|
||||||
|
attacker: attacker,
|
||||||
|
targetEntity: target,
|
||||||
|
isSuccess: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a successful defense event.
|
||||||
|
static EffectEvent createDefenseEvent({
|
||||||
|
required Character attacker,
|
||||||
|
required Character target,
|
||||||
|
required EffectTarget effectTarget,
|
||||||
|
required RiskLevel risk,
|
||||||
|
required int armorGained,
|
||||||
|
required Random random,
|
||||||
|
}) {
|
||||||
|
return EffectEvent(
|
||||||
|
id: _generateId(random),
|
||||||
|
type: ActionType.defend,
|
||||||
|
risk: risk,
|
||||||
|
target: effectTarget,
|
||||||
|
feedbackType: null,
|
||||||
|
attacker: attacker,
|
||||||
|
targetEntity: target,
|
||||||
|
armorGained: armorGained,
|
||||||
|
isSuccess: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
import 'dart:math';
|
||||||
|
import '../enums.dart';
|
||||||
|
import '../models.dart';
|
||||||
|
import '../config.dart';
|
||||||
|
import 'combat_calculator.dart';
|
||||||
|
|
||||||
|
class EnemyAIService {
|
||||||
|
/// Decides the next action for the enemy based on status effects and probability.
|
||||||
|
static EnemyIntent generateIntent(Character enemy, Random random) {
|
||||||
|
if (enemy.isDead) {
|
||||||
|
return EnemyIntent(
|
||||||
|
type: EnemyActionType.attack,
|
||||||
|
value: 0,
|
||||||
|
risk: RiskLevel.safe,
|
||||||
|
description: "Dead",
|
||||||
|
isSuccess: false,
|
||||||
|
finalValue: 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide Action Type
|
||||||
|
bool canDefend =
|
||||||
|
enemy.baseDefense > 0 &&
|
||||||
|
!enemy.hasStatus(StatusEffectType.defenseForbidden);
|
||||||
|
|
||||||
|
bool isAttack = true; // Default to attack
|
||||||
|
|
||||||
|
if (canDefend) {
|
||||||
|
// Both options available or forced? Currently using probability from config.
|
||||||
|
isAttack = random.nextDouble() < BattleConfig.enemyAttackChance;
|
||||||
|
} else {
|
||||||
|
// Must attack if defense is forbidden or base defense is 0
|
||||||
|
isAttack = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide Risk Level
|
||||||
|
RiskLevel risk = RiskLevel.values[random.nextInt(RiskLevel.values.length)];
|
||||||
|
|
||||||
|
CombatResult result;
|
||||||
|
if (isAttack) {
|
||||||
|
result = CombatCalculator.calculateActionOutcome(
|
||||||
|
actionType: ActionType.attack,
|
||||||
|
risk: risk,
|
||||||
|
luck: enemy.totalLuck,
|
||||||
|
baseValue: enemy.totalAtk,
|
||||||
|
);
|
||||||
|
|
||||||
|
return EnemyIntent(
|
||||||
|
type: EnemyActionType.attack,
|
||||||
|
value: result.value,
|
||||||
|
risk: risk,
|
||||||
|
description: "${result.value} (${risk.name})",
|
||||||
|
isSuccess: result.success,
|
||||||
|
finalValue: result.value,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
result = CombatCalculator.calculateActionOutcome(
|
||||||
|
actionType: ActionType.defend,
|
||||||
|
risk: risk,
|
||||||
|
luck: enemy.totalLuck,
|
||||||
|
baseValue: enemy.totalDefense,
|
||||||
|
);
|
||||||
|
|
||||||
|
return EnemyIntent(
|
||||||
|
type: EnemyActionType.defend,
|
||||||
|
value: result.value,
|
||||||
|
risk: risk,
|
||||||
|
description: "${result.value} (${risk.name})",
|
||||||
|
isSuccess: result.success,
|
||||||
|
finalValue: result.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
import 'dart:math';
|
||||||
|
import '../enums.dart';
|
||||||
|
import '../models.dart';
|
||||||
|
import '../data.dart';
|
||||||
|
import '../config.dart';
|
||||||
|
|
||||||
|
class StageManager {
|
||||||
|
/// Determines the stage type based on the stage number and configured intervals.
|
||||||
|
static StageType getStageTypeFor(int stageNumber) {
|
||||||
|
if (stageNumber % GameConfig.eliteStageInterval == 0) {
|
||||||
|
return StageType.elite;
|
||||||
|
} else if (stageNumber % GameConfig.shopStageInterval == 0) {
|
||||||
|
return StageType.shop;
|
||||||
|
} else if (stageNumber % GameConfig.restStageInterval == 0) {
|
||||||
|
return StageType.rest;
|
||||||
|
}
|
||||||
|
return StageType.battle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a Character instance for the enemy in the current stage.
|
||||||
|
static Character generateEnemy(int stage, StageType type) {
|
||||||
|
bool isElite = type == StageType.elite;
|
||||||
|
|
||||||
|
// For non-battle stages, return dummy characters (Merchants/Campfires)
|
||||||
|
if (type == StageType.shop) {
|
||||||
|
return Character(name: "Merchant", maxHp: 9999, armor: 0, atk: 0);
|
||||||
|
} else if (type == StageType.rest) {
|
||||||
|
return Character(name: "Campfire", maxHp: 9999, armor: 0, atk: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal or Elite Battle
|
||||||
|
EnemyTemplate template = EnemyTable.getRandomEnemy(
|
||||||
|
stage: stage,
|
||||||
|
isElite: isElite,
|
||||||
|
);
|
||||||
|
return template.createCharacter(stage: stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates 3 item reward options based on the current stage and tier.
|
||||||
|
static List<Item> generateRewardOptions(int stage, StageType currentStageType) {
|
||||||
|
ItemTier currentTier = _getTierForStage(stage);
|
||||||
|
List<Item> rewardOptions = [];
|
||||||
|
|
||||||
|
bool isElite = currentStageType == StageType.elite;
|
||||||
|
bool isTier1 = currentTier == ItemTier.tier1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
ItemRarity? minRarity;
|
||||||
|
ItemRarity? maxRarity;
|
||||||
|
|
||||||
|
if (isElite && i == 0) {
|
||||||
|
if (isTier1) {
|
||||||
|
minRarity = ItemRarity.rare;
|
||||||
|
maxRarity = ItemRarity.rare;
|
||||||
|
} else {
|
||||||
|
minRarity = ItemRarity.legendary;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isTier1) {
|
||||||
|
maxRarity = ItemRarity.magic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemTemplate? item = ItemTable.getRandomItem(
|
||||||
|
tier: currentTier,
|
||||||
|
minRarity: minRarity,
|
||||||
|
maxRarity: maxRarity,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (item != null) {
|
||||||
|
rewardOptions.add(item.createItem(stage: stage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rewardOptions.add(_createSkipRewardItem());
|
||||||
|
return rewardOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates the gold reward for defeating an enemy.
|
||||||
|
static int calculateGoldReward(int stage, Random random) {
|
||||||
|
return GameConfig.baseGoldReward +
|
||||||
|
(stage * GameConfig.goldRewardPerStage) +
|
||||||
|
random.nextInt(GameConfig.goldRewardVariance);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ItemTier _getTierForStage(int stage) {
|
||||||
|
if (stage > GameConfig.tier2StageMax) {
|
||||||
|
return ItemTier.tier3;
|
||||||
|
} else if (stage > GameConfig.tier1StageMax) {
|
||||||
|
return ItemTier.tier2;
|
||||||
|
}
|
||||||
|
return ItemTier.tier1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Item _createSkipRewardItem() {
|
||||||
|
return Item(
|
||||||
|
id: "reward_skip",
|
||||||
|
name: "Skip Reward",
|
||||||
|
description: "Take nothing and move on.",
|
||||||
|
atkBonus: 0,
|
||||||
|
hpBonus: 0,
|
||||||
|
slot: EquipmentSlot.accessory,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
import '../enums.dart';
|
||||||
|
|
||||||
|
/// Represents the result of applying status effects at the start of a turn.
|
||||||
|
class TurnEffectResult {
|
||||||
|
final bool canAct;
|
||||||
|
final bool effectTriggered;
|
||||||
|
|
||||||
|
TurnEffectResult({required this.canAct, required this.effectTriggered});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the planned action of an enemy for the current turn.
|
||||||
|
class EnemyIntent {
|
||||||
|
final EnemyActionType type;
|
||||||
|
final int value;
|
||||||
|
final RiskLevel risk;
|
||||||
|
final String description;
|
||||||
|
final bool isSuccess;
|
||||||
|
final int finalValue;
|
||||||
|
bool isApplied; // Mutable flag to prevent double execution
|
||||||
|
|
||||||
|
EnemyIntent({
|
||||||
|
required this.type,
|
||||||
|
required this.value,
|
||||||
|
required this.risk,
|
||||||
|
required this.description,
|
||||||
|
required this.isSuccess,
|
||||||
|
required this.finalValue,
|
||||||
|
this.isApplied = false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -5,12 +5,14 @@ enum DamageTarget { player, enemy }
|
||||||
|
|
||||||
class DamageEvent {
|
class DamageEvent {
|
||||||
final int damage;
|
final int damage;
|
||||||
|
final int armorDamage; // New field
|
||||||
final DamageTarget target;
|
final DamageTarget target;
|
||||||
final DamageType type;
|
final DamageType type;
|
||||||
final RiskLevel? risk;
|
final RiskLevel? risk;
|
||||||
|
|
||||||
DamageEvent({
|
DamageEvent({
|
||||||
required this.damage,
|
required this.damage,
|
||||||
|
this.armorDamage = 0,
|
||||||
required this.target,
|
required this.target,
|
||||||
this.type = DamageType.normal,
|
this.type = DamageType.normal,
|
||||||
this.risk,
|
this.risk,
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ export 'model/stage.dart';
|
||||||
export 'model/stat.dart';
|
export 'model/stat.dart';
|
||||||
export 'model/stat_modifier.dart';
|
export 'model/stat_modifier.dart';
|
||||||
export 'model/status_effect.dart';
|
export 'model/status_effect.dart';
|
||||||
|
export 'model/battle_models.dart';
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,432 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../game/enums.dart';
|
||||||
|
import '../game/models.dart';
|
||||||
|
import '../game/config.dart';
|
||||||
|
import '../providers/battle_provider.dart';
|
||||||
|
import '../providers/settings_provider.dart';
|
||||||
|
import '../widgets/battle/effect_sprite_widget.dart';
|
||||||
|
import '../widgets/battle/floating_battle_texts.dart';
|
||||||
|
import '../widgets/battle/battle_animation_widget.dart';
|
||||||
|
import '../widgets/battle/shake_widget.dart';
|
||||||
|
import '../widgets/battle/explosion_widget.dart';
|
||||||
|
|
||||||
|
enum AnimationPhase { none, start, middle, end, hurt, block }
|
||||||
|
|
||||||
|
mixin BattleVisualHandler<T extends StatefulWidget> on State<T> {
|
||||||
|
// State variables for animations
|
||||||
|
final List<DamageTextData> floatingDamageTexts = [];
|
||||||
|
final List<FloatingEffectData> floatingEffects = [];
|
||||||
|
final List<FeedbackTextData> floatingFeedbackTexts = [];
|
||||||
|
|
||||||
|
final GlobalKey playerKey = GlobalKey();
|
||||||
|
final GlobalKey enemyKey = GlobalKey();
|
||||||
|
final GlobalKey stackKey = GlobalKey();
|
||||||
|
final GlobalKey<ShakeWidgetState> shakeKey = GlobalKey<ShakeWidgetState>();
|
||||||
|
final GlobalKey<BattleAnimationWidgetState> playerAnimKey = GlobalKey();
|
||||||
|
final GlobalKey<BattleAnimationWidgetState> enemyAnimKey = GlobalKey();
|
||||||
|
final GlobalKey<ExplosionWidgetState> explosionKey = GlobalKey();
|
||||||
|
final GlobalKey<EffectSpriteWidgetState> effectSpriteKey = GlobalKey();
|
||||||
|
final GlobalKey rootStackKey = GlobalKey();
|
||||||
|
|
||||||
|
AnimationPhase playerAnimPhase = AnimationPhase.none;
|
||||||
|
RiskLevel? activeRiskLevel;
|
||||||
|
bool isAttackSuccess = true;
|
||||||
|
bool isPlayerAttacking = false;
|
||||||
|
bool isEnemyAttacking = false;
|
||||||
|
|
||||||
|
StreamSubscription<DamageEvent>? damageSubscription;
|
||||||
|
StreamSubscription<EffectEvent>? effectSubscription;
|
||||||
|
StreamSubscription<HealEvent>? healSubscription;
|
||||||
|
|
||||||
|
DateTime? lastFeedbackTime;
|
||||||
|
|
||||||
|
void setupVisualListeners(BattleProvider battleProvider) {
|
||||||
|
damageSubscription = battleProvider.damageStream.listen(_onDamageEvent);
|
||||||
|
effectSubscription = battleProvider.effectStream.listen(onEffectEvent);
|
||||||
|
healSubscription = battleProvider.healStream.listen(onHealEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void disposeVisualListeners() {
|
||||||
|
damageSubscription?.cancel();
|
||||||
|
effectSubscription?.cancel();
|
||||||
|
healSubscription?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Animation Core Logic ---
|
||||||
|
|
||||||
|
void _onDamageEvent(DamageEvent event) {
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
if (event.target == DamageTarget.player) {
|
||||||
|
if (event.armorDamage > 0) {
|
||||||
|
_triggerPlayerBlock();
|
||||||
|
} else if (event.damage > 0) {
|
||||||
|
_triggerPlayerHurt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addFloatingDamageText(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _triggerPlayerHurt() {
|
||||||
|
if (playerAnimPhase != AnimationPhase.none &&
|
||||||
|
playerAnimPhase != AnimationPhase.hurt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() => playerAnimPhase = AnimationPhase.hurt);
|
||||||
|
Future.delayed(const Duration(milliseconds: 800), () {
|
||||||
|
if (mounted && playerAnimPhase == AnimationPhase.hurt) {
|
||||||
|
setState(() => playerAnimPhase = AnimationPhase.none);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _triggerPlayerBlock() {
|
||||||
|
if (playerAnimPhase != AnimationPhase.none &&
|
||||||
|
playerAnimPhase != AnimationPhase.block) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() => playerAnimPhase = AnimationPhase.block);
|
||||||
|
Future.delayed(const Duration(milliseconds: 800), () {
|
||||||
|
if (mounted && playerAnimPhase == AnimationPhase.block) {
|
||||||
|
setState(() => playerAnimPhase = AnimationPhase.none);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void onHealEvent(HealEvent event) {
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
RenderBox? rootBox =
|
||||||
|
rootStackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (rootBox == null) return;
|
||||||
|
Offset rootOffset = rootBox.localToGlobal(Offset.zero);
|
||||||
|
|
||||||
|
Offset position = Offset(rootBox.size.width / 2, rootBox.size.height / 2);
|
||||||
|
|
||||||
|
if (event.target == HealTarget.player && playerAnimKey.currentContext != null) {
|
||||||
|
RenderBox? imageBox =
|
||||||
|
playerAnimKey.currentContext!.findRenderObject() as RenderBox?;
|
||||||
|
if (imageBox != null) {
|
||||||
|
Offset globalCenter = imageBox.localToGlobal(
|
||||||
|
Offset(imageBox.size.width / 2, imageBox.size.height / 2),
|
||||||
|
);
|
||||||
|
position = globalCenter - rootOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
effectSpriteKey.currentState?.playEffect(
|
||||||
|
position: position,
|
||||||
|
assetPath: 'assets/images/effects/heal.png',
|
||||||
|
frameCount: 4,
|
||||||
|
tileWidth: 100.0,
|
||||||
|
tileHeight: 100.0,
|
||||||
|
scale: 6.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
final String id = UniqueKey().toString();
|
||||||
|
setState(() {
|
||||||
|
floatingDamageTexts.add(
|
||||||
|
DamageTextData(
|
||||||
|
id: id,
|
||||||
|
widget: Positioned(
|
||||||
|
key: ValueKey('pos_$id'),
|
||||||
|
left: position.dx + BattleConfig.damageTextOffsetX,
|
||||||
|
top: position.dy + BattleConfig.damageTextOffsetY,
|
||||||
|
child: FloatingDamageText(
|
||||||
|
key: ValueKey(id),
|
||||||
|
damage: "+${event.amount}",
|
||||||
|
color: ThemeConfig.statHpPlayerColor,
|
||||||
|
onRemove: () {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => floatingDamageTexts.removeWhere((e) => e.id == id));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void onEffectEvent(EffectEvent event) {
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
void showEffect() {
|
||||||
|
if (event.feedbackType != null) {
|
||||||
|
addFloatingFeedbackText(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IconData icon = BattleConfig.getIcon(event.type);
|
||||||
|
Color color = BattleConfig.getColor(event.type, event.risk);
|
||||||
|
double size = BattleConfig.getSize(event.risk);
|
||||||
|
addFloatingEffect(event, icon, color, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isVisualOnly) {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
} else if (event.type == ActionType.attack && event.target == EffectTarget.enemy) {
|
||||||
|
final RenderBox? pBox = playerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
final RenderBox? eBox = enemyKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
|
||||||
|
if (pBox != null && eBox != null) {
|
||||||
|
final offset = eBox.localToGlobal(Offset.zero) - pBox.localToGlobal(Offset.zero);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
isPlayerAttacking = true;
|
||||||
|
activeRiskLevel = event.risk;
|
||||||
|
isAttackSuccess = event.isSuccess == true && event.feedbackType == null;
|
||||||
|
});
|
||||||
|
|
||||||
|
final animRisk = event.feedbackType != null ? RiskLevel.safe : event.risk;
|
||||||
|
|
||||||
|
playerAnimKey.currentState?.animateAttack(
|
||||||
|
offset,
|
||||||
|
() {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
if (event.risk == RiskLevel.risky && event.feedbackType == null) {
|
||||||
|
shakeKey.currentState?.shake();
|
||||||
|
RenderBox? sBox = stackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (sBox != null) {
|
||||||
|
Offset localEnemyPos = sBox.globalToLocal(eBox.localToGlobal(Offset.zero)) +
|
||||||
|
Offset(eBox.size.width / 2, eBox.size.height / 2);
|
||||||
|
explosionKey.currentState?.explode(localEnemyPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
animRisk,
|
||||||
|
onAnimationStart: () => setState(() => playerAnimPhase = AnimationPhase.start),
|
||||||
|
onAnimationMiddle: () => setState(() => playerAnimPhase = AnimationPhase.middle),
|
||||||
|
onAnimationEnd: () => setState(() => playerAnimPhase = AnimationPhase.end),
|
||||||
|
).then((_) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isPlayerAttacking = false;
|
||||||
|
playerAnimPhase = AnimationPhase.none;
|
||||||
|
activeRiskLevel = null;
|
||||||
|
isAttackSuccess = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (event.type == ActionType.attack && event.target == EffectTarget.player) {
|
||||||
|
bool enableAnim = context.read<SettingsProvider>().enableEnemyAnimations;
|
||||||
|
if (!enableAnim) {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final RenderBox? pBox = playerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
final RenderBox? eBox = enemyKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
|
||||||
|
if (pBox != null && eBox != null) {
|
||||||
|
final offset = pBox.localToGlobal(Offset.zero) - eBox.localToGlobal(Offset.zero);
|
||||||
|
setState(() => isEnemyAttacking = true);
|
||||||
|
|
||||||
|
final animRisk = event.feedbackType != null ? RiskLevel.safe : event.risk;
|
||||||
|
|
||||||
|
enemyAnimKey.currentState?.animateAttack(offset, () {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
if (event.risk == RiskLevel.risky && event.feedbackType == null) {
|
||||||
|
shakeKey.currentState?.shake();
|
||||||
|
RenderBox? sBox = stackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (sBox != null) {
|
||||||
|
Offset localPlayerPos = sBox.globalToLocal(pBox.localToGlobal(Offset.zero)) +
|
||||||
|
Offset(pBox.size.width / 2, pBox.size.height / 2);
|
||||||
|
explosionKey.currentState?.explode(localPlayerPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, animRisk).then((_) {
|
||||||
|
if (mounted) setState(() => isEnemyAttacking = false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (event.type == ActionType.defend) {
|
||||||
|
if (event.target == EffectTarget.player) {
|
||||||
|
setState(() => isPlayerAttacking = true);
|
||||||
|
playerAnimKey.currentState?.animateDefense(() {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
}).then((_) {
|
||||||
|
if (mounted) setState(() => isPlayerAttacking = false);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showEffect();
|
||||||
|
context.read<BattleProvider>().handleImpact(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addFloatingDamageText(DamageEvent event) {
|
||||||
|
if (!mounted) return;
|
||||||
|
final String id = UniqueKey().toString();
|
||||||
|
final targetKey = event.target == DamageTarget.player ? playerKey : enemyKey;
|
||||||
|
final RenderBox? box = targetKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (box == null) return;
|
||||||
|
|
||||||
|
Offset position = box.localToGlobal(Offset(box.size.width / 2, box.size.height / 3));
|
||||||
|
RenderBox? rootBox = rootStackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (rootBox != null) position = rootBox.globalToLocal(position);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
floatingDamageTexts.add(
|
||||||
|
DamageTextData(
|
||||||
|
id: id,
|
||||||
|
widget: Positioned(
|
||||||
|
key: ValueKey('pos_$id'),
|
||||||
|
left: position.dx,
|
||||||
|
top: position.dy,
|
||||||
|
child: FloatingDamageText(
|
||||||
|
key: ValueKey(id),
|
||||||
|
damage: event.damage.toString(),
|
||||||
|
color: event.color,
|
||||||
|
onRemove: () {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => floatingDamageTexts.removeWhere((e) => e.id == id));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void addFloatingEffect(EffectEvent event, IconData icon, Color color, double size) {
|
||||||
|
if (!mounted) return;
|
||||||
|
final String id = UniqueKey().toString();
|
||||||
|
final targetKey = event.target == EffectTarget.player ? playerKey : enemyKey;
|
||||||
|
final RenderBox? box = targetKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (box == null) return;
|
||||||
|
|
||||||
|
Offset position = box.localToGlobal(Offset.zero);
|
||||||
|
RenderBox? rootBox = rootStackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (rootBox != null) {
|
||||||
|
position = rootBox.globalToLocal(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
double offsetX = 0;
|
||||||
|
double offsetY = 0;
|
||||||
|
if (event.target == EffectTarget.enemy) {
|
||||||
|
offsetX = box.size.width * BattleConfig.effectEnemyOffsetX;
|
||||||
|
offsetY = box.size.height * BattleConfig.effectEnemyOffsetY;
|
||||||
|
} else {
|
||||||
|
offsetX = box.size.width * BattleConfig.effectPlayerOffsetX;
|
||||||
|
offsetY = box.size.height * BattleConfig.effectPlayerOffsetY;
|
||||||
|
}
|
||||||
|
position = position + Offset(offsetX, offsetY);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
floatingEffects.add(
|
||||||
|
FloatingEffectData(
|
||||||
|
id: id,
|
||||||
|
widget: Positioned(
|
||||||
|
key: ValueKey('pos_$id'),
|
||||||
|
left: position.dx,
|
||||||
|
top: position.dy,
|
||||||
|
child: FloatingEffect(
|
||||||
|
key: ValueKey(id),
|
||||||
|
icon: icon,
|
||||||
|
color: color,
|
||||||
|
size: size,
|
||||||
|
onRemove: () {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => floatingEffects.removeWhere((e) => e.id == id));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void addFloatingFeedbackText(EffectEvent event) {
|
||||||
|
if (!mounted || event.feedbackType == null) return;
|
||||||
|
|
||||||
|
final now = DateTime.now();
|
||||||
|
if (lastFeedbackTime != null && now.difference(lastFeedbackTime!) < const Duration(milliseconds: 300)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastFeedbackTime = now;
|
||||||
|
|
||||||
|
final String id = UniqueKey().toString();
|
||||||
|
final targetKey = event.target == EffectTarget.player ? playerKey : enemyKey;
|
||||||
|
final RenderBox? box = targetKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (box == null) return;
|
||||||
|
|
||||||
|
Offset position = box.localToGlobal(Offset.zero);
|
||||||
|
RenderBox? rootBox = rootStackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||||
|
if (rootBox != null) {
|
||||||
|
position = rootBox.globalToLocal(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
double offsetX = 0;
|
||||||
|
double offsetY = 0;
|
||||||
|
if (event.target == EffectTarget.enemy) {
|
||||||
|
offsetX = box.size.width * BattleConfig.effectEnemyOffsetX;
|
||||||
|
offsetY = box.size.height * BattleConfig.effectEnemyOffsetY;
|
||||||
|
} else {
|
||||||
|
offsetX = box.size.width * BattleConfig.effectPlayerOffsetX;
|
||||||
|
offsetY = box.size.height * BattleConfig.effectPlayerOffsetY;
|
||||||
|
}
|
||||||
|
position = position + Offset(offsetX, offsetY);
|
||||||
|
|
||||||
|
final feedbackText = BattleConfig.getFeedbackText(event.feedbackType!);
|
||||||
|
final feedbackColor = BattleConfig.getFeedbackColor(event.feedbackType!);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
floatingFeedbackTexts.add(
|
||||||
|
FeedbackTextData(
|
||||||
|
id: id,
|
||||||
|
eventId: event.id,
|
||||||
|
widget: Positioned(
|
||||||
|
key: ValueKey('pos_$id'),
|
||||||
|
left: position.dx,
|
||||||
|
top: position.dy,
|
||||||
|
child: FloatingFeedbackText(
|
||||||
|
key: ValueKey(id),
|
||||||
|
feedback: feedbackText,
|
||||||
|
color: feedbackColor,
|
||||||
|
onRemove: () {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => floatingFeedbackTexts.removeWhere((e) => e.id == id));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get hasPendingBattleAnimations {
|
||||||
|
return isPlayerAttacking ||
|
||||||
|
isEnemyAttacking ||
|
||||||
|
floatingDamageTexts.isNotEmpty ||
|
||||||
|
floatingEffects.isNotEmpty ||
|
||||||
|
floatingFeedbackTexts.isNotEmpty ||
|
||||||
|
(explosionKey.currentState?.isAnimating ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> waitForBattleAnimationsToSettle() async {
|
||||||
|
final deadline = DateTime.now().add(
|
||||||
|
AnimationConfig.attackRiskyTotal +
|
||||||
|
AnimationConfig.floatingTextDuration +
|
||||||
|
const Duration(milliseconds: 400),
|
||||||
|
);
|
||||||
|
|
||||||
|
while (mounted && hasPendingBattleAnimations && DateTime.now().isBefore(deadline)) {
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
export 'battle/battle_bottom_section.dart';
|
||||||
|
export 'battle/battle_arena.dart';
|
||||||
export 'battle/battle_animation_widget.dart';
|
export 'battle/battle_animation_widget.dart';
|
||||||
export 'battle/battle_controls.dart';
|
export 'battle/battle_controls.dart';
|
||||||
export 'battle/battle_header.dart';
|
export 'battle/battle_header.dart';
|
||||||
|
|
@ -7,3 +9,5 @@ export 'battle/explosion_widget.dart';
|
||||||
export 'battle/floating_battle_texts.dart';
|
export 'battle/floating_battle_texts.dart';
|
||||||
export 'battle/risk_selection_dialog.dart';
|
export 'battle/risk_selection_dialog.dart';
|
||||||
export 'battle/shake_widget.dart';
|
export 'battle/shake_widget.dart';
|
||||||
|
export 'battle/battle_overlays.dart';
|
||||||
|
export 'battle/effect_sprite_widget.dart';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../providers/battle_provider.dart';
|
||||||
|
import 'character_status_card.dart';
|
||||||
|
import 'shake_widget.dart';
|
||||||
|
import 'battle_animation_widget.dart';
|
||||||
|
|
||||||
|
class BattleArena extends StatelessWidget {
|
||||||
|
final BattleProvider battleProvider;
|
||||||
|
final GlobalKey playerKey;
|
||||||
|
final GlobalKey enemyKey;
|
||||||
|
final GlobalKey<BattleAnimationWidgetState> playerAnimKey;
|
||||||
|
final GlobalKey<BattleAnimationWidgetState> enemyAnimKey;
|
||||||
|
final GlobalKey<ShakeWidgetState> shakeKey;
|
||||||
|
final GlobalKey stackKey;
|
||||||
|
final bool isPlayerAttacking;
|
||||||
|
final bool isEnemyAttacking;
|
||||||
|
final String? playerOverrideImage;
|
||||||
|
final String? enemyOverrideImage;
|
||||||
|
|
||||||
|
const BattleArena({
|
||||||
|
super.key,
|
||||||
|
required this.battleProvider,
|
||||||
|
required this.playerKey,
|
||||||
|
required this.enemyKey,
|
||||||
|
required this.playerAnimKey,
|
||||||
|
required this.enemyAnimKey,
|
||||||
|
required this.shakeKey,
|
||||||
|
required this.stackKey,
|
||||||
|
required this.isPlayerAttacking,
|
||||||
|
required this.isEnemyAttacking,
|
||||||
|
this.playerOverrideImage,
|
||||||
|
this.enemyOverrideImage,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ShakeWidget(
|
||||||
|
key: shakeKey,
|
||||||
|
child: Stack(
|
||||||
|
key: stackKey,
|
||||||
|
children: [
|
||||||
|
// 1. Background Image
|
||||||
|
Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage('assets/images/background/tier_1.jpg'),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// 1.1 Opacity Layer
|
||||||
|
Container(color: Colors.black.withValues(alpha: 0.7)),
|
||||||
|
|
||||||
|
// 2. Character Area
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
// Player (Bottom Left)
|
||||||
|
Positioned(
|
||||||
|
bottom: 80,
|
||||||
|
left: 16,
|
||||||
|
child: CharacterStatusCard(
|
||||||
|
character: battleProvider.player,
|
||||||
|
isPlayer: true,
|
||||||
|
isTurn: battleProvider.isPlayerTurn,
|
||||||
|
key: playerKey,
|
||||||
|
animationKey: playerAnimKey,
|
||||||
|
hideStats: isPlayerAttacking,
|
||||||
|
overrideImage: playerOverrideImage,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Enemy (Top Right)
|
||||||
|
Positioned(
|
||||||
|
top: 16,
|
||||||
|
right: 16,
|
||||||
|
child: CharacterStatusCard(
|
||||||
|
character: battleProvider.enemy,
|
||||||
|
isPlayer: false,
|
||||||
|
isTurn: !battleProvider.isPlayerTurn,
|
||||||
|
key: enemyKey,
|
||||||
|
animationKey: enemyAnimKey,
|
||||||
|
hideStats: isEnemyAttacking,
|
||||||
|
overrideImage: enemyOverrideImage,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../game/enums.dart';
|
||||||
|
import '../../game/config.dart';
|
||||||
|
import '../../providers/battle_provider.dart';
|
||||||
|
import 'battle_controls.dart';
|
||||||
|
import 'battle_log_overlay.dart';
|
||||||
|
|
||||||
|
class BattleBottomSection extends StatelessWidget {
|
||||||
|
final BattleProvider battleProvider;
|
||||||
|
final bool showLogs;
|
||||||
|
final bool isPlayerAttacking;
|
||||||
|
final bool isEnemyAttacking;
|
||||||
|
final VoidCallback onToggleLogs;
|
||||||
|
final VoidCallback onAttackPressed;
|
||||||
|
final VoidCallback onDefendPressed;
|
||||||
|
final VoidCallback onItemPressed;
|
||||||
|
|
||||||
|
// Custom buttons/panels passed from parent to keep their logic there for now
|
||||||
|
final Widget equipmentSwapButton;
|
||||||
|
final Widget? equipmentSwapPanel;
|
||||||
|
|
||||||
|
const BattleBottomSection({
|
||||||
|
super.key,
|
||||||
|
required this.battleProvider,
|
||||||
|
required this.showLogs,
|
||||||
|
required this.isPlayerAttacking,
|
||||||
|
required this.isEnemyAttacking,
|
||||||
|
required this.onToggleLogs,
|
||||||
|
required this.onAttackPressed,
|
||||||
|
required this.onDefendPressed,
|
||||||
|
required this.onItemPressed,
|
||||||
|
required this.equipmentSwapButton,
|
||||||
|
this.equipmentSwapPanel,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
// 1. Logs Overlay
|
||||||
|
if (showLogs && battleProvider.logs.isNotEmpty)
|
||||||
|
Positioned(
|
||||||
|
top: 60,
|
||||||
|
left: 16,
|
||||||
|
right: 16,
|
||||||
|
height: BattleConfig.logsOverlayHeight,
|
||||||
|
child: BattleLogOverlay(logs: battleProvider.logs),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 2. Battle Controls (Bottom Right)
|
||||||
|
Positioned(
|
||||||
|
bottom: 20,
|
||||||
|
right: 20,
|
||||||
|
child: BattleControls(
|
||||||
|
isAttackEnabled: battleProvider.isPlayerTurn &&
|
||||||
|
!battleProvider.player.isDead &&
|
||||||
|
!battleProvider.enemy.isDead &&
|
||||||
|
!battleProvider.showRewardPopup &&
|
||||||
|
!isPlayerAttacking &&
|
||||||
|
!isEnemyAttacking,
|
||||||
|
isDefendEnabled: battleProvider.isPlayerTurn &&
|
||||||
|
!battleProvider.player.isDead &&
|
||||||
|
!battleProvider.enemy.isDead &&
|
||||||
|
!battleProvider.showRewardPopup &&
|
||||||
|
!isPlayerAttacking &&
|
||||||
|
!isEnemyAttacking &&
|
||||||
|
!battleProvider.player.hasStatus(
|
||||||
|
StatusEffectType.defenseForbidden,
|
||||||
|
),
|
||||||
|
onAttackPressed: onAttackPressed,
|
||||||
|
onDefendPressed: onDefendPressed,
|
||||||
|
onItemPressed: onItemPressed,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 3. Equipment Swap Panel
|
||||||
|
if (equipmentSwapPanel != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 20,
|
||||||
|
right: 96,
|
||||||
|
width: 260,
|
||||||
|
child: equipmentSwapPanel!,
|
||||||
|
),
|
||||||
|
|
||||||
|
// 4. Log Toggle & Swap Button (Bottom Left)
|
||||||
|
Positioned(
|
||||||
|
bottom: 20,
|
||||||
|
left: 20,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
equipmentSwapButton,
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
FloatingActionButton(
|
||||||
|
heroTag: "logToggle",
|
||||||
|
mini: true,
|
||||||
|
backgroundColor: ThemeConfig.toggleBtnBg,
|
||||||
|
onPressed: onToggleLogs,
|
||||||
|
child: Icon(
|
||||||
|
showLogs ? Icons.visibility_off : Icons.visibility,
|
||||||
|
color: ThemeConfig.textColorWhite,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,186 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../game/enums.dart';
|
||||||
|
import '../../game/models.dart';
|
||||||
|
import '../../game/config.dart';
|
||||||
|
import '../../providers/battle_provider.dart';
|
||||||
|
import '../../utils/item_utils.dart';
|
||||||
|
import '../inventory/item_stat_widget.dart';
|
||||||
|
import '../test/sprite_animation_widget.dart';
|
||||||
|
import '../../screens/main_menu_screen.dart';
|
||||||
|
|
||||||
|
class BattleRewardOverlay extends StatefulWidget {
|
||||||
|
final BattleProvider battleProvider;
|
||||||
|
|
||||||
|
const BattleRewardOverlay({super.key, required this.battleProvider});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<BattleRewardOverlay> createState() => _BattleRewardOverlayState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BattleRewardOverlayState extends State<BattleRewardOverlay> {
|
||||||
|
bool _isCompletingReward = false;
|
||||||
|
|
||||||
|
Future<void> _selectReward(Item item) async {
|
||||||
|
if (_isCompletingReward) return;
|
||||||
|
setState(() => _isCompletingReward = true);
|
||||||
|
|
||||||
|
widget.battleProvider.selectReward(item);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _isCompletingReward = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final battleProvider = widget.battleProvider;
|
||||||
|
return Container(
|
||||||
|
color: ThemeConfig.cardBgColor,
|
||||||
|
child: Center(
|
||||||
|
child: SimpleDialog(
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
"${AppStrings.victory} ${AppStrings.chooseReward}",
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.monetization_on,
|
||||||
|
color: ThemeConfig.statGoldColor,
|
||||||
|
size: ThemeConfig.itemIconSizeSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
"${battleProvider.lastGoldReward} G",
|
||||||
|
style: TextStyle(
|
||||||
|
color: ThemeConfig.statGoldColor,
|
||||||
|
fontSize: ThemeConfig.fontSizeBody,
|
||||||
|
fontWeight: ThemeConfig.fontWeightBold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
children: battleProvider.rewardOptions.map((item) {
|
||||||
|
bool isSkip = item.id == "reward_skip";
|
||||||
|
return SimpleDialogOption(
|
||||||
|
onPressed: _isCompletingReward ? null : () => _selectReward(item),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
if (!isSkip)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: ThemeConfig.rewardItemBg,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
border: Border.all(
|
||||||
|
color: item.rarity != ItemRarity.magic
|
||||||
|
? ItemUtils.getRarityColor(item.rarity)
|
||||||
|
: ThemeConfig.rarityCommon,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Image.asset(
|
||||||
|
ItemUtils.getIconPath(item.slot),
|
||||||
|
width: ThemeConfig.itemIconSizeMedium,
|
||||||
|
height: ThemeConfig.itemIconSizeMedium,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
filterQuality: FilterQuality.high,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (!isSkip) const SizedBox(width: 12),
|
||||||
|
Text(
|
||||||
|
item.name,
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: ThemeConfig.fontWeightBold,
|
||||||
|
fontSize: ThemeConfig.fontSizeLarge,
|
||||||
|
color: isSkip
|
||||||
|
? ThemeConfig.textColorGrey
|
||||||
|
: ItemUtils.getRarityColor(item.rarity),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (!isSkip) ItemStatWidget(item: item),
|
||||||
|
Text(
|
||||||
|
item.description,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: ThemeConfig.fontSizeMedium,
|
||||||
|
color: ThemeConfig.textColorGrey,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BattleDefeatOverlay extends StatelessWidget {
|
||||||
|
const BattleDefeatOverlay({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
color: ThemeConfig.battleBg,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const SpriteAnimationWidget(
|
||||||
|
assetPath: 'assets/images/character/Knight-Death.png',
|
||||||
|
frameCount: 4,
|
||||||
|
scale: 4.0,
|
||||||
|
loop: false,
|
||||||
|
customDuration: Duration(milliseconds: 1500),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
const Text(
|
||||||
|
AppStrings.defeat,
|
||||||
|
style: TextStyle(
|
||||||
|
color: ThemeConfig.statHpColor,
|
||||||
|
fontSize: ThemeConfig.fontSizeHuge,
|
||||||
|
fontWeight: ThemeConfig.fontWeightBold,
|
||||||
|
letterSpacing: ThemeConfig.letterSpacingHeader,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: ThemeConfig.menuButtonBg,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: ThemeConfig.paddingBtnHorizontal,
|
||||||
|
vertical: ThemeConfig.paddingBtnVertical,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pushAndRemoveUntil(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const MainMenuScreen(),
|
||||||
|
),
|
||||||
|
(route) => false,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
AppStrings.returnToMenu,
|
||||||
|
style: TextStyle(
|
||||||
|
color: ThemeConfig.textColorWhite,
|
||||||
|
fontSize: ThemeConfig.fontSizeHeader,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -129,7 +129,28 @@ class CharacterStatusCard extends StatelessWidget {
|
||||||
// assetPath: 'assets/images/character/Soldier.png',
|
// assetPath: 'assets/images/character/Soldier.png',
|
||||||
assetPath: overrideImage ?? character.image!,
|
assetPath: overrideImage ?? character.image!,
|
||||||
scale: 5.0, // Zoomed in (300x300 in 200x200 box)
|
scale: 5.0, // Zoomed in (300x300 in 200x200 box)
|
||||||
frameCount: 6,
|
frameCount: (overrideImage != null &&
|
||||||
|
(overrideImage!.contains("Knight-Hurt") ||
|
||||||
|
overrideImage!.contains("Knight-Death") ||
|
||||||
|
overrideImage!.contains("Knight-Block")))
|
||||||
|
? 4
|
||||||
|
: (overrideImage != null &&
|
||||||
|
overrideImage!.contains("Knight-Attack01"))
|
||||||
|
? 7
|
||||||
|
: (overrideImage != null &&
|
||||||
|
overrideImage!
|
||||||
|
.contains("Knight-Attack02"))
|
||||||
|
? 10
|
||||||
|
: (overrideImage != null &&
|
||||||
|
overrideImage!
|
||||||
|
.contains("Knight-Attack03"))
|
||||||
|
? 11
|
||||||
|
: 6,
|
||||||
|
loop: !(overrideImage != null &&
|
||||||
|
(overrideImage!.contains("Knight-Hurt") ||
|
||||||
|
overrideImage!.contains("Knight-Death") ||
|
||||||
|
overrideImage!.contains("Knight-Block") ||
|
||||||
|
overrideImage!.contains("Knight-Attack"))),
|
||||||
flip: !isPlayer,
|
flip: !isPlayer,
|
||||||
fallbackAssetPath: !isPlayer
|
fallbackAssetPath: !isPlayer
|
||||||
? 'assets/images/enemies/Orc.png'
|
? 'assets/images/enemies/Orc.png'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
export 'inventory/character_stats_widget.dart';
|
export 'inventory/character_stats_widget.dart';
|
||||||
export 'inventory/inventory_grid_widget.dart';
|
export 'inventory/inventory_grid_widget.dart';
|
||||||
export 'inventory/equipped_items_widget.dart';
|
export 'inventory/equipped_items_widget.dart';
|
||||||
|
export 'inventory/item_stat_widget.dart';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../game/models.dart';
|
||||||
|
import '../../game/config.dart';
|
||||||
|
|
||||||
|
class ItemStatWidget extends StatelessWidget {
|
||||||
|
final Item item;
|
||||||
|
final double fontSize;
|
||||||
|
final Color? color;
|
||||||
|
|
||||||
|
const ItemStatWidget({
|
||||||
|
super.key,
|
||||||
|
required this.item,
|
||||||
|
this.fontSize = ThemeConfig.fontSizeMedium,
|
||||||
|
this.color,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List<String> stats = [];
|
||||||
|
if (item.atkBonus > 0) stats.add("+${item.atkBonus} ${AppStrings.atk}");
|
||||||
|
if (item.hpBonus > 0) stats.add("+${item.hpBonus} ${AppStrings.hp}");
|
||||||
|
if (item.armorBonus > 0) {
|
||||||
|
stats.add("+${item.armorBonus} ${AppStrings.def}");
|
||||||
|
}
|
||||||
|
if (item.luck > 0) stats.add("+${item.luck} ${AppStrings.luck}");
|
||||||
|
if (item.dodge > 0) stats.add("+${item.dodge}% Dodge");
|
||||||
|
|
||||||
|
List<String> effectTexts = item.effects.map((e) => e.description).toList();
|
||||||
|
|
||||||
|
if (stats.isEmpty && effectTexts.isEmpty) return const SizedBox.shrink();
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (stats.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
|
||||||
|
child: Text(
|
||||||
|
stats.join(", "),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: fontSize,
|
||||||
|
color: color ?? ThemeConfig.statAtkColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (effectTexts.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4.0),
|
||||||
|
child: Text(
|
||||||
|
effectTexts.join(", "),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
color: ThemeConfig.rarityLegendary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ class SpriteAnimationWidget extends StatefulWidget {
|
||||||
final int frameCount;
|
final int frameCount;
|
||||||
final double scale;
|
final double scale;
|
||||||
final bool flip;
|
final bool flip;
|
||||||
|
final bool loop;
|
||||||
|
final Duration? customDuration;
|
||||||
final String? fallbackAssetPath;
|
final String? fallbackAssetPath;
|
||||||
|
|
||||||
const SpriteAnimationWidget({
|
const SpriteAnimationWidget({
|
||||||
|
|
@ -17,10 +19,11 @@ class SpriteAnimationWidget extends StatefulWidget {
|
||||||
required this.assetPath,
|
required this.assetPath,
|
||||||
this.tileWidth = 100.0,
|
this.tileWidth = 100.0,
|
||||||
this.tileHeight = 100.0,
|
this.tileHeight = 100.0,
|
||||||
this.frameCount =
|
this.frameCount = 6,
|
||||||
6, // Default guess, will adjust logic to use actual image width if possible
|
|
||||||
this.scale = 1.0,
|
this.scale = 1.0,
|
||||||
this.flip = false,
|
this.flip = false,
|
||||||
|
this.loop = true,
|
||||||
|
this.customDuration,
|
||||||
this.fallbackAssetPath,
|
this.fallbackAssetPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -40,11 +43,22 @@ class _SpriteAnimationWidgetState extends State<SpriteAnimationWidget>
|
||||||
super.initState();
|
super.initState();
|
||||||
_controller = AnimationController(
|
_controller = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 600), // 100ms per frame approx
|
duration: widget.customDuration ?? const Duration(milliseconds: 600),
|
||||||
);
|
);
|
||||||
_loadImage();
|
_loadImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant SpriteAnimationWidget oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (oldWidget.assetPath != widget.assetPath) {
|
||||||
|
// Don't set _isLoading = true to avoid flickering.
|
||||||
|
// Keep showing the old image until the new one is loaded.
|
||||||
|
_controller.reset();
|
||||||
|
_loadImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _loadImage() async {
|
Future<void> _loadImage() async {
|
||||||
try {
|
try {
|
||||||
await _loadAsset(widget.assetPath);
|
await _loadAsset(widget.assetPath);
|
||||||
|
|
@ -82,11 +96,18 @@ class _SpriteAnimationWidgetState extends State<SpriteAnimationWidget>
|
||||||
? maxFrames
|
? maxFrames
|
||||||
: widget.frameCount;
|
: widget.frameCount;
|
||||||
|
|
||||||
// Adjust duration based on frame count
|
// Adjust duration based on frame count if not custom
|
||||||
_controller.duration = Duration(
|
if (widget.customDuration == null) {
|
||||||
milliseconds: _calculatedFrameCount * 100,
|
_controller.duration = Duration(
|
||||||
);
|
milliseconds: _calculatedFrameCount * 100,
|
||||||
_controller.repeat();
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget.loop) {
|
||||||
|
_controller.repeat();
|
||||||
|
} else {
|
||||||
|
_controller.forward();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,17 +120,26 @@ class _SpriteAnimationWidgetState extends State<SpriteAnimationWidget>
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_isLoading || _image == null) {
|
if (_image == null) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: widget.tileWidth * widget.scale,
|
width: widget.tileWidth * widget.scale,
|
||||||
height: widget.tileHeight * widget.scale,
|
height: widget.tileHeight * widget.scale,
|
||||||
child: const Center(child: CircularProgressIndicator()),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _controller,
|
animation: _controller,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
|
int frame;
|
||||||
|
if (!widget.loop) {
|
||||||
|
frame = (_controller.value * _calculatedFrameCount)
|
||||||
|
.floor()
|
||||||
|
.clamp(0, _calculatedFrameCount - 1);
|
||||||
|
} else {
|
||||||
|
frame = (_controller.value * _calculatedFrameCount).floor() %
|
||||||
|
_calculatedFrameCount;
|
||||||
|
}
|
||||||
|
|
||||||
return Transform.scale(
|
return Transform.scale(
|
||||||
scaleX: widget.flip ? -1.0 : 1.0,
|
scaleX: widget.flip ? -1.0 : 1.0,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|
@ -120,9 +150,7 @@ class _SpriteAnimationWidgetState extends State<SpriteAnimationWidget>
|
||||||
),
|
),
|
||||||
painter: SpriteSheetPainter(
|
painter: SpriteSheetPainter(
|
||||||
image: _image!,
|
image: _image!,
|
||||||
currentFrame:
|
currentFrame: frame,
|
||||||
(_controller.value * _calculatedFrameCount).floor() %
|
|
||||||
_calculatedFrameCount,
|
|
||||||
tileWidth: widget.tileWidth,
|
tileWidth: widget.tileWidth,
|
||||||
tileHeight: widget.tileHeight,
|
tileHeight: widget.tileHeight,
|
||||||
scale: widget.scale,
|
scale: widget.scale,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:game_test/game/enums.dart';
|
||||||
|
import 'package:game_test/game/models.dart';
|
||||||
|
import 'package:game_test/providers/battle_provider.dart';
|
||||||
|
import 'package:game_test/providers/shop_provider.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late BattleProvider battleProvider;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
battleProvider = BattleProvider(shopProvider: ShopProvider());
|
||||||
|
battleProvider.player = Character(
|
||||||
|
name: 'Warrior',
|
||||||
|
hp: 50,
|
||||||
|
maxHp: 100,
|
||||||
|
armor: 0,
|
||||||
|
atk: 10,
|
||||||
|
baseDefense: 5,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('healing potion restores HP and is consumed', () async {
|
||||||
|
final potion = Item(
|
||||||
|
id: 'potion_heal_small',
|
||||||
|
name: 'Healing Potion',
|
||||||
|
description: 'Restores HP.',
|
||||||
|
atkBonus: 0,
|
||||||
|
hpBonus: 20,
|
||||||
|
slot: EquipmentSlot.consumable,
|
||||||
|
);
|
||||||
|
final healEvents = <HealEvent>[];
|
||||||
|
final subscription = battleProvider.healStream.listen(healEvents.add);
|
||||||
|
battleProvider.player.addToInventory(potion);
|
||||||
|
|
||||||
|
battleProvider.useConsumable(potion);
|
||||||
|
await Future<void>.delayed(Duration.zero);
|
||||||
|
|
||||||
|
expect(battleProvider.player.hp, 70);
|
||||||
|
expect(battleProvider.player.inventory, isNot(contains(potion)));
|
||||||
|
expect(healEvents.single.amount, 20);
|
||||||
|
|
||||||
|
await subscription.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('armor potion grants armor and is consumed', () {
|
||||||
|
final potion = Item(
|
||||||
|
id: 'potion_armor_small',
|
||||||
|
name: 'Iron Skin Potion',
|
||||||
|
description: 'Grants armor.',
|
||||||
|
atkBonus: 0,
|
||||||
|
hpBonus: 0,
|
||||||
|
armorBonus: 10,
|
||||||
|
slot: EquipmentSlot.consumable,
|
||||||
|
);
|
||||||
|
battleProvider.player.addToInventory(potion);
|
||||||
|
|
||||||
|
battleProvider.useConsumable(potion);
|
||||||
|
|
||||||
|
expect(battleProvider.player.armor, 10);
|
||||||
|
expect(battleProvider.player.inventory, isNot(contains(potion)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('strength potion applies attack buff and is consumed', () {
|
||||||
|
final potion = Item(
|
||||||
|
id: 'potion_strength_small',
|
||||||
|
name: 'Strength Potion',
|
||||||
|
description: 'Increases attack.',
|
||||||
|
atkBonus: 0,
|
||||||
|
hpBonus: 0,
|
||||||
|
slot: EquipmentSlot.consumable,
|
||||||
|
effects: [
|
||||||
|
ItemEffect(
|
||||||
|
type: StatusEffectType.attackUp,
|
||||||
|
probability: 100,
|
||||||
|
duration: 1,
|
||||||
|
value: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
battleProvider.player.addToInventory(potion);
|
||||||
|
|
||||||
|
battleProvider.useConsumable(potion);
|
||||||
|
|
||||||
|
expect(battleProvider.player.hasStatus(StatusEffectType.attackUp), isTrue);
|
||||||
|
expect(battleProvider.player.totalAtk, 15);
|
||||||
|
expect(battleProvider.player.inventory, isNot(contains(potion)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:game_test/game/enums.dart';
|
||||||
|
import 'package:game_test/game/logic/effect_event_factory.dart';
|
||||||
|
import 'package:game_test/game/models.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('enemy attack can target a named player character', () {
|
||||||
|
final enemy = Character(name: 'Scrawny Piso', maxHp: 20, armor: 0, atk: 6);
|
||||||
|
final player = Character(name: 'Warrior', maxHp: 50, armor: 0, atk: 5);
|
||||||
|
|
||||||
|
final event = EffectEventFactory.createAttackEvent(
|
||||||
|
attacker: enemy,
|
||||||
|
target: player,
|
||||||
|
effectTarget: EffectTarget.player,
|
||||||
|
risk: RiskLevel.safe,
|
||||||
|
damage: 6,
|
||||||
|
random: Random(0),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(event.target, EffectTarget.player);
|
||||||
|
expect(event.attacker, enemy);
|
||||||
|
expect(event.targetEntity, player);
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue