@firestone-hs/simulate-bgs-battle 1.1.475 → 1.1.476

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.
@@ -62,6 +62,9 @@ const onMinionDeadQuest = (deadEntity, indexFromRight, board, boardHero, otherBo
62
62
  case "BG24_Quest_124":
63
63
  (0, quest_1.onQuestProgressUpdated)(boardHero, quest, board, gameState);
64
64
  break;
65
+ case "BG27_Quest_802":
66
+ (0, quest_1.onQuestProgressUpdated)(boardHero, quest, board, gameState);
67
+ break;
65
68
  }
66
69
  }
67
70
  for (const trinket of boardHero.trinkets) {
@@ -1 +1 @@
1
- {"version":3,"file":"minion-death.js","sourceRoot":"","sources":["../../src/simulation/minion-death.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,6CAAoD;AACpD,oCAAwE;AACxE,qCAAgD;AAChD,mDAAiD;AACjD,6DAAqD;AAErD,mCAAiD;AACjD,yEAAmE;AACnE,qCAA+C;AAC/C,mCAAsC;AAE/B,MAAM,cAAc,GAAG,CAC7B,KAAoB,EACpB,SAA0B,EAC1B,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACI,EAAE;IAE9B,MAAM,0BAA0B,GAAa,EAAE,CAAC;IAChD,MAAM,YAAY,GAAkB,EAAE,CAAC;IACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE;YACpD,0BAA0B,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC9D,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAS5B;KAC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C,CAAC,MAAM,iBAA0C,CAAC,CAAC;oBAC1F,MAAM,cAAc,GAAG,MAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,iBAAiB,mCAAI,CAAC,CAAC;oBACnE,MAAM,cAAc,GAAG,MAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,iBAAiB,mCAAI,CAAC,CAAC;oBACnE,IAAI,cAAc,GAAG,CAAC,IAAI,cAAc,GAAG,CAAC,EAAE;wBAC7C,MAAM,MAAM,GAAG,IAAA,kCAAa,yBAE3B,CAAC,EACD,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,WAAW,EACrB,SAAS,CAAC,SAAS,EACnB,UAAU,CAAC,QAAQ,EACnB,KAAK,CACL,CAAC;wBACF,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;4BACpB,CAAC,CAAC,MAAM,GAAG,cAAc,CAAC;4BAC1B,CAAC,CAAC,MAAM,GAAG,cAAc,CAAC;wBAC3B,CAAC,CAAC,CAAC;wBACH,IAAA,4BAAmB,EAClB,MAAM,EACN,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,SAAS,CACT,CAAC;qBACF;oBACD,OAAO,CAAC,cAAc,EAAE,CAAC;iBACzB;gBACD,MAAM;SACP;KACD;AACF,CAAC,CAAC;AArGW,QAAA,iBAAiB,qBAqG5B","sourcesContent":["import { CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { pickRandomAlive } from '../services/utils';\r\nimport { getEffectiveTribesForEntity, hasCorrectTribe } from '../utils';\r\nimport { updateAvengeCounters } from './avenge';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { removeMinionFromBoard } from './remove-minion-from-board';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { modifyStats } from './stats';\r\n\r\nexport const makeMinionsDie = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): [number[], BoardEntity[]] => {\r\n\t// Because entities spawn to the left, so the right index is unchanged\r\n\tconst deadMinionIndexesFromRight: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tconst initialBoardLength = board.length;\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexesFromRight.push(initialBoardLength - (i + 1));\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\t// console.log(\r\n\t\t\t// \t'\\tflagging dead minion 0',\r\n\t\t\t// \tstringifySimpleCard(board[i], allCards),\r\n\t\t\t// \tstringifySimple(board, allCards),\r\n\t\t\t// \tinitialBoardLength,\r\n\t\t\t// \ti,\r\n\t\t\t// \tdeadMinionIndexesFromRight,\r\n\t\t\t// );\r\n\t\t}\r\n\t}\r\n\r\n\t// These will always be processed from left to right afterwards\r\n\t// We compute the indexes as they will be once the new board is effective. For a\r\n\t// board of length N, having an indexFromRight at N means it will spawn at the very left\r\n\t// of the board (first minion)\r\n\tlet indexesFromRightAfterDeath = [];\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tconst newIndex = deadMinionIndexesFromRight[i] - indexesFromRightAfterDeath.length;\r\n\t\tindexesFromRightAfterDeath.push(newIndex);\r\n\t}\r\n\tindexesFromRightAfterDeath = indexesFromRightAfterDeath.reverse();\r\n\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\t// console.log('\\tflagging dead minion', stringifySimpleCard(board[i], allCards), deadMinionIndexesFromRight);\r\n\t\t\tremoveMinionFromBoard(board, boardHero, i, gameState);\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\r\n\t// console.debug('dead entities', stringifySimple(deadEntities, allCards));\r\n\t// Update the avenge counters as soon as minions die. If we wait until the \"avenge\" phase, we might\r\n\t// update the counters for entities that have been spawned after the death of the original entity\r\n\t// ISSUE: deaths are actually processed one by one. Once a minion dies, its DR triggers, then the next, etc.\r\n\t// This means that if you have a minion that summons another one, it can progress and complete and quest\r\n\t// and the next minion dying could count towards that quest progress\r\n\t// See http://replays.firestoneapp.com/?reviewId=0ce4db9c-3269-4704-b662-8a8c31f5afe1&turn=16&action=27\r\n\tfor (const deadEntity of deadEntities) {\r\n\t\tconst indexFromRight = indexesFromRightAfterDeath[deadEntities.indexOf(deadEntity)];\r\n\t\tupdateAvengeCounters(board, boardHero);\r\n\t\tonMinionDeadHeroPower(board, boardHero, deadEntity, gameState);\r\n\t\tonMinionDeadHeroPower(otherBoard, otherBoardHero, deadEntity, gameState);\r\n\t\tonMinionDeadQuest(deadEntity, indexFromRight, board, boardHero, otherBoard, otherBoardHero, gameState);\r\n\t\tonMinionDeadQuest(deadEntity, indexFromRight, otherBoard, otherBoardHero, board, boardHero, gameState);\r\n\t}\r\n\r\n\treturn [indexesFromRightAfterDeath, deadEntities];\r\n};\r\n\r\nexport const onMinionDeadHeroPower = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tif (\r\n\t\tboardHero.heroPowerId === CardIds.IllTakeThat &&\r\n\t\tboardHero.heroPowerUsed &&\r\n\t\tboardHero.heroPowerInfo2 <= 0 &&\r\n\t\tdeadEntity.friendly !== boardHero.friendly\r\n\t) {\r\n\t\taddCardsInHand(boardHero, board, [deadEntity.cardId], gameState);\r\n\t\tboardHero.heroPowerInfo2 = 1;\r\n\t}\r\n};\r\n\r\nexport const onMinionDeadQuest = (\r\n\tdeadEntity: BoardEntity,\r\n\tindexFromRight: number,\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst quests = boardHero.questEntities ?? [];\r\n\tfor (const quest of quests) {\r\n\t\tswitch (quest.CardId) {\r\n\t\t\tcase CardIds.ReenactTheMurder:\r\n\t\t\t\tonQuestProgressUpdated(boardHero, quest, board, gameState);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const trinket of boardHero.trinkets) {\r\n\t\tswitch (trinket.cardId) {\r\n\t\t\tcase CardIds.AllianceKeychain_BG30_MagicItem_433:\r\n\t\t\tcase CardIds.AllianceKeychain_AllianceKeychainToken_BG30_MagicItem_433t:\r\n\t\t\t\tif (trinket.scriptDataNum1 > 0 && deadEntity.friendly === boardHero.friendly) {\r\n\t\t\t\t\tconst loops = trinket.cardId === CardIds.AllianceKeychain_BG30_MagicItem_433 ? 1 : 2;\r\n\t\t\t\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\t\t\t\tconst target = pickRandomAlive(board);\r\n\t\t\t\t\t\tif (!!target) {\r\n\t\t\t\t\t\t\tmodifyStats(\r\n\t\t\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t\t\tdeadEntity.maxAttack,\r\n\t\t\t\t\t\t\t\tdeadEntity.maxHealth,\r\n\t\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\ttrinket.scriptDataNum1--;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TheEyeOfDalaran_BG30_MagicItem_981:\r\n\t\t\t\tif (\r\n\t\t\t\t\tdeadEntity.friendly === boardHero.friendly &&\r\n\t\t\t\t\tgetEffectiveTribesForEntity(deadEntity, boardHero, gameState.allCards).length === 0\r\n\t\t\t\t) {\r\n\t\t\t\t\taddCardsInHand(boardHero, board, [null], gameState);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BloodGolemSticker_BG30_MagicItem_442:\r\n\t\t\t\tif (\r\n\t\t\t\t\tdeadEntity.friendly === boardHero.friendly &&\r\n\t\t\t\t\ttrinket.scriptDataNum1 > 0 &&\r\n\t\t\t\t\thasCorrectTribe(deadEntity, boardHero, Race.QUILBOAR, gameState.allCards)\r\n\t\t\t\t) {\r\n\t\t\t\t\tconst bloodGemEnchantment =\r\n\t\t\t\t\t\tdeadEntity.enchantments?.find((e) => e.cardId === CardIds.BloodGem_BloodGemEnchantment) ??\r\n\t\t\t\t\t\tdeadEntity.enchantments?.find((e) => e.cardId === CardIds.BloodGem_BloodGemsEnchantment);\r\n\t\t\t\t\tconst bloodGemAttack = bloodGemEnchantment?.tagScriptDataNum1 ?? 0;\r\n\t\t\t\t\tconst bloodGemHealth = bloodGemEnchantment?.tagScriptDataNum2 ?? 0;\r\n\t\t\t\t\tif (bloodGemAttack > 0 || bloodGemHealth > 0) {\r\n\t\t\t\t\t\tconst spawns = spawnEntities(\r\n\t\t\t\t\t\t\tCardIds.BloodGolemSticker_BloodGolemToken_BG30_MagicItem_442t,\r\n\t\t\t\t\t\t\t1,\r\n\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tspawns.forEach((b) => {\r\n\t\t\t\t\t\t\tb.attack = bloodGemAttack;\r\n\t\t\t\t\t\t\tb.health = bloodGemHealth;\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t\ttrinket.scriptDataNum1--;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n"]}
1
+ {"version":3,"file":"minion-death.js","sourceRoot":"","sources":["../../src/simulation/minion-death.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,6CAAoD;AACpD,oCAAwE;AACxE,qCAAgD;AAChD,mDAAiD;AACjD,6DAAqD;AAErD,mCAAiD;AACjD,yEAAmE;AACnE,qCAA+C;AAC/C,mCAAsC;AAE/B,MAAM,cAAc,GAAG,CAC7B,KAAoB,EACpB,SAA0B,EAC1B,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACI,EAAE;IAE9B,MAAM,0BAA0B,GAAa,EAAE,CAAC;IAChD,MAAM,YAAY,GAAkB,EAAE,CAAC;IACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC,MA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EACN,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,SAAS,CACT,CAAC;qBACF;oBACD,OAAO,CAAC,cAAc,EAAE,CAAC;iBACzB;gBACD,MAAM;SACP;KACD;AACF,CAAC,CAAC;AAxGW,QAAA,iBAAiB,qBAwG5B","sourcesContent":["import { CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { pickRandomAlive } from '../services/utils';\r\nimport { getEffectiveTribesForEntity, hasCorrectTribe } from '../utils';\r\nimport { updateAvengeCounters } from './avenge';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { removeMinionFromBoard } from './remove-minion-from-board';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { modifyStats } from './stats';\r\n\r\nexport const makeMinionsDie = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): [number[], BoardEntity[]] => {\r\n\t// Because entities spawn to the left, so the right index is unchanged\r\n\tconst deadMinionIndexesFromRight: number[] = [];\r\n\tconst deadEntities: BoardEntity[] = [];\r\n\tconst initialBoardLength = board.length;\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\tdeadMinionIndexesFromRight.push(initialBoardLength - (i + 1));\r\n\t\t\tdeadEntities.push(board[i]);\r\n\t\t\t// console.log(\r\n\t\t\t// \t'\\tflagging dead minion 0',\r\n\t\t\t// \tstringifySimpleCard(board[i], allCards),\r\n\t\t\t// \tstringifySimple(board, allCards),\r\n\t\t\t// \tinitialBoardLength,\r\n\t\t\t// \ti,\r\n\t\t\t// \tdeadMinionIndexesFromRight,\r\n\t\t\t// );\r\n\t\t}\r\n\t}\r\n\r\n\t// These will always be processed from left to right afterwards\r\n\t// We compute the indexes as they will be once the new board is effective. For a\r\n\t// board of length N, having an indexFromRight at N means it will spawn at the very left\r\n\t// of the board (first minion)\r\n\tlet indexesFromRightAfterDeath = [];\r\n\tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n\t\tconst newIndex = deadMinionIndexesFromRight[i] - indexesFromRightAfterDeath.length;\r\n\t\tindexesFromRightAfterDeath.push(newIndex);\r\n\t}\r\n\tindexesFromRightAfterDeath = indexesFromRightAfterDeath.reverse();\r\n\r\n\tfor (let i = 0; i < board.length; i++) {\r\n\t\tif (board[i].health <= 0 || board[i].definitelyDead) {\r\n\t\t\t// console.log('\\tflagging dead minion', stringifySimpleCard(board[i], allCards), deadMinionIndexesFromRight);\r\n\t\t\tremoveMinionFromBoard(board, boardHero, i, gameState);\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\r\n\t// console.debug('dead entities', stringifySimple(deadEntities, allCards));\r\n\t// Update the avenge counters as soon as minions die. If we wait until the \"avenge\" phase, we might\r\n\t// update the counters for entities that have been spawned after the death of the original entity\r\n\t// ISSUE: deaths are actually processed one by one. Once a minion dies, its DR triggers, then the next, etc.\r\n\t// This means that if you have a minion that summons another one, it can progress and complete and quest\r\n\t// and the next minion dying could count towards that quest progress\r\n\t// See http://replays.firestoneapp.com/?reviewId=0ce4db9c-3269-4704-b662-8a8c31f5afe1&turn=16&action=27\r\n\tfor (const deadEntity of deadEntities) {\r\n\t\tconst indexFromRight = indexesFromRightAfterDeath[deadEntities.indexOf(deadEntity)];\r\n\t\tupdateAvengeCounters(board, boardHero);\r\n\t\tonMinionDeadHeroPower(board, boardHero, deadEntity, gameState);\r\n\t\tonMinionDeadHeroPower(otherBoard, otherBoardHero, deadEntity, gameState);\r\n\t\tonMinionDeadQuest(deadEntity, indexFromRight, board, boardHero, otherBoard, otherBoardHero, gameState);\r\n\t\tonMinionDeadQuest(deadEntity, indexFromRight, otherBoard, otherBoardHero, board, boardHero, gameState);\r\n\t}\r\n\r\n\treturn [indexesFromRightAfterDeath, deadEntities];\r\n};\r\n\r\nexport const onMinionDeadHeroPower = (\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\tdeadEntity: BoardEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tif (\r\n\t\tboardHero.heroPowerId === CardIds.IllTakeThat &&\r\n\t\tboardHero.heroPowerUsed &&\r\n\t\tboardHero.heroPowerInfo2 <= 0 &&\r\n\t\tdeadEntity.friendly !== boardHero.friendly\r\n\t) {\r\n\t\taddCardsInHand(boardHero, board, [deadEntity.cardId], gameState);\r\n\t\tboardHero.heroPowerInfo2 = 1;\r\n\t}\r\n};\r\n\r\nexport const onMinionDeadQuest = (\r\n\tdeadEntity: BoardEntity,\r\n\tindexFromRight: number,\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst quests = boardHero.questEntities ?? [];\r\n\tfor (const quest of quests) {\r\n\t\tswitch (quest.CardId) {\r\n\t\t\tcase CardIds.ReenactTheMurder:\r\n\t\t\t\tonQuestProgressUpdated(boardHero, quest, board, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RoundUpTheSuspects:\r\n\t\t\t\tonQuestProgressUpdated(boardHero, quest, board, gameState);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const trinket of boardHero.trinkets) {\r\n\t\tswitch (trinket.cardId) {\r\n\t\t\tcase CardIds.AllianceKeychain_BG30_MagicItem_433:\r\n\t\t\tcase CardIds.AllianceKeychain_AllianceKeychainToken_BG30_MagicItem_433t:\r\n\t\t\t\tif (trinket.scriptDataNum1 > 0 && deadEntity.friendly === boardHero.friendly) {\r\n\t\t\t\t\tconst loops = trinket.cardId === CardIds.AllianceKeychain_BG30_MagicItem_433 ? 1 : 2;\r\n\t\t\t\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\t\t\t\tconst target = pickRandomAlive(board);\r\n\t\t\t\t\t\tif (!!target) {\r\n\t\t\t\t\t\t\tmodifyStats(\r\n\t\t\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t\t\tdeadEntity.maxAttack,\r\n\t\t\t\t\t\t\t\tdeadEntity.maxHealth,\r\n\t\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\ttrinket.scriptDataNum1--;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TheEyeOfDalaran_BG30_MagicItem_981:\r\n\t\t\t\tif (\r\n\t\t\t\t\tdeadEntity.friendly === boardHero.friendly &&\r\n\t\t\t\t\tgetEffectiveTribesForEntity(deadEntity, boardHero, gameState.allCards).length === 0\r\n\t\t\t\t) {\r\n\t\t\t\t\taddCardsInHand(boardHero, board, [null], gameState);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BloodGolemSticker_BG30_MagicItem_442:\r\n\t\t\t\tif (\r\n\t\t\t\t\tdeadEntity.friendly === boardHero.friendly &&\r\n\t\t\t\t\ttrinket.scriptDataNum1 > 0 &&\r\n\t\t\t\t\thasCorrectTribe(deadEntity, boardHero, Race.QUILBOAR, gameState.allCards)\r\n\t\t\t\t) {\r\n\t\t\t\t\tconst bloodGemEnchantment =\r\n\t\t\t\t\t\tdeadEntity.enchantments?.find((e) => e.cardId === CardIds.BloodGem_BloodGemEnchantment) ??\r\n\t\t\t\t\t\tdeadEntity.enchantments?.find((e) => e.cardId === CardIds.BloodGem_BloodGemsEnchantment);\r\n\t\t\t\t\tconst bloodGemAttack = bloodGemEnchantment?.tagScriptDataNum1 ?? 0;\r\n\t\t\t\t\tconst bloodGemHealth = bloodGemEnchantment?.tagScriptDataNum2 ?? 0;\r\n\t\t\t\t\tif (bloodGemAttack > 0 || bloodGemHealth > 0) {\r\n\t\t\t\t\t\tconst spawns = spawnEntities(\r\n\t\t\t\t\t\t\tCardIds.BloodGolemSticker_BloodGolemToken_BG30_MagicItem_442t,\r\n\t\t\t\t\t\t\t1,\r\n\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tspawns.forEach((b) => {\r\n\t\t\t\t\t\t\tb.attack = bloodGemAttack;\r\n\t\t\t\t\t\t\tb.health = bloodGemHealth;\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\t\tspawns,\r\n\t\t\t\t\t\t\tboard,\r\n\t\t\t\t\t\t\tboardHero,\r\n\t\t\t\t\t\t\tdeadEntity,\r\n\t\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t\ttrinket.scriptDataNum1--;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n"]}
@@ -15,7 +15,7 @@ const onQuestProgressUpdated = (playerEntity, quest, board, gameState) => {
15
15
  avengeCurrent: gameState.cardsData.avengeValue(rewardCardId),
16
16
  scriptDataNum1: gameState.cardsData.defaultScriptDataNum(rewardCardId),
17
17
  });
18
- playerEntity.questEntities = playerEntity.questEntities.filter((quest) => quest.CardId !== quest.CardId);
18
+ playerEntity.questEntities = playerEntity.questEntities.filter((q) => q.CardId !== quest.CardId);
19
19
  updateStateAfterQuestCreated(rewardCardId, board, playerEntity, gameState);
20
20
  };
21
21
  exports.onQuestProgressUpdated = onQuestProgressUpdated;
@@ -1 +1 @@
1
- {"version":3,"file":"quest.js","sourceRoot":"","sources":["../../src/simulation/quest.ts"],"names":[],"mappings":";;;AAKO,MAAM,sBAAsB,GAAG,CACrC,YAA6B,EAC7B,KAAqB,EACrB,KAAoB,EACpB,SAAwB,EACvB,EAAE;IACH,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,aAAa,EAAE;QAChD,OAAO;KACP;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;IACtE,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7C,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC;QACrC,MAAM,EAAE,YAAY;QACpB,QAAQ,EAAE,SAAS,CAAC,WAAW,CAAC,eAAe,EAAE;QACjD,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC5D,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC5D,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,oBAAoB,CAAC,YAAY,CAAC;KACtE,CAAC,CAAC;IAGH,YAAY,CAAC,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzG,4BAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC,CAAC;AAzBW,QAAA,sBAAsB,0BAyBjC;AAEF,MAAM,4BAA4B,GAAG,CACpC,YAAoB,EACpB,KAAoB,EACpB,YAA6B,EAC7B,SAAwB,EACvB,EAAE;IACH,QAAQ,YAAY,EAAE;QACrB;YACC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACnB,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;YACH,MAAM;QACP;YACC,MAAM;KACP;AACF,CAAC,CAAC","sourcesContent":["import { CardIds } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity, BgsQuestEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { FullGameState } from './internal-game-state';\r\n\r\nexport const onQuestProgressUpdated = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tquest: BgsQuestEntity,\r\n\tboard: BoardEntity[],\r\n\tgameState: FullGameState,\r\n) => {\r\n\tquest.ProgressCurrent++;\r\n\tif (quest.ProgressCurrent < quest.ProgressTotal) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst rewardCardId = gameState.allCards.getCard(quest.RewardDbfId).id;\r\n\tplayerEntity.questRewards.push(rewardCardId);\r\n\tplayerEntity.questRewardEntities.push({\r\n\t\tcardId: rewardCardId,\r\n\t\tentityId: gameState.sharedState.currentEntityId++,\r\n\t\tavengeDefault: gameState.cardsData.avengeValue(rewardCardId),\r\n\t\tavengeCurrent: gameState.cardsData.avengeValue(rewardCardId),\r\n\t\tscriptDataNum1: gameState.cardsData.defaultScriptDataNum(rewardCardId),\r\n\t});\r\n\r\n\t// Remove the quest from the list of quests\r\n\tplayerEntity.questEntities = playerEntity.questEntities.filter((quest) => quest.CardId !== quest.CardId);\r\n\r\n\tupdateStateAfterQuestCreated(rewardCardId, board, playerEntity, gameState);\r\n};\r\n\r\nconst updateStateAfterQuestCreated = (\r\n\trewardCardId: string,\r\n\tboard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tswitch (rewardCardId) {\r\n\t\tcase CardIds.TheSmokingGun:\r\n\t\t\tboard.forEach((e) => {\r\n\t\t\t\te.attack += 4;\r\n\t\t\t});\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tbreak;\r\n\t}\r\n};\r\n"]}
1
+ {"version":3,"file":"quest.js","sourceRoot":"","sources":["../../src/simulation/quest.ts"],"names":[],"mappings":";;;AAKO,MAAM,sBAAsB,GAAG,CACrC,YAA6B,EAC7B,KAAqB,EACrB,KAAoB,EACpB,SAAwB,EACvB,EAAE;IACH,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,aAAa,EAAE;QAChD,OAAO;KACP;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;IACtE,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7C,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC;QACrC,MAAM,EAAE,YAAY;QACpB,QAAQ,EAAE,SAAS,CAAC,WAAW,CAAC,eAAe,EAAE;QACjD,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC5D,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC5D,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,oBAAoB,CAAC,YAAY,CAAC;KACtE,CAAC,CAAC;IAGH,YAAY,CAAC,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC;IAEjG,4BAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC,CAAC;AAzBW,QAAA,sBAAsB,0BAyBjC;AAEF,MAAM,4BAA4B,GAAG,CACpC,YAAoB,EACpB,KAAoB,EACpB,YAA6B,EAC7B,SAAwB,EACvB,EAAE;IACH,QAAQ,YAAY,EAAE;QACrB;YACC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACnB,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;YACH,MAAM;QACP;YACC,MAAM;KACP;AACF,CAAC,CAAC","sourcesContent":["import { CardIds } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity, BgsQuestEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { FullGameState } from './internal-game-state';\r\n\r\nexport const onQuestProgressUpdated = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tquest: BgsQuestEntity,\r\n\tboard: BoardEntity[],\r\n\tgameState: FullGameState,\r\n) => {\r\n\tquest.ProgressCurrent++;\r\n\tif (quest.ProgressCurrent < quest.ProgressTotal) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst rewardCardId = gameState.allCards.getCard(quest.RewardDbfId).id;\r\n\tplayerEntity.questRewards.push(rewardCardId);\r\n\tplayerEntity.questRewardEntities.push({\r\n\t\tcardId: rewardCardId,\r\n\t\tentityId: gameState.sharedState.currentEntityId++,\r\n\t\tavengeDefault: gameState.cardsData.avengeValue(rewardCardId),\r\n\t\tavengeCurrent: gameState.cardsData.avengeValue(rewardCardId),\r\n\t\tscriptDataNum1: gameState.cardsData.defaultScriptDataNum(rewardCardId),\r\n\t});\r\n\r\n\t// Remove the quest from the list of quests\r\n\tplayerEntity.questEntities = playerEntity.questEntities.filter((q) => q.CardId !== quest.CardId);\r\n\r\n\tupdateStateAfterQuestCreated(rewardCardId, board, playerEntity, gameState);\r\n};\r\n\r\nconst updateStateAfterQuestCreated = (\r\n\trewardCardId: string,\r\n\tboard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tswitch (rewardCardId) {\r\n\t\tcase CardIds.TheSmokingGun:\r\n\t\t\tboard.forEach((e) => {\r\n\t\t\t\te.attack += 4;\r\n\t\t\t});\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tbreak;\r\n\t}\r\n};\r\n"]}
@@ -172,12 +172,12 @@ const handleStartOfCombatQuestRewards = (playerEntity, playerBoard, opponentEnti
172
172
  };
173
173
  const handleStartOfCombatSpells = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
174
174
  if (Math.random() < 0.5) {
175
- currentAttacker = handleStartOfCombatSpellsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
176
- currentAttacker = handleStartOfCombatSpellsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState);
175
+ currentAttacker = handleStartOfCombatSpellsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, true);
176
+ currentAttacker = handleStartOfCombatSpellsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState, false);
177
177
  }
