@firestone-hs/simulate-bgs-battle 1.1.738 → 1.1.739
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/cards/cards-data.js +63 -38
- package/dist/cards/cards-data.js.map +1 -1
- package/dist/cards/impl/trinket/soul-fermenter.js +1 -1
- package/dist/cards/impl/trinket/soul-fermenter.js.map +1 -1
- package/dist/input-sanitation.js +12 -9
- package/dist/input-sanitation.js.map +1 -1
- package/dist/simulate-bgs-battle.d.ts +1 -0
- package/dist/simulate-bgs-battle.js +114 -21
- package/dist/simulate-bgs-battle.js.map +1 -1
- package/dist/simulation/after-attack.d.ts +1 -1
- package/dist/simulation/after-attack.js +21 -21
- package/dist/simulation/after-attack.js.map +1 -1
- package/dist/simulation/attack.d.ts +1 -0
- package/dist/simulation/attack.js +1 -1
- package/dist/simulation/attack.js.map +1 -1
- package/dist/simulation/auras.js +24 -6
- package/dist/simulation/auras.js.map +1 -1
- package/dist/simulation/combat-profile.d.ts +13 -0
- package/dist/simulation/combat-profile.js +37 -0
- package/dist/simulation/combat-profile.js.map +1 -0
- package/dist/simulation/death-effects.js +3 -0
- package/dist/simulation/death-effects.js.map +1 -1
- package/dist/simulation/internal-game-state.d.ts +1 -0
- package/dist/simulation/internal-game-state.js.map +1 -1
- package/dist/simulation/simulator.js +16 -5
- package/dist/simulation/simulator.js.map +1 -1
- package/dist/simulation/spectator/spectator.d.ts +1 -0
- package/dist/simulation/spectator/spectator.js +22 -6
- package/dist/simulation/spectator/spectator.js.map +1 -1
- package/dist/simulation/start-of-combat/soc-action-processor.js +10 -0
- package/dist/simulation/start-of-combat/soc-action-processor.js.map +1 -1
- package/dist/utils.js +12 -18
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -19,12 +19,14 @@ exports.applyAfterDeathEffects = applyAfterDeathEffects;
|
|
|
19
19
|
const handleAfterMinionDeathEffects = (deadEntity, deadEntityIndexFromRight, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState) => {
|
|
20
20
|
var _a, _b;
|
|
21
21
|
const allSpawns = [];
|
|
22
|
+
const boardBeforeProcs = [...boardWithDeadEntity];
|
|
22
23
|
for (const entity of boardWithDeadEntity) {
|
|
23
24
|
const impl = _card_mappings_1.cardMappings[entity.cardId];
|
|
24
25
|
if ((0, card_interface_1.hasOnAfterFriendlyMinionDeath)(impl)) {
|
|
25
26
|
impl.onAfterFriendlyMinionDeath(entity, {
|
|
26
27
|
deadEntity,
|
|
27
28
|
board: boardWithDeadEntity,
|
|
29
|
+
boardBeforeProcs,
|
|
28
30
|
hero: boardWithDeadEntityHero,
|
|
29
31
|
otherBoard,
|
|
30
32
|
otherHero: otherBoardHero,
|
|
@@ -38,6 +40,7 @@ const handleAfterMinionDeathEffects = (deadEntity, deadEntityIndexFromRight, boa
|
|
|
38
40
|
trinketImpl.onAfterFriendlyMinionDeath(trinket, {
|
|
39
41
|
deadEntity,
|
|
40
42
|
board: boardWithDeadEntity,
|
|
43
|
+
boardBeforeProcs,
|
|
41
44
|
hero: boardWithDeadEntityHero,
|
|
42
45
|
otherBoard,
|
|
43
46
|
otherHero: otherBoardHero,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"death-effects.js","sourceRoot":"","sources":["../../src/simulation/death-effects.ts"],"names":[],"mappings":";;;AAEA,4DAAwG;AACxG,iEAA4D;AAE5D,6CAAoD;AACpD,6DAAqD;AAErD,qCAA+C;AAC/C,mCAAsC;AACtC,uDAAqD;AAE9C,MAAM,sBAAsB,GAAG,CACrC,UAAuB,EACvB,wBAAgC,EAChC,mBAAkC,EAClC,uBAAwC,EACxC,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACR,EAAE;IAClB,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,MAAM,iBAAiB,GAAG,6BAA6B,CACtD,UAAU,EACV,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,cAAc,EAC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ACxB,MAAM,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBACzE,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAC;gBAC/E,MAAM,YAAY,GAAG,IAAA,kCAAa,EACjC,SAAS,EACT,CAAC,EACD,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,cAAc,EACd,SAAS,EACT,UAAU,CAAC,QAAQ,EACnB,KAAK,EACL,KAAK,EACL,IAAI,CACJ,CAAC;gBACF,SAAS,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;gBAChC,SAAS,CAAC,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;gBAClG,MAAM;SACP;KACD;IACD,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAEK,MAAM,mBAAmB,GAAG,CAClC,UAAuB,EACvB,wBAAgC,EAChC,mBAAkC,EAClC,uBAAwC,EACxC,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACvB,EAAE;IAEH,OAAO,EAAE,CAAC;AACX,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B","sourcesContent":["import { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { hasOnAfterFriendlyMinionDeath, hasRebornSelfAttributeTransfer } from '../cards/card.interface';\r\nimport { cardMappings } from '../cards/impl/_card-mappings';\r\nimport { CardIds } from '../services/card-ids';\r\nimport { pickRandomAlive } from '../services/utils';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { modifyStats } from './stats';\r\nimport { copyAttribute } from './utils/entity-utils';\r\n\r\nexport const applyAfterDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): BoardEntity[] => {\r\n\tconst allSpawns = [];\r\n\r\n\tconst spawnsFromSecrets = handleAfterMinionDeathEffects(\r\n\t\tdeadEntity,\r\n\t\tdeadEntityIndexFromRight,\r\n\t\tboardWithDeadEntity,\r\n\t\tboardWithDeadEntityHero,\r\n\t\totherBoard,\r\n\t\totherBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tallSpawns.push(...spawnsFromSecrets);\r\n\tperformEntitySpawns(\r\n\t\tallSpawns,\r\n\t\tboardWithDeadEntity,\r\n\t\tboardWithDeadEntityHero,\r\n\t\tdeadEntity,\r\n\t\tdeadEntityIndexFromRight,\r\n\t\totherBoard,\r\n\t\totherBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\r\n\treturn allSpawns;\r\n};\r\n\r\nconst handleAfterMinionDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): BoardEntity[] => {\r\n\tconst allSpawns = [];\r\n\r\n\t// TODO: move this to an \"after minion dies\" phase, instead of \"whenever minion dies\"\r\n\tfor (const entity of boardWithDeadEntity) {\r\n\t\tconst impl = cardMappings[entity.cardId];\r\n\t\tif (hasOnAfterFriendlyMinionDeath(impl)) {\r\n\t\t\timpl.onAfterFriendlyMinionDeath(entity, {\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\tboard: boardWithDeadEntity,\r\n\t\t\t\thero: boardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero: otherBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const trinket of boardWithDeadEntityHero.trinkets ?? []) {\r\n\t\tconst trinketImpl = cardMappings[trinket.cardId];\r\n\t\tif (hasOnAfterFriendlyMinionDeath(trinketImpl)) {\r\n\t\t\ttrinketImpl.onAfterFriendlyMinionDeath(trinket, {\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\tboard: boardWithDeadEntity,\r\n\t\t\t\thero: boardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero: otherBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const secret of (boardWithDeadEntityHero.secrets ?? []).filter((s) => !s.triggered)) {\r\n\t\tswitch (secret.cardId) {\r\n\t\t\tcase CardIds.Avenge_TB_Bacon_Secrets_08:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst avengeTarget = pickRandomAlive(boardWithDeadEntity);\r\n\t\t\t\tmodifyStats(avengeTarget, secret, 3, 2, boardWithDeadEntity, boardWithDeadEntityHero, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Redemption_TB_Bacon_Secrets_10:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst redemptionSpawns = spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\t// { ...newSpawn } as BoardEntity,\r\n\t\t\t\t);\r\n\t\t\t\tredemptionSpawns[0].health = 1;\r\n\t\t\t\t// I don't like duplicating this logic\r\n\t\t\t\tconst rebornImpl = cardMappings[redemptionSpawns[0].cardId];\r\n\t\t\t\tif (hasRebornSelfAttributeTransfer(rebornImpl)) {\r\n\t\t\t\t\trebornImpl.rebornSelfAttributeTransfer.forEach((attribute: keyof BoardEntity) => {\r\n\t\t\t\t\t\tcopyAttribute(redemptionSpawns[0], deadEntity, attribute);\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tallSpawns.push(...redemptionSpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(secret, redemptionSpawns[0], boardWithDeadEntity, null, null);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Redemption_BetterRedemption_TB_Bacon_Secrets_10b:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst betterRedemptionSpawns = spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t);\r\n\t\t\t\tfor (const spawn of betterRedemptionSpawns) {\r\n\t\t\t\t\tspawn.health = deadEntity.maxHealth;\r\n\t\t\t\t\tspawn.maxHealth = deadEntity.maxHealth;\r\n\t\t\t\t\tspawn.attack = deadEntity.attack;\r\n\t\t\t\t\tspawn.maxAttack = deadEntity.maxAttack;\r\n\t\t\t\t\tspawn.enchantments = deadEntity.enchantments;\r\n\t\t\t\t\tspawn.divineShield = deadEntity.hadDivineShield;\r\n\t\t\t\t\tconst rebornImpl = cardMappings[spawn.cardId];\r\n\t\t\t\t\tif (hasRebornSelfAttributeTransfer(rebornImpl)) {\r\n\t\t\t\t\t\trebornImpl.rebornSelfAttributeTransfer.forEach((attribute: keyof BoardEntity) => {\r\n\t\t\t\t\t\t\tcopyAttribute(spawn, deadEntity, attribute);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tallSpawns.push(...betterRedemptionSpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsecret,\r\n\t\t\t\t\tbetterRedemptionSpawns[0],\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Effigy_TB_Bacon_Secrets_05:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst minionTier = gameState.cardsData.getTavernLevel(deadEntity.cardId);\r\n\t\t\t\tconst newMinion = gameState.cardsData.getRandomMinionForTavernTier(minionTier);\r\n\t\t\t\tconst effigySpawns = spawnEntities(\r\n\t\t\t\t\tnewMinion,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t);\r\n\t\t\t\tallSpawns.push(...effigySpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(secret, effigySpawns[0], boardWithDeadEntity, null, null);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn allSpawns;\r\n};\r\n\r\nexport const applyOnDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\t// Nothing yet\r\n\treturn [];\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"death-effects.js","sourceRoot":"","sources":["../../src/simulation/death-effects.ts"],"names":[],"mappings":";;;AAEA,4DAAwG;AACxG,iEAA4D;AAE5D,6CAAoD;AACpD,6DAAqD;AAErD,qCAA+C;AAC/C,mCAAsC;AACtC,uDAAqD;AAE9C,MAAM,sBAAsB,GAAG,CACrC,UAAuB,EACvB,wBAAgC,EAChC,mBAAkC,EAClC,uBAAwC,EACxC,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACR,EAAE;IAClB,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,MAAM,iBAAiB,GAAG,6BAA6B,CACtD,UAAU,EACV,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,cAAc,EACd,SAAS,CACT,CAAC;IACF,SAAS,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC;IACrC,IAAA,4BAAmB,EAClB,SAAS,EACT,mBAAmB,EACnB,uBAAuB,EACvB,UAAU,EACV,wBAAwB,EACxB,UAAU,EACV,cAAc,EACd,SAAS,CACT,CAAC;IAEF,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAjCW,QAAA,sBAAsB,0BAiCjC;AAEF,MAAM,6BAA6B,GAAG,CACrC,UAAuB,EACvB,wBAAgC,EAChC,mBAAkC,EAClC,uBAAwC,EACxC,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACR,EAAE;;IAClB,MAAM,SAAS,GAAG,EAAE,CAAC;IAGrB,MAAM,gBAAgB,GAAG,CAAC,GAAG,mBAAmB,CAAC,CAAC;IAClD,KAAK,MAAM,MAAM,IAAI,mBAAmB,EAAE;QACzC,MAAM,IAAI,GAAG,6BAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,IAAA,8CAA6B,EAAC,IAAI,CAAC,EAAE;YACxC,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE;gBACv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mB,GAAG,CAClC,UAAuB,EACvB,wBAAgC,EAChC,mBAAkC,EAClC,uBAAwC,EACxC,UAAyB,EACzB,cAA+B,EAC/B,SAAwB,EACvB,EAAE;IAEH,OAAO,EAAE,CAAC;AACX,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B","sourcesContent":["import { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { hasOnAfterFriendlyMinionDeath, hasRebornSelfAttributeTransfer } from '../cards/card.interface';\r\nimport { cardMappings } from '../cards/impl/_card-mappings';\r\nimport { CardIds } from '../services/card-ids';\r\nimport { pickRandomAlive } from '../services/utils';\r\nimport { spawnEntities } from './deathrattle-spawns';\r\nimport { FullGameState } from './internal-game-state';\r\nimport { performEntitySpawns } from './spawns';\r\nimport { modifyStats } from './stats';\r\nimport { copyAttribute } from './utils/entity-utils';\r\n\r\nexport const applyAfterDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): BoardEntity[] => {\r\n\tconst allSpawns = [];\r\n\r\n\tconst spawnsFromSecrets = handleAfterMinionDeathEffects(\r\n\t\tdeadEntity,\r\n\t\tdeadEntityIndexFromRight,\r\n\t\tboardWithDeadEntity,\r\n\t\tboardWithDeadEntityHero,\r\n\t\totherBoard,\r\n\t\totherBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\tallSpawns.push(...spawnsFromSecrets);\r\n\tperformEntitySpawns(\r\n\t\tallSpawns,\r\n\t\tboardWithDeadEntity,\r\n\t\tboardWithDeadEntityHero,\r\n\t\tdeadEntity,\r\n\t\tdeadEntityIndexFromRight,\r\n\t\totherBoard,\r\n\t\totherBoardHero,\r\n\t\tgameState,\r\n\t);\r\n\r\n\treturn allSpawns;\r\n};\r\n\r\nconst handleAfterMinionDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n): BoardEntity[] => {\r\n\tconst allSpawns = [];\r\n\r\n\t// TODO: move this to an \"after minion dies\" phase, instead of \"whenever minion dies\"\r\n\tconst boardBeforeProcs = [...boardWithDeadEntity];\r\n\tfor (const entity of boardWithDeadEntity) {\r\n\t\tconst impl = cardMappings[entity.cardId];\r\n\t\tif (hasOnAfterFriendlyMinionDeath(impl)) {\r\n\t\t\timpl.onAfterFriendlyMinionDeath(entity, {\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\tboard: boardWithDeadEntity,\r\n\t\t\t\tboardBeforeProcs,\r\n\t\t\t\thero: boardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero: otherBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const trinket of boardWithDeadEntityHero.trinkets ?? []) {\r\n\t\tconst trinketImpl = cardMappings[trinket.cardId];\r\n\t\tif (hasOnAfterFriendlyMinionDeath(trinketImpl)) {\r\n\t\t\ttrinketImpl.onAfterFriendlyMinionDeath(trinket, {\r\n\t\t\t\tdeadEntity,\r\n\t\t\t\tboard: boardWithDeadEntity,\r\n\t\t\t\tboardBeforeProcs,\r\n\t\t\t\thero: boardWithDeadEntityHero,\r\n\t\t\t\totherBoard,\r\n\t\t\t\totherHero: otherBoardHero,\r\n\t\t\t\tgameState,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfor (const secret of (boardWithDeadEntityHero.secrets ?? []).filter((s) => !s.triggered)) {\r\n\t\tswitch (secret.cardId) {\r\n\t\t\tcase CardIds.Avenge_TB_Bacon_Secrets_08:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst avengeTarget = pickRandomAlive(boardWithDeadEntity);\r\n\t\t\t\tmodifyStats(avengeTarget, secret, 3, 2, boardWithDeadEntity, boardWithDeadEntityHero, gameState);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Redemption_TB_Bacon_Secrets_10:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst redemptionSpawns = spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t\t// { ...newSpawn } as BoardEntity,\r\n\t\t\t\t);\r\n\t\t\t\tredemptionSpawns[0].health = 1;\r\n\t\t\t\t// I don't like duplicating this logic\r\n\t\t\t\tconst rebornImpl = cardMappings[redemptionSpawns[0].cardId];\r\n\t\t\t\tif (hasRebornSelfAttributeTransfer(rebornImpl)) {\r\n\t\t\t\t\trebornImpl.rebornSelfAttributeTransfer.forEach((attribute: keyof BoardEntity) => {\r\n\t\t\t\t\t\tcopyAttribute(redemptionSpawns[0], deadEntity, attribute);\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tallSpawns.push(...redemptionSpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(secret, redemptionSpawns[0], boardWithDeadEntity, null, null);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Redemption_BetterRedemption_TB_Bacon_Secrets_10b:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst betterRedemptionSpawns = spawnEntities(\r\n\t\t\t\t\tdeadEntity.cardId,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t);\r\n\t\t\t\tfor (const spawn of betterRedemptionSpawns) {\r\n\t\t\t\t\tspawn.health = deadEntity.maxHealth;\r\n\t\t\t\t\tspawn.maxHealth = deadEntity.maxHealth;\r\n\t\t\t\t\tspawn.attack = deadEntity.attack;\r\n\t\t\t\t\tspawn.maxAttack = deadEntity.maxAttack;\r\n\t\t\t\t\tspawn.enchantments = deadEntity.enchantments;\r\n\t\t\t\t\tspawn.divineShield = deadEntity.hadDivineShield;\r\n\t\t\t\t\tconst rebornImpl = cardMappings[spawn.cardId];\r\n\t\t\t\t\tif (hasRebornSelfAttributeTransfer(rebornImpl)) {\r\n\t\t\t\t\t\trebornImpl.rebornSelfAttributeTransfer.forEach((attribute: keyof BoardEntity) => {\r\n\t\t\t\t\t\t\tcopyAttribute(spawn, deadEntity, attribute);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tallSpawns.push(...betterRedemptionSpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(\r\n\t\t\t\t\tsecret,\r\n\t\t\t\t\tbetterRedemptionSpawns[0],\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\tcase CardIds.Effigy_TB_Bacon_Secrets_05:\r\n\t\t\t\tsecret.triggered = true;\r\n\t\t\t\tconst minionTier = gameState.cardsData.getTavernLevel(deadEntity.cardId);\r\n\t\t\t\tconst newMinion = gameState.cardsData.getRandomMinionForTavernTier(minionTier);\r\n\t\t\t\tconst effigySpawns = spawnEntities(\r\n\t\t\t\t\tnewMinion,\r\n\t\t\t\t\t1,\r\n\t\t\t\t\tboardWithDeadEntity,\r\n\t\t\t\t\tboardWithDeadEntityHero,\r\n\t\t\t\t\totherBoard,\r\n\t\t\t\t\totherBoardHero,\r\n\t\t\t\t\tgameState,\r\n\t\t\t\t\tdeadEntity.friendly,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\tfalse,\r\n\t\t\t\t\ttrue,\r\n\t\t\t\t);\r\n\t\t\t\tallSpawns.push(...effigySpawns);\r\n\t\t\t\tgameState.spectator.registerPowerTarget(secret, effigySpawns[0], boardWithDeadEntity, null, null);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn allSpawns;\r\n};\r\n\r\nexport const applyOnDeathEffects = (\r\n\tdeadEntity: BoardEntity,\r\n\tdeadEntityIndexFromRight: number,\r\n\tboardWithDeadEntity: BoardEntity[],\r\n\tboardWithDeadEntityHero: BgsPlayerEntity,\r\n\totherBoard: BoardEntity[],\r\n\totherBoardHero: BgsPlayerEntity,\r\n\tgameState: FullGameState,\r\n) => {\r\n\t// Nothing yet\r\n\treturn [];\r\n};\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-game-state.js","sourceRoot":"","sources":["../../src/simulation/internal-game-state.ts"],"names":[],"mappings":"","sourcesContent":["import { AllCardsService, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData } from '../cards/cards-data';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport interface FullGameState {\r\n\tallCards: AllCardsService;\r\n\tcardsData: CardsData;\r\n\tspectator: Spectator;\r\n\tsharedState: SharedState;\r\n\tcurrentTurn: number;\r\n\t/** Heroes still alive in the lobby; used when applyDamageCap is set. */\r\n\tnumberOfPlayersAlive?: number;\r\n\t/** When true, apply the Battlegrounds lobby damage cap. Default off. */\r\n\tapplyDamageCap?: boolean;\r\n\t/** When true, Ice Block can prevent end-of-combat face damage. Default off. */\r\n\tapplyIceBlock?: boolean;\r\n\tvalidTribes: readonly Race[];\r\n\tanomalies: readonly string[];\r\n\tgameState: GameState;\r\n}\r\n\r\nexport interface GameState {\r\n\tplayer: PlayerState;\r\n\topponent: PlayerState;\r\n\tplayerInitial: PlayerState;\r\n\topponentInitial: PlayerState;\r\n}\r\n\r\nexport interface PlayerState {\r\n\tboard: BoardEntity[];\r\n\tplayer: BgsPlayerEntity;\r\n\tteammate?: PlayerState;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"internal-game-state.js","sourceRoot":"","sources":["../../src/simulation/internal-game-state.ts"],"names":[],"mappings":"","sourcesContent":["import { AllCardsService, Race } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { CardsData } from '../cards/cards-data';\r\nimport { SharedState } from './shared-state';\r\nimport { Spectator } from './spectator/spectator';\r\n\r\nexport interface FullGameState {\r\n\tallCards: AllCardsService;\r\n\tcardsData: CardsData;\r\n\tspectator: Spectator;\r\n\tsharedState: SharedState;\r\n\tcurrentTurn: number;\r\n\t/** Heroes still alive in the lobby; used when applyDamageCap is set. */\r\n\tnumberOfPlayersAlive?: number;\r\n\t/** When true, apply the Battlegrounds lobby damage cap. Default off. */\r\n\tapplyDamageCap?: boolean;\r\n\t/** When true, Ice Block can prevent end-of-combat face damage. Default off. */\r\n\tapplyIceBlock?: boolean;\r\n\t/** True when the battle input had a teammate board (Duos). Do not infer from in-fight teammate shells. */\r\n\tisDuos?: boolean;\r\n\tvalidTribes: readonly Race[];\r\n\tanomalies: readonly string[];\r\n\tgameState: GameState;\r\n}\r\n\r\nexport interface GameState {\r\n\tplayer: PlayerState;\r\n\topponent: PlayerState;\r\n\tplayerInitial: PlayerState;\r\n\topponentInitial: PlayerState;\r\n}\r\n\r\nexport interface PlayerState {\r\n\tboard: BoardEntity[];\r\n\tplayer: BgsPlayerEntity;\r\n\tteammate?: PlayerState;\r\n}\r\n"]}
|
|
@@ -11,6 +11,7 @@ const pending_effects_1 = require("./pending-effects");
|
|
|
11
11
|
const secrets_1 = require("./secrets");
|
|
12
12
|
const start_of_combat_1 = require("./start-of-combat/start-of-combat");
|
|
13
13
|
const summon_when_space_1 = require("./summon-when-space");
|
|
14
|
+
const combat_profile_1 = require("./combat-profile");
|
|
14
15
|
class Simulator {
|
|
15
16
|
constructor(gameState) {
|
|
16
17
|
this.gameState = gameState;
|
|
@@ -122,6 +123,7 @@ class Simulator {
|
|
|
122
123
|
};
|
|
123
124
|
const withQuestWriteback = (base) => {
|
|
124
125
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
126
|
+
const t0 = (0, combat_profile_1.combatProfileEnabled)() ? performance.now() : 0;
|
|
125
127
|
const playerQ = snapshotQuests(playerEntity);
|
|
126
128
|
const opponentQ = snapshotQuests(opponentEntity);
|
|
127
129
|
const snapshotHand = (hand) => (hand !== null && hand !== void 0 ? hand : []).map((e) => {
|
|
@@ -137,7 +139,7 @@ class Simulator {
|
|
|
137
139
|
.map((s) => ({ ...s }));
|
|
138
140
|
const snapshotTrinkets = (trinkets) => (trinkets !== null && trinkets !== void 0 ? trinkets : []).map((t) => ({ ...t }));
|
|
139
141
|
const snapshotHeroPowers = (hps) => (hps !== null && hps !== void 0 ? hps : []).map((hp) => ({ ...hp }));
|
|
140
|
-
|
|
142
|
+
const packed = {
|
|
141
143
|
...base,
|
|
142
144
|
playerQuestEntities: playerQ.questEntities,
|
|
143
145
|
playerQuestRewards: playerQ.questRewards,
|
|
@@ -162,6 +164,10 @@ class Simulator {
|
|
|
162
164
|
playerHeroPowers: snapshotHeroPowers(playerEntity === null || playerEntity === void 0 ? void 0 : playerEntity.heroPowers),
|
|
163
165
|
opponentHeroPowers: snapshotHeroPowers(opponentEntity === null || opponentEntity === void 0 ? void 0 : opponentEntity.heroPowers),
|
|
164
166
|
};
|
|
167
|
+
if (t0) {
|
|
168
|
+
(0, combat_profile_1.combatProfileAdd)('writebackMs', performance.now() - t0);
|
|
169
|
+
}
|
|
170
|
+
return packed;
|
|
165
171
|
};
|
|
166
172
|
if ((!(playerBoard === null || playerBoard === void 0 ? void 0 : playerBoard.length) && !(opponentBoard === null || opponentBoard === void 0 ? void 0 : opponentBoard.length)) ||
|
|
167
173
|
((playerBoard === null || playerBoard === void 0 ? void 0 : playerBoard.length) > 0 && (opponentBoard === null || opponentBoard === void 0 ? void 0 : opponentBoard.length) > 0)) {
|
|
@@ -237,12 +243,16 @@ class Simulator {
|
|
|
237
243
|
: effectiveOpponentBoardLength > effectivePlayerBoardLength
|
|
238
244
|
? 1
|
|
239
245
|
: Math.round(Math.random());
|
|
246
|
+
const profile = (0, combat_profile_1.combatProfileEnabled)();
|
|
247
|
+
const socT0 = profile ? performance.now() : 0;
|
|
240
248
|
const suggestedNewCurrentAttacker = (0, start_of_combat_1.handleStartOfCombat)(playerEntity, playerBoard, opponentEntity, opponentBoard, this.currentAttacker, this.gameState);
|
|
241
249
|
this.currentAttacker = suggestedNewCurrentAttacker;
|
|
250
|
+
const socMs = profile ? performance.now() - socT0 : 0;
|
|
242
251
|
let counter = 0;
|
|
243
252
|
if (debug_state_1.debugState === null || debug_state_1.debugState === void 0 ? void 0 : debug_state_1.debugState.active) {
|
|
244
253
|
this.currentAttacker = (_a = debug_state_1.debugState.forcedCurrentAttacker) !== null && _a !== void 0 ? _a : this.currentAttacker;
|
|
245
254
|
}
|
|
255
|
+
const atkT0 = profile ? performance.now() : 0;
|
|
246
256
|
while (playerBoard.length > 0 &&
|
|
247
257
|
opponentBoard.length > 0 &&
|
|
248
258
|
playerEntity.hpLeft > 0 &&
|
|
@@ -286,15 +296,16 @@ class Simulator {
|
|
|
286
296
|
break;
|
|
287
297
|
}
|
|
288
298
|
}
|
|
299
|
+
if (profile) {
|
|
300
|
+
(0, combat_profile_1.combatProfileAdd)('socMs', socMs);
|
|
301
|
+
(0, combat_profile_1.combatProfileAdd)('atkMs', performance.now() - atkT0);
|
|
302
|
+
}
|
|
289
303
|
}
|
|
290
304
|
capDamage(damage) {
|
|
291
|
-
var _a, _b;
|
|
292
305
|
if (!this.gameState.applyDamageCap) {
|
|
293
306
|
return damage;
|
|
294
307
|
}
|
|
295
|
-
|
|
296
|
-
!!((_b = this.gameState.gameState.opponentInitial) === null || _b === void 0 ? void 0 : _b.teammate);
|
|
297
|
-
return (0, damage_cap_1.applyCombatDamageCap)(damage, this.gameState.currentTurn, this.gameState.numberOfPlayersAlive, isDuos);
|
|
308
|
+
return (0, damage_cap_1.applyCombatDamageCap)(damage, this.gameState.currentTurn, this.gameState.numberOfPlayersAlive, !!this.gameState.isDuos);
|
|
298
309
|
}
|
|
299
310
|
buildBoardTotalDamage(playerBoard, teammateBoard) {
|
|
300
311
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulator.js","sourceRoot":"","sources":["../../src/simulation/simulator.ts"],"names":[],"mappings":";;;AAAA,iEAAqE;AAGrE,gDAA4C;AAE5C,oCAAgE;AAChE,qCAA0C;AAC1C,mCAA+C;AAC/C,6CAAoD;AAEpD,uDAA0D;AAC1D,uCAA+D;AAC/D,uEAAwE;AACxE,2DAA6D;AAG7D,MAAa,SAAS;IAOrB,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QAL7C,yBAAoB,GAAG,CAAC,CAAC,CAAC;QAE1B,+BAA0B,GAAG,KAAK,CAAC;IAGa,CAAC;IAIlD,oBAAoB,CAAC,WAAwB,EAAE,aAA0B;;QAC/E,IAAI,WAAW,GAAkB,WAAW,CAAC,KAAK,CAAC;QACnD,IAAI,YAAY,GAAoB,WAAW,CAAC,MAAM,CAAC;QACvD,IAAI,aAAa,GAAkB,aAAa,CAAC,KAAK,CAAC;QACvD,IAAI,cAAc,GAAoB,aAAa,CAAC,MAAM,CAAC;QAE3D,YAA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AE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,MAAM,+BAA+B,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;QAC/D,MAAM,uBAAuB,GAC5B,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CACV,KAAK,CAAC,CAAC,EAAE,+BAA+B,EACzC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACf,IAAA,sCAAqB,EAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAE9F,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,mCAAI,CAAC,CAAC;QACnC,OAAO,qBAAqB,GAAG,uBAAuB,CAAC;IACxD,CAAC;CACD;AA1aD,8BA0aC","sourcesContent":["import { getEffectiveTechLevel } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { debugState } from '../debug-state';\r\nimport { SingleSimulationResult } from '../single-simulation-result';\r\nimport { stringifySimple, stringifySimpleCard } from '../utils';\r\nimport { simulateAttack } from './attack';\r\nimport { clearStealthIfNeeded } from './auras';\r\nimport { applyCombatDamageCap } from './damage-cap';\r\nimport { FullGameState, PlayerState } from './internal-game-state';\r\nimport { resolvePendingEffects } from './pending-effects';\r\nimport { tryPreventCombatDamageWithIceBlock } from './secrets';\r\nimport { handleStartOfCombat } from './start-of-combat/start-of-combat';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\n\r\n// New simulator should be instantiated for each match\r\nexport class Simulator {\r\n\tprivate currentAttacker: number;\r\n\tprivate currentSpeedAttacker = -1;\r\n\r\n\tprivate hasShowShortCircuitWarning = false;\r\n\r\n\t// It should come already initialized\r\n\tconstructor(private readonly gameState: FullGameState) {}\r\n\r\n\t// Here we suppose that the BoardEntity only contain at most the enchantments that are linked\r\n\t// to auras (so we probably should hand-filter that, since there are actually few auras)\r\n\tpublic simulateSingleBattle(playerState: PlayerState, opponentState: PlayerState): SingleSimulationResult {\r\n\t\tlet playerBoard: BoardEntity[] = playerState.board;\r\n\t\tlet playerEntity: BgsPlayerEntity = playerState.player;\r\n\t\tlet opponentBoard: BoardEntity[] = opponentState.board;\r\n\t\tlet opponentEntity: BgsPlayerEntity = opponentState.player;\r\n\r\n\t\tplayerEntity.globalInfo = playerEntity.globalInfo ?? {};\r\n\t\topponentEntity.globalInfo = opponentEntity.globalInfo ?? {};\r\n\t\tplayerEntity.globalInfo.RallyMinionAttacksThisCombat = 0;\r\n\t\topponentEntity.globalInfo.RallyMinionAttacksThisCombat = 0;\r\n\t\tplayerEntity.globalInfo.FreeRefreshesGainedThisCombat = 0;\r\n\t\topponentEntity.globalInfo.FreeRefreshesGainedThisCombat = 0;\r\n\r\n\t\tlet maxEntityId = -Infinity;\r\n\t\tfor (const group of [playerBoard, opponentBoard, playerEntity.hand, opponentEntity.hand]) {\r\n\t\t\tfor (const entity of group ?? []) {\r\n\t\t\t\tif (entity.entityId > maxEntityId) {\r\n\t\t\t\t\tmaxEntityId = entity.entityId;\r\n\t\t\t\t}\r\n\t\t\t\tfor (const enchantment of entity.enchantments ?? []) {\r\n\t\t\t\t\tif (enchantment.originEntityId > maxEntityId) {\r\n\t\t\t\t\t\tmaxEntityId = enchantment.originEntityId;\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\tthis.gameState.sharedState.currentEntityId = maxEntityId + 1;\r\n\r\n\t\twhile (\r\n\t\t\t!playerEntity.startOfCombatDone ||\r\n\t\t\t!opponentEntity.startOfCombatDone ||\r\n\t\t\t(playerBoard?.length > 0 && opponentBoard?.length > 0)\r\n\t\t) {\r\n\t\t\t// Diagnostic only: detect runaway enchantment growth. The full entity id arrays are\r\n\t\t\t// only built in debug mode, since this allocates a lot on every battle pass\r\n\t\t\tif (debugState?.active) {\r\n\t\t\t\tthis.logRunawayEntityDiagnostics(playerBoard, playerEntity, opponentBoard, opponentEntity);\r\n\t\t\t}\r\n\t\t\tthis.simulateSingleBattlePass(playerBoard, playerEntity, opponentBoard, opponentEntity);\r\n\t\t\tif (this.hasShowShortCircuitWarning) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// The only case where there can only 0-attack minions on a board is when both boards\r\n\t\t\t// are that way (otherwise one side would kill the other)\r\n\t\t\tconst areBothBoards0Attack =\r\n\t\t\t\tplayerState.board.length > 0 &&\r\n\t\t\t\tplayerState.board.every((entity) => entity.attack === 0) &&\r\n\t\t\t\topponentState.board.length > 0 &&\r\n\t\t\t\topponentState.board.every((entity) => entity.attack === 0);\r\n\t\t\tif (areBothBoards0Attack) {\r\n\t\t\t\tplayerState.board = [];\r\n\t\t\t\topponentState.board = [];\r\n\t\t\t}\r\n\r\n\t\t\tconst isPlayerDefeated = playerState.board.length === 0 || playerState.player.hpLeft <= 0;\r\n\t\t\tconst isOpponentDefeated = opponentState.board.length === 0 || opponentState.player.hpLeft <= 0;\r\n\t\t\tif (isPlayerDefeated) {\r\n\t\t\t\tplayerBoard = playerState.teammate?.board;\r\n\t\t\t\tplayerState.board = [];\r\n\t\t\t\tplayerEntity = playerState.teammate?.player;\r\n\t\t\t} else {\r\n\t\t\t\tplayerBoard = playerState.board;\r\n\t\t\t\tplayerEntity = playerState.player;\r\n\t\t\t}\r\n\t\t\tif (isOpponentDefeated) {\r\n\t\t\t\topponentBoard = opponentState.teammate?.board;\r\n\t\t\t\topponentState.board = [];\r\n\t\t\t\topponentEntity = opponentState.teammate?.player;\r\n\t\t\t} else {\r\n\t\t\t\topponentBoard = opponentState.board;\r\n\t\t\t\topponentEntity = opponentState.player;\r\n\t\t\t}\r\n\t\t\t// So that gameState.player always refers to the active player.\r\n\t\t\t// Only swap when a real Duos teammate takes over — assigning an empty\r\n\t\t\t// teammate shell on solo defeat made isDuos true and used the flat 15\r\n\t\t\t// damage cap instead of the turn-scaled solo cap (35dd5300 t4: 13→10).\r\n\t\t\tif (isPlayerDefeated && playerEntity) {\r\n\t\t\t\t// Reset deaths\r\n\t\t\t\tthis.gameState.sharedState.deaths = this.gameState.sharedState.deaths.filter(\r\n\t\t\t\t\t(e) => e.friendly !== this.gameState.gameState.player.player.friendly,\r\n\t\t\t\t);\r\n\t\t\t\tthis.gameState.gameState.player.teammate = {\r\n\t\t\t\t\tboard: this.gameState.gameState.player.board,\r\n\t\t\t\t\tplayer: this.gameState.gameState.player.player,\r\n\t\t\t\t};\r\n\t\t\t\tthis.gameState.gameState.player.player = playerEntity;\r\n\t\t\t\tthis.gameState.gameState.player.board = playerBoard;\r\n\r\n\t\t\t\t// const initialPlayer = this.gameState.gameState.playerInitial;\r\n\t\t\t\t// const initialPlayerTeammate = initialPlayer.teammate;\r\n\t\t\t}\r\n\t\t\tif (isOpponentDefeated && opponentEntity) {\r\n\t\t\t\t// Reset deaths\r\n\t\t\t\tthis.gameState.sharedState.deaths = this.gameState.sharedState.deaths.filter(\r\n\t\t\t\t\t(e) => e.friendly !== this.gameState.gameState.opponent.player.friendly,\r\n\t\t\t\t);\r\n\t\t\t\tthis.gameState.gameState.opponent.teammate = {\r\n\t\t\t\t\tboard: this.gameState.gameState.opponent.board,\r\n\t\t\t\t\tplayer: this.gameState.gameState.opponent.player,\r\n\t\t\t\t};\r\n\t\t\t\tthis.gameState.gameState.opponent.player = opponentEntity;\r\n\t\t\t\tthis.gameState.gameState.opponent.board = opponentBoard;\r\n\t\t\t}\r\n\r\n\t\t\tif (!playerEntity || !opponentEntity) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst snapshotBoard = (board: BoardEntity[] | null | undefined): BoardEntity[] =>\r\n\t\t\t(board ?? []).map((e) => ({\r\n\t\t\t\t...e,\r\n\t\t\t\tenchantments: [...(e.enchantments ?? [])],\r\n\t\t\t\tpendingAttackBuffs: [...(e.pendingAttackBuffs ?? [])],\r\n\t\t\t\tadditionalCards: e.additionalCards ? [...e.additionalCards] : e.additionalCards,\r\n\t\t\t}));\r\n\r\n\t\tconst snapshotQuests = (hero: BgsPlayerEntity | null | undefined) => ({\r\n\t\t\tquestEntities: (hero?.questEntities ?? []).map((q) => ({ ...q })),\r\n\t\t\tquestRewards: [...(hero?.questRewards ?? [])],\r\n\t\t\tquestRewardEntities: (hero?.questRewardEntities ?? []).map((r) => ({ ...r })),\r\n\t\t});\r\n\r\n\t\tconst withQuestWriteback = (\r\n\t\t\tbase: Omit<\r\n\t\t\t\tSingleSimulationResult,\r\n\t\t\t\t| 'playerQuestEntities'\r\n\t\t\t\t| 'playerQuestRewards'\r\n\t\t\t\t| 'playerQuestRewardEntities'\r\n\t\t\t\t| 'opponentQuestEntities'\r\n\t\t\t\t| 'opponentQuestRewards'\r\n\t\t\t\t| 'opponentQuestRewardEntities'\r\n\t\t\t\t| 'playerRallyAttacksThisCombat'\r\n\t\t\t\t| 'opponentRallyAttacksThisCombat'\r\n\t\t\t\t| 'playerFreeRefreshesGainedThisCombat'\r\n\t\t\t\t| 'opponentFreeRefreshesGainedThisCombat'\r\n\t\t\t\t| 'playerFodderRefreshes'\r\n\t\t\t\t| 'opponentFodderRefreshes'\r\n\t\t\t\t| 'playerGlobalInfo'\r\n\t\t\t\t| 'opponentGlobalInfo'\r\n\t\t\t\t| 'playerHand'\r\n\t\t\t\t| 'opponentHand'\r\n\t\t\t\t| 'playerSecrets'\r\n\t\t\t\t| 'opponentSecrets'\r\n\t\t\t\t| 'playerTrinkets'\r\n\t\t\t\t| 'opponentTrinkets'\r\n\t\t\t\t| 'playerHeroPowers'\r\n\t\t\t\t| 'opponentHeroPowers'\r\n\t\t\t>,\r\n\t\t): SingleSimulationResult => {\r\n\t\t\tconst playerQ = snapshotQuests(playerEntity);\r\n\t\t\tconst opponentQ = snapshotQuests(opponentEntity);\r\n\t\t\tconst snapshotHand = (hand: typeof playerEntity.hand) =>\r\n\t\t\t\t(hand ?? []).map((e) => ({\r\n\t\t\t\t\t...e,\r\n\t\t\t\t\tenchantments: [...(e.enchantments ?? [])],\r\n\t\t\t\t\tadditionalCards: e.additionalCards ? [...e.additionalCards] : e.additionalCards,\r\n\t\t\t\t}));\r\n\t\t\tconst snapshotSecrets = (secrets: typeof playerEntity.secrets) =>\r\n\t\t\t\t(secrets ?? [])\r\n\t\t\t\t\t.filter((s) => !s.triggered)\r\n\t\t\t\t\t.map((s) => ({ ...s }));\r\n\t\t\tconst snapshotTrinkets = (trinkets: typeof playerEntity.trinkets) =>\r\n\t\t\t\t(trinkets ?? []).map((t) => ({ ...t }));\r\n\t\t\tconst snapshotHeroPowers = (hps: typeof playerEntity.heroPowers) =>\r\n\t\t\t\t(hps ?? []).map((hp) => ({ ...hp }));\r\n\t\t\treturn {\r\n\t\t\t\t...base,\r\n\t\t\t\tplayerQuestEntities: playerQ.questEntities,\r\n\t\t\t\tplayerQuestRewards: playerQ.questRewards,\r\n\t\t\t\tplayerQuestRewardEntities: playerQ.questRewardEntities,\r\n\t\t\t\topponentQuestEntities: opponentQ.questEntities,\r\n\t\t\t\topponentQuestRewards: opponentQ.questRewards,\r\n\t\t\t\topponentQuestRewardEntities: opponentQ.questRewardEntities,\r\n\t\t\t\tplayerRallyAttacksThisCombat: playerEntity?.globalInfo?.RallyMinionAttacksThisCombat ?? 0,\r\n\t\t\t\topponentRallyAttacksThisCombat: opponentEntity?.globalInfo?.RallyMinionAttacksThisCombat ?? 0,\r\n\t\t\t\tplayerFreeRefreshesGainedThisCombat:\r\n\t\t\t\t\tplayerEntity?.globalInfo?.FreeRefreshesGainedThisCombat ?? 0,\r\n\t\t\t\topponentFreeRefreshesGainedThisCombat:\r\n\t\t\t\t\topponentEntity?.globalInfo?.FreeRefreshesGainedThisCombat ?? 0,\r\n\t\t\t\tplayerFodderRefreshes: playerEntity?.globalInfo?.fodderRefreshes ?? 0,\r\n\t\t\t\topponentFodderRefreshes: opponentEntity?.globalInfo?.fodderRefreshes ?? 0,\r\n\t\t\t\tplayerGlobalInfo: { ...(playerEntity?.globalInfo ?? {}) },\r\n\t\t\t\topponentGlobalInfo: { ...(opponentEntity?.globalInfo ?? {}) },\r\n\t\t\t\tplayerHand: snapshotHand(playerEntity?.hand),\r\n\t\t\t\topponentHand: snapshotHand(opponentEntity?.hand),\r\n\t\t\t\tplayerSecrets: snapshotSecrets(playerEntity?.secrets),\r\n\t\t\t\topponentSecrets: snapshotSecrets(opponentEntity?.secrets),\r\n\t\t\t\tplayerTrinkets: snapshotTrinkets(playerEntity?.trinkets),\r\n\t\t\t\topponentTrinkets: snapshotTrinkets(opponentEntity?.trinkets),\r\n\t\t\t\tplayerHeroPowers: snapshotHeroPowers(playerEntity?.heroPowers),\r\n\t\t\t\topponentHeroPowers: snapshotHeroPowers(opponentEntity?.heroPowers),\r\n\t\t\t};\r\n\t\t};\r\n\r\n\t\tif (\r\n\t\t\t(!playerBoard?.length && !opponentBoard?.length) ||\r\n\t\t\t// E.g. when both players have a 0-attack minion\r\n\t\t\t(playerBoard?.length > 0 && opponentBoard?.length > 0)\r\n\t\t) {\r\n\t\t\treturn withQuestWriteback({\r\n\t\t\t\tresult: 'tied',\r\n\t\t\t\tdamageDealt: 0,\r\n\t\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t\t});\r\n\t\t}\r\n\t\tif (!playerBoard?.length || playerEntity?.hpLeft <= 0) {\r\n\t\t\tconst winningHero = opponentEntity ?? opponentState.player;\r\n\t\t\tconst losingHero = playerEntity ?? playerState.player;\r\n\t\t\tlet damage = this.capDamage(\r\n\t\t\t\tthis.buildBoardTotalDamage(opponentBoard, this.gameState.gameState.opponent?.teammate?.board) +\r\n\t\t\t\t\t(winningHero?.tavernTier ?? 1),\r\n\t\t\t);\r\n\t\t\t// Full-game only: Ice Block prevents face damage (opt-in via applyIceBlock).\r\n\t\t\tif (\r\n\t\t\t\tthis.gameState.applyIceBlock &&\r\n\t\t\t\tdamage > 0 &&\r\n\t\t\t\ttryPreventCombatDamageWithIceBlock(losingHero)\r\n\t\t\t) {\r\n\t\t\t\tdamage = 0;\r\n\t\t\t}\r\n\t\t\tthis.gameState.spectator.registerOpponentAttack(playerBoard, opponentBoard, damage);\r\n\t\t\treturn withQuestWriteback({\r\n\t\t\t\tresult: 'lost',\r\n\t\t\t\tdamageDealt: damage,\r\n\t\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tconst winningHero = playerEntity ?? playerState.player;\r\n\t\tconst losingHero = opponentEntity ?? opponentState.player;\r\n\t\tlet damage = this.capDamage(\r\n\t\t\tthis.buildBoardTotalDamage(playerBoard, this.gameState.gameState.player?.teammate?.board) +\r\n\t\t\t\t(winningHero?.tavernTier ?? 1),\r\n\t\t);\r\n\t\tif (\r\n\t\t\tthis.gameState.applyIceBlock &&\r\n\t\t\tdamage > 0 &&\r\n\t\t\ttryPreventCombatDamageWithIceBlock(losingHero)\r\n\t\t) {\r\n\t\t\tdamage = 0;\r\n\t\t}\r\n\t\tthis.gameState.spectator.registerPlayerAttack(playerBoard, opponentBoard, damage);\r\n\t\treturn withQuestWriteback({\r\n\t\t\tresult: 'won',\r\n\t\t\tdamageDealt: damage,\r\n\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t});\r\n\t}\r\n\r\n\tprivate logRunawayEntityDiagnostics(\r\n\t\tplayerBoard: BoardEntity[],\r\n\t\tplayerEntity: BgsPlayerEntity,\r\n\t\topponentBoard: BoardEntity[],\r\n\t\topponentEntity: BgsPlayerEntity,\r\n\t): void {\r\n\t\tconst allEntityIds: number[] = [];\r\n\t\tfor (const group of [playerBoard, opponentBoard, playerEntity.hand, opponentEntity.hand]) {\r\n\t\t\tfor (const entity of group ?? []) {\r\n\t\t\t\tconst result = [entity.entityId, ...(entity.enchantments?.map((e) => e.originEntityId) ?? [])];\r\n\t\t\t\tif (result.length > 200) {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t'too many entities for entity',\r\n\t\t\t\t\t\tresult.length,\r\n\t\t\t\t\t\tstringifySimpleCard(entity, this.gameState.allCards),\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tallEntityIds.push(...result);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (allEntityIds.length > 10000) {\r\n\t\t\tconsole.log('allEntityIds2', allEntityIds, new Error().stack);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate simulateSingleBattlePass(\r\n\t\tplayerBoard: BoardEntity[],\r\n\t\tplayerEntity: BgsPlayerEntity,\r\n\t\topponentBoard: BoardEntity[],\r\n\t\topponentEntity: BgsPlayerEntity,\r\n\t) {\r\n\t\tif (debugState?.active) {\r\n\t\t\tdebugState.onBattleStart();\r\n\t\t}\r\n\t\t// Start of combat happens only once, so we need to flag whether it has already happened for a\r\n\t\t// given player\r\n\t\tthis.gameState.spectator.registerStartOfCombat(playerBoard, opponentBoard, playerEntity, opponentEntity);\r\n\r\n\t\t// Who attacks first is decided by the game before the hero power comes into effect. However, the full board (with the generated minion)\r\n\t\t// is sent tothe simulator\r\n\t\t// But in fact, the first player decision takes into account that additional minion. See\r\n\t\t// https://replays.firestoneapp.com/?reviewId=ddbbbe93-464b-4400-8e8d-4abca8680a2e\r\n\t\tconst effectivePlayerBoardLength = playerBoard.length;\r\n\t\tconst effectiveOpponentBoardLength = opponentBoard.length;\r\n\t\tthis.currentAttacker =\r\n\t\t\teffectivePlayerBoardLength > effectiveOpponentBoardLength\r\n\t\t\t\t? 0\r\n\t\t\t\t: effectiveOpponentBoardLength > effectivePlayerBoardLength\r\n\t\t\t\t? 1\r\n\t\t\t\t: Math.round(Math.random());\r\n\t\tconst suggestedNewCurrentAttacker = handleStartOfCombat(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tthis.currentAttacker,\r\n\t\t\tthis.gameState,\r\n\t\t);\r\n\t\tthis.currentAttacker = suggestedNewCurrentAttacker;\r\n\t\tlet counter = 0;\r\n\t\tif (debugState?.active) {\r\n\t\t\tthis.currentAttacker = debugState.forcedCurrentAttacker ?? this.currentAttacker;\r\n\t\t}\r\n\t\twhile (\r\n\t\t\tplayerBoard.length > 0 &&\r\n\t\t\topponentBoard.length > 0 &&\r\n\t\t\tplayerEntity.hpLeft > 0 &&\r\n\t\t\topponentEntity.hpLeft > 0\r\n\t\t) {\r\n\t\t\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\tclearStealthIfNeeded(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t// console.log('this.currentSpeedAttacker', this.currentAttacker);\r\n\t\t\t// If there are \"attack immediately\" minions, we keep the same player\r\n\t\t\t// We put it here so that it can kick in after the start of combat effects. However here we don't want\r\n\t\t\t// to change who attacks first, so we repeat that block again after all the attacks have been resolved\r\n\t\t\t// FIXME: This is not strictly correct - if there are multiple attack immediately\r\n\t\t\t// minions that spawn on both player sides it might get a bit more complex\r\n\t\t\t// but overall it works\r\n\t\t\t// Also, this doesn't work when there are several deathrattle competing\r\n\t\t\t// to know who triggers first. See the second test case of the scallywag.test.ts\r\n\t\t\t// that is not handled properly today (the attack should in some cases happen before\r\n\t\t\t// the other deathrattle procs)\r\n\t\t\tif (playerBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 0;\r\n\t\t\t} else if (opponentBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 1;\r\n\t\t\t} else {\r\n\t\t\t\tthis.currentSpeedAttacker = -1;\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tplayerBoard.filter((e) => e.attack > 0).length === 0 &&\r\n\t\t\t\topponentBoard.filter((e) => e.attack > 0).length === 0\r\n\t\t\t) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// console.log('this.currentSpeedAttacker 2', this.currentAttacker, this.currentSpeedAttacker);\r\n\t\t\tif (this.currentSpeedAttacker === 0 || (this.currentSpeedAttacker === -1 && this.currentAttacker === 0)) {\r\n\t\t\t\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t} else {\r\n\t\t\t\tsimulateAttack(opponentBoard, opponentEntity, playerBoard, playerEntity, this.gameState);\r\n\t\t\t}\r\n\r\n\t\t\tresolvePendingEffects(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t// Update the attacker indices in case there were some deaths\r\n\t\t\tif (playerBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 0;\r\n\t\t\t} else if (opponentBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 1;\r\n\t\t\t} else {\r\n\t\t\t\tthis.currentSpeedAttacker = -1;\r\n\t\t\t\tthis.currentAttacker = (this.currentAttacker + 1) % 2;\r\n\t\t\t}\r\n\t\t\tcounter++;\r\n\t\t\tif (counter > 400 && !this.hasShowShortCircuitWarning) {\r\n\t\t\t\tconsole.warn(\r\n\t\t\t\t\t'short-circuiting simulation, too many iterations',\r\n\t\t\t\t\tcounter,\r\n\t\t\t\t\t'\\n',\r\n\t\t\t\t\tstringifySimple(playerBoard, this.gameState.allCards),\r\n\t\t\t\t\t'\\n',\r\n\t\t\t\t\tstringifySimple(opponentBoard, this.gameState.allCards),\r\n\t\t\t\t);\r\n\t\t\t\tthis.hasShowShortCircuitWarning = true;\r\n\t\t\t\tbreak;\r\n\t\t\t\t// return null;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate capDamage(damage: number): number {\r\n\t\tif (!this.gameState.applyDamageCap) {\r\n\t\t\treturn damage;\r\n\t\t}\r\n\t\tconst isDuos =\r\n\t\t\t!!this.gameState.gameState.playerInitial?.teammate ||\r\n\t\t\t!!this.gameState.gameState.opponentInitial?.teammate;\r\n\t\treturn applyCombatDamageCap(\r\n\t\t\tdamage,\r\n\t\t\tthis.gameState.currentTurn,\r\n\t\t\tthis.gameState.numberOfPlayersAlive,\r\n\t\t\tisDuos,\r\n\t\t);\r\n\t}\r\n\r\n\tprivate buildBoardTotalDamage(playerBoard: readonly BoardEntity[], teammateBoard?: BoardEntity[]): number {\r\n\t\tconst damageFromPlayerBoard = playerBoard\r\n\t\t\t.map((entity) =>\r\n\t\t\t\tgetEffectiveTechLevel(this.gameState.allCards.getCard(entity.cardId), this.gameState.allCards),\r\n\t\t\t)\r\n\t\t\t.reduce((a, b) => a + b, 0);\r\n\t\tconst numberOfTeamateMinionsToSummnon = 7 - playerBoard.length;\r\n\t\tconst damageFromTeammateBoard =\r\n\t\t\tteammateBoard\r\n\t\t\t\t?.slice(0, numberOfTeamateMinionsToSummnon)\r\n\t\t\t\t.map((entity) =>\r\n\t\t\t\t\tgetEffectiveTechLevel(this.gameState.allCards.getCard(entity.cardId), this.gameState.allCards),\r\n\t\t\t\t)\r\n\t\t\t\t.reduce((a, b) => a + b, 0) ?? 0;\r\n\t\treturn damageFromPlayerBoard + damageFromTeammateBoard;\r\n\t}\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"simulator.js","sourceRoot":"","sources":["../../src/simulation/simulator.ts"],"names":[],"mappings":";;;AAAA,iEAAqE;AAGrE,gDAA4C;AAE5C,oCAAgE;AAChE,qCAA0C;AAC1C,mCAA+C;AAC/C,6CAAoD;AAEpD,uDAA0D;AAC1D,uCAA+D;AAC/D,uEAAwE;AACxE,2DAA6D;AAC7D,qDAA0E;AAG1E,MAAa,SAAS;IAOrB,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QAL7C,yBAAoB,GAAG,CAAC,CA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AqB,EAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAE9F,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,mCAAI,CAAC,CAAC;QACnC,OAAO,qBAAqB,GAAG,uBAAuB,CAAC;IACxD,CAAC;CACD;AApbD,8BAobC","sourcesContent":["import { getEffectiveTechLevel } from '@firestone-hs/reference-data';\r\nimport { BgsPlayerEntity } from '../bgs-player-entity';\r\nimport { BoardEntity } from '../board-entity';\r\nimport { debugState } from '../debug-state';\r\nimport { SingleSimulationResult } from '../single-simulation-result';\r\nimport { stringifySimple, stringifySimpleCard } from '../utils';\r\nimport { simulateAttack } from './attack';\r\nimport { clearStealthIfNeeded } from './auras';\r\nimport { applyCombatDamageCap } from './damage-cap';\r\nimport { FullGameState, PlayerState } from './internal-game-state';\r\nimport { resolvePendingEffects } from './pending-effects';\r\nimport { tryPreventCombatDamageWithIceBlock } from './secrets';\r\nimport { handleStartOfCombat } from './start-of-combat/start-of-combat';\r\nimport { handleSummonsWhenSpace } from './summon-when-space';\r\nimport { combatProfileAdd, combatProfileEnabled } from './combat-profile';\r\n\r\n// New simulator should be instantiated for each match\r\nexport class Simulator {\r\n\tprivate currentAttacker: number;\r\n\tprivate currentSpeedAttacker = -1;\r\n\r\n\tprivate hasShowShortCircuitWarning = false;\r\n\r\n\t// It should come already initialized\r\n\tconstructor(private readonly gameState: FullGameState) {}\r\n\r\n\t// Here we suppose that the BoardEntity only contain at most the enchantments that are linked\r\n\t// to auras (so we probably should hand-filter that, since there are actually few auras)\r\n\tpublic simulateSingleBattle(playerState: PlayerState, opponentState: PlayerState): SingleSimulationResult {\r\n\t\tlet playerBoard: BoardEntity[] = playerState.board;\r\n\t\tlet playerEntity: BgsPlayerEntity = playerState.player;\r\n\t\tlet opponentBoard: BoardEntity[] = opponentState.board;\r\n\t\tlet opponentEntity: BgsPlayerEntity = opponentState.player;\r\n\r\n\t\tplayerEntity.globalInfo = playerEntity.globalInfo ?? {};\r\n\t\topponentEntity.globalInfo = opponentEntity.globalInfo ?? {};\r\n\t\tplayerEntity.globalInfo.RallyMinionAttacksThisCombat = 0;\r\n\t\topponentEntity.globalInfo.RallyMinionAttacksThisCombat = 0;\r\n\t\tplayerEntity.globalInfo.FreeRefreshesGainedThisCombat = 0;\r\n\t\topponentEntity.globalInfo.FreeRefreshesGainedThisCombat = 0;\r\n\r\n\t\tlet maxEntityId = -Infinity;\r\n\t\tfor (const group of [playerBoard, opponentBoard, playerEntity.hand, opponentEntity.hand]) {\r\n\t\t\tfor (const entity of group ?? []) {\r\n\t\t\t\tif (entity.entityId > maxEntityId) {\r\n\t\t\t\t\tmaxEntityId = entity.entityId;\r\n\t\t\t\t}\r\n\t\t\t\tfor (const enchantment of entity.enchantments ?? []) {\r\n\t\t\t\t\tif (enchantment.originEntityId > maxEntityId) {\r\n\t\t\t\t\t\tmaxEntityId = enchantment.originEntityId;\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\tthis.gameState.sharedState.currentEntityId = maxEntityId + 1;\r\n\r\n\t\twhile (\r\n\t\t\t!playerEntity.startOfCombatDone ||\r\n\t\t\t!opponentEntity.startOfCombatDone ||\r\n\t\t\t(playerBoard?.length > 0 && opponentBoard?.length > 0)\r\n\t\t) {\r\n\t\t\t// Diagnostic only: detect runaway enchantment growth. The full entity id arrays are\r\n\t\t\t// only built in debug mode, since this allocates a lot on every battle pass\r\n\t\t\tif (debugState?.active) {\r\n\t\t\t\tthis.logRunawayEntityDiagnostics(playerBoard, playerEntity, opponentBoard, opponentEntity);\r\n\t\t\t}\r\n\t\t\tthis.simulateSingleBattlePass(playerBoard, playerEntity, opponentBoard, opponentEntity);\r\n\t\t\tif (this.hasShowShortCircuitWarning) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// The only case where there can only 0-attack minions on a board is when both boards\r\n\t\t\t// are that way (otherwise one side would kill the other)\r\n\t\t\tconst areBothBoards0Attack =\r\n\t\t\t\tplayerState.board.length > 0 &&\r\n\t\t\t\tplayerState.board.every((entity) => entity.attack === 0) &&\r\n\t\t\t\topponentState.board.length > 0 &&\r\n\t\t\t\topponentState.board.every((entity) => entity.attack === 0);\r\n\t\t\tif (areBothBoards0Attack) {\r\n\t\t\t\tplayerState.board = [];\r\n\t\t\t\topponentState.board = [];\r\n\t\t\t}\r\n\r\n\t\t\tconst isPlayerDefeated = playerState.board.length === 0 || playerState.player.hpLeft <= 0;\r\n\t\t\tconst isOpponentDefeated = opponentState.board.length === 0 || opponentState.player.hpLeft <= 0;\r\n\t\t\tif (isPlayerDefeated) {\r\n\t\t\t\tplayerBoard = playerState.teammate?.board;\r\n\t\t\t\tplayerState.board = [];\r\n\t\t\t\tplayerEntity = playerState.teammate?.player;\r\n\t\t\t} else {\r\n\t\t\t\tplayerBoard = playerState.board;\r\n\t\t\t\tplayerEntity = playerState.player;\r\n\t\t\t}\r\n\t\t\tif (isOpponentDefeated) {\r\n\t\t\t\topponentBoard = opponentState.teammate?.board;\r\n\t\t\t\topponentState.board = [];\r\n\t\t\t\topponentEntity = opponentState.teammate?.player;\r\n\t\t\t} else {\r\n\t\t\t\topponentBoard = opponentState.board;\r\n\t\t\t\topponentEntity = opponentState.player;\r\n\t\t\t}\r\n\t\t\t// So that gameState.player always refers to the active player.\r\n\t\t\t// Only swap when a real Duos teammate takes over — assigning an empty\r\n\t\t\t// teammate shell on solo defeat made isDuos true and used the flat 15\r\n\t\t\t// damage cap instead of the turn-scaled solo cap (35dd5300 t4: 13→10).\r\n\t\t\tif (isPlayerDefeated && playerEntity) {\r\n\t\t\t\t// Reset deaths\r\n\t\t\t\tthis.gameState.sharedState.deaths = this.gameState.sharedState.deaths.filter(\r\n\t\t\t\t\t(e) => e.friendly !== this.gameState.gameState.player.player.friendly,\r\n\t\t\t\t);\r\n\t\t\t\tthis.gameState.gameState.player.teammate = {\r\n\t\t\t\t\tboard: this.gameState.gameState.player.board,\r\n\t\t\t\t\tplayer: this.gameState.gameState.player.player,\r\n\t\t\t\t};\r\n\t\t\t\tthis.gameState.gameState.player.player = playerEntity;\r\n\t\t\t\tthis.gameState.gameState.player.board = playerBoard;\r\n\r\n\t\t\t\t// const initialPlayer = this.gameState.gameState.playerInitial;\r\n\t\t\t\t// const initialPlayerTeammate = initialPlayer.teammate;\r\n\t\t\t}\r\n\t\t\tif (isOpponentDefeated && opponentEntity) {\r\n\t\t\t\t// Reset deaths\r\n\t\t\t\tthis.gameState.sharedState.deaths = this.gameState.sharedState.deaths.filter(\r\n\t\t\t\t\t(e) => e.friendly !== this.gameState.gameState.opponent.player.friendly,\r\n\t\t\t\t);\r\n\t\t\t\tthis.gameState.gameState.opponent.teammate = {\r\n\t\t\t\t\tboard: this.gameState.gameState.opponent.board,\r\n\t\t\t\t\tplayer: this.gameState.gameState.opponent.player,\r\n\t\t\t\t};\r\n\t\t\t\tthis.gameState.gameState.opponent.player = opponentEntity;\r\n\t\t\t\tthis.gameState.gameState.opponent.board = opponentBoard;\r\n\t\t\t}\r\n\r\n\t\t\tif (!playerEntity || !opponentEntity) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst snapshotBoard = (board: BoardEntity[] | null | undefined): BoardEntity[] =>\r\n\t\t\t(board ?? []).map((e) => ({\r\n\t\t\t\t...e,\r\n\t\t\t\tenchantments: [...(e.enchantments ?? [])],\r\n\t\t\t\tpendingAttackBuffs: [...(e.pendingAttackBuffs ?? [])],\r\n\t\t\t\tadditionalCards: e.additionalCards ? [...e.additionalCards] : e.additionalCards,\r\n\t\t\t}));\r\n\r\n\t\tconst snapshotQuests = (hero: BgsPlayerEntity | null | undefined) => ({\r\n\t\t\tquestEntities: (hero?.questEntities ?? []).map((q) => ({ ...q })),\r\n\t\t\tquestRewards: [...(hero?.questRewards ?? [])],\r\n\t\t\tquestRewardEntities: (hero?.questRewardEntities ?? []).map((r) => ({ ...r })),\r\n\t\t});\r\n\r\n\t\tconst withQuestWriteback = (\r\n\t\t\tbase: Omit<\r\n\t\t\t\tSingleSimulationResult,\r\n\t\t\t\t| 'playerQuestEntities'\r\n\t\t\t\t| 'playerQuestRewards'\r\n\t\t\t\t| 'playerQuestRewardEntities'\r\n\t\t\t\t| 'opponentQuestEntities'\r\n\t\t\t\t| 'opponentQuestRewards'\r\n\t\t\t\t| 'opponentQuestRewardEntities'\r\n\t\t\t\t| 'playerRallyAttacksThisCombat'\r\n\t\t\t\t| 'opponentRallyAttacksThisCombat'\r\n\t\t\t\t| 'playerFreeRefreshesGainedThisCombat'\r\n\t\t\t\t| 'opponentFreeRefreshesGainedThisCombat'\r\n\t\t\t\t| 'playerFodderRefreshes'\r\n\t\t\t\t| 'opponentFodderRefreshes'\r\n\t\t\t\t| 'playerGlobalInfo'\r\n\t\t\t\t| 'opponentGlobalInfo'\r\n\t\t\t\t| 'playerHand'\r\n\t\t\t\t| 'opponentHand'\r\n\t\t\t\t| 'playerSecrets'\r\n\t\t\t\t| 'opponentSecrets'\r\n\t\t\t\t| 'playerTrinkets'\r\n\t\t\t\t| 'opponentTrinkets'\r\n\t\t\t\t| 'playerHeroPowers'\r\n\t\t\t\t| 'opponentHeroPowers'\r\n\t\t\t>,\r\n\t\t): SingleSimulationResult => {\r\n\t\t\tconst t0 = combatProfileEnabled() ? performance.now() : 0;\r\n\t\t\tconst playerQ = snapshotQuests(playerEntity);\r\n\t\t\tconst opponentQ = snapshotQuests(opponentEntity);\r\n\t\t\tconst snapshotHand = (hand: typeof playerEntity.hand) =>\r\n\t\t\t\t(hand ?? []).map((e) => ({\r\n\t\t\t\t\t...e,\r\n\t\t\t\t\tenchantments: [...(e.enchantments ?? [])],\r\n\t\t\t\t\tadditionalCards: e.additionalCards ? [...e.additionalCards] : e.additionalCards,\r\n\t\t\t\t}));\r\n\t\t\tconst snapshotSecrets = (secrets: typeof playerEntity.secrets) =>\r\n\t\t\t\t(secrets ?? [])\r\n\t\t\t\t\t.filter((s) => !s.triggered)\r\n\t\t\t\t\t.map((s) => ({ ...s }));\r\n\t\t\tconst snapshotTrinkets = (trinkets: typeof playerEntity.trinkets) =>\r\n\t\t\t\t(trinkets ?? []).map((t) => ({ ...t }));\r\n\t\t\tconst snapshotHeroPowers = (hps: typeof playerEntity.heroPowers) =>\r\n\t\t\t\t(hps ?? []).map((hp) => ({ ...hp }));\r\n\t\t\tconst packed: SingleSimulationResult = {\r\n\t\t\t\t...base,\r\n\t\t\t\tplayerQuestEntities: playerQ.questEntities,\r\n\t\t\t\tplayerQuestRewards: playerQ.questRewards,\r\n\t\t\t\tplayerQuestRewardEntities: playerQ.questRewardEntities,\r\n\t\t\t\topponentQuestEntities: opponentQ.questEntities,\r\n\t\t\t\topponentQuestRewards: opponentQ.questRewards,\r\n\t\t\t\topponentQuestRewardEntities: opponentQ.questRewardEntities,\r\n\t\t\t\tplayerRallyAttacksThisCombat: playerEntity?.globalInfo?.RallyMinionAttacksThisCombat ?? 0,\r\n\t\t\t\topponentRallyAttacksThisCombat: opponentEntity?.globalInfo?.RallyMinionAttacksThisCombat ?? 0,\r\n\t\t\t\tplayerFreeRefreshesGainedThisCombat:\r\n\t\t\t\t\tplayerEntity?.globalInfo?.FreeRefreshesGainedThisCombat ?? 0,\r\n\t\t\t\topponentFreeRefreshesGainedThisCombat:\r\n\t\t\t\t\topponentEntity?.globalInfo?.FreeRefreshesGainedThisCombat ?? 0,\r\n\t\t\t\tplayerFodderRefreshes: playerEntity?.globalInfo?.fodderRefreshes ?? 0,\r\n\t\t\t\topponentFodderRefreshes: opponentEntity?.globalInfo?.fodderRefreshes ?? 0,\r\n\t\t\t\tplayerGlobalInfo: { ...(playerEntity?.globalInfo ?? {}) },\r\n\t\t\t\topponentGlobalInfo: { ...(opponentEntity?.globalInfo ?? {}) },\r\n\t\t\t\tplayerHand: snapshotHand(playerEntity?.hand),\r\n\t\t\t\topponentHand: snapshotHand(opponentEntity?.hand),\r\n\t\t\t\tplayerSecrets: snapshotSecrets(playerEntity?.secrets),\r\n\t\t\t\topponentSecrets: snapshotSecrets(opponentEntity?.secrets),\r\n\t\t\t\tplayerTrinkets: snapshotTrinkets(playerEntity?.trinkets),\r\n\t\t\t\topponentTrinkets: snapshotTrinkets(opponentEntity?.trinkets),\r\n\t\t\t\tplayerHeroPowers: snapshotHeroPowers(playerEntity?.heroPowers),\r\n\t\t\t\topponentHeroPowers: snapshotHeroPowers(opponentEntity?.heroPowers),\r\n\t\t\t};\r\n\t\t\tif (t0) {\r\n\t\t\t\tcombatProfileAdd('writebackMs', performance.now() - t0);\r\n\t\t\t}\r\n\t\t\treturn packed;\r\n\t\t};\r\n\r\n\t\tif (\r\n\t\t\t(!playerBoard?.length && !opponentBoard?.length) ||\r\n\t\t\t// E.g. when both players have a 0-attack minion\r\n\t\t\t(playerBoard?.length > 0 && opponentBoard?.length > 0)\r\n\t\t) {\r\n\t\t\treturn withQuestWriteback({\r\n\t\t\t\tresult: 'tied',\r\n\t\t\t\tdamageDealt: 0,\r\n\t\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t\t});\r\n\t\t}\r\n\t\tif (!playerBoard?.length || playerEntity?.hpLeft <= 0) {\r\n\t\t\tconst winningHero = opponentEntity ?? opponentState.player;\r\n\t\t\tconst losingHero = playerEntity ?? playerState.player;\r\n\t\t\tlet damage = this.capDamage(\r\n\t\t\t\tthis.buildBoardTotalDamage(opponentBoard, this.gameState.gameState.opponent?.teammate?.board) +\r\n\t\t\t\t\t(winningHero?.tavernTier ?? 1),\r\n\t\t\t);\r\n\t\t\t// Full-game only: Ice Block prevents face damage (opt-in via applyIceBlock).\r\n\t\t\tif (\r\n\t\t\t\tthis.gameState.applyIceBlock &&\r\n\t\t\t\tdamage > 0 &&\r\n\t\t\t\ttryPreventCombatDamageWithIceBlock(losingHero)\r\n\t\t\t) {\r\n\t\t\t\tdamage = 0;\r\n\t\t\t}\r\n\t\t\tthis.gameState.spectator.registerOpponentAttack(playerBoard, opponentBoard, damage);\r\n\t\t\treturn withQuestWriteback({\r\n\t\t\t\tresult: 'lost',\r\n\t\t\t\tdamageDealt: damage,\r\n\t\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tconst winningHero = playerEntity ?? playerState.player;\r\n\t\tconst losingHero = opponentEntity ?? opponentState.player;\r\n\t\tlet damage = this.capDamage(\r\n\t\t\tthis.buildBoardTotalDamage(playerBoard, this.gameState.gameState.player?.teammate?.board) +\r\n\t\t\t\t(winningHero?.tavernTier ?? 1),\r\n\t\t);\r\n\t\tif (\r\n\t\t\tthis.gameState.applyIceBlock &&\r\n\t\t\tdamage > 0 &&\r\n\t\t\ttryPreventCombatDamageWithIceBlock(losingHero)\r\n\t\t) {\r\n\t\t\tdamage = 0;\r\n\t\t}\r\n\t\tthis.gameState.spectator.registerPlayerAttack(playerBoard, opponentBoard, damage);\r\n\t\treturn withQuestWriteback({\r\n\t\t\tresult: 'won',\r\n\t\t\tdamageDealt: damage,\r\n\t\t\tplayerBoard: snapshotBoard(playerBoard),\r\n\t\t\topponentBoard: snapshotBoard(opponentBoard),\r\n\t\t});\r\n\t}\r\n\r\n\tprivate logRunawayEntityDiagnostics(\r\n\t\tplayerBoard: BoardEntity[],\r\n\t\tplayerEntity: BgsPlayerEntity,\r\n\t\topponentBoard: BoardEntity[],\r\n\t\topponentEntity: BgsPlayerEntity,\r\n\t): void {\r\n\t\tconst allEntityIds: number[] = [];\r\n\t\tfor (const group of [playerBoard, opponentBoard, playerEntity.hand, opponentEntity.hand]) {\r\n\t\t\tfor (const entity of group ?? []) {\r\n\t\t\t\tconst result = [entity.entityId, ...(entity.enchantments?.map((e) => e.originEntityId) ?? [])];\r\n\t\t\t\tif (result.length > 200) {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t'too many entities for entity',\r\n\t\t\t\t\t\tresult.length,\r\n\t\t\t\t\t\tstringifySimpleCard(entity, this.gameState.allCards),\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t\tallEntityIds.push(...result);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (allEntityIds.length > 10000) {\r\n\t\t\tconsole.log('allEntityIds2', allEntityIds, new Error().stack);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate simulateSingleBattlePass(\r\n\t\tplayerBoard: BoardEntity[],\r\n\t\tplayerEntity: BgsPlayerEntity,\r\n\t\topponentBoard: BoardEntity[],\r\n\t\topponentEntity: BgsPlayerEntity,\r\n\t) {\r\n\t\tif (debugState?.active) {\r\n\t\t\tdebugState.onBattleStart();\r\n\t\t}\r\n\t\t// Start of combat happens only once, so we need to flag whether it has already happened for a\r\n\t\t// given player\r\n\t\tthis.gameState.spectator.registerStartOfCombat(playerBoard, opponentBoard, playerEntity, opponentEntity);\r\n\r\n\t\t// Who attacks first is decided by the game before the hero power comes into effect. However, the full board (with the generated minion)\r\n\t\t// is sent tothe simulator\r\n\t\t// But in fact, the first player decision takes into account that additional minion. See\r\n\t\t// https://replays.firestoneapp.com/?reviewId=ddbbbe93-464b-4400-8e8d-4abca8680a2e\r\n\t\tconst effectivePlayerBoardLength = playerBoard.length;\r\n\t\tconst effectiveOpponentBoardLength = opponentBoard.length;\r\n\t\tthis.currentAttacker =\r\n\t\t\teffectivePlayerBoardLength > effectiveOpponentBoardLength\r\n\t\t\t\t? 0\r\n\t\t\t\t: effectiveOpponentBoardLength > effectivePlayerBoardLength\r\n\t\t\t\t? 1\r\n\t\t\t\t: Math.round(Math.random());\r\n\t\tconst profile = combatProfileEnabled();\r\n\t\tconst socT0 = profile ? performance.now() : 0;\r\n\t\tconst suggestedNewCurrentAttacker = handleStartOfCombat(\r\n\t\t\tplayerEntity,\r\n\t\t\tplayerBoard,\r\n\t\t\topponentEntity,\r\n\t\t\topponentBoard,\r\n\t\t\tthis.currentAttacker,\r\n\t\t\tthis.gameState,\r\n\t\t);\r\n\t\tthis.currentAttacker = suggestedNewCurrentAttacker;\r\n\t\tconst socMs = profile ? performance.now() - socT0 : 0;\r\n\t\tlet counter = 0;\r\n\t\tif (debugState?.active) {\r\n\t\t\tthis.currentAttacker = debugState.forcedCurrentAttacker ?? this.currentAttacker;\r\n\t\t}\r\n\t\tconst atkT0 = profile ? performance.now() : 0;\r\n\t\twhile (\r\n\t\t\tplayerBoard.length > 0 &&\r\n\t\t\topponentBoard.length > 0 &&\r\n\t\t\tplayerEntity.hpLeft > 0 &&\r\n\t\t\topponentEntity.hpLeft > 0\r\n\t\t) {\r\n\t\t\thandleSummonsWhenSpace(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\tclearStealthIfNeeded(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t// console.log('this.currentSpeedAttacker', this.currentAttacker);\r\n\t\t\t// If there are \"attack immediately\" minions, we keep the same player\r\n\t\t\t// We put it here so that it can kick in after the start of combat effects. However here we don't want\r\n\t\t\t// to change who attacks first, so we repeat that block again after all the attacks have been resolved\r\n\t\t\t// FIXME: This is not strictly correct - if there are multiple attack immediately\r\n\t\t\t// minions that spawn on both player sides it might get a bit more complex\r\n\t\t\t// but overall it works\r\n\t\t\t// Also, this doesn't work when there are several deathrattle competing\r\n\t\t\t// to know who triggers first. See the second test case of the scallywag.test.ts\r\n\t\t\t// that is not handled properly today (the attack should in some cases happen before\r\n\t\t\t// the other deathrattle procs)\r\n\t\t\tif (playerBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 0;\r\n\t\t\t} else if (opponentBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 1;\r\n\t\t\t} else {\r\n\t\t\t\tthis.currentSpeedAttacker = -1;\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tplayerBoard.filter((e) => e.attack > 0).length === 0 &&\r\n\t\t\t\topponentBoard.filter((e) => e.attack > 0).length === 0\r\n\t\t\t) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\t// console.log('this.currentSpeedAttacker 2', this.currentAttacker, this.currentSpeedAttacker);\r\n\t\t\tif (this.currentSpeedAttacker === 0 || (this.currentSpeedAttacker === -1 && this.currentAttacker === 0)) {\r\n\t\t\t\tsimulateAttack(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t} else {\r\n\t\t\t\tsimulateAttack(opponentBoard, opponentEntity, playerBoard, playerEntity, this.gameState);\r\n\t\t\t}\r\n\r\n\t\t\tresolvePendingEffects(playerBoard, playerEntity, opponentBoard, opponentEntity, this.gameState);\r\n\t\t\t// Update the attacker indices in case there were some deaths\r\n\t\t\tif (playerBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 0;\r\n\t\t\t} else if (opponentBoard.some((entity) => entity.attackImmediately)) {\r\n\t\t\t\tthis.currentSpeedAttacker = 1;\r\n\t\t\t} else {\r\n\t\t\t\tthis.currentSpeedAttacker = -1;\r\n\t\t\t\tthis.currentAttacker = (this.currentAttacker + 1) % 2;\r\n\t\t\t}\r\n\t\t\tcounter++;\r\n\t\t\tif (counter > 400 && !this.hasShowShortCircuitWarning) {\r\n\t\t\t\tconsole.warn(\r\n\t\t\t\t\t'short-circuiting simulation, too many iterations',\r\n\t\t\t\t\tcounter,\r\n\t\t\t\t\t'\\n',\r\n\t\t\t\t\tstringifySimple(playerBoard, this.gameState.allCards),\r\n\t\t\t\t\t'\\n',\r\n\t\t\t\t\tstringifySimple(opponentBoard, this.gameState.allCards),\r\n\t\t\t\t);\r\n\t\t\t\tthis.hasShowShortCircuitWarning = true;\r\n\t\t\t\tbreak;\r\n\t\t\t\t// return null;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (profile) {\r\n\t\t\tcombatProfileAdd('socMs', socMs);\r\n\t\t\tcombatProfileAdd('atkMs', performance.now() - atkT0);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate capDamage(damage: number): number {\r\n\t\tif (!this.gameState.applyDamageCap) {\r\n\t\t\treturn damage;\r\n\t\t}\r\n\t\treturn applyCombatDamageCap(\r\n\t\t\tdamage,\r\n\t\t\tthis.gameState.currentTurn,\r\n\t\t\tthis.gameState.numberOfPlayersAlive,\r\n\t\t\t!!this.gameState.isDuos,\r\n\t\t);\r\n\t}\r\n\r\n\tprivate buildBoardTotalDamage(playerBoard: readonly BoardEntity[], teammateBoard?: BoardEntity[]): number {\r\n\t\tconst damageFromPlayerBoard = playerBoard\r\n\t\t\t.map((entity) =>\r\n\t\t\t\tgetEffectiveTechLevel(this.gameState.allCards.getCard(entity.cardId), this.gameState.allCards),\r\n\t\t\t)\r\n\t\t\t.reduce((a, b) => a + b, 0);\r\n\t\tconst numberOfTeamateMinionsToSummnon = 7 - playerBoard.length;\r\n\t\tconst damageFromTeammateBoard =\r\n\t\t\tteammateBoard\r\n\t\t\t\t?.slice(0, numberOfTeamateMinionsToSummnon)\r\n\t\t\t\t.map((entity) =>\r\n\t\t\t\t\tgetEffectiveTechLevel(this.gameState.allCards.getCard(entity.cardId), this.gameState.allCards),\r\n\t\t\t\t)\r\n\t\t\t\t.reduce((a, b) => a + b, 0) ?? 0;\r\n\t\treturn damageFromPlayerBoard + damageFromTeammateBoard;\r\n\t}\r\n}\r\n"]}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Spectator = void 0;
|
|
3
|
+
exports.noopSpectator = exports.Spectator = void 0;
|
|
4
4
|
const game_action_1 = require("./game-action");
|
|
5
5
|
const MAX_SAMPLES = 1;
|
|
6
|
+
const EMPTY_ACTIONS = [];
|
|
7
|
+
const EMPTY_SAMPLES = [];
|
|
6
8
|
class Spectator {
|
|
7
9
|
constructor(enabled) {
|
|
8
10
|
this.enabled = enabled;
|
|
9
11
|
this.recording = false;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (enabled) {
|
|
13
|
+
this.actionsForCurrentBattle = [];
|
|
14
|
+
this.wonBattles = [];
|
|
15
|
+
this.tiedBattles = [];
|
|
16
|
+
this.lostBattles = [];
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.actionsForCurrentBattle = EMPTY_ACTIONS;
|
|
20
|
+
this.wonBattles = EMPTY_SAMPLES;
|
|
21
|
+
this.tiedBattles = EMPTY_SAMPLES;
|
|
22
|
+
this.lostBattles = EMPTY_SAMPLES;
|
|
23
|
+
}
|
|
14
24
|
}
|
|
15
25
|
startRecording() {
|
|
16
26
|
if (this.enabled) {
|
|
@@ -19,7 +29,9 @@ class Spectator {
|
|
|
19
29
|
}
|
|
20
30
|
stopRecording() {
|
|
21
31
|
this.recording = false;
|
|
22
|
-
this.
|
|
32
|
+
if (this.enabled) {
|
|
33
|
+
this.actionsForCurrentBattle = [];
|
|
34
|
+
}
|
|
23
35
|
}
|
|
24
36
|
hasSampleFor(result) {
|
|
25
37
|
switch (result) {
|
|
@@ -61,6 +73,9 @@ class Spectator {
|
|
|
61
73
|
return result;
|
|
62
74
|
}
|
|
63
75
|
commitBattleResult(result) {
|
|
76
|
+
if (!this.enabled) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
64
79
|
if (!this.recording) {
|
|
65
80
|
this.actionsForCurrentBattle = [];
|
|
66
81
|
return;
|
|
@@ -409,4 +424,5 @@ class Spectator {
|
|
|
409
424
|
}
|
|
410
425
|
}
|
|
411
426
|
exports.Spectator = Spectator;
|
|
427
|
+
exports.noopSpectator = new Spectator(false);
|
|
412
428
|
//# sourceMappingURL=spectator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spectator.js","sourceRoot":"","sources":["../../../src/simulation/spect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E,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;SACP,CAAA,CAClB,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,QAAiC;QACzD,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAA,EAAE;YACtB,OAAO,SAAS,CAAC;SACjB;QACD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAC1B,CAAC,CAAC,EAAE,EAAE,CACL,CAAC;YACA,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,IAAI,EAAE,CAAC,CAAC,IAAI;SACK,CAAA,CACnB,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAngBD,8BAmgBC","sourcesContent":["import { BgsGameState } from '../../bgs-battle-info';\r\nimport { BgsPlayerEntity, BoardTrinket } from '../../bgs-player-entity';\r\nimport { BoardEnchantment, BoardEntity } from '../../board-entity';\r\nimport { BoardSecret } from '../../board-secret';\r\nimport { GameAction, buildGameAction } from './game-action';\r\nimport { GameSample } from './game-sample';\r\n\r\nconst MAX_SAMPLES = 1;\r\n\r\nexport class Spectator {\r\n\tprivate actionsForCurrentBattle: GameAction[];\r\n\tprivate wonBattles: GameSample[];\r\n\tprivate tiedBattles: GameSample[];\r\n\tprivate lostBattles: GameSample[];\r\n\t// Recording every action is a significant part of the total simulation cost, so the\r\n\t// main simulation loop runs with recording off. Outcome samples are captured post-hoc:\r\n\t// once the outcome distribution is known, a few battles are re-run with recording\r\n\t// explicitly turned on until each outcome bucket that occurred has a sample.\r\n\tprivate recording = false;\r\n\r\n\tconstructor(private readonly enabled: boolean) {\r\n\t\tthis.actionsForCurrentBattle = [];\r\n\t\tthis.wonBattles = [];\r\n\t\tthis.tiedBattles = [];\r\n\t\tthis.lostBattles = [];\r\n\t}\r\n\r\n\tpublic startRecording(): void {\r\n\t\tif (this.enabled) {\r\n\t\t\tthis.recording = true;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic stopRecording(): void {\r\n\t\tthis.recording = false;\r\n\t\tthis.actionsForCurrentBattle = [];\r\n\t}\r\n\r\n\tpublic hasSampleFor(result: 'won' | 'lost' | 'tied'): boolean {\r\n\t\tswitch (result) {\r\n\t\t\tcase 'won':\r\n\t\t\t\treturn this.wonBattles.length >= MAX_SAMPLES;\r\n\t\t\tcase 'lost':\r\n\t\t\t\treturn this.lostBattles.length >= MAX_SAMPLES;\r\n\t\t\tcase 'tied':\r\n\t\t\t\treturn this.tiedBattles.length >= MAX_SAMPLES;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic prune(): void {\r\n\t\tthis.wonBattles = this.wonBattles.slice(0, MAX_SAMPLES);\r\n\t\tthis.lostBattles = this.lostBattles.slice(0, MAX_SAMPLES);\r\n\t\tthis.tiedBattles = this.tiedBattles.slice(0, MAX_SAMPLES);\r\n\t}\r\n\r\n\tpublic buildOutcomeSamples(gameState: BgsGameState): {\r\n\t\twon: readonly GameSample[];\r\n\t\tlost: readonly GameSample[];\r\n\t\ttied: readonly GameSample[];\r\n\t} {\r\n\t\tif (!this.enabled) {\r\n\t\t\treturn {\r\n\t\t\t\twon: [],\r\n\t\t\t\tlost: [],\r\n\t\t\t\ttied: [],\r\n\t\t\t};\r\n\t\t}\r\n\t\treturn {\r\n\t\t\twon: this.wonBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t\tlost: this.lostBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t\ttied: this.tiedBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t};\r\n\t}\r\n\r\n\tprivate cleanUpActions(battle: GameSample, gameState: BgsGameState): GameSample {\r\n\t\tconst collapsed = this.collapseActions(battle.actions);\r\n\t\tconst result: GameSample = {\r\n\t\t\t...battle,\r\n\t\t\tactions: collapsed,\r\n\t\t\tanomalies: gameState.anomalies,\r\n\t\t};\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic commitBattleResult(result: 'won' | 'lost' | 'tied'): void {\r\n\t\tif (!this.recording) {\r\n\t\t\tthis.actionsForCurrentBattle = [];\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst actionsForBattle = this.actionsForCurrentBattle;\r\n\t\tthis.actionsForCurrentBattle = [];\r\n\r\n\t\tconst battle: GameSample = {\r\n\t\t\tactions: actionsForBattle,\r\n\t\t\tanomalies: [],\r\n\t\t};\r\n\t\t// Only keep the sample if this bucket still needs one (prune() would discard the\r\n\t\t// extras anyway, and holding on to them wastes memory)\r\n\t\tswitch (result) {\r\n\t\t\tcase 'won':\r\n\t\t\t\tif (this.wonBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.wonBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase 'lost':\r\n\t\t\t\tif (this.lostBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.lostBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase 'tied':\r\n\t\t\t\tif (this.tiedBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.tiedBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic registerAttack(\r\n\t\tattackingEntity: BoardEntity,\r\n\t\tdefendingEntity: BoardEntity,\r\n\t\tattackingBoard: readonly BoardEntity[],\r\n\t\tdefendingBoard: readonly BoardEntity[],\r\n\t\tattackingBoardHero: BgsPlayerEntity,\r\n\t\tdefendingBoardHero: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.debug(\r\n\t\t// \t'\\n register attack',\r\n\t\t// \tstringifySimple(attackingBoard),\r\n\t\t// \t'\\n',\r\n\t\t// \tstringifySimple(defendingBoard),\r\n\t\t// \t'\\n',\r\n\t\t// \tattackingBoard.find((e) => e.entityId === 2441),\r\n\t\t// \t'\\n',\r\n\t\t// \tattackingBoard.find((e) => e.entityId === 2442),\r\n\t\t// );\r\n\t\tconst isAttackerFriendly = attackingBoard.every((entity) => entity.friendly);\r\n\t\tconst playerHero = isAttackerFriendly ? attackingBoardHero : defendingBoardHero;\r\n\t\tconst opponentHero = isAttackerFriendly ? defendingBoardHero : attackingBoardHero;\r\n\t\tconst friendlyBoard = isAttackerFriendly ? attackingBoard : defendingBoard;\r\n\t\tconst opponentBoard = isAttackerFriendly ? defendingBoard : attackingBoard;\r\n\t\tconst action: GameAction = buildGameAction(playerHero, opponentHero, {\r\n\t\t\ttype: 'attack',\r\n\t\t\tsourceEntityId: attackingEntity.entityId,\r\n\t\t\ttargetEntityId: defendingEntity.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\tplayerHand: this.sanitize(playerHero.hand),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\topponentHand: this.sanitize(opponentHero.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerStartOfCombat(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tfriendlyHero: BgsPlayerEntity,\r\n\t\topponentHero: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'start-of-combat',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPlayerAttack(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tdamage: number,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'player-attack',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tdamage: damage,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerOpponentAttack(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tdamage: number,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'opponent-attack',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tdamage: damage,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerDamageDealt(\r\n\t\tdamagingEntity: BoardEntity,\r\n\t\tdamagedEntity: BoardEntity,\r\n\t\tdamageTaken: number,\r\n\t\tdamagedEntityBoard: BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!damagingEntity.entityId) {\r\n\t\t\t// console.error('missing damaging entity id', damagingEntity.cardId);\r\n\t\t}\r\n\t\tconst friendlyBoard = damagedEntityBoard.every((entity) => entity.friendly) ? damagedEntityBoard : null;\r\n\t\tconst opponentBoard = damagedEntityBoard.every((entity) => !entity.friendly) ? damagedEntityBoard : null;\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'damage',\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tsourceEntityId: damagingEntity.entityId,\r\n\t\t\t\t\ttargetEntityId: damagedEntity.entityId,\r\n\t\t\t\t\tdamage: damageTaken,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPowerTarget(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardSecret | BoardTrinket | BoardEnchantment,\r\n\t\ttargetEntity: BoardEntity | BgsPlayerEntity,\r\n\t\ttargetBoard: BoardEntity[],\r\n\t\thero1: BgsPlayerEntity,\r\n\t\thero2: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!targetEntity) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.log('registerPowerTarget', stringifySimpleCard(sourceEntity), stringifySimpleCard(targetEntity), new Error().stack);\r\n\t\tconst friendlyBoard = targetBoard?.every((entity) => entity.friendly) ? targetBoard : null;\r\n\t\tconst opponentBoard = targetBoard?.every((entity) => !entity.friendly) ? targetBoard : null;\r\n\t\tconst friendlyHero = hero1?.friendly ? hero1 : hero2?.friendly ? hero2 : null;\r\n\t\tconst opponentHero = hero1?.friendly ? hero2 : hero2?.friendly ? hero1 : null;\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'power-target',\r\n\t\t\tsourceEntityId:\r\n\t\t\t\t(sourceEntity as BoardEnchantment)?.originEntityId ?? (sourceEntity as BoardEntity).entityId,\r\n\t\t\ttargetEntityId: targetEntity.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero?.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero?.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPowerTargets(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardSecret | BoardTrinket,\r\n\t\ttargetEntities: (BoardEntity | BgsPlayerEntity)[],\r\n\t\ttargetBoard: BoardEntity[],\r\n\t\thero1: BgsPlayerEntity,\r\n\t\thero2: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!targetEntities?.length) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.log('registerPowerTarget', stringifySimpleCard(sourceEntity), stringifySimpleCard(targetEntity), new Error().stack);\r\n\t\tconst friendlyBoard = targetBoard?.every((entity) => entity.friendly) ? targetBoard : null;\r\n\t\tconst opponentBoard = targetBoard?.every((entity) => !entity.friendly) ? targetBoard : null;\r\n\t\tconst friendlyHero = hero1?.friendly ? hero1 : hero2?.friendly ? hero2 : null;\r\n\t\tconst opponentHero = hero1?.friendly ? hero2 : hero2?.friendly ? hero1 : null;\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'power-target',\r\n\t\t\tsourceEntityId: sourceEntity.entityId,\r\n\t\t\ttargetEntityIds: targetEntities.map((entity) => entity.entityId),\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero?.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero?.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerMinionsSpawn(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardTrinket,\r\n\t\tboardOnWhichToSpawn: BoardEntity[],\r\n\t\tspawnedEntities: readonly BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!spawnedEntities || spawnedEntities.length === 0) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (!sourceEntity?.entityId) {\r\n\t\t\t// console.error('missing spawn source entity id', sourceEntity);\r\n\t\t}\r\n\t\tconst friendlyBoard = boardOnWhichToSpawn.every((entity) => entity.friendly) ? boardOnWhichToSpawn : null;\r\n\t\tconst opponentBoard = boardOnWhichToSpawn.every((entity) => !entity.friendly) ? boardOnWhichToSpawn : null;\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'spawn',\r\n\t\t\tspawns: this.sanitize(spawnedEntities),\r\n\t\t\tsourceEntityId: sourceEntity?.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerDeadEntities(\r\n\t\tdeadMinionIndexes1: number[],\r\n\t\tdeadEntities1: BoardEntity[],\r\n\t\tboard1: BoardEntity[],\r\n\t\tdeadMinionIndexes2: number[],\r\n\t\tdeadEntities2: BoardEntity[],\r\n\t\tboard2: BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst deaths = [...(deadEntities1 || []), ...(deadEntities2 || [])];\r\n\t\tif (!deaths || deaths.length === 0) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'minion-death',\r\n\t\t\tdeaths: this.sanitize(deaths),\r\n\t\t\tdeadMinionsPositionsOnBoard: [\r\n\t\t\t\t...(deadMinionIndexes1 || []).map((i) => board1.length - i),\r\n\t\t\t\t...(deadMinionIndexes2 || []).map((i) => board2.length - i),\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tprivate addAction(action: GameAction) {\r\n\t\tthis.actionsForCurrentBattle.push(action);\r\n\t}\r\n\r\n\tprivate collapseActions(actions: readonly GameAction[]): readonly GameAction[] {\r\n\t\tif (!this.enabled) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\tif (!actions || actions.length === 0) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\tconst result: GameAction[] = [];\r\n\t\tfor (let i = 0; i < actions.length; i++) {\r\n\t\t\tconst action: GameAction = {\r\n\t\t\t\t...actions[i],\r\n\t\t\t\tplayerBoard: this.sanitize(actions[i].playerBoard),\r\n\t\t\t\topponentBoard: this.sanitize(actions[i].opponentBoard),\r\n\t\t\t\tplayerHand: this.sanitize(actions[i].playerHand),\r\n\t\t\t\topponentHand: this.sanitize(actions[i].opponentHand),\r\n\t\t\t\t// spawns: this.sanitize(actions[i].spawns),\r\n\t\t\t\tdeaths: this.sanitize(actions[i].deaths),\r\n\t\t\t\tplayerTrinkets: this.sanitizeTrinkets(actions[i].playerTrinkets),\r\n\t\t\t\topponentTrinkets: this.sanitizeTrinkets(actions[i].opponentTrinkets),\r\n\t\t\t};\r\n\t\t\t// action.playerBoard && console.debug('\\naction playerboard', stringifySimple(action.playerBoard));\r\n\t\t\tconst lastAction = result.length > 0 ? result[result.length - 1] : null;\r\n\r\n\t\t\tif (lastAction) {\r\n\t\t\t\taction.playerBoard = action.playerBoard ?? lastAction.playerBoard;\r\n\t\t\t\taction.opponentBoard = action.opponentBoard ?? lastAction.opponentBoard;\r\n\t\t\t\taction.playerHand = action.playerHand ?? lastAction.playerHand;\r\n\t\t\t\taction.opponentHand = action.opponentHand ?? lastAction.opponentHand;\r\n\t\t\t\taction.playerSecrets = action.playerSecrets ?? lastAction.playerSecrets;\r\n\t\t\t\taction.opponentSecrets = action.opponentSecrets ?? lastAction.opponentSecrets;\r\n\t\t\t\taction.playerRewardCardId = action.playerRewardCardId ?? lastAction.playerRewardCardId;\r\n\t\t\t\taction.playerRewardEntityId = action.playerRewardEntityId ?? lastAction.playerRewardEntityId;\r\n\t\t\t\taction.playerRewardData = action.playerRewardData ?? lastAction.playerRewardData;\r\n\t\t\t\taction.opponentRewardCardId = action.opponentRewardCardId ?? lastAction.opponentRewardCardId;\r\n\t\t\t\taction.opponentRewardEntityId = action.opponentRewardEntityId ?? lastAction.opponentRewardEntityId;\r\n\t\t\t\taction.opponentRewardData = action.opponentRewardData ?? lastAction.opponentRewardData;\r\n\t\t\t\taction.playerCardId = action.playerCardId ?? lastAction.playerCardId;\r\n\t\t\t\taction.playerEntityId = action.playerEntityId ?? lastAction.playerEntityId;\r\n\t\t\t\taction.playerHeroPowerCardId = action.playerHeroPowerCardId ?? lastAction.playerHeroPowerCardId;\r\n\t\t\t\taction.playerHeroPowerEntityId = action.playerHeroPowerEntityId ?? lastAction.playerHeroPowerEntityId;\r\n\t\t\t\taction.playerHeroPowerUsed = action.playerHeroPowerUsed ?? lastAction.playerHeroPowerUsed;\r\n\t\t\t\taction.opponentCardId = action.opponentCardId ?? lastAction.opponentCardId;\r\n\t\t\t\taction.opponentEntityId = action.opponentEntityId ?? lastAction.opponentEntityId;\r\n\t\t\t\taction.opponentHeroPowerCardId = action.opponentHeroPowerCardId ?? lastAction.opponentHeroPowerCardId;\r\n\t\t\t\taction.opponentHeroPowerEntityId =\r\n\t\t\t\t\taction.opponentHeroPowerEntityId ?? lastAction.opponentHeroPowerEntityId;\r\n\t\t\t\taction.opponentHeroPowerUsed = action.opponentHeroPowerUsed ?? lastAction.opponentHeroPowerUsed;\r\n\t\t\t\taction.playerTrinkets = action.playerTrinkets ?? lastAction.playerTrinkets;\r\n\t\t\t\taction.opponentTrinkets = action.opponentTrinkets ?? lastAction.opponentTrinkets;\r\n\t\t\t}\r\n\r\n\t\t\tif (lastAction && action.type === 'damage' && lastAction.type === 'attack') {\r\n\t\t\t\tlastAction.damages = lastAction.damages || [];\r\n\t\t\t\tlastAction.damages.push({\r\n\t\t\t\t\tdamage: action.damages[0].damage,\r\n\t\t\t\t\tsourceEntityId: action.damages[0].sourceEntityId,\r\n\t\t\t\t\ttargetEntityId: action.damages[0].targetEntityId,\r\n\t\t\t\t});\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else if (lastAction && action.type === 'damage' && lastAction.type === 'damage') {\r\n\t\t\t\tlastAction.damages = lastAction.damages || [];\r\n\t\t\t\tlastAction.damages.push({\r\n\t\t\t\t\tdamage: action.damages[0].damage,\r\n\t\t\t\t\tsourceEntityId: action.damages[0].sourceEntityId,\r\n\t\t\t\t\ttargetEntityId: action.damages[0].targetEntityId,\r\n\t\t\t\t});\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else if (\r\n\t\t\t\tlastAction &&\r\n\t\t\t\taction.type === 'power-target' &&\r\n\t\t\t\tlastAction.type === 'power-target' &&\r\n\t\t\t\taction.sourceEntityId === lastAction.sourceEntityId\r\n\t\t\t) {\r\n\t\t\t\tlastAction.targetEntityIds =\r\n\t\t\t\t\tlastAction.targetEntityIds ?? (lastAction.targetEntityId ? [lastAction.targetEntityId] : []);\r\n\t\t\t\taction.targetEntityIds =\r\n\t\t\t\t\taction.targetEntityIds ?? (action.targetEntityId ? [action.targetEntityId] : []);\r\n\t\t\t\tlastAction.targetEntityIds.push(...action.targetEntityIds);\r\n\t\t\t\t// So that when multiple Leapfroggers enchantments target the same minion,\r\n\t\t\t\t// we can count them in the replay viewer's text\r\n\t\t\t\t// lastAction.targetEntityIds = [...new Set(lastAction.targetEntityIds)];\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else {\r\n\t\t\t\tresult.push(action);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// Calling sanitize every time before we add an action to the list is mandatory, since\r\n\t// the entities and boards are mutable\r\n\tprivate sanitize(board: readonly BoardEntity[]): readonly BoardEntity[] {\r\n\t\tif (!board) {\r\n\t\t\treturn undefined;\r\n\t\t}\r\n\t\treturn board.map(\r\n\t\t\t(entity) =>\r\n\t\t\t\t({\r\n\t\t\t\t\tentityId: entity.entityId,\r\n\t\t\t\t\tcardId: entity.cardId,\r\n\t\t\t\t\tfriendly: entity.friendly,\r\n\t\t\t\t\tattack: entity.attack,\r\n\t\t\t\t\thealth: entity.health,\r\n\t\t\t\t\tmaxHealth: entity.maxHealth,\r\n\t\t\t\t\ttaunt: entity.taunt,\r\n\t\t\t\t\tdivineShield: entity.divineShield,\r\n\t\t\t\t\tpoisonous: entity.poisonous,\r\n\t\t\t\t\tvenomous: entity.venomous,\r\n\t\t\t\t\treborn: entity.reborn,\r\n\t\t\t\t\twindfury: entity.windfury,\r\n\t\t\t\t\tstealth: entity.stealth,\r\n\t\t\t\t} as BoardEntity),\r\n\t\t);\r\n\t}\r\n\r\n\tprivate sanitizeTrinkets(trinkets: readonly BoardTrinket[]): readonly BoardTrinket[] {\r\n\t\tif (!trinkets?.length) {\r\n\t\t\treturn undefined;\r\n\t\t}\r\n\t\tconst result = trinkets.map(\r\n\t\t\t(t) =>\r\n\t\t\t\t({\r\n\t\t\t\t\tcardId: t.cardId,\r\n\t\t\t\t\tentityId: t.entityId,\r\n\t\t\t\t\tscriptDataNum1: t.scriptDataNum1,\r\n\t\t\t\t\tscriptDataNum6: t.scriptDataNum6,\r\n\t\t\t\t\ttags: t.tags,\r\n\t\t\t\t} as BoardTrinket),\r\n\t\t);\r\n\t\treturn result;\r\n\t}\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"spectator.js","sourceRoot":"","sources":["../../../src/simulation/spectator/spectator.ts"],"names":[],"mappings":";;;AAIA,+CAA4D;AAG5D,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,aAAa,GAAiB,EAAE,CAAC;AACvC,MAAM,aAAa,GAAiB,EAAE,CAAC;AA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info';\r\nimport { BgsPlayerEntity, BoardTrinket } from '../../bgs-player-entity';\r\nimport { BoardEnchantment, BoardEntity } from '../../board-entity';\r\nimport { BoardSecret } from '../../board-secret';\r\nimport { GameAction, buildGameAction } from './game-action';\r\nimport { GameSample } from './game-sample';\r\n\r\nconst MAX_SAMPLES = 1;\r\nconst EMPTY_ACTIONS: GameAction[] = [];\r\nconst EMPTY_SAMPLES: GameSample[] = [];\r\n\r\nexport class Spectator {\r\n\tprivate actionsForCurrentBattle: GameAction[];\r\n\tprivate wonBattles: GameSample[];\r\n\tprivate tiedBattles: GameSample[];\r\n\tprivate lostBattles: GameSample[];\r\n\t// Recording every action is a significant part of the total simulation cost, so the\r\n\t// main simulation loop runs with recording off. Outcome samples are captured post-hoc:\r\n\t// once the outcome distribution is known, a few battles are re-run with recording\r\n\t// explicitly turned on until each outcome bucket that occurred has a sample.\r\n\tprivate recording = false;\r\n\r\n\tconstructor(private readonly enabled: boolean) {\r\n\t\tif (enabled) {\r\n\t\t\tthis.actionsForCurrentBattle = [];\r\n\t\t\tthis.wonBattles = [];\r\n\t\t\tthis.tiedBattles = [];\r\n\t\t\tthis.lostBattles = [];\r\n\t\t} else {\r\n\t\t\tthis.actionsForCurrentBattle = EMPTY_ACTIONS;\r\n\t\t\tthis.wonBattles = EMPTY_SAMPLES;\r\n\t\t\tthis.tiedBattles = EMPTY_SAMPLES;\r\n\t\t\tthis.lostBattles = EMPTY_SAMPLES;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic startRecording(): void {\r\n\t\tif (this.enabled) {\r\n\t\t\tthis.recording = true;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic stopRecording(): void {\r\n\t\tthis.recording = false;\r\n\t\tif (this.enabled) {\r\n\t\t\tthis.actionsForCurrentBattle = [];\r\n\t\t}\r\n\t}\r\n\r\n\tpublic hasSampleFor(result: 'won' | 'lost' | 'tied'): boolean {\r\n\t\tswitch (result) {\r\n\t\t\tcase 'won':\r\n\t\t\t\treturn this.wonBattles.length >= MAX_SAMPLES;\r\n\t\t\tcase 'lost':\r\n\t\t\t\treturn this.lostBattles.length >= MAX_SAMPLES;\r\n\t\t\tcase 'tied':\r\n\t\t\t\treturn this.tiedBattles.length >= MAX_SAMPLES;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic prune(): void {\r\n\t\tthis.wonBattles = this.wonBattles.slice(0, MAX_SAMPLES);\r\n\t\tthis.lostBattles = this.lostBattles.slice(0, MAX_SAMPLES);\r\n\t\tthis.tiedBattles = this.tiedBattles.slice(0, MAX_SAMPLES);\r\n\t}\r\n\r\n\tpublic buildOutcomeSamples(gameState: BgsGameState): {\r\n\t\twon: readonly GameSample[];\r\n\t\tlost: readonly GameSample[];\r\n\t\ttied: readonly GameSample[];\r\n\t} {\r\n\t\tif (!this.enabled) {\r\n\t\t\treturn {\r\n\t\t\t\twon: [],\r\n\t\t\t\tlost: [],\r\n\t\t\t\ttied: [],\r\n\t\t\t};\r\n\t\t}\r\n\t\treturn {\r\n\t\t\twon: this.wonBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t\tlost: this.lostBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t\ttied: this.tiedBattles?.map((battle) => this.cleanUpActions(battle, gameState)),\r\n\t\t};\r\n\t}\r\n\r\n\tprivate cleanUpActions(battle: GameSample, gameState: BgsGameState): GameSample {\r\n\t\tconst collapsed = this.collapseActions(battle.actions);\r\n\t\tconst result: GameSample = {\r\n\t\t\t...battle,\r\n\t\t\tactions: collapsed,\r\n\t\t\tanomalies: gameState.anomalies,\r\n\t\t};\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic commitBattleResult(result: 'won' | 'lost' | 'tied'): void {\r\n\t\tif (!this.enabled) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!this.recording) {\r\n\t\t\tthis.actionsForCurrentBattle = [];\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst actionsForBattle = this.actionsForCurrentBattle;\r\n\t\tthis.actionsForCurrentBattle = [];\r\n\r\n\t\tconst battle: GameSample = {\r\n\t\t\tactions: actionsForBattle,\r\n\t\t\tanomalies: [],\r\n\t\t};\r\n\t\t// Only keep the sample if this bucket still needs one (prune() would discard the\r\n\t\t// extras anyway, and holding on to them wastes memory)\r\n\t\tswitch (result) {\r\n\t\t\tcase 'won':\r\n\t\t\t\tif (this.wonBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.wonBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase 'lost':\r\n\t\t\t\tif (this.lostBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.lostBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase 'tied':\r\n\t\t\t\tif (this.tiedBattles.length < MAX_SAMPLES) {\r\n\t\t\t\t\tthis.tiedBattles.push(battle);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic registerAttack(\r\n\t\tattackingEntity: BoardEntity,\r\n\t\tdefendingEntity: BoardEntity,\r\n\t\tattackingBoard: readonly BoardEntity[],\r\n\t\tdefendingBoard: readonly BoardEntity[],\r\n\t\tattackingBoardHero: BgsPlayerEntity,\r\n\t\tdefendingBoardHero: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.debug(\r\n\t\t// \t'\\n register attack',\r\n\t\t// \tstringifySimple(attackingBoard),\r\n\t\t// \t'\\n',\r\n\t\t// \tstringifySimple(defendingBoard),\r\n\t\t// \t'\\n',\r\n\t\t// \tattackingBoard.find((e) => e.entityId === 2441),\r\n\t\t// \t'\\n',\r\n\t\t// \tattackingBoard.find((e) => e.entityId === 2442),\r\n\t\t// );\r\n\t\tconst isAttackerFriendly = attackingBoard.every((entity) => entity.friendly);\r\n\t\tconst playerHero = isAttackerFriendly ? attackingBoardHero : defendingBoardHero;\r\n\t\tconst opponentHero = isAttackerFriendly ? defendingBoardHero : attackingBoardHero;\r\n\t\tconst friendlyBoard = isAttackerFriendly ? attackingBoard : defendingBoard;\r\n\t\tconst opponentBoard = isAttackerFriendly ? defendingBoard : attackingBoard;\r\n\t\tconst action: GameAction = buildGameAction(playerHero, opponentHero, {\r\n\t\t\ttype: 'attack',\r\n\t\t\tsourceEntityId: attackingEntity.entityId,\r\n\t\t\ttargetEntityId: defendingEntity.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\tplayerHand: this.sanitize(playerHero.hand),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\topponentHand: this.sanitize(opponentHero.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerStartOfCombat(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tfriendlyHero: BgsPlayerEntity,\r\n\t\topponentHero: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'start-of-combat',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPlayerAttack(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tdamage: number,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'player-attack',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tdamage: damage,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerOpponentAttack(\r\n\t\tfriendlyBoard: readonly BoardEntity[],\r\n\t\topponentBoard: readonly BoardEntity[],\r\n\t\tdamage: number,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'opponent-attack',\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tdamage: damage,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerDamageDealt(\r\n\t\tdamagingEntity: BoardEntity,\r\n\t\tdamagedEntity: BoardEntity,\r\n\t\tdamageTaken: number,\r\n\t\tdamagedEntityBoard: BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!damagingEntity.entityId) {\r\n\t\t\t// console.error('missing damaging entity id', damagingEntity.cardId);\r\n\t\t}\r\n\t\tconst friendlyBoard = damagedEntityBoard.every((entity) => entity.friendly) ? damagedEntityBoard : null;\r\n\t\tconst opponentBoard = damagedEntityBoard.every((entity) => !entity.friendly) ? damagedEntityBoard : null;\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'damage',\r\n\t\t\tdamages: [\r\n\t\t\t\t{\r\n\t\t\t\t\tsourceEntityId: damagingEntity.entityId,\r\n\t\t\t\t\ttargetEntityId: damagedEntity.entityId,\r\n\t\t\t\t\tdamage: damageTaken,\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPowerTarget(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardSecret | BoardTrinket | BoardEnchantment,\r\n\t\ttargetEntity: BoardEntity | BgsPlayerEntity,\r\n\t\ttargetBoard: BoardEntity[],\r\n\t\thero1: BgsPlayerEntity,\r\n\t\thero2: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!targetEntity) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.log('registerPowerTarget', stringifySimpleCard(sourceEntity), stringifySimpleCard(targetEntity), new Error().stack);\r\n\t\tconst friendlyBoard = targetBoard?.every((entity) => entity.friendly) ? targetBoard : null;\r\n\t\tconst opponentBoard = targetBoard?.every((entity) => !entity.friendly) ? targetBoard : null;\r\n\t\tconst friendlyHero = hero1?.friendly ? hero1 : hero2?.friendly ? hero2 : null;\r\n\t\tconst opponentHero = hero1?.friendly ? hero2 : hero2?.friendly ? hero1 : null;\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'power-target',\r\n\t\t\tsourceEntityId:\r\n\t\t\t\t(sourceEntity as BoardEnchantment)?.originEntityId ?? (sourceEntity as BoardEntity).entityId,\r\n\t\t\ttargetEntityId: targetEntity.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero?.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero?.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerPowerTargets(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardSecret | BoardTrinket,\r\n\t\ttargetEntities: (BoardEntity | BgsPlayerEntity)[],\r\n\t\ttargetBoard: BoardEntity[],\r\n\t\thero1: BgsPlayerEntity,\r\n\t\thero2: BgsPlayerEntity,\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!targetEntities?.length) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// console.log('registerPowerTarget', stringifySimpleCard(sourceEntity), stringifySimpleCard(targetEntity), new Error().stack);\r\n\t\tconst friendlyBoard = targetBoard?.every((entity) => entity.friendly) ? targetBoard : null;\r\n\t\tconst opponentBoard = targetBoard?.every((entity) => !entity.friendly) ? targetBoard : null;\r\n\t\tconst friendlyHero = hero1?.friendly ? hero1 : hero2?.friendly ? hero2 : null;\r\n\t\tconst opponentHero = hero1?.friendly ? hero2 : hero2?.friendly ? hero1 : null;\r\n\t\tconst action: GameAction = buildGameAction(friendlyHero, opponentHero, {\r\n\t\t\ttype: 'power-target',\r\n\t\t\tsourceEntityId: sourceEntity.entityId,\r\n\t\t\ttargetEntityIds: targetEntities.map((entity) => entity.entityId),\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: this.sanitize(friendlyHero?.hand),\r\n\t\t\topponentHand: this.sanitize(opponentHero?.hand),\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerMinionsSpawn(\r\n\t\tsourceEntity: BoardEntity | BgsPlayerEntity | BoardTrinket,\r\n\t\tboardOnWhichToSpawn: BoardEntity[],\r\n\t\tspawnedEntities: readonly BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif (!spawnedEntities || spawnedEntities.length === 0) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (!sourceEntity?.entityId) {\r\n\t\t\t// console.error('missing spawn source entity id', sourceEntity);\r\n\t\t}\r\n\t\tconst friendlyBoard = boardOnWhichToSpawn.every((entity) => entity.friendly) ? boardOnWhichToSpawn : null;\r\n\t\tconst opponentBoard = boardOnWhichToSpawn.every((entity) => !entity.friendly) ? boardOnWhichToSpawn : null;\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'spawn',\r\n\t\t\tspawns: this.sanitize(spawnedEntities),\r\n\t\t\tsourceEntityId: sourceEntity?.entityId,\r\n\t\t\tplayerBoard: this.sanitize(friendlyBoard),\r\n\t\t\topponentBoard: this.sanitize(opponentBoard),\r\n\t\t\tplayerHand: null,\r\n\t\t\topponentHand: null,\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tpublic registerDeadEntities(\r\n\t\tdeadMinionIndexes1: number[],\r\n\t\tdeadEntities1: BoardEntity[],\r\n\t\tboard1: BoardEntity[],\r\n\t\tdeadMinionIndexes2: number[],\r\n\t\tdeadEntities2: BoardEntity[],\r\n\t\tboard2: BoardEntity[],\r\n\t): void {\r\n\t\tif (!this.recording) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst deaths = [...(deadEntities1 || []), ...(deadEntities2 || [])];\r\n\t\tif (!deaths || deaths.length === 0) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconst action: GameAction = buildGameAction(null, null, {\r\n\t\t\ttype: 'minion-death',\r\n\t\t\tdeaths: this.sanitize(deaths),\r\n\t\t\tdeadMinionsPositionsOnBoard: [\r\n\t\t\t\t...(deadMinionIndexes1 || []).map((i) => board1.length - i),\r\n\t\t\t\t...(deadMinionIndexes2 || []).map((i) => board2.length - i),\r\n\t\t\t],\r\n\t\t});\r\n\t\tthis.addAction(action);\r\n\t}\r\n\r\n\tprivate addAction(action: GameAction) {\r\n\t\tthis.actionsForCurrentBattle.push(action);\r\n\t}\r\n\r\n\tprivate collapseActions(actions: readonly GameAction[]): readonly GameAction[] {\r\n\t\tif (!this.enabled) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\tif (!actions || actions.length === 0) {\r\n\t\t\treturn [];\r\n\t\t}\r\n\t\tconst result: GameAction[] = [];\r\n\t\tfor (let i = 0; i < actions.length; i++) {\r\n\t\t\tconst action: GameAction = {\r\n\t\t\t\t...actions[i],\r\n\t\t\t\tplayerBoard: this.sanitize(actions[i].playerBoard),\r\n\t\t\t\topponentBoard: this.sanitize(actions[i].opponentBoard),\r\n\t\t\t\tplayerHand: this.sanitize(actions[i].playerHand),\r\n\t\t\t\topponentHand: this.sanitize(actions[i].opponentHand),\r\n\t\t\t\t// spawns: this.sanitize(actions[i].spawns),\r\n\t\t\t\tdeaths: this.sanitize(actions[i].deaths),\r\n\t\t\t\tplayerTrinkets: this.sanitizeTrinkets(actions[i].playerTrinkets),\r\n\t\t\t\topponentTrinkets: this.sanitizeTrinkets(actions[i].opponentTrinkets),\r\n\t\t\t};\r\n\t\t\t// action.playerBoard && console.debug('\\naction playerboard', stringifySimple(action.playerBoard));\r\n\t\t\tconst lastAction = result.length > 0 ? result[result.length - 1] : null;\r\n\r\n\t\t\tif (lastAction) {\r\n\t\t\t\taction.playerBoard = action.playerBoard ?? lastAction.playerBoard;\r\n\t\t\t\taction.opponentBoard = action.opponentBoard ?? lastAction.opponentBoard;\r\n\t\t\t\taction.playerHand = action.playerHand ?? lastAction.playerHand;\r\n\t\t\t\taction.opponentHand = action.opponentHand ?? lastAction.opponentHand;\r\n\t\t\t\taction.playerSecrets = action.playerSecrets ?? lastAction.playerSecrets;\r\n\t\t\t\taction.opponentSecrets = action.opponentSecrets ?? lastAction.opponentSecrets;\r\n\t\t\t\taction.playerRewardCardId = action.playerRewardCardId ?? lastAction.playerRewardCardId;\r\n\t\t\t\taction.playerRewardEntityId = action.playerRewardEntityId ?? lastAction.playerRewardEntityId;\r\n\t\t\t\taction.playerRewardData = action.playerRewardData ?? lastAction.playerRewardData;\r\n\t\t\t\taction.opponentRewardCardId = action.opponentRewardCardId ?? lastAction.opponentRewardCardId;\r\n\t\t\t\taction.opponentRewardEntityId = action.opponentRewardEntityId ?? lastAction.opponentRewardEntityId;\r\n\t\t\t\taction.opponentRewardData = action.opponentRewardData ?? lastAction.opponentRewardData;\r\n\t\t\t\taction.playerCardId = action.playerCardId ?? lastAction.playerCardId;\r\n\t\t\t\taction.playerEntityId = action.playerEntityId ?? lastAction.playerEntityId;\r\n\t\t\t\taction.playerHeroPowerCardId = action.playerHeroPowerCardId ?? lastAction.playerHeroPowerCardId;\r\n\t\t\t\taction.playerHeroPowerEntityId = action.playerHeroPowerEntityId ?? lastAction.playerHeroPowerEntityId;\r\n\t\t\t\taction.playerHeroPowerUsed = action.playerHeroPowerUsed ?? lastAction.playerHeroPowerUsed;\r\n\t\t\t\taction.opponentCardId = action.opponentCardId ?? lastAction.opponentCardId;\r\n\t\t\t\taction.opponentEntityId = action.opponentEntityId ?? lastAction.opponentEntityId;\r\n\t\t\t\taction.opponentHeroPowerCardId = action.opponentHeroPowerCardId ?? lastAction.opponentHeroPowerCardId;\r\n\t\t\t\taction.opponentHeroPowerEntityId =\r\n\t\t\t\t\taction.opponentHeroPowerEntityId ?? lastAction.opponentHeroPowerEntityId;\r\n\t\t\t\taction.opponentHeroPowerUsed = action.opponentHeroPowerUsed ?? lastAction.opponentHeroPowerUsed;\r\n\t\t\t\taction.playerTrinkets = action.playerTrinkets ?? lastAction.playerTrinkets;\r\n\t\t\t\taction.opponentTrinkets = action.opponentTrinkets ?? lastAction.opponentTrinkets;\r\n\t\t\t}\r\n\r\n\t\t\tif (lastAction && action.type === 'damage' && lastAction.type === 'attack') {\r\n\t\t\t\tlastAction.damages = lastAction.damages || [];\r\n\t\t\t\tlastAction.damages.push({\r\n\t\t\t\t\tdamage: action.damages[0].damage,\r\n\t\t\t\t\tsourceEntityId: action.damages[0].sourceEntityId,\r\n\t\t\t\t\ttargetEntityId: action.damages[0].targetEntityId,\r\n\t\t\t\t});\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else if (lastAction && action.type === 'damage' && lastAction.type === 'damage') {\r\n\t\t\t\tlastAction.damages = lastAction.damages || [];\r\n\t\t\t\tlastAction.damages.push({\r\n\t\t\t\t\tdamage: action.damages[0].damage,\r\n\t\t\t\t\tsourceEntityId: action.damages[0].sourceEntityId,\r\n\t\t\t\t\ttargetEntityId: action.damages[0].targetEntityId,\r\n\t\t\t\t});\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else if (\r\n\t\t\t\tlastAction &&\r\n\t\t\t\taction.type === 'power-target' &&\r\n\t\t\t\tlastAction.type === 'power-target' &&\r\n\t\t\t\taction.sourceEntityId === lastAction.sourceEntityId\r\n\t\t\t) {\r\n\t\t\t\tlastAction.targetEntityIds =\r\n\t\t\t\t\tlastAction.targetEntityIds ?? (lastAction.targetEntityId ? [lastAction.targetEntityId] : []);\r\n\t\t\t\taction.targetEntityIds =\r\n\t\t\t\t\taction.targetEntityIds ?? (action.targetEntityId ? [action.targetEntityId] : []);\r\n\t\t\t\tlastAction.targetEntityIds.push(...action.targetEntityIds);\r\n\t\t\t\t// So that when multiple Leapfroggers enchantments target the same minion,\r\n\t\t\t\t// we can count them in the replay viewer's text\r\n\t\t\t\t// lastAction.targetEntityIds = [...new Set(lastAction.targetEntityIds)];\r\n\t\t\t\tlastAction.playerBoard = action.playerBoard;\r\n\t\t\t\tlastAction.opponentBoard = action.opponentBoard;\r\n\t\t\t\tlastAction.playerHand = action.playerHand;\r\n\t\t\t\tlastAction.opponentHand = action.opponentHand;\r\n\t\t\t\tlastAction.playerSecrets = action.playerSecrets;\r\n\t\t\t\tlastAction.opponentSecrets = action.opponentSecrets;\r\n\t\t\t\tlastAction.playerTrinkets = action.playerTrinkets;\r\n\t\t\t\tlastAction.opponentTrinkets = action.opponentTrinkets;\r\n\t\t\t} else {\r\n\t\t\t\tresult.push(action);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// Calling sanitize every time before we add an action to the list is mandatory, since\r\n\t// the entities and boards are mutable\r\n\tprivate sanitize(board: readonly BoardEntity[]): readonly BoardEntity[] {\r\n\t\tif (!board) {\r\n\t\t\treturn undefined;\r\n\t\t}\r\n\t\treturn board.map(\r\n\t\t\t(entity) =>\r\n\t\t\t\t({\r\n\t\t\t\t\tentityId: entity.entityId,\r\n\t\t\t\t\tcardId: entity.cardId,\r\n\t\t\t\t\tfriendly: entity.friendly,\r\n\t\t\t\t\tattack: entity.attack,\r\n\t\t\t\t\thealth: entity.health,\r\n\t\t\t\t\tmaxHealth: entity.maxHealth,\r\n\t\t\t\t\ttaunt: entity.taunt,\r\n\t\t\t\t\tdivineShield: entity.divineShield,\r\n\t\t\t\t\tpoisonous: entity.poisonous,\r\n\t\t\t\t\tvenomous: entity.venomous,\r\n\t\t\t\t\treborn: entity.reborn,\r\n\t\t\t\t\twindfury: entity.windfury,\r\n\t\t\t\t\tstealth: entity.stealth,\r\n\t\t\t\t} as BoardEntity),\r\n\t\t);\r\n\t}\r\n\r\n\tprivate sanitizeTrinkets(trinkets: readonly BoardTrinket[]): readonly BoardTrinket[] {\r\n\t\tif (!trinkets?.length) {\r\n\t\t\treturn undefined;\r\n\t\t}\r\n\t\tconst result = trinkets.map(\r\n\t\t\t(t) =>\r\n\t\t\t\t({\r\n\t\t\t\t\tcardId: t.cardId,\r\n\t\t\t\t\tentityId: t.entityId,\r\n\t\t\t\t\tscriptDataNum1: t.scriptDataNum1,\r\n\t\t\t\t\tscriptDataNum6: t.scriptDataNum6,\r\n\t\t\t\t\ttags: t.tags,\r\n\t\t\t\t} as BoardTrinket),\r\n\t\t);\r\n\t\treturn result;\r\n\t}\r\n}\r\n\r\n/** Shared no-op spectator for single-combat / tavern triggers (no sample arrays). */\r\nexport const noopSpectator = new Spectator(false);\r\n\r\n"]}
|