@pkmn/engine 0.1.0-dev.89cc1c98 → 0.1.0-dev.900756a9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,17 +97,8 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
97
97
  },
98
98
  .OHKO => {
99
99
  if (!try canMove(battle, player, state, options)) return;
100
-
101
- // OHKO calls adjustDamage but only actually cares about immunity
102
- assert(move.type == .Normal or move.type == .Ground);
103
- const foe = battle.foe(player);
104
- const immune = if (move.type == .Normal)
105
- foe.active.types.includes(.Ghost) and !foe.active.volatiles.Foresight
106
- else
107
- foe.active.types.includes(.Ghost);
108
- state.effectiveness = if (immune) 0 else Effectiveness.neutral;
109
-
110
- try Effects.ohko(battle, player, state, options);
100
+ try Effects.ohko.immune(battle, player, state, options);
101
+ try Effects.ohko.damage(battle, player, state, options);
111
102
  try applyDamage(battle, player, state, options);
112
103
  try reportOutcome(battle, player, state, options);
113
104
  _ = try afterMove(!KINGS, battle, player, state, options);
@@ -118,9 +109,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
118
109
  try calcDamage(battle, player, state, options);
119
110
  try adjustDamage(battle, player, state, options);
120
111
  try randomizeDamage(battle, player, state, options);
121
-
122
- if (battle.foe(player).active.volatiles.Flying) state.damage *|= 2;
123
-
112
+ try Effects.double.flying(battle, player, state, options);
124
113
  try checkHit(battle, player, state, options);
125
114
  try applyDamage(battle, player, state, options);
126
115
  try reportOutcome(battle, player, state, options);
@@ -157,9 +146,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
157
146
  try calcDamage(battle, player, state, options);
158
147
  try adjustDamage(battle, player, state, options);
159
148
  try randomizeDamage(battle, player, state, options);
160
-
161
- if (battle.foe(player).active.volatiles.minimized) state.damage *|= 2;
162
-
149
+ try Effects.double.minimize(battle, player, state, options);
163
150
  try checkHit(battle, player, state, options);
164
151
  try effectChance(battle, player, state, options);
165
152
  try applyDamage(battle, player, state, options);
@@ -273,7 +260,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
273
260
  try Effects.hyperBeam(battle, player, state, options);
274
261
  _ = try afterMove(!KINGS, battle, player, state, options);
275
262
  },
