-
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
Conversation
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.
Too many problems as-is.
- the name
run
is too generic, it should berefundOnBreak
- The code is bugged, and won't remove the degraded item unless it also refunds an item
- The code doesn't take into consideration items degraded from the bank
- A union type should be used to avoid creating anonymous functions to return a constant value
- The constant Bank()'s should end with .freeze(), which i know isn't your bug, but this would be a good place to fix that.
- I don't think anonymous functions are the right solution here.... it should probably be some kind of
refundVariants
array which is easier to maintain:
Something like:
refundVariants: [ ['Holy scythe', 'Holy scythe (uncharged)' ], [ 'Sang scythe', 'Sang scythe uncharged'] ];
or maybe even
refundVariants: [
{
variant: getOSItem('Holy scythe of vitur'),
refund: new Bank().add('Holy scythe of vitur (uncharged')
}, {
variant: getOSItem('Sanguine scythe of vitur'),
refund: new Bank().add('Sanguine scythe of vitur (uncharged)').freeze();
}
],
And then the degradeItem()
logic will obviously have to be updated to support the chosen method.
src/lib/degradeableItems.ts
Outdated
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 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.
src/lib/degradeableItems.ts
Outdated
@@ -125,7 +141,9 @@ export const degradeableItems: DegradeableItem[] = [ | |||
{ | |||
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'); |
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.
Could this be reviewed again? People are still losing their kits. |
closes: #5305
Description:
This addresses the issue of charged items reverting to their normal variant when minion charges reach zero. i.e. when you have a Sanguine Scythe of vitur and you run out of charges you are given a Scythe of vitur (uncharged) and the kit is lost.
Changes:
Changes how the bot determines which item to give back to the user. This returns the correct unchanged version of the item that has reached zero charges.
Other checks:
I have done extensive testing in my private server. It may be beneficial to move this over to the test server and let the community do more testing to ensure no bugs.