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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/**
 * Tests for mechanic override system from the design document
 * Tests special abilities that modify core battle mechanics
 */

import { describe, it, expect, beforeEach } from 'vitest';
import { BattleEngine } from './BattleEngine';
import { PicletDefinition, Move, SpecialAbility } from './types';
import { PicletType, AttackType } from './types';

const STANDARD_STATS = { hp: 100, attack: 80, defense: 70, speed: 60 };

describe('Mechanic Override System - TDD Implementation', () => {
  describe('Critical Hit Mechanics', () => {
    it('should handle Shell Armor - cannot be critically hit', () => {
      const shellArmor: SpecialAbility = {
        name: "Shell Armor",
        description: "Hard shell prevents critical hits",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'criticalHits',
            condition: 'always',
            value: false
          }
        ]
      };

      const shellPiclet: PicletDefinition = {
        name: "Shell Defender",
        description: "Protected by a hard shell",
        tier: 'medium',
        primaryType: PicletType.MINERAL,
        baseStats: STANDARD_STATS,
        nature: "Bold",
        specialAbility: shellArmor,
        movepool: [{
          name: "Tackle", type: AttackType.NORMAL, power: 40, accuracy: 100, pp: 35,
          priority: 0, flags: [], effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
        }]
      };

      // Test would verify this Piclet cannot be critically hit
      expect(shellArmor.effects![0].mechanic).toBe('criticalHits');
      expect(shellArmor.effects![0].value).toBe(false);
    });

    it('should handle Super Luck - always critical hits', () => {
      const superLuck: SpecialAbility = {
        name: "Super Luck",
        description: "Extremely lucky, always lands critical hits",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'criticalHits',
            condition: 'always',
            value: true
          }
        ]
      };

      expect(superLuck.effects![0].value).toBe(true);
    });

    it('should handle Scope Lens - double critical hit rate', () => {
      const scopeLens: SpecialAbility = {
        name: "Scope Lens",
        description: "Enhanced precision doubles critical hit rate",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'criticalHits',
            condition: 'always',
            value: 'double'
          }
        ]
      };

      expect(scopeLens.effects![0].value).toBe('double');
    });
  });

  describe('Status Immunity', () => {
    it('should handle Insomnia - sleep immunity', () => {
      const insomnia: SpecialAbility = {
        name: "Insomnia",
        description: "Prevents sleep status",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'statusImmunity',
            value: ['sleep']
          }
        ]
      };

      const insomniaPiclet: PicletDefinition = {
        name: "Sleepless Guardian",
        description: "Never sleeps",
        tier: 'medium',
        primaryType: PicletType.CULTURE,
        baseStats: STANDARD_STATS,
        nature: "Alert",
        specialAbility: insomnia,
        movepool: [{
          name: "Tackle", type: AttackType.NORMAL, power: 40, accuracy: 100, pp: 35,
          priority: 0, flags: [], effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
        }]
      };

      expect(insomnia.effects![0].value).toContain('sleep');
    });

    it('should handle multi-status immunity', () => {
      const immunity: SpecialAbility = {
        name: "Pure Body",
        description: "Immune to poison and burn",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'statusImmunity',
            value: ['poison', 'burn']
          }
        ]
      };

      expect(immunity.effects![0].value).toEqual(['poison', 'burn']);
    });
  });

  describe('Damage Reflection', () => {
    it('should handle Rough Skin - contact damage reflection', () => {
      const roughSkin: SpecialAbility = {
        name: "Rough Skin",
        description: "Rough skin damages attackers on contact",
        triggers: [
          {
            event: 'onContactDamage',
            effects: [
              {
                type: 'damage',
                target: 'attacker',
                formula: 'fixed',
                value: 12
              }
            ]
          }
        ]
      };

      const roughPiclet: PicletDefinition = {
        name: "Spike Beast",
        description: "Covered in rough spikes",
        tier: 'medium',
        primaryType: PicletType.MINERAL,
        baseStats: STANDARD_STATS,
        nature: "Hardy",
        specialAbility: roughSkin,
        movepool: [{
          name: "Tackle", type: AttackType.NORMAL, power: 40, accuracy: 100, pp: 35,
          priority: 0, flags: [], effects: [{ type: 'damage', target: 'opponent', amount: 'normal' }]
        }]
      };

      expect(roughSkin.triggers![0].event).toBe('onContactDamage');
      expect(roughSkin.triggers![0].effects[0].target).toBe('attacker');
    });

    it('should handle damage reflection percentage', () => {
      const reflectArmor: SpecialAbility = {
        name: "Mirror Armor",
        description: "Reflects 50% of damage back",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'damageReflection',
            value: 0.5
          }
        ]
      };

      expect(reflectArmor.effects![0].value).toBe(0.5);
    });
  });

  describe('Type Mechanics', () => {
    it('should handle Wonder Guard - only super-effective moves hit', () => {
      const wonderGuard: SpecialAbility = {
        name: "Wonder Guard",
        description: "Only super-effective moves deal damage",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'damageCalculation',
            condition: 'ifNotSuperEffective',
            value: false
          }
        ]
      };

      expect(wonderGuard.effects![0].mechanic).toBe('damageCalculation');
      expect(wonderGuard.effects![0].condition).toBe('ifNotSuperEffective');
    });

    it('should handle Levitate - ground type immunity', () => {
      const levitate: SpecialAbility = {
        name: "Levitate",
        description: "Floating ability makes ground moves miss",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'typeImmunity',
            value: ['ground']
          }
        ]
      };

      expect(levitate.effects![0].value).toContain('ground');
    });

    it('should handle Protean - type changes to match move', () => {
      const protean: SpecialAbility = {
        name: "Protean",
        description: "Changes type to match the move being used",
        triggers: [
          {
            event: 'beforeMoveUse',
            effects: [
              {
                type: 'mechanicOverride',  
                mechanic: 'typeChange',
                value: 'matchMoveType'
              }
            ]
          }
        ]
      };

      expect(protean.triggers![0].event).toBe('beforeMoveUse');
      expect(protean.triggers![0].effects[0].value).toBe('matchMoveType');
    });
  });

  describe('Healing Mechanics', () => {
    it('should handle Poison Heal - poison heals instead of damages', () => {
      const poisonHeal: SpecialAbility = {
        name: "Poison Heal",
        description: "Poison heals instead of damages",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'healingInversion',
            value: 'invert'
          }
        ]
      };

      expect(poisonHeal.effects![0].mechanic).toBe('healingInversion');
      expect(poisonHeal.effects![0].value).toBe('invert');
    });

    it('should handle healing blocked', () => {
      const healBlock: SpecialAbility = {
        name: "Cursed Body",
        description: "Cannot be healed by any means",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'healingBlocked',
            value: true
          }
        ]
      };

      expect(healBlock.effects![0].value).toBe(true);
    });
  });

  describe('Damage Absorption', () => {
    it('should handle Photosynthesis - absorbs flora moves', () => {
      const photosynthesis: SpecialAbility = {
        name: "Photosynthesis",
        description: "Absorbs flora-type moves to restore HP",
        triggers: [
          {
            event: 'onDamageTaken',
            condition: 'ifMoveType:flora',
            effects: [
              {
                type: 'mechanicOverride',
                mechanic: 'damageAbsorption',
                value: 'absorb'
              },
              {
                type: 'heal',
                target: 'self',
                formula: 'percentage',
                value: 25
              }
            ]
          }
        ]
      };

      expect(photosynthesis.triggers![0].condition).toBe('ifMoveType:flora');
      expect(photosynthesis.triggers![0].effects[0].mechanic).toBe('damageAbsorption');
    });
  });

  describe('Stat Modification Mechanics', () => {
    it('should handle Contrary - stat changes are reversed', () => {
      const contrary: SpecialAbility = {
        name: "Contrary",
        description: "Stat changes have the opposite effect",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'statModification',
            value: 'invert'
          }
        ]
      };

      expect(contrary.effects![0].value).toBe('invert');
    });
  });

  describe('Flag-Based Immunities', () => {
    it('should handle Sky Dancer - immune to ground-flagged attacks', () => {
      const skyDancer: SpecialAbility = {
        name: "Sky Dancer",
        description: "Floating in air, immune to ground-based attacks",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'flagImmunity',
            value: ['ground']
          }
        ]
      };

      expect(skyDancer.effects![0].value).toContain('ground');
    });

    it('should handle Sound Barrier - immune to sound attacks', () => {
      const soundBarrier: SpecialAbility = {
        name: "Sound Barrier",
        description: "Natural sound dampening prevents sound-based moves",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'flagImmunity',
            value: ['sound']
          }
        ]
      };

      expect(soundBarrier.effects![0].value).toContain('sound');
    });

    it('should handle Soft Body - immune to explosive, weak to punch', () => {
      const softBody: SpecialAbility = {
        name: "Soft Body",
        description: "Gelatinous form absorbs explosions but vulnerable to direct hits",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'flagImmunity',
            value: ['explosive']
          },
          {
            type: 'mechanicOverride',
            mechanic: 'flagWeakness',
            value: ['punch']
          }
        ]
      };

      expect(softBody.effects![0].value).toContain('explosive');
      expect(softBody.effects![1].value).toContain('punch');
    });

    it('should handle flag resistance', () => {
      const thickHide: SpecialAbility = {
        name: "Thick Hide",
        description: "Tough skin reduces impact from physical contact",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'flagResistance',
            value: ['contact']
          }
        ]
      };

      expect(thickHide.effects![0].value).toContain('contact');
    });
  });

  describe('Priority Override', () => {
    it('should handle Prankster - status moves get priority', () => {
      const prankster: SpecialAbility = {
        name: "Prankster",
        description: "Status moves gain priority",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'priorityOverride',
            condition: 'ifStatusMove',
            value: 1
          }
        ]
      };

      expect(prankster.effects![0].condition).toBe('ifStatusMove');
      expect(prankster.effects![0].value).toBe(1);
    });
  });

  describe('Drain Inversion', () => {
    it('should handle Vampiric - drain moves damage the drainer', () => {
      const vampiric: SpecialAbility = {
        name: "Vampiric",
        description: "Cursed blood damages those who try to drain it",
        triggers: [
          {
            event: 'onHPDrained',
            effects: [
              {
                type: 'mechanicOverride',
                mechanic: 'drainInversion',
                value: true
              },
              {
                type: 'damage',
                target: 'attacker',
                formula: 'fixed',
                value: 20
              }
            ]
          }
        ]
      };

      expect(vampiric.triggers![0].event).toBe('onHPDrained');
      expect(vampiric.triggers![0].effects[0].mechanic).toBe('drainInversion');
    });
  });

  describe('Target Redirection', () => {
    it('should handle Magic Bounce - reflects status moves', () => {
      const magicBounce: SpecialAbility = {
        name: "Magic Bounce",
        description: "Reflects status moves back at the user",
        triggers: [
          {
            event: 'onStatusMoveTargeted',
            effects: [
              {
                type: 'mechanicOverride',
                mechanic: 'targetRedirection',
                value: 'reflect'
              }
            ]
          }
        ]
      };

      expect(magicBounce.triggers![0].event).toBe('onStatusMoveTargeted');
      expect(magicBounce.triggers![0].effects[0].value).toBe('reflect');
    });
  });

  describe('Status Replacement', () => {
    it('should handle Frost Walker - freeze becomes attack boost', () => {
      const frostWalker: SpecialAbility = {
        name: "Frost Walker",
        description: "Instead of being frozen, gains +50% attack",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'statusReplacement',
            value: {
              status: 'freeze',
              replacement: {
                type: 'modifyStats',
                target: 'self',
                stats: { attack: 'greatly_increase' }
              }
            }
          }
        ]
      };

      expect(frostWalker.effects![0].mechanic).toBe('statusReplacement');
      expect(frostWalker.effects![0].value.status).toBe('freeze');
    });
  });

  describe('Damage Multiplier', () => {
    it('should handle damage multiplication abilities', () => {
      const damageBoost: SpecialAbility = {
        name: "Rage Mode",
        description: "All damage dealt is doubled when at low HP",
        effects: [
          {
            type: 'mechanicOverride',
            mechanic: 'damageMultiplier',
            condition: 'ifLowHp',
            value: 2.0
          }
        ]
      };

      expect(damageBoost.effects![0].value).toBe(2.0);
      expect(damageBoost.effects![0].condition).toBe('ifLowHp');
    });
  });

  describe('Extra Turn Mechanics', () => {
    it('should handle extra turn abilities', () => {
      const extraTurn: SpecialAbility = {
        name: "Time Distortion",
        description: "Gets an extra turn when switching in",
        triggers: [
          {
            event: 'onSwitchIn',
            effects: [
              {
                type: 'mechanicOverride',
                mechanic: 'extraTurn',
                value: true,
                condition: 'nextTurn'
              }
            ]
          }
        ]
      };

      expect(extraTurn.triggers![0].effects[0].mechanic).toBe('extraTurn');
      expect(extraTurn.triggers![0].effects[0].condition).toBe('nextTurn');
    });
  });
});