-
Notifications
You must be signed in to change notification settings - Fork 133
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
| 'blood_essence_charges' | ||
| 'trident_charges' | ||
| 'scythe_of_vitur_charges'; | ||
itemsToRefundOnBreak: Bank; | ||
run: (user: MUser) => Bank; | ||
setup: GearSetupType; | ||
aliases: string[]; | ||
chargeInput: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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'); | ||
}, | ||
setup: 'melee', | ||
aliases: ['blood fury', 'amulet of blood fury'], | ||
chargeInput: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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: { | ||
|
@@ -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 GitHub Actions / ESLint
|
||
|
||
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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
There was a problem hiding this comment.
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.