libram 0.5.4 → 0.5.8
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.
- package/dist/actions/ActionSource.js +6 -3
- package/dist/actions/FreeRun.js +10 -12
- package/dist/ascend.d.ts +22 -11
- package/dist/ascend.js +84 -78
- package/dist/mood.js +14 -2
- package/dist/propertyTypes.d.ts +1 -1
- package/dist/resources/2009/Bandersnatch.d.ts +2 -2
- package/dist/resources/2009/Bandersnatch.js +2 -2
- package/dist/resources/2011/StompingBoots.d.ts +44 -0
- package/dist/resources/2011/StompingBoots.js +63 -0
- package/dist/resources/2015/ChateauMantegna.d.ts +13 -6
- package/dist/resources/2015/ChateauMantegna.js +22 -11
- package/dist/resources/2017/AsdonMartin.js +49 -10
- package/dist/resources/2020/Guzzlr.js +2 -2
- package/dist/resources/2021/DaylightShavings.d.ts +25 -0
- package/dist/resources/2021/DaylightShavings.js +57 -0
- package/dist/resources/index.d.ts +3 -1
- package/dist/resources/index.js +3 -1
- package/package.json +2 -2
- package/dist/actions/FreeFight.d.ts +0 -0
- package/dist/actions/FreeFight.js +0 -14
- package/dist/actions/action.d.ts +0 -117
- package/dist/actions/action.js +0 -154
- package/dist/freerun.d.ts +0 -24
- package/dist/freerun.js +0 -99
- package/dist/resources/FreeKill.d.ts +0 -14
- package/dist/resources/FreeKill.js +0 -88
- package/dist/resources/FreeRun.d.ts +0 -14
- package/dist/resources/FreeRun.js +0 -151
- package/dist/resources/action.d.ts +0 -117
- package/dist/resources/action.js +0 -154
package/dist/resources/action.js
DELETED
|
@@ -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
|
-
}
|