@firestone-hs/simulate-bgs-battle 1.1.466 → 1.1.467
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.
- package/dist/simulation/attack.js +5 -1
- package/dist/simulation/attack.js.map +1 -1
- package/dist/simulation/start-of-combat.d.ts +1 -1
- package/dist/simulation/start-of-combat.js +35 -6
- package/dist/simulation/start-of-combat.js.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -201,10 +201,14 @@ const performAttack = (attackingEntity, defendingEntity, attackingBoard, attacki
|
|
|
201
201
|
}
|
|
202
202
|
if (attackingEntity.cleave) {
|
|
203
203
|
for (const neighbour of defenderNeighbours) {
|
|
204
|
-
|
|
204
|
+
const thisAttackDamage = (0, exports.bumpEntities)(neighbour, attackingEntity, defendingBoard, defendingBoardHero, attackingBoard, attackingBoardHero, gameState);
|
|
205
|
+
damageDoneByAttacker += thisAttackDamage;
|
|
205
206
|
if (attackingEntity.attack > 0 && neighbour.divineShield) {
|
|
206
207
|
(0, utils_2.updateDivineShield)(neighbour, defendingBoard, false, gameState.allCards);
|
|
207
208
|
}
|
|
209
|
+
if (thisAttackDamage > 0) {
|
|
210
|
+
(0, damage_effects_1.onEntityDamaged)(neighbour, defendingBoard, defendingBoardHero, attackingBoard, attackingBoardHero, thisAttackDamage, gameState);
|
|
211
|
+
}
|
|
208
212
|
if (neighbour.health <= 0 || neighbour.definitelyDead) {
|
|
209
213
|
(0, minion_kill_1.onMinionKill)(attackingEntity, neighbour, attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);
|
|
210
214
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attack.js","sourceRoot":"","sources":["../../src/simulation/attack.ts"],"names":[],"mappings":";;;AACA,iEAAwF;AAGxF,6CAAgE;AAChE,oCASkB;AAClB,mDAAiD;AACjD,qDAAmD;AACnD,+DAA+E;AAC/E,2EAAyG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7B,IAAI,eAAe,GAAG,IAAI,CAAC;IAC3B,IACC,CAAC,eAAe,GAAG,MAAA,kBAAkB,CAAC,OAAO,0CAAE,IAAI,CAClD,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,0BAAgC,CAC/E,CAAC,IAAI,IAAI,EACT;QACD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;YAC/B,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC;YACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC3B,MAAM,QAAQ,GAAG,IAAA,kBAAU,EAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;gBAC7D,iBAAiB,CAAC,IAAI,CACrB,GAAG,IAAA,kCAAa,EACf,QAAQ,EACR,CAAC,EACD,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,WAAW,EACrB,SAAS,CAAC,SAAS,EACnB,kBAAkB,CAAC,QAAQ,EAC3B,KAAK,CACL,CACD,CAAC;aACF;SACD;KACD;IACD,IAAA,4BAAmB,EAClB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,CAAC,EACD,UAAU,EACV,eAAe,EACf,SAAS,CACT,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, CardType, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport {\r\n\taddImpliedMechanics,\r\n\tgrantRandomStats,\r\n\tgrantStatsToMinionsOfEachType,\r\n\thasCorrectTribe,\r\n\tisFish,\r\n\tstringifySimple,\r\n\tstringifySimpleCard,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport { onEntityDamaged } from './damage-effects';\r\nimport { applyMonstrosity, rememberDeathrattles } from './deathrattle-effects';\r\nimport { orchestrateMinionDeathEffects, processDeathrattleForMinion } from './deathrattle-orchestration';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { getValidDeathrattles } from './deathrattle-utils';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { makeMinionsDie } from './minion-death';\r\nimport { onMinionKill } from './minion-kill';\r\nimport { applyOnAttackEffects } from './on-attack';\r\nimport { applyOnBeingAttackedBuffs } from './on-being-attacked';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { applyAfterStatsUpdate, modifyStats } from './stats';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\nimport { canAttack } from './utils/entity-utils';\r\n\r\n// Only use it to simulate actual attack. To simulate damage, or something similar, use bumpInto\r\nexport const simulateAttack = (\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// console.debug(\r\n\t// \t'\\nsimulating attack',\r\n\t// \tstringifySimple(attackingBoard, gameState.allCards),\r\n\t// \t'\\n',\r\n\t// \tstringifySimple(defendingBoard, gameState.allCards),\r\n\t// );\r\n\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst attackingEntity = getAttackingEntity(attackingBoard, gameState.allCards);\r\n\tif (attackingEntity) {\r\n\t\tattackingEntity.attacking = true;\r\n\t\t// Get the left entities now, otherwise things might break if the attacker dies and/or other\r\n\t\t// entities pop\r\n\t\tconst attackingEntityIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\tconst attackingEntitiesToTheLeft = attackingBoard.slice(0, attackingEntityIndex);\r\n\t\tconst isAttackingImmediately = attackingEntity.attackImmediately;\r\n\t\t// In case of Broodmother spawn, it spawns where the dead minion was, and has no influence on the\r\n\t\t// attack order\r\n\t\t// Situation this is trying to resolve by putting this right at the top of the loop:\r\n\t\t// - One scallywag attacks into another one, both die\r\n\t\t// - The first one attacks. To its left is a Harmless Bonehead with 1 HP. The scallywag attacks, and both scallys die\r\n\t\t// - The *other* sky pirate attacks first, and kills the bonehead. Two minions are spawned\r\n\t\t// - The first sy pirate attacks\r\n\t\t// - The initial loop is resolved. If this is at the end, the Harmless Bonehead is already dead, and not flagged\r\n\t\t// While having this right away, we immediately flag all minions to the left\r\n\t\tif (!isAttackingImmediately) {\r\n\t\t\t// Make sure they won't be able to attack until everyone has attacked\r\n\t\t\t// See http://replays.firestoneapp.com/?reviewId=a1b3066d-e806-44c1-ab4b-7ef9dbf9b5b9&turn=5&action=4\r\n\t\t\tattackingEntitiesToTheLeft.forEach((entity) => (entity.hasAttacked = 2));\r\n\t\t}\r\n\r\n\t\tconst numberOfAttacks = attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// We refresh the entity in case of windfury\r\n\t\t\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\t\t\t// We still want to flag the entity as having attacked, so that it doesn't attack again\r\n\t\t\t\t// after teammate switch in Duos\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t// Check that didn't die\r\n\t\t\tif (attackingBoard.find((entity) => entity.entityId === attackingEntity.entityId)) {\r\n\t\t\t\tconst defendingEntity: BoardEntity = getDefendingEntity(defendingBoard, attackingEntity);\r\n\t\t\t\t// Can happen with a single defender that has stealth\r\n\t\t\t\tif (defendingEntity) {\r\n\t\t\t\t\tdoFullAttack(\r\n\t\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Solves the edge case of Sky Pirate vs a stealth board\r\n\t\t\t\t\tattackingEntity.attackImmediately = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tattackingEntity.attacking = false;\r\n\t\tattackingEntity.hasAttacked = 1;\r\n\t}\r\n};\r\n\r\nexport const doFullAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tgameState.spectator.registerAttack(\r\n\t\tattackingEntity,\r\n\t\tdefendingEntity,\r\n\t\tattackingBoard,\r\n\t\tdefendingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoardHero,\r\n\t);\r\n\t// http://replays.firestoneapp.com/?reviewId=50576a9f-2e6a-4600-87ba-6e737ca9853e&turn=21&action=4\r\n\t// Looks like onBeingAttacked effects apply before onAttack effects\r\n\tapplyOnBeingAttackedBuffs(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tapplyOnAttackEffects(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tconst { damageDoneByAttacker, damageDoneByDefender } = performAttack(\r\n\t\tattackingEntity,\r\n\t\tdefendingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tapplyAfterAttackEffects(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoardHero,\r\n\t\tdamageDoneByAttacker,\r\n\t\tdamageDoneByDefender,\r\n\t\tgameState,\r\n\t);\r\n\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);\r\n\tapplyAfterStatsUpdate(gameState);\r\n\tattackingEntity.immuneWhenAttackCharges = Math.max(0, (attackingEntity.immuneWhenAttackCharges ?? 0) - 1);\r\n\tif (\r\n\t\tdefendingEntity.health > 0 &&\r\n\t\t!defendingEntity.definitelyDead &&\r\n\t\t(defendingEntity.cardId === CardIds.YoHoOgre_BGS_060 ||\r\n\t\t\tdefendingEntity.cardId === CardIds.YoHoOgre_TB_BaconUps_150)\r\n\t) {\r\n\t\tdefendingEntity.attackImmediately = true;\r\n\t\tif (defendingEntity.attackImmediately) {\r\n\t\t\tsimulateAttack(defendingBoard, defendingBoardHero, attackingBoard, attackingBoardHero, gameState);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst applyAfterAttackEffects = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageDoneByAttacker: number,\r\n\tdamageDoneByDefender: number,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tlet secretTriggered = null;\r\n\tif (\r\n\t\t(secretTriggered = defendingBoardHero.secrets?.find(\r\n\t\t\t(secret) => !secret.triggered && secret?.cardId === CardIds.Reckoning_TB_Bacon_Secrets_14,\r\n\t\t)) != null\r\n\t) {\r\n\t\t// console.log('triggering secret?', damageDoneByAttacker, stringifySimpleCard(attackingEntity, allCards));\r\n\t\tif (damageDoneByAttacker >= 3 && !(attackingEntity.health <= 0 || attackingEntity.definitelyDead)) {\r\n\t\t\tsecretTriggered.triggered = true;\r\n\t\t\tattackingEntity.definitelyDead = true;\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tsecretTriggered,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tif (attackingEntity.cardId === CardIds.Bonker_BG20_104 || attackingEntity.cardId === CardIds.Bonker_BG20_104_G) {\r\n\t\tconst quantity = attackingEntity.cardId === CardIds.Bonker_BG20_104_G ? 2 : 1;\r\n\t\tconst cards = quantity === 1 ? [CardIds.BloodGem] : [CardIds.BloodGem, CardIds.BloodGem];\r\n\t\taddCardsInHand(attackingBoardHero, attackingBoard, cards, gameState);\r\n\t} else if (attackingEntity.cardId === CardIds.Yrel_BG23_350 || attackingEntity.cardId === CardIds.Yrel_BG23_350_G) {\r\n\t\tconst modifier = attackingEntity.cardId === CardIds.Yrel_BG23_350_G ? 2 : 1;\r\n\t\tgrantStatsToMinionsOfEachType(\r\n\t\t\tattackingEntity,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tmodifier * 1,\r\n\t\t\tmodifier * 2,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117 ||\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117_G\r\n\t) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\t// Putricide-only\r\n\telse if (attackingEntity.additionalCards?.includes(CardIds.IncorporealCorporal_BG26_RLK_117)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tattackingBoard\r\n\t\t.filter((e) => e.additionalCards?.includes(CardIds.FesterootHulk_BG_GIL_655))\r\n\t\t.forEach((e) => {\r\n\t\t\tmodifyStats(e, 1, 0, attackingBoard, attackingBoardHero, gameState);\r\n\t\t});\r\n\r\n\tattackingEntity.stealth = false;\r\n\tapplyOnAttackQuest(attackingEntity, attackingBoard, attackingBoardHero, gameState);\r\n};\r\n\r\nconst applyOnAttackQuest = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst quests = attackingBoardHero.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.CrackTheCase:\r\n\t\t\t\tonQuestProgressUpdated(attackingBoardHero, quest, attackingBoard, gameState);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst performAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): { damageDoneByAttacker: number; damageDoneByDefender: number } => {\r\n\tlet damageDoneByAttacker = 0;\r\n\tlet damageDoneByDefender = 0;\r\n\r\n\tif (hasCorrectTribe(attackingEntity, Race.DRAGON, gameState.allCards)) {\r\n\t\tconst prestors = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attackingEntity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012 ||\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012_G,\r\n\t\t\t);\r\n\t\tprestors.forEach((prestor) => {\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tprestor,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tprestor,\r\n\t\t\t\tprestor.cardId === CardIds.PrestorsPyrospawn_BG21_012_G ? 6 : 3,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362 ||\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362_G\r\n\t) {\r\n\t\tconst targets = [defendingEntity, ...getNeighbours(defendingBoard, defendingEntity)];\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.Atramedes_BG23_362_G ? 2 : 1;\r\n\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\ttargets.forEach((target) => {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\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\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t}\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.Niuzao_BG27_822 ||\r\n\t\tattackingEntity.cardId === CardIds.Niuzao_BG27_822_G\r\n\t) {\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.Niuzao_BG27_822_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tconst target = pickRandom(defendingBoard.filter((e) => e.entityId != defendingEntity.entityId));\r\n\t\t\tif (target) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\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\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tattackingEntity.attack,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\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 ([CardIds.BabyKrush_BG22_001, CardIds.BabyKrush_BG22_001_G].includes(attackingEntity.cardId as CardIds)) {\r\n\t\tconst spawns = spawnEntities(\r\n\t\t\tattackingEntity.cardId === CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t? CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t: CardIds.BabyKrush_DevilsaurToken,\r\n\t\t\t1,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tgameState.allCards,\r\n\t\t\tgameState.cardsData,\r\n\t\t\tgameState.sharedState,\r\n\t\t\tgameState.spectator,\r\n\t\t\ttrue,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tif (spawns.length > 0) {\r\n\t\t\tconst sourceIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\t\tconst actualSpawns = performEntitySpawns(\r\n\t\t\t\tspawns,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tsourceIndex,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tfor (const actualSpawn of actualSpawns) {\r\n\t\t\t\tif (defendingEntity.health > 0 && !defendingEntity.definitelyDead) {\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tactualSpawn,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// For Prestor\r\n\tconst defenderAliveBeforeAttack = defendingEntity.health > 0 && !defendingEntity.definitelyDead;\r\n\t// Because of Bristleback Knight, which changes its divine shield status during bumpEntities\r\n\tconst attackerHadDivineShield = attackingEntity.divineShield;\r\n\tconst defenderHadDivineShield = defendingEntity.divineShield;\r\n\t// For cleave\r\n\t// We do that now so that we don't include entities that spawn on entity damaged\r\n\tconst defenderNeighbours: readonly BoardEntity[] = getNeighbours(defendingBoard, defendingEntity);\r\n\tif (defenderAliveBeforeAttack) {\r\n\t\tif (!attackingEntity.immuneWhenAttackCharges) {\r\n\t\t\t// TODO: this bumpEntities approach doesn't work well, as it leads to code duplication\r\n\t\t\tdamageDoneByDefender += bumpEntities(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tdamageDoneByAttacker += bumpEntities(\r\n\t\t\tdefendingEntity,\r\n\t\t\tattackingEntity,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tif (defendingEntity.attack > 0 && attackerHadDivineShield && !attackingEntity.immuneWhenAttackCharges) {\r\n\t\t\tupdateDivineShield(attackingEntity, attackingBoard, false, gameState.allCards);\r\n\t\t}\r\n\t\tif (attackingEntity.attack > 0 && defenderHadDivineShield) {\r\n\t\t\tupdateDivineShield(defendingEntity, defendingBoard, false, gameState.allCards);\r\n\t\t}\r\n\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t// cause wrong results to happen\r\n\t\t// This whole logic is a MEEEEESSSSSSSSSSSSSSS\r\n\t\tif (damageDoneByDefender > 0) {\r\n\t\t\tonEntityDamaged(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tdamageDoneByDefender,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (damageDoneByAttacker > 0) {\r\n\t\t\tonEntityDamaged(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdamageDoneByAttacker,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (defendingEntity.health <= 0 || defendingEntity.definitelyDead) {\r\n\t\t\tonMinionKill(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (attackingEntity.health <= 0 || attackingEntity.definitelyDead) {\r\n\t\t\tonMinionKill(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\t// Cleave\r\n\tif (attackingEntity.cleave) {\r\n\t\tfor (const neighbour of defenderNeighbours) {\r\n\t\t\tdamageDoneByAttacker += bumpEntities(\r\n\t\t\t\tneighbour,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t\t// cause wrong results to happen\r\n\t\t\tif (attackingEntity.attack > 0 && neighbour.divineShield) {\r\n\t\t\t\tupdateDivineShield(neighbour, defendingBoard, false, gameState.allCards);\r\n\t\t\t}\r\n\t\t\tif (neighbour.health <= 0 || neighbour.definitelyDead) {\r\n\t\t\t\tonMinionKill(\r\n\t\t\t\t\tattackingEntity,\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\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}\r\n\tif (\r\n\t\t(defendingEntity.health <= 0 || defendingEntity.definitelyDead) &&\r\n\t\t(attackingEntity.cardId === CardIds.WildfireElemental_BGS_126 ||\r\n\t\t\tattackingEntity.cardId === CardIds.WildfireElemental_TB_BaconUps_166)\r\n\t) {\r\n\t\tconst excessDamage = -defendingEntity.health;\r\n\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\tif (defenderNeighbours.length > 0) {\r\n\t\t\tif (attackingEntity.cardId === CardIds.WildfireElemental_BGS_126) {\r\n\t\t\t\tconst randomTarget = defenderNeighbours[Math.floor(Math.random() * defenderNeighbours.length)];\r\n\t\t\t\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\trandomTarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tdamageDoneByAttacker += defenderNeighbours\r\n\t\t\t\t\t.map((neighbour) =>\r\n\t\t\t\t\t\tdealDamageToMinion(\r\n\t\t\t\t\t\t\tneighbour,\r\n\t\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\t\t\texcessDamage,\r\n\t\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\t\tattackingBoardHero,\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\t.reduce((a, b) => a + b, 0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// After attack hooks\r\n\t// Arcane Cannon\r\n\t// Monstrous Macaw\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.MonstrousMacaw_BGS_078 ||\r\n\t\tattackingEntity.cardId === CardIds.MonstrousMacaw_TB_BaconUps_135\r\n\t) {\r\n\t\tconst loops = attackingEntity.cardId === CardIds.MonstrousMacaw_TB_BaconUps_135 ? 2 : 1;\r\n\t\tconst validDeathrattles = getValidDeathrattles(attackingBoard, gameState);\r\n\t\tconst leftMost = validDeathrattles[0];\r\n\t\tif (!!leftMost) {\r\n\t\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tleftMost,\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\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(leftMost) + 1);\r\n\t\t\t\tprocessDeathrattleForMinion(\r\n\t\t\t\t\tleftMost,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t[leftMost],\r\n\t\t\t\t\tleftMost.friendly ? gameState.gameState.player : gameState.gameState.opponent,\r\n\t\t\t\t\tleftMost.friendly ? gameState.gameState.opponent : gameState.gameState.player,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tattackingEntity.attackImmediately = false;\r\n\tif (attackingEntity.enchantments.some((e) => e.cardId === CardIds.VolatileVenom_VolatileEnchantment)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\treturn { damageDoneByAttacker, damageDoneByDefender };\r\n};\r\n\r\nconst triggerRandomDeathrattle = (\r\n\tsourceEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst validDeathrattles = getValidDeathrattles(attackingBoard, gameState).filter(\r\n\t\t(entity) => !excludeSource || entity.entityId !== sourceEntity.entityId,\r\n\t);\r\n\tif (validDeathrattles.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst targetEntity = pickRandom(validDeathrattles);\r\n\tif (!targetEntity?.cardId) {\r\n\t\tconsole.error(\r\n\t\t\t'missing card id when triggering random deathrattle',\r\n\t\t\tstringifySimpleCard(targetEntity, gameState.allCards),\r\n\t\t\ttargetEntity,\r\n\t\t\tvalidDeathrattles.length,\r\n\t\t\tstringifySimple(validDeathrattles, gameState.allCards),\r\n\t\t\tstringifySimple(attackingBoard, gameState.allCards),\r\n\t\t\texcludeSource,\r\n\t\t\tstringifySimpleCard(sourceEntity, gameState.allCards),\r\n\t\t);\r\n\t}\r\n\tgameState.spectator.registerPowerTarget(\r\n\t\tsourceEntity,\r\n\t\ttargetEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoardHero,\r\n\t);\r\n\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(targetEntity) + 1);\r\n\r\n\tprocessDeathrattleForMinion(\r\n\t\ttargetEntity,\r\n\t\tindexFromRight,\r\n\t\t[targetEntity],\r\n\t\ttargetEntity.friendly ? gameState.gameState.player : gameState.gameState.opponent,\r\n\t\ttargetEntity.friendly ? gameState.gameState.opponent : gameState.gameState.player,\r\n\t\tgameState,\r\n\t\tfalse,\r\n\t);\r\n\t// The reborn minion spawns to the right of the DR spawns\r\n\t// buildBoardAfterRebornSpawns(\r\n\t// \tattackingBoard,\r\n\t// \tattackingBoardHero,\r\n\t// \ttargetEntity,\r\n\t// \tindexFromRight,\r\n\t// \tdefendingBoard,\r\n\t// \tdefendingBoardHero,\r\n\t// \tallCards,\r\n\t// \tspawns,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nconst getAttackingEntity = (attackingBoard: BoardEntity[], allCards: AllCardsService): BoardEntity => {\r\n\tconst debug = attackingBoard.map((e) => ({\r\n\t\tname: allCards.getCard(e.cardId)?.name,\r\n\t\tattacked: e.hasAttacked,\r\n\t\tentityId: e.entityId,\r\n\t\treborn: e.reborn,\r\n\t}));\r\n\tlet validAttackers = attackingBoard.filter((entity) => canAttack(entity));\r\n\tif (validAttackers.length === 0) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\t// console.debug(\r\n\t// \t'\\nvalid attackers',\r\n\t// \tstringifySimple(validAttackers, allCards),\r\n\t// \tstringifySimple(attackingBoard, allCards),\r\n\t// );\r\n\r\n\tif (validAttackers.some((entity) => entity.attackImmediately)) {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => entity.attackImmediately);\r\n\t} else if (validAttackers.every((e) => e.hasAttacked)) {\r\n\t\tattackingBoard.forEach((e) => (e.hasAttacked = 0));\r\n\t} else {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => !entity.hasAttacked);\r\n\t}\r\n\tconst attacker = validAttackers[0];\r\n\t// console.debug('\\t attacker', stringifySimpleCard(attacker, allCards));\r\n\treturn attacker;\r\n};\r\n\r\nexport const findNearestEnemies = (\r\n\tattackingBoard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tentityIndexFromRight: number,\r\n\tdefendingBoard: BoardEntity[],\r\n\tnumberOfTargets: number,\r\n\tallCards: AllCardsService,\r\n): BoardEntity[] => {\r\n\tconst result = [];\r\n\tif (defendingBoard.length > 0) {\r\n\t\t// console.debug('defending board', numberOfTargets, stringifySimple(defendingBoard, allCards));\r\n\t\tconst attackerIndex = attackingBoard.length - entityIndexFromRight - 1;\r\n\t\tconst targetIndex = attackerIndex - (attackingBoard.length - defendingBoard.length) / 2;\r\n\t\t// console.debug('indexes', attackerIndex, entityIndexFromRight, targetIndex, attackingBoard.length);\r\n\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst possibleTargets = defendingBoard\r\n\t\t\t\t.filter((e) => !e.definitelyDead && e.health > 0)\r\n\t\t\t\t.filter((e) => !result.includes(e));\r\n\t\t\t// console.debug('possibleTargets', stringifySimple(possibleTargets, allCards));\r\n\t\t\tif (!possibleTargets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tconst targetGroups = groupByFunction((e: BoardEntity) => Math.abs(defendingBoard.indexOf(e) - targetIndex))(\r\n\t\t\t\tpossibleTargets,\r\n\t\t\t);\r\n\t\t\tconst distances = Object.keys(targetGroups)\r\n\t\t\t\t.map((k) => +k)\r\n\t\t\t\t.sort();\r\n\t\t\tconst nearestDistance = distances[0];\r\n\t\t\tif (nearestDistance != null) {\r\n\t\t\t\t// console.debug(\r\n\t\t\t\t// \t'targetGroups[nearestDistance]',\r\n\t\t\t\t// \tnearestDistance,\r\n\t\t\t\t// \tstringifySimple(targetGroups[nearestDistance], allCards),\r\n\t\t\t\t// );\r\n\t\t\t\tconst target = pickRandom(targetGroups[nearestDistance]);\r\n\t\t\t\tresult.push(target);\r\n\t\t\t}\r\n\t\t\t// console.debug('\\n');\r\n\t\t}\r\n\t}\r\n\treturn result.filter((e) => !!e);\r\n};\r\n\r\nexport const getNeighbours = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\t// When triggering DR with Hawkstrider, the entity is still on the board\r\n\tif (deadEntityIndexFromRight != null && !board.includes(entity)) {\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\tneighbours.push(leftNeighbour);\r\n\t\t}\r\n\r\n\t\t// If the deadEntityIndexFromRight === 0 (right-most minion), no neighbour will be found\r\n\t\tconst rightNeighbourIndex = board.length - 1 - (deadEntityIndexFromRight - 1);\r\n\t\tconst rightNeighbour = board[rightNeighbourIndex];\r\n\t\tif (rightNeighbour) {\r\n\t\t\tneighbours.push(rightNeighbour);\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\tneighbours.push(board[index - 1]);\r\n\t\t}\r\n\t\t// neighbours.push(entity);\r\n\t\tif (index + 1 < board.length) {\r\n\t\t\tneighbours.push(board[index + 1]);\r\n\t\t}\r\n\t}\r\n\treturn neighbours;\r\n};\r\n\r\nexport const getLeftNeighbour = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): BoardEntity => {\r\n\t// When triggering DR with Hawkstrider, the entity is still on the board\r\n\tif (deadEntityIndexFromRight != null && !board.includes(entity)) {\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\treturn leftNeighbour;\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\treturn board[index - 1];\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const dealDamageToRandomEnemy = (\r\n\tboardToBeDamaged: BoardEntity[],\r\n\tboardToBeDamagedHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (boardToBeDamaged.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst validTargets = boardToBeDamaged.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tconst defendingEntity: BoardEntity = pickRandom(validTargets);\r\n\tif (defendingEntity) {\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tdamageSource,\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t);\r\n\t\tdealDamageToMinion(\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tdamageSource,\r\n\t\t\tdamage,\r\n\t\t\tboardWithAttackOrigin,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const dealDamageToMinion = (\r\n\ttarget: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\t// console.log('dealing damage to', damage, stringifySimpleCard(defendingEntity, allCards));\r\n\tif (!target) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tconst isDeadBeforeDamage = target.definitelyDead || target.health <= 0;\r\n\tconst spawns = [];\r\n\t// Why do we use a fakeAttacker? Is that for the \"attacking\" prop?\r\n\t// That prop is only used for Overkill, and even in that case it looks like it would work\r\n\t// without it\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damage,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tconst actualDamageDone = bumpEntities(target, fakeAttacker, board, hero, otherBoard, otherHero, gameState);\r\n\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t// cause wrong results to happen\r\n\tif (fakeAttacker.attack > 0 && target.divineShield) {\r\n\t\tupdateDivineShield(target, board, false, gameState.allCards);\r\n\t}\r\n\tif (actualDamageDone > 0) {\r\n\t\t// TODO: handle entities that have been spawned here to adjust the dead entity index from parent stack\r\n\t\tconst newSpawns = onEntityDamaged(target, board, hero, otherBoard, otherHero, actualDamageDone, gameState);\r\n\t}\r\n\tif (!isDeadBeforeDamage && actualDamageDone > 0) {\r\n\t\ttarget.lastAffectedByEntity = damageSource;\r\n\r\n\t\tif (target.health <= 0 || target.definitelyDead) {\r\n\t\t\tonMinionKill(damageSource, target, otherBoard, otherHero, board, hero, gameState);\r\n\t\t}\r\n\t}\r\n\tconst defendingEntityIndex = board.map((entity) => entity.entityId).indexOf(target.entityId);\r\n\tboard[defendingEntityIndex] = target;\r\n\treturn actualDamageDone;\r\n};\r\n\r\nexport const getDefendingEntity = (\r\n\tdefendingBoard: BoardEntity[],\r\n\tattackingEntity: BoardEntity,\r\n\tignoreTaunts = false,\r\n): BoardEntity => {\r\n\t// if (attackingEntity.entityId === 4946) {\r\n\t// \tlet def = null;\r\n\t// \tif (!!(def = defendingBoard.find((e) => e.entityId === 7170))) {\r\n\t// \t\treturn def;\r\n\t// \t}\r\n\t// }\r\n\r\n\tlet possibleDefenders: readonly BoardEntity[];\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.ZappSlywick_BGS_022 ||\r\n\t\tattackingEntity.cardId === CardIds.ZappSlywick_TB_BaconUps_091\r\n\t) {\r\n\t\tconst minAttack = Math.min(...defendingBoard.map((entity) => entity.attack));\r\n\t\tpossibleDefenders = defendingBoard.filter((entity) => entity.attack === minAttack);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.WorgenVigilante_BG26_921 ||\r\n\t\tattackingEntity.cardId === CardIds.WorgenVigilante_BG26_921_G\r\n\t) {\r\n\t\tpossibleDefenders = defendingBoard\r\n\t\t\t.filter(\r\n\t\t\t\t(entity) =>\r\n\t\t\t\t\tentity.health <= attackingEntity.attack || attackingEntity.venomous || attackingEntity.poisonous,\r\n\t\t\t)\r\n\t\t\t.filter((e) => !e.divineShield);\r\n\t\tif (!possibleDefenders.length) {\r\n\t\t\tpossibleDefenders = defendingBoard;\r\n\t\t}\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard.filter((e) => !e.stealth);\r\n\t\tif (!ignoreTaunts) {\r\n\t\t\tconst taunts = possibleDefenders.filter((entity) => entity.taunt);\r\n\t\t\tpossibleDefenders = taunts.length > 0 ? taunts : possibleDefenders;\r\n\t\t}\r\n\t}\r\n\r\n\tlet chosenDefender = pickRandom(possibleDefenders);\r\n\tif (chosenDefender?.taunt) {\r\n\t\tconst elistras = defendingBoard.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_BGS_205 ||\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_TB_BaconUps_306,\r\n\t\t);\r\n\t\tif (elistras.length > 0) {\r\n\t\t\tchosenDefender = elistras[Math.floor(Math.random() * elistras.length)];\r\n\t\t}\r\n\t}\r\n\treturn chosenDefender;\r\n};\r\n\r\nexport const bumpEntities = (\r\n\tentity: BoardEntity,\r\n\tbumpInto: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\tapplyVenomous = true,\r\n): number => {\r\n\t// No attack has no impact\r\n\tif (bumpInto.attack === 0) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\t// Matador effect has priority\r\n\tif (\r\n\t\tentity.abiityChargesLeft > 0 &&\r\n\t\t(entity.cardId === CardIds.MadMatador_BG28_404 || entity.cardId === CardIds.MadMatador_BG28_404_G)\r\n\t) {\r\n\t\tentity.abiityChargesLeft--;\r\n\t\tconst newTarget = pickRandom(otherBoard);\r\n\t\tif (newTarget) {\r\n\t\t\tgameState.spectator.registerPowerTarget(entity, newTarget, otherBoard, entityBoardHero, otherHero);\r\n\t\t\t// TODO: here the MadMatador is the source of the damage, not the initial attacker\r\n\t\t\t// Not sure exactly what the impact would be, as there is no counter\r\n\t\t\tconst newSource = {\r\n\t\t\t\t...entity,\r\n\t\t\t\tattack: bumpInto.attack,\r\n\t\t\t\tattacking: true,\r\n\t\t\t} as BoardEntity;\r\n\t\t\tconst defenderHadDivineShield = newTarget.divineShield;\r\n\t\t\tconst damageDone = bumpEntities(\r\n\t\t\t\tnewTarget,\r\n\t\t\t\tnewSource,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero,\r\n\t\t\t\tentityBoard,\r\n\t\t\t\tentityBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t\tfalse,\r\n\t\t\t);\r\n\t\t\tif (newSource.attack > 0 && defenderHadDivineShield) {\r\n\t\t\t\tupdateDivineShield(newTarget, otherBoard, false, gameState.allCards);\r\n\t\t\t}\r\n\t\t\tif (damageDone > 0) {\r\n\t\t\t\tonEntityDamaged(newTarget, otherBoard, otherHero, entityBoard, entityBoardHero, damageDone, gameState);\r\n\t\t\t}\r\n\t\t\treturn damageDone;\r\n\t\t}\r\n\t}\r\n\r\n\tif (entity.divineShield) {\r\n\t\t// Handle all the divine shield loss effects here\r\n\t\tfor (let i = 0; i < entityBoard.length; i++) {\r\n\t\t\tif (entityBoard[i].cardId === CardIds.BolvarFireblood_ICC_858) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 2, 0, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.BolvarFireblood_TB_BaconUps_047) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 4, 0, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer_BGS_067) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 2, 2, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer_TB_BaconUps_117) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 4, 4, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].entityId !== entity.entityId &&\r\n\t\t\t\t(entityBoard[i].cardId === CardIds.HolyMecherel_BG20_401 ||\r\n\t\t\t\t\tentityBoard[i].cardId === CardIds.HolyMecherel_BG20_401_G)\r\n\t\t\t) {\r\n\t\t\t\tupdateDivineShield(entityBoard[i], entityBoard, true, gameState.allCards);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, [CardIds.BloodGem], gameState);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037_G) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, [CardIds.BloodGem, CardIds.BloodGem], gameState);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].cardId === CardIds.CogworkCopter_BG24_008 ||\r\n\t\t\t\tentityBoard[i].cardId === CardIds.CogworkCopter_BG24_008_G\r\n\t\t\t) {\r\n\t\t\t\t// When it's the opponent, the game state already contains all the buffs\r\n\t\t\t\tif (entityBoard[i]?.friendly) {\r\n\t\t\t\t\tconst buff = entityBoard[i].cardId === CardIds.CogworkCopter_BG24_008_G ? 2 : 1;\r\n\t\t\t\t\tgrantRandomStats(\r\n\t\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\t\tentityBoardHero.hand.filter(\r\n\t\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\t\tgameState.allCards.getCard(e.cardId).type?.toUpperCase() === CardType[CardType.MINION],\r\n\t\t\t\t\t\t),\r\n\t\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\t\tbuff,\r\n\t\t\t\t\t\tbuff,\r\n\t\t\t\t\t\tnull,\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}\r\n\r\n\t\t\t// So that self-buffs from Bolvar are taken into account\r\n\t\t\t// if (entityBoard[i].entityId === entity.entityId && entity.divineShield) {\r\n\t\t\t// \tupdateDivineShield(entityBoard[i], entityBoard, false, allCards);\r\n\t\t\t// }\r\n\t\t}\r\n\t\tconst greaseBots = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot_BG21_024);\r\n\t\tconst greaseBotBattlegrounds = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot_BG21_024_G);\r\n\t\tgreaseBots.forEach((bot) => {\r\n\t\t\tmodifyStats(entity, 2, 2, entityBoard, entityBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(bot, entity, entityBoard, entityBoardHero, otherHero);\r\n\t\t});\r\n\t\tgreaseBotBattlegrounds.forEach((bot) => {\r\n\t\t\tmodifyStats(entity, 4, 4, entityBoard, entityBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(bot, entity, entityBoard, entityBoardHero, otherHero);\r\n\t\t});\r\n\r\n\t\tgameState.spectator.registerDamageDealt(bumpInto, entity, 0, entityBoard);\r\n\t\treturn 0;\r\n\t\t// return entity;\r\n\t}\r\n\r\n\tconst damageDealt = (entity.damageMultiplier || 1) * bumpInto.attack;\r\n\tentity.health = entity.health - damageDealt;\r\n\t// FIXME: This will likely be incorrect in terms of timings, e.g. if the entity ends up\r\n\t// surviving following a buff like Spawn.\r\n\tgameState.spectator.registerDamageDealt(bumpInto, entity, damageDealt, entityBoard);\r\n\r\n\tif (entity.cardId === CardIds.Bubblette_BG_TID_713 && bumpInto.attack === 1) {\r\n\t\tentity.definitelyDead = true;\r\n\t} else if (entity.cardId === CardIds.Bubblette_BG_TID_713_G && bumpInto.attack === 2) {\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\t// Do it last, so that other effects are still processed\r\n\tif (bumpInto.poisonous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\tif (bumpInto.venomous && applyVenomous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t\tbumpInto.venomous = false;\r\n\t}\r\n\t// Ideally we should do the Reckoning stuff here. However, at this point we only have half the damage\r\n\t// information, so it is possible that the entity deals more than 3 (which should trigger Reckoning)\r\n\t// but dies during the exchange (and Reckoning doesn't trigger then)\r\n\r\n\tentity.lastAffectedByEntity = bumpInto;\r\n\tif (entity.frenzyChargesLeft > 0 && entity.health > 0 && !entity.definitelyDead) {\r\n\t\tapplyFrenzy(entity, entityBoard, entityBoardHero, gameState);\r\n\t\tentity.frenzyChargesLeft--;\r\n\t}\r\n\r\n\t// We spawn them here, because it says \"whenever\", and so happens right away\r\n\t// FIXME: there could be a bug here, if a Cleave attacks several IGB at the same time. The current\r\n\t// implementation could spawn minions above the max board size. Fringe case though, so leaving it\r\n\t// like this for now\r\n\t// const entitySpawns = getWheneverEntitySpawns(\r\n\t// \tentity,\r\n\t// \tentityBoard,\r\n\t// \tentityBoardHero,\r\n\t// \totherBoard,\r\n\t// \totherHero,\r\n\t// \tgameState.allCards,\r\n\t// \tgameState.cardsData,\r\n\t// \tgameState.sharedState,\r\n\t// \tgameState.spectator,\r\n\t// );\r\n\t// if (!!entitySpawns?.length) {\r\n\t// \t// Spawn to the right\r\n\t// \tconst index = entityBoard.map((e) => e.entityId).indexOf(entity.entityId) + 1;\r\n\t// \taddMinionsToBoard(entityBoard, entityBoardHero, otherHero, index, entitySpawns, gameState);\r\n\t// \tgameState.spectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t// }\r\n\treturn bumpInto.attack;\r\n};\r\n\r\n// const getWheneverEntitySpawns = (\r\n// \tentity: BoardEntity,\r\n// \tentityBoard: BoardEntity[],\r\n// \tentityBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherHero: BgsPlayerEntity,\r\n// \tallCards: AllCardsService,\r\n// \tcardsData: CardsData,\r\n// \tsharedState: SharedState,\r\n// \tspectator: Spectator,\r\n// ): readonly BoardEntity[] => {\r\n// \tif (entityBoard.length === 7) {\r\n// \t\treturn null;\r\n// \t}\r\n\r\n// \tif (entity.cardId === CardIds.ImpGangBoss_BRM_006) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.ImpGangBoss_ImpToken_BRM_006t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.ImpGangBoss_TB_BaconUps_030) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.ImpGangBoss_ImpToken_TB_BaconUps_030t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.ImpMama_BGS_044) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t).map((entity) => ({ ...entity, taunt: true }));\r\n// \t} else if (entity.cardId === CardIds.ImpMama_TB_BaconUps_116) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n// \t\t\t2,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t).map((entity) => ({ ...entity, taunt: true }));\r\n// \t} else if (entity.cardId === CardIds.SecurityRover_BOT_218) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.SecurityRover_GuardBotToken_BOT_218t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.SecurityRover_TB_BaconUps_041) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.SecurityRover_GuardBotToken_TB_BaconUps_041t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t}\r\n// \treturn null;\r\n// };\r\n\r\nexport const processMinionDeath = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// const debug = board1.some((e) => e.health <= 0) || board2.some((e) => e.health <= 0);\r\n\t// debug && console.debug('\\nprocessing minions death');\r\n\t// debug && console.debug(stringifySimple(board1, gameState.allCards));\r\n\t// debug && console.debug(stringifySimple(board2, gameState.allCards));\r\n\tconst [deadMinionIndexesFromRights1, deadEntities1] = makeMinionsDie(\r\n\t\tboard1,\r\n\t\tboard1Hero,\r\n\t\tboard2,\r\n\t\tboard2Hero,\r\n\t\tgameState,\r\n\t);\r\n\tconst [deadMinionIndexesFromRights2, deadEntities2] = makeMinionsDie(\r\n\t\tboard2,\r\n\t\tboard2Hero,\r\n\t\tboard1,\r\n\t\tboard1Hero,\r\n\t\tgameState,\r\n\t);\r\n\t// debug && console.debug('after processing minions death');\r\n\t// debug && console.debug(stringifySimple(board1, gameState.allCards));\r\n\t// debug && console.debug(stringifySimple(board2, gameState.allCards));\r\n\t// debug && console.debug(deadMinionIndexesFromRights1);\r\n\t// debug && console.debug(deadMinionIndexesFromRights2);\r\n\t// console.debug('dead entities', stringifySimple(deadEntities1, allCards), stringifySimple(deadEntities2, allCards));\r\n\t// No death to process, we can return\r\n\tif (deadEntities1.length === 0 && deadEntities2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\r\n\t// Remember them right away, so that subsequent deaths do not break the order\r\n\t// TODO: move this to the deathrattle-orchestration?\r\n\t// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) =>\r\n\t\t\trememberDeathrattles(entity, deadEntities1, gameState.cardsData, gameState.allCards, gameState.sharedState),\r\n\t\t);\r\n\tboard2\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) =>\r\n\t\t\trememberDeathrattles(entity, deadEntities2, gameState.cardsData, gameState.allCards, gameState.sharedState),\r\n\t\t);\r\n\r\n\tgameState.spectator.registerDeadEntities(\r\n\t\tdeadMinionIndexesFromRights1,\r\n\t\tdeadEntities1,\r\n\t\tboard1,\r\n\t\tdeadMinionIndexesFromRights2,\r\n\t\tdeadEntities2,\r\n\t\tboard2,\r\n\t);\r\n\tgameState.sharedState.deaths.push(\r\n\t\t...deadEntities1.map((e) =>\r\n\t\t\taddImpliedMechanics({ ...e, health: e.maxHealth, definitelyDead: false }, gameState.cardsData),\r\n\t\t),\r\n\t);\r\n\tgameState.sharedState.deaths.push(\r\n\t\t...deadEntities2.map((e) =>\r\n\t\t\taddImpliedMechanics({ ...e, health: e.maxHealth, definitelyDead: false }, gameState.cardsData),\r\n\t\t),\r\n\t);\r\n\tboard1Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard1Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities1.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight_BG25_008 || e.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t).length;\r\n\tboard2Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard2Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities2.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight_BG25_008 || e.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t).length;\r\n\r\n\torchestrateMinionDeathEffects({\r\n\t\tgameState: gameState,\r\n\t\tplayerDeadEntities: board1Hero.friendly ? deadEntities1 : deadEntities2,\r\n\t\tplayerDeadEntityIndexesFromRight: board1Hero.friendly\r\n\t\t\t? deadMinionIndexesFromRights1\r\n\t\t\t: deadMinionIndexesFromRights2,\r\n\t\topponentDeadEntities: board1Hero.friendly ? deadEntities2 : deadEntities1,\r\n\t\topponentDeadEntityIndexesFromRight: board1Hero.friendly\r\n\t\t\t? deadMinionIndexesFromRights2\r\n\t\t\t: deadMinionIndexesFromRights1,\r\n\t});\r\n\r\n\tboard1\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy ||\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy_G,\r\n\t\t)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities1, board1, board1Hero, gameState));\r\n\tboard2\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy ||\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy_G,\r\n\t\t)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities2, board2, board2Hero, gameState));\r\n\r\n\t// Make sure we only return when there are no more deaths to process\r\n\t// Make sure to do this right before the end of the process\r\n\t// FIXME: this will propagate the killer between rounds, which is incorrect. For instance,\r\n\t// if a dragon kills a Ghoul, then the Ghoul's deathrattle kills a Kaboom, the killer should\r\n\t// now be the ghoul. Then if the Kaboom kills someone, the killer should again change. You could\r\n\t// also have multiple killers, which is not taken into account here.\r\n\t// The current assumption is that it's a suffienctly fringe case to not matter too much\r\n\tprocessMinionDeath(board1, board1Hero, board2, board2Hero, gameState);\r\n\r\n\t// Not sure about the timing here, but I have bothered Mitchell quite a lot already recently :)\r\n\thandleSummonsWhenSpace(board1, board1Hero, board2, board2Hero, gameState);\r\n\r\n\t// Apply \"after minion death\" effects\r\n\thandleAfterMinionsDeaths(board1, deadEntities1, board1Hero, board2, deadEntities2, board2Hero, gameState);\r\n};\r\n\r\nconst handleAfterMinionsDeaths = (\r\n\tboard1: BoardEntity[],\r\n\tdeadEntities1: BoardEntity[],\r\n\theroEntity1: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tdeadEntities2: BoardEntity[],\r\n\theroEntity2: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst random = Math.random() > 0.5;\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\trandom ? board1 : board2,\r\n\t\trandom ? deadEntities1 : deadEntities2,\r\n\t\trandom ? heroEntity1 : heroEntity2,\r\n\t\trandom ? board2 : board1,\r\n\t\trandom ? deadEntities2 : deadEntities1,\r\n\t\trandom ? heroEntity2 : heroEntity1,\r\n\t\tgameState,\r\n\t);\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\t!random ? board1 : board2,\r\n\t\t!random ? deadEntities1 : deadEntities2,\r\n\t\t!random ? heroEntity1 : heroEntity2,\r\n\t\t!random ? board2 : board1,\r\n\t\t!random ? deadEntities2 : deadEntities1,\r\n\t\t!random ? heroEntity2 : heroEntity1,\r\n\t\tgameState,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeathsForBoard = (\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyDeadEntities: BoardEntity[],\r\n\tfriendlyHeroEntity: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherDeadEntities: BoardEntity[],\r\n\totherHeroEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst candidateEntities = [];\r\n\tlet secretTriggered = null;\r\n\tif (\r\n\t\t(secretTriggered = friendlyHeroEntity.secrets?.find(\r\n\t\t\t(secret) => !secret.triggered && secret?.cardId === CardIds.MagicBlackSoulstone,\r\n\t\t)) != null\r\n\t) {\r\n\t\tif (friendlyBoard.length === 0) {\r\n\t\t\tsecretTriggered.triggered = true;\r\n\t\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\t\tconst toSummon = pickRandom(gameState.cardsData.demonSpawns);\r\n\t\t\t\tcandidateEntities.push(\r\n\t\t\t\t\t...spawnEntities(\r\n\t\t\t\t\t\ttoSummon,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\tfriendlyHeroEntity,\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherHeroEntity,\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\tfriendlyHeroEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tperformEntitySpawns(\r\n\t\tcandidateEntities,\r\n\t\tfriendlyBoard,\r\n\t\tfriendlyHeroEntity,\r\n\t\tsecretTriggered,\r\n\t\t0,\r\n\t\totherBoard,\r\n\t\totherHeroEntity,\r\n\t\tgameState,\r\n\t);\r\n};\r\n\r\n// TODO\r\n// const handleDeathrattlesForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \t// TODO: this can be buggy, in case multiple minions die, both at a 0 or negative final index from left\r\n// \t// In that case, the first minion will spawn at the left, then the next one will spawn again at the left\r\n// \t// thus inverting the expected order\r\n// \t// We still want to process the minions from left to right, but maybe we need to decrease the index from\r\n// \t// the right in case of multiple minions dying and dpawning at the same time\r\n// \t// let boardSizeBeforeDrSpawn = firstBoard.length;\r\n// \tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n// \t\t\t// console.log('\\ndead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n// \t\t\t// console.log(deadMinionIndexesFromRight);\r\n// \t\t\t// console.log(stringifySimple(firstBoard, allCards));\r\n// \t\t\t// Because we use the index from right, and spawn minions from left to right, we actually\r\n// \t\t\t// don't need to update the index after a minion has spawned\r\n// \t\t\tconst modifiedIndexFromRight = Math.min(firstBoard.length, indexFromRight);\r\n// \t\t\t// console.log('spawning at', modifiedIndexFromRight, indexFromRight, totalSpawned, firstBoard.length);\r\n// \t\t\tbuildBoardAfterDeathrattleSpawns(\r\n// \t\t\t\tfirstBoard,\r\n// \t\t\t\tfirstBoardHero,\r\n// \t\t\t\tentity,\r\n// \t\t\t\tmodifiedIndexFromRight,\r\n// \t\t\t\totherBoard,\r\n// \t\t\t\totherBoardHero,\r\n// \t\t\t\tdeadEntities,\r\n// \t\t\t\tgameState,\r\n// \t\t\t);\r\n// \t\t} else if (firstBoard.length > 0) {\r\n// \t\t\t// const newBoardD = [...firstBoard];\r\n// \t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n// \t\t\t// firstBoard = newBoardD;\r\n// \t\t}\r\n// \t\t// boardSizeBeforeDrSpawn = firstBoard.length;\r\n// \t}\r\n// \t// return [firstBoard, otherBoard];\r\n// };\r\n\r\n// const handleRebornForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \t// console.log('will handle reborn', stringifySimple(firstBoard, allCards), deadMinionIndexesFromRight);\r\n// \tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n// \t\t\t// console.log('dead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n// \t\t\tbuildBoardAfterRebornSpawns(\r\n// \t\t\t\tfirstBoard,\r\n// \t\t\t\tfirstBoardHero,\r\n// \t\t\t\tentity,\r\n// \t\t\t\tindexFromRight,\r\n// \t\t\t\totherBoard,\r\n// \t\t\t\totherBoardHero,\r\n// \t\t\t\tgameState,\r\n// \t\t\t);\r\n// \t\t\t// console.log('after rebord', stringifySimple(firstBoard, allCards));\r\n// \t\t} else if (firstBoard.length > 0) {\r\n// \t\t\t// const newBoardD = [...firstBoard];\r\n// \t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n// \t\t\t// firstBoard = newBoardD;\r\n// \t\t}\r\n// \t}\r\n// \t// return [firstBoard, otherBoard];\r\n// };\r\n\r\n// const handleAfterDeathEffectsForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tapplyAfterDeathEffects(\r\n// \t\t\tentity,\r\n// \t\t\tindexFromRight,\r\n// \t\t\tfirstBoard,\r\n// \t\t\tfirstBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherBoardHero,\r\n// \t\t\tgameState,\r\n// \t\t);\r\n// \t}\r\n// };\r\n"]}
|
|
1
|
+
{"version":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B,EAClB,eAAe,EACf,CAAC,EACD,UAAU,EACV,eAAe,EACf,SAAS,CACT,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds, CardType, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport {\r\n\taddImpliedMechanics,\r\n\tgrantRandomStats,\r\n\tgrantStatsToMinionsOfEachType,\r\n\thasCorrectTribe,\r\n\tisFish,\r\n\tstringifySimple,\r\n\tstringifySimpleCard,\r\n\tupdateDivineShield,\r\n} from '../utils';\r\nimport { addCardsInHand } from './cards-in-hand';\r\nimport { onEntityDamaged } from './damage-effects';\r\nimport { applyMonstrosity, rememberDeathrattles } from './deathrattle-effects';\r\nimport { orchestrateMinionDeathEffects, processDeathrattleForMinion } from './deathrattle-orchestration';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { getValidDeathrattles } from './deathrattle-utils';\r\nimport { applyFrenzy } from './frenzy';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { makeMinionsDie } from './minion-death';\r\nimport { onMinionKill } from './minion-kill';\r\nimport { applyOnAttackEffects } from './on-attack';\r\nimport { applyOnBeingAttackedBuffs } from './on-being-attacked';\r\nimport { onQuestProgressUpdated } from './quest';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { applyAfterStatsUpdate, modifyStats } from './stats';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\nimport { canAttack } from './utils/entity-utils';\r\n\r\n// Only use it to simulate actual attack. To simulate damage, or something similar, use bumpInto\r\nexport const simulateAttack = (\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// console.debug(\r\n\t// \t'\\nsimulating attack',\r\n\t// \tstringifySimple(attackingBoard, gameState.allCards),\r\n\t// \t'\\n',\r\n\t// \tstringifySimple(defendingBoard, gameState.allCards),\r\n\t// );\r\n\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst attackingEntity = getAttackingEntity(attackingBoard, gameState.allCards);\r\n\tif (attackingEntity) {\r\n\t\tattackingEntity.attacking = true;\r\n\t\t// Get the left entities now, otherwise things might break if the attacker dies and/or other\r\n\t\t// entities pop\r\n\t\tconst attackingEntityIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\tconst attackingEntitiesToTheLeft = attackingBoard.slice(0, attackingEntityIndex);\r\n\t\tconst isAttackingImmediately = attackingEntity.attackImmediately;\r\n\t\t// In case of Broodmother spawn, it spawns where the dead minion was, and has no influence on the\r\n\t\t// attack order\r\n\t\t// Situation this is trying to resolve by putting this right at the top of the loop:\r\n\t\t// - One scallywag attacks into another one, both die\r\n\t\t// - The first one attacks. To its left is a Harmless Bonehead with 1 HP. The scallywag attacks, and both scallys die\r\n\t\t// - The *other* sky pirate attacks first, and kills the bonehead. Two minions are spawned\r\n\t\t// - The first sy pirate attacks\r\n\t\t// - The initial loop is resolved. If this is at the end, the Harmless Bonehead is already dead, and not flagged\r\n\t\t// While having this right away, we immediately flag all minions to the left\r\n\t\tif (!isAttackingImmediately) {\r\n\t\t\t// Make sure they won't be able to attack until everyone has attacked\r\n\t\t\t// See http://replays.firestoneapp.com/?reviewId=a1b3066d-e806-44c1-ab4b-7ef9dbf9b5b9&turn=5&action=4\r\n\t\t\tattackingEntitiesToTheLeft.forEach((entity) => (entity.hasAttacked = 2));\r\n\t\t}\r\n\r\n\t\tconst numberOfAttacks = attackingEntity.windfury ? 2 : 1;\r\n\t\tfor (let i = 0; i < numberOfAttacks; i++) {\r\n\t\t\t// We refresh the entity in case of windfury\r\n\t\t\tif (attackingBoard.length === 0 || defendingBoard.length === 0) {\r\n\t\t\t\t// We still want to flag the entity as having attacked, so that it doesn't attack again\r\n\t\t\t\t// after teammate switch in Duos\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t// Check that didn't die\r\n\t\t\tif (attackingBoard.find((entity) => entity.entityId === attackingEntity.entityId)) {\r\n\t\t\t\tconst defendingEntity: BoardEntity = getDefendingEntity(defendingBoard, attackingEntity);\r\n\t\t\t\t// Can happen with a single defender that has stealth\r\n\t\t\t\tif (defendingEntity) {\r\n\t\t\t\t\tdoFullAttack(\r\n\t\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Solves the edge case of Sky Pirate vs a stealth board\r\n\t\t\t\t\tattackingEntity.attackImmediately = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tattackingEntity.attacking = false;\r\n\t\tattackingEntity.hasAttacked = 1;\r\n\t}\r\n};\r\n\r\nexport const doFullAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tgameState.spectator.registerAttack(\r\n\t\tattackingEntity,\r\n\t\tdefendingEntity,\r\n\t\tattackingBoard,\r\n\t\tdefendingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoardHero,\r\n\t);\r\n\t// http://replays.firestoneapp.com/?reviewId=50576a9f-2e6a-4600-87ba-6e737ca9853e&turn=21&action=4\r\n\t// Looks like onBeingAttacked effects apply before onAttack effects\r\n\tapplyOnBeingAttackedBuffs(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tapplyOnAttackEffects(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tconst { damageDoneByAttacker, damageDoneByDefender } = performAttack(\r\n\t\tattackingEntity,\r\n\t\tdefendingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoard,\r\n\t\tdefendingBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tapplyAfterAttackEffects(\r\n\t\tattackingEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingEntity,\r\n\t\tdefendingBoardHero,\r\n\t\tdamageDoneByAttacker,\r\n\t\tdamageDoneByDefender,\r\n\t\tgameState,\r\n\t);\r\n\tprocessMinionDeath(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);\r\n\tapplyAfterStatsUpdate(gameState);\r\n\tattackingEntity.immuneWhenAttackCharges = Math.max(0, (attackingEntity.immuneWhenAttackCharges ?? 0) - 1);\r\n\tif (\r\n\t\tdefendingEntity.health > 0 &&\r\n\t\t!defendingEntity.definitelyDead &&\r\n\t\t(defendingEntity.cardId === CardIds.YoHoOgre_BGS_060 ||\r\n\t\t\tdefendingEntity.cardId === CardIds.YoHoOgre_TB_BaconUps_150)\r\n\t) {\r\n\t\tdefendingEntity.attackImmediately = true;\r\n\t\tif (defendingEntity.attackImmediately) {\r\n\t\t\tsimulateAttack(defendingBoard, defendingBoardHero, attackingBoard, attackingBoardHero, gameState);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst applyAfterAttackEffects = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tdamageDoneByAttacker: number,\r\n\tdamageDoneByDefender: number,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tlet secretTriggered = null;\r\n\tif (\r\n\t\t(secretTriggered = defendingBoardHero.secrets?.find(\r\n\t\t\t(secret) => !secret.triggered && secret?.cardId === CardIds.Reckoning_TB_Bacon_Secrets_14,\r\n\t\t)) != null\r\n\t) {\r\n\t\t// console.log('triggering secret?', damageDoneByAttacker, stringifySimpleCard(attackingEntity, allCards));\r\n\t\tif (damageDoneByAttacker >= 3 && !(attackingEntity.health <= 0 || attackingEntity.definitelyDead)) {\r\n\t\t\tsecretTriggered.triggered = true;\r\n\t\t\tattackingEntity.definitelyDead = true;\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tsecretTriggered,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tif (attackingEntity.cardId === CardIds.Bonker_BG20_104 || attackingEntity.cardId === CardIds.Bonker_BG20_104_G) {\r\n\t\tconst quantity = attackingEntity.cardId === CardIds.Bonker_BG20_104_G ? 2 : 1;\r\n\t\tconst cards = quantity === 1 ? [CardIds.BloodGem] : [CardIds.BloodGem, CardIds.BloodGem];\r\n\t\taddCardsInHand(attackingBoardHero, attackingBoard, cards, gameState);\r\n\t} else if (attackingEntity.cardId === CardIds.Yrel_BG23_350 || attackingEntity.cardId === CardIds.Yrel_BG23_350_G) {\r\n\t\tconst modifier = attackingEntity.cardId === CardIds.Yrel_BG23_350_G ? 2 : 1;\r\n\t\tgrantStatsToMinionsOfEachType(\r\n\t\t\tattackingEntity,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tmodifier * 1,\r\n\t\t\tmodifier * 2,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117 ||\r\n\t\tattackingEntity.cardId === CardIds.IncorporealCorporal_BG26_RLK_117_G\r\n\t) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\t// Putricide-only\r\n\telse if (attackingEntity.additionalCards?.includes(CardIds.IncorporealCorporal_BG26_RLK_117)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\tattackingBoard\r\n\t\t.filter((e) => e.additionalCards?.includes(CardIds.FesterootHulk_BG_GIL_655))\r\n\t\t.forEach((e) => {\r\n\t\t\tmodifyStats(e, 1, 0, attackingBoard, attackingBoardHero, gameState);\r\n\t\t});\r\n\r\n\tattackingEntity.stealth = false;\r\n\tapplyOnAttackQuest(attackingEntity, attackingBoard, attackingBoardHero, gameState);\r\n};\r\n\r\nconst applyOnAttackQuest = (\r\n\tattackingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst quests = attackingBoardHero.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.CrackTheCase:\r\n\t\t\t\tonQuestProgressUpdated(attackingBoardHero, quest, attackingBoard, gameState);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n\r\nconst performAttack = (\r\n\tattackingEntity: BoardEntity,\r\n\tdefendingEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): { damageDoneByAttacker: number; damageDoneByDefender: number } => {\r\n\tlet damageDoneByAttacker = 0;\r\n\tlet damageDoneByDefender = 0;\r\n\r\n\tif (hasCorrectTribe(attackingEntity, Race.DRAGON, gameState.allCards)) {\r\n\t\tconst prestors = attackingBoard\r\n\t\t\t.filter((e) => e.entityId !== attackingEntity.entityId)\r\n\t\t\t.filter(\r\n\t\t\t\t(e) =>\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012 ||\r\n\t\t\t\t\te.cardId === CardIds.PrestorsPyrospawn_BG21_012_G,\r\n\t\t\t);\r\n\t\tprestors.forEach((prestor) => {\r\n\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\tprestor,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t);\r\n\t\t\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tprestor,\r\n\t\t\t\tprestor.cardId === CardIds.PrestorsPyrospawn_BG21_012_G ? 6 : 3,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362 ||\r\n\t\tattackingEntity.cardId === CardIds.Atramedes_BG23_362_G\r\n\t) {\r\n\t\tconst targets = [defendingEntity, ...getNeighbours(defendingBoard, defendingEntity)];\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.Atramedes_BG23_362_G ? 2 : 1;\r\n\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\ttargets.forEach((target) => {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\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\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\t3,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t}\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.Niuzao_BG27_822 ||\r\n\t\tattackingEntity.cardId === CardIds.Niuzao_BG27_822_G\r\n\t) {\r\n\t\tconst multiplier = attackingEntity.cardId === CardIds.Niuzao_BG27_822_G ? 2 : 1;\r\n\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\tconst target = pickRandom(defendingBoard.filter((e) => e.entityId != defendingEntity.entityId));\r\n\t\t\tif (target) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\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\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\ttarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tattackingEntity.attack,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\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 ([CardIds.BabyKrush_BG22_001, CardIds.BabyKrush_BG22_001_G].includes(attackingEntity.cardId as CardIds)) {\r\n\t\tconst spawns = spawnEntities(\r\n\t\t\tattackingEntity.cardId === CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t? CardIds.BabyKrush_BG22_001_G\r\n\t\t\t\t: CardIds.BabyKrush_DevilsaurToken,\r\n\t\t\t1,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tgameState.allCards,\r\n\t\t\tgameState.cardsData,\r\n\t\t\tgameState.sharedState,\r\n\t\t\tgameState.spectator,\r\n\t\t\ttrue,\r\n\t\t\ttrue,\r\n\t\t);\r\n\t\tif (spawns.length > 0) {\r\n\t\t\tconst sourceIndex = attackingBoard.indexOf(attackingEntity);\r\n\t\t\tconst actualSpawns = performEntitySpawns(\r\n\t\t\t\tspawns,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tsourceIndex,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tfor (const actualSpawn of actualSpawns) {\r\n\t\t\t\tif (defendingEntity.health > 0 && !defendingEntity.definitelyDead) {\r\n\t\t\t\t\tperformAttack(\r\n\t\t\t\t\t\tactualSpawn,\r\n\t\t\t\t\t\tdefendingEntity,\r\n\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\tgameState,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// For Prestor\r\n\tconst defenderAliveBeforeAttack = defendingEntity.health > 0 && !defendingEntity.definitelyDead;\r\n\t// Because of Bristleback Knight, which changes its divine shield status during bumpEntities\r\n\tconst attackerHadDivineShield = attackingEntity.divineShield;\r\n\tconst defenderHadDivineShield = defendingEntity.divineShield;\r\n\t// For cleave\r\n\t// We do that now so that we don't include entities that spawn on entity damaged\r\n\tconst defenderNeighbours: readonly BoardEntity[] = getNeighbours(defendingBoard, defendingEntity);\r\n\tif (defenderAliveBeforeAttack) {\r\n\t\tif (!attackingEntity.immuneWhenAttackCharges) {\r\n\t\t\t// TODO: this bumpEntities approach doesn't work well, as it leads to code duplication\r\n\t\t\tdamageDoneByDefender += bumpEntities(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tdamageDoneByAttacker += bumpEntities(\r\n\t\t\tdefendingEntity,\r\n\t\t\tattackingEntity,\r\n\t\t\tdefendingBoard,\r\n\t\t\tdefendingBoardHero,\r\n\t\t\tattackingBoard,\r\n\t\t\tattackingBoardHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t\tif (defendingEntity.attack > 0 && attackerHadDivineShield && !attackingEntity.immuneWhenAttackCharges) {\r\n\t\t\tupdateDivineShield(attackingEntity, attackingBoard, false, gameState.allCards);\r\n\t\t}\r\n\t\tif (attackingEntity.attack > 0 && defenderHadDivineShield) {\r\n\t\t\tupdateDivineShield(defendingEntity, defendingBoard, false, gameState.allCards);\r\n\t\t}\r\n\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t// cause wrong results to happen\r\n\t\t// This whole logic is a MEEEEESSSSSSSSSSSSSSS\r\n\t\tif (damageDoneByDefender > 0) {\r\n\t\t\tonEntityDamaged(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tdamageDoneByDefender,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (damageDoneByAttacker > 0) {\r\n\t\t\tonEntityDamaged(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdamageDoneByAttacker,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (defendingEntity.health <= 0 || defendingEntity.definitelyDead) {\r\n\t\t\tonMinionKill(\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t\tif (attackingEntity.health <= 0 || attackingEntity.definitelyDead) {\r\n\t\t\tonMinionKill(\r\n\t\t\t\tdefendingEntity,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\t// Cleave\r\n\tif (attackingEntity.cleave) {\r\n\t\tfor (const neighbour of defenderNeighbours) {\r\n\t\t\tconst thisAttackDamage = bumpEntities(\r\n\t\t\t\tneighbour,\r\n\t\t\t\tattackingEntity,\r\n\t\t\t\tdefendingBoard,\r\n\t\t\t\tdefendingBoardHero,\r\n\t\t\t\tattackingBoard,\r\n\t\t\t\tattackingBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t);\r\n\t\t\tdamageDoneByAttacker += thisAttackDamage;\r\n\t\t\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t\t\t// cause wrong results to happen\r\n\t\t\tif (attackingEntity.attack > 0 && neighbour.divineShield) {\r\n\t\t\t\tupdateDivineShield(neighbour, defendingBoard, false, gameState.allCards);\r\n\t\t\t}\r\n\t\t\tif (thisAttackDamage > 0) {\r\n\t\t\t\tonEntityDamaged(\r\n\t\t\t\t\tneighbour,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tthisAttackDamage,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t\tif (neighbour.health <= 0 || neighbour.definitelyDead) {\r\n\t\t\t\tonMinionKill(\r\n\t\t\t\t\tattackingEntity,\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\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}\r\n\tif (\r\n\t\t(defendingEntity.health <= 0 || defendingEntity.definitelyDead) &&\r\n\t\t(attackingEntity.cardId === CardIds.WildfireElemental_BGS_126 ||\r\n\t\t\tattackingEntity.cardId === CardIds.WildfireElemental_TB_BaconUps_166)\r\n\t) {\r\n\t\tconst excessDamage = -defendingEntity.health;\r\n\t\t// console.log('neighbours', stringifySimple(neighbours, allCards));\r\n\t\tif (defenderNeighbours.length > 0) {\r\n\t\t\tif (attackingEntity.cardId === CardIds.WildfireElemental_BGS_126) {\r\n\t\t\t\tconst randomTarget = defenderNeighbours[Math.floor(Math.random() * defenderNeighbours.length)];\r\n\t\t\t\tdamageDoneByAttacker += dealDamageToMinion(\r\n\t\t\t\t\trandomTarget,\r\n\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\texcessDamage,\r\n\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\tattackingBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tdamageDoneByAttacker += defenderNeighbours\r\n\t\t\t\t\t.map((neighbour) =>\r\n\t\t\t\t\t\tdealDamageToMinion(\r\n\t\t\t\t\t\t\tneighbour,\r\n\t\t\t\t\t\t\tdefendingBoard,\r\n\t\t\t\t\t\t\tdefendingBoardHero,\r\n\t\t\t\t\t\t\tdefendingEntity.lastAffectedByEntity,\r\n\t\t\t\t\t\t\texcessDamage,\r\n\t\t\t\t\t\t\tattackingBoard,\r\n\t\t\t\t\t\t\tattackingBoardHero,\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\t.reduce((a, b) => a + b, 0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// After attack hooks\r\n\t// Arcane Cannon\r\n\t// Monstrous Macaw\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.MonstrousMacaw_BGS_078 ||\r\n\t\tattackingEntity.cardId === CardIds.MonstrousMacaw_TB_BaconUps_135\r\n\t) {\r\n\t\tconst loops = attackingEntity.cardId === CardIds.MonstrousMacaw_TB_BaconUps_135 ? 2 : 1;\r\n\t\tconst validDeathrattles = getValidDeathrattles(attackingBoard, gameState);\r\n\t\tconst leftMost = validDeathrattles[0];\r\n\t\tif (!!leftMost) {\r\n\t\t\tfor (let i = 0; i < loops; i++) {\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tattackingEntity,\r\n\t\t\t\t\tleftMost,\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\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(leftMost) + 1);\r\n\t\t\t\tprocessDeathrattleForMinion(\r\n\t\t\t\t\tleftMost,\r\n\t\t\t\t\tindexFromRight,\r\n\t\t\t\t\t[leftMost],\r\n\t\t\t\t\tleftMost.friendly ? gameState.gameState.player : gameState.gameState.opponent,\r\n\t\t\t\t\tleftMost.friendly ? gameState.gameState.opponent : gameState.gameState.player,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tattackingEntity.attackImmediately = false;\r\n\tif (attackingEntity.enchantments.some((e) => e.cardId === CardIds.VolatileVenom_VolatileEnchantment)) {\r\n\t\tattackingEntity.definitelyDead = true;\r\n\t}\r\n\treturn { damageDoneByAttacker, damageDoneByDefender };\r\n};\r\n\r\nconst triggerRandomDeathrattle = (\r\n\tsourceEntity: BoardEntity,\r\n\tattackingBoard: BoardEntity[],\r\n\tattackingBoardHero: BgsPlayerEntity,\r\n\tdefendingBoard: BoardEntity[],\r\n\tdefendingBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst validDeathrattles = getValidDeathrattles(attackingBoard, gameState).filter(\r\n\t\t(entity) => !excludeSource || entity.entityId !== sourceEntity.entityId,\r\n\t);\r\n\tif (validDeathrattles.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst targetEntity = pickRandom(validDeathrattles);\r\n\tif (!targetEntity?.cardId) {\r\n\t\tconsole.error(\r\n\t\t\t'missing card id when triggering random deathrattle',\r\n\t\t\tstringifySimpleCard(targetEntity, gameState.allCards),\r\n\t\t\ttargetEntity,\r\n\t\t\tvalidDeathrattles.length,\r\n\t\t\tstringifySimple(validDeathrattles, gameState.allCards),\r\n\t\t\tstringifySimple(attackingBoard, gameState.allCards),\r\n\t\t\texcludeSource,\r\n\t\t\tstringifySimpleCard(sourceEntity, gameState.allCards),\r\n\t\t);\r\n\t}\r\n\tgameState.spectator.registerPowerTarget(\r\n\t\tsourceEntity,\r\n\t\ttargetEntity,\r\n\t\tattackingBoard,\r\n\t\tattackingBoardHero,\r\n\t\tdefendingBoardHero,\r\n\t);\r\n\tconst indexFromRight = attackingBoard.length - (attackingBoard.indexOf(targetEntity) + 1);\r\n\r\n\tprocessDeathrattleForMinion(\r\n\t\ttargetEntity,\r\n\t\tindexFromRight,\r\n\t\t[targetEntity],\r\n\t\ttargetEntity.friendly ? gameState.gameState.player : gameState.gameState.opponent,\r\n\t\ttargetEntity.friendly ? gameState.gameState.opponent : gameState.gameState.player,\r\n\t\tgameState,\r\n\t\tfalse,\r\n\t);\r\n\t// The reborn minion spawns to the right of the DR spawns\r\n\t// buildBoardAfterRebornSpawns(\r\n\t// \tattackingBoard,\r\n\t// \tattackingBoardHero,\r\n\t// \ttargetEntity,\r\n\t// \tindexFromRight,\r\n\t// \tdefendingBoard,\r\n\t// \tdefendingBoardHero,\r\n\t// \tallCards,\r\n\t// \tspawns,\r\n\t// \tsharedState,\r\n\t// \tspectator,\r\n\t// );\r\n};\r\n\r\nconst getAttackingEntity = (attackingBoard: BoardEntity[], allCards: AllCardsService): BoardEntity => {\r\n\tconst debug = attackingBoard.map((e) => ({\r\n\t\tname: allCards.getCard(e.cardId)?.name,\r\n\t\tattacked: e.hasAttacked,\r\n\t\tentityId: e.entityId,\r\n\t\treborn: e.reborn,\r\n\t}));\r\n\tlet validAttackers = attackingBoard.filter((entity) => canAttack(entity));\r\n\tif (validAttackers.length === 0) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\t// console.debug(\r\n\t// \t'\\nvalid attackers',\r\n\t// \tstringifySimple(validAttackers, allCards),\r\n\t// \tstringifySimple(attackingBoard, allCards),\r\n\t// );\r\n\r\n\tif (validAttackers.some((entity) => entity.attackImmediately)) {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => entity.attackImmediately);\r\n\t} else if (validAttackers.every((e) => e.hasAttacked)) {\r\n\t\tattackingBoard.forEach((e) => (e.hasAttacked = 0));\r\n\t} else {\r\n\t\tvalidAttackers = validAttackers.filter((entity) => !entity.hasAttacked);\r\n\t}\r\n\tconst attacker = validAttackers[0];\r\n\t// console.debug('\\t attacker', stringifySimpleCard(attacker, allCards));\r\n\treturn attacker;\r\n};\r\n\r\nexport const findNearestEnemies = (\r\n\tattackingBoard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tentityIndexFromRight: number,\r\n\tdefendingBoard: BoardEntity[],\r\n\tnumberOfTargets: number,\r\n\tallCards: AllCardsService,\r\n): BoardEntity[] => {\r\n\tconst result = [];\r\n\tif (defendingBoard.length > 0) {\r\n\t\t// console.debug('defending board', numberOfTargets, stringifySimple(defendingBoard, allCards));\r\n\t\tconst attackerIndex = attackingBoard.length - entityIndexFromRight - 1;\r\n\t\tconst targetIndex = attackerIndex - (attackingBoard.length - defendingBoard.length) / 2;\r\n\t\t// console.debug('indexes', attackerIndex, entityIndexFromRight, targetIndex, attackingBoard.length);\r\n\r\n\t\tfor (let i = 0; i < numberOfTargets; i++) {\r\n\t\t\tconst possibleTargets = defendingBoard\r\n\t\t\t\t.filter((e) => !e.definitelyDead && e.health > 0)\r\n\t\t\t\t.filter((e) => !result.includes(e));\r\n\t\t\t// console.debug('possibleTargets', stringifySimple(possibleTargets, allCards));\r\n\t\t\tif (!possibleTargets.length) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tconst targetGroups = groupByFunction((e: BoardEntity) => Math.abs(defendingBoard.indexOf(e) - targetIndex))(\r\n\t\t\t\tpossibleTargets,\r\n\t\t\t);\r\n\t\t\tconst distances = Object.keys(targetGroups)\r\n\t\t\t\t.map((k) => +k)\r\n\t\t\t\t.sort();\r\n\t\t\tconst nearestDistance = distances[0];\r\n\t\t\tif (nearestDistance != null) {\r\n\t\t\t\t// console.debug(\r\n\t\t\t\t// \t'targetGroups[nearestDistance]',\r\n\t\t\t\t// \tnearestDistance,\r\n\t\t\t\t// \tstringifySimple(targetGroups[nearestDistance], allCards),\r\n\t\t\t\t// );\r\n\t\t\t\tconst target = pickRandom(targetGroups[nearestDistance]);\r\n\t\t\t\tresult.push(target);\r\n\t\t\t}\r\n\t\t\t// console.debug('\\n');\r\n\t\t}\r\n\t}\r\n\treturn result.filter((e) => !!e);\r\n};\r\n\r\nexport const getNeighbours = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): readonly BoardEntity[] => {\r\n\tconst neighbours = [];\r\n\t// When triggering DR with Hawkstrider, the entity is still on the board\r\n\tif (deadEntityIndexFromRight != null && !board.includes(entity)) {\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\tneighbours.push(leftNeighbour);\r\n\t\t}\r\n\r\n\t\t// If the deadEntityIndexFromRight === 0 (right-most minion), no neighbour will be found\r\n\t\tconst rightNeighbourIndex = board.length - 1 - (deadEntityIndexFromRight - 1);\r\n\t\tconst rightNeighbour = board[rightNeighbourIndex];\r\n\t\tif (rightNeighbour) {\r\n\t\t\tneighbours.push(rightNeighbour);\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\tneighbours.push(board[index - 1]);\r\n\t\t}\r\n\t\t// neighbours.push(entity);\r\n\t\tif (index + 1 < board.length) {\r\n\t\t\tneighbours.push(board[index + 1]);\r\n\t\t}\r\n\t}\r\n\treturn neighbours;\r\n};\r\n\r\nexport const getLeftNeighbour = (\r\n\tboard: BoardEntity[],\r\n\tentity: BoardEntity,\r\n\tdeadEntityIndexFromRight?: number,\r\n): BoardEntity => {\r\n\t// When triggering DR with Hawkstrider, the entity is still on the board\r\n\tif (deadEntityIndexFromRight != null && !board.includes(entity)) {\r\n\t\tconst leftNeighbourIndex = board.length - 1 - deadEntityIndexFromRight;\r\n\t\tconst leftNeighbour = board[leftNeighbourIndex];\r\n\t\tif (leftNeighbour) {\r\n\t\t\treturn leftNeighbour;\r\n\t\t}\r\n\t} else {\r\n\t\tconst index = board.map((e) => e.entityId).indexOf(entity.entityId);\r\n\t\tif (index - 1 >= 0) {\r\n\t\t\treturn board[index - 1];\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const dealDamageToRandomEnemy = (\r\n\tboardToBeDamaged: BoardEntity[],\r\n\tboardToBeDamagedHero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\tboardWithAttackOrigin: BoardEntity[],\r\n\tboardWithAttackOriginHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\tif (boardToBeDamaged.length === 0) {\r\n\t\treturn;\r\n\t}\r\n\tconst validTargets = boardToBeDamaged.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tconst defendingEntity: BoardEntity = pickRandom(validTargets);\r\n\tif (defendingEntity) {\r\n\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\tdamageSource,\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t);\r\n\t\tdealDamageToMinion(\r\n\t\t\tdefendingEntity,\r\n\t\t\tboardToBeDamaged,\r\n\t\t\tboardToBeDamagedHero,\r\n\t\t\tdamageSource,\r\n\t\t\tdamage,\r\n\t\t\tboardWithAttackOrigin,\r\n\t\t\tboardWithAttackOriginHero,\r\n\t\t\tgameState,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const dealDamageToMinion = (\r\n\ttarget: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thero: BgsPlayerEntity,\r\n\tdamageSource: BoardEntity,\r\n\tdamage: number,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): number => {\r\n\t// console.log('dealing damage to', damage, stringifySimpleCard(defendingEntity, allCards));\r\n\tif (!target) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tconst isDeadBeforeDamage = target.definitelyDead || target.health <= 0;\r\n\tconst spawns = [];\r\n\t// Why do we use a fakeAttacker? Is that for the \"attacking\" prop?\r\n\t// That prop is only used for Overkill, and even in that case it looks like it would work\r\n\t// without it\r\n\tconst fakeAttacker = {\r\n\t\t...(damageSource || {}),\r\n\t\tentityId: -1,\r\n\t\tattack: damage,\r\n\t\tattacking: true,\r\n\t} as BoardEntity;\r\n\tconst actualDamageDone = bumpEntities(target, fakeAttacker, board, hero, otherBoard, otherHero, gameState);\r\n\t// Do it after the damage has been done, so that entities that update on DS lose / gain (CyborgDrake) don't\r\n\t// cause wrong results to happen\r\n\tif (fakeAttacker.attack > 0 && target.divineShield) {\r\n\t\tupdateDivineShield(target, board, false, gameState.allCards);\r\n\t}\r\n\tif (actualDamageDone > 0) {\r\n\t\t// TODO: handle entities that have been spawned here to adjust the dead entity index from parent stack\r\n\t\tconst newSpawns = onEntityDamaged(target, board, hero, otherBoard, otherHero, actualDamageDone, gameState);\r\n\t}\r\n\tif (!isDeadBeforeDamage && actualDamageDone > 0) {\r\n\t\ttarget.lastAffectedByEntity = damageSource;\r\n\r\n\t\tif (target.health <= 0 || target.definitelyDead) {\r\n\t\t\tonMinionKill(damageSource, target, otherBoard, otherHero, board, hero, gameState);\r\n\t\t}\r\n\t}\r\n\tconst defendingEntityIndex = board.map((entity) => entity.entityId).indexOf(target.entityId);\r\n\tboard[defendingEntityIndex] = target;\r\n\treturn actualDamageDone;\r\n};\r\n\r\nexport const getDefendingEntity = (\r\n\tdefendingBoard: BoardEntity[],\r\n\tattackingEntity: BoardEntity,\r\n\tignoreTaunts = false,\r\n): BoardEntity => {\r\n\t// if (attackingEntity.entityId === 4946) {\r\n\t// \tlet def = null;\r\n\t// \tif (!!(def = defendingBoard.find((e) => e.entityId === 7170))) {\r\n\t// \t\treturn def;\r\n\t// \t}\r\n\t// }\r\n\r\n\tlet possibleDefenders: readonly BoardEntity[];\r\n\tif (\r\n\t\tattackingEntity.cardId === CardIds.ZappSlywick_BGS_022 ||\r\n\t\tattackingEntity.cardId === CardIds.ZappSlywick_TB_BaconUps_091\r\n\t) {\r\n\t\tconst minAttack = Math.min(...defendingBoard.map((entity) => entity.attack));\r\n\t\tpossibleDefenders = defendingBoard.filter((entity) => entity.attack === minAttack);\r\n\t} else if (\r\n\t\tattackingEntity.cardId === CardIds.WorgenVigilante_BG26_921 ||\r\n\t\tattackingEntity.cardId === CardIds.WorgenVigilante_BG26_921_G\r\n\t) {\r\n\t\tpossibleDefenders = defendingBoard\r\n\t\t\t.filter(\r\n\t\t\t\t(entity) =>\r\n\t\t\t\t\tentity.health <= attackingEntity.attack || attackingEntity.venomous || attackingEntity.poisonous,\r\n\t\t\t)\r\n\t\t\t.filter((e) => !e.divineShield);\r\n\t\tif (!possibleDefenders.length) {\r\n\t\t\tpossibleDefenders = defendingBoard;\r\n\t\t}\r\n\t} else {\r\n\t\tpossibleDefenders = defendingBoard.filter((e) => !e.stealth);\r\n\t\tif (!ignoreTaunts) {\r\n\t\t\tconst taunts = possibleDefenders.filter((entity) => entity.taunt);\r\n\t\t\tpossibleDefenders = taunts.length > 0 ? taunts : possibleDefenders;\r\n\t\t}\r\n\t}\r\n\r\n\tlet chosenDefender = pickRandom(possibleDefenders);\r\n\tif (chosenDefender?.taunt) {\r\n\t\tconst elistras = defendingBoard.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_BGS_205 ||\r\n\t\t\t\tentity.cardId === CardIds.ElistraTheImmortal_TB_BaconUps_306,\r\n\t\t);\r\n\t\tif (elistras.length > 0) {\r\n\t\t\tchosenDefender = elistras[Math.floor(Math.random() * elistras.length)];\r\n\t\t}\r\n\t}\r\n\treturn chosenDefender;\r\n};\r\n\r\nexport const bumpEntities = (\r\n\tentity: BoardEntity,\r\n\tbumpInto: BoardEntity,\r\n\tentityBoard: BoardEntity[],\r\n\tentityBoardHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n\tapplyVenomous = true,\r\n): number => {\r\n\t// No attack has no impact\r\n\tif (bumpInto.attack === 0) {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\t// Matador effect has priority\r\n\tif (\r\n\t\tentity.abiityChargesLeft > 0 &&\r\n\t\t(entity.cardId === CardIds.MadMatador_BG28_404 || entity.cardId === CardIds.MadMatador_BG28_404_G)\r\n\t) {\r\n\t\tentity.abiityChargesLeft--;\r\n\t\tconst newTarget = pickRandom(otherBoard);\r\n\t\tif (newTarget) {\r\n\t\t\tgameState.spectator.registerPowerTarget(entity, newTarget, otherBoard, entityBoardHero, otherHero);\r\n\t\t\t// TODO: here the MadMatador is the source of the damage, not the initial attacker\r\n\t\t\t// Not sure exactly what the impact would be, as there is no counter\r\n\t\t\tconst newSource = {\r\n\t\t\t\t...entity,\r\n\t\t\t\tattack: bumpInto.attack,\r\n\t\t\t\tattacking: true,\r\n\t\t\t} as BoardEntity;\r\n\t\t\tconst defenderHadDivineShield = newTarget.divineShield;\r\n\t\t\tconst damageDone = bumpEntities(\r\n\t\t\t\tnewTarget,\r\n\t\t\t\tnewSource,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero,\r\n\t\t\t\tentityBoard,\r\n\t\t\t\tentityBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t\tfalse,\r\n\t\t\t);\r\n\t\t\tif (newSource.attack > 0 && defenderHadDivineShield) {\r\n\t\t\t\tupdateDivineShield(newTarget, otherBoard, false, gameState.allCards);\r\n\t\t\t}\r\n\t\t\tif (damageDone > 0) {\r\n\t\t\t\tonEntityDamaged(newTarget, otherBoard, otherHero, entityBoard, entityBoardHero, damageDone, gameState);\r\n\t\t\t}\r\n\t\t\treturn damageDone;\r\n\t\t}\r\n\t}\r\n\r\n\tif (entity.divineShield) {\r\n\t\t// Handle all the divine shield loss effects here\r\n\t\tfor (let i = 0; i < entityBoard.length; i++) {\r\n\t\t\tif (entityBoard[i].cardId === CardIds.BolvarFireblood_ICC_858) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 2, 0, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.BolvarFireblood_TB_BaconUps_047) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 4, 0, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer_BGS_067) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 2, 2, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.DrakonidEnforcer_TB_BaconUps_117) {\r\n\t\t\t\tmodifyStats(entityBoard[i], 4, 4, entityBoard, entityBoardHero, gameState);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\tentityBoard,\r\n\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\totherHero,\r\n\t\t\t\t);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].entityId !== entity.entityId &&\r\n\t\t\t\t(entityBoard[i].cardId === CardIds.HolyMecherel_BG20_401 ||\r\n\t\t\t\t\tentityBoard[i].cardId === CardIds.HolyMecherel_BG20_401_G)\r\n\t\t\t) {\r\n\t\t\t\tupdateDivineShield(entityBoard[i], entityBoard, true, gameState.allCards);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, [CardIds.BloodGem], gameState);\r\n\t\t\t} else if (entityBoard[i].cardId === CardIds.Gemsplitter_BG21_037_G) {\r\n\t\t\t\taddCardsInHand(entityBoardHero, entityBoard, [CardIds.BloodGem, CardIds.BloodGem], gameState);\r\n\t\t\t} else if (\r\n\t\t\t\tentityBoard[i].cardId === CardIds.CogworkCopter_BG24_008 ||\r\n\t\t\t\tentityBoard[i].cardId === CardIds.CogworkCopter_BG24_008_G\r\n\t\t\t) {\r\n\t\t\t\t// When it's the opponent, the game state already contains all the buffs\r\n\t\t\t\tif (entityBoard[i]?.friendly) {\r\n\t\t\t\t\tconst buff = entityBoard[i].cardId === CardIds.CogworkCopter_BG24_008_G ? 2 : 1;\r\n\t\t\t\t\tgrantRandomStats(\r\n\t\t\t\t\t\tentityBoard[i],\r\n\t\t\t\t\t\tentityBoardHero.hand.filter(\r\n\t\t\t\t\t\t\t(e) =>\r\n\t\t\t\t\t\t\t\tgameState.allCards.getCard(e.cardId).type?.toUpperCase() === CardType[CardType.MINION],\r\n\t\t\t\t\t\t),\r\n\t\t\t\t\t\tentityBoardHero,\r\n\t\t\t\t\t\tbuff,\r\n\t\t\t\t\t\tbuff,\r\n\t\t\t\t\t\tnull,\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}\r\n\r\n\t\t\t// So that self-buffs from Bolvar are taken into account\r\n\t\t\t// if (entityBoard[i].entityId === entity.entityId && entity.divineShield) {\r\n\t\t\t// \tupdateDivineShield(entityBoard[i], entityBoard, false, allCards);\r\n\t\t\t// }\r\n\t\t}\r\n\t\tconst greaseBots = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot_BG21_024);\r\n\t\tconst greaseBotBattlegrounds = entityBoard.filter((entity) => entity.cardId === CardIds.GreaseBot_BG21_024_G);\r\n\t\tgreaseBots.forEach((bot) => {\r\n\t\t\tmodifyStats(entity, 2, 2, entityBoard, entityBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(bot, entity, entityBoard, entityBoardHero, otherHero);\r\n\t\t});\r\n\t\tgreaseBotBattlegrounds.forEach((bot) => {\r\n\t\t\tmodifyStats(entity, 4, 4, entityBoard, entityBoardHero, gameState);\r\n\t\t\tgameState.spectator.registerPowerTarget(bot, entity, entityBoard, entityBoardHero, otherHero);\r\n\t\t});\r\n\r\n\t\tgameState.spectator.registerDamageDealt(bumpInto, entity, 0, entityBoard);\r\n\t\treturn 0;\r\n\t\t// return entity;\r\n\t}\r\n\r\n\tconst damageDealt = (entity.damageMultiplier || 1) * bumpInto.attack;\r\n\tentity.health = entity.health - damageDealt;\r\n\t// FIXME: This will likely be incorrect in terms of timings, e.g. if the entity ends up\r\n\t// surviving following a buff like Spawn.\r\n\tgameState.spectator.registerDamageDealt(bumpInto, entity, damageDealt, entityBoard);\r\n\r\n\tif (entity.cardId === CardIds.Bubblette_BG_TID_713 && bumpInto.attack === 1) {\r\n\t\tentity.definitelyDead = true;\r\n\t} else if (entity.cardId === CardIds.Bubblette_BG_TID_713_G && bumpInto.attack === 2) {\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\t// Do it last, so that other effects are still processed\r\n\tif (bumpInto.poisonous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t}\r\n\tif (bumpInto.venomous && applyVenomous) {\r\n\t\t// So that further buffs don't revive it\r\n\t\t// And we don't just set the health to avoid applying overkill effects\r\n\t\tentity.definitelyDead = true;\r\n\t\tbumpInto.venomous = false;\r\n\t}\r\n\t// Ideally we should do the Reckoning stuff here. However, at this point we only have half the damage\r\n\t// information, so it is possible that the entity deals more than 3 (which should trigger Reckoning)\r\n\t// but dies during the exchange (and Reckoning doesn't trigger then)\r\n\r\n\tentity.lastAffectedByEntity = bumpInto;\r\n\tif (entity.frenzyChargesLeft > 0 && entity.health > 0 && !entity.definitelyDead) {\r\n\t\tapplyFrenzy(entity, entityBoard, entityBoardHero, gameState);\r\n\t\tentity.frenzyChargesLeft--;\r\n\t}\r\n\r\n\t// We spawn them here, because it says \"whenever\", and so happens right away\r\n\t// FIXME: there could be a bug here, if a Cleave attacks several IGB at the same time. The current\r\n\t// implementation could spawn minions above the max board size. Fringe case though, so leaving it\r\n\t// like this for now\r\n\t// const entitySpawns = getWheneverEntitySpawns(\r\n\t// \tentity,\r\n\t// \tentityBoard,\r\n\t// \tentityBoardHero,\r\n\t// \totherBoard,\r\n\t// \totherHero,\r\n\t// \tgameState.allCards,\r\n\t// \tgameState.cardsData,\r\n\t// \tgameState.sharedState,\r\n\t// \tgameState.spectator,\r\n\t// );\r\n\t// if (!!entitySpawns?.length) {\r\n\t// \t// Spawn to the right\r\n\t// \tconst index = entityBoard.map((e) => e.entityId).indexOf(entity.entityId) + 1;\r\n\t// \taddMinionsToBoard(entityBoard, entityBoardHero, otherHero, index, entitySpawns, gameState);\r\n\t// \tgameState.spectator.registerMinionsSpawn(entity, entityBoard, entitySpawns);\r\n\t// }\r\n\treturn bumpInto.attack;\r\n};\r\n\r\n// const getWheneverEntitySpawns = (\r\n// \tentity: BoardEntity,\r\n// \tentityBoard: BoardEntity[],\r\n// \tentityBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherHero: BgsPlayerEntity,\r\n// \tallCards: AllCardsService,\r\n// \tcardsData: CardsData,\r\n// \tsharedState: SharedState,\r\n// \tspectator: Spectator,\r\n// ): readonly BoardEntity[] => {\r\n// \tif (entityBoard.length === 7) {\r\n// \t\treturn null;\r\n// \t}\r\n\r\n// \tif (entity.cardId === CardIds.ImpGangBoss_BRM_006) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.ImpGangBoss_ImpToken_BRM_006t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.ImpGangBoss_TB_BaconUps_030) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.ImpGangBoss_ImpToken_TB_BaconUps_030t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.ImpMama_BGS_044) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t).map((entity) => ({ ...entity, taunt: true }));\r\n// \t} else if (entity.cardId === CardIds.ImpMama_TB_BaconUps_116) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tcardsData.impMamaSpawns[Math.floor(Math.random() * cardsData.impMamaSpawns.length)],\r\n// \t\t\t2,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t).map((entity) => ({ ...entity, taunt: true }));\r\n// \t} else if (entity.cardId === CardIds.SecurityRover_BOT_218) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.SecurityRover_GuardBotToken_BOT_218t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t} else if (entity.cardId === CardIds.SecurityRover_TB_BaconUps_041) {\r\n// \t\treturn spawnEntities(\r\n// \t\t\tCardIds.SecurityRover_GuardBotToken_TB_BaconUps_041t,\r\n// \t\t\t1,\r\n// \t\t\tentityBoard,\r\n// \t\t\tentityBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherHero,\r\n// \t\t\tallCards,\r\n// \t\t\tcardsData,\r\n// \t\t\tsharedState,\r\n// \t\t\tspectator,\r\n// \t\t\tentity.friendly,\r\n// \t\t\ttrue,\r\n// \t\t);\r\n// \t}\r\n// \treturn null;\r\n// };\r\n\r\nexport const processMinionDeath = (\r\n\tboard1: BoardEntity[],\r\n\tboard1Hero: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tboard2Hero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): void => {\r\n\t// const debug = board1.some((e) => e.health <= 0) || board2.some((e) => e.health <= 0);\r\n\t// debug && console.debug('\\nprocessing minions death');\r\n\t// debug && console.debug(stringifySimple(board1, gameState.allCards));\r\n\t// debug && console.debug(stringifySimple(board2, gameState.allCards));\r\n\tconst [deadMinionIndexesFromRights1, deadEntities1] = makeMinionsDie(\r\n\t\tboard1,\r\n\t\tboard1Hero,\r\n\t\tboard2,\r\n\t\tboard2Hero,\r\n\t\tgameState,\r\n\t);\r\n\tconst [deadMinionIndexesFromRights2, deadEntities2] = makeMinionsDie(\r\n\t\tboard2,\r\n\t\tboard2Hero,\r\n\t\tboard1,\r\n\t\tboard1Hero,\r\n\t\tgameState,\r\n\t);\r\n\t// debug && console.debug('after processing minions death');\r\n\t// debug && console.debug(stringifySimple(board1, gameState.allCards));\r\n\t// debug && console.debug(stringifySimple(board2, gameState.allCards));\r\n\t// debug && console.debug(deadMinionIndexesFromRights1);\r\n\t// debug && console.debug(deadMinionIndexesFromRights2);\r\n\t// console.debug('dead entities', stringifySimple(deadEntities1, allCards), stringifySimple(deadEntities2, allCards));\r\n\t// No death to process, we can return\r\n\tif (deadEntities1.length === 0 && deadEntities2.length === 0) {\r\n\t\treturn;\r\n\t\t// return [board1, board2];\r\n\t}\r\n\r\n\t// Remember them right away, so that subsequent deaths do not break the order\r\n\t// TODO: move this to the deathrattle-orchestration?\r\n\t// If the fish dies (from Scallywag for instance), it doesn't remember the deathrattle\r\n\tboard1\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) =>\r\n\t\t\trememberDeathrattles(entity, deadEntities1, gameState.cardsData, gameState.allCards, gameState.sharedState),\r\n\t\t);\r\n\tboard2\r\n\t\t.filter((entity) => isFish(entity))\r\n\t\t.forEach((entity) =>\r\n\t\t\trememberDeathrattles(entity, deadEntities2, gameState.cardsData, gameState.allCards, gameState.sharedState),\r\n\t\t);\r\n\r\n\tgameState.spectator.registerDeadEntities(\r\n\t\tdeadMinionIndexesFromRights1,\r\n\t\tdeadEntities1,\r\n\t\tboard1,\r\n\t\tdeadMinionIndexesFromRights2,\r\n\t\tdeadEntities2,\r\n\t\tboard2,\r\n\t);\r\n\tgameState.sharedState.deaths.push(\r\n\t\t...deadEntities1.map((e) =>\r\n\t\t\taddImpliedMechanics({ ...e, health: e.maxHealth, definitelyDead: false }, gameState.cardsData),\r\n\t\t),\r\n\t);\r\n\tgameState.sharedState.deaths.push(\r\n\t\t...deadEntities2.map((e) =>\r\n\t\t\taddImpliedMechanics({ ...e, health: e.maxHealth, definitelyDead: false }, gameState.cardsData),\r\n\t\t),\r\n\t);\r\n\tboard1Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard1Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities1.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight_BG25_008 || e.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t).length;\r\n\tboard2Hero.globalInfo.EternalKnightsDeadThisGame =\r\n\t\tboard2Hero.globalInfo.EternalKnightsDeadThisGame +\r\n\t\tdeadEntities2.filter(\r\n\t\t\t(e) => e.cardId === CardIds.EternalKnight_BG25_008 || e.cardId === CardIds.EternalKnight_BG25_008_G,\r\n\t\t).length;\r\n\r\n\torchestrateMinionDeathEffects({\r\n\t\tgameState: gameState,\r\n\t\tplayerDeadEntities: board1Hero.friendly ? deadEntities1 : deadEntities2,\r\n\t\tplayerDeadEntityIndexesFromRight: board1Hero.friendly\r\n\t\t\t? deadMinionIndexesFromRights1\r\n\t\t\t: deadMinionIndexesFromRights2,\r\n\t\topponentDeadEntities: board1Hero.friendly ? deadEntities2 : deadEntities1,\r\n\t\topponentDeadEntityIndexesFromRight: board1Hero.friendly\r\n\t\t\t? deadMinionIndexesFromRights2\r\n\t\t\t: deadMinionIndexesFromRights1,\r\n\t});\r\n\r\n\tboard1\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy ||\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy_G,\r\n\t\t)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities1, board1, board1Hero, gameState));\r\n\tboard2\r\n\t\t.filter(\r\n\t\t\t(entity) =>\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy ||\r\n\t\t\t\tentity.cardId === CardIds.Monstrosity_BG20_HERO_282_Buddy_G,\r\n\t\t)\r\n\t\t.forEach((entity) => applyMonstrosity(entity, deadEntities2, board2, board2Hero, gameState));\r\n\r\n\t// Make sure we only return when there are no more deaths to process\r\n\t// Make sure to do this right before the end of the process\r\n\t// FIXME: this will propagate the killer between rounds, which is incorrect. For instance,\r\n\t// if a dragon kills a Ghoul, then the Ghoul's deathrattle kills a Kaboom, the killer should\r\n\t// now be the ghoul. Then if the Kaboom kills someone, the killer should again change. You could\r\n\t// also have multiple killers, which is not taken into account here.\r\n\t// The current assumption is that it's a suffienctly fringe case to not matter too much\r\n\tprocessMinionDeath(board1, board1Hero, board2, board2Hero, gameState);\r\n\r\n\t// Not sure about the timing here, but I have bothered Mitchell quite a lot already recently :)\r\n\thandleSummonsWhenSpace(board1, board1Hero, board2, board2Hero, gameState);\r\n\r\n\t// Apply \"after minion death\" effects\r\n\thandleAfterMinionsDeaths(board1, deadEntities1, board1Hero, board2, deadEntities2, board2Hero, gameState);\r\n};\r\n\r\nconst handleAfterMinionsDeaths = (\r\n\tboard1: BoardEntity[],\r\n\tdeadEntities1: BoardEntity[],\r\n\theroEntity1: BgsPlayerEntity,\r\n\tboard2: BoardEntity[],\r\n\tdeadEntities2: BoardEntity[],\r\n\theroEntity2: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst random = Math.random() > 0.5;\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\trandom ? board1 : board2,\r\n\t\trandom ? deadEntities1 : deadEntities2,\r\n\t\trandom ? heroEntity1 : heroEntity2,\r\n\t\trandom ? board2 : board1,\r\n\t\trandom ? deadEntities2 : deadEntities1,\r\n\t\trandom ? heroEntity2 : heroEntity1,\r\n\t\tgameState,\r\n\t);\r\n\thandleAfterMinionsDeathsForBoard(\r\n\t\t!random ? board1 : board2,\r\n\t\t!random ? deadEntities1 : deadEntities2,\r\n\t\t!random ? heroEntity1 : heroEntity2,\r\n\t\t!random ? board2 : board1,\r\n\t\t!random ? deadEntities2 : deadEntities1,\r\n\t\t!random ? heroEntity2 : heroEntity1,\r\n\t\tgameState,\r\n\t);\r\n};\r\n\r\nconst handleAfterMinionsDeathsForBoard = (\r\n\tfriendlyBoard: BoardEntity[],\r\n\tfriendlyDeadEntities: BoardEntity[],\r\n\tfriendlyHeroEntity: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherDeadEntities: BoardEntity[],\r\n\totherHeroEntity: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\tconst candidateEntities = [];\r\n\tlet secretTriggered = null;\r\n\tif (\r\n\t\t(secretTriggered = friendlyHeroEntity.secrets?.find(\r\n\t\t\t(secret) => !secret.triggered && secret?.cardId === CardIds.MagicBlackSoulstone,\r\n\t\t)) != null\r\n\t) {\r\n\t\tif (friendlyBoard.length === 0) {\r\n\t\t\tsecretTriggered.triggered = true;\r\n\t\t\tfor (let i = 0; i < 2; i++) {\r\n\t\t\t\tconst toSummon = pickRandom(gameState.cardsData.demonSpawns);\r\n\t\t\t\tcandidateEntities.push(\r\n\t\t\t\t\t...spawnEntities(\r\n\t\t\t\t\t\ttoSummon,\r\n\t\t\t\t\t\t1,\r\n\t\t\t\t\t\tfriendlyBoard,\r\n\t\t\t\t\t\tfriendlyHeroEntity,\r\n\t\t\t\t\t\totherBoard,\r\n\t\t\t\t\t\totherHeroEntity,\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\tfriendlyHeroEntity.friendly,\r\n\t\t\t\t\t\tfalse,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tperformEntitySpawns(\r\n\t\tcandidateEntities,\r\n\t\tfriendlyBoard,\r\n\t\tfriendlyHeroEntity,\r\n\t\tsecretTriggered,\r\n\t\t0,\r\n\t\totherBoard,\r\n\t\totherHeroEntity,\r\n\t\tgameState,\r\n\t);\r\n};\r\n\r\n// TODO\r\n// const handleDeathrattlesForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \t// TODO: this can be buggy, in case multiple minions die, both at a 0 or negative final index from left\r\n// \t// In that case, the first minion will spawn at the left, then the next one will spawn again at the left\r\n// \t// thus inverting the expected order\r\n// \t// We still want to process the minions from left to right, but maybe we need to decrease the index from\r\n// \t// the right in case of multiple minions dying and dpawning at the same time\r\n// \t// let boardSizeBeforeDrSpawn = firstBoard.length;\r\n// \tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n// \t\t\t// console.log('\\ndead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n// \t\t\t// console.log(deadMinionIndexesFromRight);\r\n// \t\t\t// console.log(stringifySimple(firstBoard, allCards));\r\n// \t\t\t// Because we use the index from right, and spawn minions from left to right, we actually\r\n// \t\t\t// don't need to update the index after a minion has spawned\r\n// \t\t\tconst modifiedIndexFromRight = Math.min(firstBoard.length, indexFromRight);\r\n// \t\t\t// console.log('spawning at', modifiedIndexFromRight, indexFromRight, totalSpawned, firstBoard.length);\r\n// \t\t\tbuildBoardAfterDeathrattleSpawns(\r\n// \t\t\t\tfirstBoard,\r\n// \t\t\t\tfirstBoardHero,\r\n// \t\t\t\tentity,\r\n// \t\t\t\tmodifiedIndexFromRight,\r\n// \t\t\t\totherBoard,\r\n// \t\t\t\totherBoardHero,\r\n// \t\t\t\tdeadEntities,\r\n// \t\t\t\tgameState,\r\n// \t\t\t);\r\n// \t\t} else if (firstBoard.length > 0) {\r\n// \t\t\t// const newBoardD = [...firstBoard];\r\n// \t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n// \t\t\t// firstBoard = newBoardD;\r\n// \t\t}\r\n// \t\t// boardSizeBeforeDrSpawn = firstBoard.length;\r\n// \t}\r\n// \t// return [firstBoard, otherBoard];\r\n// };\r\n\r\n// const handleRebornForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \t// console.log('will handle reborn', stringifySimple(firstBoard, allCards), deadMinionIndexesFromRight);\r\n// \tfor (let i = deadMinionIndexesFromRight.length - 1; i >= 0; i--) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tif (entity.health <= 0 || entity.definitelyDead) {\r\n// \t\t\t// console.log('dead entity', stringifySimpleCard(entity, allCards), indexFromRight);\r\n// \t\t\tbuildBoardAfterRebornSpawns(\r\n// \t\t\t\tfirstBoard,\r\n// \t\t\t\tfirstBoardHero,\r\n// \t\t\t\tentity,\r\n// \t\t\t\tindexFromRight,\r\n// \t\t\t\totherBoard,\r\n// \t\t\t\totherBoardHero,\r\n// \t\t\t\tgameState,\r\n// \t\t\t);\r\n// \t\t\t// console.log('after rebord', stringifySimple(firstBoard, allCards));\r\n// \t\t} else if (firstBoard.length > 0) {\r\n// \t\t\t// const newBoardD = [...firstBoard];\r\n// \t\t\tfirstBoard.splice(firstBoard.length - indexFromRight, 1, entity);\r\n// \t\t\t// firstBoard = newBoardD;\r\n// \t\t}\r\n// \t}\r\n// \t// return [firstBoard, otherBoard];\r\n// };\r\n\r\n// const handleAfterDeathEffectsForFirstBoard = (\r\n// \tfirstBoard: BoardEntity[],\r\n// \tfirstBoardHero: BgsPlayerEntity,\r\n// \totherBoard: BoardEntity[],\r\n// \totherBoardHero: BgsPlayerEntity,\r\n// \tdeadMinionIndexesFromRight: readonly number[],\r\n// \tdeadEntities: readonly BoardEntity[],\r\n// \tgameState: FullGameState,\r\n// ): void => {\r\n// \tfor (let i = 0; i < deadMinionIndexesFromRight.length; i++) {\r\n// \t\tconst entity = deadEntities[i];\r\n// \t\tconst indexFromRight = deadMinionIndexesFromRight[i];\r\n// \t\tapplyAfterDeathEffects(\r\n// \t\t\tentity,\r\n// \t\t\tindexFromRight,\r\n// \t\t\tfirstBoard,\r\n// \t\t\tfirstBoardHero,\r\n// \t\t\totherBoard,\r\n// \t\t\totherBoardHero,\r\n// \t\t\tgameState,\r\n// \t\t);\r\n// \t}\r\n// };\r\n"]}
|
|
@@ -5,4 +5,4 @@ export declare const handleStartOfCombat: (playerEntity: BgsPlayerEntity, player
|
|
|
5
5
|
export declare const handleIllidanHeroPowers: (playerEntity: BgsPlayerEntity, playerBoard: BoardEntity[], opponentEntity: BgsPlayerEntity, opponentBoard: BoardEntity[], currentAttacker: number, gameState: FullGameState) => number;
|
|
6
6
|
export declare const handleStartOfCombatHeroPowers: (playerEntity: BgsPlayerEntity, playerBoard: BoardEntity[], opponentEntity: BgsPlayerEntity, opponentBoard: BoardEntity[], currentAttacker: number, gameState: FullGameState) => number;
|
|
7
7
|
export declare const getHeroPowerForHero: (heroCardId: string) => string;
|
|
8
|
-
export declare const performStartOfCombatMinionsForPlayer: (attacker: BoardEntity, attackingBoard: BoardEntity[], attackingBoardHero: BgsPlayerEntity, defendingBoard: BoardEntity[], defendingBoardHero: BgsPlayerEntity, attackingBoardBefore: BoardEntity[], defendingBoardBefore: BoardEntity[], gameState: FullGameState) =>
|
|
8
|
+
export declare const performStartOfCombatMinionsForPlayer: (attacker: BoardEntity, attackingBoard: BoardEntity[], attackingBoardHero: BgsPlayerEntity, defendingBoard: BoardEntity[], defendingBoardHero: BgsPlayerEntity, attackingBoardBefore: BoardEntity[], defendingBoardBefore: BoardEntity[], gameState: FullGameState) => boolean;
|
|
@@ -15,6 +15,16 @@ const stats_1 = require("./stats");
|
|
|
15
15
|
const summon_when_space_1 = require("./summon-when-space");
|
|
16
16
|
const golden_1 = require("./utils/golden");
|
|
17
17
|
const handleStartOfCombat = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
|
|
18
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
19
|
+
const shouldRecomputeCurrentAttacker = true;
|
|
20
|
+
if (shouldRecomputeCurrentAttacker) {
|
|
21
|
+
currentAttacker =
|
|
22
|
+
playerBoard.length > opponentBoard.length
|
|
23
|
+
? 0
|
|
24
|
+
: opponentBoard.length > playerBoard.length
|
|
25
|
+
? 1
|
|
26
|
+
: Math.round(Math.random());
|
|
27
|
+
}
|
|
18
28
|
currentAttacker = handleStartOfCombatQuestRewards(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
|
|
19
29
|
currentAttacker = handleStartOfCombatAnomalies(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
|
|
20
30
|
currentAttacker = handlePreCombatHeroPowers(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
|
|
@@ -39,6 +49,7 @@ const handlePreCombatHeroPowers = (playerEntity, playerBoard, opponentEntity, op
|
|
|
39
49
|
currentAttacker = handlePreCombatHeroPowersForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, false, gameState);
|
|
40
50
|
currentAttacker = handlePreCombatHeroPowersForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, true, gameState);
|
|
41
51
|
}
|
|
52
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
42
53
|
return currentAttacker;
|
|
43
54
|
};
|
|
44
55
|
const handlePreCombatHeroPowersForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, friendly, gameState) => {
|
|
@@ -111,29 +122,39 @@ const handleIllidanHeroPowers = (playerEntity, playerBoard, opponentEntity, oppo
|
|
|
111
122
|
currentAttacker = handlePlayerIllidanHeroPowers(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, true, gameState);
|
|
112
123
|
}
|
|
113
124
|
(0, attack_1.processMinionDeath)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
125
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
114
126
|
return currentAttacker;
|
|
115
127
|
};
|
|
116
128
|
exports.handleIllidanHeroPowers = handleIllidanHeroPowers;
|
|
117
129
|
const handleStartOfCombatMinions = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, playerBoardBefore, opponentBoardBefore, gameState) => {
|
|
118
|
-
let attackerForStart =
|
|
130
|
+
let attackerForStart = Math.random() < 0.5 ? 0 : 1;
|
|
119
131
|
const playerAttackers = [...playerBoard];
|
|
120
132
|
const opponentAttackers = [...opponentBoard];
|
|
121
133
|
while (playerAttackers.length > 0 || opponentAttackers.length > 0) {
|
|
134
|
+
let shouldUpdateNextPlayer = false;
|
|
122
135
|
if (attackerForStart === 0 && playerAttackers.length > 0) {
|
|
123
136
|
const attacker = playerAttackers.splice(0, 1)[0];
|
|
124
137
|
if (attacker.health <= 0 || attacker.definitelyDead) {
|
|
125
138
|
continue;
|
|
126
139
|
}
|
|
127
|
-
(0, exports.performStartOfCombatMinionsForPlayer)(attacker, playerBoard, playerEntity, opponentBoard, opponentEntity, playerBoardBefore, opponentBoardBefore, gameState);
|
|
140
|
+
shouldUpdateNextPlayer = (0, exports.performStartOfCombatMinionsForPlayer)(attacker, playerBoard, playerEntity, opponentBoard, opponentEntity, playerBoardBefore, opponentBoardBefore, gameState);
|
|
141
|
+
}
|
|
142
|
+
else if (attackerForStart === 0 && playerAttackers.length === 0) {
|
|
143
|
+
shouldUpdateNextPlayer = true;
|
|
128
144
|
}
|
|
129
145
|
else if (attackerForStart === 1 && opponentAttackers.length > 0) {
|
|
130
146
|
const attacker = opponentAttackers.splice(0, 1)[0];
|
|
131
147
|
if (attacker.health <= 0 || attacker.definitelyDead) {
|
|
132
148
|
continue;
|
|
133
149
|
}
|
|
134
|
-
(0, exports.performStartOfCombatMinionsForPlayer)(attacker, opponentBoard, opponentEntity, playerBoard, playerEntity, opponentBoardBefore, playerBoardBefore, gameState);
|
|
150
|
+
shouldUpdateNextPlayer = (0, exports.performStartOfCombatMinionsForPlayer)(attacker, opponentBoard, opponentEntity, playerBoard, playerEntity, opponentBoardBefore, playerBoardBefore, gameState);
|
|
151
|
+
}
|
|
152
|
+
else if (attackerForStart === 1 && opponentAttackers.length === 0) {
|
|
153
|
+
shouldUpdateNextPlayer = true;
|
|
154
|
+
}
|
|
155
|
+
if (shouldUpdateNextPlayer) {
|
|
156
|
+
attackerForStart = (attackerForStart + 1) % 2;
|
|
135
157
|
}
|
|
136
|
-
attackerForStart = (attackerForStart + 1) % 2;
|
|
137
158
|
}
|
|
138
159
|
return currentAttacker;
|
|
139
160
|
};
|
|
@@ -146,6 +167,7 @@ const handleStartOfCombatQuestRewards = (playerEntity, playerBoard, opponentEnti
|
|
|
146
167
|
currentAttacker = handleStartOfCombatQuestRewardsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState, false);
|
|
147
168
|
currentAttacker = handleStartOfCombatQuestRewardsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, true);
|
|
148
169
|
}
|
|
170
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
149
171
|
return currentAttacker;
|
|
150
172
|
};
|
|
151
173
|
const handleStartOfCombatSpells = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
|
|
@@ -157,11 +179,13 @@ const handleStartOfCombatSpells = (playerEntity, playerBoard, opponentEntity, op
|
|
|
157
179
|
currentAttacker = handleStartOfCombatSpellsForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState);
|
|
158
180
|
currentAttacker = handleStartOfCombatSpellsForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
|
|
159
181
|
}
|
|
182
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
160
183
|
return currentAttacker;
|
|
161
184
|
};
|
|
162
185
|
const handleStartOfCombatAnomalies = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
|
|
163
186
|
currentAttacker = handleStartOfCombatAnomaliesForPlayer(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState);
|
|
164
187
|
currentAttacker = handleStartOfCombatAnomaliesForPlayer(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, gameState);
|
|
188
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
165
189
|
return currentAttacker;
|
|
166
190
|
};
|
|
167
191
|
const handleStartOfCombatQuestRewardsForPlayer = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState, playerIsFriendly) => {
|
|
@@ -231,7 +255,6 @@ const handleStartOfCombatSpellsForPlayer = (playerEntity, playerBoard, opponentE
|
|
|
231
255
|
break;
|
|
232
256
|
case "BG28_603":
|
|
233
257
|
secret.scriptDataNum1 = (_b = secret.scriptDataNum1) !== null && _b !== void 0 ? _b : 1;
|
|
234
|
-
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
235
258
|
break;
|
|
236
259
|
case "BG28_519":
|
|
237
260
|
(0, utils_2.addStatsToBoard)(secret, playerBoard, playerEntity, 2, 1, gameState);
|
|
@@ -292,6 +315,7 @@ const handleStartOfCombatHeroPowers = (playerEntity, playerBoard, opponentEntity
|
|
|
292
315
|
currentAttacker = handlePlayerStartOfCombatHeroPowers(opponentEntity, opponentBoard, playerEntity, playerBoard, currentAttacker, false, gameState);
|
|
293
316
|
currentAttacker = handlePlayerStartOfCombatHeroPowers(playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, true, gameState);
|
|
294
317
|
}
|
|
318
|
+
(0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
|
|
295
319
|
return currentAttacker;
|
|
296
320
|
};
|
|
297
321
|
exports.handleStartOfCombatHeroPowers = handleStartOfCombatHeroPowers;
|
|
@@ -532,8 +556,9 @@ exports.getHeroPowerForHero = getHeroPowerForHero;
|
|
|
532
556
|
const performStartOfCombatMinionsForPlayer = (attacker, attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, attackingBoardBefore, defendingBoardBefore, gameState) => {
|
|
533
557
|
var _a, _b, _c, _d;
|
|
534
558
|
if (attackingBoardHero.startOfCombatDone) {
|
|
535
|
-
return;
|
|
559
|
+
return false;
|
|
536
560
|
}
|
|
561
|
+
let hasProcessed = true;
|
|
537
562
|
if (attacker.cardId === "BGS_019") {
|
|
538
563
|
const damage = attackingBoardBefore
|
|
539
564
|
.map((entity) => gameState.allCards.getCard(entity.cardId).races)
|
|
@@ -864,7 +889,11 @@ const performStartOfCombatMinionsForPlayer = (attacker, attackingBoard, attackin
|
|
|
864
889
|
gameState.spectator.registerPowerTarget(attacker, attacker, attackingBoard, attackingBoardHero, defendingBoardHero);
|
|
865
890
|
}
|
|
866
891
|
}
|
|
892
|
+
else {
|
|
893
|
+
hasProcessed = false;
|
|
894
|
+
}
|
|
867
895
|
(0, attack_1.processMinionDeath)(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);
|
|
896
|
+
return hasProcessed;
|
|
868
897
|
};
|
|
869
898
|
exports.performStartOfCombatMinionsForPlayer = performStartOfCombatMinionsForPlayer;
|
|
870
899
|
const applyAllWillBurn = (board1, board1Hero, board2, board2Hero, sourceEntity, gameState) => {
|