178
178
  else {
179
- currentAttacker = handleStartOfCombatSpellsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState);
180
- currentAttacker = handleStartOfCombatSpellsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
179
+ currentAttacker = handleStartOfCombatSpellsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState, false);
180
+ currentAttacker = handleStartOfCombatSpellsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, true);
181
181
  }
182
182
  (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
183
183
  return currentAttacker;
@@ -189,10 +189,82 @@ const handleStartOfCombatAnomalies = (playerEntity, playerBoard, opponentEntity,
189
189
  return currentAttacker;
190
190
  };
191
191
  const handleStartOfCombatQuestRewardsForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, playerIsFriendly) => {
192
- var _a, _b;
193
192
  if (playerEntity.startOfCombatDone) {
194
193
  return currentAttacker;
195
194
  }
195
+ for (const reward of playerEntity.questRewards) {
196
+ switch (reward) {
197
+ case "BG24_Reward_111":
198
+ if (!!playerBoard.length && playerBoard.length < 7) {
199
+ const highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];
200
+ const copy = {
201
+ ...highestHealthMinion,
202
+ lastAffectedByEntity: null,
203
+ };
204
+ const newMinions = (0, deathrattle_spawns_1.spawnEntities)(copy.cardId, 1, playerBoard, playerEntity, opponentBoard, opponentEntity, gameState.allCards, gameState.cardsData, gameState.sharedState, gameState.spectator, highestHealthMinion.friendly, true, false, false, copy);
205
+ const indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);
206
+ (0, spawns_1.performEntitySpawns)(newMinions, playerBoard, playerEntity, highestHealthMinion, indexFromRight, opponentBoard, opponentEntity, gameState);
207
+ gameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);
208
+ currentAttacker =
209
+ playerBoard.length > opponentBoard.length
210
+ ? playerIsFriendly
211
+ ? 0
212
+ : 1
213
+ : opponentBoard.length > playerBoard.length
214
+ ? playerIsFriendly
215
+ ? 1
216
+ : 0
217
+ : Math.round(Math.random());
218
+ }
219
+ break;
220
+ case "BG24_Reward_312":
221
+ playerBoard.forEach((entity) => {
222
+ (0, stats_1.modifyStats)(entity, 15, 15, playerBoard, playerEntity, gameState);
223
+ gameState.spectator.registerPowerTarget(playerEntity, entity, playerBoard, null, null);
224
+ });
225
+ break;
226
+ case "BG24_Reward_109":
227
+ if (playerBoard.length > 0) {
228
+ (0, golden_1.makeMinionGolden)(playerBoard[0], playerEntity, playerBoard, playerEntity, opponentEntity, gameState);
229
+ }
230
+ if (playerBoard.length > 1) {
231
+ (0, golden_1.makeMinionGolden)(playerBoard[playerBoard.length - 1], playerEntity, playerBoard, playerEntity, opponentEntity, gameState);
232
+ }
233
+ break;
234
+ }
235
+ }
236
+ return currentAttacker;
237
+ };
238
+ const handleStartOfCombatSpellsForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, playerIsFriendly) => {
239
+ var _a, _b, _c;
240
+ if (playerEntity.startOfCombatDone) {
241
+ return currentAttacker;
242
+ }
243
+ for (const secret of (_a = playerEntity.secrets) !== null && _a !== void 0 ? _a : []) {
244
+ switch (secret.cardId) {
245
+ case "BG28_573":
246
+ if (!!opponentBoard.length) {
247
+ const target = (0, utils_1.pickRandom)(opponentBoard);
248
+ target.health = 1;
249
+ target.maxHealth = 1;
250
+ gameState.spectator.registerPowerTarget(playerEntity, target, opponentBoard, null, null);
251
+ }
252
+ break;
253
+ case "BG28_603":
254
+ secret.scriptDataNum1 = 1;
255
+ break;
256
+ case "BG28_519":
257
+ (0, utils_2.addStatsToBoard)(secret, playerBoard, playerEntity, 2, 1, gameState);
258
+ break;
259
+ case "BG28_641":
260
+ if (playerBoard.length < 7) {
261
+ const newMinions = (0, deathrattle_spawns_1.spawnEntities)("BG28_641t", 1, playerBoard, playerEntity, opponentBoard, opponentEntity, gameState.allCards, gameState.cardsData, gameState.sharedState, gameState.spectator, playerEntity.friendly, true, false, false);
262
+ newMinions[0].attackImmediately = true;
263
+ (0, spawns_1.performEntitySpawns)(newMinions, playerBoard, playerEntity, null, 0, opponentBoard, opponentEntity, gameState);
264
+ }
265
+ break;
266
+ }
267
+ }
196
268
  for (const trinket of playerEntity.trinkets) {
197
269
  switch (trinket.cardId) {
198
270
  case "BG30_MagicItem_902":
@@ -305,7 +377,7 @@ const handleStartOfCombatQuestRewardsForPlayer = (playerEntity, playerBoard, opp
305
377
  case "BG30_MagicItem_989t":
306
378
  const artisanalUrnBuff = trinket.cardId === "BG30_MagicItem_989" ? 3 : 7;
307
379
  playerEntity.globalInfo.UndeadAttackBonus =
308
- ((_a = playerEntity.globalInfo.UndeadAttackBonus) !== null && _a !== void 0 ? _a : 0) + artisanalUrnBuff;
380
+ ((_b = playerEntity.globalInfo.UndeadAttackBonus) !== null && _b !== void 0 ? _b : 0) + artisanalUrnBuff;
309
381
  break;
310
382
  case "BG30_MagicItem_310":
311
383
  playerBoard
@@ -314,7 +386,7 @@ const handleStartOfCombatQuestRewardsForPlayer = (playerEntity, playerBoard, opp
314
386
  .forEach((e) => (e.stealth = true));
315
387
  break;
316
388
  case "BG30_MagicItem_441":
317
- const highestHealthMinionInHand = (_b = playerEntity.hand) === null || _b === void 0 ? void 0 : _b.sort((a, b) => b.health - a.health)[0];
389
+ const highestHealthMinionInHand = (_c = playerEntity.hand) === null || _c === void 0 ? void 0 : _c.sort((a, b) => b.health - a.health)[0];
318
390
  if (highestHealthMinionInHand && playerBoard.length > 0) {
319
391
  (0, stats_1.modifyStats)(playerBoard[0], highestHealthMinionInHand.attack, highestHealthMinionInHand.health, playerBoard, playerEntity, gameState);
320
392
  }
@@ -382,82 +454,6 @@ const handleStartOfCombatQuestRewardsForPlayer = (playerEntity, playerBoard, opp
382
454
  break;
383
455
  }
384
456
  }
385
- for (const reward of playerEntity.questRewards) {
386
- switch (reward) {
387
- case "BG24_Reward_111":
388
- if (!!playerBoard.length && playerBoard.length < 7) {
389
- const highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];
390
- const copy = {
391
- ...highestHealthMinion,
392
- lastAffectedByEntity: null,
393
- };
394
- const newMinions = (0, deathrattle_spawns_1.spawnEntities)(copy.cardId, 1, playerBoard, playerEntity, opponentBoard, opponentEntity, gameState.allCards, gameState.cardsData, gameState.sharedState, gameState.spectator, highestHealthMinion.friendly, true, false, false, copy);
395
- const indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);
396
- (0, spawns_1.performEntitySpawns)(newMinions, playerBoard, playerEntity, highestHealthMinion, indexFromRight, opponentBoard, opponentEntity, gameState);
397
- gameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);
398
- currentAttacker =
399
- playerBoard.length > opponentBoard.length
400
- ? playerIsFriendly
401
- ? 0
402
- : 1
403
- : opponentBoard.length > playerBoard.length
404
- ? playerIsFriendly
405
- ? 1
406
- : 0
407
- : Math.round(Math.random());
408
- }
409
- break;
410
- case "BG24_Reward_312":
411
- playerBoard.forEach((entity) => {
412
- (0, stats_1.modifyStats)(entity, 15, 15, playerBoard, playerEntity, gameState);
413
- gameState.spectator.registerPowerTarget(playerEntity, entity, playerBoard, null, null);
414
- });
415
- break;
416
- case "BG24_Reward_109":
417
- if (playerBoard.length > 0) {
418
- (0, golden_1.makeMinionGolden)(playerBoard[0], playerEntity, playerBoard, playerEntity, opponentEntity, gameState);
419
- }
420
- if (playerBoard.length > 1) {
421
- (0, golden_1.makeMinionGolden)(playerBoard[playerBoard.length - 1], playerEntity, playerBoard, playerEntity, opponentEntity, gameState);
422
- }
423
- break;
424
- }
425
- }
426
- return currentAttacker;
427
- };
428
- const handleStartOfCombatSpellsForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
429
- var _a;
430
- if (playerEntity.startOfCombatDone) {
431
- return currentAttacker;
432
- }
433
- if (!((_a = playerEntity.secrets) === null || _a === void 0 ? void 0 : _a.length)) {
434
- return currentAttacker;
435
- }
436
- for (const secret of playerEntity.secrets) {
437
- switch (secret.cardId) {
438
- case "BG28_573":
439
- if (!!opponentBoard.length) {
440
- const target = (0, utils_1.pickRandom)(opponentBoard);
441
- target.health = 1;
442
- target.maxHealth = 1;
443
- gameState.spectator.registerPowerTarget(playerEntity, target, opponentBoard, null, null);
444
- }
445
- break;
446
- case "BG28_603":
447
- secret.scriptDataNum1 = 1;
448
- break;
449
- case "BG28_519":
450
- (0, utils_2.addStatsToBoard)(secret, playerBoard, playerEntity, 2, 1, gameState);
451
- break;
452
- case "BG28_641":
453
- if (playerBoard.length < 7) {
454
- const newMinions = (0, deathrattle_spawns_1.spawnEntities)("BG28_641t", 1, playerBoard, playerEntity, opponentBoard, opponentEntity, gameState.allCards, gameState.cardsData, gameState.sharedState, gameState.spectator, playerEntity.friendly, true, false, false);
455
- newMinions[0].attackImmediately = true;
456
- (0, spawns_1.performEntitySpawns)(newMinions, playerBoard, playerEntity, null, 0, opponentBoard, opponentEntity, gameState);
457
- }
458
- break;
459
- }
460
- }
461
457
  return currentAttacker;
462
458
  };
463
459
  const handleStartOfCombatAnomaliesForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
