Refactor: Slim down BattleProvider and extract logic services. Restore original animations and positioning.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user