-
Notifications
You must be signed in to change notification settings - Fork 824
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
spectral damage off by 1 #7021
spectral damage off by 1 #7021
Conversation
the maximum damage is max-1
Source/player.cpp
Outdated
@@ -600,7 +600,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) | |||
} | |||
|
|||
if (gbIsHellfire && HasAllOf(player._pIFlags, ItemSpecialEffect::FireDamage | ItemSpecialEffect::LightningDamage)) { | |||
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam); | |||
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam + 1); |
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.
int midam = player._pIFMinDam + GenerateRnd((player._pIFMaxDam - player._pIFMinDam) + 1);
While the order of operations here will result in the same result regardless if you add these parentheses or not, it's best practice to make the order of operations explicit, for maintainability and readability, since max - (min + 1) would produce a different result.
It wouldn't hurt to also add these parentheses in other functions that use GenerateRnd()
with min and max damage however maybe best in a separate PR.
Source/player.cpp
Outdated
@@ -920,7 +920,7 @@ bool DoRangeAttack(Player &player) | |||
mistype = MissileID::LightningArrow; | |||
} | |||
if (HasAllOf(player._pIFlags, ItemSpecialEffect::FireArrows | ItemSpecialEffect::LightningArrows)) { | |||
dmg = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam); | |||
dmg = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam + 1); |
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.
Same as above.
Source/player.cpp
Outdated
@@ -600,7 +600,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) | |||
} | |||
|
|||
if (gbIsHellfire && HasAllOf(player._pIFlags, ItemSpecialEffect::FireDamage | ItemSpecialEffect::LightningDamage)) { | |||
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam); | |||
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam + 1); |
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.
Isn't there a randomIntBetween
function we can use here that already does this?
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.
Yeah, use RandomIntBetween(player._pIFMinDam, player._pIFMaxDam)
. Closed ranges (where you add one to the roll to get a result back that potentially includes the max damage) are the default
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.
Fixed. Thanks guys
Interesting that you can close issues across repos like that |
Oh I hadn't noticed that! That's new to me as well, good to know. |
the maximum damage is max-1
fixes diasurgical/devilution#64 (comment)