mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
Implement getNormalizedEnchantmentCharge() method and use it
This commit is contained in:
parent
54bd7b2dcf
commit
c3e8d536cd
5 changed files with 24 additions and 62 deletions
|
@ -86,66 +86,24 @@ 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 = static_cast<int>(left.mBase.getCellRef().getNormalizedEnchantmentCharge(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 = static_cast<int>(right.mBase.getCellRef().getNormalizedEnchantmentCharge(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,8 +34,9 @@ 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))
|
||||||
|
{
|
||||||
price *= item.getClass().getItemNormalizedHealth(item);
|
price *= item.getClass().getItemNormalizedHealth(item);
|
||||||
|
}
|
||||||
return static_cast<int>(price * count);
|
return static_cast<int>(price * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1369,22 +1369,7 @@ 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 = 100;
|
int chargePercent = static_cast<int>(item.getCellRef().getNormalizedEnchantmentCharge(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));
|
||||||
}
|
}
|
||||||
|
@ -1402,7 +1387,6 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
durabilityPercent = static_cast<int>(item.getClass().getItemNormalizedHealth(item));
|
durabilityPercent = static_cast<int>(item.getClass().getItemNormalizedHealth(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
mHud->setSelectedWeapon(item, durabilityPercent);
|
mHud->setSelectedWeapon(item, durabilityPercent);
|
||||||
mInventoryWindow->setTitle(item.getClass().getName(item));
|
mInventoryWindow->setTitle(item.getClass().getName(item));
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,22 @@ namespace MWWorld
|
||||||
return mCellRef.mEnchantmentCharge;
|
return mCellRef.mEnchantmentCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float CellRef::getNormalizedEnchantmentCharge(int maxCharge) const
|
||||||
|
{
|
||||||
|
if (maxCharge == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (mCellRef.mEnchantmentCharge == -1)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return mCellRef.mEnchantmentCharge / static_cast<float>(maxCharge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CellRef::setEnchantmentCharge(float charge)
|
void CellRef::setEnchantmentCharge(float charge)
|
||||||
{
|
{
|
||||||
if (charge != mCellRef.mEnchantmentCharge)
|
if (charge != mCellRef.mEnchantmentCharge)
|
||||||
|
|
|
@ -56,6 +56,9 @@ namespace MWWorld
|
||||||
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
||||||
float getEnchantmentCharge() const;
|
float getEnchantmentCharge() const;
|
||||||
|
|
||||||
|
// Remaining enchantment charge rescaled to the supplied maximum charge (such as one of the enchantment).
|
||||||
|
float getNormalizedEnchantmentCharge(int maxCharge) const;
|
||||||
|
|
||||||
void setEnchantmentCharge(float charge);
|
void setEnchantmentCharge(float charge);
|
||||||
|
|
||||||
// For weapon or armor, this is the remaining item health.
|
// For weapon or armor, this is the remaining item health.
|
||||||
|
|
Loading…
Reference in a new issue