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: prevent crash on combatBlockHit #2650

Closed
wants to merge 5 commits into from
Closed

Conversation

carlospess0a
Copy link
Contributor

No description provided.

@carlospess0a carlospess0a changed the title fix: prevent crash on combatBlockHit draft: fix: prevent crash on combatBlockHit May 24, 2024
@@ -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;
Copy link
Member

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

Comment on lines +6463 to +6470
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;
}
Copy link
Member

@dudantas dudantas May 24, 2024

Choose a reason for hiding this comment

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

Suggested change
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;
}
}

@dudantas dudantas marked this pull request as draft May 24, 2024 20:14
@dudantas dudantas changed the title draft: fix: prevent crash on combatBlockHit fix: prevent crash on combatBlockHit May 24, 2024
@majestyotbr
Copy link
Contributor

Do you intend to finish this PR?

@majestyotbr
Copy link
Contributor

majestyotbr commented Jul 10, 2024

Update your pull request and use the pull request template.

@majestyotbr
Copy link
Contributor

i'm closing this pull request due to inactivity. Feel free to reopen when you decide to finish.

@majestyotbr majestyotbr deleted the fix_crash_combatblock branch January 11, 2025 20:33
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