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

return correct uncharged item when charges run out #5422

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
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
78 changes: 59 additions & 19 deletions src/lib/degradeableItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| 'blood_essence_charges'
| 'trident_charges'
| 'scythe_of_vitur_charges';
itemsToRefundOnBreak: Bank;
run: (user: MUser) => Bank;
setup: GearSetupType;
aliases: string[];
chargeInput: {
Expand Down Expand Up @@ -58,7 +58,9 @@
{
item: getOSItem('Abyssal tentacle'),
settingsKey: 'tentacle_charges',
itemsToRefundOnBreak: new Bank().add('Kraken tentacle'),
run: () => {
return new Bank().add('Kraken tentacle');
},
setup: 'melee',
aliases: ['tentacle', 'tent'],
chargeInput: {
Expand All @@ -70,7 +72,15 @@
{
item: getOSItem('Sanguinesti staff'),
settingsKey: 'sang_charges',
itemsToRefundOnBreak: new Bank().add('Sanguinesti staff (uncharged)'),
run: (user: MUser) => {
let unchargedItem: string = '';
if (user.hasEquipped('Holy sanguinesti staff')) {
unchargedItem = 'Holy sanguinesti staff (uncharged)';
} else {
unchargedItem = 'Sanguinesti staff (uncharged)';
}
return new Bank().add(unchargedItem);
},
setup: 'mage',
aliases: ['sang', 'sang staff', 'sanguinesti staff', 'sanguinesti'],
chargeInput: {
Expand All @@ -84,7 +94,9 @@
{
item: getOSItem('Celestial ring'),
settingsKey: 'celestial_ring_charges',
itemsToRefundOnBreak: new Bank().add('Celestial ring (uncharged)'),
run: () => {
return new Bank().add('Celestial ring (uncharged)');
},
setup: 'skilling',
aliases: ['celestial ring'],
chargeInput: {
Expand All @@ -98,7 +110,9 @@
{
item: getOSItem('Ash sanctifier'),
settingsKey: 'ash_sanctifier_charges',
itemsToRefundOnBreak: new Bank().add('Ash sanctifier'),
run: () => {
return new Bank().add('Ash sanctifier');
},
setup: 'skilling',
aliases: ['ash sanctifier'],
chargeInput: {
Expand All @@ -111,7 +125,9 @@
{
item: getOSItem('Serpentine helm'),
settingsKey: 'serp_helm_charges',
itemsToRefundOnBreak: new Bank().add('Serpentine helm (uncharged)'),
run: () => {
return new Bank().add('Serpentine helm (uncharged)');
},
setup: 'melee',
aliases: ['serp', 'serp helm', 'serpentine helm'],
chargeInput: {
Expand All @@ -125,7 +141,9 @@
{
item: getOSItem('Amulet of blood fury'),
settingsKey: 'blood_fury_charges',
itemsToRefundOnBreak: new Bank().add('Amulet of fury'),
run: () => {
return new Bank().add('Amulet of fury');
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no reason to use anonymous arrays here; these should remain constant Bank() objects, and a union type + type checking should be used to support both types.

},
setup: 'melee',
aliases: ['blood fury', 'amulet of blood fury'],
chargeInput: {
Expand All @@ -139,7 +157,9 @@
{
item: getOSItem("Tumeken's shadow"),
settingsKey: 'tum_shadow_charges',
itemsToRefundOnBreak: new Bank().add("Tumeken's shadow (uncharged)"),
run: () => {
return new Bank().add("Tumeken's shadow (uncharged)");
},
setup: 'mage',
aliases: ['ts', 'tum shadow', 'tumekens shadow'],
chargeInput: {
Expand All @@ -153,7 +173,9 @@
{
item: getOSItem('Blood essence (active)'),
settingsKey: 'blood_essence_charges',
itemsToRefundOnBreak: new Bank(),
run: () => {
return new Bank();
},
setup: 'skilling',
aliases: ['blood essence'],
chargeInput: {
Expand All @@ -165,7 +187,15 @@
{
item: getOSItem('Trident of the swamp'),
settingsKey: 'trident_charges',
itemsToRefundOnBreak: new Bank().add('Uncharged toxic trident'),
run: (user: MUser) => {
let unchargedItem: string = '';
if (user.hasEquipped('Trident of the swamp')) {
unchargedItem = 'Uncharged toxic trident';
} else {
unchargedItem = 'Uncharged trident';
}
return new Bank().add(unchargedItem);
},
setup: 'mage',
aliases: ['trident', 'trident of the swamp'],
chargeInput: {
Expand All @@ -179,7 +209,17 @@
{
item: getOSItem('Scythe of vitur'),
settingsKey: 'scythe_of_vitur_charges',
itemsToRefundOnBreak: new Bank().add('Scythe of vitur (uncharged)'),
run: (user: MUser) => {
let unchargedItem: string = '';
if (user.hasEquipped('Holy Scythe of vitur')) {
unchargedItem = 'Holy scythe of vitur (uncharged)';
} else if (user.hasEquipped('Sanguine Scythe of vitur')) {
unchargedItem = 'Sanguine scythe of vitur (uncharged)';
} else {
unchargedItem = 'Scythe of vitur (uncharged)';
}
return new Bank().add(unchargedItem);
},
setup: 'melee',
aliases: ['scythe of vitur'],
chargeInput: {
Expand Down Expand Up @@ -282,25 +322,25 @@
});
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

[eslint] reported by reviewdog 🐶 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. Raw Output: {"ruleId":"@typescript-eslint/no-floating-promises","severity":1,"message":"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.","line":325,"column":3,"nodeType":"ExpressionStatement","messageId":"floatingVoid","endLine":325,"endColumn":58,"suggestions":[{"messageId":"floatingFixVoid","fix":{"range":[8788,8843],"text":"void updateBankSetting('degraded_items_cost', itemsDeleted);"},"desc":"Add void operator to ignore."}]}

if (hasEquipped) {
// If its equipped, unequip and delete it.
// If its equipped, give user new item, unequip old item and delete it.
const gear = { ...user.gear[degItem.setup].raw() };
if (degItem.run !== undefined) {
const bankValue = degItem.run(user);
await user.addItemsToBank({ items: bankValue, collectionLog: false });
}
gear[item.equipment!.slot] = null;
await user.update({
[`gear_${degItem.setup}`]: gear
});
if (degItem.itemsToRefundOnBreak) {
await user.addItemsToBank({ items: degItem.itemsToRefundOnBreak, collectionLog: false });
}
} else if (hasInBank) {
// If its in bank, just remove 1 from bank.
let itemsToAdd = undefined;
if (degItem.itemsToRefundOnBreak) {
itemsToAdd = degItem.itemsToRefundOnBreak;
if (degItem.run !== undefined) {
const itemsToAdd = degItem.run(user); // Call the function to get the actual Bank value
await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd });
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where the bug I mentioned is; notice it only removes the degraded item if there's an item to refund.

This may not always be the case if something degrades into dust, and should be accounted for, even if not used currently.

}
await user.transactItems({ itemsToRemove: new Bank().add(item.id, 1), itemsToAdd });
} else {
// If its not in bank OR equipped, something weird has gone on.
throw new Error(
Expand Down