libram 0.8.27 → 0.8.28

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 (195) hide show
  1. package/package.json +9 -8
  2. package/dist/Clan.d.ts +0 -128
  3. package/dist/Clan.js +0 -300
  4. package/dist/Copier.d.ts +0 -9
  5. package/dist/Copier.js +0 -15
  6. package/dist/Dungeon.d.ts +0 -45
  7. package/dist/Dungeon.js +0 -115
  8. package/dist/Kmail.d.ts +0 -104
  9. package/dist/Kmail.js +0 -182
  10. package/dist/actions/ActionSource.d.ts +0 -131
  11. package/dist/actions/ActionSource.js +0 -177
  12. package/dist/actions/Banish.d.ts +0 -16
  13. package/dist/actions/Banish.js +0 -121
  14. package/dist/actions/FreeKill.d.ts +0 -16
  15. package/dist/actions/FreeKill.js +0 -94
  16. package/dist/actions/FreeRun.d.ts +0 -16
  17. package/dist/actions/FreeRun.js +0 -77
  18. package/dist/actions/index.d.ts +0 -4
  19. package/dist/actions/index.js +0 -4
  20. package/dist/ascend.d.ts +0 -83
  21. package/dist/ascend.js +0 -268
  22. package/dist/challengePaths/2014/HeavyRains.d.ts +0 -22
  23. package/dist/challengePaths/2014/HeavyRains.js +0 -75
  24. package/dist/challengePaths/2015/CommunityService.d.ts +0 -125
  25. package/dist/challengePaths/2015/CommunityService.js +0 -334
  26. package/dist/challengePaths/2016/NuclearAutumn.d.ts +0 -13
  27. package/dist/challengePaths/2016/NuclearAutumn.js +0 -21
  28. package/dist/challengePaths/index.d.ts +0 -4
  29. package/dist/challengePaths/index.js +0 -4
  30. package/dist/combat.d.ts +0 -414
  31. package/dist/combat.js +0 -711
  32. package/dist/console.d.ts +0 -12
  33. package/dist/console.js +0 -14
  34. package/dist/counter.d.ts +0 -22
  35. package/dist/counter.js +0 -37
  36. package/dist/diet/index.d.ts +0 -80
  37. package/dist/diet/index.js +0 -662
  38. package/dist/diet/knapsack.d.ts +0 -8
  39. package/dist/diet/knapsack.js +0 -128
  40. package/dist/index.d.ts +0 -29
  41. package/dist/index.js +0 -26
  42. package/dist/lib.d.ts +0 -497
  43. package/dist/lib.js +0 -958
  44. package/dist/logger.d.ts +0 -35
  45. package/dist/logger.js +0 -62
  46. package/dist/maximize.d.ts +0 -121
  47. package/dist/maximize.js +0 -525
  48. package/dist/modifier.d.ts +0 -41
  49. package/dist/modifier.js +0 -160
  50. package/dist/modifierTypes.d.ts +0 -16
  51. package/dist/modifierTypes.js +0 -9
  52. package/dist/mood.d.ts +0 -105
  53. package/dist/mood.js +0 -349
  54. package/dist/moonSign.d.ts +0 -13
  55. package/dist/moonSign.js +0 -25
  56. package/dist/overlappingNames.d.ts +0 -3
  57. package/dist/overlappingNames.js +0 -42
  58. package/dist/property.d.ts +0 -222
  59. package/dist/property.js +0 -385
  60. package/dist/propertyTypes.d.ts +0 -19
  61. package/dist/propertyTypes.js +0 -10
  62. package/dist/propertyTyping.d.ts +0 -65
  63. package/dist/propertyTyping.js +0 -91
  64. package/dist/resources/2007/CandyHearts.d.ts +0 -9
  65. package/dist/resources/2007/CandyHearts.js +0 -24
  66. package/dist/resources/2008/DivineFavors.d.ts +0 -9
  67. package/dist/resources/2008/DivineFavors.js +0 -27
  68. package/dist/resources/2008/Stickers.d.ts +0 -49
  69. package/dist/resources/2008/Stickers.js +0 -84
  70. package/dist/resources/2009/Bandersnatch.d.ts +0 -56
  71. package/dist/resources/2009/Bandersnatch.js +0 -93
  72. package/dist/resources/2009/LoveSongs.d.ts +0 -9
  73. package/dist/resources/2009/LoveSongs.js +0 -24
  74. package/dist/resources/2009/SpookyPutty.d.ts +0 -31
  75. package/dist/resources/2009/SpookyPutty.js +0 -49
  76. package/dist/resources/2010/Brickos.d.ts +0 -9
  77. package/dist/resources/2010/Brickos.js +0 -21
  78. package/dist/resources/2010/CrownOfThrones.d.ts +0 -68
  79. package/dist/resources/2010/CrownOfThrones.js +0 -418
  80. package/dist/resources/2010/LookingGlass.d.ts +0 -29
  81. package/dist/resources/2010/LookingGlass.js +0 -89
  82. package/dist/resources/2011/Gygaxian.d.ts +0 -9
  83. package/dist/resources/2011/Gygaxian.js +0 -24
  84. package/dist/resources/2011/ObtuseAngel.d.ts +0 -33
  85. package/dist/resources/2011/ObtuseAngel.js +0 -51
  86. package/dist/resources/2011/StompingBoots.d.ts +0 -37
  87. package/dist/resources/2011/StompingBoots.js +0 -57
  88. package/dist/resources/2012/RainDoh.d.ts +0 -25
  89. package/dist/resources/2012/RainDoh.js +0 -37
  90. package/dist/resources/2012/ReagnimatedGnome.d.ts +0 -31
  91. package/dist/resources/2012/ReagnimatedGnome.js +0 -46
  92. package/dist/resources/2012/Resolutions.d.ts +0 -9
  93. package/dist/resources/2012/Resolutions.js +0 -28
  94. package/dist/resources/2013/Florist.d.ts +0 -81
  95. package/dist/resources/2013/Florist.js +0 -245
  96. package/dist/resources/2013/JungMan.d.ts +0 -33
  97. package/dist/resources/2013/JungMan.js +0 -69
  98. package/dist/resources/2013/PulledTaffy.d.ts +0 -9
  99. package/dist/resources/2013/PulledTaffy.js +0 -33
  100. package/dist/resources/2014/CrimboShrub.d.ts +0 -42
  101. package/dist/resources/2014/CrimboShrub.js +0 -89
  102. package/dist/resources/2014/DNALab.d.ts +0 -56
  103. package/dist/resources/2014/DNALab.js +0 -162
  104. package/dist/resources/2014/WinterGarden.d.ts +0 -23
  105. package/dist/resources/2014/WinterGarden.js +0 -35
  106. package/dist/resources/2015/BarrelShrine.d.ts +0 -8
  107. package/dist/resources/2015/BarrelShrine.js +0 -25
  108. package/dist/resources/2015/ChateauMantegna.d.ts +0 -52
  109. package/dist/resources/2015/ChateauMantegna.js +0 -99
  110. package/dist/resources/2015/DeckOfEveryCard.d.ts +0 -29
  111. package/dist/resources/2015/DeckOfEveryCard.js +0 -122
  112. package/dist/resources/2015/Dinseylandfill.d.ts +0 -89
  113. package/dist/resources/2015/Dinseylandfill.js +0 -205
  114. package/dist/resources/2015/MayoClinic.d.ts +0 -23
  115. package/dist/resources/2015/MayoClinic.js +0 -49
  116. package/dist/resources/2016/GingerBread.d.ts +0 -32
  117. package/dist/resources/2016/GingerBread.js +0 -73
  118. package/dist/resources/2016/SourceTerminal.d.ts +0 -181
  119. package/dist/resources/2016/SourceTerminal.js +0 -275
  120. package/dist/resources/2016/Witchess.d.ts +0 -17
  121. package/dist/resources/2016/Witchess.js +0 -47
  122. package/dist/resources/2017/AsdonMartin.d.ts +0 -59
  123. package/dist/resources/2017/AsdonMartin.js +0 -238
  124. package/dist/resources/2017/Horsery.d.ts +0 -19
  125. package/dist/resources/2017/Horsery.js +0 -42
  126. package/dist/resources/2017/MummingTrunk.d.ts +0 -8
  127. package/dist/resources/2017/MummingTrunk.js +0 -33
  128. package/dist/resources/2017/Pantogram.d.ts +0 -92
  129. package/dist/resources/2017/Pantogram.js +0 -174
  130. package/dist/resources/2017/Robortender.d.ts +0 -30
  131. package/dist/resources/2017/Robortender.js +0 -90
  132. package/dist/resources/2017/Spacegate.d.ts +0 -86
  133. package/dist/resources/2017/Spacegate.js +0 -178
  134. package/dist/resources/2017/TunnelOfLove.d.ts +0 -39
  135. package/dist/resources/2017/TunnelOfLove.js +0 -120
  136. package/dist/resources/2018/LatteLoversMembersMug.d.ts +0 -392
  137. package/dist/resources/2018/LatteLoversMembersMug.js +0 -303
  138. package/dist/resources/2018/SongBoom.d.ts +0 -33
  139. package/dist/resources/2018/SongBoom.js +0 -55
  140. package/dist/resources/2019/BeachComb.d.ts +0 -72
  141. package/dist/resources/2019/BeachComb.js +0 -118
  142. package/dist/resources/2019/CampAway.d.ts +0 -39
  143. package/dist/resources/2019/CampAway.js +0 -72
  144. package/dist/resources/2019/Snapper.d.ts +0 -33
  145. package/dist/resources/2019/Snapper.js +0 -73
  146. package/dist/resources/2020/Cartography.d.ts +0 -16
  147. package/dist/resources/2020/Cartography.js +0 -48
  148. package/dist/resources/2020/Guzzlr.d.ts +0 -160
  149. package/dist/resources/2020/Guzzlr.js +0 -275
  150. package/dist/resources/2020/RetroCape.d.ts +0 -51
  151. package/dist/resources/2020/RetroCape.js +0 -115
  152. package/dist/resources/2021/CrystalBall.d.ts +0 -14
  153. package/dist/resources/2021/CrystalBall.js +0 -39
  154. package/dist/resources/2021/DaylightShavings.d.ts +0 -40
  155. package/dist/resources/2021/DaylightShavings.js +0 -74
  156. package/dist/resources/2022/AutumnAton.d.ts +0 -78
  157. package/dist/resources/2022/AutumnAton.js +0 -182
  158. package/dist/resources/2022/CombatLoversLocket.d.ts +0 -44
  159. package/dist/resources/2022/CombatLoversLocket.js +0 -82
  160. package/dist/resources/2022/GreyGoose.d.ts +0 -59
  161. package/dist/resources/2022/GreyGoose.js +0 -90
  162. package/dist/resources/2022/JuneCleaver.d.ts +0 -47
  163. package/dist/resources/2022/JuneCleaver.js +0 -69
  164. package/dist/resources/2022/TrainSet.d.ts +0 -146
  165. package/dist/resources/2022/TrainSet.js +0 -228
  166. package/dist/resources/2023/AugustScepter.d.ts +0 -25
  167. package/dist/resources/2023/AugustScepter.js +0 -40
  168. package/dist/resources/2023/BurningLeaves.d.ts +0 -25
  169. package/dist/resources/2023/BurningLeaves.js +0 -74
  170. package/dist/resources/2023/CinchoDeMayo.d.ts +0 -25
  171. package/dist/resources/2023/CinchoDeMayo.js +0 -45
  172. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +0 -80
  173. package/dist/resources/2023/ClosedCircuitPayphone.js +0 -129
  174. package/dist/resources/2023/CursedMonkeyPaw.d.ts +0 -46
  175. package/dist/resources/2023/CursedMonkeyPaw.js +0 -113
  176. package/dist/resources/2024/AprilingBandHelmet.d.ts +0 -57
  177. package/dist/resources/2024/AprilingBandHelmet.js +0 -118
  178. package/dist/resources/2024/ChestMimic.d.ts +0 -35
  179. package/dist/resources/2024/ChestMimic.js +0 -108
  180. package/dist/resources/LibramSummon.d.ts +0 -18
  181. package/dist/resources/LibramSummon.js +0 -74
  182. package/dist/resources/index.d.ts +0 -54
  183. package/dist/resources/index.js +0 -54
  184. package/dist/resources/putty-likes.d.ts +0 -21
  185. package/dist/resources/putty-likes.js +0 -33
  186. package/dist/session.d.ts +0 -169
  187. package/dist/session.js +0 -284
  188. package/dist/since.d.ts +0 -51
  189. package/dist/since.js +0 -108
  190. package/dist/template-string.d.ts +0 -324
  191. package/dist/template-string.js +0 -265
  192. package/dist/url.d.ts +0 -35
  193. package/dist/url.js +0 -67
  194. package/dist/utils.d.ts +0 -178
  195. package/dist/utils.js +0 -255
