mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Don't attempt to lock or unlock unsuitable objects (Fixes #2826)
This commit is contained in:
parent
0d8f07d563
commit
211deeb63e
8 changed files with 27 additions and 10 deletions
|
@ -281,9 +281,12 @@ namespace MWClass
|
|||
ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative
|
||||
}
|
||||
|
||||
bool Container::canLock(const MWWorld::Ptr &ptr) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
MWWorld::Ptr
|
||||
Container::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
||||
MWWorld::Ptr Container::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Container> *ref =
|
||||
ptr.get<ESM::Container>();
|
||||
|
@ -291,8 +294,7 @@ namespace MWClass
|
|||
return MWWorld::Ptr(&cell.get<ESM::Container>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
||||
const
|
||||
void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const
|
||||
{
|
||||
const ESM::ContainerState& state2 = dynamic_cast<const ESM::ContainerState&> (state);
|
||||
|
||||
|
@ -307,8 +309,7 @@ namespace MWClass
|
|||
readState (state2.mInventory);
|
||||
}
|
||||
|
||||
void Container::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
||||
const
|
||||
void Container::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) const
|
||||
{
|
||||
ESM::ContainerState& state2 = dynamic_cast<ESM::ContainerState&> (state);
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ namespace MWClass
|
|||
virtual void unlock (const MWWorld::Ptr& ptr) const;
|
||||
///< Unlock object
|
||||
|
||||
virtual bool canLock(const MWWorld::Ptr &ptr) const;
|
||||
|
||||
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
||||
const;
|
||||
///< Read additional state from \a state into \a ptr.
|
||||
|
|
|
@ -207,6 +207,11 @@ namespace MWClass
|
|||
ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative
|
||||
}
|
||||
|
||||
bool Door::canLock(const MWWorld::Ptr &ptr) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Door::getScript (const MWWorld::Ptr& ptr) const
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Door> *ref =
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace MWClass
|
|||
virtual void unlock (const MWWorld::Ptr& ptr) const;
|
||||
///< Unlock object
|
||||
|
||||
virtual bool canLock(const MWWorld::Ptr &ptr) const;
|
||||
|
||||
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
|
||||
///< Return name of the script attached to ptr
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace MWMechanics
|
|||
void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick,
|
||||
std::string& resultMessage, std::string& resultSound)
|
||||
{
|
||||
if (!(lock.getCellRef().getLockLevel() > 0)) //If it's unlocked back out immediately
|
||||
if (!(lock.getCellRef().getLockLevel() > 0) || !lock.getClass().canLock(lock)) //If it's unlocked back out immediately
|
||||
return;
|
||||
|
||||
int lockStrength = lock.getCellRef().getLockLevel();
|
||||
|
|
|
@ -562,7 +562,7 @@ namespace MWMechanics
|
|||
void CastSpell::applyInstantEffect(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, const MWMechanics::EffectKey& effect, float magnitude)
|
||||
{
|
||||
short effectId = effect.mId;
|
||||
if (!target.getClass().isActor())
|
||||
if (target.getClass().canLock(target))
|
||||
{
|
||||
if (effectId == ESM::MagicEffect::Lock)
|
||||
{
|
||||
|
@ -570,7 +570,7 @@ namespace MWMechanics
|
|||
{
|
||||
if (caster == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}");
|
||||
target.getCellRef().setLockLevel(static_cast<int>(magnitude));
|
||||
target.getClass().lock(target, static_cast<int>(magnitude));
|
||||
}
|
||||
}
|
||||
else if (effectId == ESM::MagicEffect::Open)
|
||||
|
@ -586,7 +586,7 @@ namespace MWMechanics
|
|||
if (caster == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}");
|
||||
}
|
||||
target.getCellRef().setLockLevel(-abs(target.getCellRef().getLockLevel()));
|
||||
target.getClass().unlock(target);
|
||||
}
|
||||
else
|
||||
MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock Fail", 1.f, 1.f);
|
||||
|
|
|
@ -144,6 +144,11 @@ namespace MWWorld
|
|||
throw std::runtime_error ("class does not support unlocking");
|
||||
}
|
||||
|
||||
bool Class::canLock(const Ptr &ptr) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Class::setRemainingUsageTime (const Ptr& ptr, float duration) const
|
||||
{
|
||||
throw std::runtime_error ("class does not support time-based uses");
|
||||
|
|
|
@ -161,6 +161,8 @@ namespace MWWorld
|
|||
virtual void unlock (const Ptr& ptr) const;
|
||||
///< Unlock object (default implementation: throw an exception)
|
||||
|
||||
virtual bool canLock (const Ptr& ptr) const;
|
||||
|
||||
virtual void setRemainingUsageTime (const Ptr& ptr, float duration) const;
|
||||
///< Sets the remaining duration of the object, such as an equippable light
|
||||
/// source. (default implementation: throw an exception)
|
||||
|
|
Loading…
Reference in a new issue