276
- .Counter => {
263
+ .MirrorCoat, .Counter => {
277
264
  if (!try canMove(battle, player, state, options)) return;
278
265
  try Effects.counter(battle, player, state, options);
279
266
  try applyDamage(battle, player, state, options);
@@ -308,7 +295,6 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
308
295
  if (!try canMove(battle, player, state, options)) return;
309
296
  try checkCriticalHit(battle, player, state, options);
310
297
  try calcDamage(battle, player, state, options);
311
- // TODO thunderaccuracy
312
298
  try checkHit(battle, player, state, options);
313
299
  try effectChance(battle, player, state, options);
314
300
  try adjustDamage(battle, player, state, options);
@@ -324,9 +310,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
324
310
  try calcDamage(battle, player, state, options);
325
311
  try adjustDamage(battle, player, state, options);
326
312
  try randomizeDamage(battle, player, state, options);
327
-
328
- if (battle.foe(player).active.volatiles.Underground) state.damage *|= 2;
329
-
313
+ try Effects.double.underground(battle, player, state, options);
330
314
  try checkHit(battle, player, state, options);
331
315
  try effectChance(battle, player, state, options);
332
316
  try applyDamage(battle, player, state, options);
@@ -339,13 +323,10 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
339
323
  try calcDamage(battle, player, state, options);
340
324
  try adjustDamage(battle, player, state, options);
341
325
  try checkHit(battle, player, state, options);
342
-
343
- assert(volatiles.Rage);
344
- state.damage *|= (volatiles.rage +| 1);
345
-
326
+ try Effects.rage.damage(battle, player, state, options);
346
327
  try randomizeDamage(battle, player, state, options);
347
328
  // TODO failuretext
348
- try Effects.rage(battle, player, state, options);
329
+ try Effects.rage.start(battle, player, state, options);
349
330
  try applyDamage(battle, player, state, options);
350
331
  try reportOutcome(battle, player, state, options);
351
332
  _ = try afterMove(KINGS, battle, player, state, options);
@@ -363,39 +344,24 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
363
344
  if (!try canMove(battle, player, state, options)) return;
364
345
  try Effects.heal(battle, player, state, options);
365
346
  },
347
+ .LightScreen => {
348
+ if (!try canMove(battle, player, state, options)) return;
349
+ try Effects.lightScreen(battle, player, state, options);
350
+ },
366
351
  .Haze => {
367
352
  if (!try canMove(battle, player, state, options)) return;
368
353
  try Effects.haze(battle, player, state, options);
369
354
  },
370
- .LightScreen, .Reflect => {
355
+ .Reflect => {
371
356
  if (!try canMove(battle, player, state, options)) return;
372
- try Effects.screens(battle, player, state, options);
357
+ try Effects.reflect(battle, player, state, options);
373
358
  },
374
359
  .FocusEnergy => {
375
360
  if (!try canMove(battle, player, state, options)) return;
376
361
  try Effects.focusEnergy(battle, player, state, options);
377
362
  },
378
363
  .Bide => {
379
- if (!volatiles.Bide) return;
380
-
381
- assert(volatiles.attacks > 0);
382
- // if (options.calc.modify(player, .attacking)) |extend| {
383
- // if (!extend) volatiles.attacks = 0;
384
- // } else {
385
- volatiles.attacks -= 1;
386
- // }
387
- try options.chance.attacking(player, volatiles.attacks);
388
-
389
- if (volatiles.attacks != 0) return try options.log.activate(ident, .Bide);
390
-
391
- volatiles.Bide = false;
392
- try options.log.end(ident, .Bide);
393
-
394
- state.damage = volatiles.bide *% 2;
395
- volatiles.bide = 0;
396
-
397
- if (state.damage == 0) state.miss = true;
398
-
364
+ try Effects.bide.store(battle, player, state, options);
399
365
  // doturn
400
366
  const charging = false; // TODO
401
367
  const skip_pp = charging or state.move == .Struggle or
@@ -403,7 +369,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
403
369
  if (!skip_pp) _ = decrementPP(side, state.move, state.mslot); // TODO if no pp return
404
370
  // usedmovetext
405
371
  try log.move(ident, state.move, foe_ident); // FIXME self? from?
406
- // TODO unleashenergy
372
+ try Effects.bide.unleash(battle, player, state, options);
407
373
 
408
374
  if (state.immune()) {
409
375
  state.damage = 0;
@@ -522,7 +488,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
522
488
  try randomizeDamage(battle, player, state, options);
523
489
  try checkHit(battle, player, state, options);
524
490
  try effectChance(battle, player, state, options);
525
- try Effects.snore(battle, player, state, options);
491
+ if (!try Effects.snore(battle, player, state, options)) return;
526
492
  try applyDamage(battle, player, state, options);
527
493
  try reportOutcome(battle, player, state, options);
528
494
  if (!try afterMove(!KINGS, battle, player, state, options)) return;
@@ -582,7 +548,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
582
548
  try Effects.sandstorm(battle, player, state, options);
583
549
  },
584
550
  .Rollout => {
585
- // TODO checkcurl
551
+ try Effects.rollout.check(battle, player, state, options);
586
552
  // doturn
587
553
  const charging = false; // TODO
588
554
  const skip_pp = charging or state.move == .Struggle or
@@ -594,7 +560,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
594
560
  try calcDamage(battle, player, state, options);
595
561
  try adjustDamage(battle, player, state, options);
596
562
  try checkHit(battle, player, state, options);
597
- // TODO rolloutpower
563
+ try Effects.rollout.power(battle, player, state, options);
598
564
  try randomizeDamage(battle, player, state, options);
599
565
  try applyDamage(battle, player, state, options);
600
566
  try reportOutcome(battle, player, state, options);
@@ -615,12 +581,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
615
581
  .Swagger => {
616
582
  if (!try canMove(battle, player, state, options)) return;
617
583
  try checkHit(battle, player, state, options);
618
- // TODO switchturn
619
- // TODO attackup2
620
- // TODO switchturn
621
- // TODO failuretext
622
- // TODO switchturn
623
- // TODO switchturn
584
+ try Effects.boost(battle, player.foe(), state, options);
624
585
  try Effects.confusionChance(battle, player, state, options);
625
586
  },
626
587
  .FuryCutter => {
@@ -694,14 +655,12 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
694
655
  .Magnitude => {
695
656
  if (!try canMove(battle, player, state, options)) return;
696
657
  try checkCriticalHit(battle, player, state, options);
697
- // TODO getmagnitude
658
+ try Effects.magnitude(battle, player, state, options);
698
659
  try calcDamage(battle, player, state, options);
699
660
  try adjustDamage(battle, player, state, options);
700
661
  try randomizeDamage(battle, player, state, options);
701
662
  try checkHit(battle, player, state, options);
702
-
703
- if (battle.foe(player).active.volatiles.Underground) state.damage *|= 2;
704
-
663
+ try Effects.double.underground(battle, player, state, options);
705
664
  try applyDamage(battle, player, state, options);
706
665
  try reportOutcome(battle, player, state, options);
707
666
  _ = try afterMove(KINGS, battle, player, state, options);
@@ -755,9 +714,7 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
755
714
  try calcDamage(battle, player, state, options);
756
715
  try adjustDamage(battle, player, state, options);
757
716
  try randomizeDamage(battle, player, state, options);
758
-
759
- if (battle.foe(player).active.volatiles.Flying) state.damage *|= 2;
760
-
717
+ try Effects.double.flying(battle, player, state, options);
761
718
  try checkHit(battle, player, state, options);
762
719
  try effectChance(battle, player, state, options);
763
720
  try applyDamage(battle, player, state, options);
@@ -773,12 +730,6 @@ pub fn runMove(battle: anytype, player: Player, state: *State, options: anytype)
773
730
  if (!try canMove(battle, player, state, options)) return;
774
731
  try Effects.sunnyDay(battle, player, state, options);
775
732
  },
776
- .MirrorCoat => {
777
- if (!try canMove(battle, player, state, options)) return;
778
- try Effects.mirrorCoat(battle, player, state, options);
779
- try applyDamage(battle, player, state, options);
780
- _ = try afterMove(KINGS, battle, player, state, options);
781
- },
782
733
  .PsychUp => {
783
734
  if (!try canMove(battle, player, state, options)) return;
784
735
  try Effects.psychUp(battle, player, state, options);