libram 0.8.26 → 0.8.27

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.
@@ -48,3 +48,10 @@ export declare function conduct(result: Item | Instrument | Effect | MarchingSon
48
48
  * @returns Whether we successfully played our instrument
49
49
  */
50
50
  export declare function play(instrument: Instrument | Item, acquire?: boolean): boolean;
51
+ /**
52
+ * Determine whether you can play an instrument
53
+ * @param instrument The instrument you want to play
54
+ * @param acquire Whether you're willing to obtain an instrument you don't already have
55
+ * @returns Whether you can play that instrument
56
+ */
57
+ export declare function canPlay(instrument: Instrument | Item, acquire?: boolean): boolean;
@@ -35,9 +35,9 @@ function makeConductFunction(mafiaClass, canDo, set, offset) {
35
35
  return (input) => {
36
36
  if (!canDo())
37
37
  return false;
38
- const [name, instance] = typeof input === "object"
39
- ? [input.toString(), input]
40
- : [input, mafiaClass.get(input)];
38
+ const [name, instance] = typeof input === "string"
39
+ ? [input, mafiaClass.get(input)]
40
+ : [input.name, input];
41
41
  if (have_(instance))
42
42
  return true;
43
43
  const key = set.indexOf(name);
@@ -78,8 +78,7 @@ export const changeSong = makeConductFunction(Effect, canChangeSong, MARCHING_SO
78
78
  * @returns Whether we successfully completed the task
79
79
  */
80
80
  export function conduct(result) {
81
- if ((typeof result === "object" && result instanceof Item) ||
82
- arrayContains(result, INSTRUMENTS)) {
81
+ if (result instanceof Item || arrayContains(result, INSTRUMENTS)) {
83
82
  return joinSection(result);
84
83
  }
85
84
  return changeSong(result);
@@ -92,12 +91,28 @@ export function conduct(result) {
92
91
  * @returns Whether we successfully played our instrument
93
92
  */
94
93
  export function play(instrument, acquire = false) {
95
- const item = typeof instrument === "object" ? instrument : Item.get(instrument);
96
- if (!(acquire ? joinSection : have_)(item))
94
+ const item = instrument instanceof Item ? instrument : Item.get(instrument);
95
+ if (!canPlay(instrument, acquire))
97
96
  return false;
97
+ if (acquire && !have_(item))
98
+ joinSection(item);
98
99
  const currentUsesRemaining = item.dailyusesleft;
99
- if (currentUsesRemaining <= 0)
100
- return false;
101
100
  visitUrl(`inventory.php?pwd=${myHash()}&iid=${item.id}&action=aprilplay`, false);
102
101
  return item.dailyusesleft !== currentUsesRemaining;
103
102
  }
103
+ /**
104
+ * Determine whether you can play an instrument
105
+ * @param instrument The instrument you want to play
106
+ * @param acquire Whether you're willing to obtain an instrument you don't already have
107
+ * @returns Whether you can play that instrument
108
+ */
109
+ export function canPlay(instrument, acquire = false) {
110
+ if (!have())
111
+ return false;
112
+ const item = instrument instanceof Item ? instrument : Item.get(instrument);
113
+ if (!have_(item) && (!acquire || !canJoinSection()))
114
+ return false;
115
+ if (item.dailyusesleft <= 0)
116
+ return false;
117
+ return true;
118
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.8.26",
3
+ "version": "0.8.27",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,7 +53,7 @@
53
53
  "husky": "^4.3.6",
54
54
  "java-parser": "^1.4.0",
55
55
  "jest": "^27.1.0",
56
- "kolmafia": "^5.27668.0",
56
+ "kolmafia": "^5.27901.0",
57
57
  "lint-staged": ">=10",
58
58
  "node-fetch": "^2.6.1",
59
59
  "prettier": "^2.1.2",