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

spectral damage off by 1 #7021

Merged
merged 2 commits into from
Mar 14, 2024
Merged

spectral damage off by 1 #7021

merged 2 commits into from
Mar 14, 2024

Conversation

ikonomov
Copy link
Contributor

@ikonomov ikonomov commented Mar 14, 2024

the maximum damage is max-1
fixes diasurgical/devilution#64 (comment)

the maximum damage is max-1
@qndel qndel changed the title spectral damage and melee elemental damage spectral and melee elemental damage off by 1 Mar 14, 2024
@ikonomov ikonomov changed the title spectral and melee elemental damage off by 1 spectral damage off by 1 Mar 14, 2024
@@ -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);
Copy link
Collaborator

@kphoenix137 kphoenix137 Mar 14, 2024

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.

@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

@@ -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);
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks guys

@AJenbo AJenbo merged commit 9930808 into diasurgical:master Mar 14, 2024
22 checks passed
@AJenbo
Copy link
Member

AJenbo commented Mar 14, 2024

Interesting that you can close issues across repos like that

@julealgon
Copy link
Contributor

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.

@ikonomov ikonomov deleted the patch-1 branch March 15, 2024 15:52
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.

Document Diablo's bugs
5 participants