File size: 3,343 Bytes
e78d70c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { describe, it, expect } from 'vitest';
import { BattleEngine } from './BattleEngine';
import type { PicletDefinition } from './types';
import { PicletType, AttackType } from './types';

describe('Debug Field Effects', () => {
  it('should debug field effect creation and damage calculation', () => {
    const fieldUser: PicletDefinition = {
      name: "Field User",
      description: "Creates field effects",
      tier: 'medium',
      primaryType: PicletType.BEAST, // Changed to BEAST so opponent can damage it
      baseStats: { hp: 100, attack: 60, defense: 80, speed: 60 },
      nature: "Calm",
      specialAbility: { name: "No Ability", description: "" },
      movepool: [
        {
          name: "Contact Barrier",
          type: AttackType.SPACE,
          power: 0,
          accuracy: 100,
          pp: 10,
          priority: 0,
          flags: [],
          effects: [
            {
              type: 'fieldEffect',
              effect: 'reflect',
              target: 'playerSide',
              stackable: false
            }
          ]
        }
      ]
    };

    const attacker: PicletDefinition = {
      name: "Contact Attacker",
      description: "Uses contact 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: 60,
          accuracy: 100,
          pp: 15,
          priority: 0,
          flags: ['contact'],
          effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
        }
      ]
    };

    const engine = new BattleEngine(fieldUser, attacker);
    
    console.log('Initial state:', {
      playerHp: engine.getState().playerPiclet.currentHp,
      opponentHp: engine.getState().opponentPiclet.currentHp,
      fieldEffects: engine.getState().fieldEffects
    });

    // First turn: create barrier and get attacked
    engine.executeActions(
      { type: 'move', piclet: 'player', moveIndex: 0 }, // Contact Barrier
      { type: 'move', piclet: 'opponent', moveIndex: 0 }  // Physical Strike
    );

    console.log('After first turn:', {
      playerHp: engine.getState().playerPiclet.currentHp,
      opponentHp: engine.getState().opponentPiclet.currentHp,
      fieldEffects: engine.getState().fieldEffects,
      log: engine.getLog()
    });

    // Second turn: opponent attacks again (should be reduced)
    const hpBeforeSecondAttack = engine.getState().playerPiclet.currentHp;
    
    engine.executeActions(
      { type: 'move', piclet: 'player', moveIndex: 0 }, // Contact Barrier (no effect)
      { type: 'move', piclet: 'opponent', moveIndex: 0 }  // Physical Strike (should be reduced)
    );

    const hpAfterSecondAttack = engine.getState().playerPiclet.currentHp;
    const damage = hpBeforeSecondAttack - hpAfterSecondAttack;

    console.log('After second turn:', {
      playerHp: hpAfterSecondAttack,
      damage: damage,
      fieldEffects: engine.getState().fieldEffects,
      log: engine.getLog()
    });

    expect(engine.getState().fieldEffects.length).toBeGreaterThan(0);
    expect(damage).toBeGreaterThan(0); // Some damage should occur
  });
});