mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Recharge enchanted items in player's inventory over time
This commit is contained in:
parent
74e42a2d02
commit
e8dcd74741
6 changed files with 58 additions and 0 deletions
|
@ -59,6 +59,8 @@ namespace MWBase
|
||||||
/// \param paused In game type does not currently advance (this usually means some GUI
|
/// \param paused In game type does not currently advance (this usually means some GUI
|
||||||
/// component is up).
|
/// component is up).
|
||||||
|
|
||||||
|
virtual void advanceTime (float duration) = 0;
|
||||||
|
|
||||||
virtual void setPlayerName (const std::string& name) = 0;
|
virtual void setPlayerName (const std::string& name) = 0;
|
||||||
///< Set player name.
|
///< Set player name.
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,14 @@ namespace MWMechanics
|
||||||
mWatched = ptr;
|
mWatched = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MechanicsManager::advanceTime (float duration)
|
||||||
|
{
|
||||||
|
// Uses ingame time, but scaled to real time
|
||||||
|
duration /= MWBase::Environment::get().getWorld()->getTimeScaleFactor();
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
player.getClass().getInventoryStore(player).rechargeItems(duration);
|
||||||
|
}
|
||||||
|
|
||||||
void MechanicsManager::update(float duration, bool paused)
|
void MechanicsManager::update(float duration, bool paused)
|
||||||
{
|
{
|
||||||
if(!mWatched.isEmpty())
|
if(!mWatched.isEmpty())
|
||||||
|
|
|
@ -63,6 +63,8 @@ namespace MWMechanics
|
||||||
/// \param paused In game type does not currently advance (this usually means some GUI
|
/// \param paused In game type does not currently advance (this usually means some GUI
|
||||||
/// component is up).
|
/// component is up).
|
||||||
|
|
||||||
|
virtual void advanceTime (float duration);
|
||||||
|
|
||||||
virtual void setPlayerName (const std::string& name);
|
virtual void setPlayerName (const std::string& name);
|
||||||
///< Set player name.
|
///< Set player name.
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,8 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
|
||||||
autoEquip(actorPtr);
|
autoEquip(actorPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateRechargingItems();
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,6 +461,8 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
|
||||||
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateRechargingItems();
|
||||||
|
|
||||||
return retCount;
|
return retCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,3 +581,35 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MWWorld::InventoryStore::updateRechargingItems()
|
||||||
|
{
|
||||||
|
mRechargingItems.clear();
|
||||||
|
for (ContainerStoreIterator it = begin(); it != end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->getClass().getEnchantment(*it) != "")
|
||||||
|
{
|
||||||
|
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(
|
||||||
|
it->getClass().getEnchantment(*it));
|
||||||
|
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed
|
||||||
|
|| enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
|
||||||
|
mRechargingItems.push_back(std::make_pair(it, enchantment->mData.mCharge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWWorld::InventoryStore::rechargeItems(float duration)
|
||||||
|
{
|
||||||
|
for (TRechargingItems::iterator it = mRechargingItems.begin(); it != mRechargingItems.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->first->getCellRef().mEnchantmentCharge == -1
|
||||||
|
|| it->first->getCellRef().mEnchantmentCharge == it->second)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
static float fMagicItemRechargePerSecond = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
"fMagicItemRechargePerSecond")->getFloat();
|
||||||
|
|
||||||
|
it->first->getCellRef().mEnchantmentCharge = std::min (it->first->getCellRef().mEnchantmentCharge + fMagicItemRechargePerSecond * duration,
|
||||||
|
it->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -92,11 +92,16 @@ namespace MWWorld
|
||||||
// selected magic item (for using enchantments of type "Cast once" or "Cast when used")
|
// selected magic item (for using enchantments of type "Cast once" or "Cast when used")
|
||||||
ContainerStoreIterator mSelectedEnchantItem;
|
ContainerStoreIterator mSelectedEnchantItem;
|
||||||
|
|
||||||
|
// (item, max charge)
|
||||||
|
typedef std::vector<std::pair<ContainerStoreIterator, float> > TRechargingItems;
|
||||||
|
TRechargingItems mRechargingItems;
|
||||||
|
|
||||||
void copySlots (const InventoryStore& store);
|
void copySlots (const InventoryStore& store);
|
||||||
|
|
||||||
void initSlots (TSlots& slots_);
|
void initSlots (TSlots& slots_);
|
||||||
|
|
||||||
void updateMagicEffects(const Ptr& actor);
|
void updateMagicEffects(const Ptr& actor);
|
||||||
|
void updateRechargingItems();
|
||||||
|
|
||||||
void fireEquipmentChangedEvent();
|
void fireEquipmentChangedEvent();
|
||||||
|
|
||||||
|
@ -172,6 +177,9 @@ namespace MWWorld
|
||||||
///< Set a listener for various events, see \a InventoryStoreListener
|
///< Set a listener for various events, see \a InventoryStoreListener
|
||||||
|
|
||||||
void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor);
|
void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor);
|
||||||
|
|
||||||
|
void rechargeItems (float duration);
|
||||||
|
/// Restore charge on enchanted items. Note this should only be done for the player.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -607,6 +607,8 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::advanceTime (double hours)
|
void World::advanceTime (double hours)
|
||||||
{
|
{
|
||||||
|
MWBase::Environment::get().getMechanicsManager()->advanceTime(hours*3600);
|
||||||
|
|
||||||
mWeatherManager->advanceTime (hours);
|
mWeatherManager->advanceTime (hours);
|
||||||
|
|
||||||
hours += mGlobalVariables->getFloat ("gamehour");
|
hours += mGlobalVariables->getFloat ("gamehour");
|
||||||
|
|
Loading…
Reference in a new issue