Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to Ghommal's lucky penny #5686

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/lib/degradeableItems.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { percentChance } from 'e';
import { Bank } from 'oldschooljs';
import { Item } from 'oldschooljs/dist/meta/types';
import Monster from 'oldschooljs/dist/structures/Monster';
Expand Down Expand Up @@ -211,7 +212,7 @@
setup: 'melee',
aliases: ['scythe of vitur'],
chargeInput: {
cost: new Bank().add('Blood rune', 300).add('Vial of blood').freeze(),
cost: new Bank().add('Blood rune', 200).add('Vial of blood').freeze(),
charges: 100
},
unchargedItem: getOSItem('Scythe of vitur (uncharged)'),
Expand Down Expand Up @@ -297,6 +298,17 @@
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its a 5% percent chance, we should use percentChance(5)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched it to percentChance(5)

let pennyReduction = 0;
if (user.hasEquipped("Ghommal's lucky penny")) {
for (let i = 0; i < chargesToDegrade; i++) {
if (percentChance(5)) {
pennyReduction++;
}
}
}
chargesToDegrade -= pennyReduction;

const currentCharges = user.user[degItem.settingsKey];
assert(typeof currentCharges === 'number');
const newCharges = Math.floor(currentCharges - chargesToDegrade);
Expand All @@ -310,7 +322,7 @@
});
const itemsDeleted = new Bank().add(item.id);

updateBankSetting('degraded_items_cost', itemsDeleted);

Check warning on line 325 in src/lib/degradeableItems.ts

View workflow job for this annotation

GitHub Actions / ESLint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

if (hasEquipped) {
// Get the users equipped item.
Expand All @@ -331,7 +343,7 @@
} else if (hasInBank) {
// If its in bank, just remove 1 from bank.
let itemsToAdd = undefined;
if (degItem.itemsToRefundOnBreak) {

Check warning on line 346 in src/lib/degradeableItems.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected object value in conditional. The condition is always true
itemsToAdd = degItem.itemsToRefundOnBreak;
}
await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd });
Expand All @@ -353,7 +365,11 @@
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
Loading