-
-
Notifications
You must be signed in to change notification settings - Fork 658
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: prevent crash on combatBlockHit #2650
Conversation
…r/canary into fix_crash_combatblock
@@ -6481,13 +6483,13 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr<Creature> attack | |||
CombatParams damageReflectedParams; | |||
|
|||
BlockType_t primaryBlockType, secondaryBlockType; | |||
std::shared_ptr<Player> targetPlayer = target->getPlayer(); | |||
std::shared_ptr<Player> targetPlayer = target ? target->getPlayer() : nullptr; |
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.
You can move this to the line 6463 and avoid nesting the if
if (target) { | ||
if (std::shared_ptr<Player> targetPlayer = target->getPlayer()) { | ||
auto chance = targetPlayer->getDodgeChance(); | ||
if (chance > 0 && uniform_random(0, 10000) < chance) { | ||
InternalGame::sendBlockEffect(BLOCK_DODGE, damage.primary.type, target->getPosition(), attacker); | ||
targetPlayer->sendTextMessage(MESSAGE_ATTENTION, "You dodged an attack."); | ||
return true; | ||
} |
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.
if (target) { | |
if (std::shared_ptr<Player> targetPlayer = target->getPlayer()) { | |
auto chance = targetPlayer->getDodgeChance(); | |
if (chance > 0 && uniform_random(0, 10000) < chance) { | |
InternalGame::sendBlockEffect(BLOCK_DODGE, damage.primary.type, target->getPosition(), attacker); | |
targetPlayer->sendTextMessage(MESSAGE_ATTENTION, "You dodged an attack."); | |
return true; | |
} | |
const auto &targetPlayer = target ? target->getPlayer() : nullptr; | |
// Skill dodge (ruse) | |
if (targetPlayer) { | |
auto chance = targetPlayer->getDodgeChance(); | |
if (chance > 0 && uniform_random(0, 10000) < chance) { | |
InternalGame::sendBlockEffect(BLOCK_DODGE, damage.primary.type, target->getPosition(), attacker); | |
targetPlayer->sendTextMessage(MESSAGE_ATTENTION, "You dodged an attack."); | |
return true; | |
} | |
} |
Do you intend to finish this PR? |
Update your pull request and use the pull request template. |
i'm closing this pull request due to inactivity. Feel free to reopen when you decide to finish. |
No description provided.