libram 0.5.6 → 0.5.7

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.
@@ -177,10 +177,10 @@ export const platinumCocktailToIngredient = invertMap(ingredientToPlatinumCockta
177
177
  export function getCheapestPlatinumCocktail(freeCraft = true) {
178
178
  const defaultCocktail = [$item `Dish of Clarified Butter`, $item `Buttery Boy`];
179
179
  if (freeCraft) {
180
- return (maxBy(Array.from(ingredientToPlatinumCocktail), (ingredientAndCocktail) => Math.min(...ingredientAndCocktail.map((item) => mallPrice(item)))) ?? defaultCocktail)[1];
180
+ return (maxBy(Array.from(ingredientToPlatinumCocktail), (ingredientAndCocktail) => Math.max(...ingredientAndCocktail.map((item) => -mallPrice(item)))) ?? defaultCocktail)[1];
181
181
  }
182
182
  else {
183
- return (maxBy(Array.from(ingredientToPlatinumCocktail), (ingredientAndCocktail) => mallPrice(ingredientAndCocktail[1])) ?? defaultCocktail)[1];
183
+ return (maxBy(Array.from(ingredientToPlatinumCocktail), (ingredientAndCocktail) => -mallPrice(ingredientAndCocktail[1])) ?? defaultCocktail)[1];
184
184
  }
185
185
  }
186
186
  export function turnsLeftOnQuest(useShoes = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
File without changes
@@ -1,14 +0,0 @@
1
- export class FreeFightSource {
2
- /**
3
- * @param source Source of the action (e.g. item or skill needed).
4
- * @param potential Function returning how many times this action can be used.
5
- * @param macro Macro to execute this action in combat.
6
- * @param constraints Constraints required for this action to be available.
7
- */
8
- constructor(source, potential, macro, constraints = {}) {
9
- this.source = source;
10
- this.potential = potential;
11
- this.macro = macro;
12
- this.constraints = constraints;
13
- }
14
- }
@@ -1,117 +0,0 @@
1
- import { Macro } from "../combat";
2
- import { Requirement } from "../maximize";
3
- export declare type FindActionSourceConstraints = {
4
- /**
5
- * Function returning true if we only accept familiar-based actions.
6
- */
7
- requireFamiliar?: () => boolean;
8
- /**
9
- * Function returning true if we only accept sources that are unlimited.
10
- */
11
- requireUnlimited?: () => boolean;
12
- /**
13
- * Function returning whether to disallow actions requiring familiar change.
14
- */
15
- noFamiliar?: () => boolean;
16
- /**
17
- * Function returning whether to disallow actions requiring equipment change.
18
- */
19
- noRequirements?: () => boolean;
20
- /**
21
- * Function returning whether to disallow actions requiring preparation.
22
- */
23
- noPreparation?: () => boolean;
24
- /**
25
- * Function returning maximum cost of allowed actions. If undefined, allow
26
- * only actions that cost nothing.
27
- */
28
- maximumCost?: () => number;
29
- };
30
- export declare type ActionConstraints = {
31
- /**
32
- * Equipment requirements to have this action available.
33
- */
34
- equipmentRequirements?: () => Requirement;
35
- /**
36
- * Familiar required to be in use to have this action available.
37
- */
38
- familiar?: () => Familiar;
39
- /**
40
- * Miscellaneous preparation to ensure this action is available.
41
- */
42
- preparation?: () => boolean;
43
- /**
44
- * Cost in meat per usage of this action.
45
- */
46
- cost?: () => number;
47
- };
48
- /**
49
- * A basic of an action resource in the game (e.g. a free run or free kill).
50
- */
51
- export declare class ActionSource {
52
- source: Item | Skill | Familiar;
53
- potential: () => number;
54
- macro: Macro;
55
- constraints: ActionConstraints;
56
- /**
57
- *
58
- * @param source Source of the action (e.g. item or skill needed).
59
- * @param potential Function returning how many times this action can be used.
60
- * @param macro Macro to execute this action in combat.
61
- * @param constraints Constraints required for this action to be available.
62
- */
63
- constructor(source: Item | Skill | Familiar, potential: () => number, macro: Macro, constraints?: ActionConstraints);
64
- /**
65
- * @returns Name of the action source.
66
- */
67
- name(): string;
68
- /**
69
- * @returns Whether the action is available.
70
- */
71
- available(): boolean;
72
- /**
73
- * @returns Cost in meat per usage of the action.
74
- */
75
- cost(): number;
76
- /**
77
- * @returns Whether the action costs 0 meat to use.
78
- */
79
- isFree(): boolean;
80
- /**
81
- * @returns Whether unlimited uses of the action are available.
82
- */
83
- isUnlimited(): boolean;
84
- /**
85
- * Create a compound action source with merged constraints.
86
- * @param others Other actions to have available.
87
- * @returns Merged constraints, or null if they are inconsistent.
88
- */
89
- merge(...others: ActionSource[]): ActionSource | null;
90
- /**
91
- * Perform all preparation necessary to make this action available.
92
- * @param otherRequirements Any other equipment requirements.
93
- * @returns Whether preparation succeeded.
94
- */
95
- prepare(otherRequirements?: Requirement): boolean;
96
- /**
97
- * Perform all preparation necessary to make this action available.
98
- * Throws an error if preparation fails.
99
- * @param otherRequirements Any other equipment requirements.
100
- */
101
- ensure(otherRequirements?: Requirement): void;
102
- }
103
- /**
104
- * Find an available action source subject to constraints.
105
- * @param actions Action source list.
106
- * @param constraints Preexisting constraints that restrict possible sources.
107
- * @returns Available action source satisfying constraints, or null.
108
- */
109
- export declare function findActionSource(actions: ActionSource[], constraints?: FindActionSourceConstraints): ActionSource | null;
110
- /**
111
- * Count available action sources subject to constraints. Note that, if
112
- * constraints.maximumCost is high enough, this will return Infinity.
113
- * @param actions Action source list.
114
- * @param constraints Preexisting constraints that restrict possible sources.
115
- * @returns Count of available action sources.
116
- */
117
- export declare function actionSourcesAvailable(actions: ActionSource[], constraints?: FindActionSourceConstraints): number;
@@ -1,154 +0,0 @@
1
- import { useFamiliar } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { Requirement } from "../maximize";
4
- import { sum } from "../utils";
5
- function mergeConstraints(...allConstraints) {
6
- const familiars = allConstraints.map((constraints) => constraints.familiar);
7
- if (familiars.length > 1) {
8
- // Inconsistent requirements.
9
- return null;
10
- }
11
- return {
12
- equipmentRequirements: () => Requirement.merge([
13
- ...allConstraints.map((constraints) => constraints.equipmentRequirements?.() ?? new Requirement([], {})),
14
- ]),
15
- preparation: () => {
16
- let success = true;
17
- for (const constraints of allConstraints) {
18
- success =
19
- success && (!constraints.preparation || constraints.preparation());
20
- }
21
- return success;
22
- },
23
- familiar: familiars[0],
24
- cost: () => sum(allConstraints, (constraints) => constraints.cost?.() ?? 0),
25
- };
26
- }
27
- /**
28
- * A basic of an action resource in the game (e.g. a free run or free kill).
29
- */
30
- export class ActionSource {
31
- source;
32
- potential; // Infinity: unlimited
33
- macro;
34
- constraints;
35
- /**
36
- *
37
- * @param source Source of the action (e.g. item or skill needed).
38
- * @param potential Function returning how many times this action can be used.
39
- * @param macro Macro to execute this action in combat.
40
- * @param constraints Constraints required for this action to be available.
41
- */
42
- constructor(source, potential, macro, constraints = {}) {
43
- this.source = source;
44
- this.potential = potential;
45
- this.macro = macro;
46
- this.constraints = constraints;
47
- }
48
- /**
49
- * @returns Name of the action source.
50
- */
51
- name() {
52
- return this.source.toString();
53
- }
54
- /**
55
- * @returns Whether the action is available.
56
- */
57
- available() {
58
- return this.potential() > 0;
59
- }
60
- /**
61
- * @returns Cost in meat per usage of the action.
62
- */
63
- cost() {
64
- return this.constraints.cost ? this.constraints.cost() : 0;
65
- }
66
- /**
67
- * @returns Whether the action costs 0 meat to use.
68
- */
69
- isFree() {
70
- return !this.cost || this.cost() === 0;
71
- }
72
- /**
73
- * @returns Whether unlimited uses of the action are available.
74
- */
75
- isUnlimited() {
76
- return this.potential() === Infinity;
77
- }
78
- /**
79
- * Create a compound action source with merged constraints.
80
- * @param others Other actions to have available.
81
- * @returns Merged constraints, or null if they are inconsistent.
82
- */
83
- merge(...others) {
84
- const actions = [this, ...others];
85
- const constraints = mergeConstraints(...actions.map((action) => action.constraints));
86
- if (constraints === null) {
87
- // Inconsistent constraints - no path forward here.
88
- return null;
89
- }
90
- return new ActionSource(this.source, () => sum(actions, (action) => action.potential()), Macro.step(...actions.map((action) => action.macro)), constraints);
91
- }
92
- /**
93
- * Perform all preparation necessary to make this action available.
94
- * @param otherRequirements Any other equipment requirements.
95
- * @returns Whether preparation succeeded.
96
- */
97
- prepare(otherRequirements) {
98
- if (this.constraints.familiar?.()) {
99
- if (!useFamiliar(this.constraints.familiar()))
100
- return false;
101
- }
102
- if (this.constraints.equipmentRequirements) {
103
- const requirement = otherRequirements
104
- ? otherRequirements.merge(this.constraints.equipmentRequirements())
105
- : this.constraints.equipmentRequirements();
106
- if (!requirement.maximize())
107
- return false;
108
- }
109
- if (this.constraints.preparation)
110
- return this.constraints.preparation();
111
- return true;
112
- }
113
- /**
114
- * Perform all preparation necessary to make this action available.
115
- * Throws an error if preparation fails.
116
- * @param otherRequirements Any other equipment requirements.
117
- */
118
- ensure(otherRequirements) {
119
- if (!this.prepare(otherRequirements)) {
120
- throw new Error(`Failed to prepare action ${this.name()}.`);
121
- }
122
- }
123
- }
124
- function filterAction(action, constraints) {
125
- return (action.available() &&
126
- !(constraints.requireFamiliar?.() && !action.constraints.familiar) &&
127
- !(constraints.requireUnlimited?.() && !action.isUnlimited()) &&
128
- !(constraints.noFamiliar?.() && action.constraints.familiar) &&
129
- !(constraints.noRequirements?.() && action.constraints.equipmentRequirements) &&
130
- !(constraints.noPreparation?.() && action.constraints.preparation) &&
131
- action.cost() <= (constraints.maximumCost?.() ?? 0));
132
- }
133
- /**
134
- * Find an available action source subject to constraints.
135
- * @param actions Action source list.
136
- * @param constraints Preexisting constraints that restrict possible sources.
137
- * @returns Available action source satisfying constraints, or null.
138
- */
139
- export function findActionSource(actions, constraints = {}) {
140
- return (actions
141
- .filter((actions) => filterAction(actions, constraints))
142
- .sort((a, b) => a.cost() - b.cost())[0] ?? null);
143
- }
144
- /**
145
- * Count available action sources subject to constraints. Note that, if
146
- * constraints.maximumCost is high enough, this will return Infinity.
147
- * @param actions Action source list.
148
- * @param constraints Preexisting constraints that restrict possible sources.
149
- * @returns Count of available action sources.
150
- */
151
- export function actionSourcesAvailable(actions, constraints = {}) {
152
- // TODO: This will overcount if any Actions share a counter
153
- return sum(actions.filter((action) => filterAction(action, constraints ?? {})), (action) => action.potential());
154
- }
package/dist/freerun.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { Macro } from "./combat";
2
- import { Requirement } from "./maximize";
3
- export declare type AdventureOptions = {
4
- equipmentRequirements?: () => Requirement;
5
- preparation?: () => boolean;
6
- location?: () => Location;
7
- macro?: () => Macro;
8
- familiar?: () => Familiar;
9
- available?: () => boolean;
10
- };
11
- export declare type FreeRunOptions = {
12
- equipmentRequirements?: () => Requirement;
13
- preparation?: () => boolean;
14
- familiar?: () => Familiar;
15
- };
16
- export declare class FreeRun {
17
- name: string;
18
- available: () => boolean;
19
- macro: Macro;
20
- options?: FreeRunOptions;
21
- constructor(name: string, available: () => boolean, macro: Macro, options?: FreeRunOptions);
22
- }
23
- export declare function tryFindFreeRun(useFamiliar?: boolean): FreeRun | null;
24
- export declare function ensureFreeRun(useFamiliar?: boolean): FreeRun;
package/dist/freerun.js DELETED
@@ -1,99 +0,0 @@
1
- import { cliExecute, mallPrice, restoreMp, retrieveItem, visitUrl, } from "kolmafia";
2
- import { Macro } from "./combat";
3
- import { ensureEffect, getFoldGroup, getSongCount, getSongLimit, have, } from "./lib";
4
- import { Requirement } from "./maximize";
5
- import { get } from "./property";
6
- import { Bandersnatch } from "./resources";
7
- import { $effect, $familiar, $item, $items, $skill } from "./template-string";
8
- export class FreeRun {
9
- name;
10
- available;
11
- macro;
12
- options;
13
- constructor(name, available, macro, options) {
14
- this.name = name;
15
- this.available = available;
16
- this.macro = macro;
17
- this.options = options;
18
- }
19
- }
20
- const freeRuns = [
21
- new FreeRun("Bander", () => have($familiar `Frumious Bandersnatch`) &&
22
- (have($effect `Ode to Booze`) || getSongCount() < getSongLimit()) &&
23
- Bandersnatch.getRemainingRunaways() > 0, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).step("runaway"), {
24
- equipmentRequirements: () => new Requirement(["Familiar Weight"], {}),
25
- preparation: () => {
26
- ensureEffect($effect `Ode to Booze`);
27
- return true;
28
- },
29
- familiar: () => $familiar `Frumious Bandersnatch`,
30
- }),
31
- new FreeRun("Boots", () => have($familiar `Pair of Stomping Boots`) &&
32
- Bandersnatch.getRemainingRunaways() > 0, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).step("runaway"), {
33
- equipmentRequirements: () => new Requirement(["Familiar Weight"], {}),
34
- familiar: () => $familiar `Pair of Stomping Boots`,
35
- }),
36
- new FreeRun("Snokebomb", () => get("_snokebombUsed") < 3 && have($skill `Snokebomb`), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `Snokebomb`), {
37
- preparation: () => restoreMp(50),
38
- }),
39
- new FreeRun("Hatred", () => get("_feelHatredUsed") < 3 && have($skill `Emotionally Chipped`), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `Feel Hatred`)),
40
- new FreeRun("KGB", () => have($item `Kremlin's Greatest Briefcase`) &&
41
- get("_kgbTranquilizerDartUses") < 3, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `KGB tranquilizer dart`), {
42
- equipmentRequirements: () => new Requirement([], {
43
- forceEquip: $items `Kremlin's Greatest Briefcase`,
44
- }),
45
- }),
46
- new FreeRun("Latte", () => have($item `latte lovers member's mug`) && !get("_latteBanishUsed"), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill("Throw Latte on Opponent"), {
47
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `latte lovers member's mug` }),
48
- }),
49
- new FreeRun("Docbag", () => have($item `Lil' Doctor™ bag`) && get("_reflexHammerUsed") < 3, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `Reflex Hammer`), {
50
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `Lil' Doctor™ bag` }),
51
- }),
52
- new FreeRun("Middle Finger", () => have($item `mafia middle finger ring`) &&
53
- !get("_mafiaMiddleFingerRingUsed"), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `Show them your ring`), {
54
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `mafia middle finger ring` }),
55
- }),
56
- new FreeRun("VMask", () => have($item `V for Vivala mask`) && !get("_vmaskBanisherUsed"), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill($skill `Creepy Grin`), {
57
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `V for Vivala mask` }),
58
- preparation: () => restoreMp(30),
59
- }),
60
- new FreeRun("Stinkeye", () => getFoldGroup($item `stinky cheese diaper`).some((item) => have(item)) &&
61
- !get("_stinkyCheeseBanisherUsed"), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill("Give Your Opponent the Stinkeye"), {
62
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `stinky cheese eye` }),
63
- preparation: () => {
64
- if (!have($item `stinky cheese eye`))
65
- cliExecute(`fold stinky cheese eye`);
66
- return have($item `stinky cheese eye`);
67
- },
68
- }),
69
- new FreeRun("Navel Ring", () => have($item `navel ring of navel gazing`) && get("_navelRunaways") < 3, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).step("runaway"), {
70
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `navel ring of navel gazing` }),
71
- }),
72
- new FreeRun("GAP", () => have($item `Greatest American Pants`) && get("_navelRunaways") < 3, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).step("runaway"), {
73
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `Greatest American Pants` }),
74
- }),
75
- new FreeRun("Scrapbook", () => {
76
- visitUrl("desc_item.php?whichitem=463063785");
77
- return have($item `familiar scrapbook`) && get("scrapbookCharges") >= 100;
78
- }, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).skill("Show Your Boring Familiar Pictures"), {
79
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `familiar scrapbook` }),
80
- }),
81
- new FreeRun("Parasol", () => have($item `peppermint parasol`) &&
82
- get("parasolUsed") < 9 &&
83
- get("_navelRunaways") < 3, Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).item($item `peppermint parasol`)),
84
- ];
85
- function cheapestRunSource() {
86
- return $items `Louder Than Bomb, divine champagne popper, tennis ball`.sort((a, b) => mallPrice(a) - mallPrice(b))[0];
87
- }
88
- function cheapestItemRun() {
89
- const cheapestRun = cheapestRunSource();
90
- return new FreeRun("Cheap Combat Item", () => retrieveItem(cheapestRun), Macro.trySkill($skill `Asdon Martin: Spring-Loaded Front Bumper`).item(cheapestRun), {
91
- preparation: () => retrieveItem(cheapestRun),
92
- });
93
- }
94
- export function tryFindFreeRun(useFamiliar = true) {
95
- return (freeRuns.find((run) => run.available() && (useFamiliar || run?.options?.familiar)) ?? null);
96
- }
97
- export function ensureFreeRun(useFamiliar = true) {
98
- return tryFindFreeRun(useFamiliar) ?? cheapestItemRun();
99
- }
@@ -1,14 +0,0 @@
1
- import { ActionSource, FindActionSourceConstraints } from "./action";
2
- /**
3
- * Find an available free kill source subject to constraints.
4
- * @param constraints Preexisting constraints that restrict possible sources.
5
- * @returns Free kill source satisfying constraints, or null.
6
- */
7
- export declare function tryFindFreeKill(constraints?: FindActionSourceConstraints): ActionSource | null;
8
- /**
9
- * Ensure an available free kill source subject to constraints.
10
- * Throws an error if no source can be found.
11
- * @param constraints Preexisting constraints that restrict possible sources.
12
- * @returns Free kill source satisfying constraints.
13
- */
14
- export declare function ensureFreeKill(constraints?: FindActionSourceConstraints): ActionSource;
@@ -1,88 +0,0 @@
1
- import { mallPrice, myLightning, restoreMp, retrieveItem, use } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { have } from "../lib";
4
- import { Requirement } from "../maximize";
5
- import { get } from "../property";
6
- import { $familiar, $item, $items, $skill } from "../template-string";
7
- import { ActionSource, findActionSource, } from "./action";
8
- import * as AsdonMartin from "./2017/AsdonMartin";
9
- const freeKillSources = [
10
- // Free limited sources
11
- new ActionSource($skill `Gingerbread Mob Hit`, () => !get("_gingerbreadMobHitUsed") && have($skill `Gingerbread Mob Hit`)
12
- ? 1
13
- : 0, Macro.skill($skill `Gingerbread Mob Hit`), {
14
- preparation: () => restoreMp(30),
15
- }),
16
- new ActionSource($skill `Shattering Punch`, () => have($skill `Shattering Punch`) ? 3 - get("_shatteringPunchUsed") : 0, Macro.skill($skill `Shattering Punch`), {
17
- preparation: () => restoreMp(30),
18
- }),
19
- new ActionSource($item `replica bat-oomerang`, () => have($item `replica bat-oomerang`)
20
- ? 3 - get("_usedReplicaBatoomerang")
21
- : 0, Macro.item($item `replica bat-oomerang`)),
22
- new ActionSource($item `The Jokester's gun`, () => !get("_firedJokestersGun") && have($item `The Jokester's gun`) ? 1 : 0, Macro.skill($skill `Fire the Jokester's Gun`), {
23
- equipmentRequirements: () => new Requirement([], {
24
- forceEquip: $items `The Jokester's gun`,
25
- }),
26
- }),
27
- new ActionSource($item `Lil' Doctor™ bag`, () => (have($item `Lil' Doctor™ bag`) ? 3 - get("_chestXRayUsed") : 0), Macro.skill($skill `Chest X-Ray`), {
28
- equipmentRequirements: () => new Requirement([], {
29
- forceEquip: $items `Lil' Doctor™ bag`,
30
- }),
31
- }),
32
- new ActionSource($skill `Asdon Martin: Missile Launcher`, () => (!get("_missileLauncherUsed") && AsdonMartin.installed() ? 1 : 0), Macro.skill($skill `Asdon Martin: Missile Launcher`), {
33
- preparation: () => AsdonMartin.fillTo(100),
34
- }),
35
- // Heavy Rains
36
- new ActionSource($skill `Lightning Strike`, () => (have($skill `Lightning Strike`) ? Math.floor(myLightning() / 20) : 0), Macro.skill($skill `Lightning Strike`)),
37
- // Expensive limited sources
38
- new ActionSource($item `powdered madness`, () => 5 - get("_powderedMadnessUses"), Macro.item($item `powdered madness`), {
39
- preparation: () => retrieveItem($item `powdered madness`),
40
- cost: () => mallPrice($item `powdered madness`),
41
- }),
42
- // Expensive unlimited sources
43
- new ActionSource($skill `Shocking Lick`, () => -1, Macro.skill($skill `Shocking Lick`), {
44
- preparation: () => {
45
- if (get("shockingLickCharges") === 0 &&
46
- retrieveItem($item `battery (9-Volt)`)) {
47
- use($item `battery (9-Volt)`);
48
- }
49
- return get("shockingLickCharges") > 0;
50
- },
51
- cost: () => mallPrice($item `battery (AAA)`) * 4,
52
- }),
53
- new ActionSource($familiar `Puck Man`, () => (have($familiar `Puck Man`) ? -1 : 0), Macro.item($item `power pill`), {
54
- familiar: () => $familiar `Puck Man`,
55
- preparation: () => retrieveItem($item `power pill`),
56
- cost: () => mallPrice($item `power pill`),
57
- }),
58
- new ActionSource($familiar `Ms. Puck Man`, () => (have($familiar `Ms. Puck Man`) ? -1 : 0), Macro.item($item `power pill`), {
59
- familiar: () => $familiar `Ms. Puck Man`,
60
- preparation: () => retrieveItem($item `power pill`),
61
- cost: () => mallPrice($item `power pill`),
62
- }),
63
- ...$items `Daily Affirmation: Think Win-Lose, superduperheated metal`.map((item) => new ActionSource(item, () => -1, Macro.item(item), {
64
- preparation: () => retrieveItem(item),
65
- cost: () => mallPrice(item),
66
- })),
67
- ];
68
- /**
69
- * Find an available free kill source subject to constraints.
70
- * @param constraints Preexisting constraints that restrict possible sources.
71
- * @returns Free kill source satisfying constraints, or null.
72
- */
73
- export function tryFindFreeKill(constraints) {
74
- return findActionSource(freeKillSources, constraints);
75
- }
76
- /**
77
- * Ensure an available free kill source subject to constraints.
78
- * Throws an error if no source can be found.
79
- * @param constraints Preexisting constraints that restrict possible sources.
80
- * @returns Free kill source satisfying constraints.
81
- */
82
- export function ensureFreeKill(constraints) {
83
- const source = tryFindFreeKill(constraints);
84
- if (!source) {
85
- throw new Error("Failed to ensure Free Kill source");
86
- }
87
- return source;
88
- }
@@ -1,14 +0,0 @@
1
- import { ActionSource, FindActionSourceConstraints } from "./action";
2
- /**
3
- * Find an available free run source subject to constraints.
4
- * @param constraints Preexisting constraints that restrict possible sources.
5
- * @returns Free run source satisfying constraints, or null.
6
- */
7
- export declare function tryFindFreeRun(constraints?: FindActionSourceConstraints): ActionSource | null;
8
- /**
9
- * Ensure an available free run source subject to constraints.
10
- * Throws an error if no source can be found.
11
- * @param constraints Preexisting constraints that restrict possible sources.
12
- * @returns Free run source satisfying constraints.
13
- */
14
- export declare function ensureFreeRun(constraints?: FindActionSourceConstraints): ActionSource;
@@ -1,151 +0,0 @@
1
- import { cliExecute, mallPrice, myTurncount, restoreMp, retrieveItem, visitUrl, } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { ensureEffect, getFoldGroup, getSongCount, getSongLimit, have, } from "../lib";
4
- import { Requirement } from "../maximize";
5
- import { get } from "../property";
6
- import { $effect, $familiar, $item, $items, $skill } from "../template-string";
7
- import { ActionSource, findActionSource, } from "./action";
8
- import * as Bandersnatch from "./2009/Bandersnatch";
9
- import * as AsdonMartin from "./2017/AsdonMartin";
10
- // Value of _lastCombatStarted the last time we updated scrapbook charges.
11
- let scrapbookChargesLastUpdated = get("_lastCombatStarted");
12
- // Free unlimited source every 30 turns.
13
- // Does not work on special monsters so needs a backup, see tryFindFreeRun.
14
- const asdonMartinSource = new ActionSource($skill `Asdon Martin: Spring-Loaded Front Bumper`, () => {
15
- if (!AsdonMartin.installed())
16
- return 0;
17
- const banishes = get("banishedMonsters").split(":");
18
- const bumperIndex = banishes
19
- .map((string) => string.toLowerCase())
20
- .indexOf("spring-loaded front bumper");
21
- if (bumperIndex === -1)
22
- return 1;
23
- return myTurncount() - parseInt(banishes[bumperIndex + 1]) > 30 ? 1 : 0;
24
- }, Macro.skill($skill `Asdon Martin: Spring-Loaded Front Bumper`), {
25
- preparation: () => AsdonMartin.fillTo(50),
26
- });
27
- const freeRunSources = [
28
- // Free limited sources
29
- new ActionSource($familiar `Frumious Bandersnatch`, () => have($familiar `Frumious Bandersnatch`) &&
30
- (have($effect `Ode to Booze`) || getSongCount() < getSongLimit()) &&
31
- Bandersnatch.getRemainingRunaways() > 0
32
- ? 0
33
- : 0, Macro.step("runaway"), {
34
- equipmentRequirements: () => new Requirement(["Familiar Weight"], {}),
35
- preparation: () => {
36
- ensureEffect($effect `Ode to Booze`);
37
- return have($effect `Ode to Booze`);
38
- },
39
- familiar: () => $familiar `Frumious Bandersnatch`,
40
- }),
41
- new ActionSource($familiar `Pair of Stomping Boots`, () => have($familiar `Pair of Stomping Boots`) &&
42
- Bandersnatch.getRemainingRunaways() > 0
43
- ? 0
44
- : 0, Macro.step("runaway"), {
45
- equipmentRequirements: () => new Requirement(["Familiar Weight"], {}),
46
- familiar: () => $familiar `Pair of Stomping Boots`,
47
- }),
48
- new ActionSource($skill `Snokebomb`, () => (have($skill `Snokebomb`) ? 3 - get("_snokebombUsed") : 0), Macro.skill($skill `Snokebomb`), {
49
- preparation: () => restoreMp(50),
50
- }),
51
- new ActionSource($skill `Emotionally Chipped`, () => (have($skill `Emotionally Chipped`) ? 3 - get("_feelHatredUsed") : 0), Macro.skill($skill `Feel Hatred`)),
52
- new ActionSource($item `Kremlin's Greatest Briefcase`, () => have($item `Kremlin's Greatest Briefcase`)
53
- ? 3 - get("_kgbTranquilizerDartUses")
54
- : 0, Macro.skill($skill `KGB tranquilizer dart`), {
55
- equipmentRequirements: () => new Requirement([], {
56
- forceEquip: $items `Kremlin's Greatest Briefcase`,
57
- }),
58
- }),
59
- new ActionSource($item `latte lovers member's mug`, () => have($item `latte lovers member's mug`) && !get("_latteBanishUsed")
60
- ? 1
61
- : 0, Macro.skill($skill `Throw Latte on Opponent`), {
62
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `latte lovers member's mug` }),
63
- }),
64
- new ActionSource($item `Lil' Doctor™ bag`, () => (have($item `Lil' Doctor™ bag`) ? 3 - get("_reflexHammerUsed") : 0), Macro.skill($skill `Reflex Hammer`), {
65
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `Lil' Doctor™ bag` }),
66
- }),
67
- new ActionSource($item `mafia middle finger ring`, () => have($item `mafia middle finger ring`) &&
68
- !get("_mafiaMiddleFingerRingUsed")
69
- ? 1
70
- : 0, Macro.skill($skill `Show them your ring`), {
71
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `mafia middle finger ring` }),
72
- }),
73
- new ActionSource($item `V for Vivala mask`, () => have($item `V for Vivala mask`) && !get("_vmaskBanisherUsed") ? 1 : 0, Macro.skill($skill `Creepy Grin`), {
74
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `V for Vivala mask` }),
75
- preparation: () => restoreMp(30),
76
- }),
77
- new ActionSource($item `stinky cheese eye`, () => getFoldGroup($item `stinky cheese eye`).some((item) => have(item)) &&
78
- !get("_stinkyCheeseBanisherUsed")
79
- ? 1
80
- : 0, Macro.skill($skill `Give Your Opponent the Stinkeye`), {
81
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `stinky cheese eye` }),
82
- preparation: () => {
83
- if (!have($item `stinky cheese eye`)) {
84
- cliExecute(`fold stinky cheese eye`);
85
- }
86
- return have($item `stinky cheese eye`);
87
- },
88
- }),
89
- new ActionSource($item `navel ring of navel gazing`, () => have($item `navel ring of navel gazing`)
90
- ? Math.max(0, 3 - get("_navelRunaways"))
91
- : 0, Macro.step("runaway"), {
92
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `navel ring of navel gazing` }),
93
- }),
94
- new ActionSource($item `Greatest American Pants`, () => have($item `Greatest American Pants`)
95
- ? Math.max(0, 3 - get("_navelRunaways"))
96
- : 0, Macro.step("runaway"), {
97
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `Greatest American Pants` }),
98
- }),
99
- new ActionSource($skill `Show your boring familiar pictures`, () => {
100
- if (have($item `familiar scrapbook`)) {
101
- if (scrapbookChargesLastUpdated !== get("_lastCombatStarted")) {
102
- visitUrl("desc_item.php?whichitem=463063785");
103
- scrapbookChargesLastUpdated = get("_lastCombatStarted");
104
- }
105
- return Math.floor(get("scrapbookCharges") / 100);
106
- }
107
- return 0;
108
- }, Macro.skill($skill `Show your boring familiar pictures`), {
109
- equipmentRequirements: () => new Requirement([], { forceEquip: $items `familiar scrapbook` }),
110
- }),
111
- new ActionSource($item `peppermint parasol`, () => Math.max(0, 3 - get("_navelRunaways")), Macro.item($item `peppermint parasol`), {
112
- preparation: () => retrieveItem($item `peppermint parasol`),
113
- cost: () => Math.min(mallPrice($item `peppermint sprout`) * 5, mallPrice($item `peppermint parasol`)) / 10, // Breaks after 10 successful runaways.
114
- }),
115
- new ActionSource($item `human musk`, () => Math.max(0, 3 - get("_humanMuskUses")), Macro.item($item `human musk`), {
116
- preparation: () => retrieveItem($item `human musk`),
117
- cost: () => mallPrice($item `human musk`),
118
- }),
119
- // Expensive unlimited sources
120
- ...$items `Louder Than Bomb, divine champagne popper, tennis ball`.map((item) => new ActionSource(item, () => Infinity, Macro.item(item), {
121
- preparation: () => retrieveItem(item),
122
- cost: () => mallPrice(item),
123
- })),
124
- ];
125
- /**
126
- * Find an available free run source subject to constraints.
127
- * @param constraints Preexisting constraints that restrict possible sources.
128
- * @returns Free run source satisfying constraints, or null.
129
- */
130
- export function tryFindFreeRun(constraints) {
131
- let source = findActionSource(freeRunSources, constraints);
132
- // Always try to use Asdon Martin: Spring-Loaded Front Bumper first,
133
- // but only if another source has been found.
134
- if (source && asdonMartinSource.available()) {
135
- source = asdonMartinSource.merge(source);
136
- }
137
- return source;
138
- }
139
- /**
140
- * Ensure an available free run source subject to constraints.
141
- * Throws an error if no source can be found.
142
- * @param constraints Preexisting constraints that restrict possible sources.
143
- * @returns Free run source satisfying constraints.
144
- */
145
- export function ensureFreeRun(constraints) {
146
- const source = tryFindFreeRun(constraints);
147
- if (!source) {
148
- throw new Error("Failed to ensure Free Run source");
149
- }
150
- return source;
151
- }
@@ -1,117 +0,0 @@
1
- import { Macro } from "../combat";
2
- import { Requirement } from "../maximize";
3
- export declare type FindActionSourceConstraints = {
4
- /**
5
- * Function returning true if we only accept familiar-based actions.
6
- */
7
- requireFamiliar?: () => boolean;
8
- /**
9
- * Function returning true if we only accept sources that are unlimited.
10
- */
11
- requireUnlimited?: () => boolean;
12
- /**
13
- * Function returning whether to disallow actions requiring familiar change.
14
- */
15
- noFamiliar?: () => boolean;
16
- /**
17
- * Function returning whether to disallow actions requiring equipment change.
18
- */
19
- noRequirements?: () => boolean;
20
- /**
21
- * Function returning whether to disallow actions requiring preparation.
22
- */
23
- noPreparation?: () => boolean;
24
- /**
25
- * Function returning maximum cost of allowed actions. If undefined, allow
26
- * only actions that cost nothing.
27
- */
28
- maximumCost?: () => number;
29
- };
30
- export declare type ActionConstraints = {
31
- /**
32
- * Equipment requirements to have this action available.
33
- */
34
- equipmentRequirements?: () => Requirement;
35
- /**
36
- * Familiar required to be in use to have this action available.
37
- */
38
- familiar?: () => Familiar;
39
- /**
40
- * Miscellaneous preparation to ensure this action is available.
41
- */
42
- preparation?: () => boolean;
43
- /**
44
- * Cost in meat per usage of this action.
45
- */
46
- cost?: () => number;
47
- };
48
- /**
49
- * A basic of an action resource in the game (e.g. a free run or free kill).
50
- */
51
- export declare class ActionSource {
52
- source: Item | Skill | Familiar;
53
- potential: () => number;
54
- macro: Macro;
55
- constraints: ActionConstraints;
56
- /**
57
- *
58
- * @param source Source of the action (e.g. item or skill needed).
59
- * @param potential Function returning how many times this action can be used.
60
- * @param macro Macro to execute this action in combat.
61
- * @param constraints Constraints required for this action to be available.
62
- */
63
- constructor(source: Item | Skill | Familiar, potential: () => number, macro: Macro, constraints?: ActionConstraints);
64
- /**
65
- * @returns Name of the action source.
66
- */
67
- name(): string;
68
- /**
69
- * @returns Whether the action is available.
70
- */
71
- available(): boolean;
72
- /**
73
- * @returns Cost in meat per usage of the action.
74
- */
75
- cost(): number;
76
- /**
77
- * @returns Whether the action costs 0 meat to use.
78
- */
79
- isFree(): boolean;
80
- /**
81
- * @returns Whether unlimited uses of the action are available.
82
- */
83
- isUnlimited(): boolean;
84
- /**
85
- * Create a compound action source with merged constraints.
86
- * @param others Other actions to have available.
87
- * @returns Merged constraints, or null if they are inconsistent.
88
- */
89
- merge(...others: ActionSource[]): ActionSource | null;
90
- /**
91
- * Perform all preparation necessary to make this action available.
92
- * @param otherRequirements Any other equipment requirements.
93
- * @returns Whether preparation succeeded.
94
- */
95
- prepare(otherRequirements?: Requirement): boolean;
96
- /**
97
- * Perform all preparation necessary to make this action available.
98
- * Throws an error if preparation fails.
99
- * @param otherRequirements Any other equipment requirements.
100
- */
101
- ensure(otherRequirements?: Requirement): void;
102
- }
103
- /**
104
- * Find an available action source subject to constraints.
105
- * @param actions Action source list.
106
- * @param constraints Preexisting constraints that restrict possible sources.
107
- * @returns Available action source satisfying constraints, or null.
108
- */
109
- export declare function findActionSource(actions: ActionSource[], constraints?: FindActionSourceConstraints): ActionSource | null;
110
- /**
111
- * Count available action sources subject to constraints. Note that, if
112
- * constraints.maximumCost is high enough, this will return Infinity.
113
- * @param actions Action source list.
114
- * @param constraints Preexisting constraints that restrict possible sources.
115
- * @returns Count of available action sources.
116
- */
117
- export declare function actionSourcesAvailable(actions: ActionSource[], constraints?: FindActionSourceConstraints): number;
@@ -1,154 +0,0 @@
1
- import { useFamiliar } from "kolmafia";
2
- import { Macro } from "../combat";
3
- import { Requirement } from "../maximize";
4
- import { sum } from "../utils";
5
- function mergeConstraints(...allConstraints) {
6
- const familiars = allConstraints.map((constraints) => constraints.familiar);
7
- if (familiars.length > 1) {
8
- // Inconsistent requirements.
9
- return null;
10
- }
11
- return {
12
- equipmentRequirements: () => Requirement.merge([
13
- ...allConstraints.map((constraints) => constraints.equipmentRequirements?.() ?? new Requirement([], {})),
14
- ]),
15
- preparation: () => {
16
- let success = true;
17
- for (const constraints of allConstraints) {
18
- success =
19
- success && (!constraints.preparation || constraints.preparation());
20
- }
21
- return success;
22
- },
23
- familiar: familiars[0],
24
- cost: () => sum(allConstraints, (constraints) => constraints.cost?.() ?? 0),
25
- };
26
- }
27
- /**
28
- * A basic of an action resource in the game (e.g. a free run or free kill).
29
- */
30
- export class ActionSource {
31
- source;
32
- potential; // Infinity: unlimited
33
- macro;
34
- constraints;
35
- /**
36
- *
37
- * @param source Source of the action (e.g. item or skill needed).
38
- * @param potential Function returning how many times this action can be used.
39
- * @param macro Macro to execute this action in combat.
40
- * @param constraints Constraints required for this action to be available.
41
- */
42
- constructor(source, potential, macro, constraints = {}) {
43
- this.source = source;
44
- this.potential = potential;
45
- this.macro = macro;
46
- this.constraints = constraints;
47
- }
48
- /**
49
- * @returns Name of the action source.
50
- */
51
- name() {
52
- return this.source.toString();
53
- }
54
- /**
55
- * @returns Whether the action is available.
56
- */
57
- available() {
58
- return this.potential() > 0;
59
- }
60
- /**
61
- * @returns Cost in meat per usage of the action.
62
- */
63
- cost() {
64
- return this.constraints.cost ? this.constraints.cost() : 0;
65
- }
66
- /**
67
- * @returns Whether the action costs 0 meat to use.
68
- */
69
- isFree() {
70
- return !this.cost || this.cost() === 0;
71
- }
72
- /**
73
- * @returns Whether unlimited uses of the action are available.
74
- */
75
- isUnlimited() {
76
- return this.potential() === Infinity;
77
- }
78
- /**
79
- * Create a compound action source with merged constraints.
80
- * @param others Other actions to have available.
81
- * @returns Merged constraints, or null if they are inconsistent.
82
- */
83
- merge(...others) {
84
- const actions = [this, ...others];
85
- const constraints = mergeConstraints(...actions.map((action) => action.constraints));
86
- if (constraints === null) {
87
- // Inconsistent constraints - no path forward here.
88
- return null;
89
- }
90
- return new ActionSource(this.source, () => sum(actions, (action) => action.potential()), Macro.step(...actions.map((action) => action.macro)), constraints);
91
- }
92
- /**
93
- * Perform all preparation necessary to make this action available.
94
- * @param otherRequirements Any other equipment requirements.
95
- * @returns Whether preparation succeeded.
96
- */
97
- prepare(otherRequirements) {
98
- if (this.constraints.familiar?.()) {
99
- if (!useFamiliar(this.constraints.familiar()))
100
- return false;
101
- }
102
- if (this.constraints.equipmentRequirements) {
103
- const requirement = otherRequirements
104
- ? otherRequirements.merge(this.constraints.equipmentRequirements())
105
- : this.constraints.equipmentRequirements();
106
- if (!requirement.maximize())
107
- return false;
108
- }
109
- if (this.constraints.preparation)
110
- return this.constraints.preparation();
111
- return true;
112
- }
113
- /**
114
- * Perform all preparation necessary to make this action available.
115
- * Throws an error if preparation fails.
116
- * @param otherRequirements Any other equipment requirements.
117
- */
118
- ensure(otherRequirements) {
119
- if (!this.prepare(otherRequirements)) {
120
- throw new Error(`Failed to prepare action ${this.name()}.`);
121
- }
122
- }
123
- }
124
- function filterAction(action, constraints) {
125
- return (action.available() &&
126
- !(constraints.requireFamiliar?.() && !action.constraints.familiar) &&
127
- !(constraints.requireUnlimited?.() && !action.isUnlimited()) &&
128
- !(constraints.noFamiliar?.() && action.constraints.familiar) &&
129
- !(constraints.noRequirements?.() && action.constraints.equipmentRequirements) &&
130
- !(constraints.noPreparation?.() && action.constraints.preparation) &&
131
- action.cost() <= (constraints.maximumCost?.() ?? 0));
132
- }
133
- /**
134
- * Find an available action source subject to constraints.
135
- * @param actions Action source list.
136
- * @param constraints Preexisting constraints that restrict possible sources.
137
- * @returns Available action source satisfying constraints, or null.
138
- */
139
- export function findActionSource(actions, constraints = {}) {
140
- return (actions
141
- .filter((actions) => filterAction(actions, constraints))
142
- .sort((a, b) => a.cost() - b.cost())[0] ?? null);
143
- }
144
- /**
145
- * Count available action sources subject to constraints. Note that, if
146
- * constraints.maximumCost is high enough, this will return Infinity.
147
- * @param actions Action source list.
148
- * @param constraints Preexisting constraints that restrict possible sources.
149
- * @returns Count of available action sources.
150
- */
151
- export function actionSourcesAvailable(actions, constraints = {}) {
152
- // TODO: This will overcount if any Actions share a counter
153
- return sum(actions.filter((action) => filterAction(action, constraints ?? {})), (action) => action.potential());
154
- }