Skip to content

Commit 6241d2b

Browse files
authored
Refactor rollForMoonKeyHalf function (#6618)
1 parent fc4fbe5 commit 6241d2b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/lib/util/minionUtils.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { perTimeUnitChance, Time } from '@oldschoolgg/toolkit';
1+
import { Time } from '@oldschoolgg/toolkit';
22
import type { Bank } from 'oldschooljs';
33

44
import { QuestID } from '@/lib/minions/data/quests.js';
55

6+
const MOON_KEY_ONE_IN_PER_MINUTE = 60;
7+
68
export function rollForMoonKeyHalf({
79
rng,
810
user,
@@ -16,7 +18,20 @@ export function rollForMoonKeyHalf({
1618
}) {
1719
if (typeof user === 'boolean' && !user) return;
1820
if (typeof user !== 'boolean' && !user.user.finished_quest_ids.includes(QuestID.ChildrenOfTheSun)) return;
19-
perTimeUnitChance(rng, duration, 1, Time.Minute * 60, () => {
20-
loot.add('Loop half of key (moon key)');
21-
});
21+
const minutes = duration / Time.Minute;
22+
const fullMinutes = Math.floor(minutes);
23+
const remainderMinutes = minutes - fullMinutes;
24+
25+
for (let i = 0; i < fullMinutes; i++) {
26+
if (rng.roll(MOON_KEY_ONE_IN_PER_MINUTE)) {
27+
loot.add('Loop half of key (moon key)');
28+
}
29+
}
30+
31+
if (remainderMinutes > 0) {
32+
const percentChance = (remainderMinutes / MOON_KEY_ONE_IN_PER_MINUTE) * 100;
33+
if (percentChance > 0 && rng.percentChance(percentChance)) {
34+
loot.add('Loop half of key (moon key)');
35+
}
36+
}
2237
}

0 commit comments

Comments
 (0)