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

Show accurate armor/dmg #7427

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
display true dmg
qndel committed Sep 23, 2024
commit ba9ebb215fc64e35236af438b87f99714c03e152
28 changes: 7 additions & 21 deletions Source/items.cpp
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@
#include "utils/format_int.hpp"
#include "utils/language.h"
#include "utils/log.hpp"
#include "utils/math.h"
#include "utils/str_case.hpp"
#include "utils/str_cat.hpp"
#include "utils/utf8.hpp"
@@ -2472,20 +2471,6 @@ void InitItems()
initItemGetRecords();
}

int GetBonusAC(const Item &item)
{
if (item._iPLAC != 0) {
int tempAc = item._iAC;
tempAc *= item._iPLAC;
tempAc /= 100;
if (tempAc == 0)
tempAc = math::Sign(item._iPLAC);
return tempAc;
}

return 0;
}

void CalcPlrDamage(Player &player, int minDamage, int maxDamage)
{
const uint8_t playerLevel = player.getCharacterLevel();
@@ -2817,7 +2802,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx)
if (item._iMagical == ITEM_QUALITY_NORMAL || item._iIdentified) {
dam += item._iPLDam;
toHit += item._iPLToHit;
bonusAc += GetBonusAC(item);
bonusAc += item.getBonusAC();
flags |= item._iFlags;
damAcFlags |= item._iDamAcFlags;
strength += item._iPLStr;
@@ -4097,22 +4082,23 @@ void PrintItemDetails(const Item &item)
return;

if (item._iClass == ICLASS_WEAPON) {
std::pair<int, int> realDamage = item.getFinalDamage(showItemBaseStats || !item._iIdentified);
if (item._iMinDam == item._iMaxDam) {
if (item._iMaxDur == DUR_INDESTRUCTIBLE)
AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Indestructible")), item._iMinDam));
AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Indestructible")), realDamage.first));
else
AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d} Dur: {:d}/{:d}")), item._iMinDam, item._iDurability, item._iMaxDur));
AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d} Dur: {:d}/{:d}")), realDamage.first, item._iDurability, item._iMaxDur));
} else {
if (item._iMaxDur == DUR_INDESTRUCTIBLE)
AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Indestructible")), item._iMinDam, item._iMaxDam));
AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Indestructible")), realDamage.first, realDamage.second));
else
AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d}-{:d} Dur: {:d}/{:d}")), item._iMinDam, item._iMaxDam, item._iDurability, item._iMaxDur));
AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d}-{:d} Dur: {:d}/{:d}")), realDamage.first, realDamage.second, item._iDurability, item._iMaxDur));
}
}
if (item._iClass == ICLASS_ARMOR) {
int realAC = item._iAC;
if (!showItemBaseStats && item._iIdentified) {
realAC += GetBonusAC(item);
realAC += item.getBonusAC();
}
if (item._iMaxDur == DUR_INDESTRUCTIBLE)
AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Indestructible")), realAC));
28 changes: 28 additions & 0 deletions Source/items.h
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include "engine/point.hpp"
#include "itemdat.h"
#include "monster.h"
#include "utils/math.h"
#include "utils/string_or_view.hpp"

namespace devilution {
@@ -420,6 +421,33 @@ struct Item {
return _iSeed == seed && IDidx == itemIndex && _iCreateInfo == createInfo;
}

int getBonusAC() const
{
if (_iPLAC != 0) {
int tempAc = _iAC;
tempAc *= _iPLAC;
tempAc /= 100;
if (tempAc == 0)
tempAc = math::Sign(_iPLAC);
return tempAc;
}

return 0;
}

std::pair<int, int> getFinalDamage(bool baseDamage) const
{
int minDmg = _iMinDam;
int maxDmg = _iMaxDam;
if (!baseDamage) {
minDmg += minDmg * _iPLDam / 100;
maxDmg += maxDmg * _iPLDam / 100;
minDmg += _iPLDamMod;
maxDmg += _iPLDamMod;
}
return { minDmg, maxDmg };
}

UiFlags getTextColor() const
{
switch (_iMagical) {
15 changes: 11 additions & 4 deletions Source/stores.cpp
Original file line number Diff line number Diff line change
@@ -305,10 +305,17 @@ void PrintStoreItem(const Item &item, int l, UiFlags flags, bool cursIndent = fa
}

if (item._itype != ItemType::Misc) {
if (item._iClass == ICLASS_WEAPON)
productLine = fmt::format(fmt::runtime(_("Damage: {:d}-{:d} ")), item._iMinDam, item._iMaxDam);
else if (item._iClass == ICLASS_ARMOR)
productLine = fmt::format(fmt::runtime(_("Armor: {:d} ")), item._iAC);
if (item._iClass == ICLASS_WEAPON) {
std::pair<int, int> realDamage = item.getFinalDamage(showItemBaseStats || !item._iIdentified);
productLine = fmt::format(fmt::runtime(_("Damage: {:d}-{:d} ")), realDamage.first, realDamage.second);
}
else if (item._iClass == ICLASS_ARMOR) {
int realAC = item._iAC;
if (!showItemBaseStats && item._iIdentified) {
realAC += item.getBonusAC();
}
productLine = fmt::format(fmt::runtime(_("Armor: {:d} ")), realAC);
}
if (item._iMaxDur != DUR_INDESTRUCTIBLE && item._iMaxDur != 0)
productLine += fmt::format(fmt::runtime(_("Dur: {:d}/{:d}")), item._iDurability, item._iMaxDur);
else