gotchi-battler-game-logic 4.0.5 → 4.0.7

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.
@@ -75,7 +75,7 @@ const gameLoop = (team1, team2, seed, options = { debug: false, type: 'training'
75
75
  while (getAlive(team1).length && getAlive(team2).length) {
76
76
  // Check if turnCounter is ready for environment effects (99,149,199, etc)
77
77
  let isEnvironmentTurn = [
78
- 99, 149, 199, 249, 299, 349, 399, 449, 499,
78
+ 99, 149, 199, 249, 299, 349, 399, 449, 499,
79
79
  549, 599, 649, 699, 749, 799, 849, 899, 949, 999].includes(turnCounter)
80
80
  if (isEnvironmentTurn) {
81
81
  allAliveGotchis.forEach(x => {
@@ -119,7 +119,7 @@ const gameLoop = (team1, team2, seed, options = { debug: false, type: 'training'
119
119
  team1: getTeamStats(team1),
120
120
  team2: getTeamStats(team2)
121
121
  }
122
-
122
+
123
123
  logs.result.winner = getAlive(team1).length ? 1 : 2
124
124
  logs.result.winningTeam = logs.result.winner === 1 ? getTeamGotchis(team1) : getTeamGotchis(team2)
125
125
  logs.result.winningTeam = logs.result.winningTeam.map((gotchi) => {
@@ -191,7 +191,7 @@ const executeTurn = (team1, team2, rng) => {
191
191
  // Execute special attack
192
192
  actionName = attackingGotchi.specialExpanded.code
193
193
  const specialResults = attack(attackingGotchi, attackingTeam, defendingTeam, rng, true)
194
-
194
+
195
195
  actionEffects = specialResults.actionEffects
196
196
  additionalEffects = specialResults.additionalEffects
197
197
  statusesExpired = specialResults.statusesExpired
@@ -201,7 +201,7 @@ const executeTurn = (team1, team2, rng) => {
201
201
  repeatAttack = true
202
202
  } else {
203
203
  // Reset specialBar
204
- attackingGotchi.specialBar = Math.round((100/6) * (6 - attackingGotchi.specialExpanded.cooldown))
204
+ attackingGotchi.specialBar = Math.round((100 / 6) * (6 - attackingGotchi.specialExpanded.cooldown))
205
205
  }
206
206
  } else {
207
207
  // Do an auto attack
@@ -212,7 +212,7 @@ const executeTurn = (team1, team2, rng) => {
212
212
  statusesExpired = attackResults.statusesExpired
213
213
 
214
214
  // Increase specialBar by 1/6th
215
- attackingGotchi.specialBar = Math.round(attackingGotchi.specialBar + (100/6))
215
+ attackingGotchi.specialBar = Math.round(attackingGotchi.specialBar + (100 / 6))
216
216
  if (attackingGotchi.specialBar > 100) attackingGotchi.specialBar = 100
217
217
  }
218
218
 
@@ -377,13 +377,23 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
377
377
  const targetCode = isSpecial ? attackingGotchi.specialExpanded.target : 'enemy_random'
378
378
  const targets = getTargetsFromCode(targetCode, attackingGotchi, attackingTeam, defendingTeam, rng)
379
379
 
380
- let actionMultipler = isSpecial ? attackingGotchi.specialExpanded.actionMultiplier : 1
380
+ const actionMultipler = isSpecial ? attackingGotchi.specialExpanded.actionMultiplier : 1
381
+
382
+ const specialEffects = isSpecial ? (attackingGotchi.specialExpanded.effects || []) : []
381
383
 
382
384
  const actionEffects = []
383
385
  const additionalEffects = []
384
386
  const statusesExpired = []
387
+
388
+ // repeat_attack is a meta-effect: roll once per special use (not once per target)
389
+ const repeatAttackEffect = isSpecial ? specialEffects.find(e => e.effectType === 'repeat_attack') : null
390
+ const nonRepeatSpecialEffects = isSpecial ? specialEffects.filter(e => e.effectType !== 'repeat_attack') : []
391
+
385
392
  let repeatAttack = false
386
-
393
+ if (isSpecial && repeatAttackEffect) {
394
+ repeatAttack = rng() <= repeatAttackEffect.chance
395
+ }
396
+
387
397
  targets.forEach((target) => {
388
398
  // The effect for the main action of the attack
389
399
  let targetActionEffect
@@ -391,13 +401,14 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
391
401
  // For an additional effects that come for the special attack e.g. heals
392
402
  const targetAdditionalEffects = []
393
403
 
404
+ // Roll for crit multiplier
405
+ const critMultiplier = getCritMultiplier(attackingGotchi, rng)
406
+ const isCrit = critMultiplier > 1
407
+ const totalMultiplier = actionMultipler * critMultiplier
408
+
394
409
  // Handle action first
395
410
  if (action === 'attack') {
396
- const critMultiplier = getCritMultiplier(attackingGotchi, rng)
397
- const isCrit = critMultiplier > 1
398
- actionMultipler *= critMultiplier
399
-
400
- const damage = getDamage(attackingGotchi, target, actionMultipler)
411
+ const damage = getDamage(attackingGotchi, target, totalMultiplier)
401
412
 
402
413
  targetActionEffect = {
403
414
  target: target.id,
@@ -416,7 +427,7 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
416
427
  target.stats.dmgReceived += damage
417
428
 
418
429
  } else if (action === 'heal') {
419
- const amountToHeal = getHealFromMultiplier(attackingGotchi, target, actionMultipler)
430
+ const amountToHeal = getHealFromMultiplier(attackingGotchi, target, totalMultiplier)
420
431
 
421
432
  targetActionEffect = {
422
433
  target: target.id,
@@ -437,7 +448,7 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
437
448
 
438
449
  // If it's a special attack then handle the special effects with target 'same_as_attack'
439
450
  if (isSpecial) {
440
- attackingGotchi.specialExpanded.effects.forEach((specialEffect) => {
451
+ nonRepeatSpecialEffects.forEach((specialEffect) => {
441
452
  // Only handle special effects here that have a target code of 'same_as_attack'
442
453
  // Handle the rest after the action is done
443
454
  // This is to ensure that these effects are not applied multiple times
@@ -463,10 +474,6 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
463
474
  targetAdditionalEffects.push(...specialEffectResults.additionalEffects)
464
475
 
465
476
  statusesExpired.push(...specialEffectResults.statusesExpired)
466
-
467
- if (specialEffectResults.repeatAttack) {
468
- repeatAttack = true
469
- }
470
477
  }
471
478
  })
472
479
  } else {
@@ -584,11 +591,11 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
584
591
 
585
592
  // Handle specialEffects that are not 'same_as_attack'
586
593
  if (isSpecial) {
587
- attackingGotchi.specialExpanded.effects.forEach((specialEffect) => {
594
+ nonRepeatSpecialEffects.forEach((specialEffect) => {
588
595
  if (specialEffect.target !== 'same_as_attack') {
589
596
  const targets = getTargetsFromCode(specialEffect.target, attackingGotchi, attackingTeam, defendingTeam, rng)
590
597
 
591
- targets.forEach((target) => {
598
+ targets.forEach((target) => {
592
599
  const specialEffectResults = handleSpecialEffects(attackingTeam, attackingGotchi, target, specialEffect, rng)
593
600
 
594
601
  additionalEffects.push(specialEffectResults.actionEffect)
@@ -596,10 +603,6 @@ const attack = (attackingGotchi, attackingTeam, defendingTeam, rng, isSpecial =
596
603
  additionalEffects.push(...specialEffectResults.additionalEffects)
597
604
 
598
605
  statusesExpired.push(...specialEffectResults.statusesExpired)
599
-
600
- if (specialEffectResults.repeatAttack) {
601
- repeatAttack = true
602
- }
603
606
  })
604
607
  }
605
608
  })
@@ -622,15 +625,13 @@ const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEff
622
625
 
623
626
  const additionalEffects = []
624
627
  const statusesExpired = []
625
- let repeatAttack = false
626
628
 
627
629
  // Check for chance of the special effect
628
630
  if (specialEffect.chance && specialEffect.chance < 1 && rng() > specialEffect.chance) {
629
631
  return {
630
632
  actionEffect,
631
633
  additionalEffects,
632
- statusesExpired,
633
- repeatAttack
634
+ statusesExpired
634
635
  }
635
636
  }
636
637
 
@@ -652,7 +653,7 @@ const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEff
652
653
  }
653
654
  case 'heal': {
654
655
  const amountToHeal = getHealFromMultiplier(attackingGotchi, target, specialEffect.actionMultiplier)
655
-
656
+
656
657
  // Add another effect for the healing
657
658
  additionalEffects.push({
658
659
  target: target.id,
@@ -662,7 +663,7 @@ const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEff
662
663
  })
663
664
 
664
665
  target.health += amountToHeal
665
-
666
+
666
667
  break
667
668
  }
668
669
  case 'remove_buff': {
@@ -756,10 +757,6 @@ const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEff
756
757
 
757
758
  break
758
759
  }
759
- case 'repeat_attack': {
760
- repeatAttack = true
761
- break
762
- }
763
760
  default:
764
761
  throw new Error(`Invalid special effect type: ${specialEffect.effectType}`)
765
762
  }
@@ -767,8 +764,7 @@ const handleSpecialEffects = (attackingTeam, attackingGotchi, target, specialEff
767
764
  return {
768
765
  actionEffect,
769
766
  additionalEffects,
770
- statusesExpired,
771
- repeatAttack
767
+ statusesExpired
772
768
  }
773
769
  }
774
770
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gotchi-battler-game-logic",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "mocha \"tests/**/*.test.js\"",