1
This commit is contained in:
@@ -229,7 +229,92 @@ describe('buildBattlePlan', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not turn recovery fallback into a random player attack', () => {
|
||||
it('keeps battle_attack_basic as a single basic attack instead of randomly selecting another skill', () => {
|
||||
const state = {
|
||||
...createBaseState(),
|
||||
playerMana: 20,
|
||||
sceneHostileNpcs: [
|
||||
{
|
||||
id: 'monster-1',
|
||||
name: '山狼',
|
||||
action: '压低身体',
|
||||
description: '测试敌人',
|
||||
animation: 'idle' as const,
|
||||
xMeters: 3,
|
||||
yOffset: 0,
|
||||
facing: 'left' as const,
|
||||
attackRange: 1,
|
||||
speed: 1,
|
||||
hp: 80,
|
||||
maxHp: 80,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const plan = buildBattlePlan({
|
||||
state,
|
||||
option: {
|
||||
...createBattleOption(),
|
||||
functionId: 'battle_attack_basic',
|
||||
},
|
||||
character: createTestCharacter(),
|
||||
totalSequenceMs: 900,
|
||||
turnVisualMs: 820,
|
||||
resetStageMs: 260,
|
||||
minTurnCount: 1,
|
||||
});
|
||||
|
||||
const playerTurns = plan.turns.filter((turn) => turn.actor === 'player');
|
||||
|
||||
expect(playerTurns).toHaveLength(1);
|
||||
expect(playerTurns[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
selectedSkillId: 'battle-basic-attack',
|
||||
}),
|
||||
);
|
||||
expect(plan.finalState.playerMana).toBe(state.playerMana);
|
||||
});
|
||||
|
||||
it('resolves one full speed-ordered round when combat continues', () => {
|
||||
const state = {
|
||||
...createBaseState(),
|
||||
sceneHostileNpcs: [
|
||||
{
|
||||
id: 'monster-1',
|
||||
name: '山狼',
|
||||
action: '压低身体',
|
||||
description: '测试敌人',
|
||||
animation: 'idle' as const,
|
||||
xMeters: 3,
|
||||
yOffset: 0,
|
||||
facing: 'left' as const,
|
||||
attackRange: 1,
|
||||
speed: 1,
|
||||
hp: 120,
|
||||
maxHp: 120,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const plan = buildBattlePlan({
|
||||
state,
|
||||
option: {
|
||||
...createBattleOption(),
|
||||
functionId: 'battle_attack_basic',
|
||||
},
|
||||
character: createTestCharacter(),
|
||||
totalSequenceMs: 6000,
|
||||
turnVisualMs: 820,
|
||||
resetStageMs: 260,
|
||||
minTurnCount: 6,
|
||||
});
|
||||
|
||||
expect(plan.turns.map((turn) => turn.actor)).toEqual(['player', 'monster']);
|
||||
expect(plan.finalState.inBattle).toBe(true);
|
||||
expect(plan.finalState.sceneHostileNpcs[0]?.hp).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('keeps recovery as a player turn without converting it into an attack', () => {
|
||||
const state = {
|
||||
...createBaseState(),
|
||||
playerHp: 40,
|
||||
@@ -265,8 +350,77 @@ describe('buildBattlePlan', () => {
|
||||
minTurnCount: 1,
|
||||
});
|
||||
|
||||
expect(plan.turns.some((turn) => turn.actor === 'player')).toBe(false);
|
||||
expect(plan.preparedState.playerHp).toBeGreaterThan(state.playerHp);
|
||||
expect(plan.preparedState.playerMana).toBeGreaterThan(state.playerMana);
|
||||
const playerTurn = plan.turns.find((turn) => turn.actor === 'player');
|
||||
|
||||
expect(playerTurn).toEqual(
|
||||
expect.objectContaining({
|
||||
actor: 'player',
|
||||
actionKind: 'recover',
|
||||
selectedSkillId: null,
|
||||
damage: 0,
|
||||
}),
|
||||
);
|
||||
expect(plan.finalState.playerHp).toBeGreaterThan(state.playerHp);
|
||||
expect(plan.finalState.playerMana).toBeGreaterThan(state.playerMana);
|
||||
});
|
||||
|
||||
it('includes companion turns in fight mode and orders the round by speed', () => {
|
||||
const state = {
|
||||
...createBaseState(),
|
||||
currentNpcBattleMode: 'fight' as const,
|
||||
companions: [
|
||||
{
|
||||
npcId: 'companion-1',
|
||||
characterId: 'archer-hero',
|
||||
joinedAtAffinity: 10,
|
||||
hp: 60,
|
||||
maxHp: 60,
|
||||
mana: 20,
|
||||
maxMana: 20,
|
||||
skillCooldowns: {},
|
||||
},
|
||||
],
|
||||
sceneHostileNpcs: [
|
||||
{
|
||||
id: 'monster-1',
|
||||
name: '山狼',
|
||||
action: '压低身体',
|
||||
description: '测试敌人',
|
||||
animation: 'idle' as const,
|
||||
xMeters: 3,
|
||||
yOffset: 0,
|
||||
facing: 'left' as const,
|
||||
attackRange: 1,
|
||||
speed: 0.5,
|
||||
hp: 120,
|
||||
maxHp: 120,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const plan = buildBattlePlan({
|
||||
state,
|
||||
option: {
|
||||
...createBattleOption(),
|
||||
functionId: 'battle_attack_basic',
|
||||
},
|
||||
character: createTestCharacter(),
|
||||
totalSequenceMs: 6000,
|
||||
turnVisualMs: 820,
|
||||
resetStageMs: 260,
|
||||
minTurnCount: 6,
|
||||
});
|
||||
|
||||
expect(plan.turns.map((turn) => turn.actor)).toEqual([
|
||||
'companion',
|
||||
'player',
|
||||
'monster',
|
||||
]);
|
||||
expect(plan.turns[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
actor: 'companion',
|
||||
companionNpcId: 'companion-1',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user