libram 0.8.28 → 0.8.29

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/dist/Clan.d.ts +128 -0
  2. package/dist/Clan.js +300 -0
  3. package/dist/Copier.d.ts +9 -0
  4. package/dist/Copier.js +15 -0
  5. package/dist/Dungeon.d.ts +45 -0
  6. package/dist/Dungeon.js +115 -0
  7. package/dist/Kmail.d.ts +133 -0
  8. package/dist/Kmail.js +259 -0
  9. package/dist/actions/ActionSource.d.ts +131 -0
  10. package/dist/actions/ActionSource.js +178 -0
  11. package/dist/actions/Banish.d.ts +16 -0
  12. package/dist/actions/Banish.js +121 -0
  13. package/dist/actions/FreeKill.d.ts +16 -0
  14. package/dist/actions/FreeKill.js +94 -0
  15. package/dist/actions/FreeRun.d.ts +16 -0
  16. package/dist/actions/FreeRun.js +81 -0
  17. package/dist/actions/index.d.ts +4 -0
  18. package/dist/actions/index.js +4 -0
  19. package/dist/ascend.d.ts +83 -0
  20. package/dist/ascend.js +268 -0
  21. package/dist/challengePaths/2014/HeavyRains.d.ts +22 -0
  22. package/dist/challengePaths/2014/HeavyRains.js +75 -0
  23. package/dist/challengePaths/2015/CommunityService.d.ts +125 -0
  24. package/dist/challengePaths/2015/CommunityService.js +334 -0
  25. package/dist/challengePaths/2016/NuclearAutumn.d.ts +13 -0
  26. package/dist/challengePaths/2016/NuclearAutumn.js +21 -0
  27. package/dist/challengePaths/index.d.ts +4 -0
  28. package/dist/challengePaths/index.js +4 -0
  29. package/dist/combat.d.ts +414 -0
  30. package/dist/combat.js +711 -0
  31. package/dist/console.d.ts +12 -0
  32. package/dist/console.js +14 -0
  33. package/dist/counter.d.ts +22 -0
  34. package/dist/counter.js +37 -0
  35. package/dist/diet/index.d.ts +80 -0
  36. package/dist/diet/index.js +680 -0
  37. package/dist/diet/knapsack.d.ts +8 -0
  38. package/dist/diet/knapsack.js +128 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +26 -0
  41. package/dist/lib.d.ts +507 -0
  42. package/dist/lib.js +970 -0
  43. package/dist/logger.d.ts +35 -0
  44. package/dist/logger.js +62 -0
  45. package/dist/maximize.d.ts +122 -0
  46. package/dist/maximize.js +531 -0
  47. package/dist/modifier.d.ts +41 -0
  48. package/dist/modifier.js +160 -0
  49. package/dist/modifierTypes.d.ts +16 -0
  50. package/dist/modifierTypes.js +9 -0
  51. package/dist/mood.d.ts +105 -0
  52. package/dist/mood.js +349 -0
  53. package/dist/moonSign.d.ts +13 -0
  54. package/dist/moonSign.js +25 -0
  55. package/dist/overlappingNames.d.ts +3 -0
  56. package/dist/overlappingNames.js +42 -0
  57. package/dist/property.d.ts +222 -0
  58. package/dist/property.js +385 -0
  59. package/dist/propertyTypes.d.ts +19 -0
  60. package/dist/propertyTypes.js +10 -0
  61. package/dist/propertyTyping.d.ts +65 -0
  62. package/dist/propertyTyping.js +91 -0
  63. package/dist/resources/2007/CandyHearts.d.ts +9 -0
  64. package/dist/resources/2007/CandyHearts.js +24 -0
  65. package/dist/resources/2008/DivineFavors.d.ts +9 -0
  66. package/dist/resources/2008/DivineFavors.js +27 -0
  67. package/dist/resources/2008/Stickers.d.ts +49 -0
  68. package/dist/resources/2008/Stickers.js +84 -0
  69. package/dist/resources/2009/Bandersnatch.d.ts +56 -0
  70. package/dist/resources/2009/Bandersnatch.js +93 -0
  71. package/dist/resources/2009/LoveSongs.d.ts +9 -0
  72. package/dist/resources/2009/LoveSongs.js +24 -0
  73. package/dist/resources/2009/SpookyPutty.d.ts +31 -0
  74. package/dist/resources/2009/SpookyPutty.js +49 -0
  75. package/dist/resources/2010/Brickos.d.ts +9 -0
  76. package/dist/resources/2010/Brickos.js +21 -0
  77. package/dist/resources/2010/CrownOfThrones.d.ts +68 -0
  78. package/dist/resources/2010/CrownOfThrones.js +418 -0
  79. package/dist/resources/2010/LookingGlass.d.ts +29 -0
  80. package/dist/resources/2010/LookingGlass.js +89 -0
  81. package/dist/resources/2011/Gygaxian.d.ts +9 -0
  82. package/dist/resources/2011/Gygaxian.js +24 -0
  83. package/dist/resources/2011/ObtuseAngel.d.ts +33 -0
  84. package/dist/resources/2011/ObtuseAngel.js +51 -0
  85. package/dist/resources/2011/StompingBoots.d.ts +37 -0
  86. package/dist/resources/2011/StompingBoots.js +57 -0
  87. package/dist/resources/2012/RainDoh.d.ts +25 -0
  88. package/dist/resources/2012/RainDoh.js +37 -0
  89. package/dist/resources/2012/ReagnimatedGnome.d.ts +31 -0
  90. package/dist/resources/2012/ReagnimatedGnome.js +46 -0
  91. package/dist/resources/2012/Resolutions.d.ts +9 -0
  92. package/dist/resources/2012/Resolutions.js +28 -0
  93. package/dist/resources/2013/Florist.d.ts +81 -0
  94. package/dist/resources/2013/Florist.js +245 -0
  95. package/dist/resources/2013/JungMan.d.ts +33 -0
  96. package/dist/resources/2013/JungMan.js +69 -0
  97. package/dist/resources/2013/PulledTaffy.d.ts +9 -0
  98. package/dist/resources/2013/PulledTaffy.js +33 -0
  99. package/dist/resources/2014/CrimboShrub.d.ts +42 -0
  100. package/dist/resources/2014/CrimboShrub.js +89 -0
  101. package/dist/resources/2014/DNALab.d.ts +56 -0
  102. package/dist/resources/2014/DNALab.js +162 -0
  103. package/dist/resources/2014/WinterGarden.d.ts +23 -0
  104. package/dist/resources/2014/WinterGarden.js +35 -0
  105. package/dist/resources/2015/BarrelShrine.d.ts +8 -0
  106. package/dist/resources/2015/BarrelShrine.js +25 -0
  107. package/dist/resources/2015/ChateauMantegna.d.ts +52 -0
  108. package/dist/resources/2015/ChateauMantegna.js +99 -0
  109. package/dist/resources/2015/DeckOfEveryCard.d.ts +29 -0
  110. package/dist/resources/2015/DeckOfEveryCard.js +122 -0
  111. package/dist/resources/2015/Dinseylandfill.d.ts +89 -0
  112. package/dist/resources/2015/Dinseylandfill.js +205 -0
  113. package/dist/resources/2015/MayoClinic.d.ts +23 -0
  114. package/dist/resources/2015/MayoClinic.js +49 -0
  115. package/dist/resources/2016/GingerBread.d.ts +32 -0
  116. package/dist/resources/2016/GingerBread.js +73 -0
  117. package/dist/resources/2016/SourceTerminal.d.ts +181 -0
  118. package/dist/resources/2016/SourceTerminal.js +275 -0
  119. package/dist/resources/2016/Witchess.d.ts +17 -0
  120. package/dist/resources/2016/Witchess.js +47 -0
  121. package/dist/resources/2017/AsdonMartin.d.ts +59 -0
  122. package/dist/resources/2017/AsdonMartin.js +238 -0
  123. package/dist/resources/2017/Horsery.d.ts +19 -0
  124. package/dist/resources/2017/Horsery.js +42 -0
  125. package/dist/resources/2017/MummingTrunk.d.ts +8 -0
  126. package/dist/resources/2017/MummingTrunk.js +33 -0
  127. package/dist/resources/2017/Pantogram.d.ts +92 -0
  128. package/dist/resources/2017/Pantogram.js +174 -0
  129. package/dist/resources/2017/Robortender.d.ts +30 -0
  130. package/dist/resources/2017/Robortender.js +90 -0
  131. package/dist/resources/2017/Spacegate.d.ts +86 -0
  132. package/dist/resources/2017/Spacegate.js +178 -0
  133. package/dist/resources/2017/TunnelOfLove.d.ts +39 -0
  134. package/dist/resources/2017/TunnelOfLove.js +120 -0
  135. package/dist/resources/2018/LatteLoversMembersMug.d.ts +392 -0
  136. package/dist/resources/2018/LatteLoversMembersMug.js +303 -0
  137. package/dist/resources/2018/SongBoom.d.ts +33 -0
  138. package/dist/resources/2018/SongBoom.js +55 -0
  139. package/dist/resources/2019/BeachComb.d.ts +72 -0
  140. package/dist/resources/2019/BeachComb.js +118 -0
  141. package/dist/resources/2019/CampAway.d.ts +39 -0
  142. package/dist/resources/2019/CampAway.js +72 -0
  143. package/dist/resources/2019/Snapper.d.ts +33 -0
  144. package/dist/resources/2019/Snapper.js +73 -0
  145. package/dist/resources/2020/Cartography.d.ts +16 -0
  146. package/dist/resources/2020/Cartography.js +48 -0
  147. package/dist/resources/2020/Guzzlr.d.ts +160 -0
  148. package/dist/resources/2020/Guzzlr.js +275 -0
  149. package/dist/resources/2020/RetroCape.d.ts +51 -0
  150. package/dist/resources/2020/RetroCape.js +115 -0
  151. package/dist/resources/2021/CrystalBall.d.ts +14 -0
  152. package/dist/resources/2021/CrystalBall.js +41 -0
  153. package/dist/resources/2021/DaylightShavings.d.ts +40 -0
  154. package/dist/resources/2021/DaylightShavings.js +74 -0
  155. package/dist/resources/2022/AutumnAton.d.ts +78 -0
  156. package/dist/resources/2022/AutumnAton.js +182 -0
  157. package/dist/resources/2022/CombatLoversLocket.d.ts +44 -0
  158. package/dist/resources/2022/CombatLoversLocket.js +82 -0
  159. package/dist/resources/2022/GreyGoose.d.ts +59 -0
  160. package/dist/resources/2022/GreyGoose.js +90 -0
  161. package/dist/resources/2022/JuneCleaver.d.ts +47 -0
  162. package/dist/resources/2022/JuneCleaver.js +69 -0
  163. package/dist/resources/2022/TrainSet.d.ts +146 -0
  164. package/dist/resources/2022/TrainSet.js +228 -0
  165. package/dist/resources/2023/AugustScepter.d.ts +25 -0
  166. package/dist/resources/2023/AugustScepter.js +40 -0
  167. package/dist/resources/2023/BurningLeaves.d.ts +25 -0
  168. package/dist/resources/2023/BurningLeaves.js +74 -0
  169. package/dist/resources/2023/CinchoDeMayo.d.ts +25 -0
  170. package/dist/resources/2023/CinchoDeMayo.js +45 -0
  171. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +80 -0
  172. package/dist/resources/2023/ClosedCircuitPayphone.js +129 -0
  173. package/dist/resources/2023/CursedMonkeyPaw.d.ts +46 -0
  174. package/dist/resources/2023/CursedMonkeyPaw.js +113 -0
  175. package/dist/resources/2024/AprilingBandHelmet.d.ts +57 -0
  176. package/dist/resources/2024/AprilingBandHelmet.js +118 -0
  177. package/dist/resources/2024/ChestMimic.d.ts +42 -0
  178. package/dist/resources/2024/ChestMimic.js +125 -0
  179. package/dist/resources/LibramSummon.d.ts +18 -0
  180. package/dist/resources/LibramSummon.js +74 -0
  181. package/dist/resources/index.d.ts +54 -0
  182. package/dist/resources/index.js +54 -0
  183. package/dist/resources/putty-likes.d.ts +21 -0
  184. package/dist/resources/putty-likes.js +33 -0
  185. package/dist/session.d.ts +169 -0
  186. package/dist/session.js +284 -0
  187. package/dist/since.d.ts +51 -0
  188. package/dist/since.js +108 -0
  189. package/dist/template-string.d.ts +324 -0
  190. package/dist/template-string.js +265 -0
  191. package/dist/url.d.ts +35 -0
  192. package/dist/url.js +67 -0
  193. package/dist/utils.d.ts +178 -0
  194. package/dist/utils.js +255 -0
  195. package/package.json +2 -2
