@firestone-hs/simulate-bgs-battle 1.1.313 → 1.1.315

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.
@@ -23,7 +23,7 @@ exports.default = async (event) => {
23
23
  return response;
24
24
  };
25
25
  const simulateBattle = (battleInput, cards, cardsData) => {
26
- var _a, _b, _c, _d, _e;
26
+ var _a, _b, _c, _d, _e, _f, _g;
27
27
  const start = Date.now();
28
28
  const maxAcceptableDuration = ((_a = battleInput.options) === null || _a === void 0 ? void 0 : _a.maxAcceptableDuration) || 8000;
29
29
  const numberOfSimulations = ((_b = battleInput.options) === null || _b === void 0 ? void 0 : _b.numberOfSimulations) || 5000;
@@ -46,7 +46,9 @@ const simulateBattle = (battleInput, cards, cardsData) => {
46
46
  const playerInfo = battleInput.playerBoard;
47
47
  const opponentInfo = battleInput.opponentBoard;
48
48
  const playerBoard = playerInfo.board.map((entity) => ({ ...(0, utils_1.addImpliedMechanics)(entity, cardsData), friendly: true }));
49
+ const playerHand = (_c = playerInfo.player.hand) === null || _c === void 0 ? void 0 : _c.map((entity) => ({ ...(0, utils_1.addImpliedMechanics)(entity, cardsData), friendly: true }));
49
50
  const opponentBoard = opponentInfo.board.map((entity) => ({ ...(0, utils_1.addImpliedMechanics)(entity, cardsData), friendly: false }));
51
+ const opponentHand = (_d = opponentInfo.player.hand) === null || _d === void 0 ? void 0 : _d.map((entity) => ({ ...(0, utils_1.addImpliedMechanics)(entity, cardsData), friendly: true }));
50
52
  (0, auras_1.setMissingAuras)(playerBoard, playerInfo.player, opponentInfo.player, cards);
51
53
  (0, auras_1.setMissingAuras)(opponentBoard, opponentInfo.player, playerInfo.player, cards);
52
54
  (0, auras_1.setImplicitDataHero)(playerInfo.player, cardsData, true);
@@ -54,17 +56,23 @@ const simulateBattle = (battleInput, cards, cardsData) => {
54
56
  const inputReady = {
55
57
  playerBoard: {
56
58
  board: playerBoard,
57
- player: playerInfo.player,
59
+ player: {
60
+ ...playerInfo.player,
61
+ hand: playerHand,
62
+ },
58
63
  },
59
64
  opponentBoard: {
60
65
  board: opponentBoard,
61
- player: opponentInfo.player,
66
+ player: {
67
+ ...opponentInfo.player,
68
+ hand: opponentHand,
69
+ },
62
70
  },
63
71
  gameState: battleInput.gameState,
64
72
  };
65
73
  const inputStr = JSON.stringify(inputReady);
66
74
  const spectator = new spectator_1.Spectator(battleInput.playerBoard.player.cardId, battleInput.playerBoard.player.heroPowerId, battleInput.opponentBoard.player.cardId, battleInput.opponentBoard.player.heroPowerId);
67
- !((_c = battleInput.options) === null || _c === void 0 ? void 0 : _c.skipInfoLogs) && console.time('simulation');
75
+ !((_e = battleInput.options) === null || _e === void 0 ? void 0 : _e.skipInfoLogs) && console.time('simulation');
68
76
  const outcomes = {};
69
77
  for (let i = 0; i < numberOfSimulations; i++) {
70
78
  const simulator = new simulator_1.Simulator(cards, cardsData);
@@ -87,7 +95,7 @@ const simulateBattle = (battleInput, cards, cardsData) => {
87
95
  else if (battleResult.result === 'lost') {
88
96
  simulationResult.lost++;
89
97
  simulationResult.damageLost += battleResult.damageDealt;
90
- outcomes[battleResult.damageDealt] = ((_d = outcomes[battleResult.damageDealt]) !== null && _d !== void 0 ? _d : 0) + 1;
98
+ outcomes[battleResult.damageDealt] = ((_f = outcomes[battleResult.damageDealt]) !== null && _f !== void 0 ? _f : 0) + 1;
91
99
  if (battleInput.playerBoard.player.hpLeft &&
92
100
  battleResult.damageDealt >= battleInput.playerBoard.player.hpLeft) {
93
101
  simulationResult.lostLethal++;
@@ -116,7 +124,7 @@ const simulateBattle = (battleInput, cards, cardsData) => {
116
124
  if (simulationResult.averageDamageLost > 0 && simulationResult.averageDamageLost < opponentInfo.player.tavernTier) {
117
125
  console.warn('average damage lost issue', simulationResult, opponentInfo);
118
126
  }
119
- !((_e = battleInput.options) === null || _e === void 0 ? void 0 : _e.skipInfoLogs) && console.timeEnd('simulation');
127
+ !((_g = battleInput.options) === null || _g === void 0 ? void 0 : _g.skipInfoLogs) && console.timeEnd('simulation');
120
128
  spectator.prune();
121
129
  simulationResult.outcomeSamples = spectator.buildOutcomeSamples();
122
130
  return simulationResult;
@@ -1 +1 @@
1
- {"version":3,"file":"simulate-bgs-battle.js","sourceRoot":"","sources":["../src/simulate-bgs-battle.ts"],"names":[],"mappings":";;;AACA,iEAAwE;AAGxE,mDAA+C;AAE/C,8CAA0E;AAC1E,sDAAmD;AACnD,gEAA6D;AAC7D,mCAA8C;AAE9C,MAAM,KAAK,GAAG,IAAI,gCAAe,EAAE,CAAC;AAKpC,kBAAe,KAAK,EAAE,KAAK,EAAgB,EAAE;;IAC5C,MAAM,WAAW,GAAkB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,SAAS,CAAC,YAAY,CACrB,MAAA,MAAA,WAAW,CAAC,SAAS,0CAAE,WAAW,mCAAI,MAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,EACtE,MAAA,MAAA,WAAW,CAAC,SAAS,0CAAE,SAAS,mCAAI,EAAE,CACtC,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAA,sBAAc,EAAC,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAG;QAChB,UAAU,EAAE,GAAG;QACf,eAAe,EAAE,KAAK;QACtB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;KACtC,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAEK,MAAM,cAAc,GAAG,CAC7B,WAA0B,EAC1B,KAAsB,EACtB,SAAoB,EACD,EAAE;;IACrB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEzB,MAAM,qBAAqB,GAAG,CAAA,MAAA,WAAW,CAAC,OAA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W,QAAA,cAAc,kBAwJzB;AAEF,MAAM,aAAa,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,UAAkB,EAAU,EAAE;IAChG,IAAI,YAAY,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,EAAE;QAC7C,OAAO,IAAI,CAAC;KACZ;IACD,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,UAAU,EAAE;QACxD,OAAO,IAAI,CAAC;KACZ;IACD,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAA0B,EAAE;IACnF,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7B,GAAG,MAAM;QACT,YAAY,EAAE,0BAA0B,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;KACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;CAoBhC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAClC,YAA2E,EAC3E,SAA4B,EACoC,EAAE;IAClE,OAAO,YAAY,CAAC,MAAM,CACzB,CAAC,OAAO,EAAE,EAAE,CACX,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAChD,yBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAC5D,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds } from '@firestone-hs/reference-data';\r\nimport { BgsBattleInfo } from './bgs-battle-info';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { SimulationResult } from './simulation-result';\r\nimport { setImplicitDataHero, setMissingAuras } from './simulation/auras';\r\nimport { Simulator } from './simulation/simulator';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\nimport { addImpliedMechanics } from './utils';\r\n\r\nconst cards = new AllCardsService();\r\n\r\n// This example demonstrates a NodeJS 8.10 async handler[1], however of course you could use\r\n// the more traditional callback-style handler.\r\n// [1]: https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/\r\nexport default async (event): Promise<any> => {\r\n\tconst battleInput: BgsBattleInfo = JSON.parse(event.body);\r\n\tawait cards.initializeCardsDb();\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(\r\n\t\tbattleInput.gameState?.validTribes ?? battleInput.options?.validTribes,\r\n\t\tbattleInput.gameState?.anomalies ?? [],\r\n\t);\r\n\tconst simulationResult = simulateBattle(battleInput, cards, cardsData);\r\n\r\n\tconst response = {\r\n\t\tstatusCode: 200,\r\n\t\tisBase64Encoded: false,\r\n\t\tbody: JSON.stringify(simulationResult),\r\n\t};\r\n\treturn response;\r\n};\r\n\r\nexport const simulateBattle = (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n): SimulationResult => {\r\n\tconst start = Date.now();\r\n\r\n\tconst maxAcceptableDuration = battleInput.options?.maxAcceptableDuration || 8000;\r\n\tconst numberOfSimulations = battleInput.options?.numberOfSimulations || 5000;\r\n\r\n\tconst simulationResult: SimulationResult = {\r\n\t\twonLethal: 0,\r\n\t\twon: 0,\r\n\t\ttied: 0,\r\n\t\tlost: 0,\r\n\t\tlostLethal: 0,\r\n\t\tdamageWon: 0,\r\n\t\tdamageLost: 0,\r\n\t\twonLethalPercent: undefined,\r\n\t\twonPercent: undefined,\r\n\t\ttiedPercent: undefined,\r\n\t\tlostPercent: undefined,\r\n\t\tlostLethalPercent: undefined,\r\n\t\taverageDamageWon: undefined,\r\n\t\taverageDamageLost: undefined,\r\n\t};\r\n\r\n\tconst playerInfo = battleInput.playerBoard;\r\n\tconst opponentInfo = battleInput.opponentBoard;\r\n\r\n\tconst playerBoard = playerInfo.board.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: true } as BoardEntity),\r\n\t);\r\n\tconst opponentBoard = opponentInfo.board.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: false } as BoardEntity),\r\n\t);\r\n\t// When using the simulator, the aura is not applied when receiving the board state. When\r\n\tsetMissingAuras(playerBoard, playerInfo.player, opponentInfo.player, cards);\r\n\tsetMissingAuras(opponentBoard, opponentInfo.player, playerInfo.player, cards);\r\n\t// Avenge, maxHealth, etc.\r\n\t// setImplicitData(playerBoard, cardsData);\r\n\t// setImplicitData(opponentBoard, cardsData);\r\n\t// Avenge, globalInfo\r\n\tsetImplicitDataHero(playerInfo.player, cardsData, true);\r\n\tsetImplicitDataHero(opponentInfo.player, cardsData, false);\r\n\r\n\t// We do this so that we can have mutated objects inside the simulation and still\r\n\t// be able to start from a fresh copy for each simulation\r\n\tconst inputReady: BgsBattleInfo = {\r\n\t\tplayerBoard: {\r\n\t\t\tboard: playerBoard,\r\n\t\t\tplayer: playerInfo.player,\r\n\t\t},\r\n\t\topponentBoard: {\r\n\t\t\tboard: opponentBoard,\r\n\t\t\tplayer: opponentInfo.player,\r\n\t\t},\r\n\t\tgameState: battleInput.gameState,\r\n\t} as BgsBattleInfo;\r\n\tconst inputStr = JSON.stringify(inputReady);\r\n\tconst spectator = new Spectator(\r\n\t\tbattleInput.playerBoard.player.cardId,\r\n\t\tbattleInput.playerBoard.player.heroPowerId,\r\n\t\tbattleInput.opponentBoard.player.cardId,\r\n\t\tbattleInput.opponentBoard.player.heroPowerId,\r\n\t);\r\n\t!battleInput.options?.skipInfoLogs && console.time('simulation');\r\n\tconst outcomes = {};\r\n\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\tconst simulator = new Simulator(cards, cardsData);\r\n\t\tconst input: BgsBattleInfo = JSON.parse(inputStr);\r\n\t\tconst battleResult = simulator.simulateSingleBattle(\r\n\t\t\tinput.playerBoard.board,\r\n\t\t\tinput.playerBoard.player,\r\n\t\t\tinput.opponentBoard.board,\r\n\t\t\tinput.opponentBoard.player,\r\n\t\t\tinput.gameState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tif (Date.now() - start > maxAcceptableDuration) {\r\n\t\t\t// Can happen in case of inifinite boards, or a bug. Don't hog the user's computer in that case\r\n\t\t\tconsole.warn('Stopping simulation after', i, 'iterations and ', Date.now() - start, 'ms', battleResult);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tif (!battleResult) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (battleResult.result === 'won') {\r\n\t\t\tsimulationResult.won++;\r\n\t\t\tsimulationResult.damageWon += battleResult.damageDealt;\r\n\t\t\tif (battleResult.damageDealt >= battleInput.opponentBoard.player.hpLeft) {\r\n\t\t\t\tsimulationResult.wonLethal++;\r\n\t\t\t}\r\n\t\t} else if (battleResult.result === 'lost') {\r\n\t\t\tsimulationResult.lost++;\r\n\t\t\tsimulationResult.damageLost += battleResult.damageDealt;\r\n\t\t\toutcomes[battleResult.damageDealt] = (outcomes[battleResult.damageDealt] ?? 0) + 1;\r\n\t\t\tif (\r\n\t\t\t\tbattleInput.playerBoard.player.hpLeft &&\r\n\t\t\t\tbattleResult.damageDealt >= battleInput.playerBoard.player.hpLeft\r\n\t\t\t) {\r\n\t\t\t\tsimulationResult.lostLethal++;\r\n\t\t\t}\r\n\t\t} else if (battleResult.result === 'tied') {\r\n\t\t\tsimulationResult.tied++;\r\n\t\t}\r\n\t\tspectator.commitBattleResult(battleResult.result);\r\n\t}\r\n\tconst totalMatches = simulationResult.won + simulationResult.tied + simulationResult.lost;\r\n\tsimulationResult.wonPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.won)) / totalMatches) / 10,\r\n\t\tsimulationResult.won,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.wonLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.wonLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lost)) / totalMatches) / 10,\r\n\t\tsimulationResult.lost,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.lostLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\t// simulationResult.tiedPercent = checkRounding(Math.round((10 * (100 * simulationResult.tied)) / totalMatches) / 10, simulationResult.tied, totalMatches);\r\n\tsimulationResult.tiedPercent = checkRounding(\r\n\t\t100 - simulationResult.lostPercent - simulationResult.wonPercent,\r\n\t\tsimulationResult.tied,\r\n\t\ttotalMatches,\r\n\t);\r\n\r\n\tsimulationResult.wonLethalPercent = Math.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10;\r\n\tsimulationResult.lostLethalPercent = Math.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10;\r\n\tsimulationResult.averageDamageWon = simulationResult.won ? simulationResult.damageWon / simulationResult.won : 0;\r\n\tsimulationResult.averageDamageLost = simulationResult.lost\r\n\t\t? simulationResult.damageLost / simulationResult.lost\r\n\t\t: 0;\r\n\tif (simulationResult.averageDamageWon > 0 && simulationResult.averageDamageWon < playerInfo.player.tavernTier) {\r\n\t\tconsole.warn('average damage won issue', simulationResult, playerInfo);\r\n\t}\r\n\tif (simulationResult.averageDamageLost > 0 && simulationResult.averageDamageLost < opponentInfo.player.tavernTier) {\r\n\t\tconsole.warn('average damage lost issue', simulationResult, opponentInfo);\r\n\t}\r\n\t!battleInput.options?.skipInfoLogs && console.timeEnd('simulation');\r\n\tspectator.prune();\r\n\tsimulationResult.outcomeSamples = spectator.buildOutcomeSamples();\r\n\treturn simulationResult;\r\n};\r\n\r\nconst checkRounding = (roundedValue: number, initialValue: number, totalValue: number): number => {\r\n\tif (roundedValue === 0 && initialValue !== 0) {\r\n\t\treturn 0.01;\r\n\t}\r\n\tif (roundedValue === 100 && initialValue !== totalValue) {\r\n\t\treturn 99.9;\r\n\t}\r\n\treturn roundedValue;\r\n};\r\n\r\nconst cleanEnchantments = (board: readonly BoardEntity[]): readonly BoardEntity[] => {\r\n\tconst entityIds = board.map((entity) => entity.entityId);\r\n\treturn board.map((entity) => ({\r\n\t\t...entity,\r\n\t\tenchantments: cleanEnchantmentsForEntity(entity.enchantments, entityIds),\r\n\t}));\r\n};\r\n\r\nexport const validEnchantments = [\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment_BG_BOT_312e,\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment_TB_BaconUps_032e,\r\n\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment_BG21_000e,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment_BG21_000_Ge,\r\n\tCardIds.Sneed_SneedsReplicator,\r\n\tCardIds.SneedsReplicator_ReplicateEnchantment,\r\n\tCardIds.EarthRecollectionEnchantment, // Spirit Raptor\r\n\tCardIds.FireRecollectionEnchantment,\r\n\tCardIds.LightningRecollectionEnchantment,\r\n\tCardIds.WaterRecollectionEnchantment,\r\n\tCardIds.EarthInvocation_ElementEarthEnchantment, // Summon a 1/1\r\n\t// CardIds.FireInvocation_ElementFireEnchantment, // Attack is doubled, probably no use to keep it\r\n\t// CardIds.WaterInvocation_ElementWaterEnchantment, // +3 health and taunt, same\r\n\tCardIds.LightningInvocation, // Deal 1 damage to 5 enemy minions\r\n\tCardIds.SurfNSurf_CrabRidingEnchantment_BG27_004e,\r\n\tCardIds.SurfNSurf_CrabRidingEnchantment_BG27_004_Ge,\r\n\tCardIds.RecurringNightmare_NightmareInsideEnchantment_BG26_055e,\r\n\tCardIds.RecurringNightmare_NightmareInsideEnchantment_BG26_055_Ge,\r\n];\r\n\r\nconst cleanEnchantmentsForEntity = (\r\n\tenchantments: { cardId: string; originEntityId?: number; timing: number }[],\r\n\tentityIds: readonly number[],\r\n): { cardId: string; originEntityId?: number; timing: number }[] => {\r\n\treturn enchantments.filter(\r\n\t\t(enchant) =>\r\n\t\t\tentityIds.indexOf(enchant.originEntityId) !== -1 ||\r\n\t\t\tvalidEnchantments.indexOf(enchant.cardId as CardIds) !== -1,\r\n\t);\r\n};\r\n"]}
1
+ {"version":3,"file":"simulate-bgs-battle.js","sourceRoot":"","sources":["../src/simulate-bgs-battle.ts"],"names":[],"mappings":";;;AACA,iEAAwE;AAGxE,mDAA+C;AAE/C,8CAA0E;AAC1E,sDAAmD;AACnD,gEAA6D;AAC7D,mCAA8C;AAE9C,MAAM,KAAK,GAAG,IAAI,gCAAe,EAAE,CAAC;AAKpC,kBAAe,KAAK,EAAE,KAAK,EAAgB,EAAE;;IAC5C,MAAM,WAAW,GAAkB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,SAAS,CAAC,YAAY,CACrB,MAAA,MAAA,WAAW,CAAC,SAAS,0CAAE,WAAW,mCAAI,MAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,EACtE,MAAA,MAAA,WAAW,CAAC,SAAS,0CAAE,SAAS,mCAAI,EAAE,CACtC,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAA,sBAAc,EAAC,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAG;QAChB,UAAU,EAAE,GAAG;QACf,eAAe,EAAE,KAAK;QACtB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;KACtC,C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,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7B,GAAG,MAAM;QACT,YAAY,EAAE,0BAA0B,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;KACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;CAoBhC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAClC,YAA2E,EAC3E,SAA4B,EACoC,EAAE;IAClE,OAAO,YAAY,CAAC,MAAM,CACzB,CAAC,OAAO,EAAE,EAAE,CACX,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAChD,yBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAC5D,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { AllCardsService, CardIds } from '@firestone-hs/reference-data';\r\nimport { BgsBattleInfo } from './bgs-battle-info';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { SimulationResult } from './simulation-result';\r\nimport { setImplicitDataHero, setMissingAuras } from './simulation/auras';\r\nimport { Simulator } from './simulation/simulator';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\nimport { addImpliedMechanics } from './utils';\r\n\r\nconst cards = new AllCardsService();\r\n\r\n// This example demonstrates a NodeJS 8.10 async handler[1], however of course you could use\r\n// the more traditional callback-style handler.\r\n// [1]: https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/\r\nexport default async (event): Promise<any> => {\r\n\tconst battleInput: BgsBattleInfo = JSON.parse(event.body);\r\n\tawait cards.initializeCardsDb();\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(\r\n\t\tbattleInput.gameState?.validTribes ?? battleInput.options?.validTribes,\r\n\t\tbattleInput.gameState?.anomalies ?? [],\r\n\t);\r\n\tconst simulationResult = simulateBattle(battleInput, cards, cardsData);\r\n\r\n\tconst response = {\r\n\t\tstatusCode: 200,\r\n\t\tisBase64Encoded: false,\r\n\t\tbody: JSON.stringify(simulationResult),\r\n\t};\r\n\treturn response;\r\n};\r\n\r\nexport const simulateBattle = (\r\n\tbattleInput: BgsBattleInfo,\r\n\tcards: AllCardsService,\r\n\tcardsData: CardsData,\r\n): SimulationResult => {\r\n\tconst start = Date.now();\r\n\r\n\tconst maxAcceptableDuration = battleInput.options?.maxAcceptableDuration || 8000;\r\n\tconst numberOfSimulations = battleInput.options?.numberOfSimulations || 5000;\r\n\r\n\tconst simulationResult: SimulationResult = {\r\n\t\twonLethal: 0,\r\n\t\twon: 0,\r\n\t\ttied: 0,\r\n\t\tlost: 0,\r\n\t\tlostLethal: 0,\r\n\t\tdamageWon: 0,\r\n\t\tdamageLost: 0,\r\n\t\twonLethalPercent: undefined,\r\n\t\twonPercent: undefined,\r\n\t\ttiedPercent: undefined,\r\n\t\tlostPercent: undefined,\r\n\t\tlostLethalPercent: undefined,\r\n\t\taverageDamageWon: undefined,\r\n\t\taverageDamageLost: undefined,\r\n\t};\r\n\r\n\tconst playerInfo = battleInput.playerBoard;\r\n\tconst opponentInfo = battleInput.opponentBoard;\r\n\r\n\tconst playerBoard = playerInfo.board.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: true } as BoardEntity),\r\n\t);\r\n\tconst playerHand = playerInfo.player.hand?.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: true } as BoardEntity),\r\n\t);\r\n\tconst opponentBoard = opponentInfo.board.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: false } as BoardEntity),\r\n\t);\r\n\tconst opponentHand = opponentInfo.player.hand?.map(\r\n\t\t(entity) => ({ ...addImpliedMechanics(entity, cardsData), friendly: true } as BoardEntity),\r\n\t);\r\n\t// When using the simulator, the aura is not applied when receiving the board state. When\r\n\tsetMissingAuras(playerBoard, playerInfo.player, opponentInfo.player, cards);\r\n\tsetMissingAuras(opponentBoard, opponentInfo.player, playerInfo.player, cards);\r\n\t// Avenge, maxHealth, etc.\r\n\t// setImplicitData(playerBoard, cardsData);\r\n\t// setImplicitData(opponentBoard, cardsData);\r\n\t// Avenge, globalInfo\r\n\tsetImplicitDataHero(playerInfo.player, cardsData, true);\r\n\tsetImplicitDataHero(opponentInfo.player, cardsData, false);\r\n\r\n\t// We do this so that we can have mutated objects inside the simulation and still\r\n\t// be able to start from a fresh copy for each simulation\r\n\tconst inputReady: BgsBattleInfo = {\r\n\t\tplayerBoard: {\r\n\t\t\tboard: playerBoard,\r\n\t\t\tplayer: {\r\n\t\t\t\t...playerInfo.player,\r\n\t\t\t\thand: playerHand,\r\n\t\t\t},\r\n\t\t},\r\n\t\topponentBoard: {\r\n\t\t\tboard: opponentBoard,\r\n\t\t\tplayer: {\r\n\t\t\t\t...opponentInfo.player,\r\n\t\t\t\thand: opponentHand,\r\n\t\t\t},\r\n\t\t},\r\n\t\tgameState: battleInput.gameState,\r\n\t} as BgsBattleInfo;\r\n\tconst inputStr = JSON.stringify(inputReady);\r\n\tconst spectator = new Spectator(\r\n\t\tbattleInput.playerBoard.player.cardId,\r\n\t\tbattleInput.playerBoard.player.heroPowerId,\r\n\t\tbattleInput.opponentBoard.player.cardId,\r\n\t\tbattleInput.opponentBoard.player.heroPowerId,\r\n\t);\r\n\t!battleInput.options?.skipInfoLogs && console.time('simulation');\r\n\tconst outcomes = {};\r\n\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\tconst simulator = new Simulator(cards, cardsData);\r\n\t\tconst input: BgsBattleInfo = JSON.parse(inputStr);\r\n\t\tconst battleResult = simulator.simulateSingleBattle(\r\n\t\t\tinput.playerBoard.board,\r\n\t\t\tinput.playerBoard.player,\r\n\t\t\tinput.opponentBoard.board,\r\n\t\t\tinput.opponentBoard.player,\r\n\t\t\tinput.gameState,\r\n\t\t\tspectator,\r\n\t\t);\r\n\t\tif (Date.now() - start > maxAcceptableDuration) {\r\n\t\t\t// Can happen in case of inifinite boards, or a bug. Don't hog the user's computer in that case\r\n\t\t\tconsole.warn('Stopping simulation after', i, 'iterations and ', Date.now() - start, 'ms', battleResult);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tif (!battleResult) {\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (battleResult.result === 'won') {\r\n\t\t\tsimulationResult.won++;\r\n\t\t\tsimulationResult.damageWon += battleResult.damageDealt;\r\n\t\t\tif (battleResult.damageDealt >= battleInput.opponentBoard.player.hpLeft) {\r\n\t\t\t\tsimulationResult.wonLethal++;\r\n\t\t\t}\r\n\t\t} else if (battleResult.result === 'lost') {\r\n\t\t\tsimulationResult.lost++;\r\n\t\t\tsimulationResult.damageLost += battleResult.damageDealt;\r\n\t\t\toutcomes[battleResult.damageDealt] = (outcomes[battleResult.damageDealt] ?? 0) + 1;\r\n\t\t\tif (\r\n\t\t\t\tbattleInput.playerBoard.player.hpLeft &&\r\n\t\t\t\tbattleResult.damageDealt >= battleInput.playerBoard.player.hpLeft\r\n\t\t\t) {\r\n\t\t\t\tsimulationResult.lostLethal++;\r\n\t\t\t}\r\n\t\t} else if (battleResult.result === 'tied') {\r\n\t\t\tsimulationResult.tied++;\r\n\t\t}\r\n\t\tspectator.commitBattleResult(battleResult.result);\r\n\t}\r\n\tconst totalMatches = simulationResult.won + simulationResult.tied + simulationResult.lost;\r\n\tsimulationResult.wonPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.won)) / totalMatches) / 10,\r\n\t\tsimulationResult.won,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.wonLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.wonLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lost)) / totalMatches) / 10,\r\n\t\tsimulationResult.lost,\r\n\t\ttotalMatches,\r\n\t);\r\n\tsimulationResult.lostLethalPercent = checkRounding(\r\n\t\tMath.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10,\r\n\t\tsimulationResult.lostLethal,\r\n\t\ttotalMatches,\r\n\t);\r\n\t// simulationResult.tiedPercent = checkRounding(Math.round((10 * (100 * simulationResult.tied)) / totalMatches) / 10, simulationResult.tied, totalMatches);\r\n\tsimulationResult.tiedPercent = checkRounding(\r\n\t\t100 - simulationResult.lostPercent - simulationResult.wonPercent,\r\n\t\tsimulationResult.tied,\r\n\t\ttotalMatches,\r\n\t);\r\n\r\n\tsimulationResult.wonLethalPercent = Math.round((10 * (100 * simulationResult.wonLethal)) / totalMatches) / 10;\r\n\tsimulationResult.lostLethalPercent = Math.round((10 * (100 * simulationResult.lostLethal)) / totalMatches) / 10;\r\n\tsimulationResult.averageDamageWon = simulationResult.won ? simulationResult.damageWon / simulationResult.won : 0;\r\n\tsimulationResult.averageDamageLost = simulationResult.lost\r\n\t\t? simulationResult.damageLost / simulationResult.lost\r\n\t\t: 0;\r\n\tif (simulationResult.averageDamageWon > 0 && simulationResult.averageDamageWon < playerInfo.player.tavernTier) {\r\n\t\tconsole.warn('average damage won issue', simulationResult, playerInfo);\r\n\t}\r\n\tif (simulationResult.averageDamageLost > 0 && simulationResult.averageDamageLost < opponentInfo.player.tavernTier) {\r\n\t\tconsole.warn('average damage lost issue', simulationResult, opponentInfo);\r\n\t}\r\n\t!battleInput.options?.skipInfoLogs && console.timeEnd('simulation');\r\n\tspectator.prune();\r\n\tsimulationResult.outcomeSamples = spectator.buildOutcomeSamples();\r\n\treturn simulationResult;\r\n};\r\n\r\nconst checkRounding = (roundedValue: number, initialValue: number, totalValue: number): number => {\r\n\tif (roundedValue === 0 && initialValue !== 0) {\r\n\t\treturn 0.01;\r\n\t}\r\n\tif (roundedValue === 100 && initialValue !== totalValue) {\r\n\t\treturn 99.9;\r\n\t}\r\n\treturn roundedValue;\r\n};\r\n\r\nconst cleanEnchantments = (board: readonly BoardEntity[]): readonly BoardEntity[] => {\r\n\tconst entityIds = board.map((entity) => entity.entityId);\r\n\treturn board.map((entity) => ({\r\n\t\t...entity,\r\n\t\tenchantments: cleanEnchantmentsForEntity(entity.enchantments, entityIds),\r\n\t}));\r\n};\r\n\r\nexport const validEnchantments = [\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment_BG_BOT_312e,\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantment_TB_BaconUps_032e,\r\n\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment_BG21_000e,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment_BG21_000_Ge,\r\n\tCardIds.Sneed_SneedsReplicator,\r\n\tCardIds.SneedsReplicator_ReplicateEnchantment,\r\n\tCardIds.EarthRecollectionEnchantment, // Spirit Raptor\r\n\tCardIds.FireRecollectionEnchantment,\r\n\tCardIds.LightningRecollectionEnchantment,\r\n\tCardIds.WaterRecollectionEnchantment,\r\n\tCardIds.EarthInvocation_ElementEarthEnchantment, // Summon a 1/1\r\n\t// CardIds.FireInvocation_ElementFireEnchantment, // Attack is doubled, probably no use to keep it\r\n\t// CardIds.WaterInvocation_ElementWaterEnchantment, // +3 health and taunt, same\r\n\tCardIds.LightningInvocation, // Deal 1 damage to 5 enemy minions\r\n\tCardIds.SurfNSurf_CrabRidingEnchantment_BG27_004e,\r\n\tCardIds.SurfNSurf_CrabRidingEnchantment_BG27_004_Ge,\r\n\tCardIds.RecurringNightmare_NightmareInsideEnchantment_BG26_055e,\r\n\tCardIds.RecurringNightmare_NightmareInsideEnchantment_BG26_055_Ge,\r\n];\r\n\r\nconst cleanEnchantmentsForEntity = (\r\n\tenchantments: { cardId: string; originEntityId?: number; timing: number }[],\r\n\tentityIds: readonly number[],\r\n): { cardId: string; originEntityId?: number; timing: number }[] => {\r\n\treturn enchantments.filter(\r\n\t\t(enchant) =>\r\n\t\t\tentityIds.indexOf(enchant.originEntityId) !== -1 ||\r\n\t\t\tvalidEnchantments.indexOf(enchant.cardId as CardIds) !== -1,\r\n\t);\r\n};\r\n"]}
package/dist/utils.js CHANGED
@@ -442,6 +442,9 @@ const setImplicitDataForEntity = (entity, cardsData) => {
442
442
  return entity;
443
443
  };
444
444
  const normalizeCardIdForSkin = (cardId) => {
445
+ if (!(cardId === null || cardId === void 0 ? void 0 : cardId.length)) {
446
+ return cardId;
447
+ }
445
448
  const skinMatch = cardId.match(/(.*)_SKIN_.*/);
446
449
  if (skinMatch) {
447
450
  return skinMatch[1];
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,iEAAoH;AAKpH,4CAA4D;AAG5D,MAAM,UAAU,GAAG;;;;;;;CAOlB,CAAC;AACF,MAAM,sBAAsB,GAAG;;;;CAI9B,CAAC;AACF,MAAM,eAAe,GAAG,8BAAoE,CAAC;AAEtF,MAAM,sBAAsB,GAAG,CACrC,MAAc,EACd,cAA+B,EAC/B,aAA4B,EAC5B,QAAyB,EACzB,QAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,KAAK,EACnB,SAAoB,EACpB,WAAwB,EACxB,aAA0B,EAC1B,iBAA8B,IAAI,EACpB,EAAE;;IAChB,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACnF,MAAM,SAAS,GAAG,CAAC,CAAC,aAAa;QAChC,CAAC,CAAE;YACD,GAAG,aAAa;YAChB,QAAQ,EAAE,WAAW,CAAC,eAAe,EAAE;YACvC,cAAc,EAAE,KAAK;YACrB,aAAa,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ACrF,MAAM,CAAC,MACP,OAAO,MAAM,CAAC,YAAY,EAAE;QAC9B,CAAC,CAAC,IAAI,CAAC;AACT,CAAC,CAAC;AANW,QAAA,mBAAmB,uBAM9B;AAEK,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAW,EAAE;;IACtD,OAAO,CACN,MAAM,CAAC,MAAM,CAAC,UAAU,wBAAwC;QAChE,MAAM,CAAC,MAAM,CAAC,UAAU,mBAAqB;SAC7C,MAAA,MAAM,CAAC,eAAe,0CAAE,QAAQ,cAAoC,CAAA,CACpE,CAAC;AACH,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEK,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,QAAyB,EAAW,EAAE;IAC9E,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,wBAAwB,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, GameTag, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { SharedState } from 'src/simulation/shared-state';\r\nimport { BgsPlayerEntity } from './bgs-player-entity';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { pickRandom, shuffleArray } from './services/utils';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\n\r\nconst CLEAVE_IDS = [\r\n\tCardIds.CaveHydra_BG_LOOT_078,\r\n\tCardIds.CaveHydra_TB_BaconUps_151,\r\n\tCardIds.FoeReaper4000_BG_GVG_113,\r\n\tCardIds.FoeReaper4000_TB_BaconUps_153,\r\n\tCardIds.BladeCollector_BG26_817,\r\n\tCardIds.BladeCollector_BG26_817_G,\r\n];\r\nconst ATTACK_IMMEDIATELY_IDS = [\r\n\tCardIds.Scallywag_SkyPirateToken_BGS_061t,\r\n\tCardIds.Scallywag_SkyPirateToken_TB_BaconUps_141t,\r\n\tCardIds.Onyxia_OnyxianWhelpToken,\r\n];\r\nconst CANT_ATTACK_IDS = [CardIds.ArcaneCannon_BGS_077, CardIds.ArcaneCannon_TB_BaconUps_128];\r\n\r\nexport const buildSingleBoardEntity = (\r\n\tcardId: string,\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tentityId = 1,\r\n\tspawnReborn = false,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tentityToSpawn: BoardEntity,\r\n\toriginalEntity: BoardEntity = null,\r\n): BoardEntity => {\r\n\tconst card = allCards.getCard(cardId);\r\n\tconst attackImmediately = ATTACK_IMMEDIATELY_IDS.indexOf(cardId as CardIds) !== -1;\r\n\tconst newEntity = !!entityToSpawn\r\n\t\t? ({\r\n\t\t\t\t...entityToSpawn,\r\n\t\t\t\tentityId: sharedState.currentEntityId++,\r\n\t\t\t\tdefinitelyDead: false,\r\n\t\t\t\tavengeCurrent: entityToSpawn.avengeDefault,\r\n\t\t\t\tattacking: false,\r\n\t\t\t\tdamageMultiplier: 1,\r\n\t\t\t\tfrenzyChargesLeft: 1,\r\n\t\t\t\tfriendly: friendly,\r\n\t\t } as BoardEntity)\r\n\t\t: addImpliedMechanics(\r\n\t\t\t\t{\r\n\t\t\t\t\tentityId: entityId,\r\n\t\t\t\t\tattack: card.attack,\r\n\t\t\t\t\tattacksPerformed: 0,\r\n\t\t\t\t\tcardId: cardId,\r\n\t\t\t\t\tdivineShield: hasMechanic(card, 'DIVINE_SHIELD'),\r\n\t\t\t\t\thealth: card.health,\r\n\t\t\t\t\tmaxHealth: card.health,\r\n\t\t\t\t\ttaunt: hasMechanic(card, GameTag[GameTag.TAUNT]),\r\n\t\t\t\t\treborn: hasMechanic(card, 'REBORN'),\r\n\t\t\t\t\tpoisonous: hasMechanic(card, GameTag[GameTag.POISONOUS]),\r\n\t\t\t\t\tvenomous: hasMechanic(card, GameTag[GameTag.VENOMOUS]),\r\n\t\t\t\t\twindfury:\r\n\t\t\t\t\t\thasMechanic(card, GameTag[GameTag.WINDFURY]) ||\r\n\t\t\t\t\t\tcard.referencedTags?.includes(GameTag[GameTag.WINDFURY]),\r\n\t\t\t\t\tenchantments: [],\r\n\t\t\t\t\tfriendly: friendly,\r\n\t\t\t\t\tattackImmediately: attackImmediately,\r\n\t\t\t\t\tavengeCurrent: cardsData.avengeValue(cardId),\r\n\t\t\t\t\tavengeDefault: cardsData.avengeValue(cardId),\r\n\t\t\t\t} as BoardEntity,\r\n\t\t\t\tcardsData,\r\n\t\t );\r\n\r\n\tif (spawnReborn && !entityToSpawn) {\r\n\t\tif (cardId === CardIds.BuildAnUndead_PutricidesCreationToken) {\r\n\t\t\tconst stitchedCardId = !!originalEntity.additionalCards?.length ? originalEntity.additionalCards[0] : null;\r\n\t\t\tif (stitchedCardId) {\r\n\t\t\t\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\t\t\t\tnewEntity.attack = newEntity.attack + stitchedCard.attack;\r\n\t\t\t\tnewEntity.maxHealth = newEntity.maxHealth + stitchedCard.health;\r\n\t\t\t\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\t\t\t\tnewEntity.divineShield =\r\n\t\t\t\t\tnewEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\t\t\t\tnewEntity.poisonous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\t\t\t\tnewEntity.venomous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\t\t\t\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\t\t\t\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t}\r\n\t\t}\r\n\t\tnewEntity.health = 1;\r\n\t\tnewEntity.reborn = false;\r\n\t}\r\n\r\n\tnewEntity.hadDivineShield = newEntity.divineShield || newEntity.hadDivineShield;\r\n\treturn newEntity;\r\n};\r\n\r\nexport const buildRandomUndeadCreation = (\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n): BoardEntity => {\r\n\tconst baseCard = pickRandom(cardsData.putricidePool1);\r\n\tconst stitchedCardId =\r\n\t\tbaseCard === CardIds.EternalSummoner_BG25_009\r\n\t\t\t? pickRandom(cardsData.putridicePool2ForEternalSummoner)\r\n\t\t\t: pickRandom(cardsData.putricidePool2);\r\n\tconst newEntity = buildSingleBoardEntity(\r\n\t\tbaseCard,\r\n\t\tcontrollerHero,\r\n\t\tfriendlyBoard,\r\n\t\tallCards,\r\n\t\tfriendly,\r\n\t\tsharedState.currentEntityId++,\r\n\t\tfalse,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tnull,\r\n\t);\r\n\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\tnewEntity.attack += stitchedCard.attack;\r\n\tnewEntity.health += stitchedCard.health;\r\n\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\tnewEntity.divineShield = newEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\tnewEntity.poisonous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\tnewEntity.venomous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\treturn newEntity;\r\n};\r\n\r\nexport const modifyAttack = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator = null,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.Tarecgosa_BG21_015_G ? 2 * amount : amount;\r\n\tentity.attack = Math.max(0, entity.attack + realAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tif (isCorrectTribe(allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t\t);\r\n\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t\t\tmodifyHealth(entity, buff, friendlyBoard, allCards);\r\n\t\t});\r\n\r\n\t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t\t\t);\r\n\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t\t\t\t(e) => modifyAttack(e, multiplier * amount, friendlyBoard, allCards);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tif ([CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(entity.cardId as CardIds)) {\r\n\t\taddStatsToBoard(\r\n\t\t\tentity,\r\n\t\t\tfriendlyBoard,\r\n\t\t\t0,\r\n\t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t\t\tallCards,\r\n\t\t\tnull,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const modifyHealth = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.Tarecgosa_BG21_015 ? 2 * amount : amount;\r\n\tentity.health += realAmount;\r\n\tif (realAmount > 0) {\r\n\t\tentity.maxHealth += realAmount;\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tconst titanicGuardians = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t);\r\n\ttitanicGuardians.forEach((guardian) => {\r\n\t\tmodifyHealth(\r\n\t\t\tguardian,\r\n\t\t\t(guardian.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const afterStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, Race.ELEMENTAL, allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealities_BG21_036_G,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\tmodifyAttack(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tmodifyHealth(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const makeMinionGolden = (\r\n\ttarget: BoardEntity,\r\n\tsource: BoardEntity | BgsPlayerEntity,\r\n\tsourceBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Typically, we are already golden\r\n\tif (isMinionGolden(target, allCards)) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst refCard = allCards.getCard(target.cardId);\r\n\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\ttarget.cardId = goldenCard.id;\r\n\t// A minion becoming golden ignore the current death.\r\n\t// This way of handling it is not ideal, since it will still trigger if both avenges trigger at the same time, but\r\n\t// should solve the other cases\r\n\ttarget.avengeCurrent = Math.min(target.avengeDefault, target.avengeCurrent + 1);\r\n\tmodifyAttack(target, refCard.attack, sourceBoard, allCards);\r\n\tmodifyHealth(target, refCard.health, sourceBoard, allCards);\r\n\tafterStatsUpdate(target, sourceBoard, allCards);\r\n\tspectator.registerPowerTarget(source, target, sourceBoard);\r\n};\r\n\r\nexport const isMinionGolden = (entity: BoardEntity, allCards: AllCardsService): boolean => {\r\n\tconst ref = allCards.getCard(entity.cardId);\r\n\treturn !ref.battlegroundsPremiumDbfId;\r\n\t// Why this condition?\r\n\t// || !allCards.getCardFromDbfId(ref.battlegroundsPremiumDbfId).id\r\n};\r\n\r\nexport const grantRandomAttack = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tadditionalAttack: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyAttack(target, additionalAttack, candidateBoard, allCards);\r\n\t\tafterStatsUpdate(target, candidateBoard, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomHealth = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyHealth(target, health, board, allCards);\r\n\t\tafterStatsUpdate(target, board, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomStats = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\trace: Race,\r\n\texcludeSource: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator?: Spectator,\r\n): BoardEntity => {\r\n\tif (board.length > 0) {\r\n\t\tconst target: BoardEntity = getRandomAliveMinion(\r\n\t\t\tboard.filter((e) => (excludeSource ? e.entityId !== source.entityId : true)),\r\n\t\t\trace,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tif (target) {\r\n\t\t\tmodifyAttack(target, attack, board, allCards);\r\n\t\t\tmodifyHealth(target, health, board, allCards);\r\n\t\t\tafterStatsUpdate(target, board, allCards);\r\n\t\t\tif (spectator) {\r\n\t\t\t\tspectator.registerPowerTarget(source, target, board);\r\n\t\t\t}\r\n\t\t\treturn target;\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const addCardsInHand = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tcardsAdded: readonly any[],\r\n): void => {\r\n\tconst previousCardsInHand = playerEntity.hand?.length ?? 0;\r\n\tconst sages = board.filter((e) => e.cardId === CardIds.DeathsHeadSage_BG20_HERO_103_Buddy);\r\n\tconst sagesGolden = board.filter((e) => e.cardId === CardIds.DeathsHeadSage_BG20_HERO_103_Buddy_G);\r\n\tconst multiplier = sages.length + 2 * sagesGolden.length;\r\n\r\n\tconst cardsThatWillBeAdded = [];\r\n\tfor (const cardAdded of cardsAdded) {\r\n\t\tconst cardToAdd: { cardId: string } = (cardAdded as BoardEntity)?.cardId\r\n\t\t\t? (cardAdded as BoardEntity)\r\n\t\t\t: ({ cardId: cardAdded as string } as BoardEntity);\r\n\t\tcardsThatWillBeAdded.push(cardToAdd);\r\n\t\tif (cardToAdd.cardId === CardIds.BloodGem) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tcardsThatWillBeAdded.push({ ...cardToAdd });\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < cardsThatWillBeAdded.length; i++) {\r\n\t\tif (playerEntity.hand.length >= 10) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tplayerEntity.hand.push(cardsThatWillBeAdded[i]);\r\n\t}\r\n\r\n\tconst numCardsAdded = playerEntity.hand.length - previousCardsInHand;\r\n\r\n\tfor (let i = 0; i < numCardsAdded; i++) {\r\n\t\tconst peggys = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.PeggySturdybone_BG25_032 || e.cardId === CardIds.PeggySturdybone_BG25_032_G,\r\n\t\t);\r\n\t\tpeggys.forEach((peggy) => {\r\n\t\t\tconst pirate = getRandomAliveMinion(\r\n\t\t\t\tboard.filter((e) => e.entityId !== peggy.entityId),\r\n\t\t\t\tRace.PIRATE,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tif (pirate) {\r\n\t\t\t\tmodifyAttack(pirate, peggy.cardId === CardIds.PeggySturdybone_BG25_032_G ? 2 : 1, board, allCards);\r\n\t\t\t\tmodifyHealth(pirate, peggy.cardId === CardIds.PeggySturdybone_BG25_032_G ? 2 : 1, board, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(peggy, pirate, board);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst thornCaptains = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.Thorncaptain_BG25_045 || e.cardId === CardIds.Thorncaptain_BG25_045_G,\r\n\t\t);\r\n\t\tthornCaptains.forEach((captain) => {\r\n\t\t\tmodifyHealth(captain, captain.cardId === CardIds.Thorncaptain_BG25_045_G ? 2 : 1, board, allCards);\r\n\t\t\tafterStatsUpdate(captain, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, captain, board);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const removeCardFromHand = (playerEntity: BgsPlayerEntity, card: BoardEntity): void => {\r\n\tlet cardToRemove: BoardEntity;\r\n\tif (card?.entityId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.entityId !== card.entityId);\r\n\t} else if (card?.cardId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.cardId === card.cardId);\r\n\t} else {\r\n\t\t// Remove a single random card in hand that doesn't have an entityId\r\n\t\tcardToRemove =\r\n\t\t\tpickRandom(playerEntity.hand.filter((c) => !c?.entityId && !c?.cardId)) ?? pickRandom(playerEntity.hand);\r\n\t}\r\n\t// Remove the first occurrence of the card from playerEntity.cardsInHand, even if it is null\r\n\tconst index = playerEntity.hand.indexOf(cardToRemove);\r\n\tif (index !== -1) {\r\n\t\tplayerEntity.hand.splice(index, 1);\r\n\t}\r\n};\r\n\r\nexport const grantRandomDivineShield = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tif (elligibleEntities.length > 0) {\r\n\t\tconst chosen = elligibleEntities[Math.floor(Math.random() * elligibleEntities.length)];\r\n\t\tupdateDivineShield(chosen, board, true, allCards);\r\n\t\tspectator.registerPowerTarget(source, chosen, board);\r\n\t}\r\n\t// return board;\r\n};\r\n\r\nexport const updateDivineShield = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tnewValue: boolean,\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\t// if ((entity.divineShield ?? false) === newValue) {\r\n\t// \treturn;\r\n\t// }\r\n\tentity.divineShield = newValue;\r\n\tif (entity.divineShield) {\r\n\t\tentity.hadDivineShield = true;\r\n\t}\r\n\tif (entity.divineShield) {\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043_G).length;\r\n\t\t// Don't trigger all \"on attack changed\" effects, since it's an aura\r\n\t\tentity.attack += statsBonus;\r\n\t} else {\r\n\t\t// Also consider itself\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043_G).length;\r\n\t\tentity.attack -= statsBonus;\r\n\t}\r\n};\r\n\r\nexport const grantAllDivineShield = (board: BoardEntity[], tribe: string, cards: AllCardsService): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => isCorrectTribe(cards.getCard(entity.cardId).races, getRaceEnum(tribe)));\r\n\tfor (const entity of elligibleEntities) {\r\n\t\tupdateDivineShield(entity, board, true, cards);\r\n\t}\r\n};\r\n\r\nexport const getRandomAliveMinion = (board: BoardEntity[], race: Race, allCards: AllCardsService): BoardEntity => {\r\n\tconst validTribes = board\r\n\t\t.filter((e) => !race || isCorrectTribe(allCards.getCard(e?.cardId).races, race))\r\n\t\t.filter((e) => !!e?.health && !e.definitelyDead);\r\n\tif (!validTribes.length) {\r\n\t\treturn null;\r\n\t}\r\n\tconst randomIndex = Math.floor(Math.random() * validTribes.length);\r\n\treturn validTribes[randomIndex];\r\n};\r\n\r\nexport const getRandomMinionWithHighestHealth = (board: BoardEntity[]): BoardEntity => {\r\n\tif (!board.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst highestHealth = Math.max(...board.map((e) => e.health));\r\n\tconst validMinions = board.filter((e) => e.health === highestHealth);\r\n\treturn validMinions[Math.floor(Math.random() * validMinions.length)];\r\n};\r\n\r\nexport const addStatsToBoard = (\r\n\tsourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\ttribe?: string,\r\n): void => {\r\n\tfor (const entity of board) {\r\n\t\tif (!tribe || hasCorrectTribe(entity, Race[tribe], allCards)) {\r\n\t\t\tmodifyAttack(entity, attack, board, allCards);\r\n\t\t\tmodifyHealth(entity, health, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\tspectator?.registerPowerTarget(sourceEntity, entity, board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const grantStatsToMinionsOfEachType = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tnumberOfDifferentTypes = 99,\r\n): void => {\r\n\tif (board.length > 0) {\r\n\t\tlet boardCopy = [...board];\r\n\t\tconst allRaces = shuffleArray(ALL_BG_RACES);\r\n\t\tlet typesBuffed = 0;\r\n\t\tfor (const tribe of allRaces) {\r\n\t\t\tif (typesBuffed >= numberOfDifferentTypes) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst validMinion: BoardEntity = getRandomAliveMinion(boardCopy, tribe, allCards);\r\n\t\t\tif (validMinion) {\r\n\t\t\t\tmodifyAttack(validMinion, attack, board, allCards);\r\n\t\t\t\tmodifyHealth(validMinion, health, board, allCards);\r\n\t\t\t\tafterStatsUpdate(validMinion, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(source, validMinion, board);\r\n\t\t\t\tboardCopy = boardCopy.filter((e) => e !== validMinion);\r\n\t\t\t\ttypesBuffed++;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const hasMechanic = (card: ReferenceCard, mechanic: string): boolean => {\r\n\treturn card.mechanics?.includes(mechanic);\r\n};\r\n\r\nexport const hasCorrectTribe = (entity: BoardEntity, targetTribe: Race, allCards: AllCardsService): boolean => {\r\n\treturn isCorrectTribe(allCards.getCard(entity.cardId).races, targetTribe);\r\n};\r\n\r\nexport const isCorrectTribe = (cardRaces: readonly string[], targetTribe: Race): boolean => {\r\n\tif (!cardRaces?.length) {\r\n\t\treturn false;\r\n\t}\r\n\treturn cardRaces\r\n\t\t.map((cardRace) => getRaceEnum(cardRace))\r\n\t\t.some((raceEnum) => raceEnum === Race.ALL || raceEnum === targetTribe);\r\n};\r\n\r\nexport const getRaceEnum = (race: string): Race => {\r\n\treturn Race[race];\r\n};\r\n\r\nexport const addImpliedMechanics = (entity: BoardEntity, cardsData: CardsData): BoardEntity => {\r\n\tconst cleave = CLEAVE_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\tconst cantAttack = CANT_ATTACK_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\treturn setImplicitDataForEntity(\r\n\t\t{\r\n\t\t\t...entity,\r\n\t\t\tcleave: cleave,\r\n\t\t\tcantAttack: cantAttack,\r\n\t\t\timmuneWhenAttackCharges:\r\n\t\t\t\tentity.cardId === CardIds.Warpwing_BG24_004 || entity.cardId === CardIds.Warpwing_BG24_004_G\r\n\t\t\t\t\t? 99999\r\n\t\t\t\t\t: 0,\r\n\t\t\tfrenzyChargesLeft:\r\n\t\t\t\tentity.cardId === CardIds.BristlebackKnight_BG20_204_G\r\n\t\t\t\t\t? 2\r\n\t\t\t\t\t: entity.cardId === CardIds.BristlebackKnight_BG20_204\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0,\r\n\t\t\t// It's not an issue adding a charge for entities without a special ability\r\n\t\t\tabiityChargesLeft: [CardIds.TransmutedBramblewitch_BG27_013_G, CardIds.Mannoroth_BG27_507_G].includes(\r\n\t\t\t\tentity.cardId as CardIds,\r\n\t\t\t)\r\n\t\t\t\t? 2\r\n\t\t\t\t: 1,\r\n\t\t} as BoardEntity,\r\n\t\tcardsData,\r\n\t);\r\n};\r\n\r\nconst setImplicitDataForEntity = (entity: BoardEntity, cardsData: CardsData): BoardEntity => {\r\n\tentity.cardId = normalizeCardIdForSkin(entity.cardId);\r\n\tentity.maxHealth = Math.max(0, entity.health);\r\n\tconst avengeValue = cardsData.avengeValue(entity.cardId);\r\n\tif (avengeValue > 0) {\r\n\t\tentity.avengeCurrent = avengeValue;\r\n\t\tentity.avengeDefault = avengeValue;\r\n\t}\r\n\treturn entity;\r\n};\r\n\r\nexport const normalizeCardIdForSkin = (cardId: string): string => {\r\n\tconst skinMatch = cardId.match(/(.*)_SKIN_.*/);\r\n\tif (skinMatch) {\r\n\t\treturn skinMatch[1];\r\n\t}\r\n\treturn cardId;\r\n};\r\n\r\nexport const stringifySimple = (board: readonly BoardEntity[], allCards: AllCardsService = null): string => {\r\n\treturn '[' + board.map((entity) => stringifySimpleCard(entity, allCards)).join(', ') + ']';\r\n};\r\n\r\nexport const stringifySimpleCard = (entity: BoardEntity, allCards: AllCardsService = null): string => {\r\n\treturn entity\r\n\t\t? `${entity.cardId}/${allCards?.getCard(entity.cardId)?.name ?? ''}/atk=${entity.attack}/hp=${\r\n\t\t\t\tentity.health\r\n\t\t }/ds=${entity.divineShield}`\r\n\t\t: null;\r\n};\r\n\r\nexport const isFish = (entity: BoardEntity): boolean => {\r\n\treturn (\r\n\t\tentity.cardId.startsWith(CardIds.AvatarOfNzoth_FishOfNzothToken) ||\r\n\t\tentity.cardId.startsWith(CardIds.FishOfNzoth) ||\r\n\t\tentity.additionalCards?.includes(CardIds.DevourerOfSouls_BG_RLK_538)\r\n\t);\r\n};\r\n\r\nexport const isGolden = (cardId: string, allCards: AllCardsService): boolean => {\r\n\treturn !!allCards.getCard(cardId).battlegroundsNormalDbfId;\r\n};\r\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,iEAAoH;AAKpH,4CAA4D;AAG5D,MAAM,UAAU,GAAG;;;;;;;CAOlB,CAAC;AACF,MAAM,sBAAsB,GAAG;;;;CAI9B,CAAC;AACF,MAAM,eAAe,GAAG,8BAAoE,CAAC;AAEtF,MAAM,sBAAsB,GAAG,CACrC,MAAc,EACd,cAA+B,EAC/B,aAA4B,EAC5B,QAAyB,EACzB,QAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,KAAK,EACnB,SAAoB,EACpB,WAAwB,EACxB,aAA0B,EAC1B,iBAA8B,IAAI,EACpB,EAAE;;IAChB,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACnF,MAAM,SAAS,GAAG,CAAC,CAAC,aAAa;QAChC,CAAC,CAAE;YACD,GAAG,aAAa;YAChB,QAAQ,EAAE,WAAW,CAAC,eAAe,EAAE;YACvC,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,aAAa,CAAC,aAAa;YAC1C,SAAS,EAAE,KAAK;YAChB,gBAAgB,EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;YACpB,QAAQ,EAAE,QAAQ;SACD;QACnB,CAAC,CAAC,IAAA,2BAAmB,EACnB;YACC,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,gBAAgB,EAAE,CAAC;YACnB,MAAM,EAAE,MAAM;YACd,YAAY,EAAE,IAAA,mBAAW,EAAC,IAAI,EA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U,wBAAwC;QAChE,MAAM,CAAC,MAAM,CAAC,UAAU,mBAAqB;SAC7C,MAAA,MAAM,CAAC,eAAe,0CAAE,QAAQ,cAAoC,CAAA,CACpE,CAAC;AACH,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEK,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,QAAyB,EAAW,EAAE;IAC9E,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,wBAAwB,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\r\nimport { ALL_BG_RACES, AllCardsService, CardIds, GameTag, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { SharedState } from 'src/simulation/shared-state';\r\nimport { BgsPlayerEntity } from './bgs-player-entity';\r\nimport { BoardEntity } from './board-entity';\r\nimport { CardsData } from './cards/cards-data';\r\nimport { pickRandom, shuffleArray } from './services/utils';\r\nimport { Spectator } from './simulation/spectator/spectator';\r\n\r\nconst CLEAVE_IDS = [\r\n\tCardIds.CaveHydra_BG_LOOT_078,\r\n\tCardIds.CaveHydra_TB_BaconUps_151,\r\n\tCardIds.FoeReaper4000_BG_GVG_113,\r\n\tCardIds.FoeReaper4000_TB_BaconUps_153,\r\n\tCardIds.BladeCollector_BG26_817,\r\n\tCardIds.BladeCollector_BG26_817_G,\r\n];\r\nconst ATTACK_IMMEDIATELY_IDS = [\r\n\tCardIds.Scallywag_SkyPirateToken_BGS_061t,\r\n\tCardIds.Scallywag_SkyPirateToken_TB_BaconUps_141t,\r\n\tCardIds.Onyxia_OnyxianWhelpToken,\r\n];\r\nconst CANT_ATTACK_IDS = [CardIds.ArcaneCannon_BGS_077, CardIds.ArcaneCannon_TB_BaconUps_128];\r\n\r\nexport const buildSingleBoardEntity = (\r\n\tcardId: string,\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tentityId = 1,\r\n\tspawnReborn = false,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n\tentityToSpawn: BoardEntity,\r\n\toriginalEntity: BoardEntity = null,\r\n): BoardEntity => {\r\n\tconst card = allCards.getCard(cardId);\r\n\tconst attackImmediately = ATTACK_IMMEDIATELY_IDS.indexOf(cardId as CardIds) !== -1;\r\n\tconst newEntity = !!entityToSpawn\r\n\t\t? ({\r\n\t\t\t\t...entityToSpawn,\r\n\t\t\t\tentityId: sharedState.currentEntityId++,\r\n\t\t\t\tdefinitelyDead: false,\r\n\t\t\t\tavengeCurrent: entityToSpawn.avengeDefault,\r\n\t\t\t\tattacking: false,\r\n\t\t\t\tdamageMultiplier: 1,\r\n\t\t\t\tfrenzyChargesLeft: 1,\r\n\t\t\t\tfriendly: friendly,\r\n\t\t } as BoardEntity)\r\n\t\t: addImpliedMechanics(\r\n\t\t\t\t{\r\n\t\t\t\t\tentityId: entityId,\r\n\t\t\t\t\tattack: card.attack,\r\n\t\t\t\t\tattacksPerformed: 0,\r\n\t\t\t\t\tcardId: cardId,\r\n\t\t\t\t\tdivineShield: hasMechanic(card, 'DIVINE_SHIELD'),\r\n\t\t\t\t\thealth: card.health,\r\n\t\t\t\t\tmaxHealth: card.health,\r\n\t\t\t\t\ttaunt: hasMechanic(card, GameTag[GameTag.TAUNT]),\r\n\t\t\t\t\treborn: hasMechanic(card, 'REBORN'),\r\n\t\t\t\t\tpoisonous: hasMechanic(card, GameTag[GameTag.POISONOUS]),\r\n\t\t\t\t\tvenomous: hasMechanic(card, GameTag[GameTag.VENOMOUS]),\r\n\t\t\t\t\twindfury:\r\n\t\t\t\t\t\thasMechanic(card, GameTag[GameTag.WINDFURY]) ||\r\n\t\t\t\t\t\tcard.referencedTags?.includes(GameTag[GameTag.WINDFURY]),\r\n\t\t\t\t\tenchantments: [],\r\n\t\t\t\t\tfriendly: friendly,\r\n\t\t\t\t\tattackImmediately: attackImmediately,\r\n\t\t\t\t\tavengeCurrent: cardsData.avengeValue(cardId),\r\n\t\t\t\t\tavengeDefault: cardsData.avengeValue(cardId),\r\n\t\t\t\t} as BoardEntity,\r\n\t\t\t\tcardsData,\r\n\t\t );\r\n\r\n\tif (spawnReborn && !entityToSpawn) {\r\n\t\tif (cardId === CardIds.BuildAnUndead_PutricidesCreationToken) {\r\n\t\t\tconst stitchedCardId = !!originalEntity.additionalCards?.length ? originalEntity.additionalCards[0] : null;\r\n\t\t\tif (stitchedCardId) {\r\n\t\t\t\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\t\t\t\tnewEntity.attack = newEntity.attack + stitchedCard.attack;\r\n\t\t\t\tnewEntity.maxHealth = newEntity.maxHealth + stitchedCard.health;\r\n\t\t\t\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\t\t\t\tnewEntity.divineShield =\r\n\t\t\t\t\tnewEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\t\t\t\tnewEntity.poisonous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\t\t\t\tnewEntity.venomous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\t\t\t\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\t\t\t\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\t\t\t}\r\n\t\t}\r\n\t\tnewEntity.health = 1;\r\n\t\tnewEntity.reborn = false;\r\n\t}\r\n\r\n\tnewEntity.hadDivineShield = newEntity.divineShield || newEntity.hadDivineShield;\r\n\treturn newEntity;\r\n};\r\n\r\nexport const buildRandomUndeadCreation = (\r\n\tcontrollerHero: BgsPlayerEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tfriendly: boolean,\r\n\tcardsData: CardsData,\r\n\tsharedState: SharedState,\r\n): BoardEntity => {\r\n\tconst baseCard = pickRandom(cardsData.putricidePool1);\r\n\tconst stitchedCardId =\r\n\t\tbaseCard === CardIds.EternalSummoner_BG25_009\r\n\t\t\t? pickRandom(cardsData.putridicePool2ForEternalSummoner)\r\n\t\t\t: pickRandom(cardsData.putricidePool2);\r\n\tconst newEntity = buildSingleBoardEntity(\r\n\t\tbaseCard,\r\n\t\tcontrollerHero,\r\n\t\tfriendlyBoard,\r\n\t\tallCards,\r\n\t\tfriendly,\r\n\t\tsharedState.currentEntityId++,\r\n\t\tfalse,\r\n\t\tcardsData,\r\n\t\tsharedState,\r\n\t\tnull,\r\n\t);\r\n\tconst stitchedCard = allCards.getCard(stitchedCardId);\r\n\tnewEntity.attack += stitchedCard.attack;\r\n\tnewEntity.health += stitchedCard.health;\r\n\tnewEntity.taunt = newEntity.taunt || hasMechanic(stitchedCard, GameTag[GameTag.TAUNT]);\r\n\tnewEntity.divineShield = newEntity.divineShield || hasMechanic(stitchedCard, GameTag[GameTag.DIVINE_SHIELD]);\r\n\tnewEntity.poisonous = newEntity.venomous || hasMechanic(stitchedCard, GameTag[GameTag.POISONOUS]);\r\n\tnewEntity.venomous = newEntity.poisonous || hasMechanic(stitchedCard, GameTag[GameTag.VENOMOUS]);\r\n\tnewEntity.windfury = newEntity.windfury || hasMechanic(stitchedCard, GameTag[GameTag.WINDFURY]);\r\n\tnewEntity.avengeCurrent = newEntity.avengeCurrent || cardsData.avengeValue(stitchedCardId);\r\n\tnewEntity.avengeDefault = newEntity.avengeDefault || cardsData.avengeValue(stitchedCardId);\r\n\treturn newEntity;\r\n};\r\n\r\nexport const modifyAttack = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator = null,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.Tarecgosa_BG21_015_G ? 2 * amount : amount;\r\n\tentity.attack = Math.max(0, entity.attack + realAmount);\r\n\tentity.previousAttack = entity.attack;\r\n\tif (isCorrectTribe(allCards.getCard(entity.cardId).races, Race.DRAGON)) {\r\n\t\tconst whelpSmugglers = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.WhelpSmuggler_BG21_013 || e.cardId === CardIds.WhelpSmuggler_BG21_013_G,\r\n\t\t);\r\n\t\twhelpSmugglers.forEach((smuggler) => {\r\n\t\t\tconst buff = smuggler.cardId === CardIds.WhelpSmuggler_BG21_013_G ? 2 : 1;\r\n\t\t\tmodifyHealth(entity, buff, friendlyBoard, allCards);\r\n\t\t});\r\n\r\n\t\tif (entity.cardId !== CardIds.Stormbringer_BG26_966 && entity.cardId !== CardIds.Stormbringer_BG26_966_G) {\r\n\t\t\tconst stormbringers = friendlyBoard.filter(\r\n\t\t\t\t(e) => e.cardId === CardIds.Stormbringer_BG26_966 || e.cardId === CardIds.Stormbringer_BG26_966_G,\r\n\t\t\t);\r\n\t\t\tstormbringers.forEach((stormbringer) => {\r\n\t\t\t\tconst multiplier = stormbringer.cardId === CardIds.Stormbringer_BG26_966_G ? 2 : 1;\r\n\t\t\t\t(e) => modifyAttack(e, multiplier * amount, friendlyBoard, allCards);\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tif ([CardIds.HunterOfGatherers_BG25_027, CardIds.HunterOfGatherers_BG25_027_G].includes(entity.cardId as CardIds)) {\r\n\t\taddStatsToBoard(\r\n\t\t\tentity,\r\n\t\t\tfriendlyBoard,\r\n\t\t\t0,\r\n\t\t\tentity.cardId === CardIds.HunterOfGatherers_BG25_027_G ? 2 : 1,\r\n\t\t\tallCards,\r\n\t\t\tnull,\r\n\t\t);\r\n\t}\r\n};\r\n\r\nexport const modifyHealth = (\r\n\tentity: BoardEntity,\r\n\tamount: number,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tconst realAmount = entity.cardId === CardIds.Tarecgosa_BG21_015 ? 2 * amount : amount;\r\n\tentity.health += realAmount;\r\n\tif (realAmount > 0) {\r\n\t\tentity.maxHealth += realAmount;\r\n\t}\r\n\tif (\r\n\t\tentity.cardId === CardIds.Menagerist_AmalgamToken ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A ||\r\n\t\tentity.cardId === CardIds.Cuddlgam_TB_BaconShop_HP_033t_SKIN_A_G ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D ||\r\n\t\tentity.cardId === CardIds.AbominableAmalgam_TB_BaconShop_HP_033t_SKIN_D_G\r\n\t) {\r\n\t\tconst mishmashes = friendlyBoard.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy ||\r\n\t\t\t\te.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G,\r\n\t\t);\r\n\t\tmishmashes.forEach((mishmash) => {\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmishmash,\r\n\t\t\t\t(mishmash.cardId === CardIds.Mishmash_TB_BaconShop_HERO_33_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\r\n\tconst titanicGuardians = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G,\r\n\t\t);\r\n\ttitanicGuardians.forEach((guardian) => {\r\n\t\tmodifyHealth(\r\n\t\t\tguardian,\r\n\t\t\t(guardian.cardId === CardIds.TitanicGuardian_TB_BaconShop_HERO_39_Buddy_G ? 2 : 1) * realAmount,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const afterStatsUpdate = (\r\n\tentity: BoardEntity,\r\n\tfriendlyBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\tif (hasCorrectTribe(entity, Race.ELEMENTAL, allCards)) {\r\n\t\tconst masterOfRealities = friendlyBoard.filter(\r\n\t\t\t(e) => e.cardId === CardIds.MasterOfRealities_BG21_036 || e.cardId === CardIds.MasterOfRealities_BG21_036_G,\r\n\t\t);\r\n\t\tmasterOfRealities.forEach((master) => {\r\n\t\t\tmodifyAttack(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tmodifyHealth(\r\n\t\t\t\tmaster,\r\n\t\t\t\tmaster.cardId === CardIds.MasterOfRealities_BG21_036_G ? 2 : 1,\r\n\t\t\t\tfriendlyBoard,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t});\r\n\t}\r\n\tconst tentaclesOfCthun = friendlyBoard\r\n\t\t.filter((e) => e.entityId !== entity.entityId)\r\n\t\t.filter(\r\n\t\t\t(e) =>\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy ||\r\n\t\t\t\te.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G,\r\n\t\t);\r\n\ttentaclesOfCthun.forEach((tentacle) => {\r\n\t\tmodifyAttack(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tmodifyHealth(\r\n\t\t\ttentacle,\r\n\t\t\ttentacle.cardId === CardIds.TentacleOfCthun_TB_BaconShop_HERO_29_Buddy_G ? 2 : 1,\r\n\t\t\tfriendlyBoard,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t});\r\n};\r\n\r\nexport const makeMinionGolden = (\r\n\ttarget: BoardEntity,\r\n\tsource: BoardEntity | BgsPlayerEntity,\r\n\tsourceBoard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\t// Typically, we are already golden\r\n\tif (isMinionGolden(target, allCards)) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tconst refCard = allCards.getCard(target.cardId);\r\n\tconst goldenCard = allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);\r\n\ttarget.cardId = goldenCard.id;\r\n\t// A minion becoming golden ignore the current death.\r\n\t// This way of handling it is not ideal, since it will still trigger if both avenges trigger at the same time, but\r\n\t// should solve the other cases\r\n\ttarget.avengeCurrent = Math.min(target.avengeDefault, target.avengeCurrent + 1);\r\n\tmodifyAttack(target, refCard.attack, sourceBoard, allCards);\r\n\tmodifyHealth(target, refCard.health, sourceBoard, allCards);\r\n\tafterStatsUpdate(target, sourceBoard, allCards);\r\n\tspectator.registerPowerTarget(source, target, sourceBoard);\r\n};\r\n\r\nexport const isMinionGolden = (entity: BoardEntity, allCards: AllCardsService): boolean => {\r\n\tconst ref = allCards.getCard(entity.cardId);\r\n\treturn !ref.battlegroundsPremiumDbfId;\r\n\t// Why this condition?\r\n\t// || !allCards.getCardFromDbfId(ref.battlegroundsPremiumDbfId).id\r\n};\r\n\r\nexport const grantRandomAttack = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tadditionalAttack: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyAttack(target, additionalAttack, candidateBoard, allCards);\r\n\t\tafterStatsUpdate(target, candidateBoard, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomHealth = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\texcludeSource = false,\r\n): void => {\r\n\tconst candidateBoard = board\r\n\t\t.filter((e) => !excludeSource || e.entityId !== source.entityId)\r\n\t\t.filter((e) => e.health > 0 && !e.definitelyDead);\r\n\tif (candidateBoard.length > 0) {\r\n\t\tconst target = candidateBoard[Math.floor(Math.random() * candidateBoard.length)];\r\n\t\tmodifyHealth(target, health, board, allCards);\r\n\t\tafterStatsUpdate(target, board, allCards);\r\n\t\tspectator.registerPowerTarget(source, target, board);\r\n\t}\r\n};\r\n\r\nexport const grantRandomStats = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\trace: Race,\r\n\texcludeSource: boolean,\r\n\tallCards: AllCardsService,\r\n\tspectator?: Spectator,\r\n): BoardEntity => {\r\n\tif (board.length > 0) {\r\n\t\tconst target: BoardEntity = getRandomAliveMinion(\r\n\t\t\tboard.filter((e) => (excludeSource ? e.entityId !== source.entityId : true)),\r\n\t\t\trace,\r\n\t\t\tallCards,\r\n\t\t);\r\n\t\tif (target) {\r\n\t\t\tmodifyAttack(target, attack, board, allCards);\r\n\t\t\tmodifyHealth(target, health, board, allCards);\r\n\t\t\tafterStatsUpdate(target, board, allCards);\r\n\t\t\tif (spectator) {\r\n\t\t\t\tspectator.registerPowerTarget(source, target, board);\r\n\t\t\t}\r\n\t\t\treturn target;\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n};\r\n\r\nexport const addCardsInHand = (\r\n\tplayerEntity: BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tcardsAdded: readonly any[],\r\n): void => {\r\n\tconst previousCardsInHand = playerEntity.hand?.length ?? 0;\r\n\tconst sages = board.filter((e) => e.cardId === CardIds.DeathsHeadSage_BG20_HERO_103_Buddy);\r\n\tconst sagesGolden = board.filter((e) => e.cardId === CardIds.DeathsHeadSage_BG20_HERO_103_Buddy_G);\r\n\tconst multiplier = sages.length + 2 * sagesGolden.length;\r\n\r\n\tconst cardsThatWillBeAdded = [];\r\n\tfor (const cardAdded of cardsAdded) {\r\n\t\tconst cardToAdd: { cardId: string } = (cardAdded as BoardEntity)?.cardId\r\n\t\t\t? (cardAdded as BoardEntity)\r\n\t\t\t: ({ cardId: cardAdded as string } as BoardEntity);\r\n\t\tcardsThatWillBeAdded.push(cardToAdd);\r\n\t\tif (cardToAdd.cardId === CardIds.BloodGem) {\r\n\t\t\tfor (let i = 0; i < multiplier; i++) {\r\n\t\t\t\tcardsThatWillBeAdded.push({ ...cardToAdd });\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfor (let i = 0; i < cardsThatWillBeAdded.length; i++) {\r\n\t\tif (playerEntity.hand.length >= 10) {\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tplayerEntity.hand.push(cardsThatWillBeAdded[i]);\r\n\t}\r\n\r\n\tconst numCardsAdded = playerEntity.hand.length - previousCardsInHand;\r\n\r\n\tfor (let i = 0; i < numCardsAdded; i++) {\r\n\t\tconst peggys = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.PeggySturdybone_BG25_032 || e.cardId === CardIds.PeggySturdybone_BG25_032_G,\r\n\t\t);\r\n\t\tpeggys.forEach((peggy) => {\r\n\t\t\tconst pirate = getRandomAliveMinion(\r\n\t\t\t\tboard.filter((e) => e.entityId !== peggy.entityId),\r\n\t\t\t\tRace.PIRATE,\r\n\t\t\t\tallCards,\r\n\t\t\t);\r\n\t\t\tif (pirate) {\r\n\t\t\t\tmodifyAttack(pirate, peggy.cardId === CardIds.PeggySturdybone_BG25_032_G ? 2 : 1, board, allCards);\r\n\t\t\t\tmodifyHealth(pirate, peggy.cardId === CardIds.PeggySturdybone_BG25_032_G ? 2 : 1, board, allCards);\r\n\t\t\t\tafterStatsUpdate(pirate, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(peggy, pirate, board);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst thornCaptains = board.filter(\r\n\t\t\t(e) => e.cardId === CardIds.Thorncaptain_BG25_045 || e.cardId === CardIds.Thorncaptain_BG25_045_G,\r\n\t\t);\r\n\t\tthornCaptains.forEach((captain) => {\r\n\t\t\tmodifyHealth(captain, captain.cardId === CardIds.Thorncaptain_BG25_045_G ? 2 : 1, board, allCards);\r\n\t\t\tafterStatsUpdate(captain, board, allCards);\r\n\t\t\tspectator.registerPowerTarget(captain, captain, board);\r\n\t\t});\r\n\t}\r\n};\r\n\r\nexport const removeCardFromHand = (playerEntity: BgsPlayerEntity, card: BoardEntity): void => {\r\n\tlet cardToRemove: BoardEntity;\r\n\tif (card?.entityId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.entityId !== card.entityId);\r\n\t} else if (card?.cardId) {\r\n\t\tcardToRemove = playerEntity.hand.find((c) => c?.cardId === card.cardId);\r\n\t} else {\r\n\t\t// Remove a single random card in hand that doesn't have an entityId\r\n\t\tcardToRemove =\r\n\t\t\tpickRandom(playerEntity.hand.filter((c) => !c?.entityId && !c?.cardId)) ?? pickRandom(playerEntity.hand);\r\n\t}\r\n\t// Remove the first occurrence of the card from playerEntity.cardsInHand, even if it is null\r\n\tconst index = playerEntity.hand.indexOf(cardToRemove);\r\n\tif (index !== -1) {\r\n\t\tplayerEntity.hand.splice(index, 1);\r\n\t}\r\n};\r\n\r\nexport const grantRandomDivineShield = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => entity.health > 0 && !entity.definitelyDead);\r\n\tif (elligibleEntities.length > 0) {\r\n\t\tconst chosen = elligibleEntities[Math.floor(Math.random() * elligibleEntities.length)];\r\n\t\tupdateDivineShield(chosen, board, true, allCards);\r\n\t\tspectator.registerPowerTarget(source, chosen, board);\r\n\t}\r\n\t// return board;\r\n};\r\n\r\nexport const updateDivineShield = (\r\n\tentity: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tnewValue: boolean,\r\n\tallCards: AllCardsService,\r\n): void => {\r\n\t// if ((entity.divineShield ?? false) === newValue) {\r\n\t// \treturn;\r\n\t// }\r\n\tentity.divineShield = newValue;\r\n\tif (entity.divineShield) {\r\n\t\tentity.hadDivineShield = true;\r\n\t}\r\n\tif (entity.divineShield) {\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043_G).length;\r\n\t\t// Don't trigger all \"on attack changed\" effects, since it's an aura\r\n\t\tentity.attack += statsBonus;\r\n\t} else {\r\n\t\t// Also consider itself\r\n\t\tconst boardForDrake = board;\r\n\t\tconst statsBonus =\r\n\t\t\t8 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043).length +\r\n\t\t\t16 * boardForDrake.filter((e) => e.cardId === CardIds.CyborgDrake_BG25_043_G).length;\r\n\t\tentity.attack -= statsBonus;\r\n\t}\r\n};\r\n\r\nexport const grantAllDivineShield = (board: BoardEntity[], tribe: string, cards: AllCardsService): void => {\r\n\tconst elligibleEntities = board\r\n\t\t.filter((entity) => !entity.divineShield)\r\n\t\t.filter((entity) => isCorrectTribe(cards.getCard(entity.cardId).races, getRaceEnum(tribe)));\r\n\tfor (const entity of elligibleEntities) {\r\n\t\tupdateDivineShield(entity, board, true, cards);\r\n\t}\r\n};\r\n\r\nexport const getRandomAliveMinion = (board: BoardEntity[], race: Race, allCards: AllCardsService): BoardEntity => {\r\n\tconst validTribes = board\r\n\t\t.filter((e) => !race || isCorrectTribe(allCards.getCard(e?.cardId).races, race))\r\n\t\t.filter((e) => !!e?.health && !e.definitelyDead);\r\n\tif (!validTribes.length) {\r\n\t\treturn null;\r\n\t}\r\n\tconst randomIndex = Math.floor(Math.random() * validTribes.length);\r\n\treturn validTribes[randomIndex];\r\n};\r\n\r\nexport const getRandomMinionWithHighestHealth = (board: BoardEntity[]): BoardEntity => {\r\n\tif (!board.length) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst highestHealth = Math.max(...board.map((e) => e.health));\r\n\tconst validMinions = board.filter((e) => e.health === highestHealth);\r\n\treturn validMinions[Math.floor(Math.random() * validMinions.length)];\r\n};\r\n\r\nexport const addStatsToBoard = (\r\n\tsourceEntity: BoardEntity | BgsPlayerEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\ttribe?: string,\r\n): void => {\r\n\tfor (const entity of board) {\r\n\t\tif (!tribe || hasCorrectTribe(entity, Race[tribe], allCards)) {\r\n\t\t\tmodifyAttack(entity, attack, board, allCards);\r\n\t\t\tmodifyHealth(entity, health, board, allCards);\r\n\t\t\tafterStatsUpdate(entity, board, allCards);\r\n\t\t\tspectator?.registerPowerTarget(sourceEntity, entity, board);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const grantStatsToMinionsOfEachType = (\r\n\tsource: BoardEntity,\r\n\tboard: BoardEntity[],\r\n\tattack: number,\r\n\thealth: number,\r\n\tallCards: AllCardsService,\r\n\tspectator: Spectator,\r\n\tnumberOfDifferentTypes = 99,\r\n): void => {\r\n\tif (board.length > 0) {\r\n\t\tlet boardCopy = [...board];\r\n\t\tconst allRaces = shuffleArray(ALL_BG_RACES);\r\n\t\tlet typesBuffed = 0;\r\n\t\tfor (const tribe of allRaces) {\r\n\t\t\tif (typesBuffed >= numberOfDifferentTypes) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst validMinion: BoardEntity = getRandomAliveMinion(boardCopy, tribe, allCards);\r\n\t\t\tif (validMinion) {\r\n\t\t\t\tmodifyAttack(validMinion, attack, board, allCards);\r\n\t\t\t\tmodifyHealth(validMinion, health, board, allCards);\r\n\t\t\t\tafterStatsUpdate(validMinion, board, allCards);\r\n\t\t\t\tspectator.registerPowerTarget(source, validMinion, board);\r\n\t\t\t\tboardCopy = boardCopy.filter((e) => e !== validMinion);\r\n\t\t\t\ttypesBuffed++;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n};\r\n\r\nexport const hasMechanic = (card: ReferenceCard, mechanic: string): boolean => {\r\n\treturn card.mechanics?.includes(mechanic);\r\n};\r\n\r\nexport const hasCorrectTribe = (entity: BoardEntity, targetTribe: Race, allCards: AllCardsService): boolean => {\r\n\treturn isCorrectTribe(allCards.getCard(entity.cardId).races, targetTribe);\r\n};\r\n\r\nexport const isCorrectTribe = (cardRaces: readonly string[], targetTribe: Race): boolean => {\r\n\tif (!cardRaces?.length) {\r\n\t\treturn false;\r\n\t}\r\n\treturn cardRaces\r\n\t\t.map((cardRace) => getRaceEnum(cardRace))\r\n\t\t.some((raceEnum) => raceEnum === Race.ALL || raceEnum === targetTribe);\r\n};\r\n\r\nexport const getRaceEnum = (race: string): Race => {\r\n\treturn Race[race];\r\n};\r\n\r\nexport const addImpliedMechanics = (entity: BoardEntity, cardsData: CardsData): BoardEntity => {\r\n\tconst cleave = CLEAVE_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\tconst cantAttack = CANT_ATTACK_IDS.indexOf(entity.cardId as CardIds) !== -1;\r\n\treturn setImplicitDataForEntity(\r\n\t\t{\r\n\t\t\t...entity,\r\n\t\t\tcleave: cleave,\r\n\t\t\tcantAttack: cantAttack,\r\n\t\t\timmuneWhenAttackCharges:\r\n\t\t\t\tentity.cardId === CardIds.Warpwing_BG24_004 || entity.cardId === CardIds.Warpwing_BG24_004_G\r\n\t\t\t\t\t? 99999\r\n\t\t\t\t\t: 0,\r\n\t\t\tfrenzyChargesLeft:\r\n\t\t\t\tentity.cardId === CardIds.BristlebackKnight_BG20_204_G\r\n\t\t\t\t\t? 2\r\n\t\t\t\t\t: entity.cardId === CardIds.BristlebackKnight_BG20_204\r\n\t\t\t\t\t? 1\r\n\t\t\t\t\t: 0,\r\n\t\t\t// It's not an issue adding a charge for entities without a special ability\r\n\t\t\tabiityChargesLeft: [CardIds.TransmutedBramblewitch_BG27_013_G, CardIds.Mannoroth_BG27_507_G].includes(\r\n\t\t\t\tentity.cardId as CardIds,\r\n\t\t\t)\r\n\t\t\t\t? 2\r\n\t\t\t\t: 1,\r\n\t\t} as BoardEntity,\r\n\t\tcardsData,\r\n\t);\r\n};\r\n\r\nconst setImplicitDataForEntity = (entity: BoardEntity, cardsData: CardsData): BoardEntity => {\r\n\tentity.cardId = normalizeCardIdForSkin(entity.cardId);\r\n\tentity.maxHealth = Math.max(0, entity.health);\r\n\tconst avengeValue = cardsData.avengeValue(entity.cardId);\r\n\tif (avengeValue > 0) {\r\n\t\tentity.avengeCurrent = avengeValue;\r\n\t\tentity.avengeDefault = avengeValue;\r\n\t}\r\n\treturn entity;\r\n};\r\n\r\nexport const normalizeCardIdForSkin = (cardId: string): string => {\r\n\tif (!cardId?.length) {\r\n\t\treturn cardId;\r\n\t}\r\n\tconst skinMatch = cardId.match(/(.*)_SKIN_.*/);\r\n\tif (skinMatch) {\r\n\t\treturn skinMatch[1];\r\n\t}\r\n\treturn cardId;\r\n};\r\n\r\nexport const stringifySimple = (board: readonly BoardEntity[], allCards: AllCardsService = null): string => {\r\n\treturn '[' + board.map((entity) => stringifySimpleCard(entity, allCards)).join(', ') + ']';\r\n};\r\n\r\nexport const stringifySimpleCard = (entity: BoardEntity, allCards: AllCardsService = null): string => {\r\n\treturn entity\r\n\t\t? `${entity.cardId}/${allCards?.getCard(entity.cardId)?.name ?? ''}/atk=${entity.attack}/hp=${\r\n\t\t\t\tentity.health\r\n\t\t }/ds=${entity.divineShield}`\r\n\t\t: null;\r\n};\r\n\r\nexport const isFish = (entity: BoardEntity): boolean => {\r\n\treturn (\r\n\t\tentity.cardId.startsWith(CardIds.AvatarOfNzoth_FishOfNzothToken) ||\r\n\t\tentity.cardId.startsWith(CardIds.FishOfNzoth) ||\r\n\t\tentity.additionalCards?.includes(CardIds.DevourerOfSouls_BG_RLK_538)\r\n\t);\r\n};\r\n\r\nexport const isGolden = (cardId: string, allCards: AllCardsService): boolean => {\r\n\treturn !!allCards.getCard(cardId).battlegroundsNormalDbfId;\r\n};\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firestone-hs/simulate-bgs-battle",
3
- "version": "1.1.313",
3
+ "version": "1.1.315",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "lint": "eslint --color --fix --ext .ts .",