libram 0.7.10 → 0.7.13

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 (147) hide show
  1. package/dist/Clan.d.ts +34 -6
  2. package/dist/Clan.js +33 -6
  3. package/dist/Copier.d.ts +5 -5
  4. package/dist/Dungeon.d.ts +45 -0
  5. package/dist/Dungeon.js +115 -0
  6. package/dist/Kmail.d.ts +8 -5
  7. package/dist/Kmail.js +8 -5
  8. package/dist/actions/ActionSource.d.ts +5 -0
  9. package/dist/actions/ActionSource.js +20 -1
  10. package/dist/actions/FreeKill.d.ts +2 -0
  11. package/dist/actions/FreeKill.js +2 -0
  12. package/dist/actions/FreeRun.d.ts +2 -0
  13. package/dist/actions/FreeRun.js +2 -0
  14. package/dist/ascend.d.ts +20 -4
  15. package/dist/ascend.js +38 -10
  16. package/dist/challengePaths/2015/CommunityService.d.ts +7 -0
  17. package/dist/challengePaths/2015/CommunityService.js +17 -5
  18. package/dist/combat.d.ts +63 -2
  19. package/dist/combat.js +99 -5
  20. package/dist/counter.d.ts +3 -0
  21. package/dist/counter.js +3 -0
  22. package/dist/diet/index.d.ts +2 -0
  23. package/dist/diet/index.js +27 -8
  24. package/dist/diet/knapsack.d.ts +1 -0
  25. package/dist/diet/knapsack.js +11 -3
  26. package/dist/index.d.ts +2 -4
  27. package/dist/index.js +1 -3
  28. package/dist/lib.d.ts +101 -34
  29. package/dist/lib.js +133 -42
  30. package/dist/logger.d.ts +24 -11
  31. package/dist/logger.js +38 -12
  32. package/dist/maximize.d.ts +25 -0
  33. package/dist/maximize.js +31 -4
  34. package/dist/modifier.d.ts +1 -1
  35. package/dist/modifier.js +9 -1
  36. package/dist/mood.d.ts +15 -1
  37. package/dist/mood.js +15 -1
  38. package/dist/property.d.ts +52 -17
  39. package/dist/property.js +64 -7
  40. package/dist/propertyTypes.d.ts +6 -6
  41. package/dist/propertyTypes.js +6 -6
  42. package/dist/propertyTyping.d.ts +54 -0
  43. package/dist/propertyTyping.js +54 -0
  44. package/dist/resources/2008/Stickers.d.ts +28 -0
  45. package/dist/resources/2008/Stickers.js +28 -0
  46. package/dist/resources/2009/Bandersnatch.d.ts +17 -7
  47. package/dist/resources/2009/Bandersnatch.js +17 -7
  48. package/dist/resources/2009/SpookyPutty.d.ts +25 -0
  49. package/dist/resources/2009/SpookyPutty.js +25 -0
  50. package/dist/resources/2010/CrownOfThrones.d.ts +23 -0
  51. package/dist/resources/2010/CrownOfThrones.js +31 -15
  52. package/dist/resources/2010/LookingGlass.d.ts +4 -0
  53. package/dist/resources/2010/LookingGlass.js +5 -0
  54. package/dist/resources/2011/ObtuseAngel.d.ts +8 -6
  55. package/dist/resources/2011/ObtuseAngel.js +8 -6
  56. package/dist/resources/2011/StompingBoots.d.ts +9 -15
  57. package/dist/resources/2011/StompingBoots.js +9 -15
  58. package/dist/resources/2012/RainDoh.d.ts +20 -0
  59. package/dist/resources/2012/RainDoh.js +20 -0
  60. package/dist/resources/2012/ReagnimatedGnome.d.ts +18 -0
  61. package/dist/resources/2012/ReagnimatedGnome.js +18 -0
  62. package/dist/resources/2012/Resolutions.d.ts +2 -2
  63. package/dist/resources/2012/Resolutions.js +2 -2
  64. package/dist/resources/2013/Florist.d.ts +15 -0
  65. package/dist/resources/2013/Florist.js +21 -0
  66. package/dist/resources/2014/CrimboShrub.d.ts +12 -0
  67. package/dist/resources/2014/CrimboShrub.js +22 -1
  68. package/dist/resources/2014/DNALab.d.ts +10 -2
  69. package/dist/resources/2014/DNALab.js +10 -2
  70. package/dist/resources/2014/WinterGarden.d.ts +15 -0
  71. package/dist/resources/2014/WinterGarden.js +15 -0
  72. package/dist/resources/2015/BarrelShrine.d.ts +6 -0
  73. package/dist/resources/2015/BarrelShrine.js +6 -0
  74. package/dist/resources/2015/ChateauMantegna.d.ts +35 -0
  75. package/dist/resources/2015/ChateauMantegna.js +35 -0
  76. package/dist/resources/2015/DeckOfEveryCard.d.ts +30 -0
  77. package/dist/resources/2015/DeckOfEveryCard.js +122 -0
  78. package/dist/resources/2015/Dinseylandfill.d.ts +1 -0
  79. package/dist/resources/2015/Dinseylandfill.js +2 -0
  80. package/dist/resources/2015/MayoClinic.d.ts +8 -1
  81. package/dist/resources/2015/MayoClinic.js +8 -1
  82. package/dist/resources/2016/SourceTerminal.d.ts +42 -21
  83. package/dist/resources/2016/SourceTerminal.js +44 -23
  84. package/dist/resources/2016/Witchess.d.ts +12 -0
  85. package/dist/resources/2016/Witchess.js +12 -0
  86. package/dist/resources/2017/AsdonMartin.d.ts +11 -3
  87. package/dist/resources/2017/AsdonMartin.js +44 -7
  88. package/dist/resources/2017/MummingTrunk.d.ts +1 -0
  89. package/dist/resources/2017/MummingTrunk.js +8 -1
  90. package/dist/resources/2017/Pantogram.d.ts +9 -0
  91. package/dist/resources/2017/Pantogram.js +33 -0
  92. package/dist/resources/2017/Robortender.d.ts +1 -0
  93. package/dist/resources/2017/Robortender.js +1 -0
  94. package/dist/resources/2017/Spacegate.js +1 -0
  95. package/dist/resources/2017/TunnelOfLove.d.ts +19 -0
  96. package/dist/resources/2017/TunnelOfLove.js +37 -0
  97. package/dist/resources/2018/LatteLoversMembersMug.d.ts +9 -0
  98. package/dist/resources/2018/LatteLoversMembersMug.js +9 -0
  99. package/dist/resources/2018/SongBoom.d.ts +9 -4
  100. package/dist/resources/2018/SongBoom.js +9 -4
  101. package/dist/resources/2019/BeachComb.d.ts +38 -1
  102. package/dist/resources/2019/BeachComb.js +39 -2
  103. package/dist/resources/2019/Snapper.d.ts +4 -0
  104. package/dist/resources/2019/Snapper.js +4 -0
  105. package/dist/resources/2020/Cartography.d.ts +13 -0
  106. package/dist/resources/2020/Cartography.js +13 -0
  107. package/dist/resources/2020/Guzzlr.d.ts +89 -23
  108. package/dist/resources/2020/Guzzlr.js +103 -34
  109. package/dist/resources/2020/RetroCape.d.ts +4 -0
  110. package/dist/resources/2020/RetroCape.js +4 -0
  111. package/dist/resources/2021/CrystalBall.d.ts +6 -0
  112. package/dist/resources/2021/CrystalBall.js +13 -1
  113. package/dist/resources/2021/DaylightShavings.d.ts +6 -0
  114. package/dist/resources/2021/DaylightShavings.js +6 -0
  115. package/dist/resources/2022/AutumnAton.d.ts +15 -0
  116. package/dist/resources/2022/AutumnAton.js +21 -0
  117. package/dist/resources/2022/CombatLoversLocket.d.ts +9 -0
  118. package/dist/resources/2022/CombatLoversLocket.js +10 -2
  119. package/dist/resources/2022/GreyGoose.d.ts +46 -0
  120. package/dist/resources/2022/GreyGoose.js +47 -1
  121. package/dist/resources/2022/JuneCleaver.d.ts +20 -0
  122. package/dist/resources/2022/JuneCleaver.js +20 -0
  123. package/dist/resources/2022/TrainSet.d.ts +48 -0
  124. package/dist/resources/2022/TrainSet.js +54 -0
  125. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +75 -0
  126. package/dist/resources/2023/ClosedCircuitPayphone.js +117 -0
  127. package/dist/resources/LibramSummon.d.ts +5 -0
  128. package/dist/resources/LibramSummon.js +10 -3
  129. package/dist/resources/index.d.ts +3 -1
  130. package/dist/resources/index.js +3 -1
  131. package/dist/resources/putty-likes.d.ts +15 -0
  132. package/dist/resources/putty-likes.js +15 -0
  133. package/dist/session.d.ts +12 -0
  134. package/dist/session.js +20 -17
  135. package/dist/since.d.ts +3 -2
  136. package/dist/since.js +4 -2
  137. package/dist/utils.d.ts +96 -5
  138. package/dist/utils.js +106 -11
  139. package/package.json +10 -11
  140. package/dist/dungeons/Dreadsylvania.d.ts +0 -5
  141. package/dist/dungeons/Dreadsylvania.js +0 -14
  142. package/dist/dungeons/Dungeon.d.ts +0 -29
  143. package/dist/dungeons/Dungeon.js +0 -99
  144. package/dist/dungeons/Hobopolis.d.ts +0 -5
  145. package/dist/dungeons/Hobopolis.js +0 -14
  146. package/dist/dungeons/SlimeTube.d.ts +0 -5
  147. package/dist/dungeons/SlimeTube.js +0 -14
