File size: 15,830 Bytes
7b95878 01d657e 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 a6cd8d1 7b95878 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
import { describe, it, expect, beforeEach } from 'vitest';
import { BattleEngine } from './BattleEngine';
import type { PicletDefinition, Move, SpecialAbility } from './types';
import { PicletType, AttackType } from './types';
describe('Missing Battle System Features', () => {
describe('manipulatePP Effects', () => {
it('should drain opponent PP', () => {
const ppDrainer: PicletDefinition = {
name: "PP Drainer",
description: "Drains opponent's PP",
tier: 'medium',
primaryType: PicletType.CULTURE,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Calm",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Mind Drain",
type: AttackType.CULTURE,
power: 0,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [
{
type: 'manipulatePP',
target: 'opponent',
action: 'drain',
amount: 'medium'
}
]
}
]
};
const opponent: PicletDefinition = {
name: "Opponent",
description: "Standard opponent",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Hardy",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Tackle",
type: AttackType.NORMAL,
power: 40,
accuracy: 100,
pp: 10,
priority: 0,
flags: ['contact'],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(ppDrainer, opponent);
const initialPP = engine.getState().opponentPiclet.moves[0].currentPP;
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
const finalPP = engine.getState().opponentPiclet.moves[0].currentPP;
expect(finalPP).toBeLessThan(initialPP);
expect(engine.getLog().some(msg => msg.includes('PP was drained'))).toBe(true);
});
it('should restore own PP', () => {
const ppRestorer: PicletDefinition = {
name: "PP Restorer",
description: "Restores own PP",
tier: 'medium',
primaryType: PicletType.FLORA,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Calm",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "PP Restore",
type: AttackType.FLORA,
power: 0,
accuracy: 100,
pp: 5,
priority: 0,
flags: [],
effects: [
{
type: 'manipulatePP',
target: 'self',
action: 'restore',
amount: 'large'
}
]
}
]
};
const opponent: PicletDefinition = {
name: "Opponent",
description: "Standard opponent",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Hardy",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Tackle",
type: AttackType.NORMAL,
power: 40,
accuracy: 100,
pp: 10,
priority: 0,
flags: ['contact'],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(ppRestorer, opponent);
// Use the PP restore move multiple times to drain it
engine['state'].playerPiclet.moves[0].currentPP = 1;
const initialPP = engine['state'].playerPiclet.moves[0].currentPP;
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
const finalPP = engine.getState().playerPiclet.moves[0].currentPP;
expect(finalPP).toBeGreaterThan(initialPP);
expect(engine.getLog().some(msg => msg.includes('PP was restored'))).toBe(true);
});
});
describe('fieldEffect System', () => {
it('should apply field effects that persist across turns', () => {
const fieldEffectUser: PicletDefinition = {
name: "Field Controller",
description: "Controls battlefield effects",
tier: 'medium',
primaryType: PicletType.SPACE,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Calm",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Reflect",
type: AttackType.SPACE,
power: 0,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [
{
type: 'fieldEffect',
effect: 'reflect',
target: 'playerSide',
stackable: false
}
]
}
]
};
const opponent: PicletDefinition = {
name: "Opponent",
description: "Standard opponent",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Hardy",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Physical Attack",
type: AttackType.BEAST,
power: 60,
accuracy: 100,
pp: 10,
priority: 0,
flags: ['contact'],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(fieldEffectUser, opponent);
// Apply reflect
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
expect(engine.getLog().some(msg => msg.includes('Reflect') && msg.includes('applied'))).toBe(true);
// Check if reflect reduces physical damage in subsequent turns
const initialHp = engine.getState().playerPiclet.currentHp;
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
const finalHp = engine.getState().playerPiclet.currentHp;
const damage = initialHp - finalHp;
// Reflect should reduce physical damage
expect(damage).toBeLessThan(30); // Should be reduced from normal ~40-50 damage
});
it('should handle spikes field effect', () => {
const spikesUser: PicletDefinition = {
name: "Spikes User",
description: "Sets entry hazards",
tier: 'medium',
primaryType: PicletType.MINERAL,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Impish",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Spikes",
type: AttackType.MINERAL,
power: 0,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [
{
type: 'fieldEffect',
effect: 'spikes',
target: 'opponentSide',
stackable: true
}
]
}
]
};
const opponent: PicletDefinition = {
name: "Opponent",
description: "Standard opponent",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 70 },
nature: "Hardy",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Tackle",
type: AttackType.NORMAL,
power: 40,
accuracy: 100,
pp: 10,
priority: 0,
flags: ['contact'],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(spikesUser, opponent);
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
expect(engine.getLog().some(msg => msg.includes('Spikes') && msg.includes('set'))).toBe(true);
// TODO: Test spikes damage when switching (requires switching mechanics)
});
});
describe('counter Effects', () => {
it('should counter physical attacks', () => {
const counterUser: PicletDefinition = {
name: "Counter Fighter",
description: "Counters physical attacks",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 100, attack: 60, defense: 80, speed: 50 },
nature: "Brave",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Counter",
type: AttackType.BEAST,
power: 0,
accuracy: 100,
pp: 10,
priority: 1, // High priority to set up counter before opponent attacks
flags: ['lowPriority'],
effects: [
{
type: 'counter',
strength: 'strong'
}
]
}
]
};
const opponent: PicletDefinition = {
name: "Physical Attacker",
description: "Uses physical moves",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 80, defense: 60, speed: 70 },
nature: "Adamant",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Physical Strike",
type: AttackType.BEAST,
power: 80,
accuracy: 100,
pp: 10,
priority: 0,
flags: ['contact'],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(counterUser, opponent);
const initialOpponentHp = engine.getState().opponentPiclet.currentHp;
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
const finalOpponentHp = engine.getState().opponentPiclet.currentHp;
expect(finalOpponentHp).toBeLessThan(initialOpponentHp);
expect(engine.getLog().some(msg => msg.includes('countered') || msg.includes('Counter'))).toBe(true);
});
});
describe('priority Effects', () => {
it('should modify move priority conditionally', () => {
const priorityUser: PicletDefinition = {
name: "Priority User",
description: "Uses priority moves based on conditions",
tier: 'medium',
primaryType: PicletType.SPACE,
baseStats: { hp: 60, attack: 70, defense: 50, speed: 40 },
nature: "Quiet",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Desperation Strike",
type: AttackType.SPACE,
power: 60,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [
{
type: 'damage',
target: 'opponent',
amount: 'normal'
},
{
type: 'priority',
target: 'self',
value: 1,
condition: 'ifLowHp'
}
]
}
]
};
const fastOpponent: PicletDefinition = {
name: "Fast Opponent",
description: "Very fast opponent",
tier: 'medium',
primaryType: PicletType.BEAST,
baseStats: { hp: 80, attack: 60, defense: 60, speed: 100 },
nature: "Timid",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Quick Attack",
type: AttackType.NORMAL,
power: 40,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
}
]
};
const engine = new BattleEngine(priorityUser, fastOpponent);
// Damage the priority user to trigger low HP condition
engine['state'].playerPiclet.currentHp = Math.floor(engine['state'].playerPiclet.maxHp * 0.2);
engine.executeActions(
{ type: 'move', piclet: 'player', moveIndex: 0 },
{ type: 'move', piclet: 'opponent', moveIndex: 0 }
);
const log = engine.getLog();
const playerMoveIndex = log.findIndex(msg => msg.includes('Priority User used Desperation Strike'));
const opponentMoveIndex = log.findIndex(msg => msg.includes('Fast Opponent used Quick Attack'));
// When at low HP, priority user should go first despite lower speed
expect(playerMoveIndex).toBeLessThan(opponentMoveIndex);
});
});
describe('removeStatus Effects', () => {
it('should remove status effects from target', () => {
// Simple test: create a move that only removes poison status
const cleanser: PicletDefinition = {
name: "Cleanser",
description: "Can remove poison",
tier: 'medium',
primaryType: PicletType.FLORA,
baseStats: { hp: 100, attack: 50, defense: 50, speed: 50 },
nature: "Calm",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Cleanse",
type: AttackType.FLORA,
power: 0,
accuracy: 100,
pp: 10,
priority: 0,
flags: [],
effects: [
{
type: 'removeStatus',
target: 'self',
status: 'poison'
}
]
}
]
};
const dummy: PicletDefinition = {
name: "Dummy",
description: "Does nothing",
tier: 'low',
primaryType: PicletType.BEAST,
baseStats: { hp: 50, attack: 30, defense: 30, speed: 30 },
nature: "Docile",
specialAbility: { name: "No Ability", description: "" },
movepool: [
{
name: "Do Nothing",
type: AttackType.NORMAL,
power: 0,
accuracy: 100,
pp: 20,
priority: 0,
flags: [],
effects: []
}
]
};
const engine = new BattleEngine(cleanser, dummy);
const playerPiclet = engine.getState().playerPiclet;
// Test the removeStatus effect by directly calling it
// This bypasses any turn/timing issues
const mockEffect = { status: 'poison' };
// First add poison manually
playerPiclet.statusEffects.push('poison');
expect(playerPiclet.statusEffects.includes('poison')).toBe(true);
// Call the removeStatus effect processor directly
engine['processRemoveStatusEffect'](mockEffect, playerPiclet);
// Check if poison was removed
expect(playerPiclet.statusEffects.includes('poison')).toBe(false);
});
});
}); |