package/dist/Kmail.d.ts DELETED
@@ -1,104 +0,0 @@
1
- import { Item } from "kolmafia";
2
- declare type RawKmail = {
3
- id: string;
4
- type: string;
5
- fromid: string;
6
- azunixtime: string;
7
- message: string;
8
- fromname: string;
9
- localtime: string;
10
- };
11
- export default class Kmail {
12
- readonly id: number;
13
- readonly date: Date;
14
- readonly type: "normal" | "giftshop";
15
- readonly senderId: number;
16
- readonly senderName: string;
17
- readonly rawMessage: string;
18
- /**
19
- * Parses a kmail from KoL's native format
20
- *
21
- * @param rawKmail Kmail in the format supplies by api.php
22
- * @returns Parsed kmail
23
- */
24
- static parse(rawKmail: RawKmail): Kmail;
25
- /**
26
- * Returns all of the player's kmails
27
- *
28
- * @param count Number of kmails to fetch
29
- * @returns Parsed kmails
30
- */
31
- static inbox(count?: number): Kmail[];
32
- /**
33
- * Bulk delete kmails
34
- *
35
- * @param kmails Kmails to delete
36
- * @returns Number of kmails deleted
37
- */
38
- static delete(kmails: Kmail[]): number;
39
- private static _genericSend;
40
- /**
41
- * Sends a kmail to a player
42
- *
43
- * Sends multiple kmails if more than 11 unique item types are attached.
44
- * Ignores any ungiftable items.
45
- * Sends a gift package to players in run
46
- *
47
- * @param to The player name or id to receive the kmail
48
- * @param message The text contents of the message
49
- * @param items The items to be attached
50
- * @param meat The quantity of meat to be attached
51
- * @returns True if the kmail was successfully sent
52
- */
53
- static send(to: string | number, message?: string, items?: Map<Item, number> | Item[], meat?: number): boolean;
54
- /**
55
- * Sends a gift to a player
56
- *
57
- * Sends multiple kmails if more than 3 unique item types are attached.
58
- * Ignores any ungiftable items.
59
- *
60
- * @param to The player name or id to receive the gift
61
- * @param message Message to send
62
- * @param items The items to be attached
63
- * @param meat The quantity of meat to be attached
64
- * @param insideNote The note on the inside of the gift
65
- * @returns True if the gift was successfully sent
66
- */
67
- static gift(to: string | number, message?: string, items?: Map<Item, number> | Item[], meat?: number, insideNote?: string): boolean;
68
- private constructor();
69
- /**
70
- * Delete the kmail
71
- *
72
- * @returns Whether the kmail was deleted
73
- */
74
- delete(): boolean;
75
- /**
76
- * Get message contents without any HTML from items or meat
77
- *
78
- * @returns Cleaned message contents
79
- */
80
- get message(): string;
81
- /**
82
- * Get items attached to the kmail
83
- *
84
- * @returns Map of items attached to the kmail and their quantities
85
- */
86
- items(): Map<Item, number>;
87
- /**
88
- * Get meat attached to the kmail
89
- *
90
- * @returns Meat attached to the kmail
91
- */
92
- meat(): number;
93
- /**
94
- * Reply to kmail
95
- *
96
- * @param message Message with which to reply
97
- * @param items Items to send
98
- * @param meat Meat to send
99
- * @see Kmail.send
100
- * @returns True if the kmail was successfully sent
101
- */
102
- reply(message?: string, items?: Map<Item, number> | Item[], meat?: number): boolean;
103
- }
104
- export {};
package/dist/Kmail.js DELETED
@@ -1,182 +0,0 @@
1
- import { extractItems, extractMeat, isGiftable, Item, visitUrl, } from "kolmafia";
2
- import { combineQuery, EMPTY_VALUE, fetchUrl } from "./url";
3
- import { arrayToCountedMap, chunk } from "./utils";
4
- export default class Kmail {
5
- id;
6
- date;
7
- type;
8
- senderId;
9
- senderName;
10
- rawMessage;
11
- /**
12
- * Parses a kmail from KoL's native format
13
- *
14
- * @param rawKmail Kmail in the format supplies by api.php
15
- * @returns Parsed kmail
16
- */
17
- static parse(rawKmail) {
18
- return new Kmail(rawKmail);
19
- }
20
- /**
21
- * Returns all of the player's kmails
22
- *
23
- * @param count Number of kmails to fetch
24
- * @returns Parsed kmails
25
- */
26
- static inbox(count = 100) {
27
- return JSON.parse(visitUrl(`api.php?what=kmail&for=libram&count=${count}`)).map(Kmail.parse);
28
- }
29
- /**
30
- * Bulk delete kmails
31
- *
32
- * @param kmails Kmails to delete
33
- * @returns Number of kmails deleted
34
- */
35
- static delete(kmails) {
36
- const results = fetchUrl("messages.php", [
37
- ["the_action", "delete"],
38
- ["box", "Inbox"],
39
- ["pwd", EMPTY_VALUE],
40
- ...kmails.map((k) => [`sel${k.id}`, "on"]),
41
- ]);
42
- return Number(results.match(/<td>(\d) messages? deleted.<\/td>/)?.[1] ?? 0);
43
- }
44
- static _genericSend(to, message, items, meat, chunkSize, constructUrl, successString) {
45
- let m = meat;
46
- const sendableItems = [...arrayToCountedMap(items).entries()].filter(([item]) => isGiftable(item));
47
- let result = true;
48
- const chunks = chunk(sendableItems, chunkSize);
49
- // Split the items to be sent into chunks of max 11 item types
50
- for (const c of chunks.length > 0 ? chunks : [null]) {
51
- const itemsQuery = {};
52
- if (c !== null) {
53
- c.forEach(([item, quantity], i) => {
54
- itemsQuery[`whichitem${i + 1}`] = item.id;
55
- itemsQuery[`howmany${i + 1}`] = quantity;
56
- });
57
- }
58
- const { path, query } = constructUrl({
59
- meat: m,
60
- chunkSize: c?.length ?? 0,
61
- });
62
- const r = fetchUrl(path, combineQuery(query, itemsQuery));
63
- if (r.includes("That player cannot receive Meat or items")) {
64
- return Kmail.gift(to, message, items, meat);
65
- }
66
- // Make sure we don't send the same batch of meat with every chunk
67
- m = 0;
68
- result &&= r.includes(successString);
69
- }
70
- return result;
71
- }
72
- /**
73
- * Sends a kmail to a player
74
- *
75
- * Sends multiple kmails if more than 11 unique item types are attached.
76
- * Ignores any ungiftable items.
77
- * Sends a gift package to players in run
78
- *
79
- * @param to The player name or id to receive the kmail
80
- * @param message The text contents of the message
81
- * @param items The items to be attached
82
- * @param meat The quantity of meat to be attached
83
- * @returns True if the kmail was successfully sent
84
- */
85
- static send(to, message = "", items = [], meat = 0) {
86
- return Kmail._genericSend(to, message, items, meat, 11, ({ meat }) => ({
87
- path: "sendmessage.php",
88
- query: {
89
- action: "send",
90
- pwd: EMPTY_VALUE,
91
- towho: to,
92
- message,
93
- sendmeat: meat,
94
- },
95
- }), ">Message sent.</");
96
- }
97
- /**
98
- * Sends a gift to a player
99
- *
100
- * Sends multiple kmails if more than 3 unique item types are attached.
101
- * Ignores any ungiftable items.
102
- *
103
- * @param to The player name or id to receive the gift
104
- * @param message Message to send
105
- * @param items The items to be attached
106
- * @param meat The quantity of meat to be attached
107
- * @param insideNote The note on the inside of the gift
108
- * @returns True if the gift was successfully sent
109
- */
110
- static gift(to, message = "", items = [], meat = 0, insideNote = "") {
111
- return Kmail._genericSend(to, message, items, meat, 3, ({ meat, chunkSize }) => ({
112
- path: `town_sendgift.php`,
113
- query: {
114
- action: "Yep.",
115
- pwd: EMPTY_VALUE,
116
- fromwhere: 0,
117
- note: message,
118
- insidenote: insideNote,
119
- towho: to,
120
- whichpackage: chunkSize,
121
- sendmeat: meat,
122
- },
123
- }), ">Package sent.</");
124
- }
125
- constructor(rawKmail) {
126
- const date = new Date(rawKmail.localtime);
127
- // Date come from KoL formatted with YY and so will be parsed 19YY, which is wrong.
128
- // We can safely add 100 because if 19YY was a leap year, 20YY will be too!
129
- date.setFullYear(date.getFullYear() + 100);
130
- this.id = Number(rawKmail.id);
131
- this.date = date;
132
- this.type = rawKmail.type;
133
- this.senderId = Number(rawKmail.fromid);
134
- this.senderName = rawKmail.fromname;
135
- this.rawMessage = rawKmail.message;
136
- }
137
- /**
138
- * Delete the kmail
139
- *
140
- * @returns Whether the kmail was deleted
141
- */
142
- delete() {
143
- return Kmail.delete([this]) === 1;
144
- }
145
- /**
146
- * Get message contents without any HTML from items or meat
147
- *
148
- * @returns Cleaned message contents
149
- */
150
- get message() {
151
- const match = this.rawMessage.match(/^(.*?)</s);
152
- return match ? match[1] : this.rawMessage;
153
- }
154
- /**
155
- * Get items attached to the kmail
156
- *
157
- * @returns Map of items attached to the kmail and their quantities
158
- */
159
- items() {
160
- return new Map(Object.entries(extractItems(this.rawMessage)).map(([itemName, quantity]) => [Item.get(itemName), quantity]));
161
- }
162
- /**
163
- * Get meat attached to the kmail
164
- *
165
- * @returns Meat attached to the kmail
166
- */
167
- meat() {
168
- return extractMeat(this.rawMessage);
169
- }
170
- /**
171
- * Reply to kmail
172
- *
173
- * @param message Message with which to reply
174
- * @param items Items to send
175
- * @param meat Meat to send
176
- * @see Kmail.send
177
- * @returns True if the kmail was successfully sent
178
- */
179
- reply(message = "", items = [], meat = 0) {
180
- return Kmail.send(this.senderId, message, items, meat);
181
- }
182
- }
@@ -1,131 +0,0 @@
1
- import { Familiar, Item, Skill } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { Requirement } from "../maximize";
4
- export declare type FindActionSourceConstraints = {
5
- /**
6
- * Function returning true if we only accept familiar-based actions.
7
- */
8
- requireFamiliar?: () => boolean;
9
- /**
10
- * Function returning true if we only accept sources that are unlimited.
11
- */
12
- requireUnlimited?: () => boolean;
13
- /**
14
- * Function returning whether to disallow actions requiring familiar change.
15
- */
16
- noFamiliar?: () => boolean;
17
- /**
18
- * Function returning whether to disallow actions requiring equipment change.
19
- */
20
- noRequirements?: () => boolean;
21
- /**
22
- * Function returning whether to disallow actions requiring preparation.
23
- */
24
- noPreparation?: () => boolean;
25
- /**
26
- * Function returning maximum cost of allowed actions. If undefined, allow
27
- * only actions that cost nothing.
28
- */
29
- maximumCost?: () => number;
30
- /**
31
- * Function allowing for custom logic if an action should be allowed.
32
- * If undefined, allow all actions to be considered by other constraints.
33
- *
34
- * @param action The action that is being considered.
35
- * @returns True if the action should be allowed.
36
- */
37
- allowedAction?: (action: ActionSource) => boolean;
38
- };
39
- export declare type ActionConstraints = {
40
- /**
41
- * Equipment requirements to have this action available.
42
- */
43
- equipmentRequirements?: () => Requirement;
44
- /**
45
- * Familiar required to be in use to have this action available.
46
- */
47
- familiar?: () => Familiar;
48
- /**
49
- * Miscellaneous preparation to ensure this action is available.
50
- */
51
- preparation?: () => boolean;
52
- /**
53
- * Cost in meat per usage of this action.
54
- */
55
- cost?: () => number;
56
- };
57
- /**
58
- * A combat-based action resource in the game (e.g. a free run or free kill).
59
- */
60
- export declare class ActionSource {
61
- static defaultPriceFunction: (item: Item) => number;
62
- source: Item | Skill | Familiar | Array<Item | Skill | Familiar>;
63
- potential: () => number;
64
- macro: Macro;
65
- constraints: ActionConstraints;
66
- /**
67
- * @param source Source(s) of the action (e.g. item, skill, or familiar needed).
68
- * @param potential Function returning how many times this action can be used.
69
- * @param macro Macro to execute this action in combat.
70
- * @param constraints Constraints required for this action to be available.
71
- */
72
- constructor(source: Item | Skill | Familiar | Array<Item | Skill | Familiar>, potential: () => number, macro: Macro, constraints?: ActionConstraints);
73
- /**
74
- * @returns Name of the action source.
75
- */
76
- name(): string;
77
- /**
78
- * @returns Whether the action is available.
79
- */
80
- available(): boolean;
81
- /**
82
- * @returns Cost in meat per usage of the action.
83
- */
84
- cost(): number;
85
- /**
86
- * @returns Whether the action costs 0 meat to use.
87
- */
88
- isFree(): boolean;
89
- /**
90
- * @returns Whether unlimited uses of the action are available.
91
- */
92
- isUnlimited(): boolean;
93
- /**
94
- * Create a compound action source with merged constraints.
95
- *
96
- * @param others Other actions to have available.
97
- * @returns Merged constraints, or null if they are inconsistent.
98
- */
99
- merge(...others: ActionSource[]): ActionSource | null;
100
- /**
101
- * Perform all preparation necessary to make this action available.
102
- *
103
- * @param otherRequirements Any other equipment requirements.
104
- * @returns Whether preparation succeeded.
105
- */
106
- prepare(otherRequirements?: Requirement): boolean;
107
- /**
108
- * Perform all preparation necessary to make this action available.
109
- * Throws an error if preparation fails.
110
- *
111
- * @param otherRequirements Any other equipment requirements.
112
- */
113
- ensure(otherRequirements?: Requirement): void;
114
- }
115
- /**
116
- * Find an available action source subject to constraints.
117
- *
118
- * @param actions Action source list.
119
- * @param constraints Preexisting constraints that restrict possible sources.
120
- * @returns Available action source satisfying constraints, or null.
121
- */
122
- export declare function findActionSource(actions: ActionSource[], constraints?: FindActionSourceConstraints): ActionSource | null;
123
- /**
124
- * Count available action sources subject to constraints. Note that, if
125
- * constraints.maximumCost is high enough, this will return Infinity.
126
- *
127
- * @param actions Action source list.
128
- * @param constraints Preexisting constraints that restrict possible sources.
129
- * @returns Count of available action sources.
130
- */
131
- export declare function actionSourcesAvailable(actions: ActionSource[], constraints?: FindActionSourceConstraints): number;
@@ -1,177 +0,0 @@
1
- import { mallPrice, useFamiliar } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { Requirement } from "../maximize";
4
- import { sum, flat } from "../utils";
5
- /**
6
- * Merge a set of constraints into one
7
- *
8
- * @param allConstraints Constraints to mege
9
- * @returns Merged constraints
10
- */
11
- function mergeConstraints(...allConstraints) {
12
- const familiars = allConstraints
13
- .map((constraints) => constraints.familiar)
14
- .filter(Boolean);
15
- if (familiars.length > 1) {
16
- // Inconsistent requirements.
17
- return null;
18
- }
19
- return {
20
- equipmentRequirements: () => Requirement.merge([
21
- ...allConstraints.map((constraints) => constraints.equipmentRequirements?.() ?? new Requirement([], {})),
22
- ]),
23
- preparation: () => {
24
- let success = true;
25
- for (const constraints of allConstraints) {
26
- success =
27
- success && (!constraints.preparation || constraints.preparation());
28
- }
29
- return success;
30
- },
31
- familiar: familiars.find((familiar) => familiar),
32
- cost: () => sum(allConstraints, (constraints) => constraints.cost?.() ?? 0),
33
- };
34
- }
35
- /**
36
- * A combat-based action resource in the game (e.g. a free run or free kill).
37
- */
38
- export class ActionSource {
39
- static defaultPriceFunction = (item) => mallPrice(item) > 0 ? mallPrice(item) : Infinity;
40
- source;
41
- potential; // Infinity: unlimited
42
- macro;
43
- constraints;
44
- /**
45
- * @param source Source(s) of the action (e.g. item, skill, or familiar needed).
46
- * @param potential Function returning how many times this action can be used.
47
- * @param macro Macro to execute this action in combat.
48
- * @param constraints Constraints required for this action to be available.
49
- */
50
- constructor(source, potential, macro, constraints = {}) {
51
- this.source = source;
52
- this.potential = potential;
53
- this.macro = macro;
54
- this.constraints = constraints;
55
- }
56
- /**
57
- * @returns Name of the action source.
58
- */
59
- name() {
60
- return this.source.toString();
61
- }
62
- /**
63
- * @returns Whether the action is available.
64
- */
65
- available() {
66
- return this.potential() > 0;
67
- }
68
- /**
69
- * @returns Cost in meat per usage of the action.
70
- */
71
- cost() {
72
- return this.constraints.cost ? this.constraints.cost() : 0;
73
- }
74
- /**
75
- * @returns Whether the action costs 0 meat to use.
76
- */
77
- isFree() {
78
- return !this.cost || this.cost() === 0;
79
- }
80
- /**
81
- * @returns Whether unlimited uses of the action are available.
82
- */
83
- isUnlimited() {
84
- return this.potential() === Infinity;
85
- }
86
- /**
87
- * Create a compound action source with merged constraints.
88
- *
89
- * @param others Other actions to have available.
90
- * @returns Merged constraints, or null if they are inconsistent.
91
- */
92
- merge(...others) {
93
- const actions = [this, ...others];
94
- const constraints = mergeConstraints(...actions.map((action) => action.constraints));
95
- if (constraints === null) {
96
- // Inconsistent constraints - no path forward here.
97
- return null;
98
- }
99
- return new ActionSource([...flat(actions.map((action) => action.source))], () => sum(actions, (action) => action.potential()), Macro.step(...actions.map((action) => action.macro)), constraints);
100
- }
101
- /**
102
- * Perform all preparation necessary to make this action available.
103
- *
104
- * @param otherRequirements Any other equipment requirements.
105
- * @returns Whether preparation succeeded.
106
- */
107
- prepare(otherRequirements) {
108
- if (this.constraints.familiar?.()) {
109
- if (!useFamiliar(this.constraints.familiar()))
110
- return false;
111
- }
112
- if (this.constraints.equipmentRequirements) {
113
- const requirement = otherRequirements
114
- ? otherRequirements.merge(this.constraints.equipmentRequirements())
115
- : this.constraints.equipmentRequirements();
116
- if (!requirement.maximize())
117
- return false;
118
- }
119
- if (this.constraints.preparation)
120
- return this.constraints.preparation();
121
- return true;
122
- }
123
- /**
124
- * Perform all preparation necessary to make this action available.
125
- * Throws an error if preparation fails.
126
- *
127
- * @param otherRequirements Any other equipment requirements.
128
- */
129
- ensure(otherRequirements) {
130
- if (!this.prepare(otherRequirements)) {
131
- throw new Error(`Failed to prepare action ${this.name()}.`);
132
- }
133
- }
134
- }
135
- /**
136
- * See if a supplied action meets a set of constraints
137
- *
138
- * @param action Action to test
139
- * @param constraints Constraints to apply
140
- * @returns Whether action meets constraints
141
- */
142
- function filterAction(action, constraints) {
143
- return (action.available() &&
144
- (constraints.allowedAction === undefined ||
145
- constraints.allowedAction(action)) &&
146
- !(constraints.requireFamiliar?.() && !action.constraints.familiar) &&
147
- !(constraints.requireUnlimited?.() && !action.isUnlimited()) &&
148
- !(constraints.noFamiliar?.() && action.constraints.familiar) &&
149
- !(constraints.noRequirements?.() && action.constraints.equipmentRequirements) &&
150
- !(constraints.noPreparation?.() && action.constraints.preparation) &&
151
- action.cost() <= (constraints.maximumCost?.() ?? 0));
152
- }
153
- /**
154
- * Find an available action source subject to constraints.
155
- *
156
- * @param actions Action source list.
157
- * @param constraints Preexisting constraints that restrict possible sources.
158
- * @returns Available action source satisfying constraints, or null.
159
- */
160
- export function findActionSource(actions, constraints = {}) {
161
- const validActions = actions.filter((actions) => filterAction(actions, constraints));
162
- if (validActions.length < 1)
163
- return null;
164
- return validActions.reduce((a, b) => (a.cost() <= b.cost() ? a : b));
165
- }
166
- /**
167
- * Count available action sources subject to constraints. Note that, if
168
- * constraints.maximumCost is high enough, this will return Infinity.
169
- *
170
- * @param actions Action source list.
171
- * @param constraints Preexisting constraints that restrict possible sources.
172
- * @returns Count of available action sources.
173
- */
174
- export function actionSourcesAvailable(actions, constraints = {}) {
175
- // TODO: This will overcount if any Actions share a counter
176
- return sum(actions.filter((action) => filterAction(action, constraints ?? {})), (action) => action.potential());
177
- }
@@ -1,16 +0,0 @@
1
- import { ActionSource, FindActionSourceConstraints } from "./ActionSource";
2
- /**
3
- * Find an available banish source subject to constraints.
4
- *
5
- * @param constraints Preexisting constraints that restrict possible sources.
6
- * @returns Banish source satisfying constraints, or null.
7
- */
8
- export declare function tryFindBanish(constraints?: FindActionSourceConstraints): ActionSource | null;
9
- /**
10
- * Ensure an available banish source subject to constraints.
11
- * Throws an error if no source can be found.
12
- *
13
- * @param constraints Preexisting constraints that restrict possible sources.
14
- * @returns Banish source satisfying constraints.
15
- */
16
- export declare function ensureBanish(constraints?: FindActionSourceConstraints): ActionSource;