@firestone-hs/simulate-bgs-battle 1.1.151 → 1.1.152

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.
Files changed (34) hide show
  1. package/dist/bgs-player-entity.d.ts +3 -0
  2. package/dist/bgs-player-entity.js.map +1 -1
  3. package/dist/cards/cards-data.d.ts +5 -3
  4. package/dist/cards/cards-data.js +22 -20
  5. package/dist/cards/cards-data.js.map +1 -1
  6. package/dist/services/utils.d.ts +4 -0
  7. package/dist/services/utils.js +29 -1
  8. package/dist/services/utils.js.map +1 -1
  9. package/dist/simulate-bgs-battle.js +2 -0
  10. package/dist/simulate-bgs-battle.js.map +1 -1
  11. package/dist/simulation/attack.d.ts +1 -0
  12. package/dist/simulation/attack.js +35 -26
  13. package/dist/simulation/attack.js.map +1 -1
  14. package/dist/simulation/auras.d.ts +2 -0
  15. package/dist/simulation/auras.js +13 -4
  16. package/dist/simulation/auras.js.map +1 -1
  17. package/dist/simulation/avenge.d.ts +7 -0
  18. package/dist/simulation/avenge.js +162 -0
  19. package/dist/simulation/avenge.js.map +1 -0
  20. package/dist/simulation/deathrattle-effects.d.ts +1 -3
  21. package/dist/simulation/deathrattle-effects.js +27 -248
  22. package/dist/simulation/deathrattle-effects.js.map +1 -1
  23. package/dist/simulation/deathrattle-spawns.js +23 -9
  24. package/dist/simulation/deathrattle-spawns.js.map +1 -1
  25. package/dist/simulation/frenzy.js +2 -2
  26. package/dist/simulation/frenzy.js.map +1 -1
  27. package/dist/simulation/spectator/spectator.d.ts +2 -1
  28. package/dist/simulation/spectator/spectator.js.map +1 -1
  29. package/dist/simulation/start-of-combat.js +6 -10
  30. package/dist/simulation/start-of-combat.js.map +1 -1
  31. package/dist/utils.d.ts +9 -4
  32. package/dist/utils.js +103 -30
  33. package/dist/utils.js.map +1 -1
  34. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  export interface BgsPlayerEntity {
2
+ readonly entityId: number;
2
3
  readonly cardId: string;
3
4
  readonly nonGhostCardId?: string;
4
5
  readonly hpLeft: number;
@@ -7,5 +8,7 @@ export interface BgsPlayerEntity {
7
8
  readonly heroPowerUsed: boolean;
8
9
  readonly heroPowerInfo?: number;
9
10
  cardsInHand?: number;
11
+ avengeCurrent?: number;
12
+ avengeDefault?: number;
10
13
  deadEyeDamageDone?: number;
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bgs-player-entity.js","sourceRoot":"","sources":["../src/bgs-player-entity.ts"],"names":[],"mappings":"","sourcesContent":["export interface BgsPlayerEntity {\r\n\treadonly cardId: string;\r\n\treadonly nonGhostCardId?: string;\r\n\treadonly hpLeft: number;\r\n\treadonly tavernTier: number;\r\n\treadonly heroPowerId: string;\r\n\treadonly heroPowerUsed: boolean;\r\n\treadonly heroPowerInfo?: number;\r\n\tcardsInHand?: number;\r\n\r\n\tdeadEyeDamageDone?: number;\r\n}\r\n"]}
1
+ {"version":3,"file":"bgs-player-entity.js","sourceRoot":"","sources":["../src/bgs-player-entity.ts"],"names":[],"mappings":"","sourcesContent":["export interface BgsPlayerEntity {\r\n\treadonly entityId: number;\r\n\treadonly cardId: string;\r\n\treadonly nonGhostCardId?: string;\r\n\treadonly hpLeft: number;\r\n\treadonly tavernTier: number;\r\n\treadonly heroPowerId: string;\r\n\treadonly heroPowerUsed: boolean;\r\n\treadonly heroPowerInfo?: number;\r\n\tcardsInHand?: number;\r\n\tavengeCurrent?: number;\r\n\tavengeDefault?: number;\r\n\r\n\tdeadEyeDamageDone?: number;\r\n}\r\n"]}
@@ -1,4 +1,8 @@
1
- import { AllCardsService, Race } from '@firestone-hs/reference-data';
1
+ import { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data';
2
+ export declare const AURA_ENCHANTMENTS: readonly string[][];
3
+ export declare const AURA_ORIGINS: readonly string[];
4
+ export declare const START_OF_COMBAT_CARD_IDS: CardIds[];
5
+ export declare const WHELP_CARD_IDS: CardIds[];
2
6
  export declare class CardsData {
3
7
  private readonly allCards;
4
8
  ghastcoilerSpawns: readonly string[];
@@ -8,9 +12,7 @@ export declare class CardsData {
8
12
  kilrekSpawns: readonly string[];
9
13
  brannEpicEggSpawns: readonly string[];
10
14
  pirateSpawns: readonly string[];
11
- auraEnchantments: readonly string[][];
12
15
  auraOrigins: readonly string[];
13
- startOfCombats: readonly string[];
14
16
  private minionsForTier;
15
17
  constructor(allCards: AllCardsService, init?: boolean);
16
18
  inititialize(validTribes?: readonly Race[]): void;
@@ -1,9 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CardsData = void 0;
3
+ exports.CardsData = exports.WHELP_CARD_IDS = exports.START_OF_COMBAT_CARD_IDS = exports.AURA_ORIGINS = exports.AURA_ENCHANTMENTS = void 0;
4
4
  const reference_data_1 = require("@firestone-hs/reference-data");
5
5
  const utils_1 = require("../services/utils");
6
6
  const utils_2 = require("../utils");
7
+ exports.AURA_ENCHANTMENTS = [
8
+ ["BG21_039", "BG21_039e"],
9
+ ["BG21_039_G", "BG21_039_Ge"],
10
+ ["EX1_507", "EX1_507e"],
11
+ ["TB_BaconUps_008", "TB_BaconUps_008e"],
12
+ ["NEW1_027", "NEW1_027e"],
13
+ ["TB_BaconUps_136", "TB_BaconUps_136e"],
14
+ ["TB_BaconShop_HERO_52_Buddy", "TB_BaconShop_HERO_52_Buddy_e"],
15
+ ["TB_BaconShop_HERO_52_Buddy_G", "TB_BaconShop_HERO_52_Buddy_G_e"],
16
+ ];
17
+ exports.AURA_ORIGINS = exports.AURA_ENCHANTMENTS.map((pair) => pair[0]);
18
+ exports.START_OF_COMBAT_CARD_IDS = [
19
+ "BGS_019",
20
+ "TB_BaconUps_102",
21
+ "BG21_014",
22
+ "BG21_014_G",
23
+ "BG22_HERO_000_Buddy",
24
+ "BG22_HERO_000_Buddy_G",
25
+ ];
26
+ exports.WHELP_CARD_IDS = ["BGS_019", "TB_BaconUps_102", "BG22_HERO_305t"];
7
27
  class CardsData {
8
28
  constructor(allCards, init = true) {
9
29
  this.allCards = allCards;
@@ -51,25 +71,6 @@ class CardsData {
51
71
  .filter((card) => !this.isGolden(card))
52
72
  .filter((card) => card.race === 'PIRATE')
53
73
  .map((card) => card.id);
54
- this.auraEnchantments = [
55
- ["BG21_039", "BG21_039e"],
56
- ["BG21_039_G", "BG21_039_Ge"],
57
- ["EX1_507", "EX1_507e"],
58
- ["TB_BaconUps_008", "TB_BaconUps_008e"],
59
- ["NEW1_027", "NEW1_027e"],
60
- ["TB_BaconUps_136", "TB_BaconUps_136e"],
61
- ["TB_BaconShop_HERO_52_Buddy", "TB_BaconShop_HERO_52_Buddy_e"],
62
- ["TB_BaconShop_HERO_52_Buddy_G", "TB_BaconShop_HERO_52_Buddy_G_e"],
63
- ];
64
- this.auraOrigins = this.auraEnchantments.map((pair) => pair[0]);
65
- this.startOfCombats = [
66
- "BGS_019",
67
- "TB_BaconUps_102",
68
- "BG21_014",
69
- "BG21_014_G",
70
- "BG22_HERO_000_Buddy",
71
- "BG22_HERO_000_Buddy_G",
72
- ];
73
74
  }
74
75
  avengeValue(cardId) {
75
76
  switch (cardId) {
@@ -96,6 +97,7 @@ class CardsData {
96
97
  case "BG21_038_G":
97
98
  case "BG21_031":
98
99
  case "BG21_031_G":
100
+ case "BG22_HERO_305p":
99
101
  return 4;
100
102
  }
101
103
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"cards-data.js","sourceRoot":"","sources":["../../src/cards/cards-data.ts"],"names":[],"mappings":";;;AAAA,iEAAkH;AAClH,6CAAgE;AAChE,oCAAoD;AAEpD,MAAa,SAAS;IAkBrB,YAA6B,QAAyB,EAAE,IAAI,GAAG,IAAI;QAAtC,aAAQ,GAAR,QAAQ,CAAiB;QACrD,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,YAAY,EAAE,CAAC;SACpB;IACF,CAAC;IAEM,YAAY,CAAC,WAA6B;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ;aACxB,QAAQ,EAAE;aACV,M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BAAqB;YACrB;gBACC,OAAO,CAAC,CAAC;YACV,gBAAgC;YAChC,kBAA6C;YAC7C,gBAAiC;YACjC,kBAA8C;YAC9C,gBAAyB;YACzB;gBACC,OAAO,CAAC,CAAC;SACV;QACD,OAAO,CAAC,CAAC;IACV,CAAC;IAEM,cAAc,CAAC,MAAc;QACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC;IAChD,CAAC;IAEM,4BAA4B,CAAC,UAAkB;QAIrD,OAAO,kBAAU,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,CAAC;IAEO,QAAQ,CAAC,IAAmB;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC;IACxC,CAAC;IAEO,YAAY,CAAC,WAA4B,EAAE,IAAY;QAC9D,MAAM,QAAQ,GAAS,mBAAW,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,QAAQ,KAAK,qBAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5G,CAAC;CACD;AAhJD,8BAgJC","sourcesContent":["import { AllCardsService, CardIds, isBattlegroundsCard, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { getRaceEnum, hasMechanic } from '../utils';\r\n\r\nexport class CardsData {\r\n\t// public shredderSpawns: readonly string[];\r\n\tpublic ghastcoilerSpawns: readonly string[];\r\n\tpublic validDeathrattles: readonly string[];\r\n\tpublic impMamaSpawns: readonly string[];\r\n\tpublic gentleDjinniSpawns: readonly string[];\r\n\tpublic kilrekSpawns: readonly string[];\r\n\tpublic brannEpicEggSpawns: readonly string[];\r\n\t// public sneedsSpawns: readonly string[];\r\n\t// public treasureChestSpawns: readonly string[];\r\n\tpublic pirateSpawns: readonly string[];\r\n\r\n\tpublic auraEnchantments: readonly string[][];\r\n\tpublic auraOrigins: readonly string[];\r\n\tpublic startOfCombats: readonly string[];\r\n\r\n\tprivate minionsForTier: { [key: string]: readonly ReferenceCard[] };\r\n\r\n\tconstructor(private readonly allCards: AllCardsService, init = true) {\r\n\t\tif (init) {\r\n\t\t\tthis.inititialize();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic inititialize(validTribes?: readonly Race[]): void {\r\n\t\tconst pool = this.allCards\r\n\t\t\t.getCards()\r\n\t\t\t.filter((card) => isBattlegroundsCard(card))\r\n\t\t\t.filter((card) => !!card.techLevel)\r\n\t\t\t.filter((card) => card.set !== 'Vanilla');\r\n\t\tthis.minionsForTier = groupByFunction((card: ReferenceCard) => card.techLevel)(pool.filter((card) => !this.isGolden(card)));\r\n\t\tthis.ghastcoilerSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.id !== 'BGS_008')\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.validDeathrattles = pool\r\n\t\t\t// .filter((card) => !card.id.startsWith('TB_BaconUps')) // Ignore golden\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.impMamaSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'DEMON')\r\n\t\t\t.filter((card) => card.id !== CardIds.ImpMama)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.gentleDjinniSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'ELEMENTAL')\r\n\t\t\t.filter((card) => card.id !== CardIds.GentleDjinni)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.kilrekSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === Race[Race.DEMON])\r\n\t\t\t.filter((card) => card.id !== CardIds.KilrekBattlegrounds1)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.brannEpicEggSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => hasMechanic(card, 'BATTLECRY'))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.pirateSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'PIRATE')\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\t// Auras are effects that are permanent (unlike deathrattles or \"whenever\" effects)\r\n\t\t// and that stop once the origin entity leaves play (so it doesn't include buffs)\r\n\t\tthis.auraEnchantments = [\r\n\t\t\t[CardIds.Kathranatir2, CardIds.Kathranatir_GraspOfKathranatirEnchantment1],\r\n\t\t\t[CardIds.KathranatirBattlegrounds, CardIds.Kathranatir_GraspOfKathranatirEnchantment2],\r\n\t\t\t[CardIds.MurlocWarleaderLegacy, CardIds.MurlocWarleader_MrgglaarglLegacyEnchantment],\r\n\t\t\t[CardIds.MurlocWarleaderBattlegrounds, CardIds.MurlocWarleader_MrgglaarglEnchantmentBattlegrounds],\r\n\t\t\t[CardIds.SouthseaCaptainLegacy, CardIds.SouthseaCaptain_YarrrLegacyEnchantment],\r\n\t\t\t[CardIds.SouthseaCaptainBattlegrounds, CardIds.SouthseaCaptain_YarrrEnchantmentBattlegrounds],\r\n\t\t\t// TODO find proper enchantment\r\n\t\t\t[CardIds.LadySinestraBattlegrounds1, CardIds.DraconicBlessingEnchantmentBattlegrounds1],\r\n\t\t\t[CardIds.LadySinestraBattlegrounds2, CardIds.DraconicBlessingEnchantmentBattlegrounds2],\r\n\t\t];\r\n\t\tthis.auraOrigins = this.auraEnchantments.map((pair) => pair[0]);\r\n\t\tthis.startOfCombats = [\r\n\t\t\tCardIds.RedWhelp,\r\n\t\t\tCardIds.RedWhelpBattlegrounds,\r\n\t\t\tCardIds.PrizedPromoDrake,\r\n\t\t\tCardIds.PrizedPromoDrakeBattlegrounds,\r\n\t\t\tCardIds.Crabby1,\r\n\t\t\tCardIds.CrabbyBattlegrounds,\r\n\t\t];\r\n\t}\r\n\r\n\tpublic avengeValue(cardId: string): number {\r\n\t\tswitch (cardId) {\r\n\t\t\tcase CardIds.BirdBuddy:\r\n\t\t\tcase CardIds.BirdBuddyBattlegrounds:\r\n\t\t\t\treturn 1;\r\n\t\t\tcase CardIds.FrostwolfLieutenant:\r\n\t\t\tcase CardIds.FrostwolfLieutenantBattlegrounds:\r\n\t\t\tcase CardIds.MechanoTank:\r\n\t\t\tcase CardIds.MechanoTankBattlegrounds:\r\n\t\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tcase CardIds.StormpikeLieutenant:\r\n\t\t\tcase CardIds.StormpikeLieutenantBattlegrounds:\r\n\t\t\t\treturn 2;\r\n\t\t\tcase CardIds.BuddingGreenthumb:\r\n\t\t\tcase CardIds.BuddingGreenthumbBattlegrounds:\r\n\t\t\tcase CardIds.Sisefin:\r\n\t\t\tcase CardIds.SisefinBattlegrounds:\r\n\t\t\t\treturn 3;\r\n\t\t\tcase CardIds.ImpatientDoomsayer:\r\n\t\t\tcase CardIds.ImpatientDoomsayerBattlegrounds:\r\n\t\t\tcase CardIds.WitchwingNestmatron:\r\n\t\t\tcase CardIds.WitchwingNestmatronBattlegrounds:\r\n\t\t\tcase CardIds.TonyTwoTusk:\r\n\t\t\tcase CardIds.TonyTwoTuskBattlegrounds:\r\n\t\t\t\treturn 4;\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic getTavernLevel(cardId: string): number {\r\n\t\treturn this.allCards.getCard(cardId).techLevel;\r\n\t}\r\n\r\n\tpublic getRandomMinionForTavernTier(tavernTier: number): string {\r\n\t\t// Tzvern tier can be undefined for hero-power specific tokens, like the Amalgam, or when\r\n\t\t// for some reason tokens end up in the shop. For now, defaulting to 1 for tavern\r\n\t\t// level seems to work in all cases\r\n\t\treturn pickRandom(this.minionsForTier[tavernTier ?? 1]).id;\r\n\t}\r\n\r\n\tprivate isGolden(card: ReferenceCard): boolean {\r\n\t\treturn !!card.battlegroundsNormalDbfId;\r\n\t}\r\n\r\n\tprivate isValidTribe(validTribes: readonly Race[], race: string): boolean {\r\n\t\tconst raceEnum: Race = getRaceEnum(race);\r\n\t\treturn raceEnum === Race.ALL || !validTribes || validTribes.length === 0 || validTribes.includes(raceEnum);\r\n\t}\r\n}\r\n"]}
1
+ {"version":3,"file":"cards-data.js","sourceRoot":"","sources":["../../src/cards/cards-data.ts"],"names":[],"mappings":";;;AAAA,iEAAkH;AAClH,6CAAgE;AAChE,oCAAoD;AAEvC,QAAA,iBAAiB,GAAwB;IACrD,yBAA0E;IAC1E,6BAAsF;IACtF,uBAAoF;IACpF,uCAAkG;IAClG,yBAA+E;IAC/E,uCAA6F;IAC7F,8DAAuF;IACvF,kEAAuF;CACvF,CAAC;AAGW,QAAA,YAAY,GAAsB,yBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,QAAA,wBAAwB,GAAG;;;;;;;CAOvC,CAAC;AACW,QAA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YAChC,kBAA6C;YAC7C,gBAAiC;YACjC,kBAA8C;YAC9C,gBAAyB;YACzB,kBAAsC;YACtC;gBACC,OAAO,CAAC,CAAC;SACV;QACD,OAAO,CAAC,CAAC;IACV,CAAC;IAEM,cAAc,CAAC,MAAc;QACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC;IAChD,CAAC;IAEM,4BAA4B,CAAC,UAAkB;QAIrD,OAAO,kBAAU,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,CAAC;IAEO,QAAQ,CAAC,IAAmB;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC;IACxC,CAAC;IAEO,YAAY,CAAC,WAA4B,EAAE,IAAY;QAC9D,MAAM,QAAQ,GAAS,mBAAW,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,QAAQ,KAAK,qBAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5G,CAAC;CACD;AAxHD,8BAwHC","sourcesContent":["import { AllCardsService, CardIds, isBattlegroundsCard, Race, ReferenceCard } from '@firestone-hs/reference-data';\r\nimport { groupByFunction, pickRandom } from '../services/utils';\r\nimport { getRaceEnum, hasMechanic } from '../utils';\r\n\r\nexport const AURA_ENCHANTMENTS: readonly string[][] = [\r\n\t[CardIds.Kathranatir2, CardIds.Kathranatir_GraspOfKathranatirEnchantment1],\r\n\t[CardIds.KathranatirBattlegrounds, CardIds.Kathranatir_GraspOfKathranatirEnchantment2],\r\n\t[CardIds.MurlocWarleaderLegacy, CardIds.MurlocWarleader_MrgglaarglLegacyEnchantment],\r\n\t[CardIds.MurlocWarleaderBattlegrounds, CardIds.MurlocWarleader_MrgglaarglEnchantmentBattlegrounds],\r\n\t[CardIds.SouthseaCaptainLegacy, CardIds.SouthseaCaptain_YarrrLegacyEnchantment],\r\n\t[CardIds.SouthseaCaptainBattlegrounds, CardIds.SouthseaCaptain_YarrrEnchantmentBattlegrounds],\r\n\t[CardIds.LadySinestraBattlegrounds1, CardIds.DraconicBlessingEnchantmentBattlegrounds1],\r\n\t[CardIds.LadySinestraBattlegrounds2, CardIds.DraconicBlessingEnchantmentBattlegrounds2],\r\n];\r\n// Auras are effects that are permanent (unlike deathrattles or \"whenever\" effects)\r\n// and that stop once the origin entity leaves play (so it doesn't include buffs)\r\nexport const AURA_ORIGINS: readonly string[] = AURA_ENCHANTMENTS.map((pair) => pair[0]);\r\nexport const START_OF_COMBAT_CARD_IDS = [\r\n\tCardIds.RedWhelp,\r\n\tCardIds.RedWhelpBattlegrounds,\r\n\tCardIds.PrizedPromoDrake,\r\n\tCardIds.PrizedPromoDrakeBattlegrounds,\r\n\tCardIds.Crabby1,\r\n\tCardIds.CrabbyBattlegrounds,\r\n];\r\nexport const WHELP_CARD_IDS = [CardIds.RedWhelp, CardIds.RedWhelpBattlegrounds, CardIds.Onyxia_OnyxianWhelpToken];\r\n\r\nexport class CardsData {\r\n\t// public shredderSpawns: readonly string[];\r\n\tpublic ghastcoilerSpawns: readonly string[];\r\n\tpublic validDeathrattles: readonly string[];\r\n\tpublic impMamaSpawns: readonly string[];\r\n\tpublic gentleDjinniSpawns: readonly string[];\r\n\tpublic kilrekSpawns: readonly string[];\r\n\tpublic brannEpicEggSpawns: readonly string[];\r\n\t// public sneedsSpawns: readonly string[];\r\n\t// public treasureChestSpawns: readonly string[];\r\n\tpublic pirateSpawns: readonly string[];\r\n\tpublic auraOrigins: readonly string[];\r\n\r\n\tprivate minionsForTier: { [key: string]: readonly ReferenceCard[] };\r\n\r\n\tconstructor(private readonly allCards: AllCardsService, init = true) {\r\n\t\tif (init) {\r\n\t\t\tthis.inititialize();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic inititialize(validTribes?: readonly Race[]): void {\r\n\t\tconst pool = this.allCards\r\n\t\t\t.getCards()\r\n\t\t\t.filter((card) => isBattlegroundsCard(card))\r\n\t\t\t.filter((card) => !!card.techLevel)\r\n\t\t\t.filter((card) => card.set !== 'Vanilla');\r\n\t\tthis.minionsForTier = groupByFunction((card: ReferenceCard) => card.techLevel)(pool.filter((card) => !this.isGolden(card)));\r\n\t\tthis.ghastcoilerSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.id !== 'BGS_008')\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.validDeathrattles = pool\r\n\t\t\t// .filter((card) => !card.id.startsWith('TB_BaconUps')) // Ignore golden\r\n\t\t\t.filter((card) => hasMechanic(card, 'DEATHRATTLE'))\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.filter((card) => this.isValidTribe(validTribes, card.race))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.impMamaSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'DEMON')\r\n\t\t\t.filter((card) => card.id !== CardIds.ImpMama)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.gentleDjinniSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'ELEMENTAL')\r\n\t\t\t.filter((card) => card.id !== CardIds.GentleDjinni)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.kilrekSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === Race[Race.DEMON])\r\n\t\t\t.filter((card) => card.id !== CardIds.KilrekBattlegrounds1)\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.brannEpicEggSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => hasMechanic(card, 'BATTLECRY'))\r\n\t\t\t.map((card) => card.id);\r\n\t\tthis.pirateSpawns = pool\r\n\t\t\t.filter((card) => !this.isGolden(card))\r\n\t\t\t.filter((card) => card.race === 'PIRATE')\r\n\t\t\t// .filter((card) => REMOVED_CARD_IDS.indexOf(card.id) === -1)\r\n\t\t\t.map((card) => card.id);\r\n\t}\r\n\r\n\tpublic avengeValue(cardId: string): number {\r\n\t\tswitch (cardId) {\r\n\t\t\tcase CardIds.BirdBuddy:\r\n\t\t\tcase CardIds.BirdBuddyBattlegrounds:\r\n\t\t\t\treturn 1;\r\n\t\t\tcase CardIds.FrostwolfLieutenant:\r\n\t\t\tcase CardIds.FrostwolfLieutenantBattlegrounds:\r\n\t\t\tcase CardIds.MechanoTank:\r\n\t\t\tcase CardIds.MechanoTankBattlegrounds:\r\n\t\t\tcase CardIds.PalescaleCrocolisk:\r\n\t\t\tcase CardIds.PalescaleCrocoliskBattlegrounds:\r\n\t\t\tcase CardIds.StormpikeLieutenant:\r\n\t\t\tcase CardIds.StormpikeLieutenantBattlegrounds:\r\n\t\t\t\treturn 2;\r\n\t\t\tcase CardIds.BuddingGreenthumb:\r\n\t\t\tcase CardIds.BuddingGreenthumbBattlegrounds:\r\n\t\t\tcase CardIds.Sisefin:\r\n\t\t\tcase CardIds.SisefinBattlegrounds:\r\n\t\t\t\treturn 3;\r\n\t\t\tcase CardIds.ImpatientDoomsayer:\r\n\t\t\tcase CardIds.ImpatientDoomsayerBattlegrounds:\r\n\t\t\tcase CardIds.WitchwingNestmatron:\r\n\t\t\tcase CardIds.WitchwingNestmatronBattlegrounds:\r\n\t\t\tcase CardIds.TonyTwoTusk:\r\n\t\t\tcase CardIds.TonyTwoTuskBattlegrounds:\r\n\t\t\tcase CardIds.Onyxia_Broodmother:\r\n\t\t\t\treturn 4;\r\n\t\t}\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic getTavernLevel(cardId: string): number {\r\n\t\treturn this.allCards.getCard(cardId).techLevel;\r\n\t}\r\n\r\n\tpublic getRandomMinionForTavernTier(tavernTier: number): string {\r\n\t\t// Tzvern tier can be undefined for hero-power specific tokens, like the Amalgam, or when\r\n\t\t// for some reason tokens end up in the shop. For now, defaulting to 1 for tavern\r\n\t\t// level seems to work in all cases\r\n\t\treturn pickRandom(this.minionsForTier[tavernTier ?? 1]).id;\r\n\t}\r\n\r\n\tprivate isGolden(card: ReferenceCard): boolean {\r\n\t\treturn !!card.battlegroundsNormalDbfId;\r\n\t}\r\n\r\n\tprivate isValidTribe(validTribes: readonly Race[], race: string): boolean {\r\n\t\tconst raceEnum: Race = getRaceEnum(race);\r\n\t\treturn raceEnum === Race.ALL || !validTribes || validTribes.length === 0 || validTribes.includes(raceEnum);\r\n\t}\r\n}\r\n"]}
@@ -7,3 +7,7 @@ export declare const groupByFunction: <T>(keyExtractor: (obj: T) => string | num
7
7
  };
8
8
  export { partitionArray, http, sleep };
9
9
  export declare const pickRandom: <T>(array: readonly T[]) => T;
10
+ export declare const encode: (input: string) => string;
11
+ export declare const decode: (base64: string) => string;
12
+ export declare const pickMultipleRandomDifferent: <T>(list: T[], n: number) => T[];
13
+ export declare const shuffleArray: <T>(array: T[]) => T[];
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.pickRandom = exports.sleep = exports.http = exports.partitionArray = exports.groupByFunction = void 0;
15
+ exports.shuffleArray = exports.pickMultipleRandomDifferent = exports.decode = exports.encode = exports.pickRandom = exports.sleep = exports.http = exports.partitionArray = exports.groupByFunction = void 0;
16
16
  const node_fetch_1 = __importDefault(require("node-fetch"));
17
17
  function partitionArray(array, partitionSize) {
18
18
  const workingCopy = [...array];
@@ -60,4 +60,32 @@ const pickRandom = (array) => {
60
60
  return array[Math.floor(Math.random() * array.length)];
61
61
  };
62
62
  exports.pickRandom = pickRandom;
63
+ const encode = (input) => {
64
+ const buff = Buffer.from(input, 'utf-8');
65
+ const base64 = buff.toString('base64');
66
+ return base64;
67
+ };
68
+ exports.encode = encode;
69
+ const decode = (base64) => {
70
+ const buff = Buffer.from(base64, 'base64');
71
+ const str = buff.toString('utf-8');
72
+ return str;
73
+ };
74
+ exports.decode = decode;
75
+ const pickMultipleRandomDifferent = (list, n) => {
76
+ const shuffled = exports.shuffleArray([...list]);
77
+ return shuffled.slice(0, n);
78
+ };
79
+ exports.pickMultipleRandomDifferent = pickMultipleRandomDifferent;
80
+ const shuffleArray = (array) => {
81
+ let currentIndex = array.length;
82
+ let randomIndex = 0;
83
+ while (currentIndex != 0) {
84
+ randomIndex = Math.floor(Math.random() * currentIndex);
85
+ currentIndex--;
86
+ [array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
87
+ }
88
+ return array;
89
+ };
90
+ exports.shuffleArray = shuffleArray;
63
91
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/services/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4DAAgD;AAEhD,SAAS,cAAc,CAAI,KAAmB,EAAE,aAAqB;IACpE,MAAM,WAAW,GAAQ,CAAC,GAAG,KAAK,CAAC,CAAC;IACpC,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,OAAO,WAAW,CAAC,MAAM,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;KAClD;I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L,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAA,EAAE;QACnB,OAAO,IAAI,CAAC;KACZ;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AALW,QAAA,UAAU,cAKrB","sourcesContent":["import fetch, { RequestInfo } from 'node-fetch';\r\n\r\nfunction partitionArray<T>(array: readonly T[], partitionSize: number): readonly T[][] {\r\n\tconst workingCopy: T[] = [...array];\r\n\tconst result: T[][] = [];\r\n\twhile (workingCopy.length) {\r\n\t\tresult.push(workingCopy.splice(0, partitionSize));\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nasync function http(request: RequestInfo): Promise<any> {\r\n\treturn new Promise((resolve) => {\r\n\t\tfetch(request)\r\n\t\t\t.then(\r\n\t\t\t\t(response) => {\r\n\t\t\t\t\treturn response.text();\r\n\t\t\t\t},\r\n\t\t\t\t(error) => {\r\n\t\t\t\t\tconsole.warn('could not retrieve review', error);\r\n\t\t\t\t},\r\n\t\t\t)\r\n\t\t\t.then((body) => {\r\n\t\t\t\tresolve(body);\r\n\t\t\t});\r\n\t});\r\n}\r\n\r\nasync function sleep(ms) {\r\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\r\n}\r\n\r\nexport const groupByFunction = <T>(keyExtractor: (obj: T) => string | number) => (array: readonly T[]): { [key: string]: readonly T[] } => {\r\n\treturn array.reduce((objectsByKeyValue, obj) => {\r\n\t\tconst value = keyExtractor(obj);\r\n\t\tobjectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);\r\n\t\treturn objectsByKeyValue;\r\n\t}, {});\r\n};\r\n\r\nexport { partitionArray, http, sleep };\r\n\r\nexport const pickRandom = <T>(array: readonly T[]): T => {\r\n\tif (!array?.length) {\r\n\t\treturn null;\r\n\t}\r\n\treturn array[Math.floor(Math.random() * array.length)];\r\n};\r\n"]}
1
+ {"version":3,"file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CAAC,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC,CAAC;AAHW,QAAA,2BAA2B,+BAGtC;AAGK,MAAM,YAAY,GAAG,CAAI,KAAU,EAAO,EAAE;IAClD,IAAI,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC;IAChC,IAAI,WAAW,GAAG,CAAC,CAAC;IAGpB,OAAO,YAAY,IAAI,CAAC,EAAE;QAEzB,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC;QACvD,YAAY,EAAE,CAAC;QAGf,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;KACtF;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB","sourcesContent":["import fetch, { RequestInfo } from 'node-fetch';\r\n\r\nfunction partitionArray<T>(array: readonly T[], partitionSize: number): readonly T[][] {\r\n\tconst workingCopy: T[] = [...array];\r\n\tconst result: T[][] = [];\r\n\twhile (workingCopy.length) {\r\n\t\tresult.push(workingCopy.splice(0, partitionSize));\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nasync function http(request: RequestInfo): Promise<any> {\r\n\treturn new Promise((resolve) => {\r\n\t\tfetch(request)\r\n\t\t\t.then(\r\n\t\t\t\t(response) => {\r\n\t\t\t\t\treturn response.text();\r\n\t\t\t\t},\r\n\t\t\t\t(error) => {\r\n\t\t\t\t\tconsole.warn('could not retrieve review', error);\r\n\t\t\t\t},\r\n\t\t\t)\r\n\t\t\t.then((body) => {\r\n\t\t\t\tresolve(body);\r\n\t\t\t});\r\n\t});\r\n}\r\n\r\nasync function sleep(ms) {\r\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\r\n}\r\n\r\nexport const groupByFunction = <T>(keyExtractor: (obj: T) => string | number) => (array: readonly T[]): { [key: string]: readonly T[] } => {\r\n\treturn array.reduce((objectsByKeyValue, obj) => {\r\n\t\tconst value = keyExtractor(obj);\r\n\t\tobjectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);\r\n\t\treturn objectsByKeyValue;\r\n\t}, {});\r\n};\r\n\r\nexport { partitionArray, http, sleep };\r\n\r\nexport const pickRandom = <T>(array: readonly T[]): T => {\r\n\tif (!array?.length) {\r\n\t\treturn null;\r\n\t}\r\n\treturn array[Math.floor(Math.random() * array.length)];\r\n};\r\n\r\nexport const encode = (input: string): string => {\r\n\t// return compressToEncodedURIComponent(input);\r\n\tconst buff = Buffer.from(input, 'utf-8');\r\n\tconst base64 = buff.toString('base64');\r\n\treturn base64;\r\n};\r\n\r\nexport const decode = (base64: string): string => {\r\n\tconst buff = Buffer.from(base64, 'base64');\r\n\tconst str = buff.toString('utf-8');\r\n\treturn str;\r\n};\r\n\r\nexport const pickMultipleRandomDifferent = <T>(list: T[], n: number): T[] => {\r\n\tconst shuffled = shuffleArray([...list]);\r\n\treturn shuffled.slice(0, n);\r\n};\r\n\r\n// https://stackoverflow.com/a/2450976/548701\r\nexport const shuffleArray = <T>(array: T[]): T[] => {\r\n\tlet currentIndex = array.length;\r\n\tlet randomIndex = 0;\r\n\r\n\t// While there remain elements to shuffle...\r\n\twhile (currentIndex != 0) {\r\n\t\t// Pick a remaining element...\r\n\t\trandomIndex = Math.floor(Math.random() * currentIndex);\r\n\t\tcurrentIndex--;\r\n\r\n\t\t// And swap it with the current element.\r\n\t\t[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];\r\n\t}\r\n\r\n\treturn array;\r\n};\r\n"]}
@@ -60,6 +60,8 @@ const simulateBattle = (battleInput, cards, cardsData) => {
60
60
  auras_1.removeAuras(opponentBoard, cardsData);
61
61
  auras_1.setImplicitData(playerBoard, cardsData);
62
62
  auras_1.setImplicitData(opponentBoard, cardsData);
63
+ auras_1.setImplicitDataHero(playerInfo.player, cardsData);
64
+ auras_1.setImplicitDataHero(opponentInfo.player, cardsData);
63
65
  const inputReady = {
64
66
  playerBoard: {
65
67
  board: playerBoard,
@@ -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,8CAAkE;AAClE,sDAAmD;AACnD,gEAA6D;AAC7D,mCAA8C;AAE9C,MAAM,KAAK,GAAG,IAAI,gCAAe,EAAE,CAAC;AAKpC,kBAAe,CAAO,KAAK,EAAgB,EAAE;;IAC5C,MAAM,WAAW,GAAkB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,SAAS,CAAC,YAAY,aAAC,WAAW,CAAC,SAAS,0CAAE,WAAW,yCAAI,WAAW,CAAC,OAAO,0CAAE,WAAW,CAAC,CAAC;IAC/F,MAAM,gBAAgB,GAAG,sBAAc,CAAC,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,CAAA,CAAC;AAEK,MAAM,cAAc,GAAG,CAAC,WAA0B,EAAE,KAAsB,EAAE,SAAoB,EAAoB,EAAE;;IAC5H,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEzB,MAAM,qBAAqB,GAAG,OAAA,WAAW,CAAC,OAAO,0CAAE,qBAAq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AAC,CAAC,IAAI,yBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAC5H,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 { removeAuras, setImplicitData } 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('121569');\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(battleInput.gameState?.validTribes ?? battleInput.options?.validTribes);\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 = (battleInput: BgsBattleInfo, cards: AllCardsService, cardsData: CardsData): 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((entity) => ({ ...addImpliedMechanics(entity), friendly: true } as BoardEntity));\r\n\tconst opponentBoard = opponentInfo.board.map((entity) => ({ ...addImpliedMechanics(entity), friendly: false } as BoardEntity));\r\n\tremoveAuras(playerBoard, cardsData);\r\n\tremoveAuras(opponentBoard, cardsData);\r\n\tsetImplicitData(playerBoard, cardsData); // Avenge, maxHealth, etc.\r\n\tsetImplicitData(opponentBoard, cardsData); // Avenge, maxHealth, etc.\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} 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\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\t// global.gc();\r\n\t\t// continue;\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\tif (battleInput.playerBoard.player.hpLeft && battleResult.damageDealt >= battleInput.playerBoard.player.hpLeft) {\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.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\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 ? simulationResult.damageLost / simulationResult.lost : 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\t// spectator.reset();\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,\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantmentBattlegrounds,\r\n\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment1,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment2,\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];\r\n\r\nconst cleanEnchantmentsForEntity = (\r\n\tenchantments: { cardId: string; originEntityId?: number }[],\r\n\tentityIds: readonly number[],\r\n): { cardId: string; originEntityId?: number }[] => {\r\n\treturn enchantments.filter(\r\n\t\t(enchant) => entityIds.indexOf(enchant.originEntityId) !== -1 || validEnchantments.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,8CAAuF;AACvF,sDAAmD;AACnD,gEAA6D;AAC7D,mCAA8C;AAE9C,MAAM,KAAK,GAAG,IAAI,gCAAe,EAAE,CAAC;AAKpC,kBAAe,CAAO,KAAK,EAAgB,EAAE;;IAC5C,MAAM,WAAW,GAAkB,IAAI,CAAC,KAAK,CAAC,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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,iCACzB,MAAM,KACT,YAAY,EAAE,0BAA0B,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,IACvE,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG;;;;;;;;;;;;;;CAgBhC,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAClC,YAA2D,EAC3D,SAA4B,EACoB,EAAE;IAClD,OAAO,YAAY,CAAC,MAAM,CACzB,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,IAAI,yBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAiB,CAAC,KAAK,CAAC,CAAC,CAC5H,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 { removeAuras, setImplicitData, setImplicitDataHero } 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('121569');\r\n\tconst cardsData = new CardsData(cards, false);\r\n\tcardsData.inititialize(battleInput.gameState?.validTribes ?? battleInput.options?.validTribes);\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 = (battleInput: BgsBattleInfo, cards: AllCardsService, cardsData: CardsData): 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((entity) => ({ ...addImpliedMechanics(entity), friendly: true } as BoardEntity));\r\n\tconst opponentBoard = opponentInfo.board.map((entity) => ({ ...addImpliedMechanics(entity), friendly: false } as BoardEntity));\r\n\tremoveAuras(playerBoard, cardsData);\r\n\tremoveAuras(opponentBoard, cardsData);\r\n\tsetImplicitData(playerBoard, cardsData); // Avenge, maxHealth, etc.\r\n\tsetImplicitData(opponentBoard, cardsData); // Avenge, maxHealth, etc.\r\n\tsetImplicitDataHero(playerInfo.player, cardsData);\r\n\tsetImplicitDataHero(opponentInfo.player, cardsData);\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} 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\tfor (let i = 0; i < numberOfSimulations; i++) {\r\n\t\t// global.gc();\r\n\t\t// continue;\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\tif (battleInput.playerBoard.player.hpLeft && battleResult.damageDealt >= battleInput.playerBoard.player.hpLeft) {\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.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\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 ? simulationResult.damageLost / simulationResult.lost : 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\t// spectator.reset();\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,\r\n\tCardIds.ReplicatingMenace_ReplicatingMenaceEnchantmentBattlegrounds,\r\n\tCardIds.LivingSpores_LivingSporesEnchantment,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment1,\r\n\tCardIds.Leapfrogger_LeapfrogginEnchantment2,\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];\r\n\r\nconst cleanEnchantmentsForEntity = (\r\n\tenchantments: { cardId: string; originEntityId?: number }[],\r\n\tentityIds: readonly number[],\r\n): { cardId: string; originEntityId?: number }[] => {\r\n\treturn enchantments.filter(\r\n\t\t(enchant) => entityIds.indexOf(enchant.originEntityId) !== -1 || validEnchantments.indexOf(enchant.cardId as CardIds) !== -1,\r\n\t);\r\n};\r\n"]}
@@ -13,3 +13,4 @@ export declare const bumpEntities: (entity: BoardEntity, bumpInto: BoardEntity,
13
13
  export declare const processMinionDeath: (board1: BoardEntity[], board1Hero: BgsPlayerEntity, board2: BoardEntity[], board2Hero: BgsPlayerEntity, allCards: AllCardsService, cardsData: CardsData, sharedState: SharedState, spectator: Spectator) => void;
14
14
  export declare const applyOnAttackBuffs: (attacker: BoardEntity, attackingBoard: BoardEntity[], allCards: AllCardsService, spectator: Spectator) => void;
15
15
  export declare const applyOnBeingAttackedBuffs: (attackedEntity: BoardEntity, defendingBoard: BoardEntity[], allCards: AllCardsService, spectator: Spectator) => void;
16
+ export declare const performEntitySpawns: (candidateEntities: readonly BoardEntity[], boardWithKilledMinion: BoardEntity[], boardWithKilledMinionHero: BgsPlayerEntity, deadEntity: BoardEntity, deadMinionIndex: number, opponentBoard: BoardEntity[], opponentBoardHero: BgsPlayerEntity, allCards: AllCardsService, cardsData: CardsData, sharedState: SharedState, spectator: Spectator) => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyOnBeingAttackedBuffs = exports.applyOnAttackBuffs = exports.processMinionDeath = exports.bumpEntities = exports.getDefendingEntity = exports.dealDamageToEnemy = exports.dealDamageToRandomEnemy = exports.getNeighbours = exports.simulateAttack = void 0;
3
+ exports.performEntitySpawns = exports.applyOnBeingAttackedBuffs = exports.applyOnAttackBuffs = exports.processMinionDeath = exports.bumpEntities = exports.getDefendingEntity = exports.dealDamageToEnemy = exports.dealDamageToRandomEnemy = exports.getNeighbours = exports.simulateAttack = void 0;
4
4
  const reference_data_1 = require("@firestone-hs/reference-data");
5
+ const avenge_1 = require("src/simulation/avenge");
5
6
  const utils_1 = require("../services/utils");
6
7
  const simulate_bgs_battle_1 = require("../simulate-bgs-battle");
7
8
  const utils_2 = require("../utils");
@@ -55,7 +56,7 @@ const simulateAttack = (attackingBoard, attackingBoardHero, defendingBoard, defe
55
56
  exports.simulateAttack = simulateAttack;
56
57
  const applyAfterAttackEffects = (attackingEntity, attackingBoard, attackingBoardHero, allCards, spectator) => {
57
58
  if (attackingEntity.cardId === "BG20_104" || attackingEntity.cardId === "BG20_104_G") {
58
- deathrattle_effects_1.addCardsInHand(attackingBoardHero, 1, attackingBoard, allCards, spectator, "BG20_GEM");
59
+ utils_2.addCardsInHand(attackingBoardHero, 1, attackingBoard, allCards, spectator, "BG20_GEM");
59
60
  }
60
61
  };
61
62
  const performAttack = (attackingEntity, defendingEntity, attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, allCards, spawns, sharedState, spectator) => {
@@ -250,10 +251,10 @@ const bumpEntities = (entity, bumpInto, entityBoard, entityBoardHero, otherBoard
250
251
  entityBoard[i].divineShield = true;
251
252
  }
252
253
  else if (entityBoard[i].cardId === "BG21_037") {
253
- deathrattle_effects_1.addCardsInHand(entityBoardHero, 1, entityBoard, allCards, spectator, "BG20_GEM");
254
+ utils_2.addCardsInHand(entityBoardHero, 1, entityBoard, allCards, spectator, "BG20_GEM");
254
255
  }
255
256
  else if (entityBoard[i].cardId === "BG21_037_G") {
256
- deathrattle_effects_1.addCardsInHand(entityBoardHero, 2, entityBoard, allCards, spectator, "BG20_GEM");
257
+ utils_2.addCardsInHand(entityBoardHero, 2, entityBoard, allCards, spectator, "BG20_GEM");
257
258
  }
258
259
  if (entityBoard[i].entityId === entity.entityId) {
259
260
  entity.divineShield = false;
@@ -356,8 +357,34 @@ const processMinionDeath = (board1, board1Hero, board2, board2Hero, allCards, ca
356
357
  board2
357
358
  .filter((entity) => entity.cardId === "BG20_HERO_282_Buddy" || entity.cardId === "BG20_HERO_282_Buddy_G")
358
359
  .forEach((entity) => deathrattle_effects_1.applyMonstrosity(entity, deadEntities2, board2, allCards));
360
+ handleAfterMinionsDeaths(board1, deadEntities1, board1Hero, board2, deadEntities2, board2Hero, allCards, cardsData, sharedState, spectator);
359
361
  };
360
362
  exports.processMinionDeath = processMinionDeath;
363
+ const handleAfterMinionsDeaths = (board1, deadEntities1, heroEntity1, board2, deadEntities2, heroEntity2, allCards, cardsData, sharedState, spectator) => {
364
+ const random = Math.random() > 0.5;
365
+ handleAfterMinionsDeathsForBoard(random ? board1 : board2, random ? deadEntities1 : deadEntities2, random ? heroEntity1 : heroEntity2, random ? board2 : board1, random ? deadEntities2 : deadEntities1, allCards, cardsData, sharedState, spectator);
366
+ handleAfterMinionsDeathsForBoard(!random ? board1 : board2, !random ? deadEntities1 : deadEntities2, !random ? heroEntity1 : heroEntity2, !random ? board2 : board1, !random ? deadEntities2 : deadEntities1, allCards, cardsData, sharedState, spectator);
367
+ };
368
+ const handleAfterMinionsDeathsForBoard = (friendlyBoard, friendlyDeadEntities, friendlyHeroEntity, otherBoard, otherDeadEntities, allCards, cardsData, sharedState, spectator) => {
369
+ for (const deadEntity of friendlyDeadEntities) {
370
+ const killer = deadEntity.lastAffectedByEntity;
371
+ if (!killer) {
372
+ continue;
373
+ }
374
+ if (killer.friendly !== deadEntity.friendly) {
375
+ if (friendlyHeroEntity.heroPowerId === "BG20_HERO_100p") {
376
+ utils_2.modifyAttack(killer, 1, friendlyBoard, allCards);
377
+ utils_2.afterStatsUpdate(killer, friendlyBoard, allCards);
378
+ friendlyBoard
379
+ .filter((e) => e.cardId === "BG20_HERO_100_Buddy" || e.cardId === "BG20_HERO_100_Buddy_G")
380
+ .forEach((icesnarl) => {
381
+ utils_2.modifyHealth(icesnarl, icesnarl.cardId === "BG20_HERO_100_Buddy_G" ? 2 : 1, friendlyBoard, allCards);
382
+ utils_2.afterStatsUpdate(icesnarl, friendlyBoard, allCards);
383
+ });
384
+ }
385
+ }
386
+ }
387
+ };
361
388
  const handleDeathrattlesForFirstBoard = (firstBoard, firstBoardHero, otherBoard, otherBoardHero, deadMinionIndexes, deadEntities, allCards, cardsData, sharedState, spectator) => {
362
389
  for (let i = 0; i < deadMinionIndexes.length; i++) {
363
390
  const entity = deadEntities[i];
@@ -484,26 +511,6 @@ const makeMinionsDie = (board, allCards) => {
484
511
  }
485
512
  return [deadMinionIndexes, deadEntities];
486
513
  };
487
- const handleKillEffects = (boardWithKilledMinion, killerBoard, deadEntity, allCards, spectator) => {
488
- var _a;
489
- if (((_a = deadEntity.lastAffectedByEntity) === null || _a === void 0 ? void 0 : _a.cardId) &&
490
- utils_2.isCorrectTribe(allCards.getCard(deadEntity.lastAffectedByEntity.cardId).race, reference_data_1.Race.DRAGON)) {
491
- for (const entity of killerBoard) {
492
- if (entity.cardId === "BGS_035") {
493
- utils_2.modifyAttack(entity, 2, killerBoard, allCards);
494
- utils_2.modifyHealth(entity, 2, killerBoard, allCards);
495
- utils_2.afterStatsUpdate(entity, killerBoard, allCards);
496
- spectator.registerPowerTarget(entity, entity, killerBoard);
497
- }
498
- else if (entity.cardId === "TB_BaconUps_105") {
499
- utils_2.modifyAttack(entity, 4, killerBoard, allCards);
500
- utils_2.modifyHealth(entity, 4, killerBoard, allCards);
501
- utils_2.afterStatsUpdate(entity, killerBoard, allCards);
502
- spectator.registerPowerTarget(entity, entity, killerBoard);
503
- }
504
- }
505
- }
506
- };
507
514
  const buildBoardAfterDeathrattleSpawns = (boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator) => {
508
515
  var _a;
509
516
  if (deadMinionIndex >= 0) {
@@ -512,7 +519,7 @@ const buildBoardAfterDeathrattleSpawns = (boardWithKilledMinion, boardWithKilled
512
519
  const entitiesFromNativeDeathrattle = deathrattle_spawns_1.spawnEntitiesFromDeathrattle(deadEntity, boardWithKilledMinion, boardWithKilledMinionHero, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
513
520
  const entitiesFromEnchantments = deathrattle_spawns_1.spawnEntitiesFromEnchantments(deadEntity, boardWithKilledMinion, boardWithKilledMinionHero, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
514
521
  const candidateEntities = [...entitiesFromNativeDeathrattle, ...entitiesFromEnchantments];
515
- performEntitySpawns(candidateEntities, boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
522
+ exports.performEntitySpawns(candidateEntities, boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
516
523
  deathrattle_effects_1.handleDeathrattleEffects(boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
517
524
  if ((_a = deadEntity.rememberedDeathrattles) === null || _a === void 0 ? void 0 : _a.length) {
518
525
  for (const deathrattle of deadEntity.rememberedDeathrattles) {
@@ -525,6 +532,7 @@ const buildBoardAfterDeathrattleSpawns = (boardWithKilledMinion, boardWithKilled
525
532
  buildBoardAfterDeathrattleSpawns(boardWithKilledMinion, boardWithKilledMinionHero, entityToProcess, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
526
533
  }
527
534
  }
535
+ avenge_1.applyAvengeEffects(deadEntity, deadMinionIndex, boardWithKilledMinion, boardWithKilledMinionHero, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
528
536
  };
529
537
  const buildBoardAfterRebornSpawns = (boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator) => {
530
538
  const otherEntityCardIds = boardWithKilledMinion.filter((e) => e.entityId !== deadEntity.entityId).map((e) => e.cardId);
@@ -534,7 +542,7 @@ const buildBoardAfterRebornSpawns = (boardWithKilledMinion, boardWithKilledMinio
534
542
  const entitiesFromReborn = deadEntity.reborn && deadMinionIndex >= 0
535
543
  ? deathrattle_spawns_1.spawnEntities(deadEntity.cardId, numberOfReborns, boardWithKilledMinion, boardWithKilledMinionHero, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator, deadEntity.friendly, false, true)
536
544
  : [];
537
- performEntitySpawns(entitiesFromReborn, boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
545
+ exports.performEntitySpawns(entitiesFromReborn, boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator);
538
546
  };
539
547
  const performEntitySpawns = (candidateEntities, boardWithKilledMinion, boardWithKilledMinionHero, deadEntity, deadMinionIndex, opponentBoard, opponentBoardHero, allCards, cardsData, sharedState, spectator) => {
540
548
  const aliveEntites = candidateEntities.filter((entity) => entity.health > 0 && !entity.definitelyDead);
@@ -557,4 +565,5 @@ const performEntitySpawns = (candidateEntities, boardWithKilledMinion, boardWith
557
565
  spawn_effect_1.handleSpawnEffects(boardWithKilledMinion, spawnedEntities, allCards, spectator);
558
566
  spectator.registerMinionsSpawn(deadEntity, boardWithKilledMinion, spawnedEntities);
559
567
  };
568
+ exports.performEntitySpawns = performEntitySpawns;
560
569
  //# sourceMappingURL=attack.js.map