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: check null pointer from master on no-pvp combat. #3355

Closed
wants to merge 8 commits into from

Conversation

kaleohanopahala
Copy link
Contributor

@kaleohanopahala kaleohanopahala commented Feb 10, 2025

Now:
Reduces redundancy by consolidating checks.
Improves readability and maintainability by organizing conditions in a more logical and grouped manner.
Makes it easier to understand the flow of the function and how different entity types are handled (players, summons, monsters, NPC's).

@myallith
Copy link
Contributor

That way, you'll end up ruining the fun for people who enjoy crashing the rival's OT lol.
kkkkk

@majestyotbr majestyotbr changed the title Fix master null reference on combat. fix: master null reference on combat Feb 10, 2025
@dudantas dudantas changed the title fix: master null reference on combat fix: check null pointer from master on no-pvp combat. Feb 10, 2025
@@ -427,14 +427,15 @@ ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &attacker, const
}
}

if (target && target->isSummon() && target->getMaster()->getPlayer()) {
if (target && target->isSummon() && target->getMaster() && target->getMaster()->getPlayer()) {
Copy link
Member

@dudantas dudantas Feb 10, 2025

Choose a reason for hiding this comment

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

You can move this for the begin of function:

const auto &targetMaster = target ? target->getMaster() : nullptr;

After from here:

const auto &attackerPlayer = attacker->getPlayer();

This will avoid increasing the reference count (as this function is called a lot, it will increase the reference every time it is called).

And you can check this: too:

if (target->isSummon() && target->getMaster()->getPlayer() && target->getZoneType() == ZONE_NOPVP) {

And remove this:

const auto &targetMaster = target->getMaster();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code has been refactored.
Can test again?

Thanks dude 👯

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.

4 participants