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

Conversation

nwjgit
Copy link
Contributor

@nwjgit nwjgit commented Oct 11, 2023

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 tested all my changes thoroughly.

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.

Copy link
Contributor

@themrrobert themrrobert left a 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 be refundOnBreak
  • 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.

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.

@@ -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');
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.

@nwjgit
Copy link
Contributor Author

nwjgit commented Oct 11, 2023

Thanks for all the feedback, I believe I made all the adjustments you wanted.

Something that may need addressed is the "unchargedItem" not taking into account variants when trying to charge items. Currently it isn't an issue because the only items that have variants are scythe & sang staff . Both have /create to make their charged versions and then /minion charge works without error. But this won't work if for example the shadow gets a variant since it's charged version isn't under /create.
Discord_ZmBbh794K1

I imagine something could be done with /degradableItemsCommand similar to what I've done here. Let me know if that should be addressed in a new pr or you would like me to add it to this one.

@nwjgit
Copy link
Contributor Author

nwjgit commented Nov 10, 2023

Could this be reviewed again? People are still losing their kits.

@gc gc merged commit d2f648d into oldschoolgg:master Nov 24, 2023
5 checks passed
@nwjgit nwjgit mentioned this pull request Jan 12, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kits on Scythe Disappear
3 participants