@@ -0,0 +1,25 @@
1
+ const MoonSigns = [
2
+ "Mongoose",
3
+ "Wallaby",
4
+ "Vole",
5
+ "Platypus",
6
+ "Opossum",
7
+ "Marmot",
8
+ "Wombat",
9
+ "Blender",
10
+ "Packrat",
11
+ ];
12
+ /**
13
+ * @param moon Moon sign name
14
+ * @returns Moon sign id else 0
15
+ */
16
+ export function signNameToId(moon) {
17
+ return MoonSigns.indexOf(moon) + 1;
18
+ }
19
+ /**
20
+ * @param id Moon sign id
21
+ * @returns Name of moon sign else "None"
22
+ */
23
+ export function signIdToName(id) {
24
+ return MoonSigns[id - 1] || "None";
25
+ }
@@ -0,0 +1,3 @@
1
+ /** THIS FILE IS AUTOMATICALLY GENERATED. See tools/parseItemSkillNames.ts for more information */
2
+ export declare const overlappingItemNames: string[];
3
+ export declare const overlappingSkillNames: string[];
@@ -0,0 +1,42 @@
1
+ /** THIS FILE IS AUTOMATICALLY GENERATED. See tools/parseItemSkillNames.ts for more information */
2
+ export const overlappingItemNames = [
3
+ "spider web",
4
+ "really sticky spider web",
5
+ "dictionary",
6
+ "NG",
7
+ "Cloaca-Cola",
8
+ "yo-yo",
9
+ "top",
10
+ "ball",
11
+ "kite",
12
+ "yo",
13
+ "red potion",
14
+ "blue potion",
15
+ "bowling ball",
16
+ "adder",
17
+ "red button",
18
+ "pile of sand",
19
+ "mushroom",
20
+ "deluxe mushroom",
21
+ ];
22
+ export const overlappingSkillNames = [
23
+ "Shoot",
24
+ "Thrust-Smack",
25
+ "Headbutt",
26
+ "Toss",
27
+ "Knife in the Dark",
28
+ "Sing",
29
+ "Disarm",
30
+ "LIGHT",
31
+ "BURN",
32
+ "Extract",
33
+ "Meteor Shower",
34
+ "Snipe",
35
+ "Bite",
36
+ "Kick",
37
+ "Howl",
38
+ "Cleave",
39
+ "Boil",
40
+ "Slice",
41
+ "Rainbow",
42
+ ];
@@ -0,0 +1,222 @@
1
+ import { Bounty, Class, Coinmaster, Effect, Element, Familiar, Item, Location, Monster, Phylum, Servant, Skill, Slot, Stat, Thrall } from "kolmafia";
2
+ import { BooleanProperty, FamiliarProperty, LocationProperty, MonsterProperty, NumericOrStringProperty, NumericProperty, PhylumProperty, StatProperty, StringProperty } from "./propertyTypes";
3
+ import { KnownProperty } from "./propertyTyping";
4
+ export declare const getString: (property: string, default_?: string | undefined) => string;
5
+ export declare const getCommaSeparated: (property: string, default_?: string[] | undefined) => string[];
6
+ export declare const getBoolean: (property: string, default_?: boolean | undefined) => boolean;
7
+ export declare const getNumber: (property: string, default_?: number | undefined) => number;
8
+ export declare const getBounty: (property: string, default_?: Bounty | undefined) => Bounty | null;
9
+ export declare const getClass: (property: string, default_?: Class | undefined) => Class | null;
10
+ export declare const getCoinmaster: (property: string, default_?: Coinmaster | undefined) => Coinmaster | null;
11
+ export declare const getEffect: (property: string, default_?: Effect | undefined) => Effect | null;
12
+ export declare const getElement: (property: string, default_?: Element | undefined) => Element | null;
13
+ export declare const getFamiliar: (property: string, default_?: Familiar | undefined) => Familiar | null;
14
+ export declare const getItem: (property: string, default_?: Item | undefined) => Item | null;
15
+ export declare const getLocation: (property: string, default_?: Location | undefined) => Location | null;
16
+ export declare const getMonster: (property: string, default_?: Monster | undefined) => Monster | null;
17
+ export declare const getPhylum: (property: string, default_?: Phylum | undefined) => Phylum | null;
18
+ export declare const getServant: (property: string, default_?: Servant | undefined) => Servant | null;
19
+ export declare const getSkill: (property: string, default_?: Skill | undefined) => Skill | null;
20
+ export declare const getSlot: (property: string, default_?: Slot | undefined) => Slot | null;
21
+ export declare const getStat: (property: string, default_?: Stat | undefined) => Stat | null;
22
+ export declare const getThrall: (property: string, default_?: Thrall | undefined) => Thrall | null;
23
+ export declare function get(property: BooleanProperty): boolean;
24
+ export declare function get(property: BooleanProperty, _default: boolean): boolean;
25
+ export declare function get(property: NumericProperty): number;
26
+ export declare function get(property: NumericProperty, _default: number): number;
27
+ export declare function get(property: NumericOrStringProperty): number | string;
28
+ export declare function get(property: NumericOrStringProperty, _default: number | string): number | string;
29
+ export declare function get(property: StringProperty): string;
30
+ export declare function get(property: StringProperty, _default: string): string;
31
+ export declare function get(property: LocationProperty): Location | null;
32
+ export declare function get(property: LocationProperty, _default: Location): Location;
33
+ export declare function get(property: MonsterProperty): Monster | null;
34
+ export declare function get(property: MonsterProperty, _default: Monster): Monster;
35
+ export declare function get(property: FamiliarProperty): Familiar | null;
36
+ export declare function get(property: FamiliarProperty, _default: Familiar): Familiar;
37
+ export declare function get(property: StatProperty): Stat | null;
38
+ export declare function get(property: StatProperty, _default: Stat): Stat;
39
+ export declare function get(property: PhylumProperty): Phylum | null;
40
+ export declare function get(property: PhylumProperty, _default: Phylum): Phylum;
41
+ export declare function get(property: string, _default: Location): Location | null;
42
+ export declare function get(property: string, _default: Monster): Monster | null;
43
+ export declare function get(property: string, _default: Familiar): Familiar | null;
44
+ export declare function get(property: string, _default: boolean): boolean;
45
+ export declare function get(property: string, _default: number): number;
46
+ export declare function get(property: string, _default?: string): string;
47
+ export declare function set(property: BooleanProperty, value: boolean): boolean;
48
+ export declare function set(property: NumericProperty, value: number): number;
49
+ export declare function set<T extends number | string>(property: NumericOrStringProperty, value: T): T;
50
+ export declare function set(property: StringProperty, value: string): string;
51
+ export declare function set(property: LocationProperty, value: Location): Location;
52
+ export declare function set(property: MonsterProperty, value: Monster): Monster;
53
+ export declare function set(property: FamiliarProperty, value: Familiar): Familiar;
54
+ export declare function set(property: StatProperty, value: Stat): Stat;
55
+ export declare function set(property: PhylumProperty, value: Phylum): Phylum;
56
+ export declare function set<D extends {
57
+ toString(): string;
58
+ }>(property: string, value: D): D;
59
+ /**
60
+ * Increment a property
61
+ *
62
+ * @param property Numeric property to increment
63
+ * @param delta Number by which to increment
64
+ * @param max Maximum value to set
65
+ * @returns New value
66
+ */
67
+ export declare function increment(property: NumericProperty, delta?: number, max?: number): number;
68
+ /**
69
+ * Decrement a property
70
+ *
71
+ * @param property Numeric property to decrement
72
+ * @param delta Number by which to decrement
73
+ * @param min Maximum value to set
74
+ * @returns New value
75
+ */
76
+ export declare function decrement(property: NumericProperty, delta?: number, min?: number): number;
77
+ declare type Properties = Partial<{
78
+ [P in KnownProperty]: unknown;
79
+ }> & {
80
+ [x in string]: unknown;
81
+ };
82
+ /**
83
+ * Sets the value of a set of mafia properties
84
+ *
85
+ * @param properties Set of properties
86
+ */
87
+ export declare function setProperties(properties: Properties): void;
88
+ /**
89
+ * Carries out a callback during which a set of properties will be set as supplied
90
+ *
91
+ * @param properties Properties to set during callback
92
+ * @param callback Callback to execute with set properties
93
+ * @returns Return value of the supplied callback
94
+ */
95
+ export declare function withProperties<T>(properties: Properties, callback: () => T): T;
96
+ /**
97
+ * Carries out a callback during which a property will be set as supplied
98
+ *
99
+ * @param property Property to set during callback
100
+ * @param value Value to set property during callback
101
+ * @param callback Callback to execute with set properties
102
+ * @returns Return value of the supplied callback
103
+ */
104
+ export declare function withProperty<P extends KnownProperty, T>(property: P, value: unknown, callback: () => T): T;
105
+ /**
106
+ * Carries out a callback during which a set of choices will be handled as supplied
107
+ *
108
+ * @param choices Choices to set during callback
109
+ * @param callback Callback to execute with set choices
110
+ * @returns Return value of the supplied callback
111
+ */
112
+ export declare function withChoices<T>(choices: {
113
+ [choice: number]: number | string;
114
+ }, callback: () => T): T;
115
+ /**
116
+ * Carries out a callback during which a choice will be handled as supplied
117
+ *
118
+ * @param choice Choice to set during callback
119
+ * @param value How to handle choice during callback
120
+ * @param callback Callback to execute with set properties
121
+ * @returns Return value of the supplied callback
122
+ */
123
+ export declare function withChoice<T>(choice: number, value: number | string, callback: () => T): T;
124
+ export declare class PropertiesManager {
125
+ private static EMPTY_PREFERENCE;
126
+ private properties;
127
+ get storedValues(): Properties;
128
+ /**
129
+ * Sets a collection of properties to the given values, storing the old values.
130
+ *
131
+ * @param propertiesToSet A Properties object, keyed by property name.
132
+ */
133
+ set(propertiesToSet: Properties): void;
134
+ /**
135
+ * Sets a collection of choice adventure properties to the given values, storing the old values.
136
+ *
137
+ * @param choicesToSet An object keyed by choice adventure number.
138
+ */
139
+ setChoices(choicesToSet: {
140
+ [choice: number]: number | string;
141
+ }): void;
142
+ /**
143
+ * Sets a single choice adventure property to the given value, storing the old value.
144
+ *
145
+ * @param choiceToSet The number of the choice adventure to set the property for.
146
+ * @param value The value to assign to that choice adventure.
147
+ */
148
+ setChoice(choiceToSet: number, value: number | string): void;
149
+ /**
150
+ * Resets the given properties to their original stored value. Does not delete entries from the manager.
151
+ *
152
+ * @param properties Collection of properties to reset.
153
+ */
154
+ reset(...properties: KnownProperty[]): void;
155
+ /**
156
+ * Iterates over all stored values, setting each property back to its original stored value. Does not delete entries from the manager.
157
+ */
158
+ resetAll(): void;
159
+ /**
160
+ * Stops storing the original values of inputted properties.
161
+ *
162
+ * @param properties Properties for the manager to forget.
163
+ */
164
+ clear(...properties: (KnownProperty | string)[]): void;
165
+ /**
166
+ * Clears all properties.
167
+ */
168
+ clearAll(): void;
169
+ /**
170
+ * Increases a numeric property to the given value if necessary.
171
+ *
172
+ * @param property The numeric property we want to potentially raise.
173
+ * @param value The minimum value we want that property to have.
174
+ * @returns Whether we needed to change the property.
175
+ */
176
+ setMinimumValue(property: NumericProperty, value: number): boolean;
177
+ /**
178
+ * Decrease a numeric property to the given value if necessary.
179
+ *
180
+ * @param property The numeric property we want to potentially lower.
181
+ * @param value The maximum value we want that property to have.
182
+ * @returns Whether we needed to change the property.
183
+ */
184
+ setMaximumValue(property: NumericProperty, value: number): boolean;
185
+ /**
186
+ * Creates a new PropertiesManager with identical stored values to this one.
187
+ *
188
+ * @returns A new PropertiesManager, with identical stored values to this one.
189
+ */
190
+ clone(): PropertiesManager;
191
+ /**
192
+ * Clamps a numeric property, modulating it up or down to fit within a specified range
193
+ *
194
+ * @param property The numeric property to clamp
195
+ * @param min The lower bound for what we want the property to be allowed to be.
196
+ * @param max The upper bound for what we want the property to be allowed to be.
197
+ * @returns Whether we ended up changing the property or not.
198
+ */
199
+ clamp(property: NumericProperty, min: number, max: number): boolean;
200
+ /**
201
+ * Determines whether this PropertiesManager has identical stored values to another.
202
+ *
203
+ * @param other The PropertiesManager to compare to this one.
204
+ * @returns Whether their StoredValues are identical.
205
+ */
206
+ equals(other: PropertiesManager): boolean;
207
+ /**
208
+ * Merges a PropertiesManager onto this one, letting the input win in the event that both PropertiesManagers have a value stored.
209
+ *
210
+ * @param other The PropertiesManager to be merged onto this one.
211
+ * @returns A new PropertiesManager with stored values from both its parents.
212
+ */
213
+ merge(other: PropertiesManager): PropertiesManager;
214
+ /**
215
+ * Merges an arbitrary collection of PropertiesManagers, letting the rightmost PropertiesManager win in the event of verlap.
216
+ *
217
+ * @param mergees The PropertiesManagers to merge together.
218
+ * @returns A PropertiesManager that is just an amalgam of all the constituents.
219
+ */
220
+ static merge(...mergees: PropertiesManager[]): PropertiesManager;
221
+ }
222
+ export {};
@@ -0,0 +1,385 @@
1
+ import { Bounty, Class, Coinmaster, Effect, Element, Familiar, getProperty, Item, Location, Monster, Phylum, propertyExists, removeProperty, Servant, setProperty, Skill, Slot, Stat, Thrall, toBounty, toClass, toCoinmaster, toEffect, toElement, toFamiliar, toItem, toLocation, toMonster, toPhylum, toServant, toSkill, toSlot, toStat, toThrall, } from "kolmafia";
2
+ import { isBooleanProperty, isFamiliarProperty, isLocationProperty, isMonsterProperty, isNumericOrStringProperty, isNumericProperty, isPhylumProperty, isStatProperty, isStringProperty, } from "./propertyTyping";
3
+ const createPropertyGetter = (transform) => (property, default_) => {
4
+ const value = getProperty(property);
5
+ if (default_ !== undefined && value === "") {
6
+ return default_;
7
+ }
8
+ return transform(value, property);
9
+ };
10
+ const createMafiaClassPropertyGetter = (Type, toType) => createPropertyGetter((value) => {
11
+ if (value === "")
12
+ return null;
13
+ const v = toType(value);
14
+ return v === Type.none ? null : v;
15
+ });
16
+ export const getString = createPropertyGetter((value) => value);
17
+ export const getCommaSeparated = createPropertyGetter((value) => value.split(/, ?/));
18
+ export const getBoolean = createPropertyGetter((value) => value === "true");
19
+ export const getNumber = createPropertyGetter((value) => Number(value));
20
+ export const getBounty = createMafiaClassPropertyGetter(Bounty, toBounty);
21
+ export const getClass = createMafiaClassPropertyGetter(Class, toClass);
22
+ export const getCoinmaster = createMafiaClassPropertyGetter(Coinmaster, toCoinmaster);
23
+ export const getEffect = createMafiaClassPropertyGetter(Effect, toEffect);
24
+ export const getElement = createMafiaClassPropertyGetter(Element, toElement);
25
+ export const getFamiliar = createMafiaClassPropertyGetter(Familiar, toFamiliar);
26
+ export const getItem = createMafiaClassPropertyGetter(Item, toItem);
27
+ export const getLocation = createMafiaClassPropertyGetter(Location, toLocation);
28
+ export const getMonster = createMafiaClassPropertyGetter(Monster, toMonster);
29
+ export const getPhylum = createMafiaClassPropertyGetter(Phylum, toPhylum);
30
+ export const getServant = createMafiaClassPropertyGetter(Servant, toServant);
31
+ export const getSkill = createMafiaClassPropertyGetter(Skill, toSkill);
32
+ export const getSlot = createMafiaClassPropertyGetter(Slot, toSlot);
33
+ export const getStat = createMafiaClassPropertyGetter(Stat, toStat);
34
+ export const getThrall = createMafiaClassPropertyGetter(Thrall, toThrall);
35
+ /**
36
+ * Gets the value of a mafia property, either built in or custom
37
+ *
38
+ * @param property Name of the property
39
+ * @param _default Default value for the property to take if not set
40
+ * @returns Value of the mafia property
41
+ */
42
+ export function get(property, _default) {
43
+ const value = getString(property);
44
+ // Handle known properties.
45
+ if (isBooleanProperty(property)) {
46
+ return getBoolean(property, _default) ?? false;
47
+ }
48
+ else if (isNumericProperty(property)) {
49
+ return getNumber(property, _default) ?? 0;
50
+ }
51
+ else if (isNumericOrStringProperty(property)) {
52
+ return value.match(/^\d+$/) ? parseInt(value) : value;
53
+ }
54
+ else if (isLocationProperty(property)) {
55
+ return getLocation(property, _default);
56
+ }
57
+ else if (isMonsterProperty(property)) {
58
+ return getMonster(property, _default);
59
+ }
60
+ else if (isFamiliarProperty(property)) {
61
+ return getFamiliar(property, _default);
62
+ }
63
+ else if (isStatProperty(property)) {
64
+ return getStat(property, _default);
65
+ }
66
+ else if (isPhylumProperty(property)) {
67
+ return getPhylum(property, _default);
68
+ }
69
+ else if (isStringProperty(property)) {
70
+ return value;
71
+ }
72
+ // Not a KnownProperty from here on out.
73
+ if (_default instanceof Location) {
74
+ return getLocation(property, _default);
75
+ }
76
+ else if (_default instanceof Monster) {
77
+ return getMonster(property, _default);
78
+ }
79
+ else if (_default instanceof Familiar) {
80
+ return getFamiliar(property, _default);
81
+ }
82
+ else if (_default instanceof Stat) {
83
+ return getStat(property, _default);
84
+ }
85
+ else if (_default instanceof Phylum) {
86
+ return getPhylum(property, _default);
87
+ }
88
+ else if (typeof _default === "boolean") {
89
+ return value === "true" ? true : value === "false" ? false : _default;
90
+ }
91
+ else if (typeof _default === "number") {
92
+ return value === "" ? _default : parseInt(value);
93
+ }
94
+ else if (value === "") {
95
+ return _default === undefined ? "" : _default;
96
+ }
97
+ else {
98
+ return value;
99
+ }
100
+ }
101
+ /**
102
+ * Sets the value of a mafia property, either built in or custom
103
+ *
104
+ * @param property Name of the property
105
+ * @param value Value to give the property
106
+ * @returns Value that was set
107
+ */
108
+ export function set(property, value) {
109
+ const stringValue = value === null ? "" : value.toString();
110
+ setProperty(property, stringValue);
111
+ return value;
112
+ }
113
+ /**
114
+ * Increment a property
115
+ *
116
+ * @param property Numeric property to increment
117
+ * @param delta Number by which to increment
118
+ * @param max Maximum value to set
119
+ * @returns New value
120
+ */
121
+ export function increment(property, delta = 1, max = Infinity) {
122
+ const value = get(property);
123
+ if (!isNumericProperty(property))
124
+ return value;
125
+ const nextValue = Math.min(max, value + delta);
126
+ return set(property, nextValue);
127
+ }
128
+ /**
129
+ * Decrement a property
130
+ *
131
+ * @param property Numeric property to decrement
132
+ * @param delta Number by which to decrement
133
+ * @param min Maximum value to set
134
+ * @returns New value
135
+ */
136
+ export function decrement(property, delta = 1, min = Infinity) {
137
+ const value = get(property);
138
+ if (!isNumericProperty(property))
139
+ return value;
140
+ const nextValue = Math.max(min, value - delta);
141
+ return set(property, nextValue);
142
+ }
143
+ /**
144
+ * Sets the value of a set of mafia properties
145
+ *
146
+ * @param properties Set of properties
147
+ */
148
+ export function setProperties(properties) {
149
+ for (const [prop, value] of Object.entries(properties)) {
150
+ set(prop, value);
151
+ }
152
+ }
153
+ /**
154
+ * Carries out a callback during which a set of properties will be set as supplied
155
+ *
156
+ * @param properties Properties to set during callback
157
+ * @param callback Callback to execute with set properties
158
+ * @returns Return value of the supplied callback
159
+ */
160
+ export function withProperties(properties, callback) {
161
+ const propertiesBackup = Object.fromEntries(Object.entries(properties).map(([prop]) => [prop, get(prop)]));
162
+ setProperties(properties);
163
+ try {
164
+ return callback();
165
+ }
166
+ finally {
167
+ setProperties(propertiesBackup);
168
+ }
169
+ }
170
+ /**
171
+ * Carries out a callback during which a property will be set as supplied
172
+ *
173
+ * @param property Property to set during callback
174
+ * @param value Value to set property during callback
175
+ * @param callback Callback to execute with set properties
176
+ * @returns Return value of the supplied callback
177
+ */
178
+ export function withProperty(property, value, callback) {
179
+ return withProperties({ [property]: value }, callback);
180
+ }
181
+ /**
182
+ * Carries out a callback during which a set of choices will be handled as supplied
183
+ *
184
+ * @param choices Choices to set during callback
185
+ * @param callback Callback to execute with set choices
186
+ * @returns Return value of the supplied callback
187
+ */
188
+ export function withChoices(choices, callback) {
189
+ const properties = Object.fromEntries(Object.entries(choices).map(([choice, option]) => [
190
+ `choiceAdventure${choice}`,
191
+ option,
192
+ ]));
193
+ return withProperties(properties, callback);
194
+ }
195
+ /**
196
+ * Carries out a callback during which a choice will be handled as supplied
197
+ *
198
+ * @param choice Choice to set during callback
199
+ * @param value How to handle choice during callback
200
+ * @param callback Callback to execute with set properties
201
+ * @returns Return value of the supplied callback
202
+ */
203
+ export function withChoice(choice, value, callback) {
204
+ return withChoices({ [choice]: value }, callback);
205
+ }
206
+ export class PropertiesManager {
207
+ static EMPTY_PREFERENCE = Symbol("empty preference");
208
+ properties = {};
209
+ get storedValues() {
210
+ return this.properties;
211
+ }
212
+ /**
213
+ * Sets a collection of properties to the given values, storing the old values.
214
+ *
215
+ * @param propertiesToSet A Properties object, keyed by property name.
216
+ */
217
+ set(propertiesToSet) {
218
+ for (const [propertyName, propertyValue] of Object.entries(propertiesToSet)) {
219
+ if (!(propertyName in this.properties)) {
220
+ this.properties[propertyName] = propertyExists(propertyName)
221
+ ? get(propertyName)
222
+ : PropertiesManager.EMPTY_PREFERENCE;
223
+ }
224
+ set(propertyName, propertyValue);
225
+ }
226
+ }
227
+ /**
228
+ * Sets a collection of choice adventure properties to the given values, storing the old values.
229
+ *
230
+ * @param choicesToSet An object keyed by choice adventure number.
231
+ */
232
+ setChoices(choicesToSet) {
233
+ this.set(Object.fromEntries(Object.entries(choicesToSet).map(([choiceNumber, choiceValue]) => [
234
+ `choiceAdventure${choiceNumber}`,
235
+ choiceValue,
236
+ ])));
237
+ }
238
+ /**
239
+ * Sets a single choice adventure property to the given value, storing the old value.
240
+ *
241
+ * @param choiceToSet The number of the choice adventure to set the property for.
242
+ * @param value The value to assign to that choice adventure.
243
+ */
244
+ setChoice(choiceToSet, value) {
245
+ this.setChoices({ [choiceToSet]: value });
246
+ }
247
+ /**
248
+ * Resets the given properties to their original stored value. Does not delete entries from the manager.
249
+ *
250
+ * @param properties Collection of properties to reset.
251
+ */
252
+ reset(...properties) {
253
+ for (const property of properties) {
254
+ if (!(property in this.properties))
255
+ continue;
256
+ const value = this.properties[property];
257
+ if (value === PropertiesManager.EMPTY_PREFERENCE) {
258
+ removeProperty(property);
259
+ }
260
+ else if (value) {
261
+ set(property, value);
262
+ }
263
+ else {
264
+ set(property, "");
265
+ }
266
+ }
267
+ }
268
+ /**
269
+ * Iterates over all stored values, setting each property back to its original stored value. Does not delete entries from the manager.
270
+ */
271
+ resetAll() {
272
+ setProperties(this.properties);
273
+ }
274
+ /**
275
+ * Stops storing the original values of inputted properties.
276
+ *
277
+ * @param properties Properties for the manager to forget.
278
+ */
279
+ clear(...properties) {
280
+ for (const property of properties) {
281
+ if (this.properties[property]) {
282
+ delete this.properties[property];
283
+ }
284
+ }
285
+ }
286
+ /**
287
+ * Clears all properties.
288
+ */
289
+ clearAll() {
290
+ this.properties = {};
291
+ }
292
+ /**
293
+ * Increases a numeric property to the given value if necessary.
294
+ *
295
+ * @param property The numeric property we want to potentially raise.
296
+ * @param value The minimum value we want that property to have.
297
+ * @returns Whether we needed to change the property.
298
+ */
299
+ setMinimumValue(property, value) {
300
+ if (get(property, 0) < value) {
301
+ this.set({ [property]: value });
302
+ return true;
303
+ }
304
+ return false;
305
+ }
306
+ /**
307
+ * Decrease a numeric property to the given value if necessary.
308
+ *
309
+ * @param property The numeric property we want to potentially lower.
310
+ * @param value The maximum value we want that property to have.
311
+ * @returns Whether we needed to change the property.
312
+ */
313
+ setMaximumValue(property, value) {
314
+ if (get(property, 0) > value) {
315
+ this.set({ [property]: value });
316
+ return true;
317
+ }
318
+ return false;
319
+ }
320
+ /**
321
+ * Creates a new PropertiesManager with identical stored values to this one.
322
+ *
323
+ * @returns A new PropertiesManager, with identical stored values to this one.
324
+ */
325
+ clone() {
326
+ const newGuy = new PropertiesManager();
327
+ newGuy.properties = this.storedValues;
328
+ return newGuy;
329
+ }
330
+ /**
331
+ * Clamps a numeric property, modulating it up or down to fit within a specified range
332
+ *
333
+ * @param property The numeric property to clamp
334
+ * @param min The lower bound for what we want the property to be allowed to be.
335
+ * @param max The upper bound for what we want the property to be allowed to be.
336
+ * @returns Whether we ended up changing the property or not.
337
+ */
338
+ clamp(property, min, max) {
339
+ if (max < min)
340
+ return false;
341
+ const start = get(property);
342
+ this.setMinimumValue(property, min);
343
+ this.setMaximumValue(property, max);
344
+ return start !== get(property);
345
+ }
346
+ /**
347
+ * Determines whether this PropertiesManager has identical stored values to another.
348
+ *
349
+ * @param other The PropertiesManager to compare to this one.
350
+ * @returns Whether their StoredValues are identical.
351
+ */
352
+ equals(other) {
353
+ const thisProps = Object.entries(this.storedValues);
354
+ const otherProps = new Map(Object.entries(other.storedValues));
355
+ if (thisProps.length !== otherProps.size)
356
+ return false;
357
+ for (const [propertyName, propertyValue] of thisProps) {
358
+ if (otherProps.get(propertyName) === propertyValue)
359
+ return false;
360
+ }
361
+ return true;
362
+ }
363
+ /**
364
+ * Merges a PropertiesManager onto this one, letting the input win in the event that both PropertiesManagers have a value stored.
365
+ *
366
+ * @param other The PropertiesManager to be merged onto this one.
367
+ * @returns A new PropertiesManager with stored values from both its parents.
368
+ */
369
+ merge(other) {
370
+ const newGuy = new PropertiesManager();
371
+ newGuy.properties = { ...this.properties, ...other.properties };
372
+ return newGuy;
373
+ }
374
+ /**
375
+ * Merges an arbitrary collection of PropertiesManagers, letting the rightmost PropertiesManager win in the event of verlap.
376
+ *
377
+ * @param mergees The PropertiesManagers to merge together.
378
+ * @returns A PropertiesManager that is just an amalgam of all the constituents.
379
+ */
380
+ static merge(...mergees) {
381
+ if (mergees.length === 0)
382
+ return new PropertiesManager();
383
+ return mergees.reduce((a, b) => a.merge(b));
384
+ }
385
+ }