File size: 12,914 Bytes
7b95878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01d657e
7b95878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01d657e
7b95878
01d657e
7b95878
 
 
01d657e
 
7b95878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01d657e
 
7b95878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01d657e
7b95878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01d657e
 
 
 
7b95878
 
 
 
01d657e
7b95878
 
01d657e
 
 
 
 
 
 
7b95878
 
 
 
01d657e
 
 
 
 
 
7b95878
01d657e
 
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
import { describe, it, expect, beforeEach } from 'vitest';
import { BattleEngine } from './BattleEngine';
import type { PicletDefinition } from './types';
import { PicletType, AttackType } from './types';

describe('Extreme Risk-Reward Moves', () => {
  describe('Self-Destruct Moves', () => {
    it('should deal massive damage to all but KO the user', () => {
      const bomber: PicletDefinition = {
        name: "Suicide Bomber",
        description: "Sacrifices itself for massive damage",
        tier: 'medium',
        primaryType: PicletType.MACHINA,
        baseStats: { hp: 60, attack: 40, defense: 60, speed: 50 },
        nature: "Brave",
        specialAbility: { name: "No Ability", description: "" },
        movepool: [
          {
            name: "Self Destruct",
            type: AttackType.MACHINA,
            power: 200,
            accuracy: 100,
            pp: 1,
            priority: 0,
            flags: ['explosive', 'contact'],
            effects: [
              {
                type: 'damage',
                target: 'all',
                formula: 'standard',
                multiplier: 1.5
              },
              {
                type: 'damage',
                target: 'self',
                formula: 'fixed',
                value: 9999,
                condition: 'afterUse'
              }
            ]
          }
        ]
      };

      const opponent: PicletDefinition = {
        name: "Sturdy Opponent",
        description: "Tanky opponent",
        tier: 'high',
        primaryType: PicletType.MINERAL,
        baseStats: { hp: 100, attack: 60, defense: 100, speed: 40 },
        nature: "Impish",
        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(bomber, opponent);
      const initialOpponentHp = engine.getState().opponentPiclet.currentHp;
      
      engine.executeActions(
        { type: 'move', piclet: 'player', moveIndex: 0 }, // Self Destruct
        { type: 'move', piclet: 'opponent', moveIndex: 0 }
      );

      const finalOpponentHp = engine.getState().opponentPiclet.currentHp;
      const playerHp = engine.getState().playerPiclet.currentHp;
      
      // User should be KO'd
      expect(playerHp).toBe(0);
      
      // Opponent should take massive damage
      expect(finalOpponentHp).toBeLessThan(initialOpponentHp);
      const damage = initialOpponentHp - finalOpponentHp;
      expect(damage).toBeGreaterThan(45); // Should be very high damage for a self-destruct move
      
      const log = engine.getLog();
      expect(log.some(msg => msg.includes('Self Destruct') || msg.includes('exploded'))).toBe(true);
      expect(engine.isGameOver()).toBe(true);
    });
  });

  describe('Gambling Moves', () => {
    it('should have random success/failure outcomes', () => {
      const gambler: PicletDefinition = {
        name: "Lucky Gambler",
        description: "Relies on luck for power",
        tier: 'medium',
        primaryType: PicletType.CULTURE,
        baseStats: { hp: 70, attack: 60, defense: 60, speed: 80 },
        nature: "Hasty",
        specialAbility: { name: "No Ability", description: "" },
        movepool: [
          {
            name: "Cursed Gambit",
            type: AttackType.CULTURE,
            power: 0,
            accuracy: 100,
            pp: 1,
            priority: 0,
            flags: ['gambling', 'cursed'],
            effects: [
              {
                type: 'heal',
                target: 'self',
                amount: 'percentage',
                value: 100,
                condition: 'ifLucky50'
              },
              {
                type: 'damage',
                target: 'self',
                formula: 'fixed',
                value: 9999,
                condition: 'ifUnlucky50'
              }
            ]
          }
        ]
      };

      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: "Do Nothing",
            type: AttackType.NORMAL,
            power: 0,
            accuracy: 100,
            pp: 10,
            priority: 0,
            flags: [],
            effects: [] // No effects - just waste a turn
          }
        ]
      };

      // Test multiple times to check for randomness
      let healedCount = 0;
      let faintedCount = 0;
      
      for (let i = 0; i < 20; i++) {
        const engine = new BattleEngine(gambler, opponent);
        // Damage the gambler first
        engine['state'].playerPiclet.currentHp = Math.floor(engine['state'].playerPiclet.maxHp * 0.5);
        const preGambitHp = engine.getState().playerPiclet.currentHp;
        
        engine.executeActions(
          { type: 'move', piclet: 'player', moveIndex: 0 },
          { type: 'move', piclet: 'opponent', moveIndex: 0 }
        );

        const postGambitHp = engine.getState().playerPiclet.currentHp;
        const maxHp = engine.getState().playerPiclet.maxHp;
        
        
        if (postGambitHp === 0) {
          faintedCount++;
        } else if (postGambitHp > preGambitHp) {
          healedCount++;
        }
      }
      
      // Should have some of each outcome (allowing for randomness)
      expect(healedCount + faintedCount).toBeGreaterThan(0);
      expect(healedCount).toBeGreaterThan(0);
      expect(faintedCount).toBeGreaterThan(0);
    });
  });

  describe('Sacrifice Moves', () => {
    it('should provide powerful effects at great personal cost', () => {
      const sacrificer: PicletDefinition = {
        name: "Blood Warrior",
        description: "Sacrifices HP for power",
        tier: 'medium',
        primaryType: PicletType.BEAST,
        baseStats: { hp: 100, attack: 70, defense: 60, speed: 60 },
        nature: "Brave",
        specialAbility: { name: "No Ability", description: "" },
        movepool: [
          {
            name: "Blood Pact",
            type: AttackType.BEAST,
            power: 0,
            accuracy: 100,
            pp: 3,
            priority: 0,
            flags: ['sacrifice'],
            effects: [
              {
                type: 'damage',
                target: 'self',
                formula: 'percentage',
                value: 50
              },
              {
                type: 'mechanicOverride',
                target: 'self',
                mechanic: 'damageMultiplier',
                value: 2.0,
                condition: 'restOfBattle'
              }
            ]
          },
          {
            name: "Strike",
            type: AttackType.BEAST,
            power: 60,
            accuracy: 100,
            pp: 10,
            priority: 0,
            flags: ['contact'],
            effects: [
              {
                type: 'damage',
                target: 'opponent',
                amount: 'normal'
              }
            ]
          }
        ]
      };

      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(sacrificer, opponent);
      const initialHp = engine.getState().playerPiclet.currentHp;
      
      // Use Blood Pact
      engine.executeActions(
        { type: 'move', piclet: 'player', moveIndex: 0 }, // Blood Pact
        { type: 'move', piclet: 'opponent', moveIndex: 0 }
      );

      const hpAfterSacrifice = engine.getState().playerPiclet.currentHp;
      expect(hpAfterSacrifice).toBeLessThan(initialHp);
      
      // Now attack should do double damage
      const initialOpponentHp = engine.getState().opponentPiclet.currentHp;
      engine.executeActions(
        { type: 'move', piclet: 'player', moveIndex: 1 }, // Strike (should be doubled)
        { type: 'move', piclet: 'opponent', moveIndex: 0 }
      );

      const finalOpponentHp = engine.getState().opponentPiclet.currentHp;
      const damage = initialOpponentHp - finalOpponentHp;
      
      // Should do significantly more damage than normal (doubled)
      expect(damage).toBeGreaterThan(60); // Normal would be ~30-40
      
      const log = engine.getLog();
      expect(log.some(msg => msg.includes('Blood Pact') || msg.includes('sacrifice'))).toBe(true);
    });
  });

  describe('Conditional Power Scaling', () => {
    it('should scale damage based on conditions', () => {
      const revengeUser: PicletDefinition = {
        name: "Revenge Fighter",
        description: "Gets stronger when damaged",
        tier: 'medium',
        primaryType: PicletType.BEAST,
        baseStats: { hp: 90, attack: 70, defense: 80, speed: 50 },
        nature: "Brave",
        specialAbility: { name: "No Ability", description: "" },
        movepool: [
          {
            name: "Revenge Strike",
            type: AttackType.BEAST,
            power: 60,
            accuracy: 100,
            pp: 10,
            priority: 0,
            flags: ['contact'],
            effects: [
              {
                type: 'damage',
                target: 'opponent',
                amount: 'normal'
              },
              {
                type: 'damage',
                target: 'opponent',
                amount: 'strong',
                condition: 'ifDamagedThisTurn'
              }
            ]
          }
        ]
      };

      const attacker: PicletDefinition = {
        name: "Fast Attacker",
        description: "Quick attacker",
        tier: 'medium',
        primaryType: PicletType.BEAST,
        baseStats: { hp: 200, attack: 80, defense: 60, speed: 100 },
        nature: "Hasty",
        specialAbility: { name: "No Ability", description: "" },
        movepool: [
          {
            name: "Quick Strike",
            type: AttackType.BEAST,
            power: 50,
            accuracy: 100,
            pp: 10,
            priority: 1,
            flags: ['contact', 'priority'],
            effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
          }
        ]
      };

      // First test: revenge without being damaged first (revenge user at full HP)
      const engine1 = new BattleEngine(revengeUser, attacker);
      const initialOpponentHp = engine1.getState().opponentPiclet.currentHp;
      engine1.executeActions(
        { type: 'move', piclet: 'player', moveIndex: 0 },
        { type: 'move', piclet: 'opponent', moveIndex: 0 }
      );

      const hpAfterNormalRevenge = engine1.getState().opponentPiclet.currentHp;
      const normalRevengeDamage = initialOpponentHp - hpAfterNormalRevenge;
      
      // Second test: revenge when damaged (revenge user starts damaged)
      const engine2 = new BattleEngine(revengeUser, attacker);
      // Damage the revenge user to trigger the condition
      engine2['state'].playerPiclet.currentHp = Math.floor(engine2['state'].playerPiclet.maxHp * 0.5);
      
      const initialOpponentHp2 = engine2.getState().opponentPiclet.currentHp;
      engine2.executeActions(
        { type: 'move', piclet: 'player', moveIndex: 0 },
        { type: 'move', piclet: 'opponent', moveIndex: 0 }
      );

      const hpAfterPoweredRevenge = engine2.getState().opponentPiclet.currentHp;
      const poweredRevengeDamage = initialOpponentHp2 - hpAfterPoweredRevenge;
      
      // Verify that the conditional effect triggered by checking for multiple damage instances
      const damageMessages = engine2.getLog().filter(msg => msg.includes('took') && msg.includes('damage'));
      expect(damageMessages.length).toBeGreaterThanOrEqual(3); // Attacker hits revenge user, then revenge user hits back twice
      
      // Verify the powered revenge did more damage overall
      expect(poweredRevengeDamage).toBeGreaterThan(100); // Should be significant damage from both effects
    });
  });
});