qpremake 1.5.1

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 (234) hide show
  1. package/README.md +184 -0
  2. package/lib/_localizationFiles/English.d.ts +2 -0
  3. package/lib/_localizationFiles/English.js +307 -0
  4. package/lib/_mods/parserModules/addSymbol.d.ts +7 -0
  5. package/lib/_mods/parserModules/addSymbol.js +18 -0
  6. package/lib/_mods/parserModules/expression.d.ts +7 -0
  7. package/lib/_mods/parserModules/expression.js +45 -0
  8. package/lib/_mods/parserModules/expression_parser.d.ts +143 -0
  9. package/lib/_mods/parserModules/expression_parser.js +728 -0
  10. package/lib/_mods/parserModules/img.d.ts +8 -0
  11. package/lib/_mods/parserModules/img.js +42 -0
  12. package/lib/_mods/parserModules/qpOriginal.d.ts +5 -0
  13. package/lib/_mods/parserModules/qpOriginal.js +27 -0
  14. package/lib/_mods/parserModules/sectionID.d.ts +13 -0
  15. package/lib/_mods/parserModules/sectionID.js +56 -0
  16. package/lib/_mods/parserModules/tags.d.ts +9 -0
  17. package/lib/_mods/parserModules/tags.js +29 -0
  18. package/lib/_mods/parserModules/uaddminus.d.ts +9 -0
  19. package/lib/_mods/parserModules/uaddminus.js +42 -0
  20. package/lib/_mods/parserModules/variantCheck.d.ts +10 -0
  21. package/lib/_mods/parserModules/variantCheck.js +53 -0
  22. package/lib/_queenSystem/handler/actionGenrator.d.ts +994 -0
  23. package/lib/_queenSystem/handler/actionGenrator.js +646 -0
  24. package/lib/_queenSystem/handler/actionInputGenerator.d.ts +95 -0
  25. package/lib/_queenSystem/handler/actionInputGenerator.js +373 -0
  26. package/lib/_queenSystem/handler/actionInputRequesterGenerator.d.ts +92 -0
  27. package/lib/_queenSystem/handler/actionInputRequesterGenerator.js +341 -0
  28. package/lib/_queenSystem/handler/cardHandler.d.ts +20 -0
  29. package/lib/_queenSystem/handler/cardHandler.js +61 -0
  30. package/lib/_queenSystem/handler/effectGenerator.d.ts +1 -0
  31. package/lib/_queenSystem/handler/effectGenerator.js +127 -0
  32. package/lib/_queenSystem/handler/localizationHandler.d.ts +28 -0
  33. package/lib/_queenSystem/handler/localizationHandler.js +166 -0
  34. package/lib/_queenSystem/handler/modHandler.d.ts +10 -0
  35. package/lib/_queenSystem/handler/modHandler.js +36 -0
  36. package/lib/_queenSystem/handler/oldDataProcessor.d.ts +9 -0
  37. package/lib/_queenSystem/handler/oldDataProcessor.js +129 -0
  38. package/lib/_queenSystem/handler/registryHandler.d.ts +36 -0
  39. package/lib/_queenSystem/handler/registryHandler.js +63 -0
  40. package/lib/_queenSystem/handler/zoneHandler.d.ts +102 -0
  41. package/lib/_queenSystem/handler/zoneHandler.js +606 -0
  42. package/lib/_queenSystem/loader/loader_card.d.ts +20 -0
  43. package/lib/_queenSystem/loader/loader_card.js +124 -0
  44. package/lib/_queenSystem/loader/loader_effect.d.ts +27 -0
  45. package/lib/_queenSystem/loader/loader_effect.js +163 -0
  46. package/lib/_queenSystem/loader/loader_handler.d.ts +11 -0
  47. package/lib/_queenSystem/loader/loader_handler.js +24 -0
  48. package/lib/_queenSystem/loader/loader_localization.d.ts +11 -0
  49. package/lib/_queenSystem/loader/loader_localization.js +73 -0
  50. package/lib/_queenSystem/loader/loader_mod.d.ts +10 -0
  51. package/lib/_queenSystem/loader/loader_mod.js +72 -0
  52. package/lib/_queenSystem/loader/loader_subtype.d.ts +9 -0
  53. package/lib/_queenSystem/loader/loader_subtype.js +39 -0
  54. package/lib/_queenSystem/loader/loader_type.d.ts +9 -0
  55. package/lib/_queenSystem/loader/loader_type.js +39 -0
  56. package/lib/_queenSystem/loader/loader_zone.d.ts +14 -0
  57. package/lib/_queenSystem/loader/loader_zone.js +35 -0
  58. package/lib/_queenSystem/queenSystem.d.ts +127 -0
  59. package/lib/_queenSystem/queenSystem.js +996 -0
  60. package/lib/_queenSystem/renderer/rendererInterface.d.ts +9 -0
  61. package/lib/_queenSystem/renderer/rendererInterface.js +2 -0
  62. package/lib/data/actionRegistry.d.ts +56 -0
  63. package/lib/data/actionRegistry.js +60 -0
  64. package/lib/data/cardRegistry.d.ts +1162 -0
  65. package/lib/data/cardRegistry.js +716 -0
  66. package/lib/data/deckRegistry.d.ts +19 -0
  67. package/lib/data/deckRegistry.js +41 -0
  68. package/lib/data/effectRegistry.d.ts +465 -0
  69. package/lib/data/effectRegistry.js +151 -0
  70. package/lib/data/effectTypeRegistry.d.ts +14 -0
  71. package/lib/data/effectTypeRegistry.js +14 -0
  72. package/lib/data/operatorRegistry.d.ts +92 -0
  73. package/lib/data/operatorRegistry.js +82 -0
  74. package/lib/data/rarityRegistry.d.ts +28 -0
  75. package/lib/data/rarityRegistry.js +63 -0
  76. package/lib/data/registryRegistry.d.ts +10 -0
  77. package/lib/data/registryRegistry.js +14 -0
  78. package/lib/data/subtypeRegistry.d.ts +15 -0
  79. package/lib/data/subtypeRegistry.js +15 -0
  80. package/lib/data/systemRegistry.d.ts +253 -0
  81. package/lib/data/systemRegistry.js +56 -0
  82. package/lib/data/zoneRegistry.d.ts +43 -0
  83. package/lib/data/zoneRegistry.js +157 -0
  84. package/lib/effectTextParser/index.d.ts +42 -0
  85. package/lib/effectTextParser/index.js +316 -0
  86. package/lib/global/index.d.ts +8 -0
  87. package/lib/global/index.js +12 -0
  88. package/lib/index.d.ts +6344 -0
  89. package/lib/index.js +213 -0
  90. package/lib/specificEffects/e_cond.d.ts +11 -0
  91. package/lib/specificEffects/e_cond.js +36 -0
  92. package/lib/specificEffects/e_fruit.d.ts +3 -0
  93. package/lib/specificEffects/e_fruit.js +187 -0
  94. package/lib/specificEffects/e_generic.d.ts +191 -0
  95. package/lib/specificEffects/e_generic.js +662 -0
  96. package/lib/specificEffects/e_generic_cardTargetting.d.ts +38 -0
  97. package/lib/specificEffects/e_generic_cardTargetting.js +82 -0
  98. package/lib/specificEffects/e_generic_noneTargetting.d.ts +10 -0
  99. package/lib/specificEffects/e_generic_noneTargetting.js +26 -0
  100. package/lib/specificEffects/e_status.d.ts +80 -0
  101. package/lib/specificEffects/e_status.js +151 -0
  102. package/lib/specificEffects/e_test.d.ts +3 -0
  103. package/lib/specificEffects/e_test.js +21 -0
  104. package/lib/types/abstract/gameComponents/API.d.ts +19 -0
  105. package/lib/types/abstract/gameComponents/API.js +2 -0
  106. package/lib/types/abstract/gameComponents/card.d.ts +108 -0
  107. package/lib/types/abstract/gameComponents/card.js +771 -0
  108. package/lib/types/abstract/gameComponents/effect.d.ts +82 -0
  109. package/lib/types/abstract/gameComponents/effect.js +331 -0
  110. package/lib/types/abstract/gameComponents/effectSubtype.d.ts +22 -0
  111. package/lib/types/abstract/gameComponents/effectSubtype.js +40 -0
  112. package/lib/types/abstract/gameComponents/effectType.d.ts +11 -0
  113. package/lib/types/abstract/gameComponents/effectType.js +8 -0
  114. package/lib/types/abstract/gameComponents/settings.d.ts +80 -0
  115. package/lib/types/abstract/gameComponents/settings.js +68 -0
  116. package/lib/types/abstract/gameComponents/zone.d.ts +113 -0
  117. package/lib/types/abstract/gameComponents/zone.js +614 -0
  118. package/lib/types/abstract/gameComponents/zone_gridBased.d.ts +18 -0
  119. package/lib/types/abstract/gameComponents/zone_gridBased.js +58 -0
  120. package/lib/types/abstract/gameComponents/zone_stackBased.d.ts +13 -0
  121. package/lib/types/abstract/gameComponents/zone_stackBased.js +55 -0
  122. package/lib/types/abstract/generics/node.d.ts +23 -0
  123. package/lib/types/abstract/generics/node.js +46 -0
  124. package/lib/types/abstract/generics/position.d.ts +23 -0
  125. package/lib/types/abstract/generics/position.js +91 -0
  126. package/lib/types/abstract/generics/tree.d.ts +25 -0
  127. package/lib/types/abstract/generics/tree.js +153 -0
  128. package/lib/types/abstract/generics/universalResponse.d.ts +4 -0
  129. package/lib/types/abstract/generics/universalResponse.js +2 -0
  130. package/lib/types/abstract/generics/wraper.d.ts +21 -0
  131. package/lib/types/abstract/generics/wraper.js +56 -0
  132. package/lib/types/abstract/parser/component.d.ts +88 -0
  133. package/lib/types/abstract/parser/component.js +132 -0
  134. package/lib/types/abstract/parser/index.d.ts +6 -0
  135. package/lib/types/abstract/parser/index.js +28 -0
  136. package/lib/types/abstract/parser/modPack.d.ts +21 -0
  137. package/lib/types/abstract/parser/modPack.js +48 -0
  138. package/lib/types/abstract/parser/moduleInputObject.d.ts +12 -0
  139. package/lib/types/abstract/parser/moduleInputObject.js +21 -0
  140. package/lib/types/abstract/parser/options.d.ts +31 -0
  141. package/lib/types/abstract/parser/options.js +45 -0
  142. package/lib/types/abstract/serializedGameComponents/Gamestate.d.ts +46 -0
  143. package/lib/types/abstract/serializedGameComponents/Gamestate.js +70 -0
  144. package/lib/types/abstract/serializedGameComponents/Localized.d.ts +69 -0
  145. package/lib/types/abstract/serializedGameComponents/Localized.js +84 -0
  146. package/lib/types/defaultZones/ability.d.ts +10 -0
  147. package/lib/types/defaultZones/ability.js +22 -0
  148. package/lib/types/defaultZones/deck.d.ts +25 -0
  149. package/lib/types/defaultZones/deck.js +90 -0
  150. package/lib/types/defaultZones/drop.d.ts +5 -0
  151. package/lib/types/defaultZones/drop.js +13 -0
  152. package/lib/types/defaultZones/field.d.ts +11 -0
  153. package/lib/types/defaultZones/field.js +35 -0
  154. package/lib/types/defaultZones/grave.d.ts +8 -0
  155. package/lib/types/defaultZones/grave.js +21 -0
  156. package/lib/types/defaultZones/hand.d.ts +5 -0
  157. package/lib/types/defaultZones/hand.js +14 -0
  158. package/lib/types/defaultZones/storage.d.ts +9 -0
  159. package/lib/types/defaultZones/storage.js +21 -0
  160. package/lib/types/defaultZones/system.d.ts +12 -0
  161. package/lib/types/defaultZones/system.js +35 -0
  162. package/lib/types/defaultZones/void.d.ts +4 -0
  163. package/lib/types/defaultZones/void.js +10 -0
  164. package/lib/types/effects/effectSubtypes/subtype_chained.d.ts +10 -0
  165. package/lib/types/effects/effectSubtypes/subtype_chained.js +17 -0
  166. package/lib/types/effects/effectSubtypes/subtype_delayed.d.ts +9 -0
  167. package/lib/types/effects/effectSubtypes/subtype_delayed.js +16 -0
  168. package/lib/types/effects/effectSubtypes/subtype_fieldLock.d.ts +9 -0
  169. package/lib/types/effects/effectSubtypes/subtype_fieldLock.js +21 -0
  170. package/lib/types/effects/effectSubtypes/subtype_graveLock.d.ts +9 -0
  171. package/lib/types/effects/effectSubtypes/subtype_graveLock.js +21 -0
  172. package/lib/types/effects/effectSubtypes/subtype_hand_or_fieldLock.d.ts +9 -0
  173. package/lib/types/effects/effectSubtypes/subtype_hand_or_fieldLock.js +21 -0
  174. package/lib/types/effects/effectSubtypes/subtype_hardUnique.d.ts +9 -0
  175. package/lib/types/effects/effectSubtypes/subtype_hardUnique.js +15 -0
  176. package/lib/types/effects/effectSubtypes/subtype_instant.d.ts +8 -0
  177. package/lib/types/effects/effectSubtypes/subtype_instant.js +20 -0
  178. package/lib/types/effects/effectSubtypes/subtype_once.d.ts +12 -0
  179. package/lib/types/effects/effectSubtypes/subtype_once.js +27 -0
  180. package/lib/types/effects/effectSubtypes/subtype_unique.d.ts +9 -0
  181. package/lib/types/effects/effectSubtypes/subtype_unique.js +16 -0
  182. package/lib/types/effects/effectTypes/initEffect.d.ts +7 -0
  183. package/lib/types/effects/effectTypes/initEffect.js +23 -0
  184. package/lib/types/effects/effectTypes/lockEffect.d.ts +9 -0
  185. package/lib/types/effects/effectTypes/lockEffect.js +25 -0
  186. package/lib/types/effects/effectTypes/manualEffect.d.ts +9 -0
  187. package/lib/types/effects/effectTypes/manualEffect.js +18 -0
  188. package/lib/types/effects/effectTypes/passiveEffect.d.ts +9 -0
  189. package/lib/types/effects/effectTypes/passiveEffect.js +23 -0
  190. package/lib/types/effects/effectTypes/triggerEffect.d.ts +9 -0
  191. package/lib/types/effects/effectTypes/triggerEffect.js +28 -0
  192. package/lib/types/errors/cannotLoad.d.ts +5 -0
  193. package/lib/types/errors/cannotLoad.js +13 -0
  194. package/lib/types/errors/cardNotExist.d.ts +5 -0
  195. package/lib/types/errors/cardNotExist.js +13 -0
  196. package/lib/types/errors/cardNotInApplicableZone.d.ts +5 -0
  197. package/lib/types/errors/cardNotInApplicableZone.js +13 -0
  198. package/lib/types/errors/effectCondNotMet.d.ts +5 -0
  199. package/lib/types/errors/effectCondNotMet.js +13 -0
  200. package/lib/types/errors/effectNotExist.d.ts +5 -0
  201. package/lib/types/errors/effectNotExist.js +13 -0
  202. package/lib/types/errors/error.d.ts +17 -0
  203. package/lib/types/errors/error.js +42 -0
  204. package/lib/types/errors/incorrectActionType.d.ts +5 -0
  205. package/lib/types/errors/incorrectActionType.js +13 -0
  206. package/lib/types/errors/index.d.ts +16 -0
  207. package/lib/types/errors/index.js +36 -0
  208. package/lib/types/errors/invalidOrderMap.d.ts +6 -0
  209. package/lib/types/errors/invalidOrderMap.js +14 -0
  210. package/lib/types/errors/invalidPosition.d.ts +6 -0
  211. package/lib/types/errors/invalidPosition.js +13 -0
  212. package/lib/types/errors/subTypeOverrideConflict.d.ts +7 -0
  213. package/lib/types/errors/subTypeOverrideConflict.js +15 -0
  214. package/lib/types/errors/unknownError.d.ts +5 -0
  215. package/lib/types/errors/unknownError.js +13 -0
  216. package/lib/types/errors/unregisteredAction.d.ts +6 -0
  217. package/lib/types/errors/unregisteredAction.js +13 -0
  218. package/lib/types/errors/wrongEffectIdx.d.ts +5 -0
  219. package/lib/types/errors/wrongEffectIdx.js +14 -0
  220. package/lib/types/errors/zoneAttrConflict.d.ts +5 -0
  221. package/lib/types/errors/zoneAttrConflict.js +15 -0
  222. package/lib/types/errors/zoneFull.d.ts +5 -0
  223. package/lib/types/errors/zoneFull.js +13 -0
  224. package/lib/types/errors/zoneNotExist.d.ts +5 -0
  225. package/lib/types/errors/zoneNotExist.js +13 -0
  226. package/lib/types/misc.d.ts +97 -0
  227. package/lib/types/misc.js +8 -0
  228. package/lib/types/mods/effectTextParserModule.d.ts +16 -0
  229. package/lib/types/mods/effectTextParserModule.js +81 -0
  230. package/lib/types/mods/gameModule.d.ts +5 -0
  231. package/lib/types/mods/gameModule.js +8 -0
  232. package/lib/utils/index.d.ts +78 -0
  233. package/lib/utils/index.js +562 -0
  234. package/package.json +45 -0