@@ -843,7 +839,7 @@ const performStartOfCombatMinionsForPlayer = (attacker, attackingBoard, attackin
843
839
  for (let i = 0; i < numberOfPicks; i++) {
844
840
  const target = (0, utils_1.pickRandom)(validTargets);
845
841
  if (!!target) {
846
- castImpure(attacker, target, attackingBoard, gameState.spectator);
842
+ castImpure(target, attacker, attackingBoard, gameState.spectator);
847
843
  const targetIndex = validTargets.findIndex((e) => e.entityId === target.entityId);
848
844
  validTargets.splice(targetIndex, 1);
849
845
  }
@@ -1 +1 @@
1
- {"version":3,"file":"start-of-combat.js","sourceRoot":"","sources":["../../src/simulation/start-of-combat.ts"],"names":[],"mappings":";;;AACA,iEAAsG;AAGtG,oDAA0F;AAC1F,6CAAqF;AACrF,oCAUkB;AAClB,+DAA4D;AAC5D,qCAQkB;AAClB,mDAAiD;AACjD,+DAM+B;AAC/B,2EAAiE;AACjE,6DAAqD;AAErD,qCAA+C;AA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CAAC,CAAC;KAClF;AACF,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,MAAmB,EAAE,KAAoB,EAAE,SAAoB,EAAE,EAAE;;IAC3G,IAAI,CAAC,MAAM,EAAE;QACZ,OAAO;KACP;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,iBAA6C,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,gBAAgB,GAAG,MAAA,MAAM,CAAC,gBAAgB,mCAAI,CAAC,CAAC;IACvD,MAAM,CAAC,gBAAgB,IAAI,UAAU,CAAC;IACtC,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,MAAmB,EAA6C,EAAE;IACvG,MAAM,aAAa,GAAkD,CAAC,OAAO,CAAC,CAAC;IAC/E,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QACnB,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC/B;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;QAClB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC5B;IACD,OAAO,IAAA,kBAAU,EAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, CardType, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { grantDivineShieldToLeftmostMinions, updateDivineShield } from '../divine-shield';\r\nimport { pickRandom, pickRandomLowestHealth, shuffleArray } from '../services/utils';\r\nimport {\r\n\taddImpliedMechanics,\r\n\taddStatsToBoard,\r\n\tcopyEntity,\r\n\tgetEffectiveTribesForEntity,\r\n\tgetMinionsOfDifferentTypes,\r\n\tgetRandomMinionWithHighestHealth,\r\n\tgetTeammateInitialState,\r\n\thasCorrectTribe,\r\n\tisGolden,\r\n} from '../utils';\r\nimport { removeAurasFromSelf } from './add-minion-to-board';\r\nimport {\r\n\tdealDamageToMinion,\r\n\tdealDamageToRandomEnemy,\r\n\tdoFullAttack,\r\n\tfindNearestEnemies,\r\n\tgetNeighbours,\r\n\tprocessMinionDeath,\r\n\tsimulateAttack,\r\n} from './attack';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport {\r\n\tapplyEarthInvocationEnchantment,\r\n\tapplyFireInvocationEnchantment,\r\n\tapplyLightningInvocationEnchantment,\r\n\tapplyWaterInvocationEnchantment,\r\n\trememberDeathrattles,\r\n} from './deathrattle-effects';\r\nimport { handleDeathrattles } from './deathrattle-orchestration';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { applyAfterStatsUpdate, modifyStats, setEntityStats } from './stats';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\nimport { makeMinionGolden } from './utils/golden';\r\n\r\n// TODO 20/04/2024: I'm not too sure about some ordering. The way I understand it, the Start of Combat has\r\n// multiple phases, and in each phase the player order is random\r\n// However, looking at http://replays.firestoneapp.com/?reviewId=a577602e-06f3-4c4b-928d-36ea98c2e6d5&turn=5&action=0,\r\n// it feels that a \"start of combat\" minion effect could trigger before an opponent's hero power effect\r\n// Or is that limited to Bru'kan?\r\n// I feel that I've asked a lot of questions recently, so I don't want to add that one to the list, as the interaction\r\n// is for now pretty marginal\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\tgameState: FullGameState,\r\n): number => {\r\n\tconst shouldRecomputeCurrentAttacker = true;\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? 0\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? 1\r\n\t\t\t\t: Math.round(Math.random());\r\n\t}\r\n\r\n\t// https://twitter.com/DCalkosz/status/1564705111850434561\r\n\tcurrentAttacker = handleStartOfCombatQuestRewards(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatAnomalies(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\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\t// Update: this seems to have changed: https://x.com/LoewenMitchell/status/1737588920139825335?s=20\r\n\t// now you have all hero powers trigger in a first phase, then you have Illidan, and once everything has triggered, you have Tavish\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\tgameState,\r\n\t);\r\n\t// Because start of combat powers like Red Whelp's use the board composition before Illidan's strike to know the amount of damage\r\n\tconst playerBoardBefore = playerBoard.map((e) => ({ ...e }));\r\n\tconst opponentBoardBefore = opponentBoard.map((e) => ({ ...e }));\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\tgameState,\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\tgameState,\r\n\t);\r\n\t// Timing confirmed by Mitchell on Discord on 2024-02-21\r\n\tcurrentAttacker = handleStartOfCombatSpells(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\t// Not sure if this can change who the first player will be\r\n\t// I don't have any official source on it at the moment, but there are some simulation\r\n\thandleStartOfCombatMinions(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tplayerBoardBefore,\r\n\t\topponentBoardBefore,\r\n\t\tgameState,\r\n\t);\r\n\tplayerEntity.startOfCombatDone = true;\r\n\topponentEntity.startOfCombatDone = true;\r\n\tapplyAfterStatsUpdate(gameState);\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePreCombatHeroPowersForPlayer = (\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone || playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\r\n\tlet shouldRecomputeCurrentAttacker = false;\r\n\t// Some are part of the incoming board: Y'Shaarj, Lich King, Ozumat\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.SwattingInsects && 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, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EarthInvocationToken) {\r\n\t\tapplyEarthInvocationEnchantment(playerBoard, null, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaterInvocationToken) {\r\n\t\tapplyWaterInvocationEnchantment(playerBoard, playerEntity, null, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.FireInvocationToken) {\r\n\t\tapplyFireInvocationEnchantment(playerBoard, playerEntity, null, playerEntity, gameState);\r\n\t} else if (playerHeroPowerId === CardIds.AllWillBurn) {\r\n\t\tapplyAllWillBurn(playerBoard, playerEntity, opponentBoard, opponentEntity, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TamsinRoame_FragrantPhylactery) {\r\n\t\thandleTamsinForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\t// Tamsin's hero power somehow happens before the current attacker is chosen.\r\n\t\t// See http://replays.firestoneapp.com/?reviewId=bce94e6b-c807-48e4-9c72-2c5c04421213&turn=6&action=9\r\n\t\t// Even worse: if a scallywag token pops, it attacks before the first attacker is recomputed\r\n\t\tshouldRecomputeCurrentAttacker = true;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EmbraceYourRage) {\r\n\t\thandleEmbraceYourRageForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\tshouldRecomputeCurrentAttacker = true;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.RebornRites) {\r\n\t\thandleRebornRitesForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TeronGorefiend_RapidReanimation) {\r\n\t\tshouldRecomputeCurrentAttacker = handleTeronForPlayer(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// Same as Tamsin? No, because the new minion should repop automatically\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaxWarband) {\r\n\t\thandleWaxWarbandForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.LightningInvocationToken) {\r\n\t\tapplyLightningInvocationEnchantment(playerBoard, playerEntity, null, opponentBoard, opponentEntity, gameState);\r\n\t} else if (\r\n\t\tplayerEntity.heroPowerUsed &&\r\n\t\tplayerHeroPowerId === CardIds.FlobbidinousFloop_GloriousGloop_BGDUO_HERO_101p\r\n\t) {\r\n\t\tapplyGloriousGloop(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t}\r\n\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: 1\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0\r\n\t\t\t\t: Math.round(Math.random());\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\tgameState: FullGameState,\r\n): number => {\r\n\t// console.log('current attacker before', currentAttacker);\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\tgameState,\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\tgameState,\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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t}\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\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\tplayerBoardBefore: BoardEntity[],\r\n\topponentBoardBefore: BoardEntity[],\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tlet attackerForStart = Math.random() < 0.5 ? 0 : 1;\r\n\tconst playerAttackers = [...playerBoard];\r\n\tconst opponentAttackers = [...opponentBoard];\r\n\r\n\twhile (playerAttackers.length > 0 || opponentAttackers.length > 0) {\r\n\t\tlet shouldUpdateNextPlayer = false;\r\n\t\tif (attackerForStart === 0 && playerAttackers.length > 0) {\r\n\t\t\tconst attacker = playerAttackers.splice(0, 1)[0];\r\n\t\t\tif (attacker.health <= 0 || attacker.definitelyDead) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tshouldUpdateNextPlayer = performStartOfCombatMinionsForPlayer(\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\tplayerBoardBefore,\r\n\t\t\t\topponentBoardBefore,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 0 && playerAttackers.length === 0) {\r\n\t\t\tshouldUpdateNextPlayer = true;\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\tif (attacker.health <= 0 || attacker.definitelyDead) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tshouldUpdateNextPlayer = performStartOfCombatMinionsForPlayer(\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\topponentBoardBefore,\r\n\t\t\t\tplayerBoardBefore,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 1 && opponentAttackers.length === 0) {\r\n\t\t\tshouldUpdateNextPlayer = true;\r\n\t\t}\r\n\r\n\t\tif (shouldUpdateNextPlayer) {\r\n\t\t\tattackerForStart = (attackerForStart + 1) % 2;\r\n\t\t}\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatQuestRewards = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t}\r\n\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatSpells = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatAnomalies = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tcurrentAttacker = handleStartOfCombatAnomaliesForPlayer(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatAnomaliesForPlayer(\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatQuestRewardsForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n\tplayerIsFriendly: boolean,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\r\n\tfor (const trinket of playerEntity.trinkets) {\r\n\t\tswitch (trinket.cardId) {\r\n\t\t\tcase CardIds.HolyMallet_BG30_MagicItem_902:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tupdateDivineShield(playerBoard[0], playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, playerBoard[0], playerBoard, null, null);\r\n\t\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\t\tupdateDivineShield(\r\n\t\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t);\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.TrainingCertificate_BG30_MagicItem_962:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tconst minionsByAttack = [...playerBoard].sort((a, b) => a.attack - b.attack);\r\n\t\t\t\t\tconst firstTarget = minionsByAttack[0];\r\n\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\tfirstTarget,\r\n\t\t\t\t\t\t2 * firstTarget.maxAttack,\r\n\t\t\t\t\t\t2 * firstTarget.maxHealth,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\t\tconst secondTarget = minionsByAttack[1];\r\n\t\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\t\tsecondTarget,\r\n\t\t\t\t\t\t\t2 * secondTarget.maxAttack,\r\n\t\t\t\t\t\t\t2 * secondTarget.maxHealth,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\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.ValorousMedallion_BG30_MagicItem_970:\r\n\t\t\tcase CardIds.ValorousMedallion_ValorousMedallionToken_BG30_MagicItem_970t:\r\n\t\t\t\tconst medallionBuff = trinket.cardId === CardIds.ValorousMedallion_BG30_MagicItem_970 ? 2 : 5;\r\n\t\t\t\taddStatsToBoard(trinket, playerBoard, playerEntity, medallionBuff, medallionBuff, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EmeraldDreamcatcher_BG30_MagicItem_542:\r\n\t\t\t\tconst highestAttack = Math.max(...playerBoard.map((entity) => entity.attack));\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.DRAGON, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\tsetEntityStats(e, highestAttack, null, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.JarredFrostling_BG30_MagicItem_952:\r\n\t\t\t\tconst elementals = shuffleArray(\r\n\t\t\t\t\tplayerBoard.filter((e) => hasCorrectTribe(e, playerEntity, Race.ELEMENTAL, gameState.allCards)),\r\n\t\t\t\t);\r\n\t\t\t\tconst targets = elementals.slice(0, 2);\r\n\t\t\t\ttargets.forEach((e) => {\r\n\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\tcardId: CardIds.JarredFrostling_FrostyGlobeEnchantment_BG30_MagicItem_952e,\r\n\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, e, playerBoard, null, null);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RustyTrident_BG30_MagicItem_917:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.NAGA, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\t\tcardId: CardIds.RustyTrident_TridentsTreasureEnchantment_BG30_MagicItem_917e,\r\n\t\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HoggyBank_BG30_MagicItem_411:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.QUILBOAR, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\t\tcardId: CardIds.HoggyBank_GemInTheBankEnchantment_BG30_MagicItem_411e,\r\n\t\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.AutomatonPortrait_BG30_MagicItem_303:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tCardIds.AstralAutomaton_BG_TTN_401,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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.ShipInABottle_BG30_MagicItem_407:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst target = pickRandom(gameState.cardsData.pirateSpawns);\r\n\t\t\t\t\taddCardsInHand(playerEntity, playerBoard, [target], gameState);\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tspawns.forEach((spawn) => (spawn.attackImmediately = true));\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EternalPortrait_BG30_MagicItem_301:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.EternalKnight_BG25_008 ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((knight) => {\r\n\t\t\t\t\t\tknight.taunt = true;\r\n\t\t\t\t\t\tknight.reborn = true;\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, knight, playerBoard, null, null);\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TwinSkyLanterns_BG30_MagicItem_822:\r\n\t\t\tcase CardIds.TwinSkyLanterns_TwinSkyLanternsToken_BG30_MagicItem_822t2:\r\n\t\t\t\ttrinket.rememberedMinion = null;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.ArtisanalUrn_BG30_MagicItem_989:\r\n\t\t\tcase CardIds.ArtisanalUrn_ArtisanalUrnToken_BG30_MagicItem_989t:\r\n\t\t\t\tconst artisanalUrnBuff = trinket.cardId === CardIds.ArtisanalUrn_BG30_MagicItem_989 ? 3 : 7;\r\n\t\t\t\tplayerEntity.globalInfo.UndeadAttackBonus =\r\n\t\t\t\t\t(playerEntity.globalInfo.UndeadAttackBonus ?? 0) + artisanalUrnBuff;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RivendarePortrait_BG30_MagicItem_310:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.TitusRivendare_BG25_354 ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.TitusRivendare_BG25_354_G,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((e) => (e.stealth = true));\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TinyfinOnesie_BG30_MagicItem_441:\r\n\t\t\t\tconst highestHealthMinionInHand = playerEntity.hand?.sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\tif (highestHealthMinionInHand && playerBoard.length > 0) {\r\n\t\t\t\t\tmodifyStats(\r\n\t\t\t\t\t\tplayerBoard[0],\r\n\t\t\t\t\t\thighestHealthMinionInHand.attack,\r\n\t\t\t\t\t\thighestHealthMinionInHand.health,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tgameState,\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.BronzeTimepiece_BG30_MagicItem_995:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tplayerBoard.forEach((entity) => {\r\n\t\t\t\t\t\tconst highest = Math.max(entity.attack, entity.health);\r\n\t\t\t\t\t\tsetEntityStats(entity, highest, highest, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(trinket, entity, playerBoard, null, null);\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.IronforgeAnvil_BG30_MagicItem_403:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tplayerBoard\r\n\t\t\t\t\t\t.filter((e) => getEffectiveTribesForEntity(e, playerEntity, gameState.allCards).length === 0)\r\n\t\t\t\t\t\t.forEach((entity) => {\r\n\t\t\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\t\t\tentity,\r\n\t\t\t\t\t\t\t\t3 * entity.attack,\r\n\t\t\t\t\t\t\t\t3 * entity.health,\r\n\t\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tgameState.spectator.registerPowerTarget(trinket, entity, playerBoard, null, null);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.KarazhanChessSet_BG30_MagicItem_972:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tfor (let i = 0; i < Math.min(playerBoard.length, 7); i++) {\r\n\t\t\t\t\t\tconst entityToCoy = playerBoard[i];\r\n\t\t\t\t\t\tconst copy: BoardEntity = copyEntity(entityToCoy);\r\n\t\t\t\t\t\tremoveAurasFromSelf(copy, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t\t1,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerBoard.length - i - 1,\r\n\t\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\t// TODO: according to http://replays.firestoneapp.com/?reviewId=576aa3bb-caa1-4e46-9d16-08a001fdd941&turn=23&action=3\r\n\t\t\t\t\t\t// it looks like the stats are simply copied from the original entity to the copy, instead\r\n\t\t\t\t\t\t// of summoning a copy and applying all the auras stuff\r\n\t\t\t\t\t\t// I've asked on Discord (2024-08-21) for clarification\r\n\t\t\t\t\t\ti += spawns.length;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FishySticker_BG30_MagicItem_821:\r\n\t\t\tcase CardIds.FishySticker_FishyStickerToken_BG30_MagicItem_821t2:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst spawnId =\r\n\t\t\t\t\t\ttrinket.cardId === CardIds.FishySticker_BG30_MagicItem_821\r\n\t\t\t\t\t\t\t? CardIds.AvatarOfNzoth_FishOfNzothToken\r\n\t\t\t\t\t\t\t: CardIds.FishOfNzoth;\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tspawnId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const reward of playerEntity.questRewards) {\r\n\t\tswitch (reward) {\r\n\t\t\tcase CardIds.EvilTwin:\r\n\t\t\t\tif (!!playerBoard.length && playerBoard.length < 7) {\r\n\t\t\t\t\tconst highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t\t...highestHealthMinion,\r\n\t\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\thighestHealthMinion.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\thighestHealthMinion,\r\n\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);\r\n\t\t\t\t\t// Recompute first attacker\r\n\t\t\t\t\t// See https://replays.firestoneapp.com/?reviewId=93229c4a-d864-4196-83dd-2fea2a5bf70a&turn=29&action=0\r\n\t\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.StaffOfOrigination_BG24_Reward_312:\r\n\t\t\t\tplayerBoard.forEach((entity) => {\r\n\t\t\t\t\tmodifyStats(entity, 15, 15, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, entity, playerBoard, null, null);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.StolenGold:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tmakeMinionGolden(\r\n\t\t\t\t\t\tplayerBoard[0],\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\tmakeMinionGolden(\r\n\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatSpellsForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tif (!playerEntity.secrets?.length) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tfor (const secret of playerEntity.secrets) {\r\n\t\tswitch (secret.cardId) {\r\n\t\t\tcase CardIds.UpperHand_BG28_573:\r\n\t\t\t\tif (!!opponentBoard.length) {\r\n\t\t\t\t\tconst target = pickRandom(opponentBoard);\r\n\t\t\t\t\ttarget.health = 1;\r\n\t\t\t\t\ttarget.maxHealth = 1;\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, target, opponentBoard, null, null);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BoonOfBeetles_BG28_603:\r\n\t\t\t\tsecret.scriptDataNum1 = 1;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FleetingVigor_BG28_519:\r\n\t\t\t\taddStatsToBoard(secret, playerBoard, playerEntity, 2, 1, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.ToxicTumbleweed_BG28_641:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tCardIds.ToxicTumbleweed_TumblingAssassinToken_BG28_641t,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tnewMinions[0].attackImmediately = true;\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatAnomaliesForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (!gameState.anomalies?.length || playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tfor (const anomaly of gameState.anomalies) {\r\n\t\tswitch (anomaly) {\r\n\t\t\tcase CardIds.BlessedOrBlighted_BG27_Anomaly_726:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tconst dsTarget = playerBoard[0];\r\n\t\t\t\t\tupdateDivineShield(dsTarget, playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t\t\t\t\tconst rebornTarget = playerBoard[playerBoard.length - 1];\r\n\t\t\t\t\trebornTarget.reborn = true;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.AnomalousTwin_BG27_Anomaly_560:\r\n\t\t\t\tif (!!playerBoard.length && playerBoard.length < 7) {\r\n\t\t\t\t\tconst highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t\t...highestHealthMinion,\r\n\t\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\thighestHealthMinion.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\thighestHealthMinion,\r\n\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);\r\n\t\t\t\t}\r\n\t\t\t\t// Recompute first attacker\r\n\t\t\t\t// See https://replays.firestoneapp.com/?reviewId=93229c4a-d864-4196-83dd-2fea2a5bf70a&turn=29&action=0\r\n\t\t\t\treturn playerBoard.length > opponentBoard.length\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: Math.round(Math.random());\r\n\t\t}\r\n\t}\r\n\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\tgameState: FullGameState,\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 = 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\tgameState,\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\tgameState,\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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.Wingmen && playerBoard.length > 0) {\r\n\t\t// After Illidan triggers, it's always the other opponent's turn\r\n\t\t// https://x.com/LoewenMitchell/status/1752714583360639131?s=20\r\n\t\thandleIllidanForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState, currentAttacker);\r\n\t\tcurrentAttacker = friendly ? 1 : 0;\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\tgameState: FullGameState,\r\n\tcurrentAttacker: number,\r\n): void => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn;\r\n\t}\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\tconst firstAttacker = playerBoard[0];\r\n\tconst secondAttacker = minionsAtStart > 1 ? playerBoard[playerBoard.length - 1] : null;\r\n\r\n\t// Stats updates\r\n\tmodifyStats(firstAttacker, 2, 1, playerBoard, playerEntity, gameState);\r\n\tgameState.spectator.registerPowerTarget(firstAttacker, firstAttacker, playerBoard, playerEntity, opponentEntity);\r\n\tif (!!secondAttacker && !secondAttacker.definitelyDead && secondAttacker.health > 0) {\r\n\t\tmodifyStats(secondAttacker, 2, 1, playerBoard, playerEntity, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tsecondAttacker,\r\n\t\t\tsecondAttacker,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentEntity,\r\n\t\t);\r\n\t}\r\n\r\n\t// Attacks\r\n\tfirstAttacker.attackImmediately = true;\r\n\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t// See http://replays.firestoneapp.com/?reviewId=f16b7a49-c2a2-4ac5-a9eb-a75f83246f70&turn=6&action=8\r\n\tfirstAttacker.hasAttacked = 0;\r\n\tif (!!secondAttacker && !secondAttacker.definitelyDead && secondAttacker.health > 0) {\r\n\t\tsecondAttacker.attackImmediately = true;\r\n\t\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\tsecondAttacker.hasAttacked = 0;\r\n\t}\r\n\r\n\t// // See http://replays.firestoneapp.com/?reviewId=7e9ec42c-a8f6-43d2-9f39-cc486dfa2395&turn=6&action=5\r\n\t// if (firstAttacker.definitelyDead || firstAttacker.health <= 0) {\r\n\t// \tcurrentAttacker = (currentAttacker + 1) % 2;\r\n\t// }\r\n\t// return currentAttacker;\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\tgameState: FullGameState,\r\n): void => {\r\n\tconst firstEntity = playerBoard[0];\r\n\tfirstEntity.windfury = true;\r\n\tif (!firstEntity.divineShield) {\r\n\t\tupdateDivineShield(firstEntity, playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t}\r\n\tfirstEntity.taunt = true;\r\n\tgameState.spectator.registerPowerTarget(firstEntity, firstEntity, playerBoard, playerEntity, opponentEntity);\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\tgameState: FullGameState,\r\n): void => {\r\n\tconst chosenEntity = pickRandomLowestHealth(playerBoard);\r\n\tif (!chosenEntity) {\r\n\t\tconsole.warn('could not pick any entity for tamsin');\r\n\t\treturn;\r\n\t}\r\n\tgameState.spectator.registerPowerTarget(playerEntity, chosenEntity, playerBoard, null, null);\r\n\tconst newBoard = playerBoard.filter((e) => e.entityId !== chosenEntity.entityId);\r\n\t// How to mark the minion as dead\r\n\tchosenEntity.definitelyDead = true;\r\n\tnewBoard.forEach((e) => {\r\n\t\tmodifyStats(e, chosenEntity.attack, chosenEntity.health, newBoard, playerEntity, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(chosenEntity, e, newBoard, playerEntity, opponentEntity);\r\n\t});\r\n};\r\n\r\nconst applyGloriousGloop = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (!playerBoard?.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst target = playerBoard.find((m) =>\r\n\t\tm.enchantments?.some((e) => e.cardId === CardIds.GloriousGloop_InTheGloopEnchantment_BGDUO_HERO_101pe2),\r\n\t);\r\n\tif (!target) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst teammateState = getTeammateInitialState(gameState.gameState, playerEntity);\r\n\tif (!teammateState?.board?.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst highestTier = Math.max(\r\n\t\t...teammateState.board.map((entity) => gameState.allCards.getCard(entity.cardId).techLevel),\r\n\t);\r\n\tconst candidates = teammateState.board.filter(\r\n\t\t(entity) => gameState.allCards.getCard(entity.cardId).techLevel === highestTier,\r\n\t);\r\n\tif (!candidates.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst highestTierMinion = pickRandom(candidates);\r\n\tconst clone: BoardEntity = addImpliedMechanics(\r\n\t\t{\r\n\t\t\t...highestTierMinion,\r\n\t\t\tlastAffectedByEntity: null,\r\n\t\t\tdefinitelyDead: false,\r\n\t\t\tattackImmediately: false,\r\n\t\t},\r\n\t\tgameState.cardsData,\r\n\t);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, target, playerBoard, playerEntity, opponentEntity);\r\n\t// Replace the \"target\" minion with the \"clone\"\r\n\tconst index = playerBoard.indexOf(target);\r\n\tplayerBoard.splice(index, 1, clone);\r\n};\r\n\r\nconst handleEmbraceYourRageForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst createdCardId = playerEntity.heroPowerInfo as string;\r\n\tif (!createdCardId?.length) {\r\n\t\t// console.warn('no card id for embrace your rage');\r\n\t\treturn;\r\n\t}\r\n\tconst spawns = spawnEntities(\r\n\t\tcreatedCardId,\r\n\t\t1,\r\n\t\tplayerBoard,\r\n\t\tplayerEntity,\r\n\t\topponentBoard,\r\n\t\topponentEntity,\r\n\t\tgameState.allCards,\r\n\t\tgameState.cardsData,\r\n\t\tgameState.sharedState,\r\n\t\tgameState.spectator,\r\n\t\tplayerEntity.friendly,\r\n\t\ttrue,\r\n\t\tfalse,\r\n\t\tfalse,\r\n\t);\r\n\tconst indexFromRight = 0;\r\n\tperformEntitySpawns(\r\n\t\tspawns,\r\n\t\tplayerBoard,\r\n\t\tplayerEntity,\r\n\t\tplayerEntity,\r\n\t\tindexFromRight,\r\n\t\topponentBoard,\r\n\t\topponentEntity,\r\n\t\tgameState,\r\n\t);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, spawns[0], playerBoard, playerEntity, opponentEntity);\r\n\taddCardsInHand(playerEntity, playerBoard, spawns, gameState);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, spawns[0], playerBoard, playerEntity, opponentEntity);\r\n};\r\n\r\nconst handleRebornRitesForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst targetEntityId = playerEntity.heroPowerInfo as number;\r\n\tconst target = playerBoard.find((entity) => entity.entityId === targetEntityId);\r\n\tif (!target) {\r\n\t\treturn;\r\n\t}\r\n\r\n\ttarget.reborn = true;\r\n\tgameState.spectator.registerPowerTarget(playerEntity, target, playerBoard, playerEntity, opponentEntity);\r\n};\r\n\r\nconst handleTeronForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): boolean => {\r\n\t// Getting the right enchantment can be tricky. The RapidReanimation enchantment can sometimes be\r\n\t// in the Graveyard zone, so we can't filter them out. In that case, we can have multiple\r\n\t// enchantments\r\n\t// However, because of how things are handled in the logs, we should be able to always take the one *\r\n\t// with the biggest entityId\r\n\tconst minionThatWillDie = playerBoard\r\n\t\t.filter((m) => m.enchantments.some((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment))\r\n\t\t.sort(\r\n\t\t\t(a, b) =>\r\n\t\t\t\tb.enchantments.find((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment)\r\n\t\t\t\t\t.originEntityId -\r\n\t\t\t\t\ta.enchantments.find((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment)\r\n\t\t\t\t\t\t.originEntityId || b.entityId - a.entityId,\r\n\t\t)[0];\r\n\tif (minionThatWillDie) {\r\n\t\t// So this is a bit tricky (as all the stuff with indices...). Because in practice it's more likely that players use Rapid Reanimation\r\n\t\t// on minions that they want to die quickly, most of the time they will be placed\r\n\t\t// to the left of the board\r\n\t\t// So using a left-based index (usually 0) is more likely to be correct after minions spawn on the board\r\n\t\t// Update: this looks like it's not the case, and looking at\r\n\t\t// http://replays.firestoneapp.com/?reviewId=2e6b389f-d904-43a2-a7cd-928a60d973ce&turn=11&action=1\r\n\t\t// the index seems to be right-based at least in some cases\r\n\t\t// Looks like even this is wrong:\r\n\t\t// http://replays.firestoneapp.com/?reviewId=9a46ab39-ccf0-478c-a010-68f2abb06c6f&turn=9&action=0\r\n\t\tconst rapidReanimationIndexFromLeft = playerBoard.indexOf(minionThatWillDie);\r\n\t\tplayerEntity.rapidReanimationIndexFromRight = playerBoard.length - 1 - rapidReanimationIndexFromLeft;\r\n\t\tconst minionToCopy = {\r\n\t\t\t...minionThatWillDie,\r\n\t\t\tenchantments: minionThatWillDie.enchantments.map((e) => ({ ...e })) ?? [],\r\n\t\t\tpendingAttackBuffs: [],\r\n\t\t} as BoardEntity;\r\n\t\tremoveAurasFromSelf(minionToCopy, playerBoard, playerEntity, gameState);\r\n\t\tplayerEntity.rapidReanimationMinion = minionToCopy;\r\n\t\tminionThatWillDie.definitelyDead = true;\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tplayerEntity,\r\n\t\t\tminionThatWillDie,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentEntity,\r\n\t\t);\r\n\t\treturn true;\r\n\t}\r\n\treturn false;\r\n};\r\n\r\nconst handleWaxWarbandForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (playerBoard.length > 0) {\r\n\t\tconst boardWithTribes = playerBoard.filter(\r\n\t\t\t(e) => !!getEffectiveTribesForEntity(e, playerEntity, gameState.allCards).length,\r\n\t\t);\r\n\t\tconst boardWithoutAll = boardWithTribes.filter(\r\n\t\t\t(e) => !gameState.allCards.getCard(e.cardId).races?.includes(Race[Race.ALL]),\r\n\t\t);\r\n\t\tconst selectedMinions = selectMinions(boardWithoutAll, ALL_BG_RACES, gameState.allCards);\r\n\t\tconst allMinions = [\r\n\t\t\t...selectedMinions,\r\n\t\t\t...boardWithTribes.filter((e) => gameState.allCards.getCard(e.cardId).races?.includes(Race[Race.ALL])),\r\n\t\t];\r\n\t\tallMinions.forEach((e) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\te,\r\n\t\t\t\tgameState.cardsData.getTavernLevel(e.cardId),\r\n\t\t\t\tgameState.cardsData.getTavernLevel(e.cardId),\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(playerEntity, e, playerBoard, playerEntity, opponentEntity);\r\n\t\t});\r\n\t}\r\n};\r\n\r\n// Not perfect, as I don't think this solves the issue where some cards are mutually exclusive\r\nconst selectMinions = (minions: BoardEntity[], tribes: Race[], allCards: AllCardsService): BoardEntity[] => {\r\n\t// Step 1\r\n\tconst minionsByTribe: { [tribe: string]: BoardEntity[] } = {};\r\n\tfor (const minion of minions) {\r\n\t\tfor (const tribe of allCards.getCard(minion.cardId).races ?? []) {\r\n\t\t\tif (!minionsByTribe[tribe]) {\r\n\t\t\t\tminionsByTribe[tribe] = [];\r\n\t\t\t}\r\n\t\t\tminionsByTribe[tribe].push(minion);\r\n\t\t}\r\n\t}\r\n\tfor (const tribe of ALL_BG_RACES) {\r\n\t\tminionsByTribe[tribe] = shuffleArray(minionsByTribe[Race[tribe]] ?? []);\r\n\t}\r\n\r\n\tconst selectedMinions: BoardEntity[] = [];\r\n\r\n\t// Step 3\r\n\tfor (const tribe of tribes) {\r\n\t\tif (minionsByTribe[tribe]) {\r\n\t\t\tminionsByTribe[tribe].sort(\r\n\t\t\t\t(a, b) => allCards.getCard(a.cardId).races.length - allCards.getCard(b.cardId).races.length,\r\n\t\t\t);\r\n\t\t\tfor (const minion of minionsByTribe[tribe]) {\r\n\t\t\t\tif (!selectedMinions.includes(minion)) {\r\n\t\t\t\t\tselectedMinions.push(minion);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Step 4\r\n\treturn selectedMinions;\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone || playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\t// eslint-disable-next-line prefer-const\r\n\tlet shouldRecomputeCurrentAttacker = false;\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\t// TODO: should this recompute the first attack order?\r\n\tif (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLeftToken) {\r\n\t\tconst target = opponentBoard[0];\r\n\t\tconst damageDone = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t}\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tconst previousCurrentAttacker = currentAttacker;\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: 1\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0\r\n\t\t\t\t: currentAttacker;\r\n\t\t// console.debug(\r\n\t\t// \t'recompting current attacker',\r\n\t\t// \tcurrentAttacker,\r\n\t\t// \tplayerBoard.length,\r\n\t\t// \topponentBoard.length,\r\n\t\t// \tpreviousCurrentAttacker,\r\n\t\t// \tstringifySimple(playerBoard, allCards),\r\n\t\t// \tstringifySimple(opponentBoard, allCards),\r\n\t\t// );\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.IllidanStormrage_TB_BaconShop_HERO_08:\r\n\t\t\treturn CardIds.Wingmen;\r\n\t\tcase CardIds.TheLichKing_TB_BaconShop_HERO_22:\r\n\t\t\treturn CardIds.RebornRites;\r\n\t\tcase CardIds.ProfessorPutricide_BG25_HERO_100:\r\n\t\t\treturn CardIds.RagePotion;\r\n\t\tcase CardIds.Deathwing_TB_BaconShop_HERO_52:\r\n\t\t\treturn CardIds.AllWillBurn;\r\n\t\tcase CardIds.TeronGorefiend_BG25_HERO_103:\r\n\t\t\treturn CardIds.TeronGorefiend_RapidReanimation;\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\t// Apparently, the board composition used for start of combat minion effects (like Red Whelp, and I assume it works the\r\n\t// same way for others like Prized Promo Drake or Mantid Queen) is the one that is used before Illidan's effect is handled.\r\n\t// Since this also runs before HP start of combat, we probably also use the state as it was before HP were triggered, like\r\n\t// Tamsin's Phylactery.\r\n\tattackingBoardBefore: BoardEntity[],\r\n\tdefendingBoardBefore: BoardEntity[],\r\n\tgameState: FullGameState,\r\n): boolean => {\r\n\tif (attackingBoardHero.startOfCombatDone) {\r\n\t\treturn false;\r\n\t}\r\n\tlet hasProcessed = true;\r\n\tif (attacker.cardId === CardIds.RedWhelp_BGS_019) {\r\n\t\tconst damage = attackingBoardBefore.filter((entity) =>\r\n\t\t\thasCorrectTribe(entity, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t).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\tgameState,\r\n\t\t);\r\n\t} else if (attacker.cardId === CardIds.RedWhelp_TB_BaconUps_102) {\r\n\t\tconst damage = attackingBoardBefore.filter((entity) =>\r\n\t\t\thasCorrectTribe(entity, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t).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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.PrizedPromoDrake_BG21_014 ||\r\n\t\tattacker.cardId === CardIds.PrizedPromoDrake_BG21_014_G\r\n\t) {\r\n\t\tconst stats = attacker.cardId === CardIds.PrizedPromoDrake_BG21_014_G ? 6 : 3;\r\n\t\tconst targets = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards));\r\n\t\tfor (const entity of targets) {\r\n\t\t\tmodifyStats(entity, stats, stats, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tentity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ChoralMrrrglr_BG26_354 ||\r\n\t\tattacker.cardId === CardIds.ChoralMrrrglr_BG26_354_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.ChoralMrrrglr_BG26_354_G ? 2 : 1;\r\n\t\tmodifyStats(\r\n\t\t\tattacker,\r\n\t\t\tmultiplier * attackingBoardHero.globalInfo?.ChoralAttackBuff,\r\n\t\t\tmultiplier * attackingBoardHero.globalInfo?.ChoralHealthBuff,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.AmberGuardian_BG24_500 ||\r\n\t\tattacker.cardId === CardIds.AmberGuardian_BG24_500_G\r\n\t) {\r\n\t\t// First try to get a target without divine shield, and if none is available, pick one with divine shield\r\n\t\tconst otherDragons = attackingBoard\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards))\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tconst loops = attacker.cardId === CardIds.AmberGuardian_BG24_500_G ? 2 : 1;\r\n\t\tconst dragonsToConsider = otherDragons;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst otherDragon =\r\n\t\t\t\tpickRandom(dragonsToConsider.filter((e) => !e.divineShield)) ?? pickRandom(dragonsToConsider);\r\n\t\t\tif (otherDragon) {\r\n\t\t\t\tif (!otherDragon.divineShield) {\r\n\t\t\t\t\tupdateDivineShield(\r\n\t\t\t\t\t\totherDragon,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tmodifyStats(otherDragon, 7, 7, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\totherDragon,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tdragonsToConsider.splice(dragonsToConsider.indexOf(otherDragon), 1);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.SanctumRester_BG26_356 ||\r\n\t\tattacker.cardId === CardIds.SanctumRester_BG26_356_G\r\n\t) {\r\n\t\tconst buff = attacker.cardId === CardIds.SanctumRester_BG26_356_G ? 16 : 8;\r\n\t\t// First try to get a target without divine shield, and if none is available, pick one with divine shield\r\n\t\tconst otherDragons = attackingBoard\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards))\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\totherDragons.forEach((otherDragon) => {\r\n\t\t\tmodifyStats(otherDragon, 0, buff, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\totherDragon,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Soulsplitter_BG25_023 ||\r\n\t\tattacker.cardId === CardIds.Soulsplitter_BG25_023_G\r\n\t) {\r\n\t\tconst numberOfTargets = attacker.cardId === CardIds.Soulsplitter_BG25_023_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst undeadsWithoutReborn = attackingBoard\r\n\t\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.UNDEAD, gameState.allCards))\r\n\t\t\t\t.filter((e) => !e.reborn);\r\n\t\t\tconst chosenUndead = pickRandom(undeadsWithoutReborn);\r\n\t\t\tif (chosenUndead) {\r\n\t\t\t\tchosenUndead.reborn = true;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tchosenUndead,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy ||\r\n\t\tattacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy_G\r\n\t) {\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tconst multiplier = attacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy_G ? 2 : 1;\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tentity,\r\n\t\t\t\tmultiplier * (attackingBoardHero.deadEyeDamageDone ?? 0),\r\n\t\t\t\tmultiplier * (attackingBoardHero.deadEyeDamageDone ?? 0),\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tentity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.CorruptedMyrmidon_BG23_012 ||\r\n\t\tattacker.cardId === CardIds.CorruptedMyrmidon_BG23_012_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.CorruptedMyrmidon_BG23_012_G ? 2 : 1;\r\n\t\tmodifyStats(\r\n\t\t\tattacker,\r\n\t\t\tmultiplier * attacker.attack,\r\n\t\t\tmultiplier * attacker.health,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.InterrogatorWhitemane_BG24_704 ||\r\n\t\tattacker.cardId === CardIds.InterrogatorWhitemane_BG24_704_G\r\n\t) {\r\n\t\tif (defendingBoard.length > 0) {\r\n\t\t\tconst validTargets = defendingBoard.filter((e) => gameState.cardsData.getTavernLevel(e.cardId) >= 5);\r\n\t\t\tconst numberOfPicks = attacker.cardId === CardIds.InterrogatorWhitemane_BG24_704_G ? 2 : 1;\r\n\t\t\tfor (let i = 0; i < numberOfPicks; i++) {\r\n\t\t\t\tconst target = pickRandom(validTargets);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tcastImpure(attacker, target, attackingBoard, gameState.spectator);\r\n\t\t\t\t\tconst targetIndex = validTargets.findIndex((e) => e.entityId === target.entityId);\r\n\t\t\t\t\tvalidTargets.splice(targetIndex, 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (attacker.cardId === CardIds.MantidQueen_BG22_402 || attacker.cardId === CardIds.MantidQueen_BG22_402_G) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.MantidQueen_BG22_402_G ? 2 : 1;\r\n\t\tconst allRaces = attackingBoardBefore\r\n\t\t\t.map((entity) => entity.cardId)\r\n\t\t\t.flatMap((cardId) => gameState.allCards.getCard(cardId).races)\r\n\t\t\t.filter((race) => !!race && race !== Race[Race.BLANK]);\r\n\t\tconst totalRaces =\r\n\t\t\t[...new Set(allRaces.filter((race) => race !== Race[Race.ALL]))].length +\r\n\t\t\tallRaces.filter((race) => race === Race[Race.ALL]).length;\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tfor (let j = 0; j < totalRaces; j++) {\r\n\t\t\t\tconst buffType = getRandomMantidQueenBuffType(attacker);\r\n\t\t\t\tswitch (buffType) {\r\n\t\t\t\t\tcase 'stats':\r\n\t\t\t\t\t\tmodifyStats(attacker, 5, 5, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'reborn':\r\n\t\t\t\t\t\tattacker.reborn = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'taunt':\r\n\t\t\t\t\t\tattacker.taunt = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'windfury':\r\n\t\t\t\t\t\tattacker.windfury = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.CarbonicCopy_BG27_503 ||\r\n\t\tattacker.cardId === CardIds.CarbonicCopy_BG27_503_G\r\n\t) {\r\n\t\tconst numberOfCopies = attacker.cardId === CardIds.CarbonicCopy_BG27_503_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfCopies; i++) {\r\n\t\t\tif (!!attackingBoard.length && attackingBoard.length < 7) {\r\n\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t...attacker,\r\n\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t};\r\n\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t1,\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\tgameState.allCards,\r\n\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\tattacker.friendly,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tcopy,\r\n\t\t\t\t);\r\n\t\t\t\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(attacker) + 1);\r\n\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\tnewMinions,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tcopy,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.DiremuckForager_BG27_556 ||\r\n\t\tattacker.cardId === CardIds.DiremuckForager_BG27_556_G\r\n\t) {\r\n\t\tconst potentialTargets = attackingBoardHero.hand\r\n\t\t\t.filter((e) => !!e.cardId)\r\n\t\t\t.filter((e) => gameState.allCards.getCard(e.cardId).type?.toUpperCase() === CardType[CardType.MINION])\r\n\t\t\t.filter((e) => !e.locked);\r\n\t\tif (potentialTargets.length > 0) {\r\n\t\t\tconst target = pickRandom(potentialTargets);\r\n\t\t\t// When it's the opponent, the game state already contains all the buffs\r\n\t\t\t// It can happen that, for the opponent, a card is first added to their hand (eg with Embrace Your Rage)\r\n\t\t\t// and then summoned by Diremuck. In that case, the stats need to be buffed\r\n\t\t\t// Update 29.2 18/04/2024: this is no longer the case, and the minions passed in the initial state should\r\n\t\t\t// reflect the values they have in hand\r\n\t\t\t// if (target?.friendly || !target?.inInitialState) {\r\n\t\t\tconst diremuckBuff = attacker.cardId === CardIds.DiremuckForager_BG27_556_G ? 4 : 2;\r\n\t\t\tmodifyStats(target, diremuckBuff, diremuckBuff, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\ttarget,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t\t// }\r\n\t\t\tif (attackingBoard.length < 7) {\r\n\t\t\t\ttarget.locked = true;\r\n\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\ttarget.cardId,\r\n\t\t\t\t\t1,\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\tgameState.allCards,\r\n\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\tattacker.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\t{ ...target } as BoardEntity,\r\n\t\t\t\t);\r\n\t\t\t\tfor (const s of newMinions) {\r\n\t\t\t\t\ts.onCanceledSummon = () => (target.locked = false);\r\n\t\t\t\t}\r\n\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\tnewMinions,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard.length - (attackingBoard.indexOf(attacker) + 1),\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.HawkstriderHerald_BG27_079 ||\r\n\t\tattacker.cardId === CardIds.HawkstriderHerald_BG27_079_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.HawkstriderHerald_BG27_079_G ? 2 : 1;\r\n\t\tfor (const entity of attackingBoard) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\thandleDeathrattles({\r\n\t\t\t\t\tgameState: gameState,\r\n\t\t\t\t\tplayerDeadEntities: attackingBoardHero.friendly ? [entity] : [],\r\n\t\t\t\t\tplayerDeadEntityIndexesFromRight: attackingBoardHero.friendly\r\n\t\t\t\t\t\t? [attackingBoard.length - 1 - attackingBoard.indexOf(entity)]\r\n\t\t\t\t\t\t: [],\r\n\t\t\t\t\topponentDeadEntities: attackingBoardHero.friendly ? [] : [entity],\r\n\t\t\t\t\topponentDeadEntityIndexesFromRight: attackingBoardHero.friendly\r\n\t\t\t\t\t\t? []\r\n\t\t\t\t\t\t: [attackingBoard.length - 1 - attackingBoard.indexOf(entity)],\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\t// console.debug('done triggering hawkstrider\\n\\n\\n');\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.AudaciousAnchor_BG28_904 ||\r\n\t\tattacker.cardId === CardIds.AudaciousAnchor_BG28_904_G\r\n\t) {\r\n\t\tconst iterations = attacker.cardId === CardIds.AudaciousAnchor_BG28_904_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < iterations; i++) {\r\n\t\t\tconst targets = findNearestEnemies(\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard.length - 1 - attackingBoard.indexOf(attacker),\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\t1,\r\n\t\t\t\tgameState.allCards,\r\n\t\t\t);\r\n\t\t\tif (!targets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (targets.length > 2) {\r\n\t\t\t\tconsole.error('Invalid number of targets', targets.length);\r\n\t\t\t}\r\n\r\n\t\t\tconst target = pickRandom(targets);\r\n\t\t\twhile (attacker.health > 0 && target.health > 0 && !attacker.definitelyDead && !target.definitelyDead) {\r\n\t\t\t\t// Attackers don't alternate\r\n\t\t\t\t// See http://replays.firestoneapp.com/?reviewId=f9f6bf62-db73-49ad-8187-d2f8848b7f36&turn=17&action=0\r\n\t\t\t\tdoFullAttack(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy ||\r\n\t\tattacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G\r\n\t) {\r\n\t\t// const iterations = attacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G ? 2 : 1;\r\n\t\trememberDeathrattles(\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId !== CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy &&\r\n\t\t\t\t\te.cardId !== CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G,\r\n\t\t\t),\r\n\t\t\tgameState.cardsData,\r\n\t\t\tgameState.allCards,\r\n\t\t\tgameState.sharedState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.IrateRooster_BG29_990 ||\r\n\t\tattacker.cardId === CardIds.IrateRooster_BG29_990_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.IrateRooster_BG29_990_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\t\tfor (const neighbour of neighbours) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tdealDamageToMinion(\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t\tmodifyStats(neighbour, 4, 0, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.MisfitDragonling_BG29_814 ||\r\n\t\tattacker.cardId === CardIds.MisfitDragonling_BG29_814_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.MisfitDragonling_BG29_814_G ? 2 : 1;\r\n\t\tconst tier = attackingBoardHero.tavernTier;\r\n\t\tconst stats = multiplier * tier;\r\n\t\tmodifyStats(attacker, stats, stats, attackingBoard, attackingBoardHero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ThousandthPaperDrake_BG29_810 ||\r\n\t\tattacker.cardId === CardIds.ThousandthPaperDrake_BG29_810_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.ThousandthPaperDrake_BG29_810_G ? 2 : 1;\r\n\t\tconst pickedTargets = [];\r\n\t\tconst dragons = attackingBoard.filter((e) =>\r\n\t\t\thasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t);\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst target = dragons.filter((e) => !pickedTargets.includes(e))[0];\r\n\t\t\tif (!!target) {\r\n\t\t\t\tmodifyStats(target, 1, 2, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\ttarget.windfury = true;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tpickedTargets.push(target);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.YulonFortuneGranter_BG29_811 ||\r\n\t\tattacker.cardId === CardIds.YulonFortuneGranter_BG29_811_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.YulonFortuneGranter_BG29_811_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst candidateBoard = attackingBoard\r\n\t\t\t\t.filter((e) => !isGolden(e.cardId, gameState.allCards))\r\n\t\t\t\t.filter(\r\n\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\te.cardId !== CardIds.YulonFortuneGranter_BG29_811 &&\r\n\t\t\t\t\t\te.cardId !== CardIds.YulonFortuneGranter_BG29_811_G,\r\n\t\t\t\t);\r\n\t\t\t// Because we pick one at random from all the ones that have the lowest tier\r\n\t\t\tconst randomBoard = shuffleArray(candidateBoard);\r\n\t\t\tconst candidates = randomBoard.sort(\r\n\t\t\t\t(a, b) => gameState.cardsData.getTavernLevel(a.cardId) - gameState.cardsData.getTavernLevel(b.cardId),\r\n\t\t\t);\r\n\t\t\tconst target = candidates[0];\r\n\t\t\tif (!!target) {\r\n\t\t\t\tmakeMinionGolden(target, attacker, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.HoardingHatespawn_BG29_872 ||\r\n\t\tattacker.cardId === CardIds.HoardingHatespawn_BG29_872_G\r\n\t) {\r\n\t\tconst stats = attacker.cardId === CardIds.HoardingHatespawn_BG29_872_G ? 20 : 10;\r\n\t\tconst target = getRandomMinionWithHighestHealth(defendingBoard);\r\n\t\tif (!!target) {\r\n\t\t\tconst previousAttack = target.attack;\r\n\t\t\tconst previousHealth = target.health;\r\n\t\t\ttarget.attack = Math.max(0, target.attack - stats);\r\n\t\t\ttarget.health = Math.max(0, target.health - stats);\r\n\t\t\ttarget.maxHealth = Math.max(0, target.maxHealth - stats);\r\n\t\t\tmodifyStats(\r\n\t\t\t\tattacker,\r\n\t\t\t\tpreviousAttack - target.attack,\r\n\t\t\t\tpreviousHealth - target.health,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\ttarget,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875 ||\r\n\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875_G\r\n\t) {\r\n\t\tconst targetEnchantment =\r\n\t\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875_G\r\n\t\t\t\t? CardIds.TheUninvitedGuest_UninvitedEnchantment_BG29_875_Ge\r\n\t\t\t\t: CardIds.TheUninvitedGuest_UninvitedEnchantment_BG29_875e;\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId != attacker.entityId)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\te.enchantments = e.enchantments || [];\r\n\t\t\t\tif (!e.enchantments.some((e) => e.cardId === targetEnchantment)) {\r\n\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\tcardId: targetEnchantment,\r\n\t\t\t\t\t\toriginEntityId: attacker.entityId,\r\n\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t} else if (attacker.cardId === CardIds.Sandy_BGDUO_125 || attacker.cardId === CardIds.Sandy_BGDUO_125_G) {\r\n\t\tconst teammateState = getTeammateInitialState(gameState.gameState, attackingBoardHero);\r\n\t\tif (teammateState?.board?.length) {\r\n\t\t\tconst isGolden = attacker.cardId === CardIds.Sandy_BGDUO_125_G;\r\n\t\t\tconst minionToCopy = getRandomMinionWithHighestHealth(teammateState.board);\r\n\t\t\tconst copy: BoardEntity = { ...minionToCopy, enchantments: [...minionToCopy.enchantments] };\r\n\t\t\tconst attackerIndex = attackingBoard.indexOf(attacker);\r\n\t\t\t// Insert the copy in its place\r\n\t\t\tattackingBoard.splice(attackerIndex, 0, copy);\r\n\t\t\tif (isGolden) {\r\n\t\t\t\tmakeMinionGolden(copy, copy, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy ||\r\n\t\tattacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy_G\r\n\t) {\r\n\t\tconst vaelastraszBonus = attacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy_G ? 6 : 3;\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tmodifyStats(e, vaelastraszBonus, vaelastraszBonus, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy ||\r\n\t\tattacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy_G\r\n\t) {\r\n\t\tconst minionsOfDifferentTypes = getMinionsOfDifferentTypes(attackingBoard, attackingBoardHero, gameState);\r\n\t\tif (minionsOfDifferentTypes.length >= 4) {\r\n\t\t\tconst highestAttackOnBoard = Math.max(...attackingBoard.map((entity) => entity.attack));\r\n\t\t\tconst highestHealthOnBoard = Math.max(...attackingBoard.map((entity) => entity.health));\r\n\t\t\tconst multiplier = attacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy_G ? 2 : 1;\r\n\t\t\tmodifyStats(\r\n\t\t\t\tattacker,\r\n\t\t\t\thighestAttackOnBoard * multiplier,\r\n\t\t\t\thighestHealthOnBoard * multiplier,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (attacker.cardId === CardIds.SunScreener_BG30_101 || attacker.cardId === CardIds.SunScreener_BG30_101_G) {\r\n\t\tif (attackingBoard.length > 0 || defendingBoard.length > 0) {\r\n\t\t\tconst quantity = attacker.cardId === CardIds.SunScreener_BG30_101 ? 3 : 6;\r\n\t\t\tgrantDivineShieldToLeftmostMinions(\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tquantity,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgrantDivineShieldToLeftmostMinions(\r\n\t\t\t\tattacker,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tquantity,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119 ||\r\n\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119_G\r\n\t) {\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.PIRATE, gameState.allCards))\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\te.enchantments = e.enchantments || [];\r\n\t\t\t\te.enchantments.push({\r\n\t\t\t\t\tcardId:\r\n\t\t\t\t\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119_G\r\n\t\t\t\t\t\t\t? CardIds.SkyPirateFlagbearer_FlagbearingEnchantment_BG30_119_Ge\r\n\t\t\t\t\t\t\t: CardIds.SkyPirateFlagbearer_FlagbearingEnchantment_BG30_119e,\r\n\t\t\t\t\toriginEntityId: attacker.entityId,\r\n\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t} else {\r\n\t\thasProcessed = false;\r\n\t}\r\n\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);\r\n\treturn hasProcessed;\r\n};\r\n\r\nconst applyAllWillBurn = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tsourceEntity: BgsPlayerEntity | BoardEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tfor (const entity of board1) {\r\n\t\tmodifyStats(entity, 2, 0, board1, board1Hero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(sourceEntity, entity, board1, null, null);\r\n\t}\r\n\tfor (const entity of board2) {\r\n\t\tmodifyStats(entity, 2, 0, board2, board1Hero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(sourceEntity, entity, board2, null, null);\r\n\t}\r\n};\r\n\r\nconst castImpure = (entity: BoardEntity, source: BoardEntity, board: BoardEntity[], spectator: Spectator) => {\r\n\tif (!entity) {\r\n\t\treturn;\r\n\t}\r\n\tconst multiplier = source.cardId === CardIds.InterrogatorWhitemane_BG24_704_G ? 3 : 2;\r\n\tentity.taunt = true;\r\n\tentity.damageMultiplier = entity.damageMultiplier ?? 1;\r\n\tentity.damageMultiplier *= multiplier;\r\n\tspectator.registerPowerTarget(source, entity, board, null, null);\r\n};\r\n\r\nconst getRandomMantidQueenBuffType = (entity: BoardEntity): 'stats' | 'reborn' | 'windfury' | 'taunt' => {\r\n\tconst possibilities: ('stats' | 'reborn' | 'windfury' | 'taunt')[] = ['stats'];\r\n\tif (!entity.reborn) {\r\n\t\tpossibilities.push('reborn');\r\n\t}\r\n\tif (!entity.windfury) {\r\n\t\tpossibilities.push('windfury');\r\n\t}\r\n\tif (!entity.taunt) {\r\n\t\tpossibilities.push('taunt');\r\n\t}\r\n\treturn pickRandom(possibilities);\r\n};\r\n"]}
1
+ {"version":3,"file":"start-of-combat.js","sourceRoot":"","sources":["../../src/simulation/start-of-combat.ts"],"names":[],"mappings":";;;AACA,iEAAsG;AAGtG,oDAA0F;AAC1F,6CAAqF;AACrF,oCAUkB;AAClB,+DAA4D;AAC5D,qCAQkB;AAClB,mDAAiD;AACjD,+DAM+B;AAC/B,2EAAiE;AACjE,6DAAqD;AAErD,qCAA+C;AAE/C,mCAA6E;AAC7E,2DAA6D;AAC7D,2CAAkD;AAS3C,MAAM,mBAAmB,GAAG,CAClC,YAA6B,EAC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AAE,EAAE;;IAC3G,IAAI,CAAC,MAAM,EAAE;QACZ,OAAO;KACP;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,iBAA6C,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,gBAAgB,GAAG,MAAA,MAAM,CAAC,gBAAgB,mCAAI,CAAC,CAAC;IACvD,MAAM,CAAC,gBAAgB,IAAI,UAAU,CAAC;IACtC,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,MAAmB,EAA6C,EAAE;IACvG,MAAM,aAAa,GAAkD,CAAC,OAAO,CAAC,CAAC;IAC/E,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QACnB,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC/B;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;QAClB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC5B;IACD,OAAO,IAAA,kBAAU,EAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, CardType, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { grantDivineShieldToLeftmostMinions, updateDivineShield } from '../divine-shield';\r\nimport { pickRandom, pickRandomLowestHealth, shuffleArray } from '../services/utils';\r\nimport {\r\n\taddImpliedMechanics,\r\n\taddStatsToBoard,\r\n\tcopyEntity,\r\n\tgetEffectiveTribesForEntity,\r\n\tgetMinionsOfDifferentTypes,\r\n\tgetRandomMinionWithHighestHealth,\r\n\tgetTeammateInitialState,\r\n\thasCorrectTribe,\r\n\tisGolden,\r\n} from '../utils';\r\nimport { removeAurasFromSelf } from './add-minion-to-board';\r\nimport {\r\n\tdealDamageToMinion,\r\n\tdealDamageToRandomEnemy,\r\n\tdoFullAttack,\r\n\tfindNearestEnemies,\r\n\tgetNeighbours,\r\n\tprocessMinionDeath,\r\n\tsimulateAttack,\r\n} from './attack';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport {\r\n\tapplyEarthInvocationEnchantment,\r\n\tapplyFireInvocationEnchantment,\r\n\tapplyLightningInvocationEnchantment,\r\n\tapplyWaterInvocationEnchantment,\r\n\trememberDeathrattles,\r\n} from './deathrattle-effects';\r\nimport { handleDeathrattles } from './deathrattle-orchestration';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { Spectator } from './spectator/spectator';\r\nimport { applyAfterStatsUpdate, modifyStats, setEntityStats } from './stats';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\nimport { makeMinionGolden } from './utils/golden';\r\n\r\n// TODO 20/04/2024: I'm not too sure about some ordering. The way I understand it, the Start of Combat has\r\n// multiple phases, and in each phase the player order is random\r\n// However, looking at http://replays.firestoneapp.com/?reviewId=a577602e-06f3-4c4b-928d-36ea98c2e6d5&turn=5&action=0,\r\n// it feels that a \"start of combat\" minion effect could trigger before an opponent's hero power effect\r\n// Or is that limited to Bru'kan?\r\n// I feel that I've asked a lot of questions recently, so I don't want to add that one to the list, as the interaction\r\n// is for now pretty marginal\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\tgameState: FullGameState,\r\n): number => {\r\n\tconst shouldRecomputeCurrentAttacker = true;\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? 0\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? 1\r\n\t\t\t\t: Math.round(Math.random());\r\n\t}\r\n\r\n\t// https://twitter.com/DCalkosz/status/1564705111850434561\r\n\tcurrentAttacker = handleStartOfCombatQuestRewards(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatAnomalies(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\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\t// Update: this seems to have changed: https://x.com/LoewenMitchell/status/1737588920139825335?s=20\r\n\t// now you have all hero powers trigger in a first phase, then you have Illidan, and once everything has triggered, you have Tavish\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\tgameState,\r\n\t);\r\n\t// Because start of combat powers like Red Whelp's use the board composition before Illidan's strike to know the amount of damage\r\n\tconst playerBoardBefore = playerBoard.map((e) => ({ ...e }));\r\n\tconst opponentBoardBefore = opponentBoard.map((e) => ({ ...e }));\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\tgameState,\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\tgameState,\r\n\t);\r\n\t// Timing confirmed by Mitchell on Discord on 2024-02-21\r\n\tcurrentAttacker = handleStartOfCombatSpells(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\t// Not sure if this can change who the first player will be\r\n\t// I don't have any official source on it at the moment, but there are some simulation\r\n\thandleStartOfCombatMinions(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tplayerBoardBefore,\r\n\t\topponentBoardBefore,\r\n\t\tgameState,\r\n\t);\r\n\tplayerEntity.startOfCombatDone = true;\r\n\topponentEntity.startOfCombatDone = true;\r\n\tapplyAfterStatsUpdate(gameState);\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t\tcurrentAttacker = handlePreCombatHeroPowersForPlayer(\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\tgameState,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handlePreCombatHeroPowersForPlayer = (\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone || playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\r\n\tlet shouldRecomputeCurrentAttacker = false;\r\n\t// Some are part of the incoming board: Y'Shaarj, Lich King, Ozumat\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.SwattingInsects && 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, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EarthInvocationToken) {\r\n\t\tapplyEarthInvocationEnchantment(playerBoard, null, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaterInvocationToken) {\r\n\t\tapplyWaterInvocationEnchantment(playerBoard, playerEntity, null, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.FireInvocationToken) {\r\n\t\tapplyFireInvocationEnchantment(playerBoard, playerEntity, null, playerEntity, gameState);\r\n\t} else if (playerHeroPowerId === CardIds.AllWillBurn) {\r\n\t\tapplyAllWillBurn(playerBoard, playerEntity, opponentBoard, opponentEntity, playerEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TamsinRoame_FragrantPhylactery) {\r\n\t\thandleTamsinForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\t// Tamsin's hero power somehow happens before the current attacker is chosen.\r\n\t\t// See http://replays.firestoneapp.com/?reviewId=bce94e6b-c807-48e4-9c72-2c5c04421213&turn=6&action=9\r\n\t\t// Even worse: if a scallywag token pops, it attacks before the first attacker is recomputed\r\n\t\tshouldRecomputeCurrentAttacker = true;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.EmbraceYourRage) {\r\n\t\thandleEmbraceYourRageForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\tshouldRecomputeCurrentAttacker = true;\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.RebornRites) {\r\n\t\thandleRebornRitesForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.TeronGorefiend_RapidReanimation) {\r\n\t\tshouldRecomputeCurrentAttacker = handleTeronForPlayer(\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentBoard,\r\n\t\t\topponentEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// Same as Tamsin? No, because the new minion should repop automatically\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.WaxWarband) {\r\n\t\thandleWaxWarbandForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t} else if (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.LightningInvocationToken) {\r\n\t\tapplyLightningInvocationEnchantment(playerBoard, playerEntity, null, opponentBoard, opponentEntity, gameState);\r\n\t} else if (\r\n\t\tplayerEntity.heroPowerUsed &&\r\n\t\tplayerHeroPowerId === CardIds.FlobbidinousFloop_GloriousGloop_BGDUO_HERO_101p\r\n\t) {\r\n\t\tapplyGloriousGloop(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t}\r\n\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: 1\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0\r\n\t\t\t\t: Math.round(Math.random());\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\tgameState: FullGameState,\r\n): number => {\r\n\t// console.log('current attacker before', currentAttacker);\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\tgameState,\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\tgameState,\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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t}\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\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\tplayerBoardBefore: BoardEntity[],\r\n\topponentBoardBefore: BoardEntity[],\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tlet attackerForStart = Math.random() < 0.5 ? 0 : 1;\r\n\tconst playerAttackers = [...playerBoard];\r\n\tconst opponentAttackers = [...opponentBoard];\r\n\r\n\twhile (playerAttackers.length > 0 || opponentAttackers.length > 0) {\r\n\t\tlet shouldUpdateNextPlayer = false;\r\n\t\tif (attackerForStart === 0 && playerAttackers.length > 0) {\r\n\t\t\tconst attacker = playerAttackers.splice(0, 1)[0];\r\n\t\t\tif (attacker.health <= 0 || attacker.definitelyDead) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tshouldUpdateNextPlayer = performStartOfCombatMinionsForPlayer(\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\tplayerBoardBefore,\r\n\t\t\t\topponentBoardBefore,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 0 && playerAttackers.length === 0) {\r\n\t\t\tshouldUpdateNextPlayer = true;\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\tif (attacker.health <= 0 || attacker.definitelyDead) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tshouldUpdateNextPlayer = performStartOfCombatMinionsForPlayer(\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\topponentBoardBefore,\r\n\t\t\t\tplayerBoardBefore,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (attackerForStart === 1 && opponentAttackers.length === 0) {\r\n\t\t\tshouldUpdateNextPlayer = true;\r\n\t\t}\r\n\r\n\t\tif (shouldUpdateNextPlayer) {\r\n\t\t\tattackerForStart = (attackerForStart + 1) % 2;\r\n\t\t}\r\n\t}\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatQuestRewards = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatQuestRewardsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t}\r\n\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatSpells = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (Math.random() < 0.5) {\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t} else {\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t\tfalse,\r\n\t\t);\r\n\t\tcurrentAttacker = handleStartOfCombatSpellsForPlayer(\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\tgameState,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatAnomalies = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tcurrentAttacker = handleStartOfCombatAnomaliesForPlayer(\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\tcurrentAttacker = handleStartOfCombatAnomaliesForPlayer(\r\n\t\topponentEntity,\r\n\t\topponentBoard,\r\n\t\tplayerEntity,\r\n\t\tplayerBoard,\r\n\t\tcurrentAttacker,\r\n\t\tgameState,\r\n\t);\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatQuestRewardsForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n\tplayerIsFriendly: boolean,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\r\n\tfor (const reward of playerEntity.questRewards) {\r\n\t\tswitch (reward) {\r\n\t\t\tcase CardIds.EvilTwin:\r\n\t\t\t\tif (!!playerBoard.length && playerBoard.length < 7) {\r\n\t\t\t\t\tconst highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t\t...highestHealthMinion,\r\n\t\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\thighestHealthMinion.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\thighestHealthMinion,\r\n\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);\r\n\t\t\t\t\t// Recompute first attacker\r\n\t\t\t\t\t// See https://replays.firestoneapp.com/?reviewId=93229c4a-d864-4196-83dd-2fea2a5bf70a&turn=29&action=0\r\n\t\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.StaffOfOrigination_BG24_Reward_312:\r\n\t\t\t\tplayerBoard.forEach((entity) => {\r\n\t\t\t\t\tmodifyStats(entity, 15, 15, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, entity, playerBoard, null, null);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.StolenGold:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tmakeMinionGolden(\r\n\t\t\t\t\t\tplayerBoard[0],\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\tmakeMinionGolden(\r\n\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatSpellsForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n\tplayerIsFriendly: boolean,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tfor (const secret of playerEntity.secrets ?? []) {\r\n\t\tswitch (secret.cardId) {\r\n\t\t\tcase CardIds.UpperHand_BG28_573:\r\n\t\t\t\tif (!!opponentBoard.length) {\r\n\t\t\t\t\tconst target = pickRandom(opponentBoard);\r\n\t\t\t\t\ttarget.health = 1;\r\n\t\t\t\t\ttarget.maxHealth = 1;\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, target, opponentBoard, null, null);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.BoonOfBeetles_BG28_603:\r\n\t\t\t\tsecret.scriptDataNum1 = 1;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FleetingVigor_BG28_519:\r\n\t\t\t\taddStatsToBoard(secret, playerBoard, playerEntity, 2, 1, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.ToxicTumbleweed_BG28_641:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tCardIds.ToxicTumbleweed_TumblingAssassinToken_BG28_641t,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tnewMinions[0].attackImmediately = true;\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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\tfor (const trinket of playerEntity.trinkets) {\r\n\t\tswitch (trinket.cardId) {\r\n\t\t\tcase CardIds.HolyMallet_BG30_MagicItem_902:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tupdateDivineShield(playerBoard[0], playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, playerBoard[0], playerBoard, null, null);\r\n\t\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\t\tupdateDivineShield(\r\n\t\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerBoard[playerBoard.length - 1],\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t\tnull,\r\n\t\t\t\t\t\t);\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.TrainingCertificate_BG30_MagicItem_962:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tconst minionsByAttack = [...playerBoard].sort((a, b) => a.attack - b.attack);\r\n\t\t\t\t\tconst firstTarget = minionsByAttack[0];\r\n\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\tfirstTarget,\r\n\t\t\t\t\t\t2 * firstTarget.maxAttack,\r\n\t\t\t\t\t\t2 * firstTarget.maxHealth,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tif (playerBoard.length > 1) {\r\n\t\t\t\t\t\tconst secondTarget = minionsByAttack[1];\r\n\t\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\t\tsecondTarget,\r\n\t\t\t\t\t\t\t2 * secondTarget.maxAttack,\r\n\t\t\t\t\t\t\t2 * secondTarget.maxHealth,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\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.ValorousMedallion_BG30_MagicItem_970:\r\n\t\t\tcase CardIds.ValorousMedallion_ValorousMedallionToken_BG30_MagicItem_970t:\r\n\t\t\t\tconst medallionBuff = trinket.cardId === CardIds.ValorousMedallion_BG30_MagicItem_970 ? 2 : 5;\r\n\t\t\t\taddStatsToBoard(trinket, playerBoard, playerEntity, medallionBuff, medallionBuff, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EmeraldDreamcatcher_BG30_MagicItem_542:\r\n\t\t\t\tconst highestAttack = Math.max(...playerBoard.map((entity) => entity.attack));\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.DRAGON, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\tsetEntityStats(e, highestAttack, null, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.JarredFrostling_BG30_MagicItem_952:\r\n\t\t\t\tconst elementals = shuffleArray(\r\n\t\t\t\t\tplayerBoard.filter((e) => hasCorrectTribe(e, playerEntity, Race.ELEMENTAL, gameState.allCards)),\r\n\t\t\t\t);\r\n\t\t\t\tconst targets = elementals.slice(0, 2);\r\n\t\t\t\ttargets.forEach((e) => {\r\n\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\tcardId: CardIds.JarredFrostling_FrostyGlobeEnchantment_BG30_MagicItem_952e,\r\n\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, e, playerBoard, null, null);\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RustyTrident_BG30_MagicItem_917:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.NAGA, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\t\tcardId: CardIds.RustyTrident_TridentsTreasureEnchantment_BG30_MagicItem_917e,\r\n\t\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.HoggyBank_BG30_MagicItem_411:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter((e) => hasCorrectTribe(e, playerEntity, Race.QUILBOAR, gameState.allCards))\r\n\t\t\t\t\t.forEach((e) => {\r\n\t\t\t\t\t\te.enchantments = e.enchantments ?? [];\r\n\t\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\t\tcardId: CardIds.HoggyBank_GemInTheBankEnchantment_BG30_MagicItem_411e,\r\n\t\t\t\t\t\t\toriginEntityId: trinket.entityId,\r\n\t\t\t\t\t\t\trepeats: 1,\r\n\t\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.AutomatonPortrait_BG30_MagicItem_303:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tCardIds.AstralAutomaton_BG_TTN_401,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\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.ShipInABottle_BG30_MagicItem_407:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst target = pickRandom(gameState.cardsData.pirateSpawns);\r\n\t\t\t\t\taddCardsInHand(playerEntity, playerBoard, [target], gameState);\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\ttarget,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tspawns.forEach((spawn) => (spawn.attackImmediately = true));\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.EternalPortrait_BG30_MagicItem_301:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.EternalKnight_BG25_008 ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((knight) => {\r\n\t\t\t\t\t\tknight.taunt = true;\r\n\t\t\t\t\t\tknight.reborn = true;\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, knight, playerBoard, null, null);\r\n\t\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TwinSkyLanterns_BG30_MagicItem_822:\r\n\t\t\tcase CardIds.TwinSkyLanterns_TwinSkyLanternsToken_BG30_MagicItem_822t2:\r\n\t\t\t\ttrinket.rememberedMinion = null;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.ArtisanalUrn_BG30_MagicItem_989:\r\n\t\t\tcase CardIds.ArtisanalUrn_ArtisanalUrnToken_BG30_MagicItem_989t:\r\n\t\t\t\tconst artisanalUrnBuff = trinket.cardId === CardIds.ArtisanalUrn_BG30_MagicItem_989 ? 3 : 7;\r\n\t\t\t\tplayerEntity.globalInfo.UndeadAttackBonus =\r\n\t\t\t\t\t(playerEntity.globalInfo.UndeadAttackBonus ?? 0) + artisanalUrnBuff;\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.RivendarePortrait_BG30_MagicItem_310:\r\n\t\t\t\tplayerBoard\r\n\t\t\t\t\t.filter(\r\n\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\te.cardId === CardIds.TitusRivendare_BG25_354 ||\r\n\t\t\t\t\t\t\te.cardId === CardIds.TitusRivendare_BG25_354_G,\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.forEach((e) => (e.stealth = true));\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.TinyfinOnesie_BG30_MagicItem_441:\r\n\t\t\t\tconst highestHealthMinionInHand = playerEntity.hand?.sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\tif (highestHealthMinionInHand && playerBoard.length > 0) {\r\n\t\t\t\t\tmodifyStats(\r\n\t\t\t\t\t\tplayerBoard[0],\r\n\t\t\t\t\t\thighestHealthMinionInHand.attack,\r\n\t\t\t\t\t\thighestHealthMinionInHand.health,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tgameState,\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.BronzeTimepiece_BG30_MagicItem_995:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tplayerBoard.forEach((entity) => {\r\n\t\t\t\t\t\tconst highest = Math.max(entity.attack, entity.health);\r\n\t\t\t\t\t\tsetEntityStats(entity, highest, highest, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(trinket, entity, playerBoard, null, null);\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.IronforgeAnvil_BG30_MagicItem_403:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tplayerBoard\r\n\t\t\t\t\t\t.filter((e) => getEffectiveTribesForEntity(e, playerEntity, gameState.allCards).length === 0)\r\n\t\t\t\t\t\t.forEach((entity) => {\r\n\t\t\t\t\t\t\tsetEntityStats(\r\n\t\t\t\t\t\t\t\tentity,\r\n\t\t\t\t\t\t\t\t3 * entity.attack,\r\n\t\t\t\t\t\t\t\t3 * entity.health,\r\n\t\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tgameState.spectator.registerPowerTarget(trinket, entity, playerBoard, null, null);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.KarazhanChessSet_BG30_MagicItem_972:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tfor (let i = 0; i < Math.min(playerBoard.length, 7); i++) {\r\n\t\t\t\t\t\tconst entityToCoy = playerBoard[i];\r\n\t\t\t\t\t\tconst copy: BoardEntity = copyEntity(entityToCoy);\r\n\t\t\t\t\t\tremoveAurasFromSelf(copy, playerBoard, playerEntity, gameState);\r\n\t\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t\t1,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t\tplayerBoard.length - i - 1,\r\n\t\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\t// TODO: according to http://replays.firestoneapp.com/?reviewId=576aa3bb-caa1-4e46-9d16-08a001fdd941&turn=23&action=3\r\n\t\t\t\t\t\t// it looks like the stats are simply copied from the original entity to the copy, instead\r\n\t\t\t\t\t\t// of summoning a copy and applying all the auras stuff\r\n\t\t\t\t\t\t// I've asked on Discord (2024-08-21) for clarification\r\n\t\t\t\t\t\ti += spawns.length;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.FishySticker_BG30_MagicItem_821:\r\n\t\t\tcase CardIds.FishySticker_FishyStickerToken_BG30_MagicItem_821t2:\r\n\t\t\t\tif (playerBoard.length < 7) {\r\n\t\t\t\t\tconst spawnId =\r\n\t\t\t\t\t\ttrinket.cardId === CardIds.FishySticker_BG30_MagicItem_821\r\n\t\t\t\t\t\t\t? CardIds.AvatarOfNzoth_FishOfNzothToken\r\n\t\t\t\t\t\t\t: CardIds.FishOfNzoth;\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tspawnId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\tplayerEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst spawns = performEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tcurrentAttacker =\r\n\t\t\t\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 0\r\n\t\t\t\t\t\t\t\t: 1\r\n\t\t\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t\t\t? playerIsFriendly\r\n\t\t\t\t\t\t\t\t? 1\r\n\t\t\t\t\t\t\t\t: 0\r\n\t\t\t\t\t\t\t: Math.round(Math.random());\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\treturn currentAttacker;\r\n};\r\n\r\nconst handleStartOfCombatAnomaliesForPlayer = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tplayerBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\tcurrentAttacker: number,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\tif (!gameState.anomalies?.length || playerEntity.startOfCombatDone) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tfor (const anomaly of gameState.anomalies) {\r\n\t\tswitch (anomaly) {\r\n\t\t\tcase CardIds.BlessedOrBlighted_BG27_Anomaly_726:\r\n\t\t\t\tif (playerBoard.length > 0) {\r\n\t\t\t\t\tconst dsTarget = playerBoard[0];\r\n\t\t\t\t\tupdateDivineShield(dsTarget, playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t\t\t\t\tconst rebornTarget = playerBoard[playerBoard.length - 1];\r\n\t\t\t\t\trebornTarget.reborn = true;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.AnomalousTwin_BG27_Anomaly_560:\r\n\t\t\t\tif (!!playerBoard.length && playerBoard.length < 7) {\r\n\t\t\t\t\tconst highestHealthMinion = [...playerBoard].sort((a, b) => b.health - a.health)[0];\r\n\t\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t\t...highestHealthMinion,\r\n\t\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState.allCards,\r\n\t\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\t\thighestHealthMinion.friendly,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t\tcopy,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tconst indexFromRight = playerBoard.length - (playerBoard.indexOf(highestHealthMinion) + 1);\r\n\t\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\t\tnewMinions,\r\n\t\t\t\t\t\tplayerBoard,\r\n\t\t\t\t\t\tplayerEntity,\r\n\t\t\t\t\t\thighestHealthMinion,\r\n\t\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t\topponentBoard,\r\n\t\t\t\t\t\topponentEntity,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tgameState.spectator.registerPowerTarget(playerEntity, copy, playerBoard, null, null);\r\n\t\t\t\t}\r\n\t\t\t\t// Recompute first attacker\r\n\t\t\t\t// See https://replays.firestoneapp.com/?reviewId=93229c4a-d864-4196-83dd-2fea2a5bf70a&turn=29&action=0\r\n\t\t\t\treturn playerBoard.length > opponentBoard.length\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: Math.round(Math.random());\r\n\t\t}\r\n\t}\r\n\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\tgameState: FullGameState,\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 = 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\tgameState,\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\tgameState,\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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t}\r\n\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\tif (playerHeroPowerId === CardIds.Wingmen && playerBoard.length > 0) {\r\n\t\t// After Illidan triggers, it's always the other opponent's turn\r\n\t\t// https://x.com/LoewenMitchell/status/1752714583360639131?s=20\r\n\t\thandleIllidanForPlayer(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState, currentAttacker);\r\n\t\tcurrentAttacker = friendly ? 1 : 0;\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\tgameState: FullGameState,\r\n\tcurrentAttacker: number,\r\n): void => {\r\n\tif (playerEntity.startOfCombatDone) {\r\n\t\treturn;\r\n\t}\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\tconst firstAttacker = playerBoard[0];\r\n\tconst secondAttacker = minionsAtStart > 1 ? playerBoard[playerBoard.length - 1] : null;\r\n\r\n\t// Stats updates\r\n\tmodifyStats(firstAttacker, 2, 1, playerBoard, playerEntity, gameState);\r\n\tgameState.spectator.registerPowerTarget(firstAttacker, firstAttacker, playerBoard, playerEntity, opponentEntity);\r\n\tif (!!secondAttacker && !secondAttacker.definitelyDead && secondAttacker.health > 0) {\r\n\t\tmodifyStats(secondAttacker, 2, 1, playerBoard, playerEntity, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tsecondAttacker,\r\n\t\t\tsecondAttacker,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentEntity,\r\n\t\t);\r\n\t}\r\n\r\n\t// Attacks\r\n\tfirstAttacker.attackImmediately = true;\r\n\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t// See http://replays.firestoneapp.com/?reviewId=f16b7a49-c2a2-4ac5-a9eb-a75f83246f70&turn=6&action=8\r\n\tfirstAttacker.hasAttacked = 0;\r\n\tif (!!secondAttacker && !secondAttacker.definitelyDead && secondAttacker.health > 0) {\r\n\t\tsecondAttacker.attackImmediately = true;\r\n\t\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\t\tsecondAttacker.hasAttacked = 0;\r\n\t}\r\n\r\n\t// // See http://replays.firestoneapp.com/?reviewId=7e9ec42c-a8f6-43d2-9f39-cc486dfa2395&turn=6&action=5\r\n\t// if (firstAttacker.definitelyDead || firstAttacker.health <= 0) {\r\n\t// \tcurrentAttacker = (currentAttacker + 1) % 2;\r\n\t// }\r\n\t// return currentAttacker;\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\tgameState: FullGameState,\r\n): void => {\r\n\tconst firstEntity = playerBoard[0];\r\n\tfirstEntity.windfury = true;\r\n\tif (!firstEntity.divineShield) {\r\n\t\tupdateDivineShield(firstEntity, playerBoard, playerEntity, opponentEntity, true, gameState);\r\n\t}\r\n\tfirstEntity.taunt = true;\r\n\tgameState.spectator.registerPowerTarget(firstEntity, firstEntity, playerBoard, playerEntity, opponentEntity);\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\tgameState: FullGameState,\r\n): void => {\r\n\tconst chosenEntity = pickRandomLowestHealth(playerBoard);\r\n\tif (!chosenEntity) {\r\n\t\tconsole.warn('could not pick any entity for tamsin');\r\n\t\treturn;\r\n\t}\r\n\tgameState.spectator.registerPowerTarget(playerEntity, chosenEntity, playerBoard, null, null);\r\n\tconst newBoard = playerBoard.filter((e) => e.entityId !== chosenEntity.entityId);\r\n\t// How to mark the minion as dead\r\n\tchosenEntity.definitelyDead = true;\r\n\tnewBoard.forEach((e) => {\r\n\t\tmodifyStats(e, chosenEntity.attack, chosenEntity.health, newBoard, playerEntity, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(chosenEntity, e, newBoard, playerEntity, opponentEntity);\r\n\t});\r\n};\r\n\r\nconst applyGloriousGloop = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (!playerBoard?.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst target = playerBoard.find((m) =>\r\n\t\tm.enchantments?.some((e) => e.cardId === CardIds.GloriousGloop_InTheGloopEnchantment_BGDUO_HERO_101pe2),\r\n\t);\r\n\tif (!target) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst teammateState = getTeammateInitialState(gameState.gameState, playerEntity);\r\n\tif (!teammateState?.board?.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst highestTier = Math.max(\r\n\t\t...teammateState.board.map((entity) => gameState.allCards.getCard(entity.cardId).techLevel),\r\n\t);\r\n\tconst candidates = teammateState.board.filter(\r\n\t\t(entity) => gameState.allCards.getCard(entity.cardId).techLevel === highestTier,\r\n\t);\r\n\tif (!candidates.length) {\r\n\t\treturn;\r\n\t}\r\n\tconst highestTierMinion = pickRandom(candidates);\r\n\tconst clone: BoardEntity = addImpliedMechanics(\r\n\t\t{\r\n\t\t\t...highestTierMinion,\r\n\t\t\tlastAffectedByEntity: null,\r\n\t\t\tdefinitelyDead: false,\r\n\t\t\tattackImmediately: false,\r\n\t\t},\r\n\t\tgameState.cardsData,\r\n\t);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, target, playerBoard, playerEntity, opponentEntity);\r\n\t// Replace the \"target\" minion with the \"clone\"\r\n\tconst index = playerBoard.indexOf(target);\r\n\tplayerBoard.splice(index, 1, clone);\r\n};\r\n\r\nconst handleEmbraceYourRageForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst createdCardId = playerEntity.heroPowerInfo as string;\r\n\tif (!createdCardId?.length) {\r\n\t\t// console.warn('no card id for embrace your rage');\r\n\t\treturn;\r\n\t}\r\n\tconst spawns = spawnEntities(\r\n\t\tcreatedCardId,\r\n\t\t1,\r\n\t\tplayerBoard,\r\n\t\tplayerEntity,\r\n\t\topponentBoard,\r\n\t\topponentEntity,\r\n\t\tgameState.allCards,\r\n\t\tgameState.cardsData,\r\n\t\tgameState.sharedState,\r\n\t\tgameState.spectator,\r\n\t\tplayerEntity.friendly,\r\n\t\ttrue,\r\n\t\tfalse,\r\n\t\tfalse,\r\n\t);\r\n\tconst indexFromRight = 0;\r\n\tperformEntitySpawns(\r\n\t\tspawns,\r\n\t\tplayerBoard,\r\n\t\tplayerEntity,\r\n\t\tplayerEntity,\r\n\t\tindexFromRight,\r\n\t\topponentBoard,\r\n\t\topponentEntity,\r\n\t\tgameState,\r\n\t);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, spawns[0], playerBoard, playerEntity, opponentEntity);\r\n\taddCardsInHand(playerEntity, playerBoard, spawns, gameState);\r\n\tgameState.spectator.registerPowerTarget(playerEntity, spawns[0], playerBoard, playerEntity, opponentEntity);\r\n};\r\n\r\nconst handleRebornRitesForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst targetEntityId = playerEntity.heroPowerInfo as number;\r\n\tconst target = playerBoard.find((entity) => entity.entityId === targetEntityId);\r\n\tif (!target) {\r\n\t\treturn;\r\n\t}\r\n\r\n\ttarget.reborn = true;\r\n\tgameState.spectator.registerPowerTarget(playerEntity, target, playerBoard, playerEntity, opponentEntity);\r\n};\r\n\r\nconst handleTeronForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): boolean => {\r\n\t// Getting the right enchantment can be tricky. The RapidReanimation enchantment can sometimes be\r\n\t// in the Graveyard zone, so we can't filter them out. In that case, we can have multiple\r\n\t// enchantments\r\n\t// However, because of how things are handled in the logs, we should be able to always take the one *\r\n\t// with the biggest entityId\r\n\tconst minionThatWillDie = playerBoard\r\n\t\t.filter((m) => m.enchantments.some((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment))\r\n\t\t.sort(\r\n\t\t\t(a, b) =>\r\n\t\t\t\tb.enchantments.find((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment)\r\n\t\t\t\t\t.originEntityId -\r\n\t\t\t\t\ta.enchantments.find((e) => e.cardId === CardIds.RapidReanimation_ImpendingDeathEnchantment)\r\n\t\t\t\t\t\t.originEntityId || b.entityId - a.entityId,\r\n\t\t)[0];\r\n\tif (minionThatWillDie) {\r\n\t\t// So this is a bit tricky (as all the stuff with indices...). Because in practice it's more likely that players use Rapid Reanimation\r\n\t\t// on minions that they want to die quickly, most of the time they will be placed\r\n\t\t// to the left of the board\r\n\t\t// So using a left-based index (usually 0) is more likely to be correct after minions spawn on the board\r\n\t\t// Update: this looks like it's not the case, and looking at\r\n\t\t// http://replays.firestoneapp.com/?reviewId=2e6b389f-d904-43a2-a7cd-928a60d973ce&turn=11&action=1\r\n\t\t// the index seems to be right-based at least in some cases\r\n\t\t// Looks like even this is wrong:\r\n\t\t// http://replays.firestoneapp.com/?reviewId=9a46ab39-ccf0-478c-a010-68f2abb06c6f&turn=9&action=0\r\n\t\tconst rapidReanimationIndexFromLeft = playerBoard.indexOf(minionThatWillDie);\r\n\t\tplayerEntity.rapidReanimationIndexFromRight = playerBoard.length - 1 - rapidReanimationIndexFromLeft;\r\n\t\tconst minionToCopy = {\r\n\t\t\t...minionThatWillDie,\r\n\t\t\tenchantments: minionThatWillDie.enchantments.map((e) => ({ ...e })) ?? [],\r\n\t\t\tpendingAttackBuffs: [],\r\n\t\t} as BoardEntity;\r\n\t\tremoveAurasFromSelf(minionToCopy, playerBoard, playerEntity, gameState);\r\n\t\tplayerEntity.rapidReanimationMinion = minionToCopy;\r\n\t\tminionThatWillDie.definitelyDead = true;\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tplayerEntity,\r\n\t\t\tminionThatWillDie,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\topponentEntity,\r\n\t\t);\r\n\t\treturn true;\r\n\t}\r\n\treturn false;\r\n};\r\n\r\nconst handleWaxWarbandForPlayer = (\r\n\tplayerBoard: BoardEntity[],\r\n\tplayerEntity: BgsPlayerEntity,\r\n\topponentBoard: BoardEntity[],\r\n\topponentEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (playerBoard.length > 0) {\r\n\t\tconst boardWithTribes = playerBoard.filter(\r\n\t\t\t(e) => !!getEffectiveTribesForEntity(e, playerEntity, gameState.allCards).length,\r\n\t\t);\r\n\t\tconst boardWithoutAll = boardWithTribes.filter(\r\n\t\t\t(e) => !gameState.allCards.getCard(e.cardId).races?.includes(Race[Race.ALL]),\r\n\t\t);\r\n\t\tconst selectedMinions = selectMinions(boardWithoutAll, ALL_BG_RACES, gameState.allCards);\r\n\t\tconst allMinions = [\r\n\t\t\t...selectedMinions,\r\n\t\t\t...boardWithTribes.filter((e) => gameState.allCards.getCard(e.cardId).races?.includes(Race[Race.ALL])),\r\n\t\t];\r\n\t\tallMinions.forEach((e) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\te,\r\n\t\t\t\tgameState.cardsData.getTavernLevel(e.cardId),\r\n\t\t\t\tgameState.cardsData.getTavernLevel(e.cardId),\r\n\t\t\t\tplayerBoard,\r\n\t\t\t\tplayerEntity,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(playerEntity, e, playerBoard, playerEntity, opponentEntity);\r\n\t\t});\r\n\t}\r\n};\r\n\r\n// Not perfect, as I don't think this solves the issue where some cards are mutually exclusive\r\nconst selectMinions = (minions: BoardEntity[], tribes: Race[], allCards: AllCardsService): BoardEntity[] => {\r\n\t// Step 1\r\n\tconst minionsByTribe: { [tribe: string]: BoardEntity[] } = {};\r\n\tfor (const minion of minions) {\r\n\t\tfor (const tribe of allCards.getCard(minion.cardId).races ?? []) {\r\n\t\t\tif (!minionsByTribe[tribe]) {\r\n\t\t\t\tminionsByTribe[tribe] = [];\r\n\t\t\t}\r\n\t\t\tminionsByTribe[tribe].push(minion);\r\n\t\t}\r\n\t}\r\n\tfor (const tribe of ALL_BG_RACES) {\r\n\t\tminionsByTribe[tribe] = shuffleArray(minionsByTribe[Race[tribe]] ?? []);\r\n\t}\r\n\r\n\tconst selectedMinions: BoardEntity[] = [];\r\n\r\n\t// Step 3\r\n\tfor (const tribe of tribes) {\r\n\t\tif (minionsByTribe[tribe]) {\r\n\t\t\tminionsByTribe[tribe].sort(\r\n\t\t\t\t(a, b) => allCards.getCard(a.cardId).races.length - allCards.getCard(b.cardId).races.length,\r\n\t\t\t);\r\n\t\t\tfor (const minion of minionsByTribe[tribe]) {\r\n\t\t\t\tif (!selectedMinions.includes(minion)) {\r\n\t\t\t\t\tselectedMinions.push(minion);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// Step 4\r\n\treturn selectedMinions;\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\tgameState: FullGameState,\r\n): number => {\r\n\tif (playerEntity.startOfCombatDone || playerEntity.hpLeft <= 0) {\r\n\t\treturn currentAttacker;\r\n\t}\r\n\t// eslint-disable-next-line prefer-const\r\n\tlet shouldRecomputeCurrentAttacker = false;\r\n\tconst playerHeroPowerId = playerEntity.heroPowerId || getHeroPowerForHero(playerEntity.cardId);\r\n\t// TODO: should this recompute the first attack order?\r\n\tif (playerEntity.heroPowerUsed && playerHeroPowerId === CardIds.AimLeftToken) {\r\n\t\tconst target = opponentBoard[0];\r\n\t\tconst damageDone = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(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 = dealDamageToMinion(\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.heroPowerInfo2 ?? 0,\r\n\t\t\tplayerBoard,\r\n\t\t\tplayerEntity,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\t// processMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, allCards, cardsData, sharedState, spectator);\r\n\t\tplayerEntity.deadEyeDamageDone = damageDone;\r\n\t}\r\n\tprocessMinionDeath(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);\r\n\tif (shouldRecomputeCurrentAttacker) {\r\n\t\tconst previousCurrentAttacker = currentAttacker;\r\n\t\tcurrentAttacker =\r\n\t\t\tplayerBoard.length > opponentBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 0\r\n\t\t\t\t\t: 1\r\n\t\t\t\t: opponentBoard.length > playerBoard.length\r\n\t\t\t\t? friendly\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0\r\n\t\t\t\t: currentAttacker;\r\n\t\t// console.debug(\r\n\t\t// \t'recompting current attacker',\r\n\t\t// \tcurrentAttacker,\r\n\t\t// \tplayerBoard.length,\r\n\t\t// \topponentBoard.length,\r\n\t\t// \tpreviousCurrentAttacker,\r\n\t\t// \tstringifySimple(playerBoard, allCards),\r\n\t\t// \tstringifySimple(opponentBoard, allCards),\r\n\t\t// );\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.IllidanStormrage_TB_BaconShop_HERO_08:\r\n\t\t\treturn CardIds.Wingmen;\r\n\t\tcase CardIds.TheLichKing_TB_BaconShop_HERO_22:\r\n\t\t\treturn CardIds.RebornRites;\r\n\t\tcase CardIds.ProfessorPutricide_BG25_HERO_100:\r\n\t\t\treturn CardIds.RagePotion;\r\n\t\tcase CardIds.Deathwing_TB_BaconShop_HERO_52:\r\n\t\t\treturn CardIds.AllWillBurn;\r\n\t\tcase CardIds.TeronGorefiend_BG25_HERO_103:\r\n\t\t\treturn CardIds.TeronGorefiend_RapidReanimation;\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\t// Apparently, the board composition used for start of combat minion effects (like Red Whelp, and I assume it works the\r\n\t// same way for others like Prized Promo Drake or Mantid Queen) is the one that is used before Illidan's effect is handled.\r\n\t// Since this also runs before HP start of combat, we probably also use the state as it was before HP were triggered, like\r\n\t// Tamsin's Phylactery.\r\n\tattackingBoardBefore: BoardEntity[],\r\n\tdefendingBoardBefore: BoardEntity[],\r\n\tgameState: FullGameState,\r\n): boolean => {\r\n\tif (attackingBoardHero.startOfCombatDone) {\r\n\t\treturn false;\r\n\t}\r\n\tlet hasProcessed = true;\r\n\tif (attacker.cardId === CardIds.RedWhelp_BGS_019) {\r\n\t\tconst damage = attackingBoardBefore.filter((entity) =>\r\n\t\t\thasCorrectTribe(entity, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t).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\tgameState,\r\n\t\t);\r\n\t} else if (attacker.cardId === CardIds.RedWhelp_TB_BaconUps_102) {\r\n\t\tconst damage = attackingBoardBefore.filter((entity) =>\r\n\t\t\thasCorrectTribe(entity, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t).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\tgameState,\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\tgameState,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.PrizedPromoDrake_BG21_014 ||\r\n\t\tattacker.cardId === CardIds.PrizedPromoDrake_BG21_014_G\r\n\t) {\r\n\t\tconst stats = attacker.cardId === CardIds.PrizedPromoDrake_BG21_014_G ? 6 : 3;\r\n\t\tconst targets = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards));\r\n\t\tfor (const entity of targets) {\r\n\t\t\tmodifyStats(entity, stats, stats, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tentity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ChoralMrrrglr_BG26_354 ||\r\n\t\tattacker.cardId === CardIds.ChoralMrrrglr_BG26_354_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.ChoralMrrrglr_BG26_354_G ? 2 : 1;\r\n\t\tmodifyStats(\r\n\t\t\tattacker,\r\n\t\t\tmultiplier * attackingBoardHero.globalInfo?.ChoralAttackBuff,\r\n\t\t\tmultiplier * attackingBoardHero.globalInfo?.ChoralHealthBuff,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.AmberGuardian_BG24_500 ||\r\n\t\tattacker.cardId === CardIds.AmberGuardian_BG24_500_G\r\n\t) {\r\n\t\t// First try to get a target without divine shield, and if none is available, pick one with divine shield\r\n\t\tconst otherDragons = attackingBoard\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards))\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\tconst loops = attacker.cardId === CardIds.AmberGuardian_BG24_500_G ? 2 : 1;\r\n\t\tconst dragonsToConsider = otherDragons;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst otherDragon =\r\n\t\t\t\tpickRandom(dragonsToConsider.filter((e) => !e.divineShield)) ?? pickRandom(dragonsToConsider);\r\n\t\t\tif (otherDragon) {\r\n\t\t\t\tif (!otherDragon.divineShield) {\r\n\t\t\t\t\tupdateDivineShield(\r\n\t\t\t\t\t\totherDragon,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\ttrue,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tmodifyStats(otherDragon, 7, 7, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\totherDragon,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tdragonsToConsider.splice(dragonsToConsider.indexOf(otherDragon), 1);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.SanctumRester_BG26_356 ||\r\n\t\tattacker.cardId === CardIds.SanctumRester_BG26_356_G\r\n\t) {\r\n\t\tconst buff = attacker.cardId === CardIds.SanctumRester_BG26_356_G ? 16 : 8;\r\n\t\t// First try to get a target without divine shield, and if none is available, pick one with divine shield\r\n\t\tconst otherDragons = attackingBoard\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards))\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId);\r\n\t\totherDragons.forEach((otherDragon) => {\r\n\t\t\tmodifyStats(otherDragon, 0, buff, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\totherDragon,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Soulsplitter_BG25_023 ||\r\n\t\tattacker.cardId === CardIds.Soulsplitter_BG25_023_G\r\n\t) {\r\n\t\tconst numberOfTargets = attacker.cardId === CardIds.Soulsplitter_BG25_023_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst undeadsWithoutReborn = attackingBoard\r\n\t\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.UNDEAD, gameState.allCards))\r\n\t\t\t\t.filter((e) => !e.reborn);\r\n\t\t\tconst chosenUndead = pickRandom(undeadsWithoutReborn);\r\n\t\t\tif (chosenUndead) {\r\n\t\t\t\tchosenUndead.reborn = true;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tchosenUndead,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy ||\r\n\t\tattacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy_G\r\n\t) {\r\n\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\tconst multiplier = attacker.cardId === CardIds.Crabby_BG22_HERO_000_Buddy_G ? 2 : 1;\r\n\t\tneighbours.forEach((entity) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tentity,\r\n\t\t\t\tmultiplier * (attackingBoardHero.deadEyeDamageDone ?? 0),\r\n\t\t\t\tmultiplier * (attackingBoardHero.deadEyeDamageDone ?? 0),\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tentity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.CorruptedMyrmidon_BG23_012 ||\r\n\t\tattacker.cardId === CardIds.CorruptedMyrmidon_BG23_012_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.CorruptedMyrmidon_BG23_012_G ? 2 : 1;\r\n\t\tmodifyStats(\r\n\t\t\tattacker,\r\n\t\t\tmultiplier * attacker.attack,\r\n\t\t\tmultiplier * attacker.health,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.InterrogatorWhitemane_BG24_704 ||\r\n\t\tattacker.cardId === CardIds.InterrogatorWhitemane_BG24_704_G\r\n\t) {\r\n\t\tif (defendingBoard.length > 0) {\r\n\t\t\tconst validTargets = defendingBoard.filter((e) => gameState.cardsData.getTavernLevel(e.cardId) >= 5);\r\n\t\t\tconst numberOfPicks = attacker.cardId === CardIds.InterrogatorWhitemane_BG24_704_G ? 2 : 1;\r\n\t\t\tfor (let i = 0; i < numberOfPicks; i++) {\r\n\t\t\t\tconst target = pickRandom(validTargets);\r\n\t\t\t\tif (!!target) {\r\n\t\t\t\t\tcastImpure(target, attacker, attackingBoard, gameState.spectator);\r\n\t\t\t\t\tconst targetIndex = validTargets.findIndex((e) => e.entityId === target.entityId);\r\n\t\t\t\t\tvalidTargets.splice(targetIndex, 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (attacker.cardId === CardIds.MantidQueen_BG22_402 || attacker.cardId === CardIds.MantidQueen_BG22_402_G) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.MantidQueen_BG22_402_G ? 2 : 1;\r\n\t\tconst allRaces = attackingBoardBefore\r\n\t\t\t.map((entity) => entity.cardId)\r\n\t\t\t.flatMap((cardId) => gameState.allCards.getCard(cardId).races)\r\n\t\t\t.filter((race) => !!race && race !== Race[Race.BLANK]);\r\n\t\tconst totalRaces =\r\n\t\t\t[...new Set(allRaces.filter((race) => race !== Race[Race.ALL]))].length +\r\n\t\t\tallRaces.filter((race) => race === Race[Race.ALL]).length;\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tfor (let j = 0; j < totalRaces; j++) {\r\n\t\t\t\tconst buffType = getRandomMantidQueenBuffType(attacker);\r\n\t\t\t\tswitch (buffType) {\r\n\t\t\t\t\tcase 'stats':\r\n\t\t\t\t\t\tmodifyStats(attacker, 5, 5, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'reborn':\r\n\t\t\t\t\t\tattacker.reborn = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'taunt':\r\n\t\t\t\t\t\tattacker.taunt = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'windfury':\r\n\t\t\t\t\t\tattacker.windfury = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.CarbonicCopy_BG27_503 ||\r\n\t\tattacker.cardId === CardIds.CarbonicCopy_BG27_503_G\r\n\t) {\r\n\t\tconst numberOfCopies = attacker.cardId === CardIds.CarbonicCopy_BG27_503_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfCopies; i++) {\r\n\t\t\tif (!!attackingBoard.length && attackingBoard.length < 7) {\r\n\t\t\t\tconst copy: BoardEntity = {\r\n\t\t\t\t\t...attacker,\r\n\t\t\t\t\tlastAffectedByEntity: null,\r\n\t\t\t\t};\r\n\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\tcopy.cardId,\r\n\t\t\t\t\t1,\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\tgameState.allCards,\r\n\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\tattacker.friendly,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tcopy,\r\n\t\t\t\t);\r\n\t\t\t\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(attacker) + 1);\r\n\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\tnewMinions,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tcopy,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.DiremuckForager_BG27_556 ||\r\n\t\tattacker.cardId === CardIds.DiremuckForager_BG27_556_G\r\n\t) {\r\n\t\tconst potentialTargets = attackingBoardHero.hand\r\n\t\t\t.filter((e) => !!e.cardId)\r\n\t\t\t.filter((e) => gameState.allCards.getCard(e.cardId).type?.toUpperCase() === CardType[CardType.MINION])\r\n\t\t\t.filter((e) => !e.locked);\r\n\t\tif (potentialTargets.length > 0) {\r\n\t\t\tconst target = pickRandom(potentialTargets);\r\n\t\t\t// When it's the opponent, the game state already contains all the buffs\r\n\t\t\t// It can happen that, for the opponent, a card is first added to their hand (eg with Embrace Your Rage)\r\n\t\t\t// and then summoned by Diremuck. In that case, the stats need to be buffed\r\n\t\t\t// Update 29.2 18/04/2024: this is no longer the case, and the minions passed in the initial state should\r\n\t\t\t// reflect the values they have in hand\r\n\t\t\t// if (target?.friendly || !target?.inInitialState) {\r\n\t\t\tconst diremuckBuff = attacker.cardId === CardIds.DiremuckForager_BG27_556_G ? 4 : 2;\r\n\t\t\tmodifyStats(target, diremuckBuff, diremuckBuff, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\ttarget,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t\t// }\r\n\t\t\tif (attackingBoard.length < 7) {\r\n\t\t\t\ttarget.locked = true;\r\n\t\t\t\tconst newMinions = spawnEntities(\r\n\t\t\t\t\ttarget.cardId,\r\n\t\t\t\t\t1,\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\tgameState.allCards,\r\n\t\t\t\t\tgameState.cardsData,\r\n\t\t\t\t\tgameState.sharedState,\r\n\t\t\t\t\tgameState.spectator,\r\n\t\t\t\t\tattacker.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\t{ ...target } as BoardEntity,\r\n\t\t\t\t);\r\n\t\t\t\tfor (const s of newMinions) {\r\n\t\t\t\t\ts.onCanceledSummon = () => (target.locked = false);\r\n\t\t\t\t}\r\n\t\t\t\tperformEntitySpawns(\r\n\t\t\t\t\tnewMinions,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard.length - (attackingBoard.indexOf(attacker) + 1),\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.HawkstriderHerald_BG27_079 ||\r\n\t\tattacker.cardId === CardIds.HawkstriderHerald_BG27_079_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.HawkstriderHerald_BG27_079_G ? 2 : 1;\r\n\t\tfor (const entity of attackingBoard) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\thandleDeathrattles({\r\n\t\t\t\t\tgameState: gameState,\r\n\t\t\t\t\tplayerDeadEntities: attackingBoardHero.friendly ? [entity] : [],\r\n\t\t\t\t\tplayerDeadEntityIndexesFromRight: attackingBoardHero.friendly\r\n\t\t\t\t\t\t? [attackingBoard.length - 1 - attackingBoard.indexOf(entity)]\r\n\t\t\t\t\t\t: [],\r\n\t\t\t\t\topponentDeadEntities: attackingBoardHero.friendly ? [] : [entity],\r\n\t\t\t\t\topponentDeadEntityIndexesFromRight: attackingBoardHero.friendly\r\n\t\t\t\t\t\t? []\r\n\t\t\t\t\t\t: [attackingBoard.length - 1 - attackingBoard.indexOf(entity)],\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\t// console.debug('done triggering hawkstrider\\n\\n\\n');\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.AudaciousAnchor_BG28_904 ||\r\n\t\tattacker.cardId === CardIds.AudaciousAnchor_BG28_904_G\r\n\t) {\r\n\t\tconst iterations = attacker.cardId === CardIds.AudaciousAnchor_BG28_904_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < iterations; i++) {\r\n\t\t\tconst targets = findNearestEnemies(\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard.length - 1 - attackingBoard.indexOf(attacker),\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\t1,\r\n\t\t\t\tgameState.allCards,\r\n\t\t\t);\r\n\t\t\tif (!targets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (targets.length > 2) {\r\n\t\t\t\tconsole.error('Invalid number of targets', targets.length);\r\n\t\t\t}\r\n\r\n\t\t\tconst target = pickRandom(targets);\r\n\t\t\twhile (attacker.health > 0 && target.health > 0 && !attacker.definitelyDead && !target.definitelyDead) {\r\n\t\t\t\t// Attackers don't alternate\r\n\t\t\t\t// See http://replays.firestoneapp.com/?reviewId=f9f6bf62-db73-49ad-8187-d2f8848b7f36&turn=17&action=0\r\n\t\t\t\tdoFullAttack(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy ||\r\n\t\tattacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G\r\n\t) {\r\n\t\t// const iterations = attacker.cardId === CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G ? 2 : 1;\r\n\t\trememberDeathrattles(\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId !== CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy &&\r\n\t\t\t\t\te.cardId !== CardIds.PilotedWhirlOTron_BG21_HERO_030_Buddy_G,\r\n\t\t\t),\r\n\t\t\tgameState.cardsData,\r\n\t\t\tgameState.allCards,\r\n\t\t\tgameState.sharedState,\r\n\t\t);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.IrateRooster_BG29_990 ||\r\n\t\tattacker.cardId === CardIds.IrateRooster_BG29_990_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.IrateRooster_BG29_990_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst neighbours = getNeighbours(attackingBoard, attacker);\r\n\t\t\tfor (const neighbour of neighbours) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tdealDamageToMinion(\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t\tmodifyStats(neighbour, 4, 0, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.MisfitDragonling_BG29_814 ||\r\n\t\tattacker.cardId === CardIds.MisfitDragonling_BG29_814_G\r\n\t) {\r\n\t\tconst multiplier = attacker.cardId === CardIds.MisfitDragonling_BG29_814_G ? 2 : 1;\r\n\t\tconst tier = attackingBoardHero.tavernTier;\r\n\t\tconst stats = multiplier * tier;\r\n\t\tmodifyStats(attacker, stats, stats, attackingBoard, attackingBoardHero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tattacker,\r\n\t\t\tattacker,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoardHero,\r\n\t\t);\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ThousandthPaperDrake_BG29_810 ||\r\n\t\tattacker.cardId === CardIds.ThousandthPaperDrake_BG29_810_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.ThousandthPaperDrake_BG29_810_G ? 2 : 1;\r\n\t\tconst pickedTargets = [];\r\n\t\tconst dragons = attackingBoard.filter((e) =>\r\n\t\t\thasCorrectTribe(e, attackingBoardHero, Race.DRAGON, gameState.allCards),\r\n\t\t);\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst target = dragons.filter((e) => !pickedTargets.includes(e))[0];\r\n\t\t\tif (!!target) {\r\n\t\t\t\tmodifyStats(target, 1, 2, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\ttarget.windfury = true;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t\tpickedTargets.push(target);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.YulonFortuneGranter_BG29_811 ||\r\n\t\tattacker.cardId === CardIds.YulonFortuneGranter_BG29_811_G\r\n\t) {\r\n\t\tconst loops = attacker.cardId === CardIds.YulonFortuneGranter_BG29_811_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\tconst candidateBoard = attackingBoard\r\n\t\t\t\t.filter((e) => !isGolden(e.cardId, gameState.allCards))\r\n\t\t\t\t.filter(\r\n\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\te.cardId !== CardIds.YulonFortuneGranter_BG29_811 &&\r\n\t\t\t\t\t\te.cardId !== CardIds.YulonFortuneGranter_BG29_811_G,\r\n\t\t\t\t);\r\n\t\t\t// Because we pick one at random from all the ones that have the lowest tier\r\n\t\t\tconst randomBoard = shuffleArray(candidateBoard);\r\n\t\t\tconst candidates = randomBoard.sort(\r\n\t\t\t\t(a, b) => gameState.cardsData.getTavernLevel(a.cardId) - gameState.cardsData.getTavernLevel(b.cardId),\r\n\t\t\t);\r\n\t\t\tconst target = candidates[0];\r\n\t\t\tif (!!target) {\r\n\t\t\t\tmakeMinionGolden(target, attacker, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.HoardingHatespawn_BG29_872 ||\r\n\t\tattacker.cardId === CardIds.HoardingHatespawn_BG29_872_G\r\n\t) {\r\n\t\tconst stats = attacker.cardId === CardIds.HoardingHatespawn_BG29_872_G ? 20 : 10;\r\n\t\tconst target = getRandomMinionWithHighestHealth(defendingBoard);\r\n\t\tif (!!target) {\r\n\t\t\tconst previousAttack = target.attack;\r\n\t\t\tconst previousHealth = target.health;\r\n\t\t\ttarget.attack = Math.max(0, target.attack - stats);\r\n\t\t\ttarget.health = Math.max(0, target.health - stats);\r\n\t\t\ttarget.maxHealth = Math.max(0, target.maxHealth - stats);\r\n\t\t\tmodifyStats(\r\n\t\t\t\tattacker,\r\n\t\t\t\tpreviousAttack - target.attack,\r\n\t\t\t\tpreviousHealth - target.health,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\ttarget,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875 ||\r\n\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875_G\r\n\t) {\r\n\t\tconst targetEnchantment =\r\n\t\t\tattacker.cardId === CardIds.TheUninvitedGuest_BG29_875_G\r\n\t\t\t\t? CardIds.TheUninvitedGuest_UninvitedEnchantment_BG29_875_Ge\r\n\t\t\t\t: CardIds.TheUninvitedGuest_UninvitedEnchantment_BG29_875e;\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId != attacker.entityId)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\te.enchantments = e.enchantments || [];\r\n\t\t\t\tif (!e.enchantments.some((e) => e.cardId === targetEnchantment)) {\r\n\t\t\t\t\te.enchantments.push({\r\n\t\t\t\t\t\tcardId: targetEnchantment,\r\n\t\t\t\t\t\toriginEntityId: attacker.entityId,\r\n\t\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t} else if (attacker.cardId === CardIds.Sandy_BGDUO_125 || attacker.cardId === CardIds.Sandy_BGDUO_125_G) {\r\n\t\tconst teammateState = getTeammateInitialState(gameState.gameState, attackingBoardHero);\r\n\t\tif (teammateState?.board?.length) {\r\n\t\t\tconst isGolden = attacker.cardId === CardIds.Sandy_BGDUO_125_G;\r\n\t\t\tconst minionToCopy = getRandomMinionWithHighestHealth(teammateState.board);\r\n\t\t\tconst copy: BoardEntity = { ...minionToCopy, enchantments: [...minionToCopy.enchantments] };\r\n\t\t\tconst attackerIndex = attackingBoard.indexOf(attacker);\r\n\t\t\t// Insert the copy in its place\r\n\t\t\tattackingBoard.splice(attackerIndex, 0, copy);\r\n\t\t\tif (isGolden) {\r\n\t\t\t\tmakeMinionGolden(copy, copy, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);\r\n\t\t\t}\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy ||\r\n\t\tattacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy_G\r\n\t) {\r\n\t\tconst vaelastraszBonus = attacker.cardId === CardIds.Vaelastrasz_TB_BaconShop_HERO_56_Buddy_G ? 6 : 3;\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\tmodifyStats(e, vaelastraszBonus, vaelastraszBonus, attackingBoard, attackingBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattacker,\r\n\t\t\t\t\te,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy ||\r\n\t\tattacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy_G\r\n\t) {\r\n\t\tconst minionsOfDifferentTypes = getMinionsOfDifferentTypes(attackingBoard, attackingBoardHero, gameState);\r\n\t\tif (minionsOfDifferentTypes.length >= 4) {\r\n\t\t\tconst highestAttackOnBoard = Math.max(...attackingBoard.map((entity) => entity.attack));\r\n\t\t\tconst highestHealthOnBoard = Math.max(...attackingBoard.map((entity) => entity.health));\r\n\t\t\tconst multiplier = attacker.cardId === CardIds.ElderTaggawag_TB_BaconShop_HERO_14_Buddy_G ? 2 : 1;\r\n\t\t\tmodifyStats(\r\n\t\t\t\tattacker,\r\n\t\t\t\thighestAttackOnBoard * multiplier,\r\n\t\t\t\thighestHealthOnBoard * multiplier,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tattacker,\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (attacker.cardId === CardIds.SunScreener_BG30_101 || attacker.cardId === CardIds.SunScreener_BG30_101_G) {\r\n\t\tif (attackingBoard.length > 0 || defendingBoard.length > 0) {\r\n\t\t\tconst quantity = attacker.cardId === CardIds.SunScreener_BG30_101 ? 3 : 6;\r\n\t\t\tgrantDivineShieldToLeftmostMinions(\r\n\t\t\t\tattacker,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tquantity,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tgrantDivineShieldToLeftmostMinions(\r\n\t\t\t\tattacker,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tquantity,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t} else if (\r\n\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119 ||\r\n\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119_G\r\n\t) {\r\n\t\tattackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attacker.entityId)\r\n\t\t\t.filter((e) => hasCorrectTribe(e, attackingBoardHero, Race.PIRATE, gameState.allCards))\r\n\t\t\t.forEach((e) => {\r\n\t\t\t\te.enchantments = e.enchantments || [];\r\n\t\t\t\te.enchantments.push({\r\n\t\t\t\t\tcardId:\r\n\t\t\t\t\t\tattacker.cardId === CardIds.SkyPirateFlagbearer_BG30_119_G\r\n\t\t\t\t\t\t\t? CardIds.SkyPirateFlagbearer_FlagbearingEnchantment_BG30_119_Ge\r\n\t\t\t\t\t\t\t: CardIds.SkyPirateFlagbearer_FlagbearingEnchantment_BG30_119e,\r\n\t\t\t\t\toriginEntityId: attacker.entityId,\r\n\t\t\t\t\ttiming: gameState.sharedState.currentEntityId++,\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t} else {\r\n\t\thasProcessed = false;\r\n\t}\r\n\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);\r\n\treturn hasProcessed;\r\n};\r\n\r\nconst applyAllWillBurn = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tsourceEntity: BgsPlayerEntity | BoardEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tfor (const entity of board1) {\r\n\t\tmodifyStats(entity, 2, 0, board1, board1Hero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(sourceEntity, entity, board1, null, null);\r\n\t}\r\n\tfor (const entity of board2) {\r\n\t\tmodifyStats(entity, 2, 0, board2, board1Hero, gameState);\r\n\t\tgameState.spectator.registerPowerTarget(sourceEntity, entity, board2, null, null);\r\n\t}\r\n};\r\n\r\nconst castImpure = (entity: BoardEntity, source: BoardEntity, board: BoardEntity[], spectator: Spectator) => {\r\n\tif (!entity) {\r\n\t\treturn;\r\n\t}\r\n\tconst multiplier = source.cardId === CardIds.InterrogatorWhitemane_BG24_704_G ? 3 : 2;\r\n\tentity.taunt = true;\r\n\tentity.damageMultiplier = entity.damageMultiplier ?? 1;\r\n\tentity.damageMultiplier *= multiplier;\r\n\tspectator.registerPowerTarget(source, entity, board, null, null);\r\n};\r\n\r\nconst getRandomMantidQueenBuffType = (entity: BoardEntity): 'stats' | 'reborn' | 'windfury' | 'taunt' => {\r\n\tconst possibilities: ('stats' | 'reborn' | 'windfury' | 'taunt')[] = ['stats'];\r\n\tif (!entity.reborn) {\r\n\t\tpossibilities.push('reborn');\r\n\t}\r\n\tif (!entity.windfury) {\r\n\t\tpossibilities.push('windfury');\r\n\t}\r\n\tif (!entity.taunt) {\r\n\t\tpossibilities.push('taunt');\r\n\t}\r\n\treturn pickRandom(possibilities);\r\n};\r\n"]}
@@ -37,6 +37,7 @@ const modifyStats = (entity, attackAmount, healthAmount, friendlyBoard, friendly
37
37
  const realHealthAmount = healthAmount * poetMultipliers * tarecgosaMultiplier;
38
38
  entity.attack = Math.max(0, entity.attack + realAttackAmount);
39
39
  entity.previousAttack = entity.attack;
40
+ entity.pendingAttackBuffs = entity.pendingAttackBuffs || [];
40
41
  entity.pendingAttackBuffs.push(realAttackAmount);
41
42
  entity.health += realHealthAmount;
42
43
  if (realAttackAmount > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/simulation/stats.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,o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MAAM,mCAAyD,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { addStatsToBoard, hasCorrectTribe } from '../utils';\r\nimport { applyAurasToSelf } from './add-minion-to-board';\r\nimport { getNeighbours } from './attack';\r\nimport { FullGameState, PlayerState } from './internal-game-state';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const setEntityStats = (\r\n\tentity: BoardEntity,\r\n\tattack: number | null,\r\n\thealth: number | null,\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (attack !== null) {\r\n\t\tentity.attack = attack;\r\n\t\tentity.maxAttack = attack;\r\n\t}\r\n\tif (health !== null) {\r\n\t\tentity.health = health;\r\n\t\tentity.maxHealth = health;\r\n\t}\r\n\tapplyAurasToSelf(entity, board, boardHero, gameState);\r\n};\r\n\r\nexport const modifyStats = (\r\n\tentity: BoardEntity,\r\n\tattackAmount: number,\r\n\thealthAmount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\tspectator: Spectator = null,\r\n): void => {\r\n\tif (attackAmount === 0 && healthAmount === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tif (entity.cardId === CardIds.LocPrince_BG29_889 || entity.cardId === CardIds.LocPrince_BG29_889_G) {\r\n\t\tconst buff = entity.cardId === CardIds.LocPrince_BG29_889_G ? 4 : 2;\r\n\t\tattackAmount += buff;\r\n\t\thealthAmount += buff;\r\n\t}\r\n\r\n\tconst otherBoardHero: BgsPlayerEntity =\r\n\t\tgameState.gameState.player.player === friendlyBoardHero\r\n\t\t\t? gameState.gameState.opponent.player\r\n\t\t\t: gameState.gameState.player.player;\r\n\r\n\tconst neighbours = getNeighbours(friendlyBoard, entity);\r\n\tconst poetMultipliers = neighbours.filter((e) => e.cardId === CardIds.PersistentPoet_BG29_813_G).length * 2 || 1;\r\n\tconst tarecgosaMultiplier = entity.cardId === CardIds.Tarecgosa_BG21_015_G ? 2 : 1;\r\n\r\n\tconst realAttackAmount = attackAmount * poetMultipliers * tarecgosaMultiplier;\r\n\tconst realHealthAmount = healthAmount * poetMultipliers * tarecgosaMultiplier;\r\n\r\n\tentity.attack = Math.max(0, entity.attack + realAttackAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tentity.pendingAttackBuffs.push(realAttackAmount);\r\n\tentity.health += realHealthAmount;\r\n\r\n\tif (realAttackAmount > 0) {\r\n\t\tentity.maxAttack += realAttackAmount;\r\n\t\tif (hasCorrectTribe(entity, friendlyBoardHero, Race.DRAGON, gameState.allCards)) {\r\n\t\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t\t\t);\r\n\t\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t\t\t\tmodifyStats(entity, 0, buff, friendlyBoard, friendlyBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsmuggler,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\r\n\t\t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t\t\t\t);\r\n\t\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t\t\t\t\t// This is never called?\r\n\t\t\t\t\t(e) => {\r\n\t\t\t\t\t\te.attack += multiplier * realAttackAmount;\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\tstormbringer,\r\n\t\t\t\t\t\t\tentity,\r\n\t\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t};\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Sinestra\r\n\t\tfriendlyBoard\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy ||\r\n\t\t\t\t\te.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy_G,\r\n\t\t\t)\r\n\t\t\t.forEach((sinestra) => {\r\n\t\t\t\tconst buff = sinestra.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy_G ? 2 : 1;\r\n\t\t\t\tentity.health += buff;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsinestra,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\r\n\t\t// TODO: what happens if the Hunter is killed during the attack?\r\n\t\tif (\r\n\t\t\t[CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(\r\n\t\t\t\tentity.cardId as CardIds,\r\n\t\t\t)\r\n\t\t) {\r\n\t\t\taddStatsToBoard(\r\n\t\t\t\tentity,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t0,\r\n\t\t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (\r\n\t\t\tentity.cardId === CardIds.DefiantShipwright_BG21_018 ||\r\n\t\t\tentity.cardId === CardIds.DefiantShipwright_BG21_018_G\r\n\t\t) {\r\n\t\t\tconst stat = entity.cardId === CardIds.DefiantShipwright_BG21_018_G ? 2 : 1;\r\n\t\t\tentity.health += stat;\r\n\t\t}\r\n\t}\r\n\r\n\tif (realHealthAmount > 0) {\r\n\t\tentity.maxHealth += realHealthAmount;\r\n\t\tconst titanicGuardians = friendlyBoard\r\n\t\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t\t);\r\n\t\ttitanicGuardians.forEach((guardian) => {\r\n\t\t\tconst buff =\r\n\t\t\t\t(guardian.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) * realHealthAmount;\r\n\t\t\tif (buff > 0) {\r\n\t\t\t\tguardian.health += buff;\r\n\t\t\t\tguardian.maxHealth += buff;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAttackAmount,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realHealthAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tonStatsUpdate(entity, friendlyBoard, friendlyBoardHero, gameState);\r\n};\r\n\r\nconst onStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tonStatUpdateMinions(entity, friendlyBoard, friendlyHero, gameState);\r\n\tonStatUpdateQuests(entity, friendlyBoard, friendlyHero, gameState);\r\n};\r\n\r\nexport const applyAfterStatsUpdate = (gameState: FullGameState) => {\r\n\tfor (const entity of gameState.gameState.player.board) {\r\n\t\tapplyAfterStatsUpdateForEntity(entity, gameState.gameState.player, gameState.gameState.opponent, gameState);\r\n\t}\r\n\tfor (const entity of gameState.gameState.opponent.board) {\r\n\t\tapplyAfterStatsUpdateForEntity(entity, gameState.gameState.opponent, gameState.gameState.player, gameState);\r\n\t}\r\n};\r\n\r\nconst applyAfterStatsUpdateForEntity = (\r\n\tentity: BoardEntity,\r\n\tplayerState: PlayerState,\r\n\topponentState: PlayerState,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// Attack buffs\r\n\t// Actually this was a bug, and the stats update happen at the same time\r\n\t// Keeping the structure here in case it's useful in the future\r\n\t// for (const attackBuff of entity.pendingAttackBuffs) {\r\n\t// \tif (isCorrectTribe(gameState.allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t// \t\tconst whelpSmugglers = playerState.board.filter(\r\n\t// \t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t// \t\t);\r\n\t// \t\twhelpSmugglers.forEach((smuggler) => {\r\n\t// \t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t// \t\t\tmodifyHealth(entity, buff, playerState.board, playerState.player, gameState);\r\n\t// \t\t\tgameState.spectator.registerPowerTarget(\r\n\t// \t\t\t\tsmuggler,\r\n\t// \t\t\t\tentity,\r\n\t// \t\t\t\tplayerState.board,\r\n\t// \t\t\t\tplayerState.player,\r\n\t// \t\t\t\topponentState.player,\r\n\t// \t\t\t);\r\n\t// \t\t});\r\n\r\n\t// \t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t// \t\t\tconst stormbringers = playerState.board.filter(\r\n\t// \t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t// \t\t\t);\r\n\t// \t\t\tstormbringers.forEach((stormbringer) => {\r\n\t// \t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t// \t\t\t\t(e) => {\r\n\t// \t\t\t\t\tmodifyAttack(e, multiplier * attackBuff, playerState.board, playerState.player, gameState);\r\n\t// \t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t// \t\t\t\t\t\tstormbringer,\r\n\t// \t\t\t\t\t\tentity,\r\n\t// \t\t\t\t\t\tplayerState.board,\r\n\t// \t\t\t\t\t\tplayerState.player,\r\n\t// \t\t\t\t\t\topponentState.player,\r\n\t// \t\t\t\t\t);\r\n\t// \t\t\t\t};\r\n\t// \t\t\t});\r\n\t// \t\t}\r\n\t// \t}\r\n\r\n\t// \t// TODO: what happens if the Hunter is killed during the attack?\r\n\t// \tif (\r\n\t// \t\t[CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(\r\n\t// \t\t\tentity.cardId as CardIds,\r\n\t// \t\t)\r\n\t// \t) {\r\n\t// \t\taddStatsToBoard(\r\n\t// \t\t\tentity,\r\n\t// \t\t\tplayerState.board,\r\n\t// \t\t\tplayerState.player,\r\n\t// \t\t\t0,\r\n\t// \t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t// \t\t\tgameState,\r\n\t// \t\t);\r\n\t// \t}\r\n\t// }\r\n\tentity.pendingAttackBuffs = [];\r\n};\r\n\r\nconst onStatUpdateQuests = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst quests = hero.questEntities ?? [];\r\n\tif (!quests.length) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tfor (const quest of quests) {\r\n\t\tswitch (quest.CardId) {\r\n\t\t\tcase CardIds.FindTheMurderWeapon:\r\n\t\t\t\tonQuestProgressUpdated(hero, quest, board, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.PressureTheAuthorities:\r\n\t\t\t\tconst totalAttack = board.map((e) => e.attack).reduce((a, b) => a + b, 0);\r\n\t\t\t\tif (totalAttack >= 35) {\r\n\t\t\t\t\tonQuestProgressUpdated(hero, quest, board, gameState);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst onStatUpdateMinions = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, friendlyBoardHero, Race.ELEMENTAL, gameState.allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealities_BG21_036_G,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\ttentacle.attack += tentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1;\r\n\t\ttentacle.health += tentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1;\r\n\t});\r\n};\r\n"]}
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/simulation/stats.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,oCAA4D;AAC5D,+DAAyD;AACzD,qCAAyC;AAEzC,mCAAiD;AAG1C,MAAM,cAAc,GAAG,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mCAAyD,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { CardIds, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { addStatsToBoard, hasCorrectTribe } from '../utils';\r\nimport { applyAurasToSelf } from './add-minion-to-board';\r\nimport { getNeighbours } from './attack';\r\nimport { FullGameState, PlayerState } from './internal-game-state';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport const setEntityStats = (\r\n\tentity: BoardEntity,\r\n\tattack: number | null,\r\n\thealth: number | null,\r\n\tboard: BoardEntity[],\r\n\tboardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (attack !== null) {\r\n\t\tentity.attack = attack;\r\n\t\tentity.maxAttack = attack;\r\n\t}\r\n\tif (health !== null) {\r\n\t\tentity.health = health;\r\n\t\tentity.maxHealth = health;\r\n\t}\r\n\tapplyAurasToSelf(entity, board, boardHero, gameState);\r\n};\r\n\r\nexport const modifyStats = (\r\n\tentity: BoardEntity,\r\n\tattackAmount: number,\r\n\thealthAmount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\tspectator: Spectator = null,\r\n): void => {\r\n\tif (attackAmount === 0 && healthAmount === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tif (entity.cardId === CardIds.LocPrince_BG29_889 || entity.cardId === CardIds.LocPrince_BG29_889_G) {\r\n\t\tconst buff = entity.cardId === CardIds.LocPrince_BG29_889_G ? 4 : 2;\r\n\t\tattackAmount += buff;\r\n\t\thealthAmount += buff;\r\n\t}\r\n\r\n\tconst otherBoardHero: BgsPlayerEntity =\r\n\t\tgameState.gameState.player.player === friendlyBoardHero\r\n\t\t\t? gameState.gameState.opponent.player\r\n\t\t\t: gameState.gameState.player.player;\r\n\r\n\tconst neighbours = getNeighbours(friendlyBoard, entity);\r\n\tconst poetMultipliers = neighbours.filter((e) => e.cardId === CardIds.PersistentPoet_BG29_813_G).length * 2 || 1;\r\n\tconst tarecgosaMultiplier = entity.cardId === CardIds.Tarecgosa_BG21_015_G ? 2 : 1;\r\n\r\n\tconst realAttackAmount = attackAmount * poetMultipliers * tarecgosaMultiplier;\r\n\tconst realHealthAmount = healthAmount * poetMultipliers * tarecgosaMultiplier;\r\n\r\n\tentity.attack = Math.max(0, entity.attack + realAttackAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tentity.pendingAttackBuffs = entity.pendingAttackBuffs || [];\r\n\tentity.pendingAttackBuffs.push(realAttackAmount);\r\n\tentity.health += realHealthAmount;\r\n\r\n\tif (realAttackAmount > 0) {\r\n\t\tentity.maxAttack += realAttackAmount;\r\n\t\tif (hasCorrectTribe(entity, friendlyBoardHero, Race.DRAGON, gameState.allCards)) {\r\n\t\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t\t\t);\r\n\t\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t\t\t\tmodifyStats(entity, 0, buff, friendlyBoard, friendlyBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsmuggler,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\r\n\t\t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t\t\t\t);\r\n\t\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t\t\t\t\t// This is never called?\r\n\t\t\t\t\t(e) => {\r\n\t\t\t\t\t\te.attack += multiplier * realAttackAmount;\r\n\t\t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\t\t\tstormbringer,\r\n\t\t\t\t\t\t\tentity,\r\n\t\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t};\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Sinestra\r\n\t\tfriendlyBoard\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy ||\r\n\t\t\t\t\te.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy_G,\r\n\t\t\t)\r\n\t\t\t.forEach((sinestra) => {\r\n\t\t\t\tconst buff = sinestra.cardId === CardIds.LadySinestra_TB_BaconShop_HERO_52_Buddy_G ? 2 : 1;\r\n\t\t\t\tentity.health += buff;\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsinestra,\r\n\t\t\t\t\tentity,\r\n\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\r\n\t\t// TODO: what happens if the Hunter is killed during the attack?\r\n\t\tif (\r\n\t\t\t[CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(\r\n\t\t\t\tentity.cardId as CardIds,\r\n\t\t\t)\r\n\t\t) {\r\n\t\t\taddStatsToBoard(\r\n\t\t\t\tentity,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\t0,\r\n\t\t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t} else if (\r\n\t\t\tentity.cardId === CardIds.DefiantShipwright_BG21_018 ||\r\n\t\t\tentity.cardId === CardIds.DefiantShipwright_BG21_018_G\r\n\t\t) {\r\n\t\t\tconst stat = entity.cardId === CardIds.DefiantShipwright_BG21_018_G ? 2 : 1;\r\n\t\t\tentity.health += stat;\r\n\t\t}\r\n\t}\r\n\r\n\tif (realHealthAmount > 0) {\r\n\t\tentity.maxHealth += realHealthAmount;\r\n\t\tconst titanicGuardians = friendlyBoard\r\n\t\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t\t);\r\n\t\ttitanicGuardians.forEach((guardian) => {\r\n\t\t\tconst buff =\r\n\t\t\t\t(guardian.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) * realHealthAmount;\r\n\t\t\tif (buff > 0) {\r\n\t\t\t\tguardian.health += buff;\r\n\t\t\t\tguardian.maxHealth += buff;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAttackAmount,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realHealthAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tonStatsUpdate(entity, friendlyBoard, friendlyBoardHero, gameState);\r\n};\r\n\r\nconst onStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tonStatUpdateMinions(entity, friendlyBoard, friendlyHero, gameState);\r\n\tonStatUpdateQuests(entity, friendlyBoard, friendlyHero, gameState);\r\n};\r\n\r\nexport const applyAfterStatsUpdate = (gameState: FullGameState) => {\r\n\tfor (const entity of gameState.gameState.player.board) {\r\n\t\tapplyAfterStatsUpdateForEntity(entity, gameState.gameState.player, gameState.gameState.opponent, gameState);\r\n\t}\r\n\tfor (const entity of gameState.gameState.opponent.board) {\r\n\t\tapplyAfterStatsUpdateForEntity(entity, gameState.gameState.opponent, gameState.gameState.player, gameState);\r\n\t}\r\n};\r\n\r\nconst applyAfterStatsUpdateForEntity = (\r\n\tentity: BoardEntity,\r\n\tplayerState: PlayerState,\r\n\topponentState: PlayerState,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// Attack buffs\r\n\t// Actually this was a bug, and the stats update happen at the same time\r\n\t// Keeping the structure here in case it's useful in the future\r\n\t// for (const attackBuff of entity.pendingAttackBuffs) {\r\n\t// \tif (isCorrectTribe(gameState.allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t// \t\tconst whelpSmugglers = playerState.board.filter(\r\n\t// \t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t// \t\t);\r\n\t// \t\twhelpSmugglers.forEach((smuggler) => {\r\n\t// \t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t// \t\t\tmodifyHealth(entity, buff, playerState.board, playerState.player, gameState);\r\n\t// \t\t\tgameState.spectator.registerPowerTarget(\r\n\t// \t\t\t\tsmuggler,\r\n\t// \t\t\t\tentity,\r\n\t// \t\t\t\tplayerState.board,\r\n\t// \t\t\t\tplayerState.player,\r\n\t// \t\t\t\topponentState.player,\r\n\t// \t\t\t);\r\n\t// \t\t});\r\n\r\n\t// \t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t// \t\t\tconst stormbringers = playerState.board.filter(\r\n\t// \t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t// \t\t\t);\r\n\t// \t\t\tstormbringers.forEach((stormbringer) => {\r\n\t// \t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t// \t\t\t\t(e) => {\r\n\t// \t\t\t\t\tmodifyAttack(e, multiplier * attackBuff, playerState.board, playerState.player, gameState);\r\n\t// \t\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t// \t\t\t\t\t\tstormbringer,\r\n\t// \t\t\t\t\t\tentity,\r\n\t// \t\t\t\t\t\tplayerState.board,\r\n\t// \t\t\t\t\t\tplayerState.player,\r\n\t// \t\t\t\t\t\topponentState.player,\r\n\t// \t\t\t\t\t);\r\n\t// \t\t\t\t};\r\n\t// \t\t\t});\r\n\t// \t\t}\r\n\t// \t}\r\n\r\n\t// \t// TODO: what happens if the Hunter is killed during the attack?\r\n\t// \tif (\r\n\t// \t\t[CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(\r\n\t// \t\t\tentity.cardId as CardIds,\r\n\t// \t\t)\r\n\t// \t) {\r\n\t// \t\taddStatsToBoard(\r\n\t// \t\t\tentity,\r\n\t// \t\t\tplayerState.board,\r\n\t// \t\t\tplayerState.player,\r\n\t// \t\t\t0,\r\n\t// \t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t// \t\t\tgameState,\r\n\t// \t\t);\r\n\t// \t}\r\n\t// }\r\n\tentity.pendingAttackBuffs = [];\r\n};\r\n\r\nconst onStatUpdateQuests = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tconst quests = hero.questEntities ?? [];\r\n\tif (!quests.length) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tfor (const quest of quests) {\r\n\t\tswitch (quest.CardId) {\r\n\t\t\tcase CardIds.FindTheMurderWeapon:\r\n\t\t\t\tonQuestProgressUpdated(hero, quest, board, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.PressureTheAuthorities:\r\n\t\t\t\tconst totalAttack = board.map((e) => e.attack).reduce((a, b) => a + b, 0);\r\n\t\t\t\tif (totalAttack >= 35) {\r\n\t\t\t\t\tonQuestProgressUpdated(hero, quest, board, gameState);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst onStatUpdateMinions = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, friendlyBoardHero, Race.ELEMENTAL, gameState.allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealities_BG21_036_G,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyStats(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tfriendlyBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\ttentacle.attack += tentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1;\r\n\t\ttentacle.health += tentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1;\r\n\t});\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.475",
3
+ "version": "1.1.476",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "lint": "eslint --color --fix --ext .ts .",