From 07a6d782a0b9ef16fa75b97d4f041b0fbfba418f Mon Sep 17 00:00:00 2001 From: nwjgit Date: Sun, 11 Feb 2024 20:48:25 -0600 Subject: [PATCH] Ghommal's lucky penny functionality --- src/lib/degradeableItems.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib/degradeableItems.ts b/src/lib/degradeableItems.ts index c97b4944c2..5252699b38 100644 --- a/src/lib/degradeableItems.ts +++ b/src/lib/degradeableItems.ts @@ -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'; @@ -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); @@ -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` : '' + }` }; }