@@ -0,0 +1,996 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const node_1 = __importDefault(require("../types/abstract/generics/node"));
16
+ const tree_1 = __importDefault(require("../types/abstract/generics/tree"));
17
+ const zoneHandler_1 = __importDefault(require("./handler/zoneHandler"));
18
+ const actionRegistry_1 = __importDefault(require("../data/actionRegistry"));
19
+ const actionGenrator_1 = require("./handler/actionGenrator");
20
+ const errors_1 = require("../types/errors");
21
+ const settings_1 = require("../types/abstract/gameComponents/settings");
22
+ const cardHandler_1 = __importDefault(require("./handler/cardHandler"));
23
+ const registryHandler_1 = __importDefault(require("./handler/registryHandler"));
24
+ const modHandler_1 = __importDefault(require("./handler/modHandler"));
25
+ const localizationHandler_1 = __importDefault(require("./handler/localizationHandler"));
26
+ const e_status_1 = require("../specificEffects/e_status");
27
+ const zoneRegistry_1 = require("../data/zoneRegistry");
28
+ const card_1 = __importDefault(require("../types/abstract/gameComponents/card"));
29
+ const zone_1 = __importDefault(require("../types/abstract/gameComponents/zone"));
30
+ const effect_1 = __importDefault(require("../types/abstract/gameComponents/effect"));
31
+ const effectSubtype_1 = __importDefault(require("../types/abstract/gameComponents/effectSubtype"));
32
+ const systemRegistry_1 = require("../data/systemRegistry");
33
+ const position_1 = __importDefault(require("../types/abstract/generics/position"));
34
+ const actionInputGenerator_1 = require("./handler/actionInputGenerator");
35
+ const effectTextParser_1 = require("../effectTextParser");
36
+ const Gamestate_1 = require("../types/abstract/serializedGameComponents/Gamestate");
37
+ class queenSystem {
38
+ get isSuspended() { return this.suspensionReason !== false; }
39
+ //cardID, effectIDs[]
40
+ get rootID() { return this.actionTree.root.id; }
41
+ getRootAction() { return this.actionTree.root.data; }
42
+ get threatLevel() { return this.zoneHandler.system.map(i => i.threat); }
43
+ set threatLevel(val) {
44
+ if (typeof val === "number") {
45
+ if (isNaN(val) || val < 0)
46
+ val = 0;
47
+ // if(val > this.zoneHandler.system.maxThreat) val = this.zoneHandler.system.maxThreat
48
+ this.zoneHandler.system.forEach(i => i.threat = val);
49
+ }
50
+ else {
51
+ const s = this.zoneHandler.system;
52
+ val.forEach((t, index) => {
53
+ s[index].threat = t;
54
+ });
55
+ }
56
+ }
57
+ get maxThreatLevel() { return this.zoneHandler.system.map(i => i.maxThreat); }
58
+ constructor(s, renderer) {
59
+ this.renderer = renderer;
60
+ //properties
61
+ this.turnAction = undefined;
62
+ this.turnCount = 0;
63
+ this.waveCount = 0;
64
+ //
65
+ this.player_stat = [];
66
+ this.processStack = [];
67
+ //stores id of node before step "recur until meet this again"
68
+ this.suspendID = -1;
69
+ //^ node id of the node before suspended,
70
+ //when unsuspended, continue processing this node from current phase ID
71
+ this.suspensionReason = false;
72
+ this.curr_input_obj = undefined;
73
+ this.fullLog = [];
74
+ this.phaseIdx = systemRegistry_1.TurnPhase.declare;
75
+ //const
76
+ this.NULLPOS = new position_1.default(-1);
77
+ this.setting = s;
78
+ this.registryFile = new registryHandler_1.default(s);
79
+ this.zoneHandler = new zoneHandler_1.default(this.registryFile);
80
+ this.cardHandler = new cardHandler_1.default(s, this.registryFile);
81
+ this.modHandler = new modHandler_1.default(s, this.registryFile);
82
+ this.localizer = new localizationHandler_1.default(this, this.registryFile);
83
+ this.actionTree = new tree_1.default(actionGenrator_1.actionConstructorRegistry.a_turn_end(actionGenrator_1.actionFormRegistry.system(), {
84
+ doIncreaseTurnCount: true
85
+ }));
86
+ this.forEach = this.zoneHandler.forEach;
87
+ this.map = this.zoneHandler.map;
88
+ this.filter = this.zoneHandler.filter;
89
+ const c = this.cardHandler.getCard("c_blank");
90
+ c.pos = new position_1.default(-1);
91
+ c.canAct = false;
92
+ this.NULLCARD = c;
93
+ }
94
+ addDeck(loadCardsInfo, merge = false) {
95
+ const p = this.player_stat.at(-1);
96
+ if (!p)
97
+ throw new Error("Tried to load deck info into a none-existent player");
98
+ merge ? p.loadCardsInfo.concat(loadCardsInfo) : p.loadCardsInfo = loadCardsInfo;
99
+ }
100
+ addPlayers(type, operatorID,
101
+ //optional
102
+ loadCardsInfo = [], heart = 20, maxHeart = heart) {
103
+ this.player_stat.push({
104
+ playerType: zoneRegistry_1.playerTypeID[type],
105
+ playerIndex: this.player_stat.length,
106
+ heart,
107
+ maxHeart,
108
+ operator: operatorID,
109
+ loadCardsInfo
110
+ });
111
+ }
112
+ load(gamestate) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ if (gamestate) {
115
+ this.loadGamestate(gamestate);
116
+ }
117
+ if (this.player_stat.length === 0)
118
+ console.warn("No player loaded, if this is unintended, make sure to call addPlayer(...) before load");
119
+ this.zoneHandler.loadZones(this.setting, this.player_stat);
120
+ let arr = [
121
+ this.localizer.load(new effectTextParser_1.loadOptions(this.setting.modFolder_parser, this.setting.parser_modules)),
122
+ this.modHandler.load(),
123
+ this.registryFile.effectLoader.load(this.setting),
124
+ ];
125
+ yield Promise.all(arr);
126
+ });
127
+ }
128
+ loadGamestate(gamestate) {
129
+ function getEffectFromSerialized(s, serialized_e) {
130
+ const newEff = s.registryFile.effectLoader.getEffect(serialized_e.dataID, s.setting, {
131
+ typeID: serialized_e.typeID,
132
+ subTypeIDs: serialized_e.subTypeIDs,
133
+ displayID_default: serialized_e.displayID_default
134
+ });
135
+ if (!newEff)
136
+ return newEff;
137
+ newEff.attr = new Map(Object.entries(serialized_e.attr));
138
+ return newEff;
139
+ }
140
+ this.player_stat = gamestate.players.map((p, index) => {
141
+ return {
142
+ playerType: p.pType,
143
+ playerIndex: index,
144
+ heart: p.heart,
145
+ maxHeart: p.heart,
146
+ operator: p.operator,
147
+ deck: p.deckName,
148
+ loadCardsInfo: []
149
+ };
150
+ });
151
+ this.turnCount = gamestate.turn;
152
+ this.waveCount = gamestate.wave;
153
+ this.zoneHandler.zoneArr = gamestate.zones.map((z, index) => {
154
+ const newZone = this.registryFile.zoneLoader.getZone(z.classID, this.setting, 0, 0, z.dataID);
155
+ if (!newZone)
156
+ throw new Error("Tried to load invalid state data");
157
+ newZone.attr = new Map(Object.entries(z.attr));
158
+ newZone.cardArr = z.cardArr.map(c => {
159
+ if (!c)
160
+ return c;
161
+ const newCard = this.registryFile.cardLoader.getCard(c.dataID, this.setting, c.variants);
162
+ if (!newCard)
163
+ return undefined;
164
+ newCard.partitionInfo = c.partitions;
165
+ newCard.attr = new Map(Object.entries(c.attr));
166
+ newCard.statusEffects = c.statusEffects.map(e => getEffectFromSerialized(this, e));
167
+ newCard.effects = c.effects.map(e => getEffectFromSerialized(this, e));
168
+ });
169
+ newZone.types = z.types;
170
+ return newZone;
171
+ });
172
+ this.restartTurn();
173
+ }
174
+ restartTurn(a) {
175
+ this.actionTree.clear();
176
+ if (a) {
177
+ this.actionTree.attach(a);
178
+ this.turnAction = a;
179
+ }
180
+ this.actionTree.attach(actionGenrator_1.actionConstructorRegistry.a_turn_start(actionGenrator_1.actionFormRegistry.system()));
181
+ this.actionTree.root.data.modifyAttr("doIncreaseTurnCount", true);
182
+ this.phaseIdx = systemRegistry_1.TurnPhase.declare;
183
+ }
184
+ resolveError(a) {
185
+ console.log(a.toString());
186
+ }
187
+ ___testAction(id) {
188
+ const oldF = this.registryFile.customActionLoader.___ObtainFunc(id);
189
+ let didCustomHandlerTriggered = false;
190
+ this.registryFile.customActionLoader.load(id, () => { didCustomHandlerTriggered = true; throw 0; });
191
+ try {
192
+ //Test forcing invaldi action to the handler
193
+ //if error or resolve normally without reaching custom action handler, we safe
194
+ const test = this.actionSwitch_resolve({ typeID: id });
195
+ if (oldF)
196
+ this.registryFile.customActionLoader.load(id, oldF);
197
+ else
198
+ this.registryFile.customActionLoader.delete(id);
199
+ return true;
200
+ }
201
+ catch (e) {
202
+ if (oldF)
203
+ this.registryFile.customActionLoader.load(id, oldF);
204
+ else
205
+ this.registryFile.customActionLoader.delete(id);
206
+ return !didCustomHandlerTriggered;
207
+ }
208
+ }
209
+ actionSwitch_resolve(a) {
210
+ //ok this is just a bunch of ifs
211
+ //lord forgive me for this
212
+ if (typeof a.typeID !== "number")
213
+ return [new errors_1.unregisteredAction(a)];
214
+ switch (a.typeID) {
215
+ case actionRegistry_1.default.a_null:
216
+ return;
217
+ case actionRegistry_1.default.error:
218
+ this.resolveError(a);
219
+ break; //break is intentional to access the default case
220
+ case actionRegistry_1.default.a_turn_start:
221
+ return; //turn start
222
+ case actionRegistry_1.default.a_turn_end:
223
+ {
224
+ //turn end
225
+ //merge statusEffects
226
+ this.zoneHandler.forEach(1, (c => {
227
+ c.mergeStatusEffect();
228
+ }));
229
+ if (a.flatAttr().doIncreaseTurnCount) {
230
+ return [
231
+ actionGenrator_1.actionConstructorRegistry.a_increase_turn_count(actionGenrator_1.actionFormRegistry.system())
232
+ ];
233
+ }
234
+ return;
235
+ }
236
+ ;
237
+ case actionRegistry_1.default.a_turn_reset:
238
+ return this.zoneHandler.handleTurnReset(this, a);
239
+ //note : may move the resolution of 6, 7, 8 to zone/system
240
+ case actionRegistry_1.default.a_increase_turn_count: {
241
+ this.turnCount++;
242
+ return;
243
+ }
244
+ case actionRegistry_1.default.a_set_threat_level: {
245
+ this.threatLevel = a.flatAttr().newThreatLevel;
246
+ if (this.threatLevel > this.maxThreatLevel) {
247
+ this.threatLevel = this.maxThreatLevel;
248
+ return [
249
+ actionGenrator_1.actionConstructorRegistry.a_do_threat_burn(actionGenrator_1.actionFormRegistry.system())
250
+ ];
251
+ }
252
+ return;
253
+ }
254
+ case actionRegistry_1.default.a_do_threat_burn: {
255
+ return this.zoneHandler.system.map((i, index) => i.doThreatBurn(this, this.player_stat[index])).reduce((res, ele) => res.concat(ele));
256
+ }
257
+ case actionRegistry_1.default.a_force_end_game: {
258
+ //end the game
259
+ //clear the tree
260
+ this.actionTree.clear();
261
+ this.suspensionReason = systemRegistry_1.suspensionReason.game_finished;
262
+ //am uhh not sure how to implememt this shit yet
263
+ //i think this is fine? for now?
264
+ this.suspend(this.actionTree.root.id);
265
+ return;
266
+ }
267
+ case actionRegistry_1.default.a_activate_effect_internal:
268
+ case actionRegistry_1.default.a_activate_effect:
269
+ // 5 and 101 resolves the same, just has different control flow
270
+ return this.zoneHandler.handleEffectActivation(this, a);
271
+ case actionRegistry_1.default.a_pos_change_force:
272
+ case actionRegistry_1.default.a_pos_change:
273
+ return this.zoneHandler.handlePosChange(this, a);
274
+ case actionRegistry_1.default.a_draw:
275
+ return this.zoneHandler.handleDraw(this, a);
276
+ case actionRegistry_1.default.a_shuffle:
277
+ return this.zoneHandler.handleShuffle(this, a);
278
+ case actionRegistry_1.default.a_execute:
279
+ return this.zoneHandler.handleExecute(this, a);
280
+ case actionRegistry_1.default.a_reprogram_start: {
281
+ //to be implemented
282
+ //note to future me
283
+ //make some kinda input_interface object
284
+ //plug it in here
285
+ return;
286
+ }
287
+ case actionRegistry_1.default.a_reprogram_end: {
288
+ //to be implemented
289
+ return;
290
+ }
291
+ case actionRegistry_1.default.a_add_status_effect: {
292
+ let s = a.flatAttr().typeID;
293
+ let eff = this.registryFile.effectLoader.getEffect(s, this.setting);
294
+ if (!eff || !(eff instanceof e_status_1.StatusEffect_base))
295
+ return [
296
+ new errors_1.cannotLoad(s, "statusEffect")
297
+ ];
298
+ return this.zoneHandler.handleAddStatusEffect(this, a, eff);
299
+ }
300
+ case actionRegistry_1.default.a_remove_status_effect:
301
+ return this.zoneHandler.handleRemoveStatusEffect(this, a);
302
+ case actionRegistry_1.default.a_activate_effect_subtype:
303
+ return this.zoneHandler.handleActivateEffectSubtypeFunc(this, a);
304
+ case actionRegistry_1.default.a_modify_action: {
305
+ let target = a.targets[0].action;
306
+ let modifyObj = a.flatAttr();
307
+ Object.entries(modifyObj).forEach(([key, val]) => {
308
+ if (key !== "type")
309
+ target.modifyAttr(key, val);
310
+ });
311
+ return;
312
+ }
313
+ case actionRegistry_1.default.a_reset_card:
314
+ return this.zoneHandler.handleCardReset(this, a);
315
+ case actionRegistry_1.default.a_replace_action:
316
+ case actionRegistry_1.default.a_negate_action: return; //tecnically not possible
317
+ case actionRegistry_1.default.a_clear_all_status_effect:
318
+ return this.zoneHandler.handleClearAllStatusEffect(this, a);
319
+ case actionRegistry_1.default.a_reset_effect:
320
+ return this.zoneHandler.handleEffectReset(this, a);
321
+ case actionRegistry_1.default.a_enable_card:
322
+ return this.zoneHandler.handleCardStatus(this, a);
323
+ case actionRegistry_1.default.a_disable_card:
324
+ return this.zoneHandler.handleCardStatus(this, a);
325
+ case actionRegistry_1.default.a_attack:
326
+ return this.zoneHandler.handleAttack(this, a);
327
+ case actionRegistry_1.default.a_deal_damage_internal:
328
+ case actionRegistry_1.default.a_deal_damage_card:
329
+ return this.zoneHandler.handleDealDamage_1(this, a);
330
+ case actionRegistry_1.default.a_deal_damage_position:
331
+ return this.zoneHandler.handleDealDamage_2(this, a);
332
+ case actionRegistry_1.default.a_deal_heart_damage:
333
+ let pid = a.targets[0].id;
334
+ let dmg = a.flatAttr().dmg;
335
+ if (this.player_stat[pid])
336
+ this.player_stat[pid].heart -= dmg;
337
+ return;
338
+ case actionRegistry_1.default.a_decompile:
339
+ case actionRegistry_1.default.a_destroy:
340
+ return this.zoneHandler.handleSendToTop(this, a, zoneRegistry_1.zoneRegistry.z_grave);
341
+ case actionRegistry_1.default.a_void:
342
+ return this.zoneHandler.handleSendToTop(this, a, zoneRegistry_1.zoneRegistry.z_void);
343
+ case actionRegistry_1.default.a_zone_interact:
344
+ return this.zoneHandler.handleZoneInteract(a.targets[0].zone, this, a);
345
+ //TODO : add the missing actions
346
+ default: {
347
+ //only should reach here iff effect is unregistered
348
+ //technically this is unreachable code but who knows
349
+ //let unhandledID = a.typeID //if this is never, we checked every cases
350
+ //new note
351
+ //mods may emit new undefined actions
352
+ //go to zone handler to fix this shit
353
+ // console.log("Unhandle case reached, ", a.typeID)
354
+ return this.registryFile.customActionLoader.handle(a.typeID, a, this);
355
+ }
356
+ }
357
+ }
358
+ start() {
359
+ this.renderer.turnStart(this.toLocalized(), this.processTurn.bind(this));
360
+ }
361
+ processTurn(param) {
362
+ if (!param) {
363
+ console.log("finish processing turn");
364
+ return true;
365
+ }
366
+ let n;
367
+ if (param instanceof node_1.default) {
368
+ n = param;
369
+ }
370
+ else {
371
+ this.restartTurn(param);
372
+ this.phaseIdx = 1;
373
+ n = this.actionTree.getNext();
374
+ if (!n)
375
+ return true;
376
+ this.suspend(n.id);
377
+ this.suspensionReason = false;
378
+ this.renderer.gameStart(this.toLocalized(), this.continue.bind(this));
379
+ return false;
380
+ }
381
+ // while(n){
382
+ let doGetNewNode = this.process(n);
383
+ if (this.suspendID !== -1) {
384
+ if (!this.curr_input_obj)
385
+ throw Error("Somehow suspended but dont want to input");
386
+ this.suspend(n.id);
387
+ this.suspensionReason = false;
388
+ let inputArr;
389
+ const input = this.curr_input_obj.requester.next();
390
+ if (input[1])
391
+ inputArr = input[1];
392
+ else
393
+ inputArr = this.getAllInputs(input[0], true);
394
+ this.renderer.requestInput(inputArr, this.phaseIdx, this.toLocalized(), n.data, this.continue.bind(this));
395
+ return false;
396
+ }
397
+ ;
398
+ const oldAction = n.data;
399
+ if (doGetNewNode)
400
+ n = this.actionTree.getNext();
401
+ if (!n)
402
+ return true;
403
+ this.suspend(n.id);
404
+ this.suspensionReason = false;
405
+ this.renderer.update(this.phaseIdx, this.toLocalized(), oldAction, this.continue.bind(this));
406
+ return false;
407
+ // }
408
+ }
409
+ process(n) {
410
+ //[phase progression graph:
411
+ //v--------------\--------------\
412
+ //1 -> 2 -> 3 -> 4 5 -> 6 -> 7
413
+ //\--if visited once--^
414
+ //technically 6 needs to go to 1 and loop through all again but screw it,
415
+ //we already resolved the dang thing, just mark it as complete and move on
416
+ // if(!n) {
417
+ // console.log("finish processing turn, clearing tree");
418
+ // this.restartTurn();
419
+ // return;
420
+ // }
421
+ switch (this.phaseIdx) {
422
+ case systemRegistry_1.TurnPhase.declare: {
423
+ //declare step
424
+ this.fullLog.push({
425
+ currentPhase: 1,
426
+ currentAction: n.data
427
+ });
428
+ if (n.id === this.processStack.at(-1)) {
429
+ this.phaseIdx = systemRegistry_1.TurnPhase.resolve;
430
+ return this.process(n);
431
+ }
432
+ // console.log("declare action: " + n.data.type)
433
+ this.phaseIdx = systemRegistry_1.TurnPhase.input;
434
+ return false;
435
+ }
436
+ case systemRegistry_1.TurnPhase.input: {
437
+ //handle input
438
+ this.fullLog.push({
439
+ currentPhase: 2,
440
+ currentAction: n.data
441
+ });
442
+ this.phaseIdx = systemRegistry_1.TurnPhase.chain;
443
+ if (n.data.is("a_get_input")) {
444
+ return this.inputHandler(n.data, n);
445
+ }
446
+ return false;
447
+ }
448
+ case systemRegistry_1.TurnPhase.chain: {
449
+ //chain step
450
+ let [actionArr, logInfo] = this.zoneHandler.respond(this, n.data, !n.data.canBeChainedTo);
451
+ this.fullLog.push({
452
+ currentPhase: 3,
453
+ currentAction: n.data,
454
+ responses: Object.fromEntries(logInfo)
455
+ });
456
+ const forcedActions = actionArr.filter(a => a.isCost);
457
+ //special handled
458
+ const isNegated = actionArr.some(i => i.id === actionRegistry_1.default.a_negate_action);
459
+ let gotoComplete = isNegated;
460
+ let replacements = actionArr.filter(a => a.is("a_replace_action")).map(i => i.targets[0].action);
461
+ if (replacements.length) {
462
+ gotoComplete = true;
463
+ actionArr = forcedActions.concat(replacements);
464
+ }
465
+ if (isNegated)
466
+ actionArr = forcedActions;
467
+ actionArr.forEach(i => {
468
+ if (i.isChain)
469
+ this.actionTree.attach_node(n, i);
470
+ else
471
+ this.actionTree.attach_node(this.actionTree.root, i);
472
+ });
473
+ this.phaseIdx = (gotoComplete) ? systemRegistry_1.TurnPhase.complete : systemRegistry_1.TurnPhase.recur;
474
+ return false;
475
+ }
476
+ case systemRegistry_1.TurnPhase.recur: {
477
+ //recur step
478
+ //recur until the last element of processStack is reached
479
+ //then that element is removed
480
+ this.fullLog.push({
481
+ currentPhase: 4,
482
+ currentAction: n.data
483
+ });
484
+ this.processStack.push(n.id);
485
+ this.phaseIdx = 1;
486
+ return true;
487
+ }
488
+ case systemRegistry_1.TurnPhase.resolve: {
489
+ //resolve
490
+ this.processStack.pop();
491
+ let x = this.actionSwitch_resolve(n.data);
492
+ if (x) {
493
+ x.forEach(i => {
494
+ if (i.isChain)
495
+ this.actionTree.attachArbitrary(n.id, i);
496
+ else
497
+ this.actionTree.attachArbitrary(this.actionTree.root.id, i);
498
+ });
499
+ }
500
+ this.fullLog.push({
501
+ currentPhase: 5,
502
+ currentAction: n.data,
503
+ resolvedResult: (x) ? x : []
504
+ });
505
+ // console.log("finish resolving acion: " + n.data.type)
506
+ if (n.data.canBeTriggeredTo)
507
+ this.phaseIdx = systemRegistry_1.TurnPhase.trigger;
508
+ else
509
+ this.phaseIdx = systemRegistry_1.TurnPhase.complete; //6 is skipped
510
+ return false;
511
+ }
512
+ case systemRegistry_1.TurnPhase.trigger: {
513
+ //trigger
514
+ let [actionArr, logInfo] = this.zoneHandler.respond(this, n.data, !n.data.canBeTriggeredTo);
515
+ this.fullLog.push({
516
+ currentPhase: 6,
517
+ currentAction: n.data,
518
+ responses: Object.fromEntries(logInfo)
519
+ });
520
+ actionArr = actionArr.map(i => {
521
+ if (i.is("a_replace_action"))
522
+ return i.targets[0].action;
523
+ return i;
524
+ });
525
+ actionArr.forEach(i => {
526
+ if (i.isChain)
527
+ this.actionTree.attach_node(n, i);
528
+ else
529
+ this.actionTree.attach_node(this.actionTree.root, i);
530
+ });
531
+ this.phaseIdx = systemRegistry_1.TurnPhase.complete;
532
+ return false;
533
+ }
534
+ case systemRegistry_1.TurnPhase.complete: {
535
+ //complete
536
+ this.fullLog.push({
537
+ currentPhase: 7,
538
+ currentAction: n.data
539
+ });
540
+ n.markComplete();
541
+ this.phaseIdx = systemRegistry_1.TurnPhase.declare;
542
+ return true;
543
+ }
544
+ }
545
+ console.log("accessed invalid phaseIdx: " + this.phaseIdx);
546
+ return false;
547
+ }
548
+ suspend(nid) {
549
+ this.suspendID = nid;
550
+ }
551
+ verifyInput(i1, i2) {
552
+ if (i1.type !== i2.type)
553
+ return false;
554
+ switch (i1.type) {
555
+ case systemRegistry_1.inputType.boolean: return i2.data === i1.data;
556
+ case systemRegistry_1.inputType.number: return i2.data === i1.data;
557
+ case systemRegistry_1.inputType.string: return i2.data === i1.data;
558
+ case systemRegistry_1.inputType.card: return i1.data instanceof card_1.default && i2.data instanceof card_1.default && i2.data.is(i1.data);
559
+ case systemRegistry_1.inputType.effect: return i1.data instanceof effect_1.default && i2.data instanceof effect_1.default && i2.data.is(i1.data);
560
+ case systemRegistry_1.inputType.effectSubtype: return i1.data instanceof effectSubtype_1.default && i2.data instanceof effectSubtype_1.default && i2.data.is(i1.data);
561
+ case systemRegistry_1.inputType.player: return typeof i1.data.id === i2.data.id;
562
+ case systemRegistry_1.inputType.position: return i2.data instanceof position_1.default && i1.data.is(i2.data);
563
+ case systemRegistry_1.inputType.zone: return i2.data instanceof zone_1.default && i1.data.is(i2.data);
564
+ }
565
+ return false;
566
+ }
567
+ inputHandler(a, n) {
568
+ console.log("processing input");
569
+ this.curr_input_obj = a.flatAttr();
570
+ let requester = this.curr_input_obj.requester;
571
+ const applicator = this.curr_input_obj.applicator;
572
+ if (!requester.hasInput()) {
573
+ console.log("blank input, skipped, logging fullObject: ", this.curr_input_obj);
574
+ this.phaseIdx = systemRegistry_1.TurnPhase.complete;
575
+ return false;
576
+ }
577
+ let final = undefined; //assign to this to NOT suspend
578
+ if (requester.isFinalized()) {
579
+ final = applicator.apply(requester);
580
+ }
581
+ else {
582
+ let [i_type, i_set] = requester.next();
583
+ //returns if break of not
584
+ function proceed(t, input) {
585
+ requester = requester.apply(t, input);
586
+ if (requester.isFinalized()) {
587
+ return applicator.apply(requester);
588
+ }
589
+ //fail safe check
590
+ if (!requester.hasInput()) {
591
+ t.curr_input_obj = undefined;
592
+ return [];
593
+ }
594
+ ;
595
+ [i_type, i_set] = requester.next();
596
+ }
597
+ switch (this.setting.auto_input) {
598
+ case settings_1.auto_input_option.first: {
599
+ while (true) {
600
+ let input = i_set ? i_set[0] : this.getAllInputs(i_type, true)[0];
601
+ const k = proceed(this, input);
602
+ if (k !== undefined) {
603
+ final = k;
604
+ break;
605
+ }
606
+ ;
607
+ }
608
+ break;
609
+ }
610
+ case settings_1.auto_input_option.last: {
611
+ while (true) {
612
+ let input = i_set ? i_set.at(-1) : this.getAllInputs(i_type, true).at(-1);
613
+ const k = proceed(this, input);
614
+ if (k !== undefined) {
615
+ final = k;
616
+ break;
617
+ }
618
+ ;
619
+ }
620
+ break;
621
+ }
622
+ case settings_1.auto_input_option.random: {
623
+ while (true) {
624
+ let input = i_set ? Utils.getRandomElement(i_set) : Utils.getRandomElement(this.getAllInputs(i_type, true));
625
+ const k = proceed(this, input);
626
+ if (k !== undefined) {
627
+ final = k;
628
+ break;
629
+ }
630
+ ;
631
+ }
632
+ }
633
+ case settings_1.auto_input_option.default: {
634
+ while (true) {
635
+ //Because of this condition, inputRequester_multiple is NOT applied automatically
636
+ //i.e input wants 2 zones, we have 2 zones, but we aint apply any cause its not 1
637
+ //this is...technically intended
638
+ //for now, since idk how to fix this
639
+ //inputs can merge afterall
640
+ if (!i_set || i_set.length !== 1)
641
+ break;
642
+ let input = i_set[0];
643
+ const k = proceed(this, input);
644
+ if (k !== undefined) {
645
+ final = k;
646
+ break;
647
+ }
648
+ ;
649
+ }
650
+ }
651
+ }
652
+ }
653
+ if (final === undefined) {
654
+ console.log("suspending waiting for inputs");
655
+ this.suspensionReason = systemRegistry_1.suspensionReason.taking_input;
656
+ this.suspend(a.id);
657
+ return false;
658
+ }
659
+ else {
660
+ console.log("inputs getting skipped, trying to apply");
661
+ this.suspensionReason = false;
662
+ this.curr_input_obj = undefined;
663
+ this.actionTree.attach_node(n, ...final);
664
+ n.markComplete();
665
+ this.phaseIdx = systemRegistry_1.TurnPhase.declare; //unwind back to declare;
666
+ this.suspendID = -1;
667
+ return true;
668
+ }
669
+ }
670
+ getAllInputs(t, force, count) {
671
+ force = Number(force);
672
+ switch (t) {
673
+ case systemRegistry_1.inputType.boolean: return force ? [{
674
+ type: systemRegistry_1.inputType.boolean,
675
+ data: Utils.rng(1, 0, true) === 1
676
+ }] : undefined;
677
+ case systemRegistry_1.inputType.number: return force ? [{
678
+ type: systemRegistry_1.inputType.number,
679
+ data: Utils.rng(100, 0, true)
680
+ }] : undefined;
681
+ case systemRegistry_1.inputType.string: return force ? [{
682
+ type: systemRegistry_1.inputType.string,
683
+ data: Utils.generateID()
684
+ }] : undefined;
685
+ case systemRegistry_1.inputType.zone: return this.map(0, z => actionInputGenerator_1.inputFormRegistry.zone(this, z));
686
+ case systemRegistry_1.inputType.card: return this.map(1, c => actionInputGenerator_1.inputFormRegistry.card(this, c));
687
+ case systemRegistry_1.inputType.player: return this.player_stat.map((_, pid) => actionInputGenerator_1.inputFormRegistry.player(this, pid));
688
+ case systemRegistry_1.inputType.position: {
689
+ let res = [];
690
+ this.forEach(0, z => res.push(...z.getAllPos()));
691
+ return res.map(pos => actionInputGenerator_1.inputFormRegistry.pos(this, pos));
692
+ }
693
+ case systemRegistry_1.inputType.effect: return this.map(2, (e, zid, cid) => {
694
+ const zone = this.zoneArr[zid];
695
+ const c = zone.cardArr[cid];
696
+ return actionInputGenerator_1.inputFormRegistry.effect(this, c, e);
697
+ });
698
+ case systemRegistry_1.inputType.effectSubtype: return this.map(3, (st, zid, cid, eid) => {
699
+ const zone = this.zoneArr[zid];
700
+ const c = zone.cardArr[cid];
701
+ const e = c.totalEffects[eid];
702
+ return actionInputGenerator_1.inputFormRegistry.subtype(this, c, e, st);
703
+ });
704
+ }
705
+ throw new Error(`get all input failed, type = ${t}`);
706
+ }
707
+ generateSignature(a) {
708
+ if (a == undefined)
709
+ return Utils.generateID();
710
+ switch (a.type) {
711
+ case systemRegistry_1.inputType.number:
712
+ case systemRegistry_1.inputType.string:
713
+ case systemRegistry_1.inputType.boolean: return String(a.data);
714
+ case systemRegistry_1.inputType.zone: return String(a.data.zone.id);
715
+ case systemRegistry_1.inputType.card: return a.data.card.id;
716
+ case systemRegistry_1.inputType.effect: return a.data.eff.id;
717
+ case systemRegistry_1.inputType.effectSubtype: return a.data.eff.id + a.data.subtype.dataID;
718
+ case systemRegistry_1.inputType.player: return String(a.data.id);
719
+ case systemRegistry_1.inputType.position: return a.data.pos.toString();
720
+ }
721
+ }
722
+ continue(input) {
723
+ let n = this.actionTree.getNode(this.suspendID);
724
+ if (this.suspensionReason === systemRegistry_1.suspensionReason.taking_input && n.data.is("a_get_input")) {
725
+ if (this.curr_input_obj === undefined || input === undefined) {
726
+ throw new Error("Cannot unsuspend, not enough input taken");
727
+ }
728
+ const requester = this.curr_input_obj.requester;
729
+ const applicator = this.curr_input_obj.applicator;
730
+ if (!requester.hasInput()) {
731
+ throw new Error("Cannot unsuspend, invalid input object");
732
+ }
733
+ let [i_type, i_set] = requester.next();
734
+ //check validity of input
735
+ //naive? check
736
+ if (i_set !== undefined) { //undefined is accept all
737
+ const filter_set = i_set.filter(i => i.type === input.type);
738
+ if (!filter_set.length) {
739
+ throw new Error("input not in valid set, wrong type");
740
+ }
741
+ const flag = filter_set.some(i => {
742
+ this.verifyInput(i, input);
743
+ });
744
+ if (!flag) {
745
+ throw new Error("input not in valid set, correct type but wrong id");
746
+ }
747
+ }
748
+ else if (input.type !== i_type) {
749
+ throw new Error(`input type is incorrect, received : ${input.type}, wanted : ${i_type}`);
750
+ }
751
+ let res = this.inputHandler(n.data, n);
752
+ //complete
753
+ if (res)
754
+ return this.processTurn();
755
+ else {
756
+ console.log("Input taken, but unfinished, please continue");
757
+ let inputArr;
758
+ const input = requester.next();
759
+ if (input[1])
760
+ inputArr = input[1];
761
+ else
762
+ inputArr = this.getAllInputs(input[0], true);
763
+ this.renderer.requestInput(inputArr, this.phaseIdx, this.toLocalized(), n.data, this.continue.bind(this));
764
+ return false;
765
+ }
766
+ }
767
+ else if (this.suspensionReason !== false)
768
+ throw new Error(`Cannot unsuspend when reason is not resolved`);
769
+ this.suspendID = -1;
770
+ return this.processTurn(n);
771
+ }
772
+ //Parsing log API
773
+ //the weird reduce thiny is equivalent to .flat(2), done since .flat is not available for es6
774
+ getActivatedEffectIDs() {
775
+ return this.fullLog.map(i => {
776
+ if (i.currentPhase !== 3 && i.currentPhase !== 6)
777
+ return [];
778
+ return Object.values(i.responses).reduce((accu, ele) => accu.concat(ele));
779
+ }).reduce((accu, ele) => accu.concat(ele));
780
+ }
781
+ getActivatedCardIDs() {
782
+ return this.fullLog.map(i => {
783
+ if (i.currentPhase !== 3 && i.currentPhase !== 6)
784
+ return [];
785
+ return Object.values(i.responses).reduce((accu, ele) => accu.concat(ele));
786
+ }).reduce((accu, ele) => accu.concat(ele));
787
+ }
788
+ getResolvedActions() {
789
+ return this.fullLog.map(i => {
790
+ if (i.currentPhase !== 5)
791
+ return undefined;
792
+ return i.currentAction;
793
+ }).filter(i => i !== undefined);
794
+ }
795
+ //more API ported from dry_system
796
+ getCardWithID(cid) {
797
+ return this.zoneHandler.getCardWithID(cid);
798
+ }
799
+ getCardWithDataID(cid) {
800
+ return this.zoneHandler.filter(1, c => c.id === cid);
801
+ }
802
+ getZoneWithID(zid) {
803
+ return this.zoneHandler.getZoneWithID(zid);
804
+ }
805
+ getZoneOf(obj) {
806
+ return this.zoneHandler.getZoneWithID(obj.pos.zoneID);
807
+ }
808
+ get zoneArr() { return this.zoneHandler.zoneArr; }
809
+ get resolutionLog() {
810
+ return this.fullLog.filter(i => i.currentPhase === systemRegistry_1.TurnPhase.resolve);
811
+ }
812
+ get chainLog() {
813
+ return this.fullLog.filter(i => i.currentPhase === systemRegistry_1.TurnPhase.chain);
814
+ }
815
+ get triggerLog() {
816
+ return this.fullLog.filter(i => i.currentPhase === systemRegistry_1.TurnPhase.trigger);
817
+ }
818
+ get completionLog() {
819
+ return this.fullLog.filter(i => i.currentPhase === systemRegistry_1.TurnPhase.complete);
820
+ }
821
+ hasActionCompleted(a, startSearchingIndex = 0) {
822
+ for (let i = startSearchingIndex; i < this.fullLog.length; i++) {
823
+ if (this.fullLog[i].currentPhase === systemRegistry_1.TurnPhase.complete) {
824
+ if (this.fullLog[i].currentAction.id === a.id)
825
+ return true;
826
+ }
827
+ }
828
+ return false;
829
+ }
830
+ /**
831
+ * Finds a chain of action A -> resolved to B -> resolved to C -> ...
832
+ * @param typeArr : action types to search
833
+ * @returns Action[] if success, unefined if not
834
+ *
835
+ *
836
+ * Search is first comes first serve, B is the first in the resoution log of A that has the wanted type (id 1 in the arr)
837
+ */
838
+ findSpecificChainOfAction_resolve(typeArr) {
839
+ if (!typeArr.length)
840
+ return [];
841
+ let res = [];
842
+ let candidateResolveLog = this.resolutionLog.find(k => k.currentAction.type === typeArr[0]);
843
+ if (!candidateResolveLog)
844
+ return undefined;
845
+ res.push(candidateResolveLog.currentAction);
846
+ if (typeArr.length === 1)
847
+ return res;
848
+ for (let i = 1; i < typeArr.length; i++) {
849
+ let matchedNext = candidateResolveLog.resolvedResult.find(k => k.type === typeArr[i]);
850
+ if (!matchedNext)
851
+ return undefined;
852
+ candidateResolveLog = this.resolutionLog.find(k => k.currentAction.id === matchedNext.id);
853
+ if (!candidateResolveLog)
854
+ return undefined;
855
+ res.push(candidateResolveLog.currentAction);
856
+ }
857
+ return res;
858
+ }
859
+ /**
860
+ * Parses the whole log though the condition funciton, tally and returns the result
861
+ * @param condition a function that returns a thing parsable to a number
862
+ * @param stopEarlyCount a count that if reached, will return early
863
+ * @returns total count
864
+ *
865
+ *
866
+ */
867
+ count(condition, stopEarlyCount) {
868
+ let c = 0;
869
+ if (stopEarlyCount === undefined)
870
+ stopEarlyCount = Infinity;
871
+ for (let i = 0; i < this.fullLog.length; i++) {
872
+ c += Utils.toSafeNumber(condition(this.fullLog[i]), true);
873
+ if (c >= stopEarlyCount)
874
+ return c;
875
+ }
876
+ return c;
877
+ }
878
+ getAllZonesOfPlayer(pid) {
879
+ if (pid < 0)
880
+ return {};
881
+ let res = {};
882
+ this.zoneArr.forEach(val => {
883
+ if (val.playerIndex === pid)
884
+ val.types.forEach(i => res[i] ? res[i].push(val) : res[i] = [val]);
885
+ });
886
+ return res;
887
+ }
888
+ getPIDof(c) {
889
+ const z = this.getZoneOf(c);
890
+ if (!z)
891
+ return NaN;
892
+ return z.playerIndex;
893
+ }
894
+ is(c, type) {
895
+ const z = this.getZoneWithID(c.pos.zoneID);
896
+ if (!z)
897
+ return false;
898
+ return z.is(type);
899
+ }
900
+ get isInTriggerPhase() { return this.phaseIdx === systemRegistry_1.TurnPhase.trigger; }
901
+ get isInChainPhase() { return this.phaseIdx === systemRegistry_1.TurnPhase.chain; }
902
+ requestInput_zone_default(c, zType, fz) {
903
+ return this.posCheck(c) ? new actionInputGenerator_1.inputRequester(systemRegistry_1.inputType.zone, this.getAllInputs(systemRegistry_1.inputType.zone, true).filter(i => i.is(zType) && i.of(this.getZoneOf(c)) && (!fz || fz(this, i.data.zone)))) :
904
+ new actionInputGenerator_1.inputRequester(systemRegistry_1.inputType.zone, this.getAllInputs(systemRegistry_1.inputType.zone, true).filter(i => i.is(zType) && i.of(c) && (!fz || fz(this, i.data.zone))));
905
+ }
906
+ requestInput_card_default(c, zType, fz, fc) {
907
+ return this.requestInput_zone_default(c, zType, fz).extend(this, (s, prev) => {
908
+ const z = prev[0].data.zone;
909
+ return z.cardArr_filtered.filter(c => (!fc || fc(s, c, z))).map(c => actionInputGenerator_1.inputFormRegistry.card(s, c));
910
+ });
911
+ }
912
+ requestInput_effect_default(c, zType, getRealEffects, getStatusEffects, fz, fc, feff) {
913
+ return this.requestInput_card_default(c, zType, fz, fc).extend(this, (s, prev) => {
914
+ const z = prev[0].data.zone;
915
+ const c = prev[1].data.card;
916
+ let eArr = (getRealEffects ? c.effects : []).map(i => i);
917
+ if (getStatusEffects)
918
+ eArr.push(...c.statusEffects);
919
+ return eArr.filter(e => (!feff || feff(s, e, c, z))).map(e => actionInputGenerator_1.inputFormRegistry.effect(s, c, e));
920
+ });
921
+ }
922
+ requestInput_effectSubtype_default(c, zType, getRealEffects, getStatusEffects, fz, fc, feff, fst) {
923
+ return this.requestInput_effect_default(c, zType, getRealEffects, getStatusEffects, fz, fc, feff).extend(this, (s, prev) => {
924
+ const z = prev[0].data.zone;
925
+ const c = prev[2].data.card;
926
+ const e = prev[2].data.eff;
927
+ return e.subTypes.filter(st => (!fst || fst(s, st, e, c, z))).map(st => actionInputGenerator_1.inputFormRegistry.subtype(s, c, e, st));
928
+ });
929
+ }
930
+ requestInput_pos_default(c, zType, getFreeOnly, fz, fpos) {
931
+ return this.requestInput_zone_default(c, zType, fz).extend(this, (s, prev) => {
932
+ const z = prev[0].data.zone;
933
+ const pArr = getFreeOnly ? (z.getEmptyPosArr ? z.getEmptyPosArr() : [z.lastPos]) : z.getAllPos();
934
+ return pArr.filter(pos => (!fpos || fpos(s, pos, z))).map(pos => actionInputGenerator_1.inputFormRegistry.pos(s, pos));
935
+ });
936
+ }
937
+ getWouldBeAttackTarget(a) {
938
+ return this.zoneHandler.getWouldBeAttackTarget(this, a);
939
+ }
940
+ // hasValidInput(depth : 0, fz? : (s : dry_system, z : dry_zone) => boolean) : boolean;
941
+ // hasValidInput(depth : 1, fz? : (s : dry_system, z : dry_zone) => boolean, fc? : (s : dry_system, c : dry_card, z : dry_zone) => boolean) : boolean;
942
+ // hasValidInput(depth : 2, fz? : (s : dry_system, z : dry_zone) => boolean, fc? : (s : dry_system, c : dry_card, z : dry_zone) => boolean, fe? : (s : dry_system, e : dry_effect, c : dry_card, z : dry_zone) => boolean) : boolean;
943
+ // hasValidInput(depth : 3, fz? : (s : dry_system, z : dry_zone) => boolean, fc? : (s : dry_system, c : dry_card, z : dry_zone) => boolean, fe? : (s : dry_system, e : dry_effect, c : dry_card, z : dry_zone) => boolean, fst? : (s : dry_system, st : dry_effectSubType, e : dry_effect, c : dry_card, z : dry_zone) => boolean) : boolean;
944
+ // hasValidInput(depth : 4, fz? : (s : dry_system, z : dry_zone) => boolean, fpos? : (s : dry_system, p : dry_position, z : dry_zone) => boolean) : boolean;
945
+ // hasValidInput(
946
+ // depth : 0 | 1 | 2 | 3 | 4,
947
+ // fz? : (s : dry_system, z : dry_zone) => boolean,
948
+ // fc? : ((s : dry_system, c : dry_card, z : dry_zone) => boolean) | ((s : dry_system, p : dry_position, z : dry_zone) => boolean),
949
+ // fe? : (s : dry_system, e : dry_effect, c : dry_card, z : dry_zone) => boolean,
950
+ // fst? : (s : dry_system, st : dry_effectSubType, e : dry_effect, c : dry_card, z : dry_zone) => boolean
951
+ // ) : boolean {
952
+ // const k = this.requestInput(depth as 3, fz, fc as any, fe, fst);
953
+ // return k[0][1] === undefined || k[0][1].length !== 0
954
+ // }
955
+ // hasValidInput_zone_default(c : Positionable | Player_specific, zType : zoneRegistry, f? : (s : dry_system, z : dry_zone) => boolean){
956
+ // return this.posCheck(c) ? this.hasValidInput(0, (s : dry_system, z : dry_zone) => z.is(zType) && z.of(s.getZoneOf(c)) && (f === undefined || f(s, z)))
957
+ // : this.hasValidInput(0, (s : dry_system, z : dry_zone) => z.is(zType) && z.playerIndex === c.playerIndex && (f === undefined || f(s, z)))
958
+ // }
959
+ // hasValidInput_card_default(c : Positionable, zType : zoneRegistry, fc? : (s : dry_system, c : dry_card, z : dry_zone) => boolean){
960
+ // return this.hasValidInput(1, (s : dry_system, z : dry_zone) => z.is(zType) && z.of(s.getZoneOf(c)), fc)
961
+ // }
962
+ // hasValidInput_pos_default(c : Positionable, zType : zoneRegistry, getFreeOnly : boolean, fpos? : (s : dry_system, p : dry_position, z : dry_zone) => boolean){
963
+ // return this.hasValidInput(
964
+ // 4,
965
+ // (s : dry_system, z : dry_zone) => z.is(zType) && z.of(s.getZoneOf(c)),
966
+ // (!getFreeOnly && fpos === undefined) ? undefined : (s : dry_system, p : dry_position, z : dry_zone) => {
967
+ // const p1 = (!getFreeOnly || !z.isOccupied(p))
968
+ // const p2 = fpos ? fpos(this, p, z) : true
969
+ // return p1 && p2
970
+ // }
971
+ // )
972
+ //}
973
+ posCheck(a) {
974
+ return a.pos instanceof position_1.default;
975
+ }
976
+ isNotActionArr(gen) {
977
+ if (!Array.isArray(gen))
978
+ return false;
979
+ return gen.some(i => !(i instanceof actionGenrator_1.Action_class));
980
+ }
981
+ isPlayAction(a) {
982
+ if (!(a.is("a_pos_change") || a.is("a_pos_change_force")))
983
+ return false;
984
+ const zoneTo = this.getZoneWithID(a.targets[1].pos.zoneID);
985
+ const cond1 = zoneTo ? zoneTo.is(zoneRegistry_1.zoneRegistry.z_field) : false;
986
+ const cond2 = a.targets[0].card.isFrom(this, zoneRegistry_1.zoneRegistry.z_hand);
987
+ return cond1 && cond2;
988
+ }
989
+ toSerialized() {
990
+ return new Gamestate_1.SerializedSystem(this.player_stat.map(p => new Gamestate_1.SerializedPlayer(p.playerType, p.heart, p.operator, p.deck)), this.zoneArr.map(z => new Gamestate_1.SerializedZone(z.classID, z.dataID, z.cardArr.map(c => c ? new Gamestate_1.SerializedCard(c.dataID, c.variants, c.effects.map(e => new Gamestate_1.Serialized_effect(e.dataID, e.type.dataID, e.subTypes.map(st => st.dataID), e.displayID, e.attr)), c.statusEffects.map(e => new Gamestate_1.Serialized_effect(e.dataID, e.type.dataID, e.subTypes.map(st => st.dataID), e.displayID, e.attr)), c.partitionInfo, c.attr) : c), z.types.slice(), z.attr)), this.turnCount, this.waveCount);
991
+ }
992
+ toLocalized(mode) {
993
+ return this.localizer.localizeSystem(this, mode);
994
+ }
995
+ }
996
+ exports.default = queenSystem;