@firestone-hs/simulate-bgs-battle 1.1.157 → 1.1.161

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.
@@ -36,6 +36,7 @@ class CardsData {
36
36
  .getCards()
37
37
  .filter((card) => reference_data_1.isBattlegroundsCard(card))
38
38
  .filter((card) => !!card.techLevel)
39
+ .filter((card) => !utils_2.hasMechanic(card, reference_data_1.GameTag[reference_data_1.GameTag.BACON_BUDDY]))
39
40
  .filter((card) => card.set !== 'Vanilla');
40
41
  this.minionsForTier = utils_1.groupByFunction((card) => card.techLevel)(pool.filter((card) => !this.isGolden(card)));
41
42
  this.ghastcoilerSpawns = pool
@@ -1 +1 @@
1
- {"version":3,"file":"cards-data.js","sourceRoot":"","sources":["../../src/cards/cards-data.ts"],"names":[],"mappings":";;;AAAA,iEAAkH;AAClH,6CAAgE;AAChE,oCAAoD;AAEvC,QAAA,iBAAiB,GAAwB;IACrD,yBAA0E;IAC1E,6BAAsF;IACtF,uBAAoF;IACpF,uCAAkG;IAClG,yBAA+E;IAC/E,uCAA6F;IAC7F,8DAAuF;IACvF,kEAAuF;CACvF,CAAC;AAGW,QAAA,YAAY,GAAsB,yBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,QAAA,wBAAwB,GAAG;;;;;;;CAOvC,CAAC;AACW,QAAA,cAAc,GAAG,gDAAmF,CAAC;AAElH,MAAa,SAAS;IAerB,YAA6B,QAAyB,EAAE,IAAI,GAAG,IAAI;QAAtC,aAAQ,GAAR,QAAQ,CAAiB;QACrD,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,YAAY,EAAE,CAAC;SACpB;IACF,CAAC;IAEM,YAAY,CAAC,WAA6B;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ;aACxB,QAAQ,EAAE;aACV,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CA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AC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,CAAC;IAEO,QAAQ,CAAC,IAAmB;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC;IACxC,CAAC;IAEO,YAAY,CAAC,WAA4B,EAAE,IAAY;QAC9D,MAAM,QAAQ,GAAS,mBAAW,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,QAAQ,KAAK,qBAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5G,CAAC;CACD;AAxHD,8BAwHC","sourcesContent":["import { AllCardsService, CardIds, isBattlegroundsCard, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { getRaceEnum, hasMechanic } from '../utils';\r\n\r\nexport const AURA_ENCHANTMENTS: readonly string[][] = [\r\n\t[CardIds.Kathranatir2, CardIds.Kathranatir_GraspOfKathranatirEnchantment1],\r\n\t[CardIds.KathranatirBattlegrounds, CardIds.Kathranatir_GraspOfKathranatirEnchantment2],\r\n\t[CardIds.MurlocWarleaderLegacy, CardIds.MurlocWarleader_MrgglaarglLegacyEnchantment],\r\n\t[CardIds.MurlocWarleaderBattlegrounds, CardIds.MurlocWarleader_MrgglaarglEnchantmentBattlegrounds],\r\n\t[CardIds.SouthseaCaptainLegacy, CardIds.SouthseaCaptain_YarrrLegacyEnchantment],\r\n\t[CardIds.SouthseaCaptainBattlegrounds, CardIds.SouthseaCaptain_YarrrEnchantmentBattlegrounds],\r\n\t[CardIds.LadySinestraBattlegrounds1, CardIds.DraconicBlessingEnchantmentBattlegrounds1],\r\n\t[CardIds.LadySinestraBattlegrounds2, CardIds.DraconicBlessingEnchantmentBattlegrounds2],\r\n];\r\n// Auras are effects that are permanent (unlike deathrattles or \"whenever\" effects)\r\n// and that stop once the origin entity leaves play (so it doesn't include buffs)\r\nexport const AURA_ORIGINS: readonly string[] = AURA_ENCHANTMENTS.map((pair) => pair[0]);\r\nexport const START_OF_COMBAT_CARD_IDS = [\r\n\tCardIds.RedWhelp,\r\n\tCardIds.RedWhelpBattlegrounds,\r\n\tCardIds.PrizedPromoDrake,\r\n\tCardIds.PrizedPromoDrakeBattlegrounds,\r\n\tCardIds.Crabby1,\r\n\tCardIds.CrabbyBattlegrounds,\r\n];\r\nexport const WHELP_CARD_IDS = [CardIds.RedWhelp, CardIds.RedWhelpBattlegrounds, CardIds.Onyxia_OnyxianWhelpToken];\r\n\r\nexport class CardsData {\r\n\t// public shredderSpawns: readonly string[];\r\n\tpublic ghastcoilerSpawns: readonly string[];\r\n\tpublic validDeathrattles: readonly string[];\r\n\tpublic impMamaSpawns: readonly string[];\r\n\tpublic gentleDjinniSpawns: readonly string[];\r\n\tpublic kilrekSpawns: readonly string[];\r\n\tpublic brannEpicEggSpawns: readonly string[];\r\n\t// public sneedsSpawns: readonly string[];\r\n\t// public treasureChestSpawns: readonly string[];\r\n\tpublic pirateSpawns: readonly string[];\r\n\tpublic auraOrigins: readonly string[];\r\n\r\n\tprivate minionsForTier: { [key: string]: readonly ReferenceCard[] };\r\n\r\n\tconstructor(private readonly allCards: AllCardsService, init = true) {\r\n\t\tif (init) {\r\n\t\t\tthis.inititialize();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic inititialize(validTribes?: readonly Race[]): void {\r\n\t\tconst pool = this.allCards\r\n\t\t\t.getCards()\r\n\t\t\t.filter((card) => isBattlegroundsCard(card))\r\n\t\t\t.filter((card) => !!card.techLevel)\r\n\t\t\t.filter((card) => card.set !== 'Vanilla');\r\n\t\tthis.minionsForTier = groupByFunction((card: ReferenceCard) => card.techLevel)(pool.filter((card) => !this.isGolden(card)));\r\n\t\tthis.ghastcoilerSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.id !== 'BGS_008')\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.validDeathrattles = pool\r\n\t\t\t// .filter((card) => !card.id.startsWith('TB_BaconUps')) // Ignore golden\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.impMamaSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'DEMON')\r\n\t\t\t.filter((card) => card.id !== CardIds.ImpMama)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.gentleDjinniSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'ELEMENTAL')\r\n\t\t\t.filter((card) => card.id !== CardIds.GentleDjinni)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.kilrekSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === Race[Race.DEMON])\r\n\t\t\t.filter((card) => card.id !== CardIds.KilrekBattlegrounds1)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.brannEpicEggSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => hasMechanic(card, 'BATTLECRY'))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.pirateSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'PIRATE')\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t}\r\n\r\n\tpublic avengeValue(cardId: string): number {\r\n\t\tswitch (cardId) {\r\n\t\t\tcase CardIds.BirdBuddy:\r\n\t\t\tcase CardIds.BirdBuddyBattlegrounds:\r\n\t\t\t\treturn 1;\r\n\t\t\tcase CardIds.FrostwolfLieutenant:\r\n\t\t\tcase CardIds.FrostwolfLieutenantBattlegrounds:\r\n\t\t\tcase CardIds.MechanoTank:\r\n\t\t\tcase CardIds.MechanoTankBattlegrounds:\r\n\t\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tcase CardIds.StormpikeLieutenant:\r\n\t\t\tcase CardIds.StormpikeLieutenantBattlegrounds:\r\n\t\t\t\treturn 2;\r\n\t\t\tcase CardIds.BuddingGreenthumb:\r\n\t\t\tcase CardIds.BuddingGreenthumbBattlegrounds:\r\n\t\t\tcase CardIds.Sisefin:\r\n\t\t\tcase CardIds.SisefinBattlegrounds:\r\n\t\t\t\treturn 3;\r\n\t\t\tcase CardIds.ImpatientDoomsayer:\r\n\t\t\tcase CardIds.ImpatientDoomsayerBattlegrounds:\r\n\t\t\tcase CardIds.WitchwingNestmatron:\r\n\t\t\tcase CardIds.WitchwingNestmatronBattlegrounds:\r\n\t\t\tcase CardIds.TonyTwoTusk:\r\n\t\t\tcase CardIds.TonyTwoTuskBattlegrounds:\r\n\t\t\tcase CardIds.Onyxia_Broodmother:\r\n\t\t\t\treturn 4;\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic getTavernLevel(cardId: string): number {\r\n\t\treturn this.allCards.getCard(cardId).techLevel;\r\n\t}\r\n\r\n\tpublic getRandomMinionForTavernTier(tavernTier: number): string {\r\n\t\t// Tzvern tier can be undefined for hero-power specific tokens, like the Amalgam, or when\r\n\t\t// for some reason tokens end up in the shop. For now, defaulting to 1 for tavern\r\n\t\t// level seems to work in all cases\r\n\t\treturn pickRandom(this.minionsForTier[tavernTier ?? 1]).id;\r\n\t}\r\n\r\n\tprivate isGolden(card: ReferenceCard): boolean {\r\n\t\treturn !!card.battlegroundsNormalDbfId;\r\n\t}\r\n\r\n\tprivate isValidTribe(validTribes: readonly Race[], race: string): boolean {\r\n\t\tconst raceEnum: Race = getRaceEnum(race);\r\n\t\treturn raceEnum === Race.ALL || !validTribes || validTribes.length === 0 || validTribes.includes(raceEnum);\r\n\t}\r\n}\r\n"]}
1
+ {"version":3,"file":"cards-data.js","sourceRoot":"","sources":["../../src/cards/cards-data.ts"],"names":[],"mappings":";;;AAAA,iEAA2H;AAC3H,6CAAgE;AAChE,oCAAoD;AAEvC,QAAA,iBAAiB,GAAwB;IACrD,yBAA0E;IAC1E,6BAAsF;IACtF,uBAAoF;IACpF,uCAAkG;IAClG,yBAA+E;IAC/E,uCAA6F;IAC7F,8DAAuF;IACvF,kEAAuF;CACvF,CAAC;AAGW,QAAA,YAAY,GAAsB,yBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,QAAA,wBAAwB,GAAG;;;;;;;CAOvC,CAAC;AACW,QAAA,cAAc,GAAG,gDAAmF,CAAC;AAElH,MAAa,SAAS;IAerB,YAA6B,QAAyB,EAAE,IAAI,GAAG,IAAI;QAAtC,aAAQ,GAAR,QAAQ,CAAiB;QACrD,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,YAAY,EAAE,CAAC;SACpB;IACF,CAAC;IAEM,YAAY,CAAC,WAA6B;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ;aACxB,QAAQ,EAAE;aACV,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oCAAmB,CAAC,IAAI,CAAC,CAAC;aAC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AC;IAChD,CAAC;IAEM,4BAA4B,CAAC,UAAkB;QAIrD,OAAO,kBAAU,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,CAAC;IAEO,QAAQ,CAAC,IAAmB;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC;IACxC,CAAC;IAEO,YAAY,CAAC,WAA4B,EAAE,IAAY;QAC9D,MAAM,QAAQ,GAAS,mBAAW,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,QAAQ,KAAK,qBAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5G,CAAC;CACD;AAzHD,8BAyHC","sourcesContent":["import { AllCardsService, CardIds, GameTag, isBattlegroundsCard, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { getRaceEnum, hasMechanic } from '../utils';\r\n\r\nexport const AURA_ENCHANTMENTS: readonly string[][] = [\r\n\t[CardIds.Kathranatir2, CardIds.Kathranatir_GraspOfKathranatirEnchantment1],\r\n\t[CardIds.KathranatirBattlegrounds, CardIds.Kathranatir_GraspOfKathranatirEnchantment2],\r\n\t[CardIds.MurlocWarleaderLegacy, CardIds.MurlocWarleader_MrgglaarglLegacyEnchantment],\r\n\t[CardIds.MurlocWarleaderBattlegrounds, CardIds.MurlocWarleader_MrgglaarglEnchantmentBattlegrounds],\r\n\t[CardIds.SouthseaCaptainLegacy, CardIds.SouthseaCaptain_YarrrLegacyEnchantment],\r\n\t[CardIds.SouthseaCaptainBattlegrounds, CardIds.SouthseaCaptain_YarrrEnchantmentBattlegrounds],\r\n\t[CardIds.LadySinestraBattlegrounds1, CardIds.DraconicBlessingEnchantmentBattlegrounds1],\r\n\t[CardIds.LadySinestraBattlegrounds2, CardIds.DraconicBlessingEnchantmentBattlegrounds2],\r\n];\r\n// Auras are effects that are permanent (unlike deathrattles or \"whenever\" effects)\r\n// and that stop once the origin entity leaves play (so it doesn't include buffs)\r\nexport const AURA_ORIGINS: readonly string[] = AURA_ENCHANTMENTS.map((pair) => pair[0]);\r\nexport const START_OF_COMBAT_CARD_IDS = [\r\n\tCardIds.RedWhelp,\r\n\tCardIds.RedWhelpBattlegrounds,\r\n\tCardIds.PrizedPromoDrake,\r\n\tCardIds.PrizedPromoDrakeBattlegrounds,\r\n\tCardIds.Crabby1,\r\n\tCardIds.CrabbyBattlegrounds,\r\n];\r\nexport const WHELP_CARD_IDS = [CardIds.RedWhelp, CardIds.RedWhelpBattlegrounds, CardIds.Onyxia_OnyxianWhelpToken];\r\n\r\nexport class CardsData {\r\n\t// public shredderSpawns: readonly string[];\r\n\tpublic ghastcoilerSpawns: readonly string[];\r\n\tpublic validDeathrattles: readonly string[];\r\n\tpublic impMamaSpawns: readonly string[];\r\n\tpublic gentleDjinniSpawns: readonly string[];\r\n\tpublic kilrekSpawns: readonly string[];\r\n\tpublic brannEpicEggSpawns: readonly string[];\r\n\t// public sneedsSpawns: readonly string[];\r\n\t// public treasureChestSpawns: readonly string[];\r\n\tpublic pirateSpawns: readonly string[];\r\n\tpublic auraOrigins: readonly string[];\r\n\r\n\tprivate minionsForTier: { [key: string]: readonly ReferenceCard[] };\r\n\r\n\tconstructor(private readonly allCards: AllCardsService, init = true) {\r\n\t\tif (init) {\r\n\t\t\tthis.inititialize();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic inititialize(validTribes?: readonly Race[]): void {\r\n\t\tconst pool = this.allCards\r\n\t\t\t.getCards()\r\n\t\t\t.filter((card) => isBattlegroundsCard(card))\r\n\t\t\t.filter((card) => !!card.techLevel)\r\n\t\t\t.filter((card) => !hasMechanic(card, GameTag[GameTag.BACON_BUDDY]))\r\n\t\t\t.filter((card) => card.set !== 'Vanilla');\r\n\t\tthis.minionsForTier = groupByFunction((card: ReferenceCard) => card.techLevel)(pool.filter((card) => !this.isGolden(card)));\r\n\t\tthis.ghastcoilerSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.id !== 'BGS_008')\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.validDeathrattles = pool\r\n\t\t\t// .filter((card) => !card.id.startsWith('TB_BaconUps')) // Ignore golden\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.impMamaSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'DEMON')\r\n\t\t\t.filter((card) => card.id !== CardIds.ImpMama)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.gentleDjinniSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'ELEMENTAL')\r\n\t\t\t.filter((card) => card.id !== CardIds.GentleDjinni)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.kilrekSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === Race[Race.DEMON])\r\n\t\t\t.filter((card) => card.id !== CardIds.KilrekBattlegrounds1)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.brannEpicEggSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => hasMechanic(card, 'BATTLECRY'))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.pirateSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'PIRATE')\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t}\r\n\r\n\tpublic avengeValue(cardId: string): number {\r\n\t\tswitch (cardId) {\r\n\t\t\tcase CardIds.BirdBuddy:\r\n\t\t\tcase CardIds.BirdBuddyBattlegrounds:\r\n\t\t\t\treturn 1;\r\n\t\t\tcase CardIds.FrostwolfLieutenant:\r\n\t\t\tcase CardIds.FrostwolfLieutenantBattlegrounds:\r\n\t\t\tcase CardIds.MechanoTank:\r\n\t\t\tcase CardIds.MechanoTankBattlegrounds:\r\n\t\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tcase CardIds.StormpikeLieutenant:\r\n\t\t\tcase CardIds.StormpikeLieutenantBattlegrounds:\r\n\t\t\t\treturn 2;\r\n\t\t\tcase CardIds.BuddingGreenthumb:\r\n\t\t\tcase CardIds.BuddingGreenthumbBattlegrounds:\r\n\t\t\tcase CardIds.Sisefin:\r\n\t\t\tcase CardIds.SisefinBattlegrounds:\r\n\t\t\t\treturn 3;\r\n\t\t\tcase CardIds.ImpatientDoomsayer:\r\n\t\t\tcase CardIds.ImpatientDoomsayerBattlegrounds:\r\n\t\t\tcase CardIds.WitchwingNestmatron:\r\n\t\t\tcase CardIds.WitchwingNestmatronBattlegrounds:\r\n\t\t\tcase CardIds.TonyTwoTusk:\r\n\t\t\tcase CardIds.TonyTwoTuskBattlegrounds:\r\n\t\t\tcase CardIds.Onyxia_Broodmother:\r\n\t\t\t\treturn 4;\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic getTavernLevel(cardId: string): number {\r\n\t\treturn this.allCards.getCard(cardId).techLevel;\r\n\t}\r\n\r\n\tpublic getRandomMinionForTavernTier(tavernTier: number): string {\r\n\t\t// Tzvern tier can be undefined for hero-power specific tokens, like the Amalgam, or when\r\n\t\t// for some reason tokens end up in the shop. For now, defaulting to 1 for tavern\r\n\t\t// level seems to work in all cases\r\n\t\treturn pickRandom(this.minionsForTier[tavernTier ?? 1]).id;\r\n\t}\r\n\r\n\tprivate isGolden(card: ReferenceCard): boolean {\r\n\t\treturn !!card.battlegroundsNormalDbfId;\r\n\t}\r\n\r\n\tprivate isValidTribe(validTribes: readonly Race[], race: string): boolean {\r\n\t\tconst raceEnum: Race = getRaceEnum(race);\r\n\t\treturn raceEnum === Race.ALL || !validTribes || validTribes.length === 0 || validTribes.includes(raceEnum);\r\n\t}\r\n}\r\n"]}
@@ -362,20 +362,20 @@ const processMinionDeath = (board1, board1Hero, board2, board2Hero, allCards, ca
362
362
  exports.processMinionDeath = processMinionDeath;
363
363
  const handleAfterMinionsDeaths = (board1, deadEntities1, heroEntity1, board2, deadEntities2, heroEntity2, allCards, cardsData, sharedState, spectator) => {
364
364
  const random = Math.random() > 0.5;
365
- handleAfterMinionsDeathsForBoard(random ? board1 : board2, random ? deadEntities1 : deadEntities2, random ? heroEntity1 : heroEntity2, random ? board2 : board1, random ? deadEntities2 : deadEntities1, allCards, cardsData, sharedState, spectator);
366
- handleAfterMinionsDeathsForBoard(!random ? board1 : board2, !random ? deadEntities1 : deadEntities2, !random ? heroEntity1 : heroEntity2, !random ? board2 : board1, !random ? deadEntities2 : deadEntities1, allCards, cardsData, sharedState, spectator);
365
+ handleAfterMinionsDeathsForBoard(random ? board1 : board2, random ? deadEntities1 : deadEntities2, random ? heroEntity1 : heroEntity2, random ? board2 : board1, random ? deadEntities2 : deadEntities1, random ? heroEntity2 : heroEntity1, allCards, cardsData, sharedState, spectator);
366
+ handleAfterMinionsDeathsForBoard(!random ? board1 : board2, !random ? deadEntities1 : deadEntities2, !random ? heroEntity1 : heroEntity2, !random ? board2 : board1, !random ? deadEntities2 : deadEntities1, !random ? heroEntity2 : heroEntity1, allCards, cardsData, sharedState, spectator);
367
367
  };
368
- const handleAfterMinionsDeathsForBoard = (friendlyBoard, friendlyDeadEntities, friendlyHeroEntity, otherBoard, otherDeadEntities, allCards, cardsData, sharedState, spectator) => {
368
+ const handleAfterMinionsDeathsForBoard = (friendlyBoard, friendlyDeadEntities, friendlyHeroEntity, otherBoard, otherDeadEntities, otherHeroEntity, allCards, cardsData, sharedState, spectator) => {
369
369
  for (const deadEntity of friendlyDeadEntities) {
370
370
  const killer = deadEntity.lastAffectedByEntity;
371
371
  if (!killer) {
372
372
  continue;
373
373
  }
374
374
  if (killer.friendly !== deadEntity.friendly) {
375
- if (friendlyHeroEntity.heroPowerId === "BG20_HERO_100p") {
376
- utils_2.modifyAttack(killer, 1, friendlyBoard, allCards);
377
- utils_2.afterStatsUpdate(killer, friendlyBoard, allCards);
378
- friendlyBoard
375
+ if (otherHeroEntity.heroPowerId === "BG20_HERO_100p") {
376
+ utils_2.modifyAttack(killer, 1, otherBoard, allCards);
377
+ utils_2.afterStatsUpdate(killer, otherBoard, allCards);
378
+ otherBoard
379
379
  .filter((e) => e.cardId === "BG20_HERO_100_Buddy" || e.cardId === "BG20_HERO_100_Buddy_G")
380
380
  .forEach((icesnarl) => {
381
381
  utils_2.modifyHealth(icesnarl, icesnarl.cardId === "BG20_HERO_100_Buddy_G" ? 2 : 1, friendlyBoard, allCards);
@@ -1 +1 @@
1
- {"version":3,"file":"attack.js","sourceRoot":"","sources":["../../src/simulation/attack.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAI9E,6CAA+C;AAC/C,gEAA2D;AAC3D,oCAAsI;AACtI,mCAAkD;AAClD,qCAA8C;AAC9C,+DAAiI;AACjI,6DAAkH;AAClH,qCAAuC;AAEvC,iDAAoD;AAEpD,uDAAwD;AAGjD,MAAM,cAA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AW,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;IAGD,iCAAkB,CAAC,qBAAqB,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChF,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,EAAE,eAAe,CAAC,CAAC;AACpF,CAAC,CAAC;AAtDW,QAAA,mBAAmB,uBAsD9B","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 { pickRandom } from '../services/utils';\r\nimport { validEnchantments } from '../simulate-bgs-battle';\r\nimport { addCardsInHand, afterStatsUpdate, hasCorrectTribe, hasMechanic, isCorrectTribe, modifyAttack, modifyHealth } from '../utils';\r\nimport { applyAuras, removeAuras } from './auras';\r\nimport { applyAvengeEffects } from './avenge';\r\nimport { applyMinionDeathEffect, applyMonstrosity, handleDeathrattleEffects, rememberDeathrattles } from './deathrattle-effects';\r\nimport { spawnEntities, spawnEntitiesFromDeathrattle, spawnEntitiesFromEnchantments } from './deathrattle-spawns';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { SharedState } from './shared-state';\r\nimport { handleSpawnEffects } from './spawn-effect';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { getHeroPowerForHero } from './start-of-combat';\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\tconst attackingHeroPowerId = attackingBoardHero.heroPowerId || getHeroPowerForHero(attackingBoardHero.cardId);\r\n\tconst defendingHeroPowerId = defendingBoardHero.heroPowerId || getHeroPowerForHero(defendingBoardHero.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\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), attackingEntity.attacking);\r\n\t\tconst numberOfAttacks = attackingEntity.megaWindfury ? 4 : attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// The auras need to be handled on a per-attack basis, as otherwise minions that spawn\r\n\t\t\t// in-between attacks don't get aura buffs\r\n\t\t\tapplyAuras(attackingBoard, numberOfDeathwingPresents, spawns, allCards);\r\n\t\t\tapplyAuras(defendingBoard, numberOfDeathwingPresents, spawns, allCards);\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\tspectator.registerAttack(attackingEntity, defendingEntity, attackingBoard, defendingBoard);\r\n\t\t\t\tapplyOnBeingAttackedBuffs(defendingEntity, defendingBoard, allCards, spectator);\r\n\t\t\t\tperformAttack(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tspawns,\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\tapplyAfterAttackEffects(attackingEntity, attackingBoard, attackingBoardHero, allCards, spectator);\r\n\t\t\t\t// FIXME: I don't know the behavior with Windfury. Should the attack be done right away, before\r\n\t\t\t\t// the windfury triggers again? The current behavior attacks after the windfury is over\r\n\t\t\t\tif (\r\n\t\t\t\t\tdefendingEntity.health > 0 &&\r\n\t\t\t\t\t!defendingEntity.definitelyDead &&\r\n\t\t\t\t\t(defendingEntity.cardId === CardIds.YoHoOgre || defendingEntity.cardId === CardIds.YoHoOgreBattlegrounds)\r\n\t\t\t\t) {\r\n\t\t\t\t\tdefendingEntity.attackImmediately = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tremoveAuras(attackingBoard, spawns);\r\n\t\t\tremoveAuras(defendingBoard, spawns);\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 || attackingEntity.cardId === CardIds.BonkerBattlegrounds) {\r\n\t\taddCardsInHand(attackingBoardHero, 1, attackingBoard, allCards, spectator, CardIds.BloodGem);\r\n\t}\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\tspawns: 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((e) => e.cardId === CardIds.PrestorsPyrospawn || e.cardId === CardIds.PrestorsPyrospawnBattlegrounds);\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.PrestorsPyrospawnBattlegrounds ? 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\tspawns,\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// 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\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\t// console.log('immune when attack', attackingEntity);\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\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\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\tspawns,\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\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\tspawns,\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\tspawns,\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\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, allCards, spawns, sharedState, spectator);\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 = validDeathrattles[Math.floor(Math.random() * validDeathrattles.length)];\r\n\tspectator.registerPowerTarget(sourceEntity, targetEntity, attackingBoard);\r\n\tbuildBoardAfterDeathrattleSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\t-1,\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\tbuildBoardAfterRebornSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\t-1,\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) => entity.attack > 0).filter((entity) => !entity.cantAttack);\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 getNeighbours = (board: BoardEntity[], entity: BoardEntity, deadEntityIndex?: number): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\tif (deadEntityIndex != null) {\r\n\t\tif (deadEntityIndex < board.length - 1) {\r\n\t\t\tneighbours.push(board[deadEntityIndex]);\r\n\t\t}\r\n\t\t// Could happen if a cleave kills several entities at the same time\r\n\t\tif (deadEntityIndex > 0 && deadEntityIndex <= board.length) {\r\n\t\t\tneighbours.push(board[deadEntityIndex - 1]);\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 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\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 = (defendingBoard: BoardEntity[], attackingEntity: BoardEntity, ignoreTaunts = false): 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 if (!ignoreTaunts) {\r\n\t\tconst taunts = defendingBoard.filter((entity) => entity.taunt);\r\n\t\tpossibleDefenders = taunts.length > 0 ? taunts : defendingBoard;\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard;\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) => entity.cardId === CardIds.ElistraTheImmortal2 || entity.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\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) {\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 || entityBoard[i].cardId === CardIds.HolyMecherelBattlegrounds)\r\n\t\t\t) {\r\n\t\t\t\tentityBoard[i].divineShield = true;\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, 1, entityBoard, allCards, spectator, CardIds.BloodGem);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.GemsplitterBattlegrounds) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, 2, entityBoard, allCards, spectator, 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\tif (entityBoard[i].entityId === entity.entityId) {\r\n\t\t\t\tentity.divineShield = false;\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, 1, 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, 2, 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\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 - bumpInto.attack;\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\t// return entity;\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, 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\tentityBoard.splice(index + 1, 0, ...entitySpawns);\r\n\t\tspectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t\thandleSpawnEffects(entityBoard, entitySpawns, allCards, spectator);\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\tconst [deadMinionIndexes1, deadEntities1] = makeMinionsDie(board1, allCards);\r\n\tconst [deadMinionIndexes2, deadEntities2] = makeMinionsDie(board2, allCards);\r\n\tspectator.registerDeadEntities(deadMinionIndexes1, deadEntities1, deadMinionIndexes2, deadEntities2);\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\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes1,\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\t// Make sure we only return when there are no more deaths to 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// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds || entity.cardId === CardIds.FishOfNzothBattlegrounds,\r\n\t\t)\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities1, cardsData));\r\n\tboard2\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds || entity.cardId === CardIds.FishOfNzothBattlegrounds,\r\n\t\t)\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities2, cardsData));\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// 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\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\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\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 (friendlyHeroEntity.heroPowerId === CardIds.Rokara_GloryOfCombat) {\r\n\t\t\t\tmodifyAttack(killer, 1, friendlyBoard, allCards);\r\n\t\t\t\tafterStatsUpdate(killer, friendlyBoard, allCards);\r\n\t\t\t\t// Icesnarl the Mighty\r\n\t\t\t\tfriendlyBoard\r\n\t\t\t\t\t.filter((e) => e.cardId === CardIds.IcesnarlTheMighty || e.cardId === CardIds.IcesnarlTheMightyBattlegrounds)\r\n\t\t\t\t\t.forEach((icesnarl) => {\r\n\t\t\t\t\t\tmodifyHealth(icesnarl, icesnarl.cardId === CardIds.IcesnarlTheMightyBattlegrounds ? 2 : 1, friendlyBoard, allCards);\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\tdeadMinionIndexes: 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 < deadMinionIndexes.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst index = deadMinionIndexes[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\tindex,\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} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(index, 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\tdeadMinionIndexes: 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 < deadMinionIndexes.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst index = deadMinionIndexes[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\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\tindex,\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} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(index, 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.GlyphGuardian2) {\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).race, Race.PIRATE)) {\r\n\t\tconst ripsnarls = attackingBoard\r\n\t\t\t.filter((e) => e.cardId === CardIds.RipsnarlCaptain)\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tconst ripsnarlsTB = attackingBoard\r\n\t\t\t.filter((entity) => entity.cardId === CardIds.RipsnarlCaptainBattlegrounds)\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tripsnarls.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 2, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(attacker, 2, 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, 4, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(attacker, 4, 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).race, 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};\r\n\r\nexport const applyOnBeingAttackedBuffs = (\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((entity) => entity.cardId === CardIds.ChampionOfYshaarjBattlegrounds);\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};\r\n\r\nconst makeMinionsDie = (board: BoardEntity[], allCards: AllCardsService): [number[], BoardEntity[]] => {\r\n\tconst deadMinionIndexes: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tconst index = board.map((entity) => entity.entityId).indexOf(board[i].entityId);\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexes.push(i);\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\tboard.splice(index, 1);\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\treturn [deadMinionIndexes, 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\tdeadMinionIndex: 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\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 (deadMinionIndex >= 0) {\r\n\t\tapplyMinionDeathEffect(\r\n\t\t\tdeadEntity,\r\n\t\t\tdeadMinionIndex,\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\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\tdeadMinionIndex,\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\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,\r\n\t\t\t\tenchantments: [\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcardId: deathrattle,\r\n\t\t\t\t\t\toriginEntityId: deadEntity.entityId,\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\tdeadMinionIndex,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\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\tdeadMinionIndex,\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\tdeadMinionIndex: 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 otherEntityCardIds = boardWithKilledMinion.filter((e) => e.entityId !== deadEntity.entityId).map((e) => e.cardId);\r\n\tconst numberOfReborns =\r\n\t\t1 +\r\n\t\t1 * otherEntityCardIds.filter((cardId) => cardId === CardIds.ArfusBattlegrounds1).length +\r\n\t\t2 * otherEntityCardIds.filter((cardId) => cardId === CardIds.ArfusBattlegrounds2).length;\r\n\t// Reborn happens after deathrattles\r\n\tconst entitiesFromReborn: readonly BoardEntity[] =\r\n\t\tdeadEntity.reborn && deadMinionIndex >= 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 )\r\n\t\t\t: [];\r\n\tperformEntitySpawns(\r\n\t\tentitiesFromReborn,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndex,\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\nexport const performEntitySpawns = (\r\n\tcandidateEntities: readonly BoardEntity[],\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndex: 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 aliveEntites = candidateEntities.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\r\n\t// const roomToSpawn: number = 7 - boardWithKilledMinion.length;\r\n\t// const spawnedEntities: readonly BoardEntity[] = aliveEntites.slice(0, roomToSpawn);\r\n\r\n\tconst indexFromRight = boardWithKilledMinion.length - deadMinionIndex;\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\tboardWithKilledMinion.splice(boardWithKilledMinion.length - indexFromRight, 0, newMinion);\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\tremoveAuras(boardWithKilledMinion, cardsData);\r\n\t\t\tremoveAuras(opponentBoard, cardsData);\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\t// Minion has already been removed from the board in the previous step\r\n\thandleSpawnEffects(boardWithKilledMinion, spawnedEntities, allCards, spectator);\r\n\tspectator.registerMinionsSpawn(deadEntity, boardWithKilledMinion, spawnedEntities);\r\n};\r\n"]}
1
+ {"version":3,"file":"attack.js","sourceRoot":"","sources":["../../src/simulation/attack.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAI9E,6CAA+C;AAC/C,gEAA2D;AAC3D,oCAAsI;AACtI,mCAAkD;AAClD,qCAA8C;AAC9C,+DAAiI;AACjI,6DAAkH;AAClH,qCAAuC;AAEvC,iDAAoD;AAEpD,uDAAwD;AAGjD,MAAM,cAAc,GAAG,CAC7B,cAA6B,EAC7B,kBAAmC,EACnC,cAA6B,EAC7B,kBAAmC,EACnC,oBAA4B,EAC5B,QAAyB,EACzB,MAAiB,EACjB,WAAwB,EACxB,SAAoB,EACpB,yBAAkC,EACzB,EAAE;IACX,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/D,OAAO;KACP;IACD,MAAM,oBAAoB,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CAAC,CAAC;SAChC;KACD;IAGD,iCAAkB,CAAC,qBAAqB,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChF,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,EAAE,eAAe,CAAC,CAAC;AACpF,CAAC,CAAC;AAtDW,QAAA,mBAAmB,uBAsD9B","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 { pickRandom } from '../services/utils';\r\nimport { validEnchantments } from '../simulate-bgs-battle';\r\nimport { addCardsInHand, afterStatsUpdate, hasCorrectTribe, hasMechanic, isCorrectTribe, modifyAttack, modifyHealth } from '../utils';\r\nimport { applyAuras, removeAuras } from './auras';\r\nimport { applyAvengeEffects } from './avenge';\r\nimport { applyMinionDeathEffect, applyMonstrosity, handleDeathrattleEffects, rememberDeathrattles } from './deathrattle-effects';\r\nimport { spawnEntities, spawnEntitiesFromDeathrattle, spawnEntitiesFromEnchantments } from './deathrattle-spawns';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { SharedState } from './shared-state';\r\nimport { handleSpawnEffects } from './spawn-effect';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { getHeroPowerForHero } from './start-of-combat';\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\tconst attackingHeroPowerId = attackingBoardHero.heroPowerId || getHeroPowerForHero(attackingBoardHero.cardId);\r\n\tconst defendingHeroPowerId = defendingBoardHero.heroPowerId || getHeroPowerForHero(defendingBoardHero.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\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), attackingEntity.attacking);\r\n\t\tconst numberOfAttacks = attackingEntity.megaWindfury ? 4 : attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// The auras need to be handled on a per-attack basis, as otherwise minions that spawn\r\n\t\t\t// in-between attacks don't get aura buffs\r\n\t\t\tapplyAuras(attackingBoard, numberOfDeathwingPresents, spawns, allCards);\r\n\t\t\tapplyAuras(defendingBoard, numberOfDeathwingPresents, spawns, allCards);\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\tspectator.registerAttack(attackingEntity, defendingEntity, attackingBoard, defendingBoard);\r\n\t\t\t\tapplyOnBeingAttackedBuffs(defendingEntity, defendingBoard, allCards, spectator);\r\n\t\t\t\tperformAttack(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tallCards,\r\n\t\t\t\t\tspawns,\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\tapplyAfterAttackEffects(attackingEntity, attackingBoard, attackingBoardHero, allCards, spectator);\r\n\t\t\t\t// FIXME: I don't know the behavior with Windfury. Should the attack be done right away, before\r\n\t\t\t\t// the windfury triggers again? The current behavior attacks after the windfury is over\r\n\t\t\t\tif (\r\n\t\t\t\t\tdefendingEntity.health > 0 &&\r\n\t\t\t\t\t!defendingEntity.definitelyDead &&\r\n\t\t\t\t\t(defendingEntity.cardId === CardIds.YoHoOgre || defendingEntity.cardId === CardIds.YoHoOgreBattlegrounds)\r\n\t\t\t\t) {\r\n\t\t\t\t\tdefendingEntity.attackImmediately = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tremoveAuras(attackingBoard, spawns);\r\n\t\t\tremoveAuras(defendingBoard, spawns);\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 || attackingEntity.cardId === CardIds.BonkerBattlegrounds) {\r\n\t\taddCardsInHand(attackingBoardHero, 1, attackingBoard, allCards, spectator, CardIds.BloodGem);\r\n\t}\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\tspawns: 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((e) => e.cardId === CardIds.PrestorsPyrospawn || e.cardId === CardIds.PrestorsPyrospawnBattlegrounds);\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.PrestorsPyrospawnBattlegrounds ? 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\tspawns,\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// 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\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\t// console.log('immune when attack', attackingEntity);\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\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\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\tspawns,\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\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\tspawns,\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\tspawns,\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\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, allCards, spawns, sharedState, spectator);\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 = validDeathrattles[Math.floor(Math.random() * validDeathrattles.length)];\r\n\tspectator.registerPowerTarget(sourceEntity, targetEntity, attackingBoard);\r\n\tbuildBoardAfterDeathrattleSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\t-1,\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\tbuildBoardAfterRebornSpawns(\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\ttargetEntity,\r\n\t\t-1,\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) => entity.attack > 0).filter((entity) => !entity.cantAttack);\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 getNeighbours = (board: BoardEntity[], entity: BoardEntity, deadEntityIndex?: number): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\tif (deadEntityIndex != null) {\r\n\t\tif (deadEntityIndex < board.length - 1) {\r\n\t\t\tneighbours.push(board[deadEntityIndex]);\r\n\t\t}\r\n\t\t// Could happen if a cleave kills several entities at the same time\r\n\t\tif (deadEntityIndex > 0 && deadEntityIndex <= board.length) {\r\n\t\t\tneighbours.push(board[deadEntityIndex - 1]);\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 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\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 = (defendingBoard: BoardEntity[], attackingEntity: BoardEntity, ignoreTaunts = false): 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 if (!ignoreTaunts) {\r\n\t\tconst taunts = defendingBoard.filter((entity) => entity.taunt);\r\n\t\tpossibleDefenders = taunts.length > 0 ? taunts : defendingBoard;\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard;\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) => entity.cardId === CardIds.ElistraTheImmortal2 || entity.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\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) {\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 || entityBoard[i].cardId === CardIds.HolyMecherelBattlegrounds)\r\n\t\t\t) {\r\n\t\t\t\tentityBoard[i].divineShield = true;\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, 1, entityBoard, allCards, spectator, CardIds.BloodGem);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.GemsplitterBattlegrounds) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, 2, entityBoard, allCards, spectator, 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\tif (entityBoard[i].entityId === entity.entityId) {\r\n\t\t\t\tentity.divineShield = false;\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, 1, 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, 2, 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\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 - bumpInto.attack;\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\t// return entity;\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, 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\tentityBoard.splice(index + 1, 0, ...entitySpawns);\r\n\t\tspectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t\thandleSpawnEffects(entityBoard, entitySpawns, allCards, spectator);\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\tconst [deadMinionIndexes1, deadEntities1] = makeMinionsDie(board1, allCards);\r\n\tconst [deadMinionIndexes2, deadEntities2] = makeMinionsDie(board2, allCards);\r\n\tspectator.registerDeadEntities(deadMinionIndexes1, deadEntities1, deadMinionIndexes2, deadEntities2);\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\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes1,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes2,\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\tdeadMinionIndexes1,\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\t// Make sure we only return when there are no more deaths to 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// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds || entity.cardId === CardIds.FishOfNzothBattlegrounds,\r\n\t\t)\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities1, cardsData));\r\n\tboard2\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.AvatarOfNzoth_FishOfNzothTokenBattlegrounds || entity.cardId === CardIds.FishOfNzothBattlegrounds,\r\n\t\t)\r\n\t\t.forEach((entity) => rememberDeathrattles(entity, deadEntities2, cardsData));\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// 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((e) => e.cardId === CardIds.IcesnarlTheMighty || e.cardId === CardIds.IcesnarlTheMightyBattlegrounds)\r\n\t\t\t\t\t.forEach((icesnarl) => {\r\n\t\t\t\t\t\tmodifyHealth(icesnarl, icesnarl.cardId === CardIds.IcesnarlTheMightyBattlegrounds ? 2 : 1, friendlyBoard, allCards);\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\tdeadMinionIndexes: 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 < deadMinionIndexes.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst index = deadMinionIndexes[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\tindex,\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} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(index, 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\tdeadMinionIndexes: 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 < deadMinionIndexes.length; i++) {\r\n\t\tconst entity = deadEntities[i];\r\n\t\tconst index = deadMinionIndexes[i];\r\n\t\tif (entity.health <= 0 || entity.definitelyDead) {\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\tindex,\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} else if (firstBoard.length > 0) {\r\n\t\t\t// const newBoardD = [...firstBoard];\r\n\t\t\tfirstBoard.splice(index, 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.GlyphGuardian2) {\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).race, Race.PIRATE)) {\r\n\t\tconst ripsnarls = attackingBoard\r\n\t\t\t.filter((e) => e.cardId === CardIds.RipsnarlCaptain)\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tconst ripsnarlsTB = attackingBoard\r\n\t\t\t.filter((entity) => entity.cardId === CardIds.RipsnarlCaptainBattlegrounds)\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tripsnarls.forEach((captain) => {\r\n\t\t\tmodifyAttack(attacker, 2, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(attacker, 2, 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, 4, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(attacker, 4, 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).race, 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};\r\n\r\nexport const applyOnBeingAttackedBuffs = (\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((entity) => entity.cardId === CardIds.ChampionOfYshaarjBattlegrounds);\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};\r\n\r\nconst makeMinionsDie = (board: BoardEntity[], allCards: AllCardsService): [number[], BoardEntity[]] => {\r\n\tconst deadMinionIndexes: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tconst index = board.map((entity) => entity.entityId).indexOf(board[i].entityId);\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexes.push(i);\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\tboard.splice(index, 1);\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\treturn [deadMinionIndexes, 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\tdeadMinionIndex: 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\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 (deadMinionIndex >= 0) {\r\n\t\tapplyMinionDeathEffect(\r\n\t\t\tdeadEntity,\r\n\t\t\tdeadMinionIndex,\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\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\tdeadMinionIndex,\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\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,\r\n\t\t\t\tenchantments: [\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcardId: deathrattle,\r\n\t\t\t\t\t\toriginEntityId: deadEntity.entityId,\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\tdeadMinionIndex,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentBoardHero,\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\tdeadMinionIndex,\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\tdeadMinionIndex: 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 otherEntityCardIds = boardWithKilledMinion.filter((e) => e.entityId !== deadEntity.entityId).map((e) => e.cardId);\r\n\tconst numberOfReborns =\r\n\t\t1 +\r\n\t\t1 * otherEntityCardIds.filter((cardId) => cardId === CardIds.ArfusBattlegrounds1).length +\r\n\t\t2 * otherEntityCardIds.filter((cardId) => cardId === CardIds.ArfusBattlegrounds2).length;\r\n\t// Reborn happens after deathrattles\r\n\tconst entitiesFromReborn: readonly BoardEntity[] =\r\n\t\tdeadEntity.reborn && deadMinionIndex >= 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 )\r\n\t\t\t: [];\r\n\tperformEntitySpawns(\r\n\t\tentitiesFromReborn,\r\n\t\tboardWithKilledMinion,\r\n\t\tboardWithKilledMinionHero,\r\n\t\tdeadEntity,\r\n\t\tdeadMinionIndex,\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\nexport const performEntitySpawns = (\r\n\tcandidateEntities: readonly BoardEntity[],\r\n\tboardWithKilledMinion: BoardEntity[],\r\n\tboardWithKilledMinionHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tdeadMinionIndex: 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 aliveEntites = candidateEntities.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\r\n\t// const roomToSpawn: number = 7 - boardWithKilledMinion.length;\r\n\t// const spawnedEntities: readonly BoardEntity[] = aliveEntites.slice(0, roomToSpawn);\r\n\r\n\tconst indexFromRight = boardWithKilledMinion.length - deadMinionIndex;\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\tboardWithKilledMinion.splice(boardWithKilledMinion.length - indexFromRight, 0, newMinion);\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\tremoveAuras(boardWithKilledMinion, cardsData);\r\n\t\t\tremoveAuras(opponentBoard, cardsData);\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\t// Minion has already been removed from the board in the previous step\r\n\thandleSpawnEffects(boardWithKilledMinion, spawnedEntities, allCards, spectator);\r\n\tspectator.registerMinionsSpawn(deadEntity, boardWithKilledMinion, spawnedEntities);\r\n};\r\n"]}
@@ -164,7 +164,7 @@ const handleDeathrattleEffects = (boardWithDeadEntity, boardWithDeadEntityHero,
164
164
  break;
165
165
  case "TB_BaconShop_HERO_41_Buddy":
166
166
  for (let i = 0; i < Math.min(1, boardWithDeadEntity.length); i++) {
167
- const rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - i];
167
+ const rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - 1 - i];
168
168
  if (rightMostMinion) {
169
169
  const refCard = allCards.getCard(rightMostMinion.cardId);
170
170
  const goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);
@@ -174,11 +174,11 @@ const handleDeathrattleEffects = (boardWithDeadEntity, boardWithDeadEntityHero,
174
174
  utils_2.afterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);
175
175
  spectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);
176
176
  }
177
- break;
178
177
  }
178
+ break;
179
179
  case "TB_BaconShop_HERO_41_Buddy_G":
180
180
  for (let i = 0; i < Math.min(2, boardWithDeadEntity.length); i++) {
181
- const rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - i];
181
+ const rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - 1 - i];
182
182
  if (rightMostMinion) {
183
183
  const refCard = allCards.getCard(rightMostMinion.cardId);
184
184
  const goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);
@@ -188,8 +188,8 @@ const handleDeathrattleEffects = (boardWithDeadEntity, boardWithDeadEntityHero,
188
188
  utils_2.afterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);
189
189
  spectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);
190
190
  }
191
- break;
192
191
  }
192
+ break;
193
193
  }
194
194
  let enchantments = [...((_a = deadEntity.enchantments) !== null && _a !== void 0 ? _a : [])];
195
195
  const threshold = 20;
@@ -1 +1 @@
1
- {"version":3,"file":"deathrattle-effects.js","sourceRoot":"","sources":["../../src/simulation/deathrattle-effects.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAG9E,oDAA8D;AAC9D,6CAA6F;AAC7F,oCAYkB;AAClB,qCAAmG;AACnG,mCAA0D;AAC1D,6DAAqD;AAI9C,MAAM,wBAAwB,GAAG,CACvC,mBAAkC,EAClC,uBAAwC,EACxC,UAAuB,EACvB,UAAyB,EACzB,cAA+B,EAC/B,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACxB,SAAoB,EACb,EAAE;;IACT,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,cAA4B,CAAC,CAAC;IAClG,MAAM,eAAe,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,sBAAwC,CAAC,CAAC;IACpH,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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AC,sBAAsB,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,CAAC;KACpF;SAAM;QACN,IAAI,CAAC,sBAAsB,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,CAAC;KAC3F;AACF,CAAC,CAAC;AA9BW,QAAA,oBAAoB,wBA8B/B;AAEF,MAAM,sBAAsB,GAAG,CAAC,mBAAkC,EAAE,QAAyB,EAAE,EAAE;IAChG,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAC1C,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,cAA6B,IAAI,MAAM,CAAC,MAAM,kBAA8B,CACrG,CAAC;IACF,MAAM,cAAc,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,sBAAoC,CAAC,CAAC;IACjH,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC3B,oBAAY,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QACxD,wBAAgB,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IACH,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACjC,oBAAY,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QACxD,wBAAgB,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC","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 { AURA_ORIGINS, CardsData } from '../cards/cards-data';\r\nimport { groupByFunction, pickMultipleRandomDifferent, pickRandom } from '../services/utils';\r\nimport {\r\n\taddStatsToBoard,\r\n\tafterStatsUpdate,\r\n\tgrantAllDivineShield,\r\n\tgrantRandomAttack,\r\n\tgrantRandomDivineShield,\r\n\tgrantRandomHealth,\r\n\tgrantRandomStats,\r\n\thasCorrectTribe,\r\n\tisCorrectTribe,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n} from '../utils';\r\nimport { bumpEntities, dealDamageToEnemy, dealDamageToRandomEnemy, getNeighbours } from './attack';\r\nimport { removeAurasAfterAuraSourceDeath } from './auras';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const handleDeathrattleEffects = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst rivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendare2);\r\n\tconst goldenRivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendareBattlegrounds);\r\n\tconst multiplier = goldenRivendare ? 3 : rivendare ? 2 : 1;\r\n\t// We do it on a case by case basis so that we deal all the damage in one go for instance\r\n\t// and avoid proccing deathrattle spawns between the times the damage triggers\r\n\tswitch (deadEntity.cardId) {\r\n\t\tcase CardIds.SelflessHero:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SelflessHeroBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpiritOfAirBattlegrounds1:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = pickRandom(boardWithDeadEntity);\r\n\t\t\t\tif (target) {\r\n\t\t\t\t\ttarget.divineShield = true;\r\n\t\t\t\t\ttarget.taunt = true;\r\n\t\t\t\t\ttarget.windfury = true;\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpiritOfAirBattlegrounds2:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = pickRandom(boardWithDeadEntity);\r\n\t\t\t\tif (target) {\r\n\t\t\t\t\ttarget.divineShield = true;\r\n\t\t\t\t\ttarget.taunt = true;\r\n\t\t\t\t\ttarget.windfury = true;\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\r\n\t\t\t\t\tconst target2 = pickRandom(boardWithDeadEntity.filter((e) => e.entityId !== target.entityId));\r\n\t\t\t\t\tif (target2) {\r\n\t\t\t\t\t\ttarget2.divineShield = true;\r\n\t\t\t\t\t\ttarget2.taunt = true;\r\n\t\t\t\t\t\ttarget2.windfury = true;\r\n\t\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.NadinaTheRed:\r\n\t\tcase CardIds.NadinaTheRedBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantAllDivineShield(boardWithDeadEntity, 'DRAGON', allCards);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpawnOfNzoth:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 1, multiplier * 1, allCards, spectator);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpawnOfNzothBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 2, multiplier * 2, allCards, spectator);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.GoldrinnTheGreatWolf:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 5, multiplier * 5, allCards, spectator, 'BEAST');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.GoldrinnTheGreatWolfBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 10, multiplier * 10, allCards, spectator, 'BEAST');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KingBagurgle:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 2, multiplier * 2, allCards, spectator, 'MURLOC');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KingBagurgleBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 4, multiplier * 4, allCards, spectator, 'MURLOC');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.FiendishServant:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.FiendishServantBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ImpulsiveTrickster:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ImpulsiveTricksterBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.Leapfrogger:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.LeapfroggerBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = grantRandomStats(deadEntity, boardWithDeadEntity, 6, 6, Race.BEAST, allCards, spectator);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = grantRandomStats(deadEntity, boardWithDeadEntity, 12, 12, Race.BEAST, allCards, spectator);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.LeapfroggerBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ElementiumSquirrelBombBattlegrounds1:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst numberOfDeadMechsThisCombat = sharedState.deaths\r\n\t\t\t\t\t.filter((entity) => entity.friendly === deadEntity.friendly)\r\n\t\t\t\t\t// eslint-disable-next-line prettier/prettier\r\n\t\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId)?.race, Race.MECH)).length;\r\n\t\t\t\tfor (let j = 0; j < numberOfDeadMechsThisCombat + 1; j++) {\r\n\t\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t3,\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.ElementiumSquirrelBombBattlegrounds2:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst numberOfDeadMechsThisCombat = sharedState.deaths\r\n\t\t\t\t\t.filter((entity) => entity.friendly === deadEntity.friendly)\r\n\t\t\t\t\t// eslint-disable-next-line prettier/prettier\r\n\t\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId)?.race, Race.MECH)).length;\r\n\t\t\t\tfor (let j = 0; j < numberOfDeadMechsThisCombat + 1; j++) {\r\n\t\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t6,\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.KaboomBot:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.KaboomBotBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\r\n\t\tcase CardIds.SrTombDiverBattlegrounds1:\r\n\t\t\tfor (let i = 0; i < Math.min(1, boardWithDeadEntity.length); i++) {\r\n\t\t\t\tconst rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - i];\r\n\t\t\t\tif (rightMostMinion) {\r\n\t\t\t\t\tconst refCard = allCards.getCard(rightMostMinion.cardId);\r\n\t\t\t\t\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\t\t\t\t\trightMostMinion.cardId = goldenCard.id;\r\n\t\t\t\t\tmodifyAttack(rightMostMinion, refCard.attack, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tmodifyHealth(rightMostMinion, refCard.health, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tafterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\tcase CardIds.SrTombDiverBattlegrounds2:\r\n\t\t\tfor (let i = 0; i < Math.min(2, boardWithDeadEntity.length); i++) {\r\n\t\t\t\tconst rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - i];\r\n\t\t\t\tif (rightMostMinion) {\r\n\t\t\t\t\tconst refCard = allCards.getCard(rightMostMinion.cardId);\r\n\t\t\t\t\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\t\t\t\t\trightMostMinion.cardId = goldenCard.id;\r\n\t\t\t\t\tmodifyAttack(rightMostMinion, refCard.attack, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tmodifyHealth(rightMostMinion, refCard.health, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tafterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t}\r\n\r\n\t// It's important to first copy the enchantments, otherwise you could end up\r\n\t// in an infinite loop - since new enchants are added after each step\r\n\tlet enchantments: { cardId: string; originEntityId?: number; repeats?: number }[] = [...(deadEntity.enchantments ?? [])];\r\n\tconst threshold = 20;\r\n\tif (enchantments.length > threshold || enchantments.some((e) => e.repeats && e.repeats > 1)) {\r\n\t\t// console.warn(\r\n\t\t// \t'too many enchtments, truncating',\r\n\t\t// \tstringifySimpleCard(deadEntity),\r\n\t\t// \tdeadEntity.enchantments.length,\r\n\t\t// \tdeadEntity.enchantments,\r\n\t\t// );\r\n\t\t// In some cases it's possible that there are way too many enchantments because of the frog\r\n\t\t// In that case, we make a trade-off and don't trigger the \"on stats change\" trigger as\r\n\t\t// often as we should, so that we can have the stats themselves correct\r\n\t\tconst enchantmentGroups = groupByFunction((enchantment: any) => enchantment.cardId)(enchantments);\r\n\t\tenchantments = Object.keys(enchantmentGroups).map((cardId) => ({\r\n\t\t\tcardId: cardId,\r\n\t\t\trepeats: enchantmentGroups[cardId].length,\r\n\t\t}));\r\n\t}\r\n\tfor (const enchantment of enchantments) {\r\n\t\tswitch (enchantment.cardId) {\r\n\t\t\tcase CardIds.Leapfrogger_LeapfrogginEnchantment1:\r\n\t\t\t\tif (!!enchantment.repeats && enchantment.repeats > 1) {\r\n\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator, multiplier * enchantment.repeats);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Leapfrogger_LeapfrogginEnchantment2:\r\n\t\t\t\tif (!!enchantment.repeats && enchantment.repeats > 1) {\r\n\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator, multiplier * enchantment.repeats);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EarthRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyEarthInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FireRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyFireInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.WaterRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyWaterInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LightningRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyLightningInvocationEnchantment(\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\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\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyLightningInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Because the golden version doubles all the remembered effects\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst targets = pickMultipleRandomDifferent(otherBoard, 5);\r\n\t\tfor (const target of targets) {\r\n\t\t\tdealDamageToEnemy(\r\n\t\t\t\ttarget,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t1,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\r\nexport const applyWaterInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst target: BoardEntity = boardWithDeadEntity[boardWithDeadEntity.length - 1];\r\n\t\tif (!!target) {\r\n\t\t\tmodifyHealth(target, 3, boardWithDeadEntity, allCards);\r\n\t\t\ttarget.taunt = true;\r\n\t\t\tafterStatsUpdate(target, boardWithDeadEntity, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyFireInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst target: BoardEntity = boardWithDeadEntity[0];\r\n\t\tif (!!target) {\r\n\t\t\tmodifyAttack(target, target.attack, boardWithDeadEntity, allCards);\r\n\t\t\tafterStatsUpdate(target, boardWithDeadEntity, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyEarthInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst minionsGrantedDeathrattle: BoardEntity[] = pickMultipleRandomDifferent(boardWithDeadEntity, 4);\r\n\t\tminionsGrantedDeathrattle.forEach((minion) => {\r\n\t\t\tminion.enchantments.push({\r\n\t\t\t\tcardId: CardIds.EarthInvocation_ElementEarthEnchantment,\r\n\t\t\t\toriginEntityId: deadEntity?.entityId,\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n};\r\n\r\nconst applyLeapFroggerEffect = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tisPremium: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tmultiplier = 1,\r\n): void => {\r\n\tmultiplier = multiplier || 1;\r\n\tconst buffed = grantRandomStats(\r\n\t\tdeadEntity,\r\n\t\tboardWithDeadEntity,\r\n\t\tmultiplier * (isPremium ? 2 : 1),\r\n\t\tmultiplier * (isPremium ? 2 : 1),\r\n\t\tRace.BEAST,\r\n\t\tallCards,\r\n\t\tspectator,\r\n\t);\r\n\tif (buffed) {\r\n\t\tbuffed.enchantments = buffed.enchantments ?? [];\r\n\t\tbuffed.enchantments.push({\r\n\t\t\tcardId: isPremium ? CardIds.Leapfrogger_LeapfrogginEnchantment2 : CardIds.Leapfrogger_LeapfrogginEnchantment1,\r\n\t\t\toriginEntityId: deadEntity.entityId,\r\n\t\t\trepeats: multiplier > 1 ? multiplier : undefined,\r\n\t\t});\r\n\t\t// Don't register power effect here, since it's already done in the random stats\r\n\t\t// spectator.registerPowerTarget(deadEntity, buffed, boardWithDeadEntity);\r\n\t\t// console.log('applyLeapFroggerEffect', stringifySimpleCard(deadEntity), stringifySimpleCard(buffed));\r\n\t}\r\n};\r\n\r\nexport const applyMinionDeathEffect = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndex: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.log('applying minion death effect', stringifySimpleCard(deadEntity, allCards));\r\n\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.BEAST)) {\r\n\t\tapplyScavengingHyenaEffect(boardWithDeadEntity, allCards, spectator);\r\n\t}\r\n\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.DEMON)) {\r\n\t\tapplySoulJugglerEffect(\r\n\t\t\tboardWithDeadEntity,\r\n\t\t\tboardWithDeadEntityHero,\r\n\t\t\totherBoard,\r\n\t\t\totherBoardHero,\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\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.MECH)) {\r\n\t\tapplyJunkbotEffect(boardWithDeadEntity, allCards, spectator);\r\n\t}\r\n\tif (hasCorrectTribe(deadEntity, Race.MURLOC, allCards)) {\r\n\t\tremoveOldMurkEyeAttack(boardWithDeadEntity, allCards);\r\n\t\tremoveOldMurkEyeAttack(otherBoard, allCards);\r\n\t}\r\n\r\n\tif (AURA_ORIGINS.includes(deadEntity.cardId)) {\r\n\t\tremoveAurasAfterAuraSourceDeath(boardWithDeadEntity, deadEntity, cardsData);\r\n\t}\r\n\r\n\tif (deadEntity.taunt) {\r\n\t\t// applyQirajiHarbringerEffect(boardWithDeadEntity, deadEntityIndex, allCards);\r\n\t}\r\n\t// Overkill\r\n\tif (deadEntity.health < 0 && deadEntity.lastAffectedByEntity?.attacking) {\r\n\t\tif (deadEntity.lastAffectedByEntity.cardId === CardIds.HeraldOfFlame2) {\r\n\t\t\tconst targets = boardWithDeadEntity.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\t\t\tif (targets.length > 0) {\r\n\t\t\t\tconst target = targets[0];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tdeadEntity.lastAffectedByEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.HeraldOfFlameBattlegrounds) {\r\n\t\t\tconst targets = boardWithDeadEntity.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\t\t\tif (targets.length > 0) {\r\n\t\t\t\tconst target = targets[0];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tdeadEntity.lastAffectedByEntity,\r\n\t\t\t\t\t6,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.WildfireElemental) {\r\n\t\t\t// console.log('applying WildfireElemental effect', stringifySimple(boardWithDeadEntity, allCards));\r\n\t\t\tconst excessDamage = -deadEntity.health;\r\n\t\t\tconst neighbours = getNeighbours(boardWithDeadEntity, null, deadEntityIndex);\r\n\t\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\t\tif (neighbours.length > 0) {\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\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.WildfireElementalBattlegrounds) {\r\n\t\t\tconst excessDamage = -deadEntity.health;\r\n\t\t\tconst neighbours = getNeighbours(boardWithDeadEntity, null, deadEntityIndex);\r\n\t\t\tneighbours.forEach((neighbour) =>\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.IronhideDirehorn) {\r\n\t\t\tconst newEntities = spawnEntities(\r\n\t\t\t\tCardIds.IronhideDirehorn_IronhideRuntToken,\r\n\t\t\t\t1,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\t!deadEntity.friendly,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t\totherBoard.splice(deadEntityIndex, 0, ...newEntities);\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.IronhideDirehornBattlegrounds) {\r\n\t\t\tconst newEntities = spawnEntities(\r\n\t\t\t\tCardIds.IronhideDirehorn_IronhideRuntTokenBattlegrounds,\r\n\t\t\t\t1,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\t!deadEntity.friendly,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t\totherBoard.splice(deadEntityIndex, 0, ...newEntities);\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.SeabreakerGoliath2) {\r\n\t\t\tconst otherPirates = otherBoard\r\n\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId).race, Race.PIRATE))\r\n\t\t\t\t.filter((entity) => entity.entityId !== deadEntity.lastAffectedByEntity.entityId);\r\n\t\t\totherPirates.forEach((pirate) => {\r\n\t\t\t\tmodifyAttack(pirate, 2, boardWithDeadEntity, allCards);\r\n\t\t\t\tmodifyHealth(pirate, 2, boardWithDeadEntity, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, boardWithDeadEntity, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(deadEntity.lastAffectedByEntity, pirate, otherBoard);\r\n\t\t\t});\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.SeabreakerGoliathBattlegrounds) {\r\n\t\t\tconst otherPirates = otherBoard\r\n\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId).race, Race.PIRATE))\r\n\t\t\t\t.filter((entity) => entity.entityId !== deadEntity.lastAffectedByEntity.entityId);\r\n\t\t\totherPirates.forEach((pirate) => {\r\n\t\t\t\tmodifyAttack(pirate, 4, boardWithDeadEntity, allCards);\r\n\t\t\t\tmodifyHealth(pirate, 4, boardWithDeadEntity, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, boardWithDeadEntity, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(deadEntity.lastAffectedByEntity, pirate, otherBoard);\r\n\t\t\t});\r\n\t\t}\r\n\t\t// else if (deadEntity.lastAffectedByEntity.cardId === CardIds.NatPagleExtremeAngler) {\r\n\t\t// }\r\n\t}\r\n\r\n\tconst rivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendare2);\r\n\tconst goldenRivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendareBattlegrounds);\r\n\tconst multiplier = goldenRivendare ? 3 : rivendare ? 2 : 1;\r\n\tif (deadEntity.cardId === CardIds.UnstableGhoul) {\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tdealDamageToAllMinions(\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t1,\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} else if (deadEntity.cardId === CardIds.UnstableGhoulBattlegrounds) {\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tdealDamageToAllMinions(\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t2,\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// applyAvengeEffects(\r\n\t// \tdeadEntity,\r\n\t// \tdeadEntityIndex,\r\n\t// \tboardWithDeadEntity,\r\n\t// \tboardWithDeadEntityHero,\r\n\t// \totherBoard,\r\n\t// \totherBoardHero,\r\n\t// \tallCards,\r\n\t// \tcardsData,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nexport const dealDamageToAllMinions = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamageDealt: number,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (board1.length === 0 && board2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\t// let updatedBoard1 = [...board1];\r\n\t// let updatedBoard2 = [...board2];\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damageDealt,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tfor (let i = 0; i < board1.length; i++) {\r\n\t\tbumpEntities(board1[i], fakeAttacker, board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n\t\t// board1[i] = entity;\r\n\t}\r\n\tfor (let i = 0; i < board2.length; i++) {\r\n\t\tbumpEntities(board2[i], fakeAttacker, board2, board2Hero, board1, board1Hero, allCards, cardsData, sharedState, spectator);\r\n\t\t// updatedBoard2 = [...boardResult];\r\n\t\t// updatedBoard2[i] = entity;\r\n\t}\r\n\t// processMinionDeath(board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n};\r\n\r\nconst applySoulJugglerEffect = (\r\n\tboardWithJugglers: BoardEntity[],\r\n\tboardWithJugglersHero: BgsPlayerEntity,\r\n\tboardToAttack: BoardEntity[],\r\n\tboardToAttackHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (boardWithJugglers.length === 0 && boardToAttack.length === 0) {\r\n\t\treturn;\r\n\t\t// return [boardWithJugglers, boardToAttack];\r\n\t}\r\n\tconst jugglers = boardWithJugglers.filter((entity) => entity.cardId === CardIds.SoulJuggler);\r\n\tfor (const juggler of jugglers) {\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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 goldenJugglers = boardWithJugglers.filter((entity) => entity.cardId === CardIds.SoulJugglerBattlegrounds);\r\n\tfor (const juggler of goldenJugglers) {\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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\t// processMinionDeath(\r\n\t// \tboardWithJugglers,\r\n\t// \tboardWithJugglersHero,\r\n\t// \tboardToAttack,\r\n\t// \tboardToAttackHero,\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 applyScavengingHyenaEffect = (board: BoardEntity[], allCards: AllCardsService, spectator: Spectator): void => {\r\n\t// const copy = [...board];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].cardId === CardIds.ScavengingHyenaLegacy) {\r\n\t\t\tmodifyAttack(board[i], 2, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 1, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t} else if (board[i].cardId === CardIds.ScavengingHyenaBattlegrounds) {\r\n\t\t\tmodifyAttack(board[i], 4, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 2, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst applyJunkbotEffect = (board: BoardEntity[], allCards: AllCardsService, spectator: Spectator): void => {\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].cardId === CardIds.Junkbot) {\r\n\t\t\tmodifyAttack(board[i], 2, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 2, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t} else if (board[i].cardId === CardIds.JunkbotBattlegrounds) {\r\n\t\t\tmodifyAttack(board[i], 4, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 4, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\n// const applyQirajiHarbringerEffect = (board: BoardEntity[], deadEntityIndex: number, allCards: AllCardsService): void => {\r\n// \tconst qiraji = board.filter((entity) => entity.cardId === CardIds.QirajiHarbinger);\r\n// \tconst goldenQiraji = board.filter((entity) => entity.cardId === CardIds.QirajiHarbingerBattlegrounds);\r\n// \tconst neighbours = getNeighbours(board, null, deadEntityIndex);\r\n\r\n// \t// TODO: if reactivated, properly apply buffs one by one, instead of all together\r\n\r\n// \tneighbours.forEach((entity) => {\r\n// \t\tmodifyAttack(entity, 2 * qiraji.length + 4 * goldenQiraji.length, board, allCards);\r\n// \t\tmodifyHealth(entity, 2 * qiraji.length + 4 * goldenQiraji.length);\r\n// \t\tafterStatsUpdate(entity, board, allCards);\r\n// \t});\r\n// };\r\n\r\nexport const applyMonstrosity = (\r\n\tmonstrosity: BoardEntity,\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tboardWithDeadEntities: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tfor (const deadEntity of deadEntities) {\r\n\t\tmodifyAttack(monstrosity, deadEntity.attack, boardWithDeadEntities, allCards);\r\n\t\tif (monstrosity.cardId === CardIds.MonstrosityBattlegrounds) {\r\n\t\t\tmodifyAttack(monstrosity, deadEntity.attack, boardWithDeadEntities, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const rememberDeathrattles = (fish: BoardEntity, deadEntities: readonly BoardEntity[], cardsData: CardsData): void => {\r\n\tconst validDeathrattles = deadEntities\r\n\t\t.filter((entity) => cardsData.validDeathrattles.includes(entity.cardId))\r\n\t\t.map((entity) => entity.cardId);\r\n\tconst validEnchantments = deadEntities\r\n\t\t.filter((entity) => entity.enchantments?.length)\r\n\t\t.map((entity) => entity.enchantments)\r\n\t\t.reduce((a, b) => a.concat(b), [])\r\n\t\t.map((enchantment) => enchantment.cardId)\r\n\t\t.filter((enchantmentId) =>\r\n\t\t\t[\r\n\t\t\t\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment,\r\n\t\t\t\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantmentBattlegrounds,\r\n\t\t\t\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\t\t\t\tCardIds.SneedsReplicator_ReplicateEnchantment,\r\n\t\t\t\tCardIds.EarthInvocation_ElementEarthEnchantment,\r\n\t\t\t\tCardIds.FireInvocation_ElementFireEnchantment,\r\n\t\t\t\tCardIds.WaterInvocation_ElementWaterEnchantment,\r\n\t\t\t\tCardIds.LightningInvocation,\r\n\t\t\t].includes(enchantmentId as CardIds),\r\n\t\t);\r\n\tconst newDeathrattles = [...validDeathrattles, ...validEnchantments];\r\n\t// Order is important\r\n\tif (fish.cardId === CardIds.FishOfNzothBattlegrounds) {\r\n\t\t// https://stackoverflow.com/questions/33305152/how-to-duplicate-elements-in-a-js-array\r\n\t\tconst doubleDr = [...validDeathrattles, ...validEnchantments].reduce((res, current) => res.concat([current, current]), []);\r\n\t\tfish.rememberedDeathrattles = [...doubleDr, ...(fish.rememberedDeathrattles || [])];\r\n\t} else {\r\n\t\tfish.rememberedDeathrattles = [...newDeathrattles, ...(fish.rememberedDeathrattles || [])];\r\n\t}\r\n};\r\n\r\nconst removeOldMurkEyeAttack = (boardWithDeadEntity: BoardEntity[], allCards: AllCardsService) => {\r\n\tconst murkeyes = boardWithDeadEntity.filter(\r\n\t\t(entity) => entity.cardId === CardIds.OldMurkEyeLegacy || entity.cardId === CardIds.OldMurkEyeVanilla,\r\n\t);\r\n\tconst goldenMurkeyes = boardWithDeadEntity.filter((entity) => entity.cardId === CardIds.OldMurkEyeBattlegrounds);\r\n\tmurkeyes.forEach((entity) => {\r\n\t\tmodifyAttack(entity, -1, boardWithDeadEntity, allCards);\r\n\t\tafterStatsUpdate(entity, boardWithDeadEntity, allCards);\r\n\t});\r\n\tgoldenMurkeyes.forEach((entity) => {\r\n\t\tmodifyAttack(entity, -2, boardWithDeadEntity, allCards);\r\n\t\tafterStatsUpdate(entity, boardWithDeadEntity, allCards);\r\n\t});\r\n};\r\n"]}
1
+ {"version":3,"file":"deathrattle-effects.js","sourceRoot":"","sources":["../../src/simulation/deathrattle-effects.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAG9E,oDAA8D;AAC9D,6CAA6F;AAC7F,oCAYkB;AAClB,qCAAmG;AACnG,mCAA0D;AAC1D,6DAAqD;AAI9C,MAAM,wBAAwB,GAAG,CACvC,mBAAkC,EAClC,uBAAwC,EACxC,UAAuB,EACvB,UAAyB,EACzB,cAA+B,EAC/B,QAAyB,EACzB,SAAoB,EACpB,WAAwB,EACxB,SAAoB,EACb,EAAE;;IACT,MAAM,SAAS,GAAG,mBAAmB,CAAC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CAAC,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QACxD,wBAAgB,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC","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 { AURA_ORIGINS, CardsData } from '../cards/cards-data';\r\nimport { groupByFunction, pickMultipleRandomDifferent, pickRandom } from '../services/utils';\r\nimport {\r\n\taddStatsToBoard,\r\n\tafterStatsUpdate,\r\n\tgrantAllDivineShield,\r\n\tgrantRandomAttack,\r\n\tgrantRandomDivineShield,\r\n\tgrantRandomHealth,\r\n\tgrantRandomStats,\r\n\thasCorrectTribe,\r\n\tisCorrectTribe,\r\n\tmodifyAttack,\r\n\tmodifyHealth,\r\n} from '../utils';\r\nimport { bumpEntities, dealDamageToEnemy, dealDamageToRandomEnemy, getNeighbours } from './attack';\r\nimport { removeAurasAfterAuraSourceDeath } from './auras';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const handleDeathrattleEffects = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst rivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendare2);\r\n\tconst goldenRivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendareBattlegrounds);\r\n\tconst multiplier = goldenRivendare ? 3 : rivendare ? 2 : 1;\r\n\t// We do it on a case by case basis so that we deal all the damage in one go for instance\r\n\t// and avoid proccing deathrattle spawns between the times the damage triggers\r\n\tswitch (deadEntity.cardId) {\r\n\t\tcase CardIds.SelflessHero:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SelflessHeroBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t\tgrantRandomDivineShield(deadEntity, boardWithDeadEntity, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpiritOfAirBattlegrounds1:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = pickRandom(boardWithDeadEntity);\r\n\t\t\t\tif (target) {\r\n\t\t\t\t\ttarget.divineShield = true;\r\n\t\t\t\t\ttarget.taunt = true;\r\n\t\t\t\t\ttarget.windfury = true;\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpiritOfAirBattlegrounds2:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = pickRandom(boardWithDeadEntity);\r\n\t\t\t\tif (target) {\r\n\t\t\t\t\ttarget.divineShield = true;\r\n\t\t\t\t\ttarget.taunt = true;\r\n\t\t\t\t\ttarget.windfury = true;\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\r\n\t\t\t\t\tconst target2 = pickRandom(boardWithDeadEntity.filter((e) => e.entityId !== target.entityId));\r\n\t\t\t\t\tif (target2) {\r\n\t\t\t\t\t\ttarget2.divineShield = true;\r\n\t\t\t\t\t\ttarget2.taunt = true;\r\n\t\t\t\t\t\ttarget2.windfury = true;\r\n\t\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.NadinaTheRed:\r\n\t\tcase CardIds.NadinaTheRedBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantAllDivineShield(boardWithDeadEntity, 'DRAGON', allCards);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpawnOfNzoth:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 1, multiplier * 1, allCards, spectator);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SpawnOfNzothBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 2, multiplier * 2, allCards, spectator);\r\n\t\t\tbreak;\r\n\t\tcase CardIds.GoldrinnTheGreatWolf:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 5, multiplier * 5, allCards, spectator, 'BEAST');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.GoldrinnTheGreatWolfBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 10, multiplier * 10, allCards, spectator, 'BEAST');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KingBagurgle:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 2, multiplier * 2, allCards, spectator, 'MURLOC');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.KingBagurgleBattlegrounds:\r\n\t\t\taddStatsToBoard(deadEntity, boardWithDeadEntity, multiplier * 4, multiplier * 4, allCards, spectator, 'MURLOC');\r\n\t\t\tbreak;\r\n\t\tcase CardIds.FiendishServant:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.FiendishServantBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t\tgrantRandomAttack(deadEntity, boardWithDeadEntity, deadEntity.attack, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ImpulsiveTrickster:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ImpulsiveTricksterBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t\tgrantRandomHealth(deadEntity, boardWithDeadEntity, deadEntity.maxHealth, allCards, spectator, true);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.Leapfrogger:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.LeapfroggerBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = grantRandomStats(deadEntity, boardWithDeadEntity, 6, 6, Race.BEAST, allCards, spectator);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst target = grantRandomStats(deadEntity, boardWithDeadEntity, 12, 12, Race.BEAST, allCards, spectator);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, target, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.LeapfroggerBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.ElementiumSquirrelBombBattlegrounds1:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst numberOfDeadMechsThisCombat = sharedState.deaths\r\n\t\t\t\t\t.filter((entity) => entity.friendly === deadEntity.friendly)\r\n\t\t\t\t\t// eslint-disable-next-line prettier/prettier\r\n\t\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId)?.race, Race.MECH)).length;\r\n\t\t\t\tfor (let j = 0; j < numberOfDeadMechsThisCombat + 1; j++) {\r\n\t\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t3,\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.ElementiumSquirrelBombBattlegrounds2:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tconst numberOfDeadMechsThisCombat = sharedState.deaths\r\n\t\t\t\t\t.filter((entity) => entity.friendly === deadEntity.friendly)\r\n\t\t\t\t\t// eslint-disable-next-line prettier/prettier\r\n\t\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId)?.race, Race.MECH)).length;\r\n\t\t\t\tfor (let j = 0; j < numberOfDeadMechsThisCombat + 1; j++) {\r\n\t\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t6,\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.KaboomBot:\r\n\t\t\t// FIXME: I don't think this way of doing things is really accurate (as some deathrattles\r\n\t\t\t// could be spawned between the shots firing), but let's say it's good enough for now\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\t\tcase CardIds.KaboomBotBattlegrounds:\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tdealDamageToRandomEnemy(\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t4,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\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\tbreak;\r\n\r\n\t\tcase CardIds.SrTombDiverBattlegrounds1:\r\n\t\t\tfor (let i = 0; i < Math.min(1, boardWithDeadEntity.length); i++) {\r\n\t\t\t\tconst rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - 1 - i];\r\n\t\t\t\tif (rightMostMinion) {\r\n\t\t\t\t\tconst refCard = allCards.getCard(rightMostMinion.cardId);\r\n\t\t\t\t\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\t\t\t\t\trightMostMinion.cardId = goldenCard.id;\r\n\t\t\t\t\tmodifyAttack(rightMostMinion, refCard.attack, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tmodifyHealth(rightMostMinion, refCard.health, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tafterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase CardIds.SrTombDiverBattlegrounds2:\r\n\t\t\tfor (let i = 0; i < Math.min(2, boardWithDeadEntity.length); i++) {\r\n\t\t\t\tconst rightMostMinion = boardWithDeadEntity[boardWithDeadEntity.length - 1 - i];\r\n\t\t\t\tif (rightMostMinion) {\r\n\t\t\t\t\tconst refCard = allCards.getCard(rightMostMinion.cardId);\r\n\t\t\t\t\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\t\t\t\t\trightMostMinion.cardId = goldenCard.id;\r\n\t\t\t\t\tmodifyAttack(rightMostMinion, refCard.attack, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tmodifyHealth(rightMostMinion, refCard.health, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tafterStatsUpdate(rightMostMinion, boardWithDeadEntity, allCards);\r\n\t\t\t\t\tspectator.registerPowerTarget(deadEntity, rightMostMinion, boardWithDeadEntity);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\t// It's important to first copy the enchantments, otherwise you could end up\r\n\t// in an infinite loop - since new enchants are added after each step\r\n\tlet enchantments: { cardId: string; originEntityId?: number; repeats?: number }[] = [...(deadEntity.enchantments ?? [])];\r\n\tconst threshold = 20;\r\n\tif (enchantments.length > threshold || enchantments.some((e) => e.repeats && e.repeats > 1)) {\r\n\t\t// console.warn(\r\n\t\t// \t'too many enchtments, truncating',\r\n\t\t// \tstringifySimpleCard(deadEntity),\r\n\t\t// \tdeadEntity.enchantments.length,\r\n\t\t// \tdeadEntity.enchantments,\r\n\t\t// );\r\n\t\t// In some cases it's possible that there are way too many enchantments because of the frog\r\n\t\t// In that case, we make a trade-off and don't trigger the \"on stats change\" trigger as\r\n\t\t// often as we should, so that we can have the stats themselves correct\r\n\t\tconst enchantmentGroups = groupByFunction((enchantment: any) => enchantment.cardId)(enchantments);\r\n\t\tenchantments = Object.keys(enchantmentGroups).map((cardId) => ({\r\n\t\t\tcardId: cardId,\r\n\t\t\trepeats: enchantmentGroups[cardId].length,\r\n\t\t}));\r\n\t}\r\n\tfor (const enchantment of enchantments) {\r\n\t\tswitch (enchantment.cardId) {\r\n\t\t\tcase CardIds.Leapfrogger_LeapfrogginEnchantment1:\r\n\t\t\t\tif (!!enchantment.repeats && enchantment.repeats > 1) {\r\n\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator, multiplier * enchantment.repeats);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, false, allCards, spectator);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Leapfrogger_LeapfrogginEnchantment2:\r\n\t\t\t\tif (!!enchantment.repeats && enchantment.repeats > 1) {\r\n\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator, multiplier * enchantment.repeats);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\t\tapplyLeapFroggerEffect(boardWithDeadEntity, deadEntity, true, allCards, spectator);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EarthRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyEarthInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FireRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyFireInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.WaterRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyWaterInvocationEnchantment(boardWithDeadEntity, deadEntity, allCards, spectator);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.LightningRecollectionEnchantment:\r\n\t\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\t\tapplyLightningInvocationEnchantment(\r\n\t\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherBoardHero,\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\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyLightningInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Because the golden version doubles all the remembered effects\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst targets = pickMultipleRandomDifferent(otherBoard, 5);\r\n\t\tfor (const target of targets) {\r\n\t\t\tdealDamageToEnemy(\r\n\t\t\t\ttarget,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t1,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\r\nexport const applyWaterInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst target: BoardEntity = boardWithDeadEntity[boardWithDeadEntity.length - 1];\r\n\t\tif (!!target) {\r\n\t\t\tmodifyHealth(target, 3, boardWithDeadEntity, allCards);\r\n\t\t\ttarget.taunt = true;\r\n\t\t\tafterStatsUpdate(target, boardWithDeadEntity, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyFireInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst target: BoardEntity = boardWithDeadEntity[0];\r\n\t\tif (!!target) {\r\n\t\t\tmodifyAttack(target, target.attack, boardWithDeadEntity, allCards);\r\n\t\t\tafterStatsUpdate(target, boardWithDeadEntity, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const applyEarthInvocationEnchantment = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst multiplier = deadEntity?.cardId === CardIds.SpiritRaptorBattlegrounds ? 2 : 1;\r\n\tfor (let i = 0; i < multiplier; i++) {\r\n\t\tconst minionsGrantedDeathrattle: BoardEntity[] = pickMultipleRandomDifferent(boardWithDeadEntity, 4);\r\n\t\tminionsGrantedDeathrattle.forEach((minion) => {\r\n\t\t\tminion.enchantments.push({\r\n\t\t\t\tcardId: CardIds.EarthInvocation_ElementEarthEnchantment,\r\n\t\t\t\toriginEntityId: deadEntity?.entityId,\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n};\r\n\r\nconst applyLeapFroggerEffect = (\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tdeadEntity: BoardEntity,\r\n\tisPremium: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tmultiplier = 1,\r\n): void => {\r\n\tmultiplier = multiplier || 1;\r\n\tconst buffed = grantRandomStats(\r\n\t\tdeadEntity,\r\n\t\tboardWithDeadEntity,\r\n\t\tmultiplier * (isPremium ? 2 : 1),\r\n\t\tmultiplier * (isPremium ? 2 : 1),\r\n\t\tRace.BEAST,\r\n\t\tallCards,\r\n\t\tspectator,\r\n\t);\r\n\tif (buffed) {\r\n\t\tbuffed.enchantments = buffed.enchantments ?? [];\r\n\t\tbuffed.enchantments.push({\r\n\t\t\tcardId: isPremium ? CardIds.Leapfrogger_LeapfrogginEnchantment2 : CardIds.Leapfrogger_LeapfrogginEnchantment1,\r\n\t\t\toriginEntityId: deadEntity.entityId,\r\n\t\t\trepeats: multiplier > 1 ? multiplier : undefined,\r\n\t\t});\r\n\t\t// Don't register power effect here, since it's already done in the random stats\r\n\t\t// spectator.registerPowerTarget(deadEntity, buffed, boardWithDeadEntity);\r\n\t\t// console.log('applyLeapFroggerEffect', stringifySimpleCard(deadEntity), stringifySimpleCard(buffed));\r\n\t}\r\n};\r\n\r\nexport const applyMinionDeathEffect = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndex: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// console.log('applying minion death effect', stringifySimpleCard(deadEntity, allCards));\r\n\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.BEAST)) {\r\n\t\tapplyScavengingHyenaEffect(boardWithDeadEntity, allCards, spectator);\r\n\t}\r\n\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.DEMON)) {\r\n\t\tapplySoulJugglerEffect(\r\n\t\t\tboardWithDeadEntity,\r\n\t\t\tboardWithDeadEntityHero,\r\n\t\t\totherBoard,\r\n\t\t\totherBoardHero,\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\tif (isCorrectTribe(allCards.getCard(deadEntity.cardId).race, Race.MECH)) {\r\n\t\tapplyJunkbotEffect(boardWithDeadEntity, allCards, spectator);\r\n\t}\r\n\tif (hasCorrectTribe(deadEntity, Race.MURLOC, allCards)) {\r\n\t\tremoveOldMurkEyeAttack(boardWithDeadEntity, allCards);\r\n\t\tremoveOldMurkEyeAttack(otherBoard, allCards);\r\n\t}\r\n\r\n\tif (AURA_ORIGINS.includes(deadEntity.cardId)) {\r\n\t\tremoveAurasAfterAuraSourceDeath(boardWithDeadEntity, deadEntity, cardsData);\r\n\t}\r\n\r\n\tif (deadEntity.taunt) {\r\n\t\t// applyQirajiHarbringerEffect(boardWithDeadEntity, deadEntityIndex, allCards);\r\n\t}\r\n\t// Overkill\r\n\tif (deadEntity.health < 0 && deadEntity.lastAffectedByEntity?.attacking) {\r\n\t\tif (deadEntity.lastAffectedByEntity.cardId === CardIds.HeraldOfFlame2) {\r\n\t\t\tconst targets = boardWithDeadEntity.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\t\t\tif (targets.length > 0) {\r\n\t\t\t\tconst target = targets[0];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tdeadEntity.lastAffectedByEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.HeraldOfFlameBattlegrounds) {\r\n\t\t\tconst targets = boardWithDeadEntity.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\t\t\tif (targets.length > 0) {\r\n\t\t\t\tconst target = targets[0];\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tdeadEntity.lastAffectedByEntity,\r\n\t\t\t\t\t6,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.WildfireElemental) {\r\n\t\t\t// console.log('applying WildfireElemental effect', stringifySimple(boardWithDeadEntity, allCards));\r\n\t\t\tconst excessDamage = -deadEntity.health;\r\n\t\t\tconst neighbours = getNeighbours(boardWithDeadEntity, null, deadEntityIndex);\r\n\t\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\t\tif (neighbours.length > 0) {\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\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.WildfireElementalBattlegrounds) {\r\n\t\t\tconst excessDamage = -deadEntity.health;\r\n\t\t\tconst neighbours = getNeighbours(boardWithDeadEntity, null, deadEntityIndex);\r\n\t\t\tneighbours.forEach((neighbour) =>\r\n\t\t\t\tdealDamageToEnemy(\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\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} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.IronhideDirehorn) {\r\n\t\t\tconst newEntities = spawnEntities(\r\n\t\t\t\tCardIds.IronhideDirehorn_IronhideRuntToken,\r\n\t\t\t\t1,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\t!deadEntity.friendly,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t\totherBoard.splice(deadEntityIndex, 0, ...newEntities);\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.IronhideDirehornBattlegrounds) {\r\n\t\t\tconst newEntities = spawnEntities(\r\n\t\t\t\tCardIds.IronhideDirehorn_IronhideRuntTokenBattlegrounds,\r\n\t\t\t\t1,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\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\t!deadEntity.friendly,\r\n\t\t\t\ttrue,\r\n\t\t\t);\r\n\t\t\totherBoard.splice(deadEntityIndex, 0, ...newEntities);\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.SeabreakerGoliath2) {\r\n\t\t\tconst otherPirates = otherBoard\r\n\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId).race, Race.PIRATE))\r\n\t\t\t\t.filter((entity) => entity.entityId !== deadEntity.lastAffectedByEntity.entityId);\r\n\t\t\totherPirates.forEach((pirate) => {\r\n\t\t\t\tmodifyAttack(pirate, 2, boardWithDeadEntity, allCards);\r\n\t\t\t\tmodifyHealth(pirate, 2, boardWithDeadEntity, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, boardWithDeadEntity, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(deadEntity.lastAffectedByEntity, pirate, otherBoard);\r\n\t\t\t});\r\n\t\t} else if (deadEntity.lastAffectedByEntity.cardId === CardIds.SeabreakerGoliathBattlegrounds) {\r\n\t\t\tconst otherPirates = otherBoard\r\n\t\t\t\t.filter((entity) => isCorrectTribe(allCards.getCard(entity.cardId).race, Race.PIRATE))\r\n\t\t\t\t.filter((entity) => entity.entityId !== deadEntity.lastAffectedByEntity.entityId);\r\n\t\t\totherPirates.forEach((pirate) => {\r\n\t\t\t\tmodifyAttack(pirate, 4, boardWithDeadEntity, allCards);\r\n\t\t\t\tmodifyHealth(pirate, 4, boardWithDeadEntity, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, boardWithDeadEntity, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(deadEntity.lastAffectedByEntity, pirate, otherBoard);\r\n\t\t\t});\r\n\t\t}\r\n\t\t// else if (deadEntity.lastAffectedByEntity.cardId === CardIds.NatPagleExtremeAngler) {\r\n\t\t// }\r\n\t}\r\n\r\n\tconst rivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendare2);\r\n\tconst goldenRivendare = boardWithDeadEntity.find((entity) => entity.cardId === CardIds.BaronRivendareBattlegrounds);\r\n\tconst multiplier = goldenRivendare ? 3 : rivendare ? 2 : 1;\r\n\tif (deadEntity.cardId === CardIds.UnstableGhoul) {\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tdealDamageToAllMinions(\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t1,\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} else if (deadEntity.cardId === CardIds.UnstableGhoulBattlegrounds) {\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tdealDamageToAllMinions(\r\n\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherBoardHero,\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\t2,\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// applyAvengeEffects(\r\n\t// \tdeadEntity,\r\n\t// \tdeadEntityIndex,\r\n\t// \tboardWithDeadEntity,\r\n\t// \tboardWithDeadEntityHero,\r\n\t// \totherBoard,\r\n\t// \totherBoardHero,\r\n\t// \tallCards,\r\n\t// \tcardsData,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nexport const dealDamageToAllMinions = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamageDealt: number,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (board1.length === 0 && board2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\t// let updatedBoard1 = [...board1];\r\n\t// let updatedBoard2 = [...board2];\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damageDealt,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tfor (let i = 0; i < board1.length; i++) {\r\n\t\tbumpEntities(board1[i], fakeAttacker, board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n\t\t// board1[i] = entity;\r\n\t}\r\n\tfor (let i = 0; i < board2.length; i++) {\r\n\t\tbumpEntities(board2[i], fakeAttacker, board2, board2Hero, board1, board1Hero, allCards, cardsData, sharedState, spectator);\r\n\t\t// updatedBoard2 = [...boardResult];\r\n\t\t// updatedBoard2[i] = entity;\r\n\t}\r\n\t// processMinionDeath(board1, board1Hero, board2, board2Hero, allCards, cardsData, sharedState, spectator);\r\n};\r\n\r\nconst applySoulJugglerEffect = (\r\n\tboardWithJugglers: BoardEntity[],\r\n\tboardWithJugglersHero: BgsPlayerEntity,\r\n\tboardToAttack: BoardEntity[],\r\n\tboardToAttackHero: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tif (boardWithJugglers.length === 0 && boardToAttack.length === 0) {\r\n\t\treturn;\r\n\t\t// return [boardWithJugglers, boardToAttack];\r\n\t}\r\n\tconst jugglers = boardWithJugglers.filter((entity) => entity.cardId === CardIds.SoulJuggler);\r\n\tfor (const juggler of jugglers) {\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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 goldenJugglers = boardWithJugglers.filter((entity) => entity.cardId === CardIds.SoulJugglerBattlegrounds);\r\n\tfor (const juggler of goldenJugglers) {\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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\tdealDamageToRandomEnemy(\r\n\t\t\tboardToAttack,\r\n\t\t\tboardToAttackHero,\r\n\t\t\tjuggler,\r\n\t\t\t3,\r\n\t\t\tboardWithJugglers,\r\n\t\t\tboardWithJugglersHero,\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\t// processMinionDeath(\r\n\t// \tboardWithJugglers,\r\n\t// \tboardWithJugglersHero,\r\n\t// \tboardToAttack,\r\n\t// \tboardToAttackHero,\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 applyScavengingHyenaEffect = (board: BoardEntity[], allCards: AllCardsService, spectator: Spectator): void => {\r\n\t// const copy = [...board];\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].cardId === CardIds.ScavengingHyenaLegacy) {\r\n\t\t\tmodifyAttack(board[i], 2, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 1, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t} else if (board[i].cardId === CardIds.ScavengingHyenaBattlegrounds) {\r\n\t\t\tmodifyAttack(board[i], 4, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 2, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst applyJunkbotEffect = (board: BoardEntity[], allCards: AllCardsService, spectator: Spectator): void => {\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].cardId === CardIds.Junkbot) {\r\n\t\t\tmodifyAttack(board[i], 2, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 2, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t} else if (board[i].cardId === CardIds.JunkbotBattlegrounds) {\r\n\t\t\tmodifyAttack(board[i], 4, board, allCards);\r\n\t\t\tmodifyHealth(board[i], 4, board, allCards);\r\n\t\t\tafterStatsUpdate(board[i], board, allCards);\r\n\t\t\tspectator.registerPowerTarget(board[i], board[i], board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\n// const applyQirajiHarbringerEffect = (board: BoardEntity[], deadEntityIndex: number, allCards: AllCardsService): void => {\r\n// \tconst qiraji = board.filter((entity) => entity.cardId === CardIds.QirajiHarbinger);\r\n// \tconst goldenQiraji = board.filter((entity) => entity.cardId === CardIds.QirajiHarbingerBattlegrounds);\r\n// \tconst neighbours = getNeighbours(board, null, deadEntityIndex);\r\n\r\n// \t// TODO: if reactivated, properly apply buffs one by one, instead of all together\r\n\r\n// \tneighbours.forEach((entity) => {\r\n// \t\tmodifyAttack(entity, 2 * qiraji.length + 4 * goldenQiraji.length, board, allCards);\r\n// \t\tmodifyHealth(entity, 2 * qiraji.length + 4 * goldenQiraji.length);\r\n// \t\tafterStatsUpdate(entity, board, allCards);\r\n// \t});\r\n// };\r\n\r\nexport const applyMonstrosity = (\r\n\tmonstrosity: BoardEntity,\r\n\tdeadEntities: readonly BoardEntity[],\r\n\tboardWithDeadEntities: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tfor (const deadEntity of deadEntities) {\r\n\t\tmodifyAttack(monstrosity, deadEntity.attack, boardWithDeadEntities, allCards);\r\n\t\tif (monstrosity.cardId === CardIds.MonstrosityBattlegrounds) {\r\n\t\t\tmodifyAttack(monstrosity, deadEntity.attack, boardWithDeadEntities, allCards);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const rememberDeathrattles = (fish: BoardEntity, deadEntities: readonly BoardEntity[], cardsData: CardsData): void => {\r\n\tconst validDeathrattles = deadEntities\r\n\t\t.filter((entity) => cardsData.validDeathrattles.includes(entity.cardId))\r\n\t\t.map((entity) => entity.cardId);\r\n\tconst validEnchantments = deadEntities\r\n\t\t.filter((entity) => entity.enchantments?.length)\r\n\t\t.map((entity) => entity.enchantments)\r\n\t\t.reduce((a, b) => a.concat(b), [])\r\n\t\t.map((enchantment) => enchantment.cardId)\r\n\t\t.filter((enchantmentId) =>\r\n\t\t\t[\r\n\t\t\t\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment,\r\n\t\t\t\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantmentBattlegrounds,\r\n\t\t\t\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\t\t\t\tCardIds.SneedsReplicator_ReplicateEnchantment,\r\n\t\t\t\tCardIds.EarthInvocation_ElementEarthEnchantment,\r\n\t\t\t\tCardIds.FireInvocation_ElementFireEnchantment,\r\n\t\t\t\tCardIds.WaterInvocation_ElementWaterEnchantment,\r\n\t\t\t\tCardIds.LightningInvocation,\r\n\t\t\t].includes(enchantmentId as CardIds),\r\n\t\t);\r\n\tconst newDeathrattles = [...validDeathrattles, ...validEnchantments];\r\n\t// Order is important\r\n\tif (fish.cardId === CardIds.FishOfNzothBattlegrounds) {\r\n\t\t// https://stackoverflow.com/questions/33305152/how-to-duplicate-elements-in-a-js-array\r\n\t\tconst doubleDr = [...validDeathrattles, ...validEnchantments].reduce((res, current) => res.concat([current, current]), []);\r\n\t\tfish.rememberedDeathrattles = [...doubleDr, ...(fish.rememberedDeathrattles || [])];\r\n\t} else {\r\n\t\tfish.rememberedDeathrattles = [...newDeathrattles, ...(fish.rememberedDeathrattles || [])];\r\n\t}\r\n};\r\n\r\nconst removeOldMurkEyeAttack = (boardWithDeadEntity: BoardEntity[], allCards: AllCardsService) => {\r\n\tconst murkeyes = boardWithDeadEntity.filter(\r\n\t\t(entity) => entity.cardId === CardIds.OldMurkEyeLegacy || entity.cardId === CardIds.OldMurkEyeVanilla,\r\n\t);\r\n\tconst goldenMurkeyes = boardWithDeadEntity.filter((entity) => entity.cardId === CardIds.OldMurkEyeBattlegrounds);\r\n\tmurkeyes.forEach((entity) => {\r\n\t\tmodifyAttack(entity, -1, boardWithDeadEntity, allCards);\r\n\t\tafterStatsUpdate(entity, boardWithDeadEntity, allCards);\r\n\t});\r\n\tgoldenMurkeyes.forEach((entity) => {\r\n\t\tmodifyAttack(entity, -2, boardWithDeadEntity, allCards);\r\n\t\tafterStatsUpdate(entity, boardWithDeadEntity, allCards);\r\n\t});\r\n};\r\n"]}
@@ -115,8 +115,15 @@ const handleTamsinForPlayer = (playerBoard, playerEntity, opponentBoard, opponen
115
115
  const lowestHealth = Math.min(...playerBoard.map((e) => e.health));
116
116
  const entitiesWithLowestHealth = playerBoard.filter((e) => e.health === lowestHealth);
117
117
  const chosenEntity = utils_1.pickRandom(entitiesWithLowestHealth);
118
- utils_2.addStatsToBoard(chosenEntity, playerBoard.filter((e) => e.entityId !== chosenEntity.entityId), chosenEntity.attack, chosenEntity.health, allCards, spectator);
118
+ const newBoard = playerBoard.filter((e) => e.entityId !== chosenEntity.entityId);
119
+ const buffedEntities = utils_1.pickMultipleRandomDifferent(newBoard, 4);
119
120
  chosenEntity.definitelyDead = true;
121
+ buffedEntities.forEach((e) => {
122
+ utils_2.modifyAttack(e, chosenEntity.attack, newBoard, allCards);
123
+ utils_2.modifyHealth(e, chosenEntity.health, newBoard, allCards);
124
+ utils_2.afterStatsUpdate(e, newBoard, allCards);
125
+ spectator.registerPowerTarget(chosenEntity, e, newBoard);
126
+ });
120
127
  };
121
128
  const handlePlayerStartOfCombatHeroPowers = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, friendly, allCards, cardsData, sharedState, spectator) => {
122
129
  var _a, _b, _c, _d;
@@ -1 +1 @@
1
- {"version":3,"file":"start-of-combat.js","sourceRoot":"","sources":["../../src/simulation/start-of-combat.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAI9E,oDAA0E;AAC1E,6CAA+C;AAC/C,oCAAyG;AACzG,qCAAyH;AACzH,mCAAkD;AAClD,+DAK+B;AAIxB,MAAM,mBAAmB,GAAG,CAClC,YAA6B,EAC7B,WAA0B,EAC1B,cAA+B,EAC/B,aAA4B,EAC5B,eAAuB,EACvB,QAAyB,EACzB,MAAiB,EACjB,WAAwB,EACxB,SAAuB,EACvB,SAAoB,EACX,EAAE;IAKX,eAAe,GAAG,yBAAyB,CAC1C,YAAY,EACZ,WAAW,EACX,cAAc,EACd,aAAa,EACb,eAAe,EACf,QAAQ,EACR,MAAM,EACN,WAAW,EACX,SAAS,EACT,SAAS,CACT,CAAC;IACF,eAAe,GAAG,+BAAuB,CACxC,YAAY,EACZ,WAAW,EAC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CAAC,GAAG,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YAC5D,wBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACnD,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;KACH;SAAM,IAAI,QAAQ,CAAC,MAAM,0BAAoB,IAAI,QAAQ,CAAC,MAAM,4BAAgC,EAAE;QAClG,MAAM,UAAU,GAAG,sBAAa,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,4BAAgC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;;YAC7B,oBAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAC,kBAAkB,CAAC,iBAAiB,mCAAI,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACzG,oBAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAC,kBAAkB,CAAC,iBAAiB,mCAAI,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACzG,wBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACnD,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;KACH;IACD,mBAAW,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACvC,mBAAW,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAvHW,QAAA,oCAAoC,wCAuH/C","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsGameState } from '../bgs-battle-info';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData, START_OF_COMBAT_CARD_IDS } from '../cards/cards-data';\r\nimport { pickRandom } from '../services/utils';\r\nimport { addStatsToBoard, afterStatsUpdate, isCorrectTribe, modifyAttack, modifyHealth } from '../utils';\r\nimport { dealDamageToEnemy, dealDamageToRandomEnemy, getNeighbours, processMinionDeath, simulateAttack } from './attack';\r\nimport { applyAuras, removeAuras } from './auras';\r\nimport {\r\n\tapplyEarthInvocationEnchantment,\r\n\tapplyFireInvocationEnchantment,\r\n\tapplyLightningInvocationEnchantment,\r\n\tapplyWaterInvocationEnchantment,\r\n} from './deathrattle-effects';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const handleStartOfCombat = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// https://twitter.com/DCalkosz/status/1488361384320528388?s=20&t=1ECxRZFdjqwEa2fRsXk32Q\r\n\t// There’s a certain order for Start of Combat hero powers, rather than “coin flips” where\r\n\t// an unlucky trigger order could mess up some positioning you had planned for your own hero\r\n\t// power. “Precombat” (Al’Akir, Y’Shaarj), then Illidan, then others.\r\n\tcurrentAttacker = handlePreCombatHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleIllidanHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatMinions(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePreCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// Some are part of the incoming board: Y'Shaarj, Lich King\r\n\t// Since the order is not important here, we just always do the player first\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.SwattingInsectsBattlegrounds && playerBoard.length > 0) {\r\n\t\t// Should be sent by the app, but it is an idempotent operation, so we can just reapply it here\r\n\t\thandleAlakirForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, spawns, sharedState, spectator);\r\n\t}\r\n\r\n\tconst opponentHeroPowerId = opponentEntity.heroPowerId || getHeroPowerForHero(opponentEntity.cardId);\r\n\tif (opponentHeroPowerId === CardIds.SwattingInsectsBattlegrounds && opponentBoard.length > 0) {\r\n\t\thandleAlakirForPlayer(opponentBoard, opponentEntity, playerBoard, playerEntity, allCards, spawns, sharedState, spectator);\r\n\t}\r\n\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const handleIllidanHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// Apparently it's a toin coss about whether to handle Illidan first or Al'Akir first\r\n\t// Auras are only relevant for Illidan, and already applied there\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatMinions = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tlet attackerForStart = Math.round(Math.random());\r\n\tconst playerAttackers = playerBoard.filter((entity) => START_OF_COMBAT_CARD_IDS.indexOf(entity.cardId as CardIds) !== -1);\r\n\tconst opponentAttackers = opponentBoard.filter((entity) => START_OF_COMBAT_CARD_IDS.indexOf(entity.cardId as CardIds) !== -1);\r\n\twhile (playerAttackers.length > 0 || opponentAttackers.length > 0) {\r\n\t\tif (attackerForStart === 0 && playerAttackers.length > 0) {\r\n\t\t\tconst attacker = playerAttackers.splice(0, 1)[0];\r\n\t\t\tperformStartOfCombatMinionsForPlayer(\r\n\t\t\t\tattacker,\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentEntity,\r\n\t\t\t\tallCards,\r\n\t\t\t\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tgameState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 1 && opponentAttackers.length > 0) {\r\n\t\t\tconst attacker = opponentAttackers.splice(0, 1)[0];\r\n\t\t\tperformStartOfCombatMinionsForPlayer(\r\n\t\t\t\tattacker,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentEntity,\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\tallCards,\r\n\t\t\t\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tgameState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tattackerForStart = (attackerForStart + 1) % 2;\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const handleStartOfCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst attackingHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tconst defendingHeroPowerId = opponentEntity.heroPowerId || getHeroPowerForHero(opponentEntity.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\r\n\tapplyAuras(playerBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\tapplyAuras(opponentBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\r\n\t// Apparently it's a toin coss about whether to handle Illidan first or Al'Akir first\r\n\t// Auras are only relevant for Illidan, and already applied there\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\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\tremoveAuras(playerBoard, cardsData);\r\n\tremoveAuras(opponentBoard, cardsData);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePlayerIllidanHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tfriendly: boolean,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.WingmenBattlegrounds && playerBoard.length > 0) {\r\n\t\thandleIllidanForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, spawns, sharedState, spectator);\r\n\t\tcurrentAttacker = (currentAttacker + 1) % 2;\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\n// TODO: not exactly correct, because of \"attack immediately\", but it's close enough\r\nconst handleIllidanForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Otherwise, if the first minion dies on the attack, and the board has only 2 minions, we\r\n\t// miss the second one\r\n\tconst minionsAtStart = playerBoard.length;\r\n\tmodifyAttack(playerBoard[0], 2, playerBoard, allCards);\r\n\tafterStatsUpdate(playerBoard[0], playerBoard, allCards);\r\n\tspectator.registerPowerTarget(playerBoard[0], playerBoard[0], playerBoard);\r\n\tif (\r\n\t\tplayerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds2) ||\r\n\t\tplayerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds1)\r\n\t) {\r\n\t\tplayerBoard[0].immuneWhenAttackCharges = 1;\r\n\t}\r\n\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, undefined, allCards, spawns, sharedState, spectator, 0);\r\n\r\n\tif (minionsAtStart > 1) {\r\n\t\tmodifyAttack(playerBoard[playerBoard.length - 1], 2, playerBoard, allCards);\r\n\t\tafterStatsUpdate(playerBoard[playerBoard.length - 1], playerBoard, allCards);\r\n\t\tspectator.registerPowerTarget(playerBoard[playerBoard.length - 1], playerBoard[playerBoard.length - 1], playerBoard);\r\n\t\tif (playerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds2)) {\r\n\t\t\tplayerBoard[playerBoard.length - 1].immuneWhenAttackCharges = 1;\r\n\t\t}\r\n\t\tsimulateAttack(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tundefined,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tplayerBoard.length - 1,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nconst handleAlakirForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst firstEntity = playerBoard[0];\r\n\tfirstEntity.windfury = true;\r\n\tfirstEntity.divineShield = true;\r\n\tfirstEntity.taunt = true;\r\n\tspectator.registerPowerTarget(firstEntity, firstEntity, playerBoard);\r\n};\r\n\r\nconst handleTamsinForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst lowestHealth = Math.min(...playerBoard.map((e) => e.health));\r\n\tconst entitiesWithLowestHealth = playerBoard.filter((e) => e.health === lowestHealth);\r\n\tconst chosenEntity = pickRandom(entitiesWithLowestHealth);\r\n\taddStatsToBoard(\r\n\t\tchosenEntity,\r\n\t\tplayerBoard.filter((e) => e.entityId !== chosenEntity.entityId),\r\n\t\tchosenEntity.attack,\r\n\t\tchosenEntity.health,\r\n\t\tallCards,\r\n\t\tspectator,\r\n\t);\r\n\t// How to mark the minion as dead\r\n\tchosenEntity.definitelyDead = true;\r\n};\r\n\r\nconst handlePlayerStartOfCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tfriendly: boolean,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TamsinRoame_FragrantPhylactery) {\r\n\t\thandleTamsinForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLeftToken) {\r\n\t\tconst target = opponentBoard[0];\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimRightToken) {\r\n\t\tconst target = opponentBoard[opponentBoard.length - 1];\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLowToken) {\r\n\t\tconst smallestHealthMinion = [...opponentBoard].sort((a, b) => a.health - b.health)[0];\r\n\t\tconst target = pickRandom(opponentBoard.filter((e) => e.health === smallestHealthMinion.health));\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimHighToken) {\r\n\t\tconst highestHealthMinion = [...opponentBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\tconst target = pickRandom(opponentBoard.filter((e) => e.health === highestHealthMinion.health));\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EarthInvocationToken) {\r\n\t\tapplyEarthInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaterInvocationToken) {\r\n\t\tapplyWaterInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.FireInvocationToken) {\r\n\t\tapplyFireInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.LightningInvocationToken) {\r\n\t\tapplyLightningInvocationEnchantment(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tnull,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const getHeroPowerForHero = (heroCardId: string): string => {\r\n\tswitch (heroCardId) {\r\n\t\tcase CardIds.IllidanStormrageBattlegrounds:\r\n\t\t\treturn CardIds.WingmenBattlegrounds;\r\n\t\tcase CardIds.TheLichKingBattlegrounds:\r\n\t\t\treturn CardIds.RebornRitesBattlegrounds;\r\n\t\tcase CardIds.ProfessorPutricideBattlegrounds:\r\n\t\t\treturn CardIds.RagePotionBattlegrounds;\r\n\t\tcase CardIds.DeathwingBattlegrounds:\r\n\t\t\treturn CardIds.AllWillBurnBattlegrounds;\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const performStartOfCombatMinionsForPlayer = (\r\n\tattacker: 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\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst attackingHeroPowerId = attackingBoardHero.heroPowerId || getHeroPowerForHero(attackingBoardHero.cardId);\r\n\tconst defendingHeroPowerId = defendingBoardHero.heroPowerId || getHeroPowerForHero(defendingBoardHero.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\r\n\tapplyAuras(attackingBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\tapplyAuras(defendingBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\r\n\t// For now we're only dealing with the red whelp\r\n\tif (attacker.cardId === CardIds.RedWhelp) {\r\n\t\tconst damage = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tprocessMinionDeath(\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);\r\n\t} else if (attacker.cardId === CardIds.RedWhelpBattlegrounds) {\r\n\t\tconst damage = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tprocessMinionDeath(\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);\r\n\t} else if (attacker.cardId === CardIds.PrizedPromoDrake) {\r\n\t\tconst numberOfDragons = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, numberOfDragons, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, numberOfDragons, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t} else if (attacker.cardId === CardIds.PrizedPromoDrakeBattlegrounds) {\r\n\t\tconst dragons = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2 * dragons, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2 * dragons, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t} else if (attacker.cardId === CardIds.Crabby1 || attacker.cardId === CardIds.CrabbyBattlegrounds) {\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tconst multiplier = attacker.cardId === CardIds.CrabbyBattlegrounds ? 2 : 1;\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, multiplier * (attackingBoardHero.deadEyeDamageDone ?? 0), attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, multiplier * (attackingBoardHero.deadEyeDamageDone ?? 0), attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t}\r\n\tremoveAuras(attackingBoard, cardsData);\r\n\tremoveAuras(defendingBoard, cardsData);\r\n};\r\n"]}
1
+ {"version":3,"file":"start-of-combat.js","sourceRoot":"","sources":["../../src/simulation/start-of-combat.ts"],"names":[],"mappings":";;;AACA,iEAA8E;AAI9E,oDAA0E;AAC1E,6CAA4E;AAC5E,oCAAwF;AACxF,qCAAyH;AACzH,mCAAkD;AAClD,+DAK+B;AAIxB,MAAM,mBAAmB,GAAG,CAClC,YAA6B,EAC7B,WAA0B,EAC1B,cAA+B,EAC/B,aAA4B,EAC5B,eAAuB,EACvB,QAAyB,EACzB,MAAiB,EACjB,WAAwB,EACxB,SAAuB,EACvB,SAAoB,EACX,EAAE;IAKX,eAAe,GAAG,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AC;YACzG,oBAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAC,kBAAkB,CAAC,iBAAiB,mCAAI,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACzG,wBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;YACnD,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;KACH;IACD,mBAAW,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACvC,mBAAW,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAvHW,QAAA,oCAAoC,wCAuH/C","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsGameState } from '../bgs-battle-info';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData, START_OF_COMBAT_CARD_IDS } from '../cards/cards-data';\r\nimport { pickMultipleRandomDifferent, pickRandom } from '../services/utils';\r\nimport { afterStatsUpdate, isCorrectTribe, modifyAttack, modifyHealth } from '../utils';\r\nimport { dealDamageToEnemy, dealDamageToRandomEnemy, getNeighbours, processMinionDeath, simulateAttack } from './attack';\r\nimport { applyAuras, removeAuras } from './auras';\r\nimport {\r\n\tapplyEarthInvocationEnchantment,\r\n\tapplyFireInvocationEnchantment,\r\n\tapplyLightningInvocationEnchantment,\r\n\tapplyWaterInvocationEnchantment,\r\n} from './deathrattle-effects';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const handleStartOfCombat = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// https://twitter.com/DCalkosz/status/1488361384320528388?s=20&t=1ECxRZFdjqwEa2fRsXk32Q\r\n\t// There’s a certain order for Start of Combat hero powers, rather than “coin flips” where\r\n\t// an unlucky trigger order could mess up some positioning you had planned for your own hero\r\n\t// power. “Precombat” (Al’Akir, Y’Shaarj), then Illidan, then others.\r\n\tcurrentAttacker = handlePreCombatHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleIllidanHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatHeroPowers(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatMinions(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tallCards,\r\n\t\tspawns,\r\n\t\tsharedState,\r\n\t\tgameState,\r\n\t\tspectator,\r\n\t);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePreCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// Some are part of the incoming board: Y'Shaarj, Lich King\r\n\t// Since the order is not important here, we just always do the player first\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.SwattingInsectsBattlegrounds && playerBoard.length > 0) {\r\n\t\t// Should be sent by the app, but it is an idempotent operation, so we can just reapply it here\r\n\t\thandleAlakirForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, spawns, sharedState, spectator);\r\n\t}\r\n\r\n\tconst opponentHeroPowerId = opponentEntity.heroPowerId || getHeroPowerForHero(opponentEntity.cardId);\r\n\tif (opponentHeroPowerId === CardIds.SwattingInsectsBattlegrounds && opponentBoard.length > 0) {\r\n\t\thandleAlakirForPlayer(opponentBoard, opponentEntity, playerBoard, playerEntity, allCards, spawns, sharedState, spectator);\r\n\t}\r\n\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const handleIllidanHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\t// Apparently it's a toin coss about whether to handle Illidan first or Al'Akir first\r\n\t// Auras are only relevant for Illidan, and already applied there\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePlayerIllidanHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatMinions = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tlet attackerForStart = Math.round(Math.random());\r\n\tconst playerAttackers = playerBoard.filter((entity) => START_OF_COMBAT_CARD_IDS.indexOf(entity.cardId as CardIds) !== -1);\r\n\tconst opponentAttackers = opponentBoard.filter((entity) => START_OF_COMBAT_CARD_IDS.indexOf(entity.cardId as CardIds) !== -1);\r\n\twhile (playerAttackers.length > 0 || opponentAttackers.length > 0) {\r\n\t\tif (attackerForStart === 0 && playerAttackers.length > 0) {\r\n\t\t\tconst attacker = playerAttackers.splice(0, 1)[0];\r\n\t\t\tperformStartOfCombatMinionsForPlayer(\r\n\t\t\t\tattacker,\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentEntity,\r\n\t\t\t\tallCards,\r\n\t\t\t\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tgameState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 1 && opponentAttackers.length > 0) {\r\n\t\t\tconst attacker = opponentAttackers.splice(0, 1)[0];\r\n\t\t\tperformStartOfCombatMinionsForPlayer(\r\n\t\t\t\tattacker,\r\n\t\t\t\topponentBoard,\r\n\t\t\t\topponentEntity,\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\tallCards,\r\n\t\t\t\tspawns,\r\n\t\t\t\tsharedState,\r\n\t\t\t\tgameState,\r\n\t\t\t\tspectator,\r\n\t\t\t);\r\n\t\t}\r\n\t\tattackerForStart = (attackerForStart + 1) % 2;\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const handleStartOfCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst attackingHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tconst defendingHeroPowerId = opponentEntity.heroPowerId || getHeroPowerForHero(opponentEntity.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\r\n\tapplyAuras(playerBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\tapplyAuras(opponentBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\r\n\t// Apparently it's a toin coss about whether to handle Illidan first or Al'Akir first\r\n\t// Auras are only relevant for Illidan, and already applied there\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\tfalse,\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\tcurrentAttacker = handlePlayerStartOfCombatHeroPowers(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tcurrentAttacker,\r\n\t\t\ttrue,\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\tremoveAuras(playerBoard, cardsData);\r\n\tremoveAuras(opponentBoard, cardsData);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePlayerIllidanHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tfriendly: boolean,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.WingmenBattlegrounds && playerBoard.length > 0) {\r\n\t\thandleIllidanForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, spawns, sharedState, spectator);\r\n\t\tcurrentAttacker = (currentAttacker + 1) % 2;\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\n// TODO: not exactly correct, because of \"attack immediately\", but it's close enough\r\nconst handleIllidanForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Otherwise, if the first minion dies on the attack, and the board has only 2 minions, we\r\n\t// miss the second one\r\n\tconst minionsAtStart = playerBoard.length;\r\n\tmodifyAttack(playerBoard[0], 2, playerBoard, allCards);\r\n\tafterStatsUpdate(playerBoard[0], playerBoard, allCards);\r\n\tspectator.registerPowerTarget(playerBoard[0], playerBoard[0], playerBoard);\r\n\tif (\r\n\t\tplayerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds2) ||\r\n\t\tplayerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds1)\r\n\t) {\r\n\t\tplayerBoard[0].immuneWhenAttackCharges = 1;\r\n\t}\r\n\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, undefined, allCards, spawns, sharedState, spectator, 0);\r\n\r\n\tif (minionsAtStart > 1) {\r\n\t\tmodifyAttack(playerBoard[playerBoard.length - 1], 2, playerBoard, allCards);\r\n\t\tafterStatsUpdate(playerBoard[playerBoard.length - 1], playerBoard, allCards);\r\n\t\tspectator.registerPowerTarget(playerBoard[playerBoard.length - 1], playerBoard[playerBoard.length - 1], playerBoard);\r\n\t\tif (playerBoard.map((e) => e.cardId).includes(CardIds.EclipsionIllidariBattlegrounds2)) {\r\n\t\t\tplayerBoard[playerBoard.length - 1].immuneWhenAttackCharges = 1;\r\n\t\t}\r\n\t\tsimulateAttack(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tundefined,\r\n\t\t\tallCards,\r\n\t\t\tspawns,\r\n\t\t\tsharedState,\r\n\t\t\tspectator,\r\n\t\t\tplayerBoard.length - 1,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nconst handleAlakirForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst firstEntity = playerBoard[0];\r\n\tfirstEntity.windfury = true;\r\n\tfirstEntity.divineShield = true;\r\n\tfirstEntity.taunt = true;\r\n\tspectator.registerPowerTarget(firstEntity, firstEntity, playerBoard);\r\n};\r\n\r\nconst handleTamsinForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tallCards: AllCardsService,\r\n\tspawns: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst lowestHealth = Math.min(...playerBoard.map((e) => e.health));\r\n\tconst entitiesWithLowestHealth = playerBoard.filter((e) => e.health === lowestHealth);\r\n\tconst chosenEntity = pickRandom(entitiesWithLowestHealth);\r\n\tconst newBoard = playerBoard.filter((e) => e.entityId !== chosenEntity.entityId);\r\n\tconst buffedEntities = pickMultipleRandomDifferent(newBoard, 4);\r\n\t// How to mark the minion as dead\r\n\tchosenEntity.definitelyDead = true;\r\n\tbuffedEntities.forEach((e) => {\r\n\t\tmodifyAttack(e, chosenEntity.attack, newBoard, allCards);\r\n\t\tmodifyHealth(e, chosenEntity.health, newBoard, allCards);\r\n\t\tafterStatsUpdate(e, newBoard, allCards);\r\n\t\tspectator.registerPowerTarget(chosenEntity, e, newBoard);\r\n\t});\r\n};\r\n\r\nconst handlePlayerStartOfCombatHeroPowers = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tfriendly: boolean,\r\n\tallCards: AllCardsService,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tspectator: Spectator,\r\n): number => {\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TamsinRoame_FragrantPhylactery) {\r\n\t\thandleTamsinForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLeftToken) {\r\n\t\tconst target = opponentBoard[0];\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimRightToken) {\r\n\t\tconst target = opponentBoard[opponentBoard.length - 1];\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLowToken) {\r\n\t\tconst smallestHealthMinion = [...opponentBoard].sort((a, b) => a.health - b.health)[0];\r\n\t\tconst target = pickRandom(opponentBoard.filter((e) => e.health === smallestHealthMinion.health));\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimHighToken) {\r\n\t\tconst highestHealthMinion = [...opponentBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\tconst target = pickRandom(opponentBoard.filter((e) => e.health === highestHealthMinion.health));\r\n\t\tconst damageDone = dealDamageToEnemy(\r\n\t\t\ttarget,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tnull,\r\n\t\t\tplayerEntity.heroPowerInfo ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EarthInvocationToken) {\r\n\t\tapplyEarthInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaterInvocationToken) {\r\n\t\tapplyWaterInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.FireInvocationToken) {\r\n\t\tapplyFireInvocationEnchantment(playerBoard, null, allCards, spectator);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.LightningInvocationToken) {\r\n\t\tapplyLightningInvocationEnchantment(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tnull,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\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\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nexport const getHeroPowerForHero = (heroCardId: string): string => {\r\n\tswitch (heroCardId) {\r\n\t\tcase CardIds.IllidanStormrageBattlegrounds:\r\n\t\t\treturn CardIds.WingmenBattlegrounds;\r\n\t\tcase CardIds.TheLichKingBattlegrounds:\r\n\t\t\treturn CardIds.RebornRitesBattlegrounds;\r\n\t\tcase CardIds.ProfessorPutricideBattlegrounds:\r\n\t\t\treturn CardIds.RagePotionBattlegrounds;\r\n\t\tcase CardIds.DeathwingBattlegrounds:\r\n\t\t\treturn CardIds.AllWillBurnBattlegrounds;\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const performStartOfCombatMinionsForPlayer = (\r\n\tattacker: 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\tgameState: BgsGameState,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst attackingHeroPowerId = attackingBoardHero.heroPowerId || getHeroPowerForHero(attackingBoardHero.cardId);\r\n\tconst defendingHeroPowerId = defendingBoardHero.heroPowerId || getHeroPowerForHero(defendingBoardHero.cardId);\r\n\tconst numberOfDeathwingPresents =\r\n\t\t(attackingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0) +\r\n\t\t(defendingHeroPowerId === CardIds.AllWillBurnBattlegrounds ? 1 : 0);\r\n\tapplyAuras(attackingBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\tapplyAuras(defendingBoard, numberOfDeathwingPresents, cardsData, allCards);\r\n\r\n\t// For now we're only dealing with the red whelp\r\n\tif (attacker.cardId === CardIds.RedWhelp) {\r\n\t\tconst damage = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tprocessMinionDeath(\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);\r\n\t} else if (attacker.cardId === CardIds.RedWhelpBattlegrounds) {\r\n\t\tconst damage = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tdealDamageToRandomEnemy(\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattacker,\r\n\t\t\tdamage,\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\tprocessMinionDeath(\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);\r\n\t} else if (attacker.cardId === CardIds.PrizedPromoDrake) {\r\n\t\tconst numberOfDragons = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, numberOfDragons, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, numberOfDragons, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t} else if (attacker.cardId === CardIds.PrizedPromoDrakeBattlegrounds) {\r\n\t\tconst dragons = attackingBoard\r\n\t\t\t.map((entity) => allCards.getCard(entity.cardId).race)\r\n\t\t\t.filter((race) => isCorrectTribe(race, Race.DRAGON)).length;\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, 2 * dragons, attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, 2 * dragons, attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t} else if (attacker.cardId === CardIds.Crabby1 || attacker.cardId === CardIds.CrabbyBattlegrounds) {\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tconst multiplier = attacker.cardId === CardIds.CrabbyBattlegrounds ? 2 : 1;\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyAttack(entity, multiplier * (attackingBoardHero.deadEyeDamageDone ?? 0), attackingBoard, allCards);\r\n\t\t\tmodifyHealth(entity, multiplier * (attackingBoardHero.deadEyeDamageDone ?? 0), attackingBoard, allCards);\r\n\t\t\tafterStatsUpdate(entity, attackingBoard, allCards);\r\n\t\t\tspectator.registerPowerTarget(attacker, entity, attackingBoard);\r\n\t\t});\r\n\t}\r\n\tremoveAuras(attackingBoard, cardsData);\r\n\tremoveAuras(defendingBoard, cardsData);\r\n};\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firestone-hs/simulate-bgs-battle",
3
- "version": "1.1.157",
3
+ "version": "1.1.161",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "lint": "eslint --color --fix --ext .ts .",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@firestone-hs/hs-replay-xml-parser": "0.0.46",
31
- "@firestone-hs/reference-data": "^0.1.198",
31
+ "@firestone-hs/reference-data": "^0.1.205",
32
32
  "cross-fetch": "^3.1.5",
33
33
  "lodash.clonedeep": "^4.5.0",
34
34
  "node-fetch": "^2.6.7"