Skip to content

Commit

Permalink
Ghommal's lucky penny functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nwjgit committed Feb 12, 2024
1 parent 2abdaff commit 07a6d78
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib/degradeableItems.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { roll } from 'e';
import { Bank } from 'oldschooljs';
import { Item } from 'oldschooljs/dist/meta/types';
import Monster from 'oldschooljs/dist/structures/Monster';
Expand Down Expand Up @@ -297,6 +298,17 @@ export async function degradeItem({
const degItem = degradeableItems.find(i => i.item === item);
if (!degItem) throw new Error('Invalid degradeable item');

// 5% chance to not consume a charge when Ghommal's lucky penny is equipped
let pennyReduction = 0;
if (user.hasEquipped("Ghommal's lucky penny")) {
for (let i = 0; i < chargesToDegrade; i++) {
if (roll(20)) {
pennyReduction++;
}
}
}
chargesToDegrade -= pennyReduction;

const currentCharges = user.user[degItem.settingsKey];
assert(typeof currentCharges === 'number');
const newCharges = Math.floor(currentCharges - chargesToDegrade);
Expand Down Expand Up @@ -353,7 +365,11 @@ export async function degradeItem({
const chargesAfter = user.user[degItem.settingsKey];
assert(typeof chargesAfter === 'number' && chargesAfter > 0);
return {
userMessage: `Your ${item.name} degraded by ${chargesToDegrade} charges, and now has ${chargesAfter} remaining.`
userMessage: `Your ${
item.name
} degraded by ${chargesToDegrade} charges, and now has ${chargesAfter} remaining.${
pennyReduction > 0 ? ` Your Ghommal's lucky penny saved ${pennyReduction} charges` : ''
}`
};
}

Expand Down

0 comments on commit 07a6d78

Please sign in to comment.