@firestone-hs/simulate-bgs-battle 1.1.276 → 1.1.278
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.
|
@@ -314,11 +314,9 @@ const handleAfterSpawnEffect = (board, spawned, allCards, spectator) => {
|
|
|
314
314
|
case "BG26_172":
|
|
315
315
|
case "BG26_172_G":
|
|
316
316
|
const xylobonesBuff = entity.cardId === "BG26_172_G" ? 6 : 3;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
spectator.registerPowerTarget(entity, e, board);
|
|
321
|
-
});
|
|
317
|
+
(0, utils_1.modifyHealth)(entity, xylobonesBuff, board, allCards);
|
|
318
|
+
(0, utils_1.afterStatsUpdate)(entity, board, allCards);
|
|
319
|
+
spectator.registerPowerTarget(entity, entity, board);
|
|
322
320
|
break;
|
|
323
321
|
case "BG26_804":
|
|
324
322
|
case "BG26_804_G":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-minion-to-board.js","sourceRoot":"","sources":["../../src/simulation/add-minion-to-board.ts"],"names":[],"mappings":";;;AAAA,iEAA8E;AAG9E,oDAAqD;AACrD,oCAOkB;AAIX,MAAM,iBAAiB,GAAG,CAChC,KAAoB,EACpB,SAA0B,EAC1B,SAA0B,EAC1B,KAAa,EACb,YAAoC,EACpC,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACjB,EAAE;IACT,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,WAAW,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;QACtD,IAAA,wBAAgB,EAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;KAC3G;IACD,uBAAuB,CAAC,KAAK,EAAE,YAAY,EAAE,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AAgB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBAC1C,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;iBACrD;gBACD,MAAM;SACP;KACD;AACF,CAAC,CAAC","sourcesContent":["import { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { WHELP_CARD_IDS } from '../cards/cards-data';\r\nimport {\r\n\tafterStatsUpdate,\r\n\thasCorrectTribe,\r\n\tisCorrectTribe,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const addMinionsToBoard = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tindex: number,\r\n\tminionsToAdd: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n): void => {\r\n\tboard.splice(index, 0, ...minionsToAdd);\r\n\tfor (const minionToAdd of [...minionsToAdd].reverse()) {\r\n\t\taddMinionToBoard(board, boardHero, otherHero, index, minionToAdd, allCards, spectator, sharedState, false);\r\n\t}\r\n\thandleAfterSpawnEffects(board, minionsToAdd, allCards, spectator);\r\n};\r\n\r\nexport const addMinionToBoard = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tindex: number,\r\n\tminionToAdd: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n\tperformAfterSpawnEffects = true,\r\n): void => {\r\n\tboard.splice(index, 0, minionToAdd);\r\n\t// Minion has already been removed from the board in the previous step\r\n\thandleSpawnEffect(board, boardHero, otherHero, minionToAdd, allCards, spectator, sharedState);\r\n\tif (performAfterSpawnEffects) {\r\n\t\thandleAfterSpawnEffects(board, [minionToAdd], allCards, spectator);\r\n\t}\r\n};\r\n\r\nconst handleSpawnEffect = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tspawned: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n): void => {\r\n\tif (otherHero.heroPowerId === CardIds.AllWillBurnBattlegrounds) {\r\n\t\tspawned.attack += 3;\r\n\t}\r\n\r\n\tswitch (boardHero.heroPowerId) {\r\n\t\tcase CardIds.AllWillBurnBattlegrounds:\r\n\t\t\tspawned.attack += 3;\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SproutItOutBattlegrounds:\r\n\t\t\tspawned.taunt = true;\r\n\t\t\tmodifyAttack(spawned, 1, board, allCards);\r\n\t\t\tmodifyHealth(spawned, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KurtrusAshfallen_CloseThePortal:\r\n\t\t\tmodifyAttack(spawned, 2, board, allCards);\r\n\t\t\tmodifyHealth(spawned, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.TinkerBattlegrounds:\r\n\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\tmodifyAttack(spawned, 2, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\tif (!!boardHero.questRewards?.length) {\r\n\t\tfor (const quest of boardHero.questRewards) {\r\n\t\t\tswitch (quest) {\r\n\t\t\t\tcase CardIds.VolatileVenom:\r\n\t\t\t\t\tspawned.attack += 7;\r\n\t\t\t\t\tspawned.health += 7;\r\n\t\t\t\t\tspawned.enchantments.push({\r\n\t\t\t\t\t\tcardId: CardIds.VolatileVenom_VolatileEnchantment,\r\n\t\t\t\t\t\toriginEntityId: undefined,\r\n\t\t\t\t\t\ttiming: sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase CardIds.TheSmokingGun:\r\n\t\t\t\t\tspawned.attack += 5;\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst cardIds = [spawned.cardId, ...(spawned.additionalCards ?? [])];\r\n\tfor (const spawnedCardId of cardIds) {\r\n\t\tswitch (spawnedCardId) {\r\n\t\t\tcase CardIds.SouthseaCaptainLegacy_BG_NEW1_027:\r\n\t\t\tcase CardIds.SouthseaCaptainLegacyBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.PIRATE, allCards))\r\n\t\t\t\t\t// Other\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\t\te.health += spawned.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.MurlocWarleaderLegacy_BG_EX1_507:\r\n\t\t\tcase CardIds.MurlocWarleaderLegacyBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.MURLOC, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.MurlocWarleaderLegacyBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HummingBird:\r\n\t\t\tcase CardIds.HummingBirdBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.BEAST, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.HummingBirdBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy:\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G:\r\n\t\t\t\tboard.forEach((e) => {\r\n\t\t\t\t\te.attack +=\r\n\t\t\t\t\t\tspawned.cardId === CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G ? 6 : 3;\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Kathranatir_BG21_039:\r\n\t\t\tcase CardIds.KathranatirBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.DEMON, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.KathranatirBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.CyborgDrake:\r\n\t\t\tcase CardIds.CyborgDrakeBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => e.divineShield)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.CyborgDrakeBattlegrounds ? 16 : 8;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.EternalKnight:\r\n\t\t\tcase CardIds.EternalKnightBattlegrounds:\r\n\t\t\t\tconst multiplierKnight = spawned.cardId === CardIds.EternalKnightBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusKnight = multiplierKnight * boardHero.globalInfo.EternalKnightsDeadThisGame;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusKnight, board, allCards);\r\n\t\t\t\tmodifyHealth(spawned, statsBonusKnight, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FlourishingFrostling:\r\n\t\t\tcase CardIds.FlourishingFrostlingBattlegrounds:\r\n\t\t\t\tconst multiplierFrostling = spawned.cardId === CardIds.FlourishingFrostlingBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusFrostling = multiplierFrostling * boardHero.globalInfo.FrostlingBonus;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusFrostling, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RotHideGnoll:\r\n\t\t\tcase CardIds.RotHideGnollBattlegrounds:\r\n\t\t\t\tconst multiplierGnoll = spawned.cardId === CardIds.RotHideGnollBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusGnoll =\r\n\t\t\t\t\tmultiplierGnoll * sharedState.deaths.filter((e) => e.friendly === spawned.friendly).length;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusGnoll, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tif (hasCorrectTribe(spawned, Race.UNDEAD, allCards)) {\r\n\t\tif (boardHero.globalInfo.UndeadAttackBonus > 0) {\r\n\t\t\tmodifyAttack(spawned, boardHero.globalInfo.UndeadAttackBonus, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t}\r\n\t}\r\n\r\n\t// https://twitter.com/LoewenMitchell/status/1491879869457879040\r\n\tif (cardIds.some((cardId) => WHELP_CARD_IDS.includes(cardId as CardIds))) {\r\n\t\tconst manyWhelps = board.filter((entity) => entity.cardId === CardIds.ManyWhelps);\r\n\t\tconst goldenManyWhelps = board.filter((entity) => entity.cardId === CardIds.ManyWhelpsBattlegrounds);\r\n\t\tmanyWhelps.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, board, allCards);\r\n\t\t\tmodifyHealth(entity, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t});\r\n\t\tgoldenManyWhelps.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 4, board, allCards);\r\n\t\t\tmodifyHealth(entity, 4, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t});\r\n\t}\r\n\r\n\tfor (const entity of board) {\r\n\t\tswitch (entity.cardId) {\r\n\t\t\tcase CardIds.MurlocWarleaderLegacy_BG_EX1_507:\r\n\t\t\tcase CardIds.MurlocWarleaderLegacyBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MURLOC, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.MurlocWarleaderLegacyBattlegrounds ? 4 : 2;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HummingBird:\r\n\t\t\tcase CardIds.HummingBirdBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.HummingBirdBattlegrounds ? 4 : 2;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.SouthseaCaptainLegacy_BG_NEW1_027:\r\n\t\t\tcase CardIds.SouthseaCaptainLegacyBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.PIRATE, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\tspawned.health += entity.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy:\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G:\r\n\t\t\t\tspawned.attack +=\r\n\t\t\t\t\tentity.cardId === CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G ? 6 : 3;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Kathranatir_BG21_039:\r\n\t\t\tcase CardIds.KathranatirBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.DEMON, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.KathranatirBattlegrounds ? 2 : 1;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.CyborgDrake:\r\n\t\t\tcase CardIds.CyborgDrakeBattlegrounds:\r\n\t\t\t\tif (spawned.divineShield) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.CyborgDrakeBattlegrounds ? 16 : 8;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy:\r\n\t\t\tcase CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy_G:\r\n\t\t\t\tif (allCards.getCard(spawned.cardId).techLevel === boardHero.tavernTier) {\r\n\t\t\t\t\tconst statsBonus =\r\n\t\t\t\t\t\tentity.cardId === CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy_G ? 8 : 4;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t// This has to happen after greybough's hero power kicks in\r\n\t\t\tcase CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy:\r\n\t\t\tcase CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy_G:\r\n\t\t\t\tif (spawned.taunt) {\r\n\t\t\t\t\tconst statsBonus =\r\n\t\t\t\t\t\tentity.cardId === CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy_G ? 4 : 2;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.CobaltGuardian:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\t\tif (!entity.divineShield) {\r\n\t\t\t\t\t\tupdateDivineShield(entity, board, true, allCards);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmodifyAttack(entity, 2, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.DeflectOBot:\r\n\t\t\tcase CardIds.DeflectOBotBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.DeflectOBotBattlegrounds ? 4 : 2;\r\n\t\t\t\t\tif (!entity.divineShield) {\r\n\t\t\t\t\t\tupdateDivineShield(entity, board, true, allCards);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmodifyAttack(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Bigfernal:\r\n\t\t\tcase CardIds.BigfernalBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.DEMON, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.BigfernalBattlegrounds ? 2 : 1;\r\n\t\t\t\t\tmodifyAttack(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.MamaBear:\r\n\t\t\tcase CardIds.MamaBearBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.MamaBearBattlegrounds ? 8 : 4;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.PackLeader:\r\n\t\t\tcase CardIds.PackLeaderBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.PackLeaderBattlegrounds ? 4 : 2;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst handleAfterSpawnEffects = (\r\n\tboard: BoardEntity[],\r\n\tallSpawned: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tfor (const spawned of allSpawned) {\r\n\t\thandleAfterSpawnEffect(board, spawned, allCards, spectator);\r\n\t}\r\n};\r\n\r\nconst handleAfterSpawnEffect = (\r\n\tboard: BoardEntity[],\r\n\tspawned: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.debug('after spawn', stringifySimpleCard(spawned, allCards), stringifySimple(board, allCards));\r\n\tfor (const entity of board) {\r\n\t\tswitch (entity.cardId) {\r\n\t\t\tcase CardIds.MurlocTidecallerLegacy:\r\n\t\t\tcase CardIds.MurlocTidecallerBattlegrounds:\r\n\t\t\t\tconst multiplier = entity.cardId === CardIds.MurlocTidecallerBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst buffAmount =\r\n\t\t\t\t\tmultiplier * (isCorrectTribe(allCards.getCard(spawned.cardId).races, Race.MURLOC) ? 1 : 0);\r\n\t\t\t\tif (buffAmount > 0) {\r\n\t\t\t\t\tmodifyAttack(entity, buffAmount, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Swampstriker:\r\n\t\t\tcase CardIds.SwampstrikerBattlegrounds:\r\n\t\t\t\tconst multiplier2 = entity.cardId === CardIds.SwampstrikerBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst buffAmount2 =\r\n\t\t\t\t\tmultiplier2 * (isCorrectTribe(allCards.getCard(spawned.cardId).races, Race.MURLOC) ? 1 : 0);\r\n\t\t\t\tif (buffAmount2 > 0) {\r\n\t\t\t\t\tmodifyAttack(entity, buffAmount2, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Felstomper:\r\n\t\t\tcase CardIds.FelstomperBattlegrounds:\r\n\t\t\t\t// console.debug('felstomper');\r\n\t\t\t\tconst felstomperBuff = entity.cardId === CardIds.FelstomperBattlegrounds ? 6 : 3;\r\n\t\t\t\tboard.forEach((e) => {\r\n\t\t\t\t\tmodifyAttack(e, felstomperBuff, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(e, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, e, board);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.XyloBones:\r\n\t\t\tcase CardIds.XyloBonesBattlegrounds:\r\n\t\t\t\tconst xylobonesBuff = entity.cardId === CardIds.XyloBonesBattlegrounds ? 6 : 3;\r\n\t\t\t\tboard.forEach((e) => {\r\n\t\t\t\t\tmodifyHealth(e, xylobonesBuff, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(e, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, e, board);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.OctosariWrapGod:\r\n\t\t\tcase CardIds.OctosariWrapGodBattlegrounds:\r\n\t\t\t\tconst octoStats = entity.cardId === CardIds.OctosariWrapGodBattlegrounds ? 4 : 2;\r\n\t\t\t\tentity.scriptDataNum1 += octoStats;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BananaSlamma:\r\n\t\t\tcase CardIds.BananaSlammaBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst bananaStatBuff = entity.cardId === CardIds.BananaSlammaBattlegrounds ? 3 : 2;\r\n\t\t\t\t\tspawned.attack = spawned.attack * bananaStatBuff;\r\n\t\t\t\t\tspawned.health = spawned.health * bananaStatBuff;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\t// Putricide-only\r\n\t\t\tcase CardIds.ArmsDealer_BG26_RLK_824:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.UNDEAD, allCards)) {\r\n\t\t\t\t\tmodifyAttack(spawned, 1, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"add-minion-to-board.js","sourceRoot":"","sources":["../../src/simulation/add-minion-to-board.ts"],"names":[],"mappings":";;;AAAA,iEAA8E;AAG9E,oDAAqD;AACrD,oCAOkB;AAIX,MAAM,iBAAiB,GAAG,CAChC,KAAoB,EACpB,SAA0B,EAC1B,SAA0B,EAC1B,KAAa,EACb,YAAoC,EACpC,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACjB,EAAE;IACT,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,WAAW,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;QACtD,IAAA,wBAAgB,EAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;KAC3G;IACD,uBAAuB,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AACnE,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAEK,MAAM,gBAAgB,GAAG,CAC/B,KAAoB,EACpB,SAA0B,EAC1B,SAA0B,EAC1B,KAAa,EACb,WAAwB,EACxB,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACxB,wBAAwB,GAAG,IAAI,EACxB,EAAE;IACT,KAAK,CAAC,MAAM,CAAC,KA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M,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC1C,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBACrD,MAAM;YACP,gBAA6B;YAC7B;gBACC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,iBAAyC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjF,MAAM,CAAC,cAAc,IAAI,SAAS,CAAC;gBACnC,MAAM;YACP,gBAA0B;YAC1B;gBACC,IAAI,IAAA,uBAAe,EAAC,OAAO,EAAE,qBAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;oBACnD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,iBAAsC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnF,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,cAAc,CAAC;oBACjD,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,cAAc,CAAC;iBACjD;gBACD,MAAM;YAGP;gBACC,IAAI,IAAA,uBAAe,EAAC,OAAO,EAAE,qBAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;oBACpD,IAAA,oBAAY,EAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBAC1C,IAAA,wBAAgB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBAC1C,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;iBACrD;gBACD,MAAM;SACP;KACD;AACF,CAAC,CAAC","sourcesContent":["import { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { WHELP_CARD_IDS } from '../cards/cards-data';\r\nimport {\r\n\tafterStatsUpdate,\r\n\thasCorrectTribe,\r\n\tisCorrectTribe,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const addMinionsToBoard = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tindex: number,\r\n\tminionsToAdd: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n): void => {\r\n\tboard.splice(index, 0, ...minionsToAdd);\r\n\tfor (const minionToAdd of [...minionsToAdd].reverse()) {\r\n\t\taddMinionToBoard(board, boardHero, otherHero, index, minionToAdd, allCards, spectator, sharedState, false);\r\n\t}\r\n\thandleAfterSpawnEffects(board, minionsToAdd, allCards, spectator);\r\n};\r\n\r\nexport const addMinionToBoard = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tindex: number,\r\n\tminionToAdd: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n\tperformAfterSpawnEffects = true,\r\n): void => {\r\n\tboard.splice(index, 0, minionToAdd);\r\n\t// Minion has already been removed from the board in the previous step\r\n\thandleSpawnEffect(board, boardHero, otherHero, minionToAdd, allCards, spectator, sharedState);\r\n\tif (performAfterSpawnEffects) {\r\n\t\thandleAfterSpawnEffects(board, [minionToAdd], allCards, spectator);\r\n\t}\r\n};\r\n\r\nconst handleSpawnEffect = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherHero: BgsPlayerEntity,\r\n\tspawned: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tsharedState: SharedState,\r\n): void => {\r\n\tif (otherHero.heroPowerId === CardIds.AllWillBurnBattlegrounds) {\r\n\t\tspawned.attack += 3;\r\n\t}\r\n\r\n\tswitch (boardHero.heroPowerId) {\r\n\t\tcase CardIds.AllWillBurnBattlegrounds:\r\n\t\t\tspawned.attack += 3;\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SproutItOutBattlegrounds:\r\n\t\t\tspawned.taunt = true;\r\n\t\t\tmodifyAttack(spawned, 1, board, allCards);\r\n\t\t\tmodifyHealth(spawned, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KurtrusAshfallen_CloseThePortal:\r\n\t\t\tmodifyAttack(spawned, 2, board, allCards);\r\n\t\t\tmodifyHealth(spawned, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.TinkerBattlegrounds:\r\n\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\tmodifyAttack(spawned, 2, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\tif (!!boardHero.questRewards?.length) {\r\n\t\tfor (const quest of boardHero.questRewards) {\r\n\t\t\tswitch (quest) {\r\n\t\t\t\tcase CardIds.VolatileVenom:\r\n\t\t\t\t\tspawned.attack += 7;\r\n\t\t\t\t\tspawned.health += 7;\r\n\t\t\t\t\tspawned.enchantments.push({\r\n\t\t\t\t\t\tcardId: CardIds.VolatileVenom_VolatileEnchantment,\r\n\t\t\t\t\t\toriginEntityId: undefined,\r\n\t\t\t\t\t\ttiming: sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase CardIds.TheSmokingGun:\r\n\t\t\t\t\tspawned.attack += 5;\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst cardIds = [spawned.cardId, ...(spawned.additionalCards ?? [])];\r\n\tfor (const spawnedCardId of cardIds) {\r\n\t\tswitch (spawnedCardId) {\r\n\t\t\tcase CardIds.SouthseaCaptainLegacy_BG_NEW1_027:\r\n\t\t\tcase CardIds.SouthseaCaptainLegacyBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.PIRATE, allCards))\r\n\t\t\t\t\t// Other\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\t\te.health += spawned.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.MurlocWarleaderLegacy_BG_EX1_507:\r\n\t\t\tcase CardIds.MurlocWarleaderLegacyBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.MURLOC, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.MurlocWarleaderLegacyBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HummingBird:\r\n\t\t\tcase CardIds.HummingBirdBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.BEAST, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.HummingBirdBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy:\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G:\r\n\t\t\t\tboard.forEach((e) => {\r\n\t\t\t\t\te.attack +=\r\n\t\t\t\t\t\tspawned.cardId === CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G ? 6 : 3;\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Kathranatir_BG21_039:\r\n\t\t\tcase CardIds.KathranatirBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, Race.DEMON, allCards))\r\n\t\t\t\t\t.filter((e) => e.entityId !== spawned.entityId)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.KathranatirBattlegrounds ? 4 : 2;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.CyborgDrake:\r\n\t\t\tcase CardIds.CyborgDrakeBattlegrounds:\r\n\t\t\t\tboard\r\n\t\t\t\t\t.filter((e) => e.divineShield)\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.attack += spawned.cardId === CardIds.CyborgDrakeBattlegrounds ? 16 : 8;\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.EternalKnight:\r\n\t\t\tcase CardIds.EternalKnightBattlegrounds:\r\n\t\t\t\tconst multiplierKnight = spawned.cardId === CardIds.EternalKnightBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusKnight = multiplierKnight * boardHero.globalInfo.EternalKnightsDeadThisGame;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusKnight, board, allCards);\r\n\t\t\t\tmodifyHealth(spawned, statsBonusKnight, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FlourishingFrostling:\r\n\t\t\tcase CardIds.FlourishingFrostlingBattlegrounds:\r\n\t\t\t\tconst multiplierFrostling = spawned.cardId === CardIds.FlourishingFrostlingBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusFrostling = multiplierFrostling * boardHero.globalInfo.FrostlingBonus;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusFrostling, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RotHideGnoll:\r\n\t\t\tcase CardIds.RotHideGnollBattlegrounds:\r\n\t\t\t\tconst multiplierGnoll = spawned.cardId === CardIds.RotHideGnollBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst statsBonusGnoll =\r\n\t\t\t\t\tmultiplierGnoll * sharedState.deaths.filter((e) => e.friendly === spawned.friendly).length;\r\n\t\t\t\tmodifyAttack(spawned, statsBonusGnoll, board, allCards);\r\n\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tif (hasCorrectTribe(spawned, Race.UNDEAD, allCards)) {\r\n\t\tif (boardHero.globalInfo.UndeadAttackBonus > 0) {\r\n\t\t\tmodifyAttack(spawned, boardHero.globalInfo.UndeadAttackBonus, board, allCards);\r\n\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t}\r\n\t}\r\n\r\n\t// https://twitter.com/LoewenMitchell/status/1491879869457879040\r\n\tif (cardIds.some((cardId) => WHELP_CARD_IDS.includes(cardId as CardIds))) {\r\n\t\tconst manyWhelps = board.filter((entity) => entity.cardId === CardIds.ManyWhelps);\r\n\t\tconst goldenManyWhelps = board.filter((entity) => entity.cardId === CardIds.ManyWhelpsBattlegrounds);\r\n\t\tmanyWhelps.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, board, allCards);\r\n\t\t\tmodifyHealth(entity, 2, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t});\r\n\t\tgoldenManyWhelps.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 4, board, allCards);\r\n\t\t\tmodifyHealth(entity, 4, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t});\r\n\t}\r\n\r\n\tfor (const entity of board) {\r\n\t\tswitch (entity.cardId) {\r\n\t\t\tcase CardIds.MurlocWarleaderLegacy_BG_EX1_507:\r\n\t\t\tcase CardIds.MurlocWarleaderLegacyBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MURLOC, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.MurlocWarleaderLegacyBattlegrounds ? 4 : 2;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HummingBird:\r\n\t\t\tcase CardIds.HummingBirdBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.HummingBirdBattlegrounds ? 4 : 2;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.SouthseaCaptainLegacy_BG_NEW1_027:\r\n\t\t\tcase CardIds.SouthseaCaptainLegacyBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.PIRATE, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t\tspawned.health += entity.cardId === CardIds.SouthseaCaptainLegacyBattlegrounds ? 2 : 1;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy:\r\n\t\t\tcase CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G:\r\n\t\t\t\tspawned.attack +=\r\n\t\t\t\t\tentity.cardId === CardIds.LadySinestraBattlegrounds_TB_BaconShop_HERO_52_Buddy_G ? 6 : 3;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Kathranatir_BG21_039:\r\n\t\t\tcase CardIds.KathranatirBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.DEMON, allCards) && entity.entityId !== spawned.entityId) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.KathranatirBattlegrounds ? 2 : 1;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.CyborgDrake:\r\n\t\t\tcase CardIds.CyborgDrakeBattlegrounds:\r\n\t\t\t\tif (spawned.divineShield) {\r\n\t\t\t\t\tspawned.attack += entity.cardId === CardIds.CyborgDrakeBattlegrounds ? 16 : 8;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy:\r\n\t\t\tcase CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy_G:\r\n\t\t\t\tif (allCards.getCard(spawned.cardId).techLevel === boardHero.tavernTier) {\r\n\t\t\t\t\tconst statsBonus =\r\n\t\t\t\t\t\tentity.cardId === CardIds.BabyYshaarjBattlegrounds_TB_BaconShop_HERO_92_Buddy_G ? 8 : 4;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t// This has to happen after greybough's hero power kicks in\r\n\t\t\tcase CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy:\r\n\t\t\tcase CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy_G:\r\n\t\t\t\tif (spawned.taunt) {\r\n\t\t\t\t\tconst statsBonus =\r\n\t\t\t\t\t\tentity.cardId === CardIds.WanderingTreantBattlegrounds_TB_BaconShop_HERO_95_Buddy_G ? 4 : 2;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(spawned, board, allCards);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase CardIds.CobaltGuardian:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\t\tif (!entity.divineShield) {\r\n\t\t\t\t\t\tupdateDivineShield(entity, board, true, allCards);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmodifyAttack(entity, 2, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.DeflectOBot:\r\n\t\t\tcase CardIds.DeflectOBotBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.MECH, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.DeflectOBotBattlegrounds ? 4 : 2;\r\n\t\t\t\t\tif (!entity.divineShield) {\r\n\t\t\t\t\t\tupdateDivineShield(entity, board, true, allCards);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmodifyAttack(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Bigfernal:\r\n\t\t\tcase CardIds.BigfernalBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.DEMON, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.BigfernalBattlegrounds ? 2 : 1;\r\n\t\t\t\t\tmodifyAttack(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(entity, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.MamaBear:\r\n\t\t\tcase CardIds.MamaBearBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.MamaBearBattlegrounds ? 8 : 4;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tmodifyHealth(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.PackLeader:\r\n\t\t\tcase CardIds.PackLeaderBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst statsBonus = entity.cardId === CardIds.PackLeaderBattlegrounds ? 4 : 2;\r\n\t\t\t\t\tmodifyAttack(spawned, statsBonus, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst handleAfterSpawnEffects = (\r\n\tboard: BoardEntity[],\r\n\tallSpawned: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tfor (const spawned of allSpawned) {\r\n\t\thandleAfterSpawnEffect(board, spawned, allCards, spectator);\r\n\t}\r\n};\r\n\r\nconst handleAfterSpawnEffect = (\r\n\tboard: BoardEntity[],\r\n\tspawned: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.debug('after spawn', stringifySimpleCard(spawned, allCards), stringifySimple(board, allCards));\r\n\tfor (const entity of board) {\r\n\t\tswitch (entity.cardId) {\r\n\t\t\tcase CardIds.MurlocTidecallerLegacy:\r\n\t\t\tcase CardIds.MurlocTidecallerBattlegrounds:\r\n\t\t\t\tconst multiplier = entity.cardId === CardIds.MurlocTidecallerBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst buffAmount =\r\n\t\t\t\t\tmultiplier * (isCorrectTribe(allCards.getCard(spawned.cardId).races, Race.MURLOC) ? 1 : 0);\r\n\t\t\t\tif (buffAmount > 0) {\r\n\t\t\t\t\tmodifyAttack(entity, buffAmount, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Swampstriker:\r\n\t\t\tcase CardIds.SwampstrikerBattlegrounds:\r\n\t\t\t\tconst multiplier2 = entity.cardId === CardIds.SwampstrikerBattlegrounds ? 2 : 1;\r\n\t\t\t\tconst buffAmount2 =\r\n\t\t\t\t\tmultiplier2 * (isCorrectTribe(allCards.getCard(spawned.cardId).races, Race.MURLOC) ? 1 : 0);\r\n\t\t\t\tif (buffAmount2 > 0) {\r\n\t\t\t\t\tmodifyAttack(entity, buffAmount2, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Felstomper:\r\n\t\t\tcase CardIds.FelstomperBattlegrounds:\r\n\t\t\t\t// console.debug('felstomper');\r\n\t\t\t\tconst felstomperBuff = entity.cardId === CardIds.FelstomperBattlegrounds ? 6 : 3;\r\n\t\t\t\tboard.forEach((e) => {\r\n\t\t\t\t\tmodifyAttack(e, felstomperBuff, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(e, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, e, board);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.XyloBones:\r\n\t\t\tcase CardIds.XyloBonesBattlegrounds:\r\n\t\t\t\tconst xylobonesBuff = entity.cardId === CardIds.XyloBonesBattlegrounds ? 6 : 3;\r\n\t\t\t\tmodifyHealth(entity, xylobonesBuff, board, allCards);\r\n\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.OctosariWrapGod:\r\n\t\t\tcase CardIds.OctosariWrapGodBattlegrounds:\r\n\t\t\t\tconst octoStats = entity.cardId === CardIds.OctosariWrapGodBattlegrounds ? 4 : 2;\r\n\t\t\t\tentity.scriptDataNum1 += octoStats;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BananaSlamma:\r\n\t\t\tcase CardIds.BananaSlammaBattlegrounds:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.BEAST, allCards)) {\r\n\t\t\t\t\tconst bananaStatBuff = entity.cardId === CardIds.BananaSlammaBattlegrounds ? 3 : 2;\r\n\t\t\t\t\tspawned.attack = spawned.attack * bananaStatBuff;\r\n\t\t\t\t\tspawned.health = spawned.health * bananaStatBuff;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\t// Putricide-only\r\n\t\t\tcase CardIds.ArmsDealer_BG26_RLK_824:\r\n\t\t\t\tif (hasCorrectTribe(spawned, Race.UNDEAD, allCards)) {\r\n\t\t\t\t\tmodifyAttack(spawned, 1, board, allCards);\r\n\t\t\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(entity, entity, board);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attack.js","sourceRoot":"","sources":["../../src/simulation/attack.ts"],"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xDW,QAAA,mBAAmB,uBAwD9B","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData } from '../cards/cards-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { validEnchantments } from '../simulate-bgs-battle';\r\nimport {\r\n\taddCardsInHand,\r\n\taddStatsToBoard,\r\n\tafterStatsUpdate,\r\n\tgrantStatsToMinionsOfEachType,\r\n\thasCorrectTribe,\r\n\thasMechanic,\r\n\tisCorrectTribe,\r\n\tisFish,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n\tstringifySimple,\r\n\tstringifySimpleCard,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { addMinionToBoard, addMinionsToBoard } from './add-minion-to-board';\r\nimport { applyAvengeEffects } from './avenge';\r\nimport {\r\n\tapplyMinionDeathEffect,\r\n\tapplyMonstrosity,\r\n\thandleDeathrattleEffects,\r\n\trememberDeathrattles,\r\n} from './deathrattle-effects';\r\nimport { spawnEntities, spawnEntitiesFromDeathrattle, spawnEntitiesFromEnchantments } from './deathrattle-spawns';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { removeMinionFromBoard } from './remove-minion-from-board';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { canAttack } from './utils/entity-utils';\r\n\r\n// Only use it to simulate actual attack. To simulate damage, or something similar, use bumpInto\r\nexport const simulateAttack = (\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tlastAttackerEntityId: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n\tforceAttackingEntityIndex?: number,\r\n): number => {\r\n\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst attackingEntity =\r\n\t\tforceAttackingEntityIndex != null\r\n\t\t\t? attackingBoard[forceAttackingEntityIndex]\r\n\t\t\t: getAttackingEntity(attackingBoard, lastAttackerEntityId);\r\n\tconst attackingEntityIndex = attackingBoard.map((e) => e.entityId).indexOf(attackingEntity?.entityId);\r\n\tif (attackingEntity) {\r\n\t\tattackingEntity.attacking = true;\r\n\t\t// console.log('attack by', stringifySimpleCard(attackingEntity, allCards), stringifySimple(defendingBoard, allCards));\r\n\t\tconst numberOfAttacks = attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// We refresh the entity in case of windfury\r\n\t\t\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t// Check that didn't die\r\n\t\t\tif (attackingBoard.find((entity) => entity.entityId === attackingEntity.entityId)) {\r\n\t\t\t\tapplyOnAttackBuffs(attackingEntity, attackingBoard, allCards, spectator);\r\n\t\t\t\tconst defendingEntity: BoardEntity = getDefendingEntity(defendingBoard, attackingEntity);\r\n\t\t\t\t// Can happen with a single defender that has stealth\r\n\t\t\t\tif (defendingEntity) {\r\n\t\t\t\t\t// console.log(\r\n\t\t\t\t\t// \t'AATTTTTTTTTTTAAAAAAAAAAAAAAAAAACK by',\r\n\t\t\t\t\t// \tstringifySimpleCard(attackingEntity, allCards),\r\n\t\t\t\t\t// \tstringifySimpleCard(defendingEntity, allCards),\r\n\t\t\t\t\t// \tstringifySimple(attackingBoard, allCards),\r\n\t\t\t\t\t// );\r\n\t\t\t\t\tspectator.registerAttack(attackingEntity, defendingEntity, attackingBoard, defendingBoard);\r\n\t\t\t\t\tapplyOnBeingAttackedBuffs(attackingEntity, defendingEntity, defendingBoard, allCards, spectator);\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tapplyAfterAttackEffects(attackingEntity, attackingBoard, attackingBoardHero, allCards, spectator);\r\n\t\t\t\t\tprocessMinionDeath(\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\tdefendingEntity.health > 0 &&\r\n\t\t\t\t\t\t!defendingEntity.definitelyDead &&\r\n\t\t\t\t\t\t(defendingEntity.cardId === CardIds.YoHoOgre ||\r\n\t\t\t\t\t\t\tdefendingEntity.cardId === CardIds.YoHoOgreBattlegrounds)\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\tdefendingEntity.attackImmediately = true;\r\n\t\t\t\t\t\tif (defendingEntity.attackImmediately) {\r\n\t\t\t\t\t\t\tsimulateAttack(\r\n\t\t\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// console.log(\r\n\t\t\t\t\t// \t'after attack by',\r\n\t\t\t\t\t// \tstringifySimpleCard(attackingEntity, allCards),\r\n\t\t\t\t\t// \tstringifySimpleCard(defendingEntity, allCards),\r\n\t\t\t\t\t// );\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Solves the edge case of Sky Pirate vs a stealth board\r\n\t\t\t\t\tattackingEntity.attackImmediately = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tattackingEntity.attacking = false;\r\n\t}\r\n\t// If entities that were before the attacker died, we need to update the attacker index\r\n\treturn attackingEntityIndex;\r\n};\r\n\r\nconst applyAfterAttackEffects = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attackingEntity.cardId === CardIds.Bonker_BG20_104 || attackingEntity.cardId === CardIds.Bonker_BG20_104_G) {\r\n\t\tconst quantity = attackingEntity.cardId === CardIds.Bonker_BG20_104_G ? 2 : 1;\r\n\t\tconst cards = quantity === 1 ? [CardIds.BloodGem] : [CardIds.BloodGem, CardIds.BloodGem];\r\n\t\taddCardsInHand(attackingBoardHero, attackingBoard, allCards, spectator, cards);\r\n\t} else if (attackingEntity.cardId === CardIds.Yrel_BG23_350 || attackingEntity.cardId === CardIds.Yrel_BG23_350_G) {\r\n\t\tconst modifier = attackingEntity.cardId === CardIds.Yrel_BG23_350_G ? 2 : 1;\r\n\t\tgrantStatsToMinionsOfEachType(attackingEntity, attackingBoard, modifier * 1, modifier * 2, allCards, spectator);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117 ||\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117_G\r\n\t) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\t// Putricide-only\r\n\telse if (attackingEntity.additionalCards?.includes(CardIds.IncorporealCorporal_BG26_RLK_117)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tattackingBoard\r\n\t\t.filter((e) => e.additionalCards?.includes(CardIds.FesterootHulk_BG_GIL_655))\r\n\t\t.forEach((e) => {\r\n\t\t\tmodifyAttack(e, 1, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(e, attackingBoard, allCards);\r\n\t\t});\r\n\r\n\tattackingEntity.stealth = false;\r\n};\r\n\r\nconst performAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (hasCorrectTribe(attackingEntity, Race.DRAGON, allCards)) {\r\n\t\tconst prestors = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attackingEntity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012 ||\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012_G,\r\n\t\t\t);\r\n\t\tprestors.forEach((prestor) => {\r\n\t\t\tspectator.registerPowerTarget(prestor, defendingEntity, defendingBoard);\r\n\t\t\tdealDamageToEnemy(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tprestor,\r\n\t\t\t\tprestor.cardId === CardIds.PrestorsPyrospawn_BG21_012_G ? 6 : 3,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362 ||\r\n\t\tattackingEntity.cardId === CardIds.AtramedesBattlegrounds\r\n\t) {\r\n\t\tconst targets = [defendingEntity, ...getNeighbours(defendingBoard, defendingEntity)];\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.AtramedesBattlegrounds ? 2 : 1;\r\n\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\ttargets.forEach((target) => {\r\n\t\t\t\tspectator.registerPowerTarget(attackingEntity, target, defendingBoard);\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tif ([CardIds.BabyKrush_BG22_001, CardIds.BabyKrush_BG22_001_G].includes(attackingEntity.cardId as CardIds)) {\r\n\t\tconst spawns = spawnEntities(\r\n\t\t\tattackingEntity.cardId === CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t? CardIds.DevilsaurBattlegrounds\r\n\t\t\t\t: CardIds.BabyKrush_DevilsaurToken,\r\n\t\t\t1,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\ttrue,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tif (spawns.length > 0) {\r\n\t\t\tconst sourceIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\t\tconst actualSpawns = performEntitySpawns(\r\n\t\t\t\tspawns,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tsourceIndex,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\tfor (const actualSpawn of actualSpawns) {\r\n\t\t\t\tif (defendingEntity.health > 0 && !defendingEntity.definitelyDead) {\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tactualSpawn,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tcardsData,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// For Prestor\r\n\tconst defenderAliveBeforeAttack = defendingEntity.health > 0 && !defendingEntity.definitelyDead;\r\n\tif (defenderAliveBeforeAttack) {\r\n\t\tif (!attackingEntity.immuneWhenAttackCharges || attackingEntity.immuneWhenAttackCharges <= 0) {\r\n\t\t\tbumpEntities(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tbumpEntities(\r\n\t\t\tdefendingEntity,\r\n\t\t\tattackingEntity,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t// cause wrong results to happen\r\n\t\tif (defendingEntity.attack > 0 && attackingEntity.divineShield) {\r\n\t\t\tupdateDivineShield(attackingEntity, attackingBoard, false, allCards);\r\n\t\t}\r\n\t\tif (attackingEntity.attack > 0 && defendingEntity.divineShield) {\r\n\t\t\tupdateDivineShield(defendingEntity, defendingBoard, false, allCards);\r\n\t\t}\r\n\t}\r\n\t// Cleave\r\n\tif (attackingEntity.cleave) {\r\n\t\tconst defenderNeighbours: readonly BoardEntity[] = getNeighbours(defendingBoard, defendingEntity);\r\n\t\tfor (const neighbour of defenderNeighbours) {\r\n\t\t\tbumpEntities(\r\n\t\t\t\tneighbour,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t\t// cause wrong results to happen\r\n\t\t\tif (attackingEntity.attack > 0 && neighbour.divineShield) {\r\n\t\t\t\tupdateDivineShield(neighbour, defendingBoard, false, allCards);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\t(defendingEntity.health <= 0 || defendingEntity.definitelyDead) &&\r\n\t\t(attackingEntity.cardId === CardIds.WildfireElemental ||\r\n\t\t\tattackingEntity.cardId === CardIds.WildfireElementalBattlegrounds)\r\n\t) {\r\n\t\tconst excessDamage = -defendingEntity.health;\r\n\t\tconst neighbours = getNeighbours(defendingBoard, defendingEntity);\r\n\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\tif (neighbours.length > 0) {\r\n\t\t\tif (attackingEntity.cardId === CardIds.WildfireElemental) {\r\n\t\t\t\tconst randomTarget = neighbours[Math.floor(Math.random() * neighbours.length)];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\trandomTarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tneighbours.forEach((neighbour) =>\r\n\t\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\t\tneighbour,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\t\texcessDamage,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tcardsData,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// After attack hooks\r\n\t// Arcane Cannon\r\n\t// Monstrous Macaw\r\n\tif (attackingEntity.cardId === CardIds.MonstrousMacaw) {\r\n\t\ttriggerRandomDeathrattle(\r\n\t\t\tattackingEntity,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (attackingEntity.cardId === CardIds.MonstrousMacawBattlegrounds) {\r\n\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\ttriggerRandomDeathrattle(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tattackingEntity.attackImmediately = false;\r\n\tif (attackingEntity.enchantments.some((e) => e.cardId === CardIds.VolatileVenom_VolatileEnchantment)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tprocessMinionDeath(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\tattackingEntity.immuneWhenAttackCharges = Math.max(0, attackingEntity.immuneWhenAttackCharges - 1);\r\n};\r\n\r\nconst triggerRandomDeathrattle = (\r\n\tsourceEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst validDeathrattles = attackingBoard\r\n\t\t.filter((entity) => !excludeSource || entity.entityId !== sourceEntity.entityId)\r\n\t\t.filter((entity) => {\r\n\t\t\tif (hasMechanic(allCards.getCard(entity.cardId), 'DEATHRATTLE')) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tif (entity.rememberedDeathrattles?.length) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tentity.enchantments &&\r\n\t\t\t\tentity.enchantments\r\n\t\t\t\t\t.map((enchantment) => enchantment.cardId)\r\n\t\t\t\t\t.some((enchantmentId) => validEnchantments.includes(enchantmentId as CardIds))\r\n\t\t\t) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t});\r\n\tif (validDeathrattles.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst targetEntity = pickRandom(validDeathrattles);\r\n\tif (!targetEntity?.cardId) {\r\n\t\tconsole.error(\r\n\t\t\t'missing card id when triggering random deathrattle',\r\n\t\t\tstringifySimpleCard(targetEntity, allCards),\r\n\t\t\ttargetEntity,\r\n\t\t\tvalidDeathrattles.length,\r\n\t\t\tstringifySimple(validDeathrattles, allCards),\r\n\t\t\tstringifySimple(attackingBoard, allCards),\r\n\t\t\texcludeSource,\r\n\t\t\tstringifySimpleCard(sourceEntity, allCards),\r\n\t\t);\r\n\t}\r\n\tspectator.registerPowerTarget(sourceEntity, targetEntity, attackingBoard);\r\n\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(targetEntity) + 1);\r\n\tbuildBoardAfterDeathrattleSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\tindexFromRight,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\t[],\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\t// The reborn minion spawns to the right of the DR spawns\r\n\t// buildBoardAfterRebornSpawns(\r\n\t// \tattackingBoard,\r\n\t// \tattackingBoardHero,\r\n\t// \ttargetEntity,\r\n\t// \tindexFromRight,\r\n\t// \tdefendingBoard,\r\n\t// \tdefendingBoardHero,\r\n\t// \tallCards,\r\n\t// \tspawns,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nconst getAttackingEntity = (attackingBoard: BoardEntity[], lastAttackerIndex: number): BoardEntity => {\r\n\tlet validAttackers = attackingBoard.filter((entity) => canAttack(entity));\r\n\tif (validAttackers.length === 0) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tif (validAttackers.some((entity) => entity.attackImmediately)) {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => entity.attackImmediately);\r\n\t}\r\n\r\n\t// Once an entity has attacked, no entity to the left of it can attack until all entities\r\n\t// on the board have attacked\r\n\t// Once the last attacker index is the last entity on the board, we cycle back to the start\r\n\tif (lastAttackerIndex != null && lastAttackerIndex < validAttackers.length - 1) {\r\n\t\t// This doesn't work if any entity that appears before the attacked index died in-between\r\n\t\tconst candidates = validAttackers.slice(lastAttackerIndex);\r\n\t\tif (candidates.length > 0) {\r\n\t\t\tvalidAttackers = candidates;\r\n\t\t}\r\n\t}\r\n\r\n\tlet attackingEntity = validAttackers[0];\r\n\tlet minNumberOfAttacks: number = attackingEntity.attacksPerformed || 0;\r\n\tfor (const entity of validAttackers) {\r\n\t\tif ((entity.attacksPerformed || 0) < minNumberOfAttacks) {\r\n\t\t\tattackingEntity = entity;\r\n\t\t\tminNumberOfAttacks = entity.attacksPerformed;\r\n\t\t}\r\n\t}\r\n\r\n\tif (!attackingEntity.attackImmediately) {\r\n\t\tattackingEntity.attacksPerformed = (attackingEntity.attacksPerformed || 0) + 1;\r\n\t}\r\n\treturn attackingEntity;\r\n};\r\n\r\nexport const findNearestEnemies = (\r\n\tattackingBoard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tentityIndexFromRight: number,\r\n\tdefendingBoard: BoardEntity[],\r\n\tnumberOfTargets: number,\r\n\tallCards: AllCardsService,\r\n): BoardEntity[] => {\r\n\tconst result = [];\r\n\tif (defendingBoard.length > 0) {\r\n\t\t// console.debug('defending board', numberOfTargets, stringifySimple(defendingBoard, allCards));\r\n\t\tconst attackerIndex = attackingBoard.length - entityIndexFromRight - 1;\r\n\t\tconst targetIndex = attackerIndex - (attackingBoard.length - defendingBoard.length) / 2;\r\n\t\t// console.debug('indexes', attackerIndex, entityIndexFromRight, targetIndex, attackingBoard.length);\r\n\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst possibleTargets = defendingBoard\r\n\t\t\t\t.filter((e) => !e.definitelyDead && e.health > 0)\r\n\t\t\t\t.filter((e) => !result.includes(e));\r\n\t\t\t// console.debug('possibleTargets', stringifySimple(possibleTargets, allCards));\r\n\t\t\tif (!possibleTargets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tconst targetGroups = groupByFunction((e: BoardEntity) => Math.abs(defendingBoard.indexOf(e) - targetIndex))(\r\n\t\t\t\tpossibleTargets,\r\n\t\t\t);\r\n\t\t\tconst distances = Object.keys(targetGroups)\r\n\t\t\t\t.map((k) => +k)\r\n\t\t\t\t.sort();\r\n\t\t\tconst nearestDistance = distances[0];\r\n\t\t\tif (nearestDistance != null) {\r\n\t\t\t\t// console.debug(\r\n\t\t\t\t// \t'targetGroups[nearestDistance]',\r\n\t\t\t\t// \tnearestDistance,\r\n\t\t\t\t// \tstringifySimple(targetGroups[nearestDistance], allCards),\r\n\t\t\t\t// );\r\n\t\t\t\tconst target = pickRandom(targetGroups[nearestDistance]);\r\n\t\t\t\tresult.push(target);\r\n\t\t\t}\r\n\t\t\t// console.debug('\\n');\r\n\t\t}\r\n\t}\r\n\treturn result.filter((e) => !!e);\r\n};\r\n\r\nexport const getNeighbours = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\tif (deadEntityIndexFromRight != null) {\r\n\t\t// If the deadEntityIndexFromRight === 0 (right-most minion), no neighbour will be found\r\n\t\tconst rightNeighbourIndex = board.length - 1 - (deadEntityIndexFromRight - 1);\r\n\t\tconst rightNeighbour = board[rightNeighbourIndex];\r\n\t\tif (rightNeighbour) {\r\n\t\t\tneighbours.push(rightNeighbour);\r\n\t\t}\r\n\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\tneighbours.push(leftNeighbour);\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\tneighbours.push(board[index - 1]);\r\n\t\t}\r\n\t\t// neighbours.push(entity);\r\n\t\tif (index + 1 < board.length) {\r\n\t\t\tneighbours.push(board[index + 1]);\r\n\t\t}\r\n\t}\r\n\treturn neighbours;\r\n};\r\n\r\nexport const dealDamageToRandomEnemy = (\r\n\tboardToBeDamaged: BoardEntity[],\r\n\tboardToBeDamagedHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (boardToBeDamaged.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst validTargets = boardToBeDamaged.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tconst defendingEntity: BoardEntity = pickRandom(validTargets);\r\n\tif (defendingEntity) {\r\n\t\tspectator.registerPowerTarget(damageSource, defendingEntity, boardToBeDamaged);\r\n\t\tdealDamageToEnemy(\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tdamageSource,\r\n\t\t\tdamage,\r\n\t\t\tboardWithAttackOrigin,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const dealDamageToEnemy = (\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// console.log('dealing damage to', damage, stringifySimpleCard(defendingEntity, allCards));\r\n\tif (!defendingEntity) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tconst isDeadBeforeDamage = defendingEntity.definitelyDead || defendingEntity.health <= 0;\r\n\t// Why do we use a fakeAttacker? Is that for the \"attacking\" prop?\r\n\t// That prop is only used for Overkill, and even in that case it looks like it would work\r\n\t// without it\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damage,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tconst actualDamageDone = bumpEntities(\r\n\t\tdefendingEntity,\r\n\t\tfakeAttacker,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tboardWithAttackOrigin,\r\n\t\tboardWithAttackOriginHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t// cause wrong results to happen\r\n\tif (fakeAttacker.attack > 0 && defendingEntity.divineShield) {\r\n\t\tupdateDivineShield(defendingEntity, defendingBoard, false, allCards);\r\n\t}\r\n\tif (!isDeadBeforeDamage && actualDamageDone > 0) {\r\n\t\tdefendingEntity.lastAffectedByEntity = damageSource;\r\n\t}\r\n\tconst defendingEntityIndex = defendingBoard.map((entity) => entity.entityId).indexOf(defendingEntity.entityId);\r\n\tdefendingBoard[defendingEntityIndex] = defendingEntity;\r\n\treturn actualDamageDone;\r\n};\r\n\r\nexport const getDefendingEntity = (\r\n\tdefendingBoard: BoardEntity[],\r\n\tattackingEntity: BoardEntity,\r\n\tignoreTaunts = false,\r\n): BoardEntity => {\r\n\tlet possibleDefenders: readonly BoardEntity[];\r\n\tif (attackingEntity.cardId === CardIds.ZappSlywick || attackingEntity.cardId === CardIds.ZappSlywickBattlegrounds) {\r\n\t\tconst minAttack = Math.min(...defendingBoard.map((entity) => entity.attack));\r\n\t\tpossibleDefenders = defendingBoard.filter((entity) => entity.attack === minAttack);\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard.filter((e) => !e.stealth);\r\n\t\tif (!ignoreTaunts) {\r\n\t\t\tconst taunts = possibleDefenders.filter((entity) => entity.taunt);\r\n\t\t\tpossibleDefenders = taunts.length > 0 ? taunts : possibleDefenders;\r\n\t\t}\r\n\t}\r\n\tlet chosenDefender = possibleDefenders[Math.floor(Math.random() * possibleDefenders.length)];\r\n\tif (chosenDefender?.taunt) {\r\n\t\tconst elistras = defendingBoard.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_BGS_205 ||\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortalBattlegrounds,\r\n\t\t);\r\n\t\tif (elistras.length > 0) {\r\n\t\t\tchosenDefender = elistras[Math.floor(Math.random() * elistras.length)];\r\n\t\t}\r\n\t}\r\n\treturn chosenDefender;\r\n};\r\n\r\nexport const bumpEntities = (\r\n\tentity: BoardEntity,\r\n\tbumpInto: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// No attack has no impact\r\n\tif (bumpInto.attack === 0) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tif (entity.divineShield) {\r\n\t\t// Handle all the divine shield loss effects here\r\n\t\tfor (let i = 0; i < entityBoard.length; i++) {\r\n\t\t\tif (entityBoard[i].cardId === CardIds.BolvarFireblood_ICC_858) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.BolvarFirebloodBattlegrounds) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tmodifyHealth(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcerBattlegrounds) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tmodifyHealth(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].entityId !== entity.entityId &&\r\n\t\t\t\t(entityBoard[i].cardId === CardIds.HolyMecherel ||\r\n\t\t\t\t\tentityBoard[i].cardId === CardIds.HolyMecherelBattlegrounds)\r\n\t\t\t) {\r\n\t\t\t\tupdateDivineShield(entityBoard[i], entityBoard, true, allCards);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, allCards, spectator, [CardIds.BloodGem]);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037_G) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, allCards, spectator, [CardIds.BloodGem, CardIds.BloodGem]);\r\n\t\t\t}\r\n\r\n\t\t\t// So that self-buffs from Bolvar are taken into account\r\n\t\t\t// if (entityBoard[i].entityId === entity.entityId && entity.divineShield) {\r\n\t\t\t// \tupdateDivineShield(entityBoard[i], entityBoard, false, allCards);\r\n\t\t\t// }\r\n\t\t}\r\n\t\tconst greaseBots = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot);\r\n\t\tconst greaseBotBattlegrounds = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBotBattlegrounds);\r\n\t\tgreaseBots.forEach((bot) => {\r\n\t\t\tmodifyAttack(entity, 2, entityBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, entityBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(bot, entity, entityBoard);\r\n\t\t});\r\n\t\tgreaseBotBattlegrounds.forEach((bot) => {\r\n\t\t\tmodifyAttack(entity, 4, entityBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, entityBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(bot, entity, entityBoard);\r\n\t\t});\r\n\r\n\t\tspectator.registerDamageDealt(bumpInto, entity, 0, entityBoard);\r\n\t\treturn 0;\r\n\t\t// return entity;\r\n\t}\r\n\tentity.health = entity.health - (entity.damageMultiplier || 1) * bumpInto.attack;\r\n\r\n\tif (entity.cardId === CardIds.Bubblette_BG_TID_713 && bumpInto.attack === 1) {\r\n\t\tentity.definitelyDead = true;\r\n\t} else if (entity.cardId === CardIds.Bubblette_BG_TID_713_G && bumpInto.attack === 2) {\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\r\n\t// Do it last, so that other effects are still processed\r\n\tif (bumpInto.poisonous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\tif (bumpInto.venomous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t\tbumpInto.venomous = false;\r\n\t}\r\n\t// FIXME: This will likely be incorrect in terms of timings, e.g. if the entity ends up\r\n\t// surviving following a buff like Spawn.\r\n\tspectator.registerDamageDealt(bumpInto, entity, (entity.damageMultiplier || 1) * bumpInto.attack, entityBoard);\r\n\tentity.lastAffectedByEntity = bumpInto;\r\n\tif (!entity.frenzyApplied && entity.health > 0 && !entity.definitelyDead) {\r\n\t\tapplyFrenzy(entity, entityBoard, entityBoardHero, allCards, cardsData, sharedState, spectator);\r\n\t\tentity.frenzyApplied = true;\r\n\t}\r\n\r\n\t// We spawn them here, because it says \"whenever\", and so happens right away\r\n\t// FIXME: there could be a bug here, if a Cleave attacks several IGB at the same time. The current\r\n\t// implementation could spawn minions above the max board size. Fringe case though, so leaving it\r\n\t// like this for now\r\n\tconst entitySpawns = getWheneverEntitySpawns(\r\n\t\tentity,\r\n\t\tentityBoard,\r\n\t\tentityBoardHero,\r\n\t\totherBoard,\r\n\t\totherHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\tif (!!entitySpawns?.length) {\r\n\t\tconst index = entityBoard.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\taddMinionsToBoard(\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherHero,\r\n\t\t\tindex,\r\n\t\t\tentitySpawns,\r\n\t\t\tallCards,\r\n\t\t\tspectator,\r\n\t\t\tsharedState,\r\n\t\t);\r\n\t\tspectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t}\r\n\treturn bumpInto.attack;\r\n};\r\n\r\nconst getWheneverEntitySpawns = (\r\n\tentity: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): readonly BoardEntity[] => {\r\n\tif (entityBoard.length === 7) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tif (entity.cardId === CardIds.ImpGangBoss) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.ImpGangBoss_ImpToken,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.ImpGangBossBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.ImpGangBoss_ImpTokenBattlegrounds,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.ImpMama) {\r\n\t\treturn spawnEntities(\r\n\t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t).map((entity) => ({ ...entity, taunt: true }));\r\n\t} else if (entity.cardId === CardIds.ImpMamaBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n\t\t\t2,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t).map((entity) => ({ ...entity, taunt: true }));\r\n\t} else if (entity.cardId === CardIds.SecurityRover) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.SecurityRover_GuardBotToken,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.SecurityRoverBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.SecurityRover_GuardBotTokenBattlegrounds,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const processMinionDeath = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.debug('processing minions death', stringifySimple(board1, allCards), stringifySimple(board2, allCards));\r\n\tconst [deadMinionIndexesFromRights1, deadEntities1] = makeMinionsDie(board1, allCards, spectator);\r\n\tconst [deadMinionIndexesFromRights2, deadEntities2] = makeMinionsDie(board2, allCards, spectator);\r\n\tspectator.registerDeadEntities(\r\n\t\tdeadMinionIndexesFromRights1,\r\n\t\tdeadEntities1,\r\n\t\tboard1,\r\n\t\tdeadMinionIndexesFromRights2,\r\n\t\tdeadEntities2,\r\n\t\tboard2,\r\n\t);\r\n\t// No death to process, we can return\r\n\tif (deadEntities1.length === 0 && deadEntities2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\r\n\tsharedState.deaths.push(...deadEntities1);\r\n\tsharedState.deaths.push(...deadEntities2);\r\n\tboard1Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard1Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities1.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight || e.cardId === CardIds.EternalKnightBattlegrounds,\r\n\t\t).length;\r\n\tboard2Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard2Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities2.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight || e.cardId === CardIds.EternalKnightBattlegrounds,\r\n\t\t).length;\r\n\r\n\t// First process all DRs, then process the reborn\r\n\tif (Math.random() > 0.5) {\r\n\t\t// Now proceed to trigger all deathrattle effects on baord1\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Now handle the other board's deathrattles\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\r\n\t// Now the reborn\r\n\tif (Math.random() > 0.5) {\r\n\t\t// Now proceed to trigger all deathrattle effects on baord1\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Now handle the other board's deathrattles\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\r\n\t// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities1, cardsData, allCards, sharedState));\r\n\tboard2\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities2, cardsData, allCards, sharedState));\r\n\r\n\tboard1\r\n\t\t.filter((entity) => entity.cardId === CardIds.Monstrosity || entity.cardId === CardIds.MonstrosityBattlegrounds)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities1, board1, allCards));\r\n\tboard2\r\n\t\t.filter((entity) => entity.cardId === CardIds.Monstrosity || entity.cardId === CardIds.MonstrosityBattlegrounds)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities2, board2, allCards));\r\n\r\n\t// Make sure we only return when there are no more deaths to process\r\n\t// Make sure to do this right before the end of the process\r\n\t// FIXME: this will propagate the killer between rounds, which is incorrect. For instance,\r\n\t// if a dragon kills a Ghoul, then the Ghoul's deathrattle kills a Kaboom, the killer should\r\n\t// now be the ghoul. Then if the Kaboom kills someone, the killer should again change. You could\r\n\t// also have multiple killers, which is not taken into account here.\r\n\t// The current assumption is that it's a suffienctly fringe case to not matter too much\r\n\tprocessMinionDeath(board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n\r\n\t// Apply \"after minion death\" effects\r\n\thandleAfterMinionsDeaths(\r\n\t\tboard1,\r\n\t\tdeadEntities1,\r\n\t\tboard1Hero,\r\n\t\tboard2,\r\n\t\tdeadEntities2,\r\n\t\tboard2Hero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeaths = (\r\n\tboard1: BoardEntity[],\r\n\tdeadEntities1: BoardEntity[],\r\n\theroEntity1: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tdeadEntities2: BoardEntity[],\r\n\theroEntity2: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n) => {\r\n\tconst random = Math.random() > 0.5;\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\trandom ? board1 : board2,\r\n\t\trandom ? deadEntities1 : deadEntities2,\r\n\t\trandom ? heroEntity1 : heroEntity2,\r\n\t\trandom ? board2 : board1,\r\n\t\trandom ? deadEntities2 : deadEntities1,\r\n\t\trandom ? heroEntity2 : heroEntity1,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\t!random ? board1 : board2,\r\n\t\t!random ? deadEntities1 : deadEntities2,\r\n\t\t!random ? heroEntity1 : heroEntity2,\r\n\t\t!random ? board2 : board1,\r\n\t\t!random ? deadEntities2 : deadEntities1,\r\n\t\t!random ? heroEntity2 : heroEntity1,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeathsForBoard = (\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyDeadEntities: BoardEntity[],\r\n\tfriendlyHeroEntity: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherDeadEntities: BoardEntity[],\r\n\totherHeroEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n) => {\r\n\tfor (const deadEntity of friendlyDeadEntities) {\r\n\t\tconst killer = deadEntity.lastAffectedByEntity;\r\n\t\tif (!killer) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t// Killed an enemy minion\r\n\t\tif (killer.friendly !== deadEntity.friendly) {\r\n\t\t\tif (otherHeroEntity.heroPowerId === CardIds.Rokara_GloryOfCombat) {\r\n\t\t\t\tmodifyAttack(killer, 1, otherBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(killer, otherBoard, allCards);\r\n\t\t\t\t// Icesnarl the Mighty\r\n\t\t\t\totherBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.IcesnarlTheMighty ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.IcesnarlTheMightyBattlegrounds,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((icesnarl) => {\r\n\t\t\t\t\t\tmodifyHealth(\r\n\t\t\t\t\t\t\ticesnarl,\r\n\t\t\t\t\t\t\ticesnarl.cardId === CardIds.IcesnarlTheMightyBattlegrounds ? 2 : 1,\r\n\t\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tafterStatsUpdate(icesnarl, friendlyBoard, allCards);\r\n\t\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst handleDeathrattlesForFirstBoard = (\r\n\tfirstBoard: BoardEntity[],\r\n\tfirstBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tdeadMinionIndexesFromRight: readonly number[],\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n\t\t\tbuildBoardAfterDeathrattleSpawns(\r\n\t\t\t\tfirstBoard,\r\n\t\t\t\tfirstBoardHero,\r\n\t\t\t\tentity,\r\n\t\t\t\tindexFromRight,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntities,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n\t\t\t// firstBoard = newBoardD;\r\n\t\t}\r\n\t}\r\n\t// return [firstBoard, otherBoard];\r\n};\r\n\r\nconst handleRebornForFirstBoard = (\r\n\tfirstBoard: BoardEntity[],\r\n\tfirstBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tdeadMinionIndexesFromRight: readonly number[],\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.log('will handle reborn', stringifySimple(firstBoard, allCards), deadMinionIndexesFromRight);\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n\t\t\tif (!entity?.cardId) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t'missing card id for entity that died',\r\n\t\t\t\t\tstringifySimpleCard(entity, allCards),\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\tdeadMinionIndexesFromRight,\r\n\t\t\t\t\tstringifySimple(firstBoard, allCards),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\t// console.log('dead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n\t\t\tbuildBoardAfterRebornSpawns(\r\n\t\t\t\tfirstBoard,\r\n\t\t\t\tfirstBoardHero,\r\n\t\t\t\tentity,\r\n\t\t\t\tindexFromRight,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\t// console.log('after rebord', stringifySimple(firstBoard, allCards));\r\n\t\t} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n\t\t\t// firstBoard = newBoardD;\r\n\t\t}\r\n\t}\r\n\t// return [firstBoard, otherBoard];\r\n};\r\n\r\nexport const applyOnAttackBuffs = (\r\n\tattacker: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attacker.cardId === CardIds.GlyphGuardian_BGS_045) {\r\n\t\t// For now the utility method only works additively, so we hack around it\r\n\t\tmodifyAttack(attacker, 2 * attacker.attack - attacker.attack, attackingBoard, allCards);\r\n\t}\r\n\tif (attacker.cardId === CardIds.GlyphGuardianBattlegrounds) {\r\n\t\tmodifyAttack(attacker, 3 * attacker.attack - attacker.attack, attackingBoard, allCards);\r\n\t}\r\n\r\n\t// Ripsnarl Captain\r\n\tif (isCorrectTribe(allCards.getCard(attacker.cardId).races, Race.PIRATE)) {\r\n\t\tconst ripsnarls = attackingBoard.filter((e) => e.cardId === CardIds.RipsnarlCaptain);\r\n\t\tconst ripsnarlsTB = attackingBoard.filter((entity) => entity.cardId === CardIds.RipsnarlCaptainBattlegrounds);\r\n\t\tripsnarls.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 3, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, attacker, attackingBoard);\r\n\t\t});\r\n\t\tripsnarlsTB.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 6, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, attacker, attackingBoard);\r\n\t\t});\r\n\t}\r\n\r\n\t// Dread Admiral Eliza\r\n\tif (isCorrectTribe(allCards.getCard(attacker.cardId).races, Race.PIRATE)) {\r\n\t\tconst elizas = attackingBoard.filter((e) => e.cardId === CardIds.DreadAdmiralEliza);\r\n\t\tconst elizasTB = attackingBoard.filter((e) => e.cardId === CardIds.DreadAdmiralElizaBattlegrounds);\r\n\r\n\t\telizas.forEach((eliza) => {\r\n\t\t\tattackingBoard.forEach((entity) => {\r\n\t\t\t\tmodifyAttack(entity, 2, attackingBoard, allCards);\r\n\t\t\t\tmodifyHealth(entity, 1, attackingBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(eliza, entity, attackingBoard);\r\n\t\t\t});\r\n\t\t});\r\n\t\telizasTB.forEach((eliza) => {\r\n\t\t\tattackingBoard.forEach((entity) => {\r\n\t\t\t\tmodifyAttack(entity, 4, attackingBoard, allCards);\r\n\t\t\t\tmodifyHealth(entity, 2, attackingBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(eliza, entity, attackingBoard);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattacker.cardId === CardIds.VanessaVancleef_BG24_708 ||\r\n\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds\r\n\t) {\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => isCorrectTribe(allCards.getCard(e.cardId).races, Race.PIRATE))\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tmodifyAttack(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds ? 4 : 2,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t);\r\n\t\t\t\tmodifyHealth(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds ? 4 : 2,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t);\r\n\t\t\t\tspectator.registerPowerTarget(attacker, e, attackingBoard);\r\n\t\t\t});\r\n\t}\r\n};\r\n\r\nexport const applyOnBeingAttackedBuffs = (\r\n\tattackerEntity: BoardEntity,\r\n\tattackedEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attackedEntity.taunt) {\r\n\t\tconst champions = defendingBoard.filter((entity) => entity.cardId === CardIds.ChampionOfYshaarj);\r\n\t\tconst goldenChampions = defendingBoard.filter(\r\n\t\t\t(entity) => entity.cardId === CardIds.ChampionOfYshaarjBattlegrounds,\r\n\t\t);\r\n\t\tchampions.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 1, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(entity, entity, defendingBoard);\r\n\t\t});\r\n\t\tgoldenChampions.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(entity, entity, defendingBoard);\r\n\t\t});\r\n\r\n\t\tconst arms = defendingBoard.filter((entity) => entity.cardId === CardIds.ArmOfTheEmpire);\r\n\t\tconst goldenArms = defendingBoard.filter((entity) => entity.cardId === CardIds.ArmOfTheEmpireBattlegrounds);\r\n\t\tarms.forEach((arm) => {\r\n\t\t\tmodifyAttack(attackedEntity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(arm, attackedEntity, defendingBoard);\r\n\t\t});\r\n\t\tgoldenArms.forEach((arm) => {\r\n\t\t\tmodifyAttack(attackedEntity, 4, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(arm, attackedEntity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.TormentedRitualist) {\r\n\t\tconst neighbours = getNeighbours(defendingBoard, attackedEntity);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 1, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attackedEntity, entity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.TormentedRitualistBattlegrounds) {\r\n\t\tconst neighbours = getNeighbours(defendingBoard, attackedEntity);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attackedEntity, entity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.DozyWhelp || attackedEntity.cardId === CardIds.DozyWhelpBattlegrounds) {\r\n\t\tmodifyAttack(\r\n\t\t\tattackedEntity,\r\n\t\t\tattackedEntity.cardId === CardIds.DozyWhelpBattlegrounds ? 2 : 1,\r\n\t\t\tdefendingBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tspectator.registerPowerTarget(attackedEntity, attackedEntity, defendingBoard);\r\n\t}\r\n\tif (\r\n\t\tattackerEntity.cardId === CardIds.SindoreiStraightShot ||\r\n\t\tattackerEntity.cardId === CardIds.SindoreiStraightShotBattlegrounds\r\n\t) {\r\n\t\tattackedEntity.taunt = false;\r\n\t\tattackedEntity.reborn = false;\r\n\t}\r\n};\r\n\r\nconst makeMinionsDie = (\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): [number[], BoardEntity[]] => {\r\n\t// Because entities spawn to the left, so the right index is unchanged\r\n\tconst deadMinionIndexesFromRight: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexesFromRight.push(board.length - (i + 1));\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\tremoveMinionFromBoard(board, i, allCards, spectator);\r\n\t\t\t// We modify the original array, so we need to update teh current index accordingly\r\n\t\t\ti--;\r\n\t\t}\r\n\t}\r\n\t// Treat all dead entities as a single block\r\n\tconst blockIndexesFromRight = [...deadMinionIndexesFromRight];\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tif (i === deadMinionIndexesFromRight.length - 1) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (Math.abs(deadMinionIndexesFromRight[i] - deadMinionIndexesFromRight[i + 1]) <= 1) {\r\n\t\t\tblockIndexesFromRight[i] = blockIndexesFromRight[i + 1];\r\n\t\t} else {\r\n\t\t\t// blockIndexesFromRight[i] = blockIndexesFromRight[i];\r\n\t\t}\r\n\t}\r\n\treturn [blockIndexesFromRight, deadEntities];\r\n};\r\n\r\n// const handleKillEffects = (\r\n// \tboardWithKilledMinion: BoardEntity[],\r\n// \tkillerBoard: BoardEntity[],\r\n// \tdeadEntity: BoardEntity,\r\n// \tallCards: AllCardsService,\r\n// \tspectator: Spectator,\r\n// ): void => {\r\n// \tif (\r\n// \t\tdeadEntity.lastAffectedByEntity?.cardId &&\r\n// \t\tisCorrectTribe(allCards.getCard(deadEntity.lastAffectedByEntity.cardId).race, Race.DRAGON)\r\n// \t) {\r\n// \t\tfor (const entity of killerBoard) {\r\n// \t\t\tif (entity.cardId === CardIds.WaxriderTogwaggle2) {\r\n// \t\t\t\tmodifyAttack(entity, 2, killerBoard, allCards);\r\n// \t\t\t\tmodifyHealth(entity, 2, killerBoard, allCards);\r\n// \t\t\t\tafterStatsUpdate(entity, killerBoard, allCards);\r\n// \t\t\t\tspectator.registerPowerTarget(entity, entity, killerBoard);\r\n// \t\t\t} else if (entity.cardId === CardIds.WaxriderTogwaggleBattlegrounds) {\r\n// \t\t\t\tmodifyAttack(entity, 4, killerBoard, allCards);\r\n// \t\t\t\tmodifyHealth(entity, 4, killerBoard, allCards);\r\n// \t\t\t\tafterStatsUpdate(entity, killerBoard, allCards);\r\n// \t\t\t\tspectator.registerPowerTarget(entity, entity, killerBoard);\r\n// \t\t\t}\r\n// \t\t}\r\n// \t}\r\n// };\r\n\r\nconst buildBoardAfterDeathrattleSpawns = (\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndexFromRight2: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tentitiesDeadThisAttack: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// TODO: don't apply this for FishOfNZoth\r\n\t// if (deadMinionIndex >= 0) {\r\n\t// \thandleKillEffects(boardWithKilledMinion, opponentBoard, deadEntity, allCards, spectator);\r\n\t// }\r\n\r\n\t// But Wildfire Element is applied first, before the DR spawns\r\n\tif (deadMinionIndexFromRight2 >= 0) {\r\n\t\tapplyMinionDeathEffect(\r\n\t\t\tdeadEntity,\r\n\t\t\tdeadMinionIndexFromRight2,\r\n\t\t\tboardWithKilledMinion,\r\n\t\t\tboardWithKilledMinionHero,\r\n\t\t\topponentBoard,\r\n\t\t\topponentBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\tconst entitiesFromNativeDeathrattle: readonly BoardEntity[] = spawnEntitiesFromDeathrattle(\r\n\t\tdeadEntity,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tentitiesDeadThisAttack,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst entitiesFromEnchantments: readonly BoardEntity[] = spawnEntitiesFromEnchantments(\r\n\t\tdeadEntity,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst candidateEntities: readonly BoardEntity[] = [...entitiesFromNativeDeathrattle, ...entitiesFromEnchantments];\r\n\tperformEntitySpawns(\r\n\t\tcandidateEntities,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\t// In case of leapfrogger, we want to first spawn the minions, then apply the frog effect\r\n\thandleDeathrattleEffects(\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\t// eslint-disable-next-line prettier/prettier\r\n\tif (deadEntity.rememberedDeathrattles?.length) {\r\n\t\tfor (const deathrattle of deadEntity.rememberedDeathrattles) {\r\n\t\t\tconst entityToProcess: BoardEntity = {\r\n\t\t\t\t...deadEntity,\r\n\t\t\t\trememberedDeathrattles: undefined,\r\n\t\t\t\tcardId: deathrattle.cardId,\r\n\t\t\t\tenchantments: [\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcardId: deathrattle.cardId,\r\n\t\t\t\t\t\toriginEntityId: deadEntity.entityId,\r\n\t\t\t\t\t\trepeats: deathrattle.repeats ?? 1,\r\n\t\t\t\t\t\ttiming: deathrattle.timing,\r\n\t\t\t\t\t},\r\n\t\t\t\t],\r\n\t\t\t};\r\n\t\t\tbuildBoardAfterDeathrattleSpawns(\r\n\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\tentityToProcess,\r\n\t\t\t\tdeadMinionIndexFromRight2,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\r\n\t\t\t\tentitiesDeadThisAttack,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\t// TODO: check if Avenge effects should proc after deathrattles instead\r\n\t// They most certainly do, since the rat pack + avenge beast buffer works\r\n\tapplyAvengeEffects(\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst buildBoardAfterRebornSpawns = (\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndexFromRight: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst numberOfReborns = 1;\r\n\t// Reborn happens after deathrattles\r\n\tif (!deadEntity.cardId) {\r\n\t\tconsole.error('missing card id for dead entity', stringifySimpleCard(deadEntity, allCards), deadEntity);\r\n\t}\r\n\tlet entityToSpawn: BoardEntity = null;\r\n\t// TODO: test\r\n\tif (deadEntity.cardId === CardIds.SinrunnerBlanchy || deadEntity.cardId === CardIds.SinrunnerBlanchyBattlegrounds) {\r\n\t\tentityToSpawn = {\r\n\t\t\t...deadEntity,\r\n\t\t\thealth: deadEntity.maxHealth,\r\n\t\t\tdivineShield: deadEntity.hadDivineShield,\r\n\t\t\treborn: false,\r\n\t\t};\r\n\t}\r\n\tconst entitiesFromReborn: readonly BoardEntity[] =\r\n\t\tdeadEntity.reborn && deadMinionIndexFromRight >= 0\r\n\t\t\t? spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\tnumberOfReborns,\r\n\t\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\t\topponentBoard,\r\n\t\t\t\t\topponentBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\tentityToSpawn,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t )\r\n\t\t\t: [];\r\n\tconst entitiesThatWereReborn = performEntitySpawns(\r\n\t\tentitiesFromReborn,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst arfus = boardWithKilledMinion\r\n\t\t.filter((e) => e.cardId === CardIds.ArfusBattlegrounds_TB_BaconShop_HERO_22_Buddy)\r\n\t\t.map((e) => e.attack)\r\n\t\t.reduce((a, b) => a + b, 0);\r\n\tconst goldenArfus = boardWithKilledMinion\r\n\t\t.filter((e) => e.cardId === CardIds.ArfusBattlegrounds_TB_BaconShop_HERO_22_Buddy_G)\r\n\t\t.map((e) => 2 * e.attack)\r\n\t\t.reduce((a, b) => a + b, 0);\r\n\tif (arfus + goldenArfus > 0) {\r\n\t\tentitiesThatWereReborn.forEach((e) => {\r\n\t\t\tmodifyAttack(e, arfus + goldenArfus, boardWithKilledMinion, allCards);\r\n\t\t\tafterStatsUpdate(e, boardWithKilledMinion, allCards);\r\n\t\t});\r\n\t}\r\n\r\n\tconst numberOfTriggersForDeathwhisper = Math.min(entitiesFromReborn.length, 1);\r\n\tfor (let i = 0; i < numberOfTriggersForDeathwhisper; i++) {\r\n\t\tboardWithKilledMinion\r\n\t\t\t.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.SisterDeathwhisper || e.cardId === CardIds.SisterDeathwhisperBattlegrounds,\r\n\t\t\t)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tconst multiplier = e.cardId === CardIds.SisterDeathwhisperBattlegrounds ? 2 : 1;\r\n\t\t\t\taddStatsToBoard(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\t\tmultiplier * 1,\r\n\t\t\t\t\tmultiplier * 2,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t\tRace[Race.UNDEAD],\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\tboardWithKilledMinion\r\n\t\t\t.filter((e) => e.cardId === CardIds.JellyBelly || e.cardId === CardIds.JellyBellyBattlegrounds)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tconst multiplier = e.cardId === CardIds.JellyBellyBattlegrounds ? 2 : 1;\r\n\t\t\t\tmodifyAttack(e, multiplier * 3, boardWithKilledMinion, allCards);\r\n\t\t\t\tmodifyHealth(e, multiplier * 3, boardWithKilledMinion, allCards);\r\n\t\t\t\tafterStatsUpdate(e, boardWithKilledMinion, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(e, e, boardWithKilledMinion);\r\n\t\t\t});\r\n\t}\r\n};\r\n\r\nexport const performEntitySpawns = (\r\n\tcandidateEntities: readonly BoardEntity[],\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tspawnSourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tspawnSourceEntityIndexFromRight: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): readonly BoardEntity[] => {\r\n\tconst aliveEntites = candidateEntities.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tconst spawnedEntities = [];\r\n\tfor (const newMinion of aliveEntites) {\r\n\t\t// All entities have been spawned\r\n\t\tif (boardWithKilledMinion.length >= 7) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\t// Avoid minions spawning backwards (we don't have this issue if we add all elements at\r\n\t\t// the same time, but here we want to be able to attack after each spawn, which in turn\r\n\t\t// means that the minion can die before the other one spawns)\r\n\t\t// In boardWithKilledMinion, the dead minion has already been removed\r\n\t\tconst indexToSpawnAt = boardWithKilledMinion.length - spawnSourceEntityIndexFromRight;\r\n\t\taddMinionToBoard(\r\n\t\t\tboardWithKilledMinion,\r\n\t\t\tboardWithKilledMinionHero,\r\n\t\t\topponentBoardHero,\r\n\t\t\tindexToSpawnAt,\r\n\t\t\tnewMinion,\r\n\t\t\tallCards,\r\n\t\t\tspectator,\r\n\t\t\tsharedState,\r\n\t\t);\r\n\t\tif (newMinion.attackImmediately) {\r\n\t\t\t// Whenever we are already in a combat phase, we need to first clean up the state\r\n\t\t\tsimulateAttack(\r\n\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\r\n\t\t\t\tnull,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (newMinion.health > 0 && !newMinion.definitelyDead) {\r\n\t\t\tspawnedEntities.push(newMinion);\r\n\t\t}\r\n\t}\r\n\r\n\tspectator.registerMinionsSpawn(spawnSourceEntity, boardWithKilledMinion, spawnedEntities);\r\n\treturn spawnedEntities;\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"attack.js","sourceRoot":"","sources":["../../src/simulation/attack.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAI9E,6CAAgE;AAChE,gEAA2D;AAC3D,oCAckB;AAClB,+DAA4E;AAC5E,qCAA8C;AAC9C,+DAK+B;AAC/B,6DAAkH;AAClH,qCAAuC;AACvC,yEAAmE;AAGnE,uDAAiD;AAG1C,MAAM,cAAc,GAAG,CAC7B,cAA6B,EAC7B,k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,EAClC,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACxB,SAAoB,EACK,EAAE;IAC3B,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACvG,MAAM,eAAe,GAAG,EAAE,CAAC;IAC3B,KAAK,MAAM,SAAS,IAAI,YAAY,EAAE;QAErC,IAAI,qBAAqB,CAAC,MAAM,IAAI,CAAC,EAAE;YACtC,MAAM;SACN;QAKD,MAAM,cAAc,GAAG,qBAAqB,CAAC,MAAM,GAAG,+BAA+B,CAAC;QACtF,IAAA,sCAAgB,EACf,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,QAAQ,EACR,SAAS,EACT,WAAW,CACX,CAAC;QACF,IAAI,SAAS,CAAC,iBAAiB,EAAE;YAEhC,IAAA,sBAAc,EACb,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,CACT,CAAC;SACF;QACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE;YACtD,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAChC;KACD;IAED,SAAS,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,qBAAqB,EAAE,eAAe,CAAC,CAAC;IAC1F,OAAO,eAAe,CAAC;AACxB,CAAC,CAAC;AAxDW,QAAA,mBAAmB,uBAwD9B","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData } from '../cards/cards-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { validEnchantments } from '../simulate-bgs-battle';\r\nimport {\r\n\taddCardsInHand,\r\n\taddStatsToBoard,\r\n\tafterStatsUpdate,\r\n\tgrantStatsToMinionsOfEachType,\r\n\thasCorrectTribe,\r\n\thasMechanic,\r\n\tisCorrectTribe,\r\n\tisFish,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n\tstringifySimple,\r\n\tstringifySimpleCard,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { addMinionToBoard, addMinionsToBoard } from './add-minion-to-board';\r\nimport { applyAvengeEffects } from './avenge';\r\nimport {\r\n\tapplyMinionDeathEffect,\r\n\tapplyMonstrosity,\r\n\thandleDeathrattleEffects,\r\n\trememberDeathrattles,\r\n} from './deathrattle-effects';\r\nimport { spawnEntities, spawnEntitiesFromDeathrattle, spawnEntitiesFromEnchantments } from './deathrattle-spawns';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { removeMinionFromBoard } from './remove-minion-from-board';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { canAttack } from './utils/entity-utils';\r\n\r\n// Only use it to simulate actual attack. To simulate damage, or something similar, use bumpInto\r\nexport const simulateAttack = (\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tlastAttackerEntityId: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n\tforceAttackingEntityIndex?: number,\r\n): number => {\r\n\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst attackingEntity =\r\n\t\tforceAttackingEntityIndex != null\r\n\t\t\t? attackingBoard[forceAttackingEntityIndex]\r\n\t\t\t: getAttackingEntity(attackingBoard, lastAttackerEntityId);\r\n\tconst attackingEntityIndex = attackingBoard.map((e) => e.entityId).indexOf(attackingEntity?.entityId);\r\n\tif (attackingEntity) {\r\n\t\tattackingEntity.attacking = true;\r\n\t\t// console.log('attack by', stringifySimpleCard(attackingEntity, allCards), stringifySimple(defendingBoard, allCards));\r\n\t\tconst numberOfAttacks = attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// We refresh the entity in case of windfury\r\n\t\t\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t// Check that didn't die\r\n\t\t\tif (attackingBoard.find((entity) => entity.entityId === attackingEntity.entityId)) {\r\n\t\t\t\tapplyOnAttackBuffs(attackingEntity, attackingBoard, allCards, spectator);\r\n\t\t\t\tconst defendingEntity: BoardEntity = getDefendingEntity(defendingBoard, attackingEntity);\r\n\t\t\t\t// Can happen with a single defender that has stealth\r\n\t\t\t\tif (defendingEntity) {\r\n\t\t\t\t\t// console.log(\r\n\t\t\t\t\t// \t'AATTTTTTTTTTTAAAAAAAAAAAAAAAAAACK by',\r\n\t\t\t\t\t// \tstringifySimpleCard(attackingEntity, allCards),\r\n\t\t\t\t\t// \tstringifySimpleCard(defendingEntity, allCards),\r\n\t\t\t\t\t// \tstringifySimple(attackingBoard, allCards),\r\n\t\t\t\t\t// );\r\n\t\t\t\t\tspectator.registerAttack(attackingEntity, defendingEntity, attackingBoard, defendingBoard);\r\n\t\t\t\t\tapplyOnBeingAttackedBuffs(attackingEntity, defendingEntity, defendingBoard, allCards, spectator);\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tapplyAfterAttackEffects(attackingEntity, attackingBoard, attackingBoardHero, allCards, spectator);\r\n\t\t\t\t\tprocessMinionDeath(\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\tdefendingEntity.health > 0 &&\r\n\t\t\t\t\t\t!defendingEntity.definitelyDead &&\r\n\t\t\t\t\t\t(defendingEntity.cardId === CardIds.YoHoOgre ||\r\n\t\t\t\t\t\t\tdefendingEntity.cardId === CardIds.YoHoOgreBattlegrounds)\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\tdefendingEntity.attackImmediately = true;\r\n\t\t\t\t\t\tif (defendingEntity.attackImmediately) {\r\n\t\t\t\t\t\t\tsimulateAttack(\r\n\t\t\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// console.debug(\r\n\t\t\t\t\t// \t'after attack by',\r\n\t\t\t\t\t// \tstringifySimpleCard(attackingEntity, allCards),\r\n\t\t\t\t\t// \t'\\n',\r\n\t\t\t\t\t// \tstringifySimple(attackingBoard, allCards),\r\n\t\t\t\t\t// \t'\\n',\r\n\t\t\t\t\t// \tstringifySimple(defendingBoard, allCards),\r\n\t\t\t\t\t// );\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Solves the edge case of Sky Pirate vs a stealth board\r\n\t\t\t\t\tattackingEntity.attackImmediately = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tattackingEntity.attacking = false;\r\n\t}\r\n\t// If entities that were before the attacker died, we need to update the attacker index\r\n\treturn attackingEntityIndex;\r\n};\r\n\r\nconst applyAfterAttackEffects = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attackingEntity.cardId === CardIds.Bonker_BG20_104 || attackingEntity.cardId === CardIds.Bonker_BG20_104_G) {\r\n\t\tconst quantity = attackingEntity.cardId === CardIds.Bonker_BG20_104_G ? 2 : 1;\r\n\t\tconst cards = quantity === 1 ? [CardIds.BloodGem] : [CardIds.BloodGem, CardIds.BloodGem];\r\n\t\taddCardsInHand(attackingBoardHero, attackingBoard, allCards, spectator, cards);\r\n\t} else if (attackingEntity.cardId === CardIds.Yrel_BG23_350 || attackingEntity.cardId === CardIds.Yrel_BG23_350_G) {\r\n\t\tconst modifier = attackingEntity.cardId === CardIds.Yrel_BG23_350_G ? 2 : 1;\r\n\t\tgrantStatsToMinionsOfEachType(attackingEntity, attackingBoard, modifier * 1, modifier * 2, allCards, spectator);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117 ||\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117_G\r\n\t) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\t// Putricide-only\r\n\telse if (attackingEntity.additionalCards?.includes(CardIds.IncorporealCorporal_BG26_RLK_117)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tattackingBoard\r\n\t\t.filter((e) => e.additionalCards?.includes(CardIds.FesterootHulk_BG_GIL_655))\r\n\t\t.forEach((e) => {\r\n\t\t\tmodifyAttack(e, 1, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(e, attackingBoard, allCards);\r\n\t\t});\r\n\r\n\tattackingEntity.stealth = false;\r\n};\r\n\r\nconst performAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (hasCorrectTribe(attackingEntity, Race.DRAGON, allCards)) {\r\n\t\tconst prestors = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attackingEntity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012 ||\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012_G,\r\n\t\t\t);\r\n\t\tprestors.forEach((prestor) => {\r\n\t\t\tspectator.registerPowerTarget(prestor, defendingEntity, defendingBoard);\r\n\t\t\tdealDamageToEnemy(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tprestor,\r\n\t\t\t\tprestor.cardId === CardIds.PrestorsPyrospawn_BG21_012_G ? 6 : 3,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362 ||\r\n\t\tattackingEntity.cardId === CardIds.AtramedesBattlegrounds\r\n\t) {\r\n\t\tconst targets = [defendingEntity, ...getNeighbours(defendingBoard, defendingEntity)];\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.AtramedesBattlegrounds ? 2 : 1;\r\n\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\ttargets.forEach((target) => {\r\n\t\t\t\tspectator.registerPowerTarget(attackingEntity, target, defendingBoard);\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tif ([CardIds.BabyKrush_BG22_001, CardIds.BabyKrush_BG22_001_G].includes(attackingEntity.cardId as CardIds)) {\r\n\t\tconst spawns = spawnEntities(\r\n\t\t\tattackingEntity.cardId === CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t? CardIds.DevilsaurBattlegrounds\r\n\t\t\t\t: CardIds.BabyKrush_DevilsaurToken,\r\n\t\t\t1,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\ttrue,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tif (spawns.length > 0) {\r\n\t\t\tconst sourceIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\t\tconst actualSpawns = performEntitySpawns(\r\n\t\t\t\tspawns,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tsourceIndex,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\tfor (const actualSpawn of actualSpawns) {\r\n\t\t\t\tif (defendingEntity.health > 0 && !defendingEntity.definitelyDead) {\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tactualSpawn,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tcardsData,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// For Prestor\r\n\tconst defenderAliveBeforeAttack = defendingEntity.health > 0 && !defendingEntity.definitelyDead;\r\n\tif (defenderAliveBeforeAttack) {\r\n\t\tif (!attackingEntity.immuneWhenAttackCharges || attackingEntity.immuneWhenAttackCharges <= 0) {\r\n\t\t\tbumpEntities(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tbumpEntities(\r\n\t\t\tdefendingEntity,\r\n\t\t\tattackingEntity,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t// cause wrong results to happen\r\n\t\tif (defendingEntity.attack > 0 && attackingEntity.divineShield) {\r\n\t\t\tupdateDivineShield(attackingEntity, attackingBoard, false, allCards);\r\n\t\t}\r\n\t\tif (attackingEntity.attack > 0 && defendingEntity.divineShield) {\r\n\t\t\tupdateDivineShield(defendingEntity, defendingBoard, false, allCards);\r\n\t\t}\r\n\t}\r\n\t// Cleave\r\n\tif (attackingEntity.cleave) {\r\n\t\tconst defenderNeighbours: readonly BoardEntity[] = getNeighbours(defendingBoard, defendingEntity);\r\n\t\tfor (const neighbour of defenderNeighbours) {\r\n\t\t\tbumpEntities(\r\n\t\t\t\tneighbour,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t\t// cause wrong results to happen\r\n\t\t\tif (attackingEntity.attack > 0 && neighbour.divineShield) {\r\n\t\t\t\tupdateDivineShield(neighbour, defendingBoard, false, allCards);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\t(defendingEntity.health <= 0 || defendingEntity.definitelyDead) &&\r\n\t\t(attackingEntity.cardId === CardIds.WildfireElemental ||\r\n\t\t\tattackingEntity.cardId === CardIds.WildfireElementalBattlegrounds)\r\n\t) {\r\n\t\tconst excessDamage = -defendingEntity.health;\r\n\t\tconst neighbours = getNeighbours(defendingBoard, defendingEntity);\r\n\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\tif (neighbours.length > 0) {\r\n\t\t\tif (attackingEntity.cardId === CardIds.WildfireElemental) {\r\n\t\t\t\tconst randomTarget = neighbours[Math.floor(Math.random() * neighbours.length)];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\trandomTarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tneighbours.forEach((neighbour) =>\r\n\t\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\t\tneighbour,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\t\texcessDamage,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\tcardsData,\r\n\t\t\t\t\t\tsharedState,\r\n\t\t\t\t\t\tspectator,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// After attack hooks\r\n\t// Arcane Cannon\r\n\t// Monstrous Macaw\r\n\tif (attackingEntity.cardId === CardIds.MonstrousMacaw) {\r\n\t\ttriggerRandomDeathrattle(\r\n\t\t\tattackingEntity,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (attackingEntity.cardId === CardIds.MonstrousMacawBattlegrounds) {\r\n\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\ttriggerRandomDeathrattle(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tattackingEntity.attackImmediately = false;\r\n\tif (attackingEntity.enchantments.some((e) => e.cardId === CardIds.VolatileVenom_VolatileEnchantment)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tprocessMinionDeath(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\tattackingEntity.immuneWhenAttackCharges = Math.max(0, attackingEntity.immuneWhenAttackCharges - 1);\r\n};\r\n\r\nconst triggerRandomDeathrattle = (\r\n\tsourceEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst validDeathrattles = attackingBoard\r\n\t\t.filter((entity) => !excludeSource || entity.entityId !== sourceEntity.entityId)\r\n\t\t.filter((entity) => {\r\n\t\t\tif (hasMechanic(allCards.getCard(entity.cardId), 'DEATHRATTLE')) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tif (entity.rememberedDeathrattles?.length) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tentity.enchantments &&\r\n\t\t\t\tentity.enchantments\r\n\t\t\t\t\t.map((enchantment) => enchantment.cardId)\r\n\t\t\t\t\t.some((enchantmentId) => validEnchantments.includes(enchantmentId as CardIds))\r\n\t\t\t) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t});\r\n\tif (validDeathrattles.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst targetEntity = pickRandom(validDeathrattles);\r\n\tif (!targetEntity?.cardId) {\r\n\t\tconsole.error(\r\n\t\t\t'missing card id when triggering random deathrattle',\r\n\t\t\tstringifySimpleCard(targetEntity, allCards),\r\n\t\t\ttargetEntity,\r\n\t\t\tvalidDeathrattles.length,\r\n\t\t\tstringifySimple(validDeathrattles, allCards),\r\n\t\t\tstringifySimple(attackingBoard, allCards),\r\n\t\t\texcludeSource,\r\n\t\t\tstringifySimpleCard(sourceEntity, allCards),\r\n\t\t);\r\n\t}\r\n\tspectator.registerPowerTarget(sourceEntity, targetEntity, attackingBoard);\r\n\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(targetEntity) + 1);\r\n\tbuildBoardAfterDeathrattleSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\tindexFromRight,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\t[],\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\t// The reborn minion spawns to the right of the DR spawns\r\n\t// buildBoardAfterRebornSpawns(\r\n\t// \tattackingBoard,\r\n\t// \tattackingBoardHero,\r\n\t// \ttargetEntity,\r\n\t// \tindexFromRight,\r\n\t// \tdefendingBoard,\r\n\t// \tdefendingBoardHero,\r\n\t// \tallCards,\r\n\t// \tspawns,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nconst getAttackingEntity = (attackingBoard: BoardEntity[], lastAttackerIndex: number): BoardEntity => {\r\n\tlet validAttackers = attackingBoard.filter((entity) => canAttack(entity));\r\n\tif (validAttackers.length === 0) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tif (validAttackers.some((entity) => entity.attackImmediately)) {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => entity.attackImmediately);\r\n\t}\r\n\r\n\t// Once an entity has attacked, no entity to the left of it can attack until all entities\r\n\t// on the board have attacked\r\n\t// Once the last attacker index is the last entity on the board, we cycle back to the start\r\n\tif (lastAttackerIndex != null && lastAttackerIndex < validAttackers.length - 1) {\r\n\t\t// This doesn't work if any entity that appears before the attacked index died in-between\r\n\t\tconst candidates = validAttackers.slice(lastAttackerIndex);\r\n\t\tif (candidates.length > 0) {\r\n\t\t\tvalidAttackers = candidates;\r\n\t\t}\r\n\t}\r\n\r\n\tlet attackingEntity = validAttackers[0];\r\n\tlet minNumberOfAttacks: number = attackingEntity.attacksPerformed || 0;\r\n\tfor (const entity of validAttackers) {\r\n\t\tif ((entity.attacksPerformed || 0) < minNumberOfAttacks) {\r\n\t\t\tattackingEntity = entity;\r\n\t\t\tminNumberOfAttacks = entity.attacksPerformed;\r\n\t\t}\r\n\t}\r\n\r\n\tif (!attackingEntity.attackImmediately) {\r\n\t\tattackingEntity.attacksPerformed = (attackingEntity.attacksPerformed || 0) + 1;\r\n\t}\r\n\treturn attackingEntity;\r\n};\r\n\r\nexport const findNearestEnemies = (\r\n\tattackingBoard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tentityIndexFromRight: number,\r\n\tdefendingBoard: BoardEntity[],\r\n\tnumberOfTargets: number,\r\n\tallCards: AllCardsService,\r\n): BoardEntity[] => {\r\n\tconst result = [];\r\n\tif (defendingBoard.length > 0) {\r\n\t\t// console.debug('defending board', numberOfTargets, stringifySimple(defendingBoard, allCards));\r\n\t\tconst attackerIndex = attackingBoard.length - entityIndexFromRight - 1;\r\n\t\tconst targetIndex = attackerIndex - (attackingBoard.length - defendingBoard.length) / 2;\r\n\t\t// console.debug('indexes', attackerIndex, entityIndexFromRight, targetIndex, attackingBoard.length);\r\n\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst possibleTargets = defendingBoard\r\n\t\t\t\t.filter((e) => !e.definitelyDead && e.health > 0)\r\n\t\t\t\t.filter((e) => !result.includes(e));\r\n\t\t\t// console.debug('possibleTargets', stringifySimple(possibleTargets, allCards));\r\n\t\t\tif (!possibleTargets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tconst targetGroups = groupByFunction((e: BoardEntity) => Math.abs(defendingBoard.indexOf(e) - targetIndex))(\r\n\t\t\t\tpossibleTargets,\r\n\t\t\t);\r\n\t\t\tconst distances = Object.keys(targetGroups)\r\n\t\t\t\t.map((k) => +k)\r\n\t\t\t\t.sort();\r\n\t\t\tconst nearestDistance = distances[0];\r\n\t\t\tif (nearestDistance != null) {\r\n\t\t\t\t// console.debug(\r\n\t\t\t\t// \t'targetGroups[nearestDistance]',\r\n\t\t\t\t// \tnearestDistance,\r\n\t\t\t\t// \tstringifySimple(targetGroups[nearestDistance], allCards),\r\n\t\t\t\t// );\r\n\t\t\t\tconst target = pickRandom(targetGroups[nearestDistance]);\r\n\t\t\t\tresult.push(target);\r\n\t\t\t}\r\n\t\t\t// console.debug('\\n');\r\n\t\t}\r\n\t}\r\n\treturn result.filter((e) => !!e);\r\n};\r\n\r\nexport const getNeighbours = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\tif (deadEntityIndexFromRight != null) {\r\n\t\t// If the deadEntityIndexFromRight === 0 (right-most minion), no neighbour will be found\r\n\t\tconst rightNeighbourIndex = board.length - 1 - (deadEntityIndexFromRight - 1);\r\n\t\tconst rightNeighbour = board[rightNeighbourIndex];\r\n\t\tif (rightNeighbour) {\r\n\t\t\tneighbours.push(rightNeighbour);\r\n\t\t}\r\n\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\tneighbours.push(leftNeighbour);\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\tneighbours.push(board[index - 1]);\r\n\t\t}\r\n\t\t// neighbours.push(entity);\r\n\t\tif (index + 1 < board.length) {\r\n\t\t\tneighbours.push(board[index + 1]);\r\n\t\t}\r\n\t}\r\n\treturn neighbours;\r\n};\r\n\r\nexport const dealDamageToRandomEnemy = (\r\n\tboardToBeDamaged: BoardEntity[],\r\n\tboardToBeDamagedHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (boardToBeDamaged.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst validTargets = boardToBeDamaged.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tconst defendingEntity: BoardEntity = pickRandom(validTargets);\r\n\tif (defendingEntity) {\r\n\t\tspectator.registerPowerTarget(damageSource, defendingEntity, boardToBeDamaged);\r\n\t\tdealDamageToEnemy(\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tdamageSource,\r\n\t\t\tdamage,\r\n\t\t\tboardWithAttackOrigin,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const dealDamageToEnemy = (\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// console.log('dealing damage to', damage, stringifySimpleCard(defendingEntity, allCards));\r\n\tif (!defendingEntity) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tconst isDeadBeforeDamage = defendingEntity.definitelyDead || defendingEntity.health <= 0;\r\n\t// Why do we use a fakeAttacker? Is that for the \"attacking\" prop?\r\n\t// That prop is only used for Overkill, and even in that case it looks like it would work\r\n\t// without it\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damage,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tconst actualDamageDone = bumpEntities(\r\n\t\tdefendingEntity,\r\n\t\tfakeAttacker,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tboardWithAttackOrigin,\r\n\t\tboardWithAttackOriginHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t// cause wrong results to happen\r\n\tif (fakeAttacker.attack > 0 && defendingEntity.divineShield) {\r\n\t\tupdateDivineShield(defendingEntity, defendingBoard, false, allCards);\r\n\t}\r\n\tif (!isDeadBeforeDamage && actualDamageDone > 0) {\r\n\t\tdefendingEntity.lastAffectedByEntity = damageSource;\r\n\t}\r\n\tconst defendingEntityIndex = defendingBoard.map((entity) => entity.entityId).indexOf(defendingEntity.entityId);\r\n\tdefendingBoard[defendingEntityIndex] = defendingEntity;\r\n\treturn actualDamageDone;\r\n};\r\n\r\nexport const getDefendingEntity = (\r\n\tdefendingBoard: BoardEntity[],\r\n\tattackingEntity: BoardEntity,\r\n\tignoreTaunts = false,\r\n): BoardEntity => {\r\n\tlet possibleDefenders: readonly BoardEntity[];\r\n\tif (attackingEntity.cardId === CardIds.ZappSlywick || attackingEntity.cardId === CardIds.ZappSlywickBattlegrounds) {\r\n\t\tconst minAttack = Math.min(...defendingBoard.map((entity) => entity.attack));\r\n\t\tpossibleDefenders = defendingBoard.filter((entity) => entity.attack === minAttack);\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard.filter((e) => !e.stealth);\r\n\t\tif (!ignoreTaunts) {\r\n\t\t\tconst taunts = possibleDefenders.filter((entity) => entity.taunt);\r\n\t\t\tpossibleDefenders = taunts.length > 0 ? taunts : possibleDefenders;\r\n\t\t}\r\n\t}\r\n\tlet chosenDefender = possibleDefenders[Math.floor(Math.random() * possibleDefenders.length)];\r\n\tif (chosenDefender?.taunt) {\r\n\t\tconst elistras = defendingBoard.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_BGS_205 ||\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortalBattlegrounds,\r\n\t\t);\r\n\t\tif (elistras.length > 0) {\r\n\t\t\tchosenDefender = elistras[Math.floor(Math.random() * elistras.length)];\r\n\t\t}\r\n\t}\r\n\treturn chosenDefender;\r\n};\r\n\r\nexport const bumpEntities = (\r\n\tentity: BoardEntity,\r\n\tbumpInto: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// No attack has no impact\r\n\tif (bumpInto.attack === 0) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tif (entity.divineShield) {\r\n\t\t// Handle all the divine shield loss effects here\r\n\t\tfor (let i = 0; i < entityBoard.length; i++) {\r\n\t\t\tif (entityBoard[i].cardId === CardIds.BolvarFireblood_ICC_858) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.BolvarFirebloodBattlegrounds) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tmodifyHealth(entityBoard[i], 2, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcerBattlegrounds) {\r\n\t\t\t\tmodifyAttack(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tmodifyHealth(entityBoard[i], 4, entityBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(entityBoard[i], entityBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(entityBoard[i], entityBoard[i], entityBoard);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].entityId !== entity.entityId &&\r\n\t\t\t\t(entityBoard[i].cardId === CardIds.HolyMecherel ||\r\n\t\t\t\t\tentityBoard[i].cardId === CardIds.HolyMecherelBattlegrounds)\r\n\t\t\t) {\r\n\t\t\t\tupdateDivineShield(entityBoard[i], entityBoard, true, allCards);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, allCards, spectator, [CardIds.BloodGem]);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037_G) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, allCards, spectator, [CardIds.BloodGem, CardIds.BloodGem]);\r\n\t\t\t}\r\n\r\n\t\t\t// So that self-buffs from Bolvar are taken into account\r\n\t\t\t// if (entityBoard[i].entityId === entity.entityId && entity.divineShield) {\r\n\t\t\t// \tupdateDivineShield(entityBoard[i], entityBoard, false, allCards);\r\n\t\t\t// }\r\n\t\t}\r\n\t\tconst greaseBots = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot);\r\n\t\tconst greaseBotBattlegrounds = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBotBattlegrounds);\r\n\t\tgreaseBots.forEach((bot) => {\r\n\t\t\tmodifyAttack(entity, 2, entityBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, entityBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(bot, entity, entityBoard);\r\n\t\t});\r\n\t\tgreaseBotBattlegrounds.forEach((bot) => {\r\n\t\t\tmodifyAttack(entity, 4, entityBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, entityBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(bot, entity, entityBoard);\r\n\t\t});\r\n\r\n\t\tspectator.registerDamageDealt(bumpInto, entity, 0, entityBoard);\r\n\t\treturn 0;\r\n\t\t// return entity;\r\n\t}\r\n\tentity.health = entity.health - (entity.damageMultiplier || 1) * bumpInto.attack;\r\n\r\n\tif (entity.cardId === CardIds.Bubblette_BG_TID_713 && bumpInto.attack === 1) {\r\n\t\tentity.definitelyDead = true;\r\n\t} else if (entity.cardId === CardIds.Bubblette_BG_TID_713_G && bumpInto.attack === 2) {\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\r\n\t// Do it last, so that other effects are still processed\r\n\tif (bumpInto.poisonous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\tif (bumpInto.venomous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t\tbumpInto.venomous = false;\r\n\t}\r\n\t// FIXME: This will likely be incorrect in terms of timings, e.g. if the entity ends up\r\n\t// surviving following a buff like Spawn.\r\n\tspectator.registerDamageDealt(bumpInto, entity, (entity.damageMultiplier || 1) * bumpInto.attack, entityBoard);\r\n\tentity.lastAffectedByEntity = bumpInto;\r\n\tif (!entity.frenzyApplied && entity.health > 0 && !entity.definitelyDead) {\r\n\t\tapplyFrenzy(entity, entityBoard, entityBoardHero, allCards, cardsData, sharedState, spectator);\r\n\t\tentity.frenzyApplied = true;\r\n\t}\r\n\r\n\t// We spawn them here, because it says \"whenever\", and so happens right away\r\n\t// FIXME: there could be a bug here, if a Cleave attacks several IGB at the same time. The current\r\n\t// implementation could spawn minions above the max board size. Fringe case though, so leaving it\r\n\t// like this for now\r\n\tconst entitySpawns = getWheneverEntitySpawns(\r\n\t\tentity,\r\n\t\tentityBoard,\r\n\t\tentityBoardHero,\r\n\t\totherBoard,\r\n\t\totherHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\tif (!!entitySpawns?.length) {\r\n\t\tconst index = entityBoard.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\taddMinionsToBoard(\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherHero,\r\n\t\t\tindex,\r\n\t\t\tentitySpawns,\r\n\t\t\tallCards,\r\n\t\t\tspectator,\r\n\t\t\tsharedState,\r\n\t\t);\r\n\t\tspectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t}\r\n\treturn bumpInto.attack;\r\n};\r\n\r\nconst getWheneverEntitySpawns = (\r\n\tentity: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): readonly BoardEntity[] => {\r\n\tif (entityBoard.length === 7) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tif (entity.cardId === CardIds.ImpGangBoss) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.ImpGangBoss_ImpToken,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.ImpGangBossBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.ImpGangBoss_ImpTokenBattlegrounds,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.ImpMama) {\r\n\t\treturn spawnEntities(\r\n\t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t).map((entity) => ({ ...entity, taunt: true }));\r\n\t} else if (entity.cardId === CardIds.ImpMamaBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n\t\t\t2,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t).map((entity) => ({ ...entity, taunt: true }));\r\n\t} else if (entity.cardId === CardIds.SecurityRover) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.SecurityRover_GuardBotToken,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t} else if (entity.cardId === CardIds.SecurityRoverBattlegrounds) {\r\n\t\treturn spawnEntities(\r\n\t\t\tCardIds.SecurityRover_GuardBotTokenBattlegrounds,\r\n\t\t\t1,\r\n\t\t\tentityBoard,\r\n\t\t\tentityBoardHero,\r\n\t\t\totherBoard,\r\n\t\t\totherHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tentity.friendly,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const processMinionDeath = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.debug('processing minions death', stringifySimple(board1, allCards), stringifySimple(board2, allCards));\r\n\tconst [deadMinionIndexesFromRights1, deadEntities1] = makeMinionsDie(board1, allCards, spectator);\r\n\tconst [deadMinionIndexesFromRights2, deadEntities2] = makeMinionsDie(board2, allCards, spectator);\r\n\tspectator.registerDeadEntities(\r\n\t\tdeadMinionIndexesFromRights1,\r\n\t\tdeadEntities1,\r\n\t\tboard1,\r\n\t\tdeadMinionIndexesFromRights2,\r\n\t\tdeadEntities2,\r\n\t\tboard2,\r\n\t);\r\n\t// No death to process, we can return\r\n\tif (deadEntities1.length === 0 && deadEntities2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\r\n\tsharedState.deaths.push(...deadEntities1);\r\n\tsharedState.deaths.push(...deadEntities2);\r\n\tboard1Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard1Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities1.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight || e.cardId === CardIds.EternalKnightBattlegrounds,\r\n\t\t).length;\r\n\tboard2Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard2Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities2.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight || e.cardId === CardIds.EternalKnightBattlegrounds,\r\n\t\t).length;\r\n\r\n\t// First process all DRs, then process the reborn\r\n\tif (Math.random() > 0.5) {\r\n\t\t// Now proceed to trigger all deathrattle effects on baord1\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Now handle the other board's deathrattles\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\thandleDeathrattlesForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\r\n\t// Now the reborn\r\n\tif (Math.random() > 0.5) {\r\n\t\t// Now proceed to trigger all deathrattle effects on baord1\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\t// Now handle the other board's deathrattles\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tdeadMinionIndexesFromRights2,\r\n\t\t\tdeadEntities2,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\thandleRebornForFirstBoard(\r\n\t\t\tboard1,\r\n\t\t\tboard1Hero,\r\n\t\t\tboard2,\r\n\t\t\tboard2Hero,\r\n\t\t\tdeadMinionIndexesFromRights1,\r\n\t\t\tdeadEntities1,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\r\n\t// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities1, cardsData, allCards, sharedState));\r\n\tboard2\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities2, cardsData, allCards, sharedState));\r\n\r\n\tboard1\r\n\t\t.filter((entity) => entity.cardId === CardIds.Monstrosity || entity.cardId === CardIds.MonstrosityBattlegrounds)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities1, board1, allCards));\r\n\tboard2\r\n\t\t.filter((entity) => entity.cardId === CardIds.Monstrosity || entity.cardId === CardIds.MonstrosityBattlegrounds)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities2, board2, allCards));\r\n\r\n\t// Make sure we only return when there are no more deaths to process\r\n\t// Make sure to do this right before the end of the process\r\n\t// FIXME: this will propagate the killer between rounds, which is incorrect. For instance,\r\n\t// if a dragon kills a Ghoul, then the Ghoul's deathrattle kills a Kaboom, the killer should\r\n\t// now be the ghoul. Then if the Kaboom kills someone, the killer should again change. You could\r\n\t// also have multiple killers, which is not taken into account here.\r\n\t// The current assumption is that it's a suffienctly fringe case to not matter too much\r\n\tprocessMinionDeath(board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n\r\n\t// Apply \"after minion death\" effects\r\n\thandleAfterMinionsDeaths(\r\n\t\tboard1,\r\n\t\tdeadEntities1,\r\n\t\tboard1Hero,\r\n\t\tboard2,\r\n\t\tdeadEntities2,\r\n\t\tboard2Hero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeaths = (\r\n\tboard1: BoardEntity[],\r\n\tdeadEntities1: BoardEntity[],\r\n\theroEntity1: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tdeadEntities2: BoardEntity[],\r\n\theroEntity2: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n) => {\r\n\tconst random = Math.random() > 0.5;\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\trandom ? board1 : board2,\r\n\t\trandom ? deadEntities1 : deadEntities2,\r\n\t\trandom ? heroEntity1 : heroEntity2,\r\n\t\trandom ? board2 : board1,\r\n\t\trandom ? deadEntities2 : deadEntities1,\r\n\t\trandom ? heroEntity2 : heroEntity1,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\t!random ? board1 : board2,\r\n\t\t!random ? deadEntities1 : deadEntities2,\r\n\t\t!random ? heroEntity1 : heroEntity2,\r\n\t\t!random ? board2 : board1,\r\n\t\t!random ? deadEntities2 : deadEntities1,\r\n\t\t!random ? heroEntity2 : heroEntity1,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeathsForBoard = (\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyDeadEntities: BoardEntity[],\r\n\tfriendlyHeroEntity: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherDeadEntities: BoardEntity[],\r\n\totherHeroEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n) => {\r\n\tfor (const deadEntity of friendlyDeadEntities) {\r\n\t\tconst killer = deadEntity.lastAffectedByEntity;\r\n\t\tif (!killer) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t// Killed an enemy minion\r\n\t\tif (killer.friendly !== deadEntity.friendly) {\r\n\t\t\tif (otherHeroEntity.heroPowerId === CardIds.Rokara_GloryOfCombat) {\r\n\t\t\t\tmodifyAttack(killer, 1, otherBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(killer, otherBoard, allCards);\r\n\t\t\t\t// Icesnarl the Mighty\r\n\t\t\t\totherBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.IcesnarlTheMighty ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.IcesnarlTheMightyBattlegrounds,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((icesnarl) => {\r\n\t\t\t\t\t\tmodifyHealth(\r\n\t\t\t\t\t\t\ticesnarl,\r\n\t\t\t\t\t\t\ticesnarl.cardId === CardIds.IcesnarlTheMightyBattlegrounds ? 2 : 1,\r\n\t\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\t\tallCards,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tafterStatsUpdate(icesnarl, friendlyBoard, allCards);\r\n\t\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst handleDeathrattlesForFirstBoard = (\r\n\tfirstBoard: BoardEntity[],\r\n\tfirstBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tdeadMinionIndexesFromRight: readonly number[],\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n\t\t\tbuildBoardAfterDeathrattleSpawns(\r\n\t\t\t\tfirstBoard,\r\n\t\t\t\tfirstBoardHero,\r\n\t\t\t\tentity,\r\n\t\t\t\tindexFromRight,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntities,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n\t\t\t// firstBoard = newBoardD;\r\n\t\t}\r\n\t}\r\n\t// return [firstBoard, otherBoard];\r\n};\r\n\r\nconst handleRebornForFirstBoard = (\r\n\tfirstBoard: BoardEntity[],\r\n\tfirstBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tdeadMinionIndexesFromRight: readonly number[],\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.log('will handle reborn', stringifySimple(firstBoard, allCards), deadMinionIndexesFromRight);\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n\t\t\tif (!entity?.cardId) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t'missing card id for entity that died',\r\n\t\t\t\t\tstringifySimpleCard(entity, allCards),\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\tdeadMinionIndexesFromRight,\r\n\t\t\t\t\tstringifySimple(firstBoard, allCards),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\t// console.log('dead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n\t\t\tbuildBoardAfterRebornSpawns(\r\n\t\t\t\tfirstBoard,\r\n\t\t\t\tfirstBoardHero,\r\n\t\t\t\tentity,\r\n\t\t\t\tindexFromRight,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t\t// console.log('after rebord', stringifySimple(firstBoard, allCards));\r\n\t\t} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n\t\t\t// firstBoard = newBoardD;\r\n\t\t}\r\n\t}\r\n\t// return [firstBoard, otherBoard];\r\n};\r\n\r\nexport const applyOnAttackBuffs = (\r\n\tattacker: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attacker.cardId === CardIds.GlyphGuardian_BGS_045) {\r\n\t\t// For now the utility method only works additively, so we hack around it\r\n\t\tmodifyAttack(attacker, 2 * attacker.attack - attacker.attack, attackingBoard, allCards);\r\n\t}\r\n\tif (attacker.cardId === CardIds.GlyphGuardianBattlegrounds) {\r\n\t\tmodifyAttack(attacker, 3 * attacker.attack - attacker.attack, attackingBoard, allCards);\r\n\t}\r\n\r\n\t// Ripsnarl Captain\r\n\tif (isCorrectTribe(allCards.getCard(attacker.cardId).races, Race.PIRATE)) {\r\n\t\tconst ripsnarls = attackingBoard.filter((e) => e.cardId === CardIds.RipsnarlCaptain);\r\n\t\tconst ripsnarlsTB = attackingBoard.filter((entity) => entity.cardId === CardIds.RipsnarlCaptainBattlegrounds);\r\n\t\tripsnarls.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 3, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, attacker, attackingBoard);\r\n\t\t});\r\n\t\tripsnarlsTB.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 6, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, attacker, attackingBoard);\r\n\t\t});\r\n\t}\r\n\r\n\t// Dread Admiral Eliza\r\n\tif (isCorrectTribe(allCards.getCard(attacker.cardId).races, Race.PIRATE)) {\r\n\t\tconst elizas = attackingBoard.filter((e) => e.cardId === CardIds.DreadAdmiralEliza);\r\n\t\tconst elizasTB = attackingBoard.filter((e) => e.cardId === CardIds.DreadAdmiralElizaBattlegrounds);\r\n\r\n\t\telizas.forEach((eliza) => {\r\n\t\t\tattackingBoard.forEach((entity) => {\r\n\t\t\t\tmodifyAttack(entity, 2, attackingBoard, allCards);\r\n\t\t\t\tmodifyHealth(entity, 1, attackingBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(eliza, entity, attackingBoard);\r\n\t\t\t});\r\n\t\t});\r\n\t\telizasTB.forEach((eliza) => {\r\n\t\t\tattackingBoard.forEach((entity) => {\r\n\t\t\t\tmodifyAttack(entity, 4, attackingBoard, allCards);\r\n\t\t\t\tmodifyHealth(entity, 2, attackingBoard, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(eliza, entity, attackingBoard);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattacker.cardId === CardIds.VanessaVancleef_BG24_708 ||\r\n\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds\r\n\t) {\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => isCorrectTribe(allCards.getCard(e.cardId).races, Race.PIRATE))\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tmodifyAttack(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds ? 4 : 2,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t);\r\n\t\t\t\tmodifyHealth(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattacker.cardId === CardIds.VanessaVancleefBattlegrounds ? 4 : 2,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t);\r\n\t\t\t\tspectator.registerPowerTarget(attacker, e, attackingBoard);\r\n\t\t\t});\r\n\t}\r\n};\r\n\r\nexport const applyOnBeingAttackedBuffs = (\r\n\tattackerEntity: BoardEntity,\r\n\tattackedEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (attackedEntity.taunt) {\r\n\t\tconst champions = defendingBoard.filter((entity) => entity.cardId === CardIds.ChampionOfYshaarj);\r\n\t\tconst goldenChampions = defendingBoard.filter(\r\n\t\t\t(entity) => entity.cardId === CardIds.ChampionOfYshaarjBattlegrounds,\r\n\t\t);\r\n\t\tchampions.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 1, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(entity, entity, defendingBoard);\r\n\t\t});\r\n\t\tgoldenChampions.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(entity, entity, defendingBoard);\r\n\t\t});\r\n\r\n\t\tconst arms = defendingBoard.filter((entity) => entity.cardId === CardIds.ArmOfTheEmpire);\r\n\t\tconst goldenArms = defendingBoard.filter((entity) => entity.cardId === CardIds.ArmOfTheEmpireBattlegrounds);\r\n\t\tarms.forEach((arm) => {\r\n\t\t\tmodifyAttack(attackedEntity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(arm, attackedEntity, defendingBoard);\r\n\t\t});\r\n\t\tgoldenArms.forEach((arm) => {\r\n\t\t\tmodifyAttack(attackedEntity, 4, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(arm, attackedEntity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.TormentedRitualist) {\r\n\t\tconst neighbours = getNeighbours(defendingBoard, attackedEntity);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 1, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 1, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attackedEntity, entity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.TormentedRitualistBattlegrounds) {\r\n\t\tconst neighbours = getNeighbours(defendingBoard, attackedEntity);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2, defendingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2, defendingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attackedEntity, entity, defendingBoard);\r\n\t\t});\r\n\t}\r\n\tif (attackedEntity.cardId === CardIds.DozyWhelp || attackedEntity.cardId === CardIds.DozyWhelpBattlegrounds) {\r\n\t\tmodifyAttack(\r\n\t\t\tattackedEntity,\r\n\t\t\tattackedEntity.cardId === CardIds.DozyWhelpBattlegrounds ? 2 : 1,\r\n\t\t\tdefendingBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tspectator.registerPowerTarget(attackedEntity, attackedEntity, defendingBoard);\r\n\t}\r\n\tif (\r\n\t\tattackerEntity.cardId === CardIds.SindoreiStraightShot ||\r\n\t\tattackerEntity.cardId === CardIds.SindoreiStraightShotBattlegrounds\r\n\t) {\r\n\t\tattackedEntity.taunt = false;\r\n\t\tattackedEntity.reborn = false;\r\n\t}\r\n};\r\n\r\nconst makeMinionsDie = (\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): [number[], BoardEntity[]] => {\r\n\t// Because entities spawn to the left, so the right index is unchanged\r\n\tconst deadMinionIndexesFromRight: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexesFromRight.push(board.length - (i + 1));\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\tremoveMinionFromBoard(board, i, allCards, spectator);\r\n\t\t\t// We modify the original array, so we need to update teh current index accordingly\r\n\t\t\ti--;\r\n\t\t}\r\n\t}\r\n\t// Treat all dead entities as a single block\r\n\tconst blockIndexesFromRight = [...deadMinionIndexesFromRight];\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tif (i === deadMinionIndexesFromRight.length - 1) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (Math.abs(deadMinionIndexesFromRight[i] - deadMinionIndexesFromRight[i + 1]) <= 1) {\r\n\t\t\tblockIndexesFromRight[i] = blockIndexesFromRight[i + 1];\r\n\t\t} else {\r\n\t\t\t// blockIndexesFromRight[i] = blockIndexesFromRight[i];\r\n\t\t}\r\n\t}\r\n\treturn [blockIndexesFromRight, deadEntities];\r\n};\r\n\r\n// const handleKillEffects = (\r\n// \tboardWithKilledMinion: BoardEntity[],\r\n// \tkillerBoard: BoardEntity[],\r\n// \tdeadEntity: BoardEntity,\r\n// \tallCards: AllCardsService,\r\n// \tspectator: Spectator,\r\n// ): void => {\r\n// \tif (\r\n// \t\tdeadEntity.lastAffectedByEntity?.cardId &&\r\n// \t\tisCorrectTribe(allCards.getCard(deadEntity.lastAffectedByEntity.cardId).race, Race.DRAGON)\r\n// \t) {\r\n// \t\tfor (const entity of killerBoard) {\r\n// \t\t\tif (entity.cardId === CardIds.WaxriderTogwaggle2) {\r\n// \t\t\t\tmodifyAttack(entity, 2, killerBoard, allCards);\r\n// \t\t\t\tmodifyHealth(entity, 2, killerBoard, allCards);\r\n// \t\t\t\tafterStatsUpdate(entity, killerBoard, allCards);\r\n// \t\t\t\tspectator.registerPowerTarget(entity, entity, killerBoard);\r\n// \t\t\t} else if (entity.cardId === CardIds.WaxriderTogwaggleBattlegrounds) {\r\n// \t\t\t\tmodifyAttack(entity, 4, killerBoard, allCards);\r\n// \t\t\t\tmodifyHealth(entity, 4, killerBoard, allCards);\r\n// \t\t\t\tafterStatsUpdate(entity, killerBoard, allCards);\r\n// \t\t\t\tspectator.registerPowerTarget(entity, entity, killerBoard);\r\n// \t\t\t}\r\n// \t\t}\r\n// \t}\r\n// };\r\n\r\nconst buildBoardAfterDeathrattleSpawns = (\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndexFromRight2: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tentitiesDeadThisAttack: readonly BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// TODO: don't apply this for FishOfNZoth\r\n\t// if (deadMinionIndex >= 0) {\r\n\t// \thandleKillEffects(boardWithKilledMinion, opponentBoard, deadEntity, allCards, spectator);\r\n\t// }\r\n\r\n\t// But Wildfire Element is applied first, before the DR spawns\r\n\tif (deadMinionIndexFromRight2 >= 0) {\r\n\t\tapplyMinionDeathEffect(\r\n\t\t\tdeadEntity,\r\n\t\t\tdeadMinionIndexFromRight2,\r\n\t\t\tboardWithKilledMinion,\r\n\t\t\tboardWithKilledMinionHero,\r\n\t\t\topponentBoard,\r\n\t\t\topponentBoardHero,\r\n\t\t\tallCards,\r\n\t\t\tcardsData,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\tconst entitiesFromNativeDeathrattle: readonly BoardEntity[] = spawnEntitiesFromDeathrattle(\r\n\t\tdeadEntity,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tentitiesDeadThisAttack,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst entitiesFromEnchantments: readonly BoardEntity[] = spawnEntitiesFromEnchantments(\r\n\t\tdeadEntity,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst candidateEntities: readonly BoardEntity[] = [...entitiesFromNativeDeathrattle, ...entitiesFromEnchantments];\r\n\tperformEntitySpawns(\r\n\t\tcandidateEntities,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\t// In case of leapfrogger, we want to first spawn the minions, then apply the frog effect\r\n\thandleDeathrattleEffects(\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\t// eslint-disable-next-line prettier/prettier\r\n\tif (deadEntity.rememberedDeathrattles?.length) {\r\n\t\tfor (const deathrattle of deadEntity.rememberedDeathrattles) {\r\n\t\t\tconst entityToProcess: BoardEntity = {\r\n\t\t\t\t...deadEntity,\r\n\t\t\t\trememberedDeathrattles: undefined,\r\n\t\t\t\tcardId: deathrattle.cardId,\r\n\t\t\t\tenchantments: [\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcardId: deathrattle.cardId,\r\n\t\t\t\t\t\toriginEntityId: deadEntity.entityId,\r\n\t\t\t\t\t\trepeats: deathrattle.repeats ?? 1,\r\n\t\t\t\t\t\ttiming: deathrattle.timing,\r\n\t\t\t\t\t},\r\n\t\t\t\t],\r\n\t\t\t};\r\n\t\t\tbuildBoardAfterDeathrattleSpawns(\r\n\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\tentityToProcess,\r\n\t\t\t\tdeadMinionIndexFromRight2,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\r\n\t\t\t\tentitiesDeadThisAttack,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\t// TODO: check if Avenge effects should proc after deathrattles instead\r\n\t// They most certainly do, since the rat pack + avenge beast buffer works\r\n\tapplyAvengeEffects(\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight2,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n};\r\n\r\nconst buildBoardAfterRebornSpawns = (\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndexFromRight: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst numberOfReborns = 1;\r\n\t// Reborn happens after deathrattles\r\n\tif (!deadEntity.cardId) {\r\n\t\tconsole.error('missing card id for dead entity', stringifySimpleCard(deadEntity, allCards), deadEntity);\r\n\t}\r\n\tlet entityToSpawn: BoardEntity = null;\r\n\t// TODO: test\r\n\tif (deadEntity.cardId === CardIds.SinrunnerBlanchy || deadEntity.cardId === CardIds.SinrunnerBlanchyBattlegrounds) {\r\n\t\tentityToSpawn = {\r\n\t\t\t...deadEntity,\r\n\t\t\thealth: deadEntity.maxHealth,\r\n\t\t\tdivineShield: deadEntity.hadDivineShield,\r\n\t\t\treborn: false,\r\n\t\t};\r\n\t}\r\n\tconst entitiesFromReborn: readonly BoardEntity[] =\r\n\t\tdeadEntity.reborn && deadMinionIndexFromRight >= 0\r\n\t\t\t? spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\tnumberOfReborns,\r\n\t\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\t\topponentBoard,\r\n\t\t\t\t\topponentBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tcardsData,\r\n\t\t\t\t\tsharedState,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\tentityToSpawn,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t )\r\n\t\t\t: [];\r\n\tconst entitiesThatWereReborn = performEntitySpawns(\r\n\t\tentitiesFromReborn,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndexFromRight,\r\n\t\topponentBoard,\r\n\t\topponentBoardHero,\r\n\t\tallCards,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tspectator,\r\n\t);\r\n\r\n\tconst arfus = boardWithKilledMinion\r\n\t\t.filter((e) => e.cardId === CardIds.ArfusBattlegrounds_TB_BaconShop_HERO_22_Buddy)\r\n\t\t.map((e) => e.attack)\r\n\t\t.reduce((a, b) => a + b, 0);\r\n\tconst goldenArfus = boardWithKilledMinion\r\n\t\t.filter((e) => e.cardId === CardIds.ArfusBattlegrounds_TB_BaconShop_HERO_22_Buddy_G)\r\n\t\t.map((e) => 2 * e.attack)\r\n\t\t.reduce((a, b) => a + b, 0);\r\n\tif (arfus + goldenArfus > 0) {\r\n\t\tentitiesThatWereReborn.forEach((e) => {\r\n\t\t\tmodifyAttack(e, arfus + goldenArfus, boardWithKilledMinion, allCards);\r\n\t\t\tafterStatsUpdate(e, boardWithKilledMinion, allCards);\r\n\t\t});\r\n\t}\r\n\r\n\tconst numberOfTriggersForDeathwhisper = Math.min(entitiesFromReborn.length, 1);\r\n\tfor (let i = 0; i < numberOfTriggersForDeathwhisper; i++) {\r\n\t\tboardWithKilledMinion\r\n\t\t\t.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.SisterDeathwhisper || e.cardId === CardIds.SisterDeathwhisperBattlegrounds,\r\n\t\t\t)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tconst multiplier = e.cardId === CardIds.SisterDeathwhisperBattlegrounds ? 2 : 1;\r\n\t\t\t\taddStatsToBoard(\r\n\t\t\t\t\te,\r\n\t\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\t\tmultiplier * 1,\r\n\t\t\t\t\tmultiplier * 2,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tspectator,\r\n\t\t\t\t\tRace[Race.UNDEAD],\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\tboardWithKilledMinion\r\n\t\t\t.filter((e) => e.cardId === CardIds.JellyBelly || e.cardId === CardIds.JellyBellyBattlegrounds)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tconst multiplier = e.cardId === CardIds.JellyBellyBattlegrounds ? 2 : 1;\r\n\t\t\t\tmodifyAttack(e, multiplier * 3, boardWithKilledMinion, allCards);\r\n\t\t\t\tmodifyHealth(e, multiplier * 3, boardWithKilledMinion, allCards);\r\n\t\t\t\tafterStatsUpdate(e, boardWithKilledMinion, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(e, e, boardWithKilledMinion);\r\n\t\t\t});\r\n\t}\r\n};\r\n\r\nexport const performEntitySpawns = (\r\n\tcandidateEntities: readonly BoardEntity[],\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tspawnSourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tspawnSourceEntityIndexFromRight: number,\r\n\topponentBoard: BoardEntity[],\r\n\topponentBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): readonly BoardEntity[] => {\r\n\tconst aliveEntites = candidateEntities.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tconst spawnedEntities = [];\r\n\tfor (const newMinion of aliveEntites) {\r\n\t\t// All entities have been spawned\r\n\t\tif (boardWithKilledMinion.length >= 7) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\t// Avoid minions spawning backwards (we don't have this issue if we add all elements at\r\n\t\t// the same time, but here we want to be able to attack after each spawn, which in turn\r\n\t\t// means that the minion can die before the other one spawns)\r\n\t\t// In boardWithKilledMinion, the dead minion has already been removed\r\n\t\tconst indexToSpawnAt = boardWithKilledMinion.length - spawnSourceEntityIndexFromRight;\r\n\t\taddMinionToBoard(\r\n\t\t\tboardWithKilledMinion,\r\n\t\t\tboardWithKilledMinionHero,\r\n\t\t\topponentBoardHero,\r\n\t\t\tindexToSpawnAt,\r\n\t\t\tnewMinion,\r\n\t\t\tallCards,\r\n\t\t\tspectator,\r\n\t\t\tsharedState,\r\n\t\t);\r\n\t\tif (newMinion.attackImmediately) {\r\n\t\t\t// Whenever we are already in a combat phase, we need to first clean up the state\r\n\t\t\tsimulateAttack(\r\n\t\t\t\tboardWithKilledMinion,\r\n\t\t\t\tboardWithKilledMinionHero,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\r\n\t\t\t\tnull,\r\n\t\t\t\tallCards,\r\n\t\t\t\tcardsData,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (newMinion.health > 0 && !newMinion.definitelyDead) {\r\n\t\t\tspawnedEntities.push(newMinion);\r\n\t\t}\r\n\t}\r\n\r\n\tspectator.registerMinionsSpawn(spawnSourceEntity, boardWithKilledMinion, spawnedEntities);\r\n\treturn spawnedEntities;\r\n};\r\n"]}
|
package/dist/utils.js
CHANGED
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,iEAAoH;AAKpH,4CAA8C;AAG9C,MAAM,UAAU,GAAG;;;;;;;CAOlB,CAAC;AACF,MAAM,sBAAsB,GAAG;;;;CAI9B,CAAC;AACF,MAAM,eAAe,GAAG,mBAAmC,CAAC;AAErD,MAAM,sBAAsB,GAAG,CACrC,MAAc,EACd,cAA+B,EAC/B,aAA4B,EAC5B,QAAyB,EACzB,QAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,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AM,EAAE;QAC7G,CAAC,CAAC,IAAI,CAAC;AACT,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B;AAEK,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAW,EAAE;;IACtD,OAAO,CACN,MAAM,CAAC,MAAM,CAAC,UAAU,wBAAqD;QAC7E,MAAM,CAAC,MAAM,CAAC,UAAU,mBAAkC;SAC1D,MAAA,MAAM,CAAC,eAAe,0CAAE,QAAQ,cAAoC,CAAA,CACpE,CAAC;AACH,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEK,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,QAAyB,EAAW,EAAE;IAC9E,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,wBAAwB,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, GameTag, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { SharedState } from 'src/simulation/shared-state';\r\nimport { BgsPlayerEntity } from './bgs-player-entity';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { pickRandom } from './services/utils';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\n\r\nconst CLEAVE_IDS = [\r\n\tCardIds.CaveHydra_BG_LOOT_078,\r\n\tCardIds.CaveHydraBattlegrounds,\r\n\tCardIds.FoeReaper4000_BG_GVG_113,\r\n\tCardIds.FoeReaper4000Battlegrounds,\r\n\tCardIds.BladeCollector,\r\n\tCardIds.BladeCollectorBattlegrounds,\r\n];\r\nconst ATTACK_IMMEDIATELY_IDS = [\r\n\tCardIds.Scallywag_SkyPirateToken,\r\n\tCardIds.Scallywag_SkyPirateTokenBattlegrounds,\r\n\tCardIds.Onyxia_OnyxianWhelpToken,\r\n];\r\nconst CANT_ATTACK_IDS = [CardIds.ArcaneCannonBattlegrounds];\r\n\r\nexport const buildSingleBoardEntity = (\r\n\tcardId: string,\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tentityId = 1,\r\n\tspawnReborn = false,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tentityToSpawn: BoardEntity,\r\n\toriginalEntity: BoardEntity = null,\r\n): BoardEntity => {\r\n\tconst card = allCards.getCard(cardId);\r\n\tconst attackImmediately = ATTACK_IMMEDIATELY_IDS.indexOf(cardId as CardIds) !== -1;\r\n\tconst newEntity = !!entityToSpawn\r\n\t\t? ({\r\n\t\t\t\t...entityToSpawn,\r\n\t\t\t\tentityId: sharedState.currentEntityId++,\r\n\t\t\t\tdefinitelyDead: false,\r\n\t\t\t\tavengeCurrent: entityToSpawn.avengeDefault,\r\n\t\t\t\tattacking: false,\r\n\t\t\t\tdamageMultiplier: 1,\r\n\t\t\t\tfrenzyApplied: false,\r\n\t\t } as BoardEntity)\r\n\t\t: addImpliedMechanics({\r\n\t\t\t\tentityId: entityId,\r\n\t\t\t\tattack: card.attack,\r\n\t\t\t\tattacksPerformed: 0,\r\n\t\t\t\tcardId: cardId,\r\n\t\t\t\tdivineShield: hasMechanic(card, 'DIVINE_SHIELD'),\r\n\t\t\t\thealth: card.health,\r\n\t\t\t\tmaxHealth: card.health,\r\n\t\t\t\ttaunt: hasMechanic(card, GameTag[GameTag.TAUNT]),\r\n\t\t\t\treborn: hasMechanic(card, 'REBORN'),\r\n\t\t\t\tpoisonous: hasMechanic(card, GameTag[GameTag.POISONOUS]),\r\n\t\t\t\tvenomous: hasMechanic(card, GameTag[GameTag.VENOMOUS]),\r\n\t\t\t\twindfury:\r\n\t\t\t\t\thasMechanic(card, GameTag[GameTag.WINDFURY]) ||\r\n\t\t\t\t\tcard.referencedTags?.includes(GameTag[GameTag.WINDFURY]),\r\n\t\t\t\tenchantments: [],\r\n\t\t\t\tfriendly: friendly,\r\n\t\t\t\tattackImmediately: attackImmediately,\r\n\t\t\t\tavengeCurrent: cardsData.avengeValue(cardId),\r\n\t\t\t\tavengeDefault: cardsData.avengeValue(cardId),\r\n\t\t } as BoardEntity);\r\n\r\n\tif (spawnReborn && !entityToSpawn) {\r\n\t\tif (cardId === CardIds.BuildAnUndead_PutricidesCreationToken) {\r\n\t\t\tconst stitchedCardId = !!originalEntity.additionalCards?.length ? originalEntity.additionalCards[0] : null;\r\n\t\t\tif (stitchedCardId) {\r\n\t\t\t\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\t\t\t\tnewEntity.attack = newEntity.attack + stitchedCard.attack;\r\n\t\t\t\tnewEntity.maxHealth = newEntity.maxHealth + stitchedCard.health;\r\n\t\t\t\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\t\t\t\tnewEntity.divineShield =\r\n\t\t\t\t\tnewEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\t\t\t\tnewEntity.poisonous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\t\t\t\tnewEntity.venomous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\t\t\t\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\t\t\t\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t}\r\n\t\t}\r\n\t\tnewEntity.health = 1;\r\n\t\tnewEntity.reborn = false;\r\n\t}\r\n\r\n\tnewEntity.hadDivineShield = newEntity.divineShield || newEntity.hadDivineShield;\r\n\treturn newEntity;\r\n};\r\n\r\nexport const buildRandomUndeadCreation = (\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n): BoardEntity => {\r\n\tconst baseCard = pickRandom(cardsData.putricidePool1);\r\n\tconst stitchedCardId =\r\n\t\tbaseCard === CardIds.EternalSummoner\r\n\t\t\t? pickRandom(cardsData.putridicePool2ForEternalSummoner)\r\n\t\t\t: pickRandom(cardsData.putricidePool2);\r\n\tconst newEntity = buildSingleBoardEntity(\r\n\t\tbaseCard,\r\n\t\tcontrollerHero,\r\n\t\tfriendlyBoard,\r\n\t\tallCards,\r\n\t\tfriendly,\r\n\t\tsharedState.currentEntityId++,\r\n\t\tfalse,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tnull,\r\n\t);\r\n\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\tnewEntity.attack += stitchedCard.attack;\r\n\tnewEntity.health += stitchedCard.health;\r\n\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\tnewEntity.divineShield = newEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\tnewEntity.poisonous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\tnewEntity.venomous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\treturn newEntity;\r\n};\r\n\r\nexport const modifyAttack = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.TarecgosaBattlegrounds ? 2 * amount : amount;\r\n\tentity.attack = Math.max(0, entity.attack + realAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tif (isCorrectTribe(allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler || e.cardId === CardIds.WhelpSmugglerBattlegrounds,\r\n\t\t);\r\n\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmugglerBattlegrounds ? 2 : 1;\r\n\t\t\tmodifyHealth(entity, buff, friendlyBoard, allCards);\r\n\t\t});\r\n\r\n\t\tif (entity.cardId !== CardIds.Stormbringer && entity.cardId !== CardIds.StormbringerBattlegrounds) {\r\n\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.Stormbringer || e.cardId === CardIds.StormbringerBattlegrounds,\r\n\t\t\t);\r\n\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.StormbringerBattlegrounds ? 2 : 1;\r\n\t\t\t\t(e) => modifyAttack(e, multiplier * amount, friendlyBoard, allCards);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamTokenBattlegrounds ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const modifyHealth = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.TarecgosaBattlegrounds ? 2 * amount : amount;\r\n\tentity.health += realAmount;\r\n\tif (realAmount > 0) {\r\n\t\tentity.maxHealth += realAmount;\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamTokenBattlegrounds ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tconst titanicGuardians = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t);\r\n\ttitanicGuardians.forEach((guardian) => {\r\n\t\tmodifyHealth(\r\n\t\t\tguardian,\r\n\t\t\t(guardian.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) *\r\n\t\t\t\trealAmount,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const afterStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, Race.ELEMENTAL, allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealitiesBattlegrounds,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealitiesBattlegrounds ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealitiesBattlegrounds ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\tmodifyAttack(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tmodifyHealth(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const makeMinionGolden = (\r\n\ttarget: BoardEntity,\r\n\tsource: BoardEntity | BgsPlayerEntity,\r\n\tsourceBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst refCard = allCards.getCard(target.cardId);\r\n\t// Typically, we are already golden\r\n\tif (!refCard.battlegroundsPremiumDbfId) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\ttarget.cardId = goldenCard.id;\r\n\t// A minion becoming golden ignore the current death.\r\n\t// This way of handling it is not ideal, since it will still trigger if both avenges trigger at the same time, but\r\n\t// should solve the other cases\r\n\ttarget.avengeCurrent = Math.min(target.avengeDefault, target.avengeCurrent + 1);\r\n\tmodifyAttack(target, refCard.attack, sourceBoard, allCards);\r\n\tmodifyHealth(target, refCard.health, sourceBoard, allCards);\r\n\tafterStatsUpdate(target, sourceBoard, allCards);\r\n\tspectator.registerPowerTarget(source, target, sourceBoard);\r\n};\r\n\r\nexport const grantRandomAttack = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tadditionalAttack: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyAttack(target, additionalAttack, candidateBoard, allCards);\r\n\t\tafterStatsUpdate(target, candidateBoard, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomHealth = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyHealth(target, health, board, allCards);\r\n\t\tafterStatsUpdate(target, board, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomStats = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\trace: Race,\r\n\texcludeSource: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator?: Spectator,\r\n): BoardEntity => {\r\n\tif (board.length > 0) {\r\n\t\tconst target: BoardEntity = getRandomAliveMinion(\r\n\t\t\tboard.filter((e) => (excludeSource ? e.entityId !== source.entityId : true)),\r\n\t\t\trace,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tif (target) {\r\n\t\t\tmodifyAttack(target, attack, board, allCards);\r\n\t\t\tmodifyHealth(target, health, board, allCards);\r\n\t\t\tafterStatsUpdate(target, board, allCards);\r\n\t\t\tif (spectator) {\r\n\t\t\t\tspectator.registerPowerTarget(source, target, board);\r\n\t\t\t}\r\n\t\t\treturn target;\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const addCardsInHand = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tcardsAdded: readonly any[],\r\n): void => {\r\n\tconst previousCardsInHand = playerEntity.hand?.length ?? 0;\r\n\tconst sages = board.filter((e) => e.cardId === CardIds.DeathsHeadSage);\r\n\tconst sagesGolden = board.filter((e) => e.cardId === CardIds.DeathsHeadSageBattlegrounds);\r\n\tconst multiplier = sages.length + 2 * sagesGolden.length;\r\n\r\n\tconst cardsThatWillBeAdded = [];\r\n\tfor (const cardAdded of cardsAdded) {\r\n\t\tconst cardToAdd: { cardId: string } = (cardAdded as BoardEntity)?.cardId\r\n\t\t\t? (cardAdded as BoardEntity)\r\n\t\t\t: ({ cardId: cardAdded as string } as BoardEntity);\r\n\t\tcardsThatWillBeAdded.push(cardToAdd);\r\n\t\tif (cardToAdd.cardId === CardIds.BloodGem) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tcardsThatWillBeAdded.push({ ...cardToAdd });\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < cardsThatWillBeAdded.length; i++) {\r\n\t\tif (playerEntity.hand.length >= 10) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tplayerEntity.hand.push(cardsThatWillBeAdded[i]);\r\n\t}\r\n\r\n\tconst numCardsAdded = playerEntity.hand.length - previousCardsInHand;\r\n\r\n\tfor (let i = 0; i < numCardsAdded; i++) {\r\n\t\tconst peggys = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.PeggySturdybone || e.cardId === CardIds.PeggySturdyboneBattlegrounds,\r\n\t\t);\r\n\t\tpeggys.forEach((peggy) => {\r\n\t\t\tconst pirate = getRandomAliveMinion(\r\n\t\t\t\tboard.filter((e) => e.entityId !== peggy.entityId),\r\n\t\t\t\tRace.PIRATE,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tif (pirate) {\r\n\t\t\t\tmodifyAttack(pirate, peggy.cardId === CardIds.PeggySturdyboneBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\t\tmodifyHealth(pirate, peggy.cardId === CardIds.PeggySturdyboneBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(peggy, pirate, board);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst thornCaptains = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.Thorncaptain || e.cardId === CardIds.ThorncaptainBattlegrounds,\r\n\t\t);\r\n\t\tthornCaptains.forEach((captain) => {\r\n\t\t\tmodifyHealth(captain, captain.cardId === CardIds.ThorncaptainBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\tafterStatsUpdate(captain, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, captain, board);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const removeCardFromHand = (playerEntity: BgsPlayerEntity, card: BoardEntity): void => {\r\n\tlet cardToRemove: BoardEntity;\r\n\tif (card?.entityId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.entityId !== card.entityId);\r\n\t} else if (card?.cardId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.cardId === card.cardId);\r\n\t} else {\r\n\t\t// Remove a single random card in hand that doesn't have an entityId\r\n\t\tcardToRemove =\r\n\t\t\tpickRandom(playerEntity.hand.filter((c) => !c?.entityId && !c?.cardId)) ?? pickRandom(playerEntity.hand);\r\n\t}\r\n\t// Remove the first occurrence of the card from playerEntity.cardsInHand, even if it is null\r\n\tconst index = playerEntity.hand.indexOf(cardToRemove);\r\n\tif (index !== -1) {\r\n\t\tplayerEntity.hand.splice(index, 1);\r\n\t}\r\n};\r\n\r\nexport const grantRandomDivineShield = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tif (elligibleEntities.length > 0) {\r\n\t\tconst chosen = elligibleEntities[Math.floor(Math.random() * elligibleEntities.length)];\r\n\t\tupdateDivineShield(chosen, board, true, allCards);\r\n\t\tspectator.registerPowerTarget(source, chosen, board);\r\n\t}\r\n\t// return board;\r\n};\r\n\r\nexport const updateDivineShield = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tnewValue: boolean,\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\t// if ((entity.divineShield ?? false) === newValue) {\r\n\t// \treturn;\r\n\t// }\r\n\tentity.divineShield = newValue;\r\n\tif (entity.divineShield) {\r\n\t\tentity.hadDivineShield = true;\r\n\t}\r\n\tif (entity.divineShield) {\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrakeBattlegrounds).length;\r\n\t\t// Don't trigger all \"on attack changed\" effects, since it's an aura\r\n\t\tentity.attack += statsBonus;\r\n\t} else {\r\n\t\t// Also consider itself\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrakeBattlegrounds).length;\r\n\t\tentity.attack -= statsBonus;\r\n\t}\r\n};\r\n\r\nexport const grantAllDivineShield = (board: BoardEntity[], tribe: string, cards: AllCardsService): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => isCorrectTribe(cards.getCard(entity.cardId).races, getRaceEnum(tribe)));\r\n\tfor (const entity of elligibleEntities) {\r\n\t\tupdateDivineShield(entity, board, true, cards);\r\n\t}\r\n};\r\n\r\nexport const getRandomAliveMinion = (board: BoardEntity[], race: Race, allCards: AllCardsService): BoardEntity => {\r\n\tconst validTribes = board\r\n\t\t.filter((e) => !race || isCorrectTribe(allCards.getCard(e?.cardId).races, race))\r\n\t\t.filter((e) => !!e?.health && !e.definitelyDead);\r\n\t// console.log('picking a random alive minion', stringifySimple(validTribes, allCards));\r\n\tif (!validTribes.length) {\r\n\t\treturn null;\r\n\t}\r\n\tconst randomIndex = Math.floor(Math.random() * validTribes.length);\r\n\treturn validTribes[randomIndex];\r\n};\r\n\r\nexport const getRandomMinionWithHighestHealth = (board: BoardEntity[]): BoardEntity => {\r\n\tif (!board.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst highestHealth = Math.max(...board.map((e) => e.health));\r\n\tconst validMinions = board.filter((e) => e.health === highestHealth);\r\n\treturn validMinions[Math.floor(Math.random() * validMinions.length)];\r\n};\r\n\r\nexport const addStatsToBoard = (\r\n\tsourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\ttribe?: string,\r\n): void => {\r\n\tfor (const entity of board) {\r\n\t\tif (!tribe || hasCorrectTribe(entity, Race[tribe], allCards)) {\r\n\t\t\tmodifyAttack(entity, attack, board, allCards);\r\n\t\t\tmodifyHealth(entity, health, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(sourceEntity, entity, board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const grantStatsToMinionsOfEachType = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (board.length > 0) {\r\n\t\tlet boardCopy = [...board];\r\n\t\tfor (const tribe of ALL_BG_RACES) {\r\n\t\t\tconst validMinion: BoardEntity = getRandomAliveMinion(boardCopy, tribe, allCards);\r\n\t\t\tif (validMinion) {\r\n\t\t\t\tmodifyAttack(validMinion, attack, board, allCards);\r\n\t\t\t\tmodifyHealth(validMinion, health, board, allCards);\r\n\t\t\t\tafterStatsUpdate(validMinion, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(source, validMinion, board);\r\n\t\t\t\tboardCopy = boardCopy.filter((e) => e !== validMinion);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const hasMechanic = (card: ReferenceCard, mechanic: string): boolean => {\r\n\treturn card.mechanics?.includes(mechanic);\r\n};\r\n\r\nexport const hasCorrectTribe = (entity: BoardEntity, targetTribe: Race, allCards: AllCardsService): boolean => {\r\n\treturn isCorrectTribe(allCards.getCard(entity.cardId).races, targetTribe);\r\n};\r\n\r\nexport const isCorrectTribe = (cardRaces: readonly string[], targetTribe: Race): boolean => {\r\n\tif (!cardRaces?.length) {\r\n\t\treturn false;\r\n\t}\r\n\treturn cardRaces\r\n\t\t.map((cardRace) => getRaceEnum(cardRace))\r\n\t\t.some((raceEnum) => raceEnum === Race.ALL || raceEnum === targetTribe);\r\n};\r\n\r\nexport const getRaceEnum = (race: string): Race => {\r\n\treturn Race[race];\r\n};\r\n\r\nexport const addImpliedMechanics = (entity: BoardEntity): BoardEntity => {\r\n\tconst cleave = CLEAVE_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\tconst cantAttack = CANT_ATTACK_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\t// Avoid creating a new object if not necessary\r\n\tif (!cleave && !cantAttack) {\r\n\t\treturn entity;\r\n\t}\r\n\treturn {\r\n\t\t...entity,\r\n\t\tcleave: cleave,\r\n\t\tcantAttack: cantAttack,\r\n\t} as BoardEntity;\r\n};\r\n\r\nexport const normalizeCardIdForSkin = (cardId: string): string => {\r\n\tconst skinMatch = cardId.match(/(.*)_SKIN_.*/);\r\n\tif (skinMatch) {\r\n\t\treturn skinMatch[1];\r\n\t}\r\n\treturn cardId;\r\n};\r\n\r\nexport const stringifySimple = (board: readonly BoardEntity[], allCards: AllCardsService = null): string => {\r\n\treturn '[' + board.map((entity) => stringifySimpleCard(entity, allCards)).join(', ') + ']';\r\n};\r\n\r\nexport const stringifySimpleCard = (entity: BoardEntity, allCards: AllCardsService = null): string => {\r\n\treturn entity\r\n\t\t? `${entity.cardId}/${allCards?.getCard(entity.cardId)?.name ?? ''}/atk=${entity.attack}/hp=${entity.health}`\r\n\t\t: null;\r\n};\r\n\r\nexport const isFish = (entity: BoardEntity): boolean => {\r\n\treturn (\r\n\t\tentity.cardId.startsWith(CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds) ||\r\n\t\tentity.cardId.startsWith(CardIds.FishOfNzothBattlegrounds) ||\r\n\t\tentity.additionalCards?.includes(CardIds.DevourerOfSouls_BG_RLK_538)\r\n\t);\r\n};\r\n\r\nexport const isGolden = (cardId: string, allCards: AllCardsService): boolean => {\r\n\treturn !!allCards.getCard(cardId).battlegroundsNormalDbfId;\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,iEAAoH;AAKpH,4CAA8C;AAG9C,MAAM,UAAU,GAAG;;;;;;;CAOlB,CAAC;AACF,MAAM,sBAAsB,GAAG;;;;CAI9B,CAAC;AAC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AAC,GAAG,MAAM,CAAC,MAAM,IAAI,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,0CAAE,IAAI,mCAAI,EAAE,QAAQ,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM,EAAE;QAC7G,CAAC,CAAC,IAAI,CAAC;AACT,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B;AAEK,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAW,EAAE;;IACtD,OAAO,CACN,MAAM,CAAC,MAAM,CAAC,UAAU,wBAAqD;QAC7E,MAAM,CAAC,MAAM,CAAC,UAAU,mBAAkC;SAC1D,MAAA,MAAM,CAAC,eAAe,0CAAE,QAAQ,cAAoC,CAAA,CACpE,CAAC;AACH,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEK,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,QAAyB,EAAW,EAAE;IAC9E,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,wBAAwB,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, GameTag, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { SharedState } from 'src/simulation/shared-state';\r\nimport { BgsPlayerEntity } from './bgs-player-entity';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { pickRandom } from './services/utils';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\n\r\nconst CLEAVE_IDS = [\r\n\tCardIds.CaveHydra_BG_LOOT_078,\r\n\tCardIds.CaveHydraBattlegrounds,\r\n\tCardIds.FoeReaper4000_BG_GVG_113,\r\n\tCardIds.FoeReaper4000Battlegrounds,\r\n\tCardIds.BladeCollector,\r\n\tCardIds.BladeCollectorBattlegrounds,\r\n];\r\nconst ATTACK_IMMEDIATELY_IDS = [\r\n\tCardIds.Scallywag_SkyPirateToken,\r\n\tCardIds.Scallywag_SkyPirateTokenBattlegrounds,\r\n\tCardIds.Onyxia_OnyxianWhelpToken,\r\n];\r\nconst CANT_ATTACK_IDS = [CardIds.ArcaneCannonBattlegrounds];\r\n\r\nexport const buildSingleBoardEntity = (\r\n\tcardId: string,\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tentityId = 1,\r\n\tspawnReborn = false,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tentityToSpawn: BoardEntity,\r\n\toriginalEntity: BoardEntity = null,\r\n): BoardEntity => {\r\n\tconst card = allCards.getCard(cardId);\r\n\tconst attackImmediately = ATTACK_IMMEDIATELY_IDS.indexOf(cardId as CardIds) !== -1;\r\n\tconst newEntity = !!entityToSpawn\r\n\t\t? ({\r\n\t\t\t\t...entityToSpawn,\r\n\t\t\t\tentityId: sharedState.currentEntityId++,\r\n\t\t\t\tdefinitelyDead: false,\r\n\t\t\t\tavengeCurrent: entityToSpawn.avengeDefault,\r\n\t\t\t\tattacking: false,\r\n\t\t\t\tdamageMultiplier: 1,\r\n\t\t\t\tfrenzyApplied: false,\r\n\t\t\t\tfriendly: friendly,\r\n\t\t } as BoardEntity)\r\n\t\t: addImpliedMechanics({\r\n\t\t\t\tentityId: entityId,\r\n\t\t\t\tattack: card.attack,\r\n\t\t\t\tattacksPerformed: 0,\r\n\t\t\t\tcardId: cardId,\r\n\t\t\t\tdivineShield: hasMechanic(card, 'DIVINE_SHIELD'),\r\n\t\t\t\thealth: card.health,\r\n\t\t\t\tmaxHealth: card.health,\r\n\t\t\t\ttaunt: hasMechanic(card, GameTag[GameTag.TAUNT]),\r\n\t\t\t\treborn: hasMechanic(card, 'REBORN'),\r\n\t\t\t\tpoisonous: hasMechanic(card, GameTag[GameTag.POISONOUS]),\r\n\t\t\t\tvenomous: hasMechanic(card, GameTag[GameTag.VENOMOUS]),\r\n\t\t\t\twindfury:\r\n\t\t\t\t\thasMechanic(card, GameTag[GameTag.WINDFURY]) ||\r\n\t\t\t\t\tcard.referencedTags?.includes(GameTag[GameTag.WINDFURY]),\r\n\t\t\t\tenchantments: [],\r\n\t\t\t\tfriendly: friendly,\r\n\t\t\t\tattackImmediately: attackImmediately,\r\n\t\t\t\tavengeCurrent: cardsData.avengeValue(cardId),\r\n\t\t\t\tavengeDefault: cardsData.avengeValue(cardId),\r\n\t\t } as BoardEntity);\r\n\r\n\tif (spawnReborn && !entityToSpawn) {\r\n\t\tif (cardId === CardIds.BuildAnUndead_PutricidesCreationToken) {\r\n\t\t\tconst stitchedCardId = !!originalEntity.additionalCards?.length ? originalEntity.additionalCards[0] : null;\r\n\t\t\tif (stitchedCardId) {\r\n\t\t\t\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\t\t\t\tnewEntity.attack = newEntity.attack + stitchedCard.attack;\r\n\t\t\t\tnewEntity.maxHealth = newEntity.maxHealth + stitchedCard.health;\r\n\t\t\t\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\t\t\t\tnewEntity.divineShield =\r\n\t\t\t\t\tnewEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\t\t\t\tnewEntity.poisonous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\t\t\t\tnewEntity.venomous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\t\t\t\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\t\t\t\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t}\r\n\t\t}\r\n\t\tnewEntity.health = 1;\r\n\t\tnewEntity.reborn = false;\r\n\t}\r\n\r\n\tnewEntity.hadDivineShield = newEntity.divineShield || newEntity.hadDivineShield;\r\n\treturn newEntity;\r\n};\r\n\r\nexport const buildRandomUndeadCreation = (\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n): BoardEntity => {\r\n\tconst baseCard = pickRandom(cardsData.putricidePool1);\r\n\tconst stitchedCardId =\r\n\t\tbaseCard === CardIds.EternalSummoner\r\n\t\t\t? pickRandom(cardsData.putridicePool2ForEternalSummoner)\r\n\t\t\t: pickRandom(cardsData.putricidePool2);\r\n\tconst newEntity = buildSingleBoardEntity(\r\n\t\tbaseCard,\r\n\t\tcontrollerHero,\r\n\t\tfriendlyBoard,\r\n\t\tallCards,\r\n\t\tfriendly,\r\n\t\tsharedState.currentEntityId++,\r\n\t\tfalse,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tnull,\r\n\t);\r\n\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\tnewEntity.attack += stitchedCard.attack;\r\n\tnewEntity.health += stitchedCard.health;\r\n\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\tnewEntity.divineShield = newEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\tnewEntity.poisonous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\tnewEntity.venomous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\treturn newEntity;\r\n};\r\n\r\nexport const modifyAttack = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.TarecgosaBattlegrounds ? 2 * amount : amount;\r\n\tentity.attack = Math.max(0, entity.attack + realAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tif (isCorrectTribe(allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler || e.cardId === CardIds.WhelpSmugglerBattlegrounds,\r\n\t\t);\r\n\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmugglerBattlegrounds ? 2 : 1;\r\n\t\t\tmodifyHealth(entity, buff, friendlyBoard, allCards);\r\n\t\t});\r\n\r\n\t\tif (entity.cardId !== CardIds.Stormbringer && entity.cardId !== CardIds.StormbringerBattlegrounds) {\r\n\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.Stormbringer || e.cardId === CardIds.StormbringerBattlegrounds,\r\n\t\t\t);\r\n\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.StormbringerBattlegrounds ? 2 : 1;\r\n\t\t\t\t(e) => modifyAttack(e, multiplier * amount, friendlyBoard, allCards);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamTokenBattlegrounds ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const modifyHealth = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.TarecgosaBattlegrounds ? 2 * amount : amount;\r\n\tentity.health += realAmount;\r\n\tif (realAmount > 0) {\r\n\t\tentity.maxHealth += realAmount;\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamTokenBattlegrounds ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.CuddlgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgamBattlegrounds_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.MishmashBattlegrounds_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tconst titanicGuardians = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t);\r\n\ttitanicGuardians.forEach((guardian) => {\r\n\t\tmodifyHealth(\r\n\t\t\tguardian,\r\n\t\t\t(guardian.cardId === CardIds.TitanicGuardianBattlegrounds_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) *\r\n\t\t\t\trealAmount,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const afterStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, Race.ELEMENTAL, allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealitiesBattlegrounds,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealitiesBattlegrounds ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealitiesBattlegrounds ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\tmodifyAttack(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tmodifyHealth(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthunBattlegrounds_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const makeMinionGolden = (\r\n\ttarget: BoardEntity,\r\n\tsource: BoardEntity | BgsPlayerEntity,\r\n\tsourceBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst refCard = allCards.getCard(target.cardId);\r\n\t// Typically, we are already golden\r\n\tif (!refCard.battlegroundsPremiumDbfId) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\ttarget.cardId = goldenCard.id;\r\n\t// A minion becoming golden ignore the current death.\r\n\t// This way of handling it is not ideal, since it will still trigger if both avenges trigger at the same time, but\r\n\t// should solve the other cases\r\n\ttarget.avengeCurrent = Math.min(target.avengeDefault, target.avengeCurrent + 1);\r\n\tmodifyAttack(target, refCard.attack, sourceBoard, allCards);\r\n\tmodifyHealth(target, refCard.health, sourceBoard, allCards);\r\n\tafterStatsUpdate(target, sourceBoard, allCards);\r\n\tspectator.registerPowerTarget(source, target, sourceBoard);\r\n};\r\n\r\nexport const grantRandomAttack = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tadditionalAttack: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyAttack(target, additionalAttack, candidateBoard, allCards);\r\n\t\tafterStatsUpdate(target, candidateBoard, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomHealth = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyHealth(target, health, board, allCards);\r\n\t\tafterStatsUpdate(target, board, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomStats = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\trace: Race,\r\n\texcludeSource: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator?: Spectator,\r\n): BoardEntity => {\r\n\tif (board.length > 0) {\r\n\t\tconst target: BoardEntity = getRandomAliveMinion(\r\n\t\t\tboard.filter((e) => (excludeSource ? e.entityId !== source.entityId : true)),\r\n\t\t\trace,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tif (target) {\r\n\t\t\tmodifyAttack(target, attack, board, allCards);\r\n\t\t\tmodifyHealth(target, health, board, allCards);\r\n\t\t\tafterStatsUpdate(target, board, allCards);\r\n\t\t\tif (spectator) {\r\n\t\t\t\tspectator.registerPowerTarget(source, target, board);\r\n\t\t\t}\r\n\t\t\treturn target;\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const addCardsInHand = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tcardsAdded: readonly any[],\r\n): void => {\r\n\tconst previousCardsInHand = playerEntity.hand?.length ?? 0;\r\n\tconst sages = board.filter((e) => e.cardId === CardIds.DeathsHeadSage);\r\n\tconst sagesGolden = board.filter((e) => e.cardId === CardIds.DeathsHeadSageBattlegrounds);\r\n\tconst multiplier = sages.length + 2 * sagesGolden.length;\r\n\r\n\tconst cardsThatWillBeAdded = [];\r\n\tfor (const cardAdded of cardsAdded) {\r\n\t\tconst cardToAdd: { cardId: string } = (cardAdded as BoardEntity)?.cardId\r\n\t\t\t? (cardAdded as BoardEntity)\r\n\t\t\t: ({ cardId: cardAdded as string } as BoardEntity);\r\n\t\tcardsThatWillBeAdded.push(cardToAdd);\r\n\t\tif (cardToAdd.cardId === CardIds.BloodGem) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tcardsThatWillBeAdded.push({ ...cardToAdd });\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < cardsThatWillBeAdded.length; i++) {\r\n\t\tif (playerEntity.hand.length >= 10) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tplayerEntity.hand.push(cardsThatWillBeAdded[i]);\r\n\t}\r\n\r\n\tconst numCardsAdded = playerEntity.hand.length - previousCardsInHand;\r\n\r\n\tfor (let i = 0; i < numCardsAdded; i++) {\r\n\t\tconst peggys = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.PeggySturdybone || e.cardId === CardIds.PeggySturdyboneBattlegrounds,\r\n\t\t);\r\n\t\tpeggys.forEach((peggy) => {\r\n\t\t\tconst pirate = getRandomAliveMinion(\r\n\t\t\t\tboard.filter((e) => e.entityId !== peggy.entityId),\r\n\t\t\t\tRace.PIRATE,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tif (pirate) {\r\n\t\t\t\tmodifyAttack(pirate, peggy.cardId === CardIds.PeggySturdyboneBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\t\tmodifyHealth(pirate, peggy.cardId === CardIds.PeggySturdyboneBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(peggy, pirate, board);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst thornCaptains = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.Thorncaptain || e.cardId === CardIds.ThorncaptainBattlegrounds,\r\n\t\t);\r\n\t\tthornCaptains.forEach((captain) => {\r\n\t\t\tmodifyHealth(captain, captain.cardId === CardIds.ThorncaptainBattlegrounds ? 2 : 1, board, allCards);\r\n\t\t\tafterStatsUpdate(captain, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, captain, board);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const removeCardFromHand = (playerEntity: BgsPlayerEntity, card: BoardEntity): void => {\r\n\tlet cardToRemove: BoardEntity;\r\n\tif (card?.entityId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.entityId !== card.entityId);\r\n\t} else if (card?.cardId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.cardId === card.cardId);\r\n\t} else {\r\n\t\t// Remove a single random card in hand that doesn't have an entityId\r\n\t\tcardToRemove =\r\n\t\t\tpickRandom(playerEntity.hand.filter((c) => !c?.entityId && !c?.cardId)) ?? pickRandom(playerEntity.hand);\r\n\t}\r\n\t// Remove the first occurrence of the card from playerEntity.cardsInHand, even if it is null\r\n\tconst index = playerEntity.hand.indexOf(cardToRemove);\r\n\tif (index !== -1) {\r\n\t\tplayerEntity.hand.splice(index, 1);\r\n\t}\r\n};\r\n\r\nexport const grantRandomDivineShield = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tif (elligibleEntities.length > 0) {\r\n\t\tconst chosen = elligibleEntities[Math.floor(Math.random() * elligibleEntities.length)];\r\n\t\tupdateDivineShield(chosen, board, true, allCards);\r\n\t\tspectator.registerPowerTarget(source, chosen, board);\r\n\t}\r\n\t// return board;\r\n};\r\n\r\nexport const updateDivineShield = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tnewValue: boolean,\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\t// if ((entity.divineShield ?? false) === newValue) {\r\n\t// \treturn;\r\n\t// }\r\n\tentity.divineShield = newValue;\r\n\tif (entity.divineShield) {\r\n\t\tentity.hadDivineShield = true;\r\n\t}\r\n\tif (entity.divineShield) {\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrakeBattlegrounds).length;\r\n\t\t// Don't trigger all \"on attack changed\" effects, since it's an aura\r\n\t\tentity.attack += statsBonus;\r\n\t} else {\r\n\t\t// Also consider itself\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrakeBattlegrounds).length;\r\n\t\tentity.attack -= statsBonus;\r\n\t}\r\n};\r\n\r\nexport const grantAllDivineShield = (board: BoardEntity[], tribe: string, cards: AllCardsService): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => isCorrectTribe(cards.getCard(entity.cardId).races, getRaceEnum(tribe)));\r\n\tfor (const entity of elligibleEntities) {\r\n\t\tupdateDivineShield(entity, board, true, cards);\r\n\t}\r\n};\r\n\r\nexport const getRandomAliveMinion = (board: BoardEntity[], race: Race, allCards: AllCardsService): BoardEntity => {\r\n\tconst validTribes = board\r\n\t\t.filter((e) => !race || isCorrectTribe(allCards.getCard(e?.cardId).races, race))\r\n\t\t.filter((e) => !!e?.health && !e.definitelyDead);\r\n\tif (!validTribes.length) {\r\n\t\treturn null;\r\n\t}\r\n\tconst randomIndex = Math.floor(Math.random() * validTribes.length);\r\n\treturn validTribes[randomIndex];\r\n};\r\n\r\nexport const getRandomMinionWithHighestHealth = (board: BoardEntity[]): BoardEntity => {\r\n\tif (!board.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst highestHealth = Math.max(...board.map((e) => e.health));\r\n\tconst validMinions = board.filter((e) => e.health === highestHealth);\r\n\treturn validMinions[Math.floor(Math.random() * validMinions.length)];\r\n};\r\n\r\nexport const addStatsToBoard = (\r\n\tsourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\ttribe?: string,\r\n): void => {\r\n\tfor (const entity of board) {\r\n\t\tif (!tribe || hasCorrectTribe(entity, Race[tribe], allCards)) {\r\n\t\t\tmodifyAttack(entity, attack, board, allCards);\r\n\t\t\tmodifyHealth(entity, health, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(sourceEntity, entity, board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const grantStatsToMinionsOfEachType = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (board.length > 0) {\r\n\t\tlet boardCopy = [...board];\r\n\t\tfor (const tribe of ALL_BG_RACES) {\r\n\t\t\tconst validMinion: BoardEntity = getRandomAliveMinion(boardCopy, tribe, allCards);\r\n\t\t\tif (validMinion) {\r\n\t\t\t\tmodifyAttack(validMinion, attack, board, allCards);\r\n\t\t\t\tmodifyHealth(validMinion, health, board, allCards);\r\n\t\t\t\tafterStatsUpdate(validMinion, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(source, validMinion, board);\r\n\t\t\t\tboardCopy = boardCopy.filter((e) => e !== validMinion);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const hasMechanic = (card: ReferenceCard, mechanic: string): boolean => {\r\n\treturn card.mechanics?.includes(mechanic);\r\n};\r\n\r\nexport const hasCorrectTribe = (entity: BoardEntity, targetTribe: Race, allCards: AllCardsService): boolean => {\r\n\treturn isCorrectTribe(allCards.getCard(entity.cardId).races, targetTribe);\r\n};\r\n\r\nexport const isCorrectTribe = (cardRaces: readonly string[], targetTribe: Race): boolean => {\r\n\tif (!cardRaces?.length) {\r\n\t\treturn false;\r\n\t}\r\n\treturn cardRaces\r\n\t\t.map((cardRace) => getRaceEnum(cardRace))\r\n\t\t.some((raceEnum) => raceEnum === Race.ALL || raceEnum === targetTribe);\r\n};\r\n\r\nexport const getRaceEnum = (race: string): Race => {\r\n\treturn Race[race];\r\n};\r\n\r\nexport const addImpliedMechanics = (entity: BoardEntity): BoardEntity => {\r\n\tconst cleave = CLEAVE_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\tconst cantAttack = CANT_ATTACK_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\t// Avoid creating a new object if not necessary\r\n\tif (!cleave && !cantAttack) {\r\n\t\treturn entity;\r\n\t}\r\n\treturn {\r\n\t\t...entity,\r\n\t\tcleave: cleave,\r\n\t\tcantAttack: cantAttack,\r\n\t} as BoardEntity;\r\n};\r\n\r\nexport const normalizeCardIdForSkin = (cardId: string): string => {\r\n\tconst skinMatch = cardId.match(/(.*)_SKIN_.*/);\r\n\tif (skinMatch) {\r\n\t\treturn skinMatch[1];\r\n\t}\r\n\treturn cardId;\r\n};\r\n\r\nexport const stringifySimple = (board: readonly BoardEntity[], allCards: AllCardsService = null): string => {\r\n\treturn '[' + board.map((entity) => stringifySimpleCard(entity, allCards)).join(', ') + ']';\r\n};\r\n\r\nexport const stringifySimpleCard = (entity: BoardEntity, allCards: AllCardsService = null): string => {\r\n\treturn entity\r\n\t\t? `${entity.cardId}/${allCards?.getCard(entity.cardId)?.name ?? ''}/atk=${entity.attack}/hp=${entity.health}`\r\n\t\t: null;\r\n};\r\n\r\nexport const isFish = (entity: BoardEntity): boolean => {\r\n\treturn (\r\n\t\tentity.cardId.startsWith(CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds) ||\r\n\t\tentity.cardId.startsWith(CardIds.FishOfNzothBattlegrounds) ||\r\n\t\tentity.additionalCards?.includes(CardIds.DevourerOfSouls_BG_RLK_538)\r\n\t);\r\n};\r\n\r\nexport const isGolden = (cardId: string, allCards: AllCardsService): boolean => {\r\n\treturn !!allCards.getCard(cardId).battlegroundsNormalDbfId;\r\n};\r\n"]}
|