package/dist/utils.js CHANGED
@@ -1,6 +1,18 @@
1
+ /**
2
+ * Type guard against null value
3
+ *
4
+ * @param value Value that can be null
5
+ * @returns Whether the value is not null or... not
6
+ */
1
7
  export function notNull(value) {
2
8
  return value !== null;
3
9
  }
10
+ /**
11
+ * Parse string to number, stripping commas
12
+ *
13
+ * @param n Numberical string to parse
14
+ * @returns Numerical value of string
15
+ */
4
16
  export function parseNumber(n) {
5
17
  return Number.parseInt(n.replace(/,/g, ""));
6
18
  }
@@ -10,6 +22,7 @@ export function parseNumber(n) {
10
22
  * @param n Number to clamp.
11
23
  * @param min Lower bound.
12
24
  * @param max Upper bound.
25
+ * @returns Clamped value
13
26
  */
14
27
  export function clamp(n, min, max) {
15
28
  return Math.max(min, Math.min(max, n));
@@ -19,6 +32,7 @@ export function clamp(n, min, max) {
19
32
  *
20
33
  * @param array Array to split
21
34
  * @param chunkSize Size of chunk
35
+ * @returns Split array
22
36
  */
23
37
  export function chunk(array, chunkSize) {
24
38
  const result = [];
@@ -27,6 +41,12 @@ export function chunk(array, chunkSize) {
27
41
  }
28
42
  return result;
29
43
  }
44
+ /**
45
+ * Count distinct values in an array
46
+ *
47
+ * @param array Array of values
48
+ * @returns Map of distinct values to count
49
+ */
30
50
  export function arrayToCountedMap(array) {
31
51
  if (!Array.isArray(array))
32
52
  return array;
@@ -36,25 +56,46 @@ export function arrayToCountedMap(array) {
36
56
  });
37
57
  return map;
38
58
  }
59
+ /**
60
+ * Turn map of distinct values to count into array of values
61
+ *
62
+ * @param map Map to turn into array
63
+ * @returns Array of values
64
+ */
39
65
  export function countedMapToArray(map) {
40
66
  return [].concat(...[...map].map(([item, quantity]) => Array(quantity).fill(item)));
41
67
  }
68
+ /**
69
+ * Stringify a counted map
70
+ *
71
+ * @param map Map of counted values
72
+ * @returns String representing map of counted values
73
+ */
42
74
  export function countedMapToString(map) {
43
75
  return [...map].map(([item, quantity]) => `${quantity} x ${item}`).join(", ");
44
76
  }
45
77
  /**
46
78
  * Sum an array of numbers.
79
+ *
47
80
  * @param addends Addends to sum.
48
- * @param mappingFunction function to turn elements into numbers
81
+ * @param x Property or mapping function of addends to sum
82
+ * @returns Sum of numbers
49
83
  */
50
- export function sum(addends, mappingFunction) {
51
- return addends.reduce((subtotal, element) => subtotal + mappingFunction(element), 0);
84
+ export function sum(addends, x) {
85
+ return addends.reduce((subtotal, element) => subtotal + (typeof x === "function" ? x(element) : element[x]), 0);
52
86
  }
87
+ /**
88
+ * Sum array of numbers
89
+ *
90
+ * @param addends Numbers to sum
91
+ * @returns Sum of numbers
92
+ */
53
93
  export function sumNumbers(addends) {
54
94
  return sum(addends, (x) => x);
55
95
  }
56
96
  /**
57
97
  * Checks if a given item is in a readonly array, acting as a typeguard.
98
+ *
58
99
  * @param item Needle
59
100
  * @param array Readonly array haystack
60
101
  * @returns Whether the item is in the array, and narrows the type of the item.
@@ -64,6 +105,7 @@ export function arrayContains(item, array) {
64
105
  }
65
106
  /**
66
107
  * Checks if two arrays contain the same elements in the same quantity.
108
+ *
67
109
  * @param a First array for comparison
68
110
  * @param b Second array for comparison
69
111
  * @returns Whether the two arrays are equal, irrespective of order.
@@ -76,7 +118,9 @@ export function setEqual(a, b) {
76
118
  }
77
119
  /**
78
120
  * Reverses keys and values for a given map
121
+ *
79
122
  * @param map Map to invert
123
+ * @returns Inverted map
80
124
  */
81
125
  export function invertMap(map) {
82
126
  const returnValue = new Map();
@@ -85,16 +129,9 @@ export function invertMap(map) {
85
129
  }
86
130
  return returnValue;
87
131
  }
88
- /**
89
- * Creates a Type Guard function for a string union type defined via an array as const.
90
- */
91
- export function createStringUnionTypeGuardFunction(array) {
92
- return function (x) {
93
- return array.includes(x);
94
- };
95
- }
96
132
  /**
97
133
  * Splits a string by commas while also respecting escaping commas with a backslash
134
+ *
98
135
  * @param str String to split
99
136
  * @returns List of tokens
100
137
  */
@@ -120,3 +157,61 @@ export function splitByCommasWithEscapes(str) {
120
157
  returnValue.push(currentString.trim());
121
158
  return returnValue;
122
159
  }
160
+ /**
161
+ * Find the best element of an array, where "best" is defined by some given criteria.
162
+ *
163
+ * @param array The array to traverse and find the best element of.
164
+ * @param optimizer Either a key on the objects we're looking at that corresponds to numerical values, or a function for mapping these objects to numbers. Essentially, some way of assigning value to the elements of the array.
165
+ * @param reverse Make this true to find the worst element of the array, and false to find the best. Defaults to false.
166
+ * @returns Best element by optimizer function
167
+ */
168
+ export function maxBy(array, optimizer, reverse = false) {
169
+ if (!array.length)
170
+ throw new Error("Cannot call maxBy on an empty array!");
171
+ if (typeof optimizer === "function") {
172
+ return [...array].reduce(({ value, item }, other) => {
173
+ const otherValue = optimizer(other);
174
+ return value >= otherValue !== reverse
175
+ ? { value, item }
176
+ : { value: otherValue, item: other };
177
+ }, { item: array[0], value: optimizer(array[0]) }).item;
178
+ }
179
+ else {
180
+ return array.reduce((a, b) => a[optimizer] >= b[optimizer] !== reverse ? a : b);
181
+ }
182
+ }
183
+ /**
184
+ * Compare arrays shallowly
185
+ *
186
+ * @param left One array to compare
187
+ * @param right The other array to compare
188
+ * @returns Whether the two arrays are shallowly equal
189
+ */
190
+ export function arrayEquals(left, right) {
191
+ if (left.length !== right.length)
192
+ return false;
193
+ return left.every((element, index) => element === right[index]);
194
+ }
195
+ /**
196
+ * Used to collapse a Delayed<T> object into an entity of type "T" as represented by the object.
197
+ *
198
+ * @param delayedObject Object of type Delayed<T> that represents either a value of type T or a function returning a value of type T.
199
+ * @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element.
200
+ */
201
+ export function undelay(delayedObject) {
202
+ return typeof delayedObject === "function" ? delayedObject() : delayedObject;
203
+ }
204
+ /**
205
+ * Makes a byX function, like byStat or byClass
206
+ *
207
+ * @param source A method for finding your stat, or class, or whatever X is in this context
208
+ * @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined.
209
+ */
210
+ export function makeByXFunction(source) {
211
+ return function (options) {
212
+ const val = undelay(source);
213
+ if ("default" in options)
214
+ return options[val] ?? options.default;
215
+ return options[val];
216
+ };
217
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.7.10",
3
+ "version": "0.7.13",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,8 +11,7 @@
11
11
  "scripts": {
12
12
  "build": "yarn run build:tsc && yarn run build:bundled",
13
13
  "build:tsc": "tsc",
14
- "build:bundled": "webpack",
15
- "build:watch": "tsc --watch",
14
+ "build:bundled": "node build.mjs",
16
15
  "clean": "rm -rf dist",
17
16
  "docs": "yarn run typedoc",
18
17
  "format": "yarn run prettier --write .",
@@ -27,12 +26,12 @@
27
26
  "devDependencies": {
28
27
  "@babel/compat-data": "^7.17.0",
29
28
  "@babel/core": "^7.17.2",
30
- "@babel/plugin-proposal-class-properties": "^7.14.5",
31
29
  "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
32
30
  "@babel/plugin-transform-runtime": "^7.15.0",
33
31
  "@babel/preset-env": "^7.16.11",
34
32
  "@babel/preset-typescript": "^7.15.0",
35
33
  "@tsconfig/node16": "^1.0.2",
34
+ "@types/array.prototype.flat": "^1.2.1",
36
35
  "@types/jest": "^27.0.1",
37
36
  "@types/lodash-es": "^4.17.4",
38
37
  "@types/node": "^16.11.11",
@@ -40,30 +39,30 @@
40
39
  "@typescript-eslint/eslint-plugin": "^5.5.0",
41
40
  "@typescript-eslint/parser": "^5.5.0",
42
41
  "babel-loader": "^8.2.3",
42
+ "esbuild": "^0.17.0",
43
+ "esbuild-plugin-babel": "^0.2.3",
43
44
  "eslint": "^7.16.0",
44
45
  "eslint-config-prettier": "^8.3.0",
45
46
  "eslint-import-resolver-typescript": "^2.5.0",
46
47
  "eslint-plugin-import": "^2.25.4",
47
48
  "eslint-plugin-jest": "^25.2.3",
48
- "eslint-plugin-libram": "^0.2.25",
49
+ "eslint-plugin-jsdoc": "^40.0.1",
50
+ "eslint-plugin-libram": "^0.2.29",
49
51
  "husky": "^4.3.6",
50
52
  "java-parser": "^1.4.0",
51
53
  "jest": "^27.1.0",
52
- "kolmafia": "^5.27075.0",
54
+ "kolmafia": "^5.27260.0",
53
55
  "lint-staged": ">=10",
54
56
  "node-fetch": "^2.6.1",
55
57
  "prettier": "^2.1.2",
56
58
  "ts-jest": "^27.0.5",
57
59
  "ts-node": "^10.4.0",
58
60
  "typedoc": "^0.22.10",
59
- "typescript": "^4.5.2",
60
- "webpack": "^5.67.0",
61
- "webpack-cli": "^4.9.2"
61
+ "typescript": "^4.5.2"
62
62
  },
63
63
  "dependencies": {
64
64
  "@babel/runtime-corejs3": "^7.17.2",
65
- "core-js": "^3.21.0",
66
- "lodash": "^4.17.21"
65
+ "array.prototype.flat": "^1.3.1"
67
66
  },
68
67
  "peerDependencies": {
69
68
  "kolmafia": "^5.26781.0"
@@ -1,5 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare function close(): boolean;
3
- export declare function open(paymentPolicy?: "None" | "All" | "Difference"): boolean;
4
- export declare function distribute(idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
5
- export declare function findLoot(): Map<Item, number>;
@@ -1,14 +0,0 @@
1
- import { myId } from "kolmafia";
2
- import { close as closeDungeon, distribute as distributeDungeon, Dreadsylvania, findLoot as findLootDungeon, open as openDungeon, } from "./Dungeon";
3
- export function close() {
4
- return closeDungeon(Dreadsylvania);
5
- }
6
- export function open(paymentPolicy = "Difference") {
7
- return openDungeon(Dreadsylvania, paymentPolicy);
8
- }
9
- export function distribute(idOrName = myId(), loot = Dreadsylvania.loot, distributeAllOfAGivenItem = true) {
10
- distributeDungeon(Dreadsylvania, idOrName, loot, distributeAllOfAGivenItem);
11
- }
12
- export function findLoot() {
13
- return findLootDungeon(Dreadsylvania);
14
- }
@@ -1,29 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare type Dungeon = {
3
- name: string;
4
- loot: Item[];
5
- openAction: string;
6
- closeAction: string;
7
- openCost: number;
8
- openImage: string;
9
- closedImage: string;
10
- };
11
- /**
12
- * Distributes loot from given dungeon
13
- * @param dungeon The dungeon to distribute loot from
14
- * @param idOrName The player you're trying to distribute to, either as a username or a player ID. Defaults to self.
15
- * @param loot The loot you're looking to distribute, specific to this dungeon
16
- * @param distributeAllOfAGivenItem For items that you can get multiple of in a dungeon. When true, this will give everything of that ilk to your chosen player.
17
- */
18
- export declare function distribute(dungeon: Dungeon, idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
19
- export declare function close(dungeon: Dungeon): boolean;
20
- /**
21
- * Opens clan dungeon and, if relevant, pays meat to do so
22
- * @param dungeon The Dungeon to open
23
- * @param paymentPolicy "None", "All", or "Difference". Difference pays into the stash the exact amount needed to open the dungeon.
24
- */
25
- export declare function open(dungeon: Dungeon, paymentPolicy?: "None" | "All" | "Difference"): boolean;
26
- export declare const Dreadsylvania: Dungeon;
27
- export declare const Hobopolis: Dungeon;
28
- export declare const SlimeTube: Dungeon;
29
- export declare function findLoot(dungeon: Dungeon): Map<Item, number>;
@@ -1,99 +0,0 @@
1
- import { getClanName, myId, toItem, visitUrl, xpath } from "kolmafia";
2
- import { Clan } from "../Clan";
3
- import { getPlayerFromIdOrName } from "../lib";
4
- import { $items } from "../template-string";
5
- import { countedMapToArray } from "../utils";
6
- /**
7
- * Distributes loot from given dungeon
8
- * @param dungeon The dungeon to distribute loot from
9
- * @param idOrName The player you're trying to distribute to, either as a username or a player ID. Defaults to self.
10
- * @param loot The loot you're looking to distribute, specific to this dungeon
11
- * @param distributeAllOfAGivenItem For items that you can get multiple of in a dungeon. When true, this will give everything of that ilk to your chosen player.
12
- */
13
- export function distribute(dungeon, idOrName = myId(), loot = dungeon.loot, distributeAllOfAGivenItem = true) {
14
- const player = getPlayerFromIdOrName(idOrName);
15
- const lootList = loot instanceof Map
16
- ? countedMapToArray(loot)
17
- : Array.isArray(loot)
18
- ? loot
19
- : [loot];
20
- const badLoot = lootList.find((lootItem) => !dungeon.loot.includes(lootItem));
21
- if (badLoot) {
22
- throw new Error(`${badLoot} is not a valid piece of dungeon loot`);
23
- }
24
- const pageText = visitUrl("clan_basement.php");
25
- if (!pageText.match(new RegExp(player.name, "i"))) {
26
- throw new Error(`${player.name} cannot be distributed loot from ${getClanName()}`);
27
- }
28
- const itemNames = xpath(pageText, "//tr/td[2]/b/text()");
29
- const whichLoots = xpath(pageText, '//form[@action="clan_basement.php"]//input[@type="hidden"][@name="whichloot"]/@value');
30
- itemNames.forEach((itemName, index) => {
31
- if (lootList.includes(toItem(itemName))) {
32
- visitUrl(`clan_basement.php?whichloot=${whichLoots[index]}&recipient=${player.id}`);
33
- if (!distributeAllOfAGivenItem)
34
- lootList.splice(lootList.indexOf(toItem(itemName)));
35
- }
36
- });
37
- }
38
- export function close(dungeon) {
39
- visitUrl(`clan_basement.php?action=${dungeon.closeAction}&confirm=true`, true);
40
- const pageText = visitUrl("clan_basement.php");
41
- return pageText.includes(dungeon.closedImage);
42
- }
43
- /**
44
- * Opens clan dungeon and, if relevant, pays meat to do so
45
- * @param dungeon The Dungeon to open
46
- * @param paymentPolicy "None", "All", or "Difference". Difference pays into the stash the exact amount needed to open the dungeon.
47
- */
48
- export function open(dungeon, paymentPolicy = "Difference") {
49
- const pageText = visitUrl("clan_basement.php");
50
- if (pageText.includes(dungeon.openImage))
51
- return true;
52
- const clan = Clan.get();
53
- if (paymentPolicy === "All") {
54
- clan.putMeatInCoffer(dungeon.openCost);
55
- }
56
- else {
57
- const stashMeat = clan.getMeatInCoffer();
58
- const payDifference = dungeon.openCost - stashMeat;
59
- if (payDifference > 0) {
60
- if (paymentPolicy === "None")
61
- return false;
62
- clan.putMeatInCoffer(payDifference);
63
- }
64
- }
65
- visitUrl(`clan_basement.php?action=${dungeon.openAction}`, true);
66
- return visitUrl("clan_basement.php").includes(dungeon.openImage);
67
- }
68
- /**
69
- * Creates dungeon object for managing clan dungeons
70
- * @param name Name of the dungeon in question
71
- * @param loot Distributable loot dropped by bosses in dungeon
72
- * @param openAction String action used in form submission to open dungeon
73
- * @param closeAction String action used in form submission to close dungeon
74
- * @param openCost Meat cost of opening dungeon
75
- * @param openImage Image text to search clan_basement.php for to check if dungeon is open
76
- * @param closedImage Image text to search clan_basement.php for to check if dungeon is closed
77
- */
78
- function createDungeon(name, loot, openAction, closeAction, openCost, openImage, closedImage) {
79
- return {
80
- name: name,
81
- loot: loot,
82
- openAction: openAction,
83
- closeAction: closeAction,
84
- openCost: openCost,
85
- openImage: openImage,
86
- closedImage: closedImage,
87
- };
88
- }
89
- export const Dreadsylvania = createDungeon("Dreadsylvania", $items `Great Wolf's headband, Great Wolf's right paw, Great Wolf's left paw, Great Wolf's lice, Great Wolf's rocket launcher, Great Wolf's beastly trousers, Drapes-You-Regally, Warms-Your-Tush, Covers-Your-Head, Protects-Your-Junk, Quiets-Your-Steps, Helps-You-Sleep, Mayor Ghost's khakis, Mayor Ghost's cloak, Mayor Ghost's toupee, Mayor Ghost's scissors, Mayor Ghost's sash, Mayor Ghost's gavel, zombie mariachi hat, zombie accordion, zombie mariachi pants, HOA regulation book, HOA zombie eyes, HOA citation pad, Unkillable Skeleton's skullcap, Unkillable Skeleton's shinguards, Unkillable Skeleton's breastplate, Unkillable Skeleton's shield, Unkillable Skeleton's sawsword, Unkillable Skeleton's restless leg, skull capacitor, Thunkula's drinking cap, Drunkula's silky pants, Drunkula's cape, Drunkula's ring of haze, Drunkula's wineglass, Drunkula's bell, bottle of Bloodweiser, bottle of Bloodweiser, bottle of Bloodweiser, bottle of Bloodweiser, electric Kool-Aid, electric Kool-Aid, electric Kool-Aid, electric Kool-Aid, ghost pepper, ghost pepper, ghost pepper, ghost pepper, Gets-You-Drunk, Gets-You-Drunk, Gets-You-Drunk, Gets-You-Drunk, wriggling severed nose, wriggling severed nose, wriggling severed nose, wriggling severed nose, Hunger™ Sauce, Hunger™ Sauce, Hunger™ Sauce, Hunger™ Sauce`, "translatemap", "foldmap", 1000000, "dvmap.gif", "foldmap.gif");
90
- export const Hobopolis = createDungeon("Hobopolis", $items `Ol' Scratch's ash can, Ol' Scratch's ol' britches, Ol' Scratch's stovepipe hat, Ol' Scratch's infernal pitchfork, Ol' Scratch's manacles, Ol' Scratch's stove door, Frosty's carrot, Frosty's nailbat, Frosty's old silk hat, Frosty's arm, Frosty's iceball, Frosty's snowball sack, Oscus's dumpster waders, Oscus's pelt, Wand of Oscus, Oscus's flypaper pants, Oscus's garbage can lid, Oscus's neverending soda, Zombo's grievous greaves, Zombo's shield, Zombo's skullcap, Zombo's empty eye, Zombo's shoulder blade, Zombo's skull ring, Chester's bag of candy, Chester's cutoffs, Chester's moustache, Chester's Aquarius medallion, Chester's muscle shirt, Chester's sunglasses, Hodgman's bow tie, Hodgman's porkpie hat, Hodgman's lobsterskin pants, Hodgman's almanac, Hodgman's lucky sock, Hodgman's metal detector, Hodgman's varcolac paw, Hodgman's harmonica, Hodgman's garbage sticker, Hodgman's cane, Hodgman's whackin' stick, Hodgman's disgusting technicolor overcoat, Hodgman's imaginary hamster`, "cleansewer", "floodsewer", 1000000, "opengrate.gif", "sewergrate.gif");
91
- export const SlimeTube = createDungeon("The Slime Tube", $items `slime-soaked brain, slime-soaked hypophysis, slime-soaked sweat gland, squirming Slime larva, caustic slime nodule, caustic slime nodule, hardened slime belt, hardened slime hat, hardened slime pants`, "cleanspot", "sealtube", 250000, "slimehole.gif", "greasespot.gif");
92
- export function findLoot(dungeon) {
93
- const returnValue = new Map();
94
- const pageText = visitUrl("clan_basement.php");
95
- for (const lootItem of dungeon.loot) {
96
- returnValue.set(lootItem, pageText.match(new RegExp(lootItem.name, "g"))?.length ?? 0);
97
- }
98
- return returnValue;
99
- }
@@ -1,5 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare function close(): boolean;
3
- export declare function open(paymentPolicy?: "None" | "All" | "Difference"): boolean;
4
- export declare function distribute(idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
5
- export declare function findLoot(): Map<Item, number>;
@@ -1,14 +0,0 @@
1
- import { myId } from "kolmafia";
2
- import { close as closeDungeon, distribute as distributeDungeon, findLoot as findLootDungeon, Hobopolis, open as openDungeon, } from "./Dungeon";
3
- export function close() {
4
- return closeDungeon(Hobopolis);
5
- }
6
- export function open(paymentPolicy = "Difference") {
7
- return openDungeon(Hobopolis, paymentPolicy);
8
- }
9
- export function distribute(idOrName = myId(), loot = Hobopolis.loot, distributeAllOfAGivenItem = true) {
10
- distributeDungeon(Hobopolis, idOrName, loot, distributeAllOfAGivenItem);
11
- }
12
- export function findLoot() {
13
- return findLootDungeon(Hobopolis);
14
- }
@@ -1,5 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare function close(): boolean;
3
- export declare function open(paymentPolicy?: "None" | "All" | "Difference"): boolean;
4
- export declare function distribute(idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
5
- export declare function findLoot(): Map<Item, number>;
@@ -1,14 +0,0 @@
1
- import { myId } from "kolmafia";
2
- import { close as closeDungeon, distribute as distributeDungeon, findLoot as findLootDungeon, open as openDungeon, SlimeTube, } from "./Dungeon";
3
- export function close() {
4
- return closeDungeon(SlimeTube);
5
- }
6
- export function open(paymentPolicy = "Difference") {
7
- return openDungeon(SlimeTube, paymentPolicy);
8
- }
9
- export function distribute(idOrName = myId(), loot = SlimeTube.loot, distributeAllOfAGivenItem = true) {
10
- distributeDungeon(SlimeTube, idOrName, loot, distributeAllOfAGivenItem);
11
- }
12
- export function findLoot() {
13
- return findLootDungeon(SlimeTube);
14
- }