gotchi-battler-game-logic 4.0.1 → 4.0.2

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.
@@ -449,32 +449,25 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
449
449
  // Handle the effect
450
450
  const specialEffectResults = handleSpecialEffects(attackingTeam, attackingGotchi, target, specialEffect, rng)
451
451
 
452
- if (specialEffectResults) {
453
- if (specialEffectResults.actionEffect) {
454
- if (targetActionEffect) {
455
- // If target is same as the actionEffect then just add statuses to the actionEffect
456
- if (targetActionEffect.target && targetActionEffect.target === specialEffectResults.actionEffect.target) {
457
- targetActionEffect.statuses.push(...specialEffectResults.actionEffect.statuses)
458
- } else {
459
- // If not then add to additionalEffects
460
- targetAdditionalEffects.push(specialEffectResults.actionEffect)
461
- }
462
- } else {
463
- targetActionEffect = specialEffectResults.actionEffect
464
- }
452
+ // Do we already have an action effect with attack damage or healing?
453
+ if (targetActionEffect) {
454
+ // If target is same as the actionEffect then just add statuses to the actionEffect
455
+ if (targetActionEffect.target && targetActionEffect.target === specialEffectResults.actionEffect.target) {
456
+ targetActionEffect.statuses.push(...specialEffectResults.actionEffect.statuses)
457
+ } else {
458
+ // If not then add to additionalEffects
459
+ targetAdditionalEffects.push(specialEffectResults.actionEffect)
465
460
  }
461
+ } else {
462
+ targetActionEffect = specialEffectResults.actionEffect
463
+ }
466
464
 
467
- if (specialEffectResults.additionalEffects) {
468
- targetAdditionalEffects.push(...specialEffectResults.additionalEffects)
469
- }
465
+ targetAdditionalEffects.push(...specialEffectResults.additionalEffects)
470
466
 
471
- if (specialEffectResults.statusesExpired) {
472
- statusesExpired.push(...specialEffectResults.statusesExpired)
473
- }
467
+ statusesExpired.push(...specialEffectResults.statusesExpired)
474
468
 
475
- if (specialEffectResults.repeatAttack) {
476
- repeatAttack = true
477
- }
469
+ if (specialEffectResults.repeatAttack) {
470
+ repeatAttack = true
478
471
  }
479
472
  }
480
473
  })
@@ -598,22 +591,14 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
598
591
  targets.forEach((target) => {
599
592
  const specialEffectResults = handleSpecialEffects(attackingTeam, attackingGotchi, target, specialEffect, rng)
600
593
 
601
- if (specialEffectResults) {
602
- if (specialEffectResults.actionEffect) {
603
- additionalEffects.push(specialEffectResults.actionEffect)
604
- }
594
+ additionalEffects.push(specialEffectResults.actionEffect)
605
595
 
606
- if (specialEffectResults.additionalEffects) {
607
- additionalEffects.push(...specialEffectResults.additionalEffects)
608
- }
596
+ additionalEffects.push(...specialEffectResults.additionalEffects)
609
597
 
610
- if (specialEffectResults.statusesExpired) {
611
- statusesExpired.push(...specialEffectResults.statusesExpired)
612
- }
598
+ statusesExpired.push(...specialEffectResults.statusesExpired)
613
599
 
614
- if (specialEffectResults.repeatAttack) {
615
- repeatAttack = true
616
- }
600
+ if (specialEffectResults.repeatAttack) {
601
+ repeatAttack = true
617
602
  }
618
603
  })
619
604
  }
@@ -629,26 +614,35 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
629
614
  }
630
615
 
631
616
  const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEffect, rng) => {
632
- if (specialEffect.chance && specialEffect.chance < 1 && rng() > specialEffect.chance) {
633
- return false
634
- }
635
-
636
617
  const actionEffect = {
637
618
  target: target.id,
638
619
  statuses: [],
639
- outcome: 'success'
620
+ outcome: 'failed'
640
621
  }
641
-
622
+
642
623
  const additionalEffects = []
643
624
  const statusesExpired = []
644
625
  let repeatAttack = false
645
626
 
627
+ // Check for chance of the special effect
628
+ if (specialEffect.chance && specialEffect.chance < 1 && rng() > specialEffect.chance) {
629
+ return {
630
+ actionEffect,
631
+ additionalEffects,
632
+ statusesExpired,
633
+ repeatAttack
634
+ }
635
+ }
636
+
646
637
  switch (specialEffect.effectType) {
647
638
  case 'status': {
648
639
  // Focus/resistance check if target is not on the same team as the attacking gotchi
649
640
  if (focusCheck(attackingTeam, attackingGotchi, target, rng)) {
650
641
  addStatusToGotchi(target, specialEffect.status)
651
642
  actionEffect.statuses.push(specialEffect.status)
643
+ actionEffect.outcome = 'success'
644
+ } else {
645
+ actionEffect.outcome = 'resisted'
652
646
  }
653
647
  break
654
648
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gotchi-battler-game-logic",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "mocha \"tests/**/*.test.js\"",