Skip to content

Commit aebc477

Browse files
committed
Fix bug with 'Consume Mastery Tokens'. Would claim normal items as tokens when more then one token was present.
1 parent c08c6d7 commit aebc477

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

app/src/components/Bank.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,49 @@ import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
33
import Melvor from '../melvor';
44

5+
const typedKeys: { <T>(o: T): Array<keyof T> } = Object.keys as any;
6+
57
export default class Bank extends Component {
68
renderTarget = document.querySelector('#bank-container > div > div:nth-child(2)')!;
9+
consumeInterval?: NodeJS.Timeout;
710

811
render() {
912
return ReactDOM.createPortal(
10-
<button type="button" className="btn btn-lg btn-info ml-2" onClick={this.onConsumeTokens}>
13+
<button type="button" className="btn btn-lg btn-info ml-2" onClick={this.onConsumeTokens.bind(this)}>
1114
Consume Mastery Tokens
1215
</button>,
1316
this.renderTarget
1417
);
1518
}
1619

17-
onConsumeTokens() {
18-
for (const id in Melvor.bank) {
19-
const item = Melvor.bank[id];
20+
clearConsumeInterval() {
21+
if (this.consumeInterval) {
22+
clearInterval(this.consumeInterval);
23+
this.consumeInterval = undefined;
24+
}
25+
}
26+
27+
onConsumeInterval() {
28+
// Find mastery token in bank
29+
const bankId = typedKeys(Melvor.bank).find((bankId) => Melvor.bank[bankId].category === 'Mastery');
30+
if (bankId === undefined) {
31+
// No mastery tokens found
32+
this.clearConsumeInterval();
33+
return;
34+
}
35+
36+
const itemId = Melvor.bank[bankId].id;
37+
Melvor.claimToken(bankId, itemId);
38+
}
2039

21-
if (item.category === 'Mastery') {
22-
Melvor.claimToken(id, item.id, true);
23-
}
40+
onConsumeTokens() {
41+
if (this.consumeInterval) {
42+
this.clearConsumeInterval();
43+
return;
2444
}
45+
46+
// Try to claim a token every 250ms
47+
this.consumeInterval = setInterval(this.onConsumeInterval.bind(this), 250);
48+
this.onConsumeInterval();
2549
}
2650
}

app/src/melvor/bindings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface MelvorBindings {
2121
};
2222
numberWithCommas: (number: number) => string;
2323
convertGP: (gp: number) => string;
24-
claimToken: (bankId: string, itemId: number, all?: boolean) => void;
24+
claimToken: (bankId: number, itemId: number, all?: boolean) => void;
2525

2626
skillLevel: { [skillId: number]: number };
2727
skillName: { [skillId: number]: string };

0 commit comments

Comments
 (0)