mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-22 04:14:04 +00:00
Avoid item condition and charge zero divisions
This commit is contained in:
parent
ecc671bfb9
commit
67de61e1fb
8 changed files with 100 additions and 16 deletions
|
@ -297,7 +297,7 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
const MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc);
|
const MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc);
|
||||||
|
|
||||||
if (ptr.getCellRef().getCharge() == 0)
|
if (getItemHealth(ptr) == 0)
|
||||||
return std::make_pair(0, "#{sInventoryMessage1}");
|
return std::make_pair(0, "#{sInventoryMessage1}");
|
||||||
|
|
||||||
// slots that this item can be equipped in
|
// slots that this item can be equipped in
|
||||||
|
|
|
@ -1148,12 +1148,19 @@ namespace MWClass
|
||||||
const bool hasHealth = it->getClass().hasItemHealth(*it);
|
const bool hasHealth = it->getClass().hasItemHealth(*it);
|
||||||
if (hasHealth)
|
if (hasHealth)
|
||||||
{
|
{
|
||||||
int armorHealth = it->getClass().getItemHealth(*it);
|
|
||||||
int armorMaxHealth = it->getClass().getItemMaxHealth(*it);
|
int armorMaxHealth = it->getClass().getItemMaxHealth(*it);
|
||||||
|
if (armorMaxHealth == 0)
|
||||||
|
{
|
||||||
|
ratings[i] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int armorHealth = it->getClass().getItemHealth(*it);
|
||||||
ratings[i] *= (float(armorHealth) / armorMaxHealth);
|
ratings[i] *= (float(armorHealth) / armorMaxHealth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float shield = stats.getMagicEffects().get(ESM::MagicEffect::Shield).getMagnitude();
|
float shield = stats.getMagicEffects().get(ESM::MagicEffect::Shield).getMagnitude();
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ namespace MWClass
|
||||||
|
|
||||||
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const
|
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const
|
||||||
{
|
{
|
||||||
if (hasItemHealth(ptr) && ptr.getCellRef().getCharge() == 0)
|
if (hasItemHealth(ptr) && getItemHealth(ptr) == 0)
|
||||||
return std::make_pair(0, "#{sInventoryMessage1}");
|
return std::make_pair(0, "#{sInventoryMessage1}");
|
||||||
|
|
||||||
// Do not allow equip weapons from inventory during attack
|
// Do not allow equip weapons from inventory during attack
|
||||||
|
|
|
@ -51,7 +51,7 @@ void MerchantRepair::setPtr(const MWWorld::Ptr &actor)
|
||||||
{
|
{
|
||||||
int maxDurability = iter->getClass().getItemMaxHealth(*iter);
|
int maxDurability = iter->getClass().getItemMaxHealth(*iter);
|
||||||
int durability = iter->getClass().getItemHealth(*iter);
|
int durability = iter->getClass().getItemHealth(*iter);
|
||||||
if (maxDurability == durability)
|
if (maxDurability == durability || maxDurability == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int basePrice = iter->getClass().getValue(*iter);
|
int basePrice = iter->getClass().getValue(*iter);
|
||||||
|
|
|
@ -86,26 +86,66 @@ namespace
|
||||||
if (!leftName.empty())
|
if (!leftName.empty())
|
||||||
{
|
{
|
||||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(leftName);
|
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(leftName);
|
||||||
|
|
||||||
if (ench)
|
if (ench)
|
||||||
{
|
{
|
||||||
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
|
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
|
||||||
|
{
|
||||||
leftChargePercent = 101;
|
leftChargePercent = 101;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
leftChargePercent = (left.mBase.getCellRef().getEnchantmentCharge() == -1) ? 100
|
{
|
||||||
: static_cast<int>(left.mBase.getCellRef().getEnchantmentCharge() / static_cast<float>(ench->mData.mCharge) * 100);
|
int maxEnchCharge = ench->mData.mCharge;
|
||||||
|
if (maxEnchCharge == 0)
|
||||||
|
{
|
||||||
|
leftChargePercent = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float enchCharge = left.mBase.getCellRef().getEnchantmentCharge();
|
||||||
|
if (enchCharge == -1)
|
||||||
|
{
|
||||||
|
leftChargePercent = 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leftChargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rightName.empty())
|
if (!rightName.empty())
|
||||||
{
|
{
|
||||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(rightName);
|
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(rightName);
|
||||||
|
|
||||||
if (ench)
|
if (ench)
|
||||||
{
|
{
|
||||||
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
|
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
|
||||||
|
{
|
||||||
rightChargePercent = 101;
|
rightChargePercent = 101;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
rightChargePercent = (right.mBase.getCellRef().getEnchantmentCharge() == -1) ? 100
|
{
|
||||||
: static_cast<int>(right.mBase.getCellRef().getEnchantmentCharge() / static_cast<float>(ench->mData.mCharge) * 100);
|
int maxEnchCharge = ench->mData.mCharge;
|
||||||
|
if (maxEnchCharge == 0)
|
||||||
|
{
|
||||||
|
rightChargePercent = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float enchCharge = right.mBase.getCellRef().getEnchantmentCharge();
|
||||||
|
if (enchCharge == -1)
|
||||||
|
{
|
||||||
|
rightChargePercent = 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rightChargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,17 @@ namespace
|
||||||
{
|
{
|
||||||
float price = static_cast<float>(item.getClass().getValue(item));
|
float price = static_cast<float>(item.getClass().getValue(item));
|
||||||
if (item.getClass().hasItemHealth(item))
|
if (item.getClass().hasItemHealth(item))
|
||||||
|
{
|
||||||
|
if (item.getClass().getItemMaxHealth(item) == 0)
|
||||||
|
{
|
||||||
|
price = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
price *= item.getClass().getItemHealth(item);
|
price *= item.getClass().getItemHealth(item);
|
||||||
price /= item.getClass().getItemMaxHealth(item);
|
price /= item.getClass().getItemMaxHealth(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return static_cast<int>(price * count);
|
return static_cast<int>(price * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1369,8 +1369,22 @@ namespace MWGui
|
||||||
const ESM::Enchantment* ench = mStore->get<ESM::Enchantment>()
|
const ESM::Enchantment* ench = mStore->get<ESM::Enchantment>()
|
||||||
.find(item.getClass().getEnchantment(item));
|
.find(item.getClass().getEnchantment(item));
|
||||||
|
|
||||||
int chargePercent = (item.getCellRef().getEnchantmentCharge() == -1) ? 100
|
int chargePercent = 100;
|
||||||
: static_cast<int>(item.getCellRef().getEnchantmentCharge() / static_cast<float>(ench->mData.mCharge) * 100);
|
|
||||||
|
int maxEnchCharge = ench->mData.mCharge;
|
||||||
|
if (maxEnchCharge == 0)
|
||||||
|
{
|
||||||
|
chargePercent = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float enchCharge = item.getCellRef().getEnchantmentCharge();
|
||||||
|
if (enchCharge != -1)
|
||||||
|
{
|
||||||
|
chargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mHud->setSelectedEnchantItem(item, chargePercent);
|
mHud->setSelectedEnchantItem(item, chargePercent);
|
||||||
mSpellWindow->setTitle(item.getClass().getName(item));
|
mSpellWindow->setTitle(item.getClass().getName(item));
|
||||||
}
|
}
|
||||||
|
@ -1386,7 +1400,16 @@ namespace MWGui
|
||||||
int durabilityPercent = 100;
|
int durabilityPercent = 100;
|
||||||
if (item.getClass().hasItemHealth(item))
|
if (item.getClass().hasItemHealth(item))
|
||||||
{
|
{
|
||||||
durabilityPercent = static_cast<int>(item.getClass().getItemHealth(item) / static_cast<float>(item.getClass().getItemMaxHealth(item)) * 100);
|
int weapmaxhealth = item.getClass().getItemMaxHealth(item);
|
||||||
|
if (weapmaxhealth == 0)
|
||||||
|
{
|
||||||
|
durabilityPercent = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int weaphealth = item.getClass().getItemHealth(item);
|
||||||
|
durabilityPercent = static_cast<int>(weaphealth / static_cast<float>(weapmaxhealth) * 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mHud->setSelectedWeapon(item, durabilityPercent);
|
mHud->setSelectedWeapon(item, durabilityPercent);
|
||||||
mInventoryWindow->setTitle(item.getClass().getName(item));
|
mInventoryWindow->setTitle(item.getClass().getName(item));
|
||||||
|
|
|
@ -371,10 +371,17 @@ namespace MWMechanics
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
||||||
if(weaphashealth)
|
if (weaphashealth)
|
||||||
{
|
{
|
||||||
int weaphealth = weapon.getClass().getItemHealth(weapon);
|
|
||||||
int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
|
int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
|
||||||
|
|
||||||
|
if (weapmaxhealth == 0)
|
||||||
|
{
|
||||||
|
damage = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int weaphealth = weapon.getClass().getItemHealth(weapon);
|
||||||
damage *= (float(weaphealth) / weapmaxhealth);
|
damage *= (float(weaphealth) / weapmaxhealth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue