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

Fix oil issue #445

Merged
merged 6 commits into from
Aug 13, 2024
Merged

Fix oil issue #445

merged 6 commits into from
Aug 13, 2024

Conversation

atidot3
Copy link
Contributor

@atidot3 atidot3 commented Aug 6, 2024

{
oil = FindConsumable(uPriorizedWizardOilIds[i]);
oil = FindConsumable(uPriorizedWizardOilIds[id]);
Copy link
Owner

Choose a reason for hiding this comment

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

This seems even worse. Imagine uPrioritizedWizardOilIds[MINOR_WIZARD_OIL] being equivalent to uPrioritizedWizardOilIds[9731].

Copy link
Contributor Author

@atidot3 atidot3 Aug 7, 2024

Choose a reason for hiding this comment

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

yea

@fuzzdeveloper
Copy link
Collaborator

fuzzdeveloper commented Aug 8, 2024

There's a bit of redundancy here:

oil = FindConsumable(id);
if (!oil)
    oil = FindConsumable(id);
if (oil)
    return oil;

You're just making same FindConsumable call twice, the original code, if you read it carefully (and you have to read it carefully because its written like hell) alternated through both arrays, in different orders for different weapon types like this:
image

I've never played a class that uses this stuff so I've no idea why you'd want to priortise the oils this way, but if you want to reproduce this behavior, I would do so by just making an array that's already in the correct order for swords/staffs/daggers, and another array that's in correct order for maces, like this:

static const uint32 uOilsWithWizardPriorty[] = {
    MINOR_WIZARD_OIL, MINOR_MANA_OIL,
    LESSER_WIZARD_OIL, LESSER_MANA_OIL,
    BRILLIANT_WIZARD_OIL, BRILLIANT_MANA_OIL,
    WIZARD_OIL, SUPERIOR_MANA_OIL,
    SUPERIOR_WIZARD_OIL,
};

static const uint32 uOilsWithManaPriorty[] = {
    MINOR_MANA_OIL, MINOR_WIZARD_OIL,
    LESSER_MANA_OIL, LESSER_WIZARD_OIL,
    BRILLIANT_MANA_OIL, BRILLIANT_WIZARD_OIL,
    SUPERIOR_MANA_OIL, WIZARD_OIL,
    SUPERIOR_WIZARD_OIL,
};

There's nothing else using those arrays so you can just replace them with the above, once you've done that you can write sane code to iterate through the arrays, like this:

    for (const auto& id : uOilsWithWizardPriorty)
    {
        for (Item* o = FindConsumable(id))
            return o;
    }

That's the loop for swords/staves/daggers, the mades one will iterate through other array (you can also remove the oil variable entirely, we're not using it in the loops anymore, so just return nullptr at the end if nothing is found).

Btw I actually wrote this entire comment twice (if you noticed) because I re-read the original code and thought I'd got things wrong (I thought it was finishing the loop and returning best oil found in either array) but then I read it again, nope, I was correct, it returns first oil found (using order in my pic). That code actually dates back to mangos bot so I'm surprised its causing issues (as horrible as it was to visually parse).

@atidot3 atidot3 closed this Aug 8, 2024
@atidot3 atidot3 reopened this Aug 8, 2024
@atidot3
Copy link
Contributor Author

atidot3 commented Aug 8, 2024

Didnt met to close this damn pr miss clicked.

I didnt paid attention to the priority of the weapon type i'll rewrite this by my end rather than fixing this retarded code.

@fuzzdeveloper
Copy link
Collaborator

Mate it took me a decent amount of staring at that code (the original) before I was sure I knew what it was doing, its like it's been written by a decompiler or something.

@atidot3
Copy link
Contributor Author

atidot3 commented Aug 8, 2024

Maybe, but good call !

@atidot3
Copy link
Contributor Author

atidot3 commented Aug 11, 2024

image
image

Is this related to oils ?

@liyunfan1223 liyunfan1223 merged commit a35b87e into liyunfan1223:master Aug 13, 2024
5 checks passed
@atidot3 atidot3 deleted the oil_fix branch August 17, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants