forked from teamnwah/openmw-tes3coop
Implement Trespassing crime
This commit is contained in:
parent
f5a70dccf0
commit
3bf36515d5
7 changed files with 32 additions and 17 deletions
|
@ -112,6 +112,8 @@ namespace MWBase
|
||||||
OffenseType type, int arg=0) = 0;
|
OffenseType type, int arg=0) = 0;
|
||||||
/// Utility to check if taking this item is illegal and calling commitCrime if so
|
/// Utility to check if taking this item is illegal and calling commitCrime if so
|
||||||
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, int count) = 0;
|
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, int count) = 0;
|
||||||
|
/// Utility to check if opening (i.e. unlocking) this object is illegal and calling commitCrime if so
|
||||||
|
virtual void objectOpened (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item) = 0;
|
||||||
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
|
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
|
||||||
/// @return was it illegal, and someone saw you doing it?
|
/// @return was it illegal, and someone saw you doing it?
|
||||||
virtual bool sleepInBed (const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed) = 0;
|
virtual bool sleepInBed (const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed) = 0;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/// @return is \a ptr allowed to take/use \a item or is it a crime?
|
/// @return is \a ptr allowed to take/use \a item or is it a crime?
|
||||||
bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item)
|
bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, MWWorld::Ptr& victim)
|
||||||
{
|
{
|
||||||
const std::string& owner = item.getCellRef().mOwner;
|
const std::string& owner = item.getCellRef().mOwner;
|
||||||
bool isOwned = !owner.empty();
|
bool isOwned = !owner.empty();
|
||||||
|
@ -33,6 +33,9 @@ namespace
|
||||||
isFactionOwned = true;
|
isFactionOwned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!item.getCellRef().mOwner.empty())
|
||||||
|
victim = MWBase::Environment::get().getWorld()->getPtr(item.getCellRef().mOwner, true);
|
||||||
|
|
||||||
return (!isOwned && !isFactionOwned);
|
return (!isOwned && !isFactionOwned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -752,11 +755,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
bool MechanicsManager::sleepInBed(const MWWorld::Ptr &ptr, const MWWorld::Ptr &bed)
|
bool MechanicsManager::sleepInBed(const MWWorld::Ptr &ptr, const MWWorld::Ptr &bed)
|
||||||
{
|
{
|
||||||
if (isAllowedToUse(ptr, bed))
|
|
||||||
return false;
|
|
||||||
MWWorld::Ptr victim;
|
MWWorld::Ptr victim;
|
||||||
if (!bed.getCellRef().mOwner.empty())
|
if (isAllowedToUse(ptr, bed, victim))
|
||||||
victim = MWBase::Environment::get().getWorld()->getPtr(bed.getCellRef().mOwner, true);
|
return false;
|
||||||
|
|
||||||
if(commitCrime(ptr, victim, OT_SleepingInOwnedBed))
|
if(commitCrime(ptr, victim, OT_SleepingInOwnedBed))
|
||||||
{
|
{
|
||||||
|
@ -767,14 +768,19 @@ namespace MWMechanics
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MechanicsManager::objectOpened(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr victim;
|
||||||
|
if (isAllowedToUse(ptr, item, victim))
|
||||||
|
return;
|
||||||
|
commitCrime(ptr, victim, OT_Trespassing);
|
||||||
|
}
|
||||||
|
|
||||||
void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, int count)
|
void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, int count)
|
||||||
{
|
{
|
||||||
if (isAllowedToUse(ptr, item))
|
|
||||||
return;
|
|
||||||
MWWorld::Ptr victim;
|
MWWorld::Ptr victim;
|
||||||
if (!item.getCellRef().mOwner.empty())
|
if (isAllowedToUse(ptr, item, victim))
|
||||||
victim = MWBase::Environment::get().getWorld()->getPtr(item.getCellRef().mOwner, true);
|
return;
|
||||||
|
|
||||||
commitCrime(ptr, victim, OT_Theft, item.getClass().getValue(item) * count);
|
commitCrime(ptr, victim, OT_Theft, item.getClass().getValue(item) * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,8 @@ namespace MWMechanics
|
||||||
OffenseType type, int arg=0);
|
OffenseType type, int arg=0);
|
||||||
/// Utility to check if taking this item is illegal and calling commitCrime if so
|
/// Utility to check if taking this item is illegal and calling commitCrime if so
|
||||||
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, int count);
|
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, int count);
|
||||||
|
/// Utility to check if opening (i.e. unlocking) this object is illegal and calling commitCrime if so
|
||||||
|
virtual void objectOpened (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item);
|
||||||
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
|
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
|
||||||
/// @return was it illegal, and someone saw you doing it?
|
/// @return was it illegal, and someone saw you doing it?
|
||||||
virtual bool sleepInBed (const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed);
|
virtual bool sleepInBed (const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
|
||||||
#include "npcstats.hpp"
|
#include "npcstats.hpp"
|
||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
|
@ -45,6 +46,7 @@ namespace MWMechanics
|
||||||
resultMessage = "#{sLockImpossible}";
|
resultMessage = "#{sLockImpossible}";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, lock);
|
||||||
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
||||||
if (roll <= x)
|
if (roll <= x)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +88,7 @@ namespace MWMechanics
|
||||||
resultMessage = "#{sTrapImpossible}";
|
resultMessage = "#{sTrapImpossible}";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, trap);
|
||||||
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
|
||||||
if (roll <= x)
|
if (roll <= x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
#include "../mwbase/soundmanager.hpp"
|
#include "../mwbase/soundmanager.hpp"
|
||||||
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/containerstore.hpp"
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/actionteleport.hpp"
|
#include "../mwworld/actionteleport.hpp"
|
||||||
|
@ -167,7 +167,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
applyInstantEffect(target, EffectKey(*effectIt), magnitude);
|
applyInstantEffect(target, caster, EffectKey(*effectIt), magnitude);
|
||||||
|
|
||||||
// HACK: Damage attribute/skill actually has a duration, even though the actual effect is instant and permanent.
|
// HACK: Damage attribute/skill actually has a duration, even though the actual effect is instant and permanent.
|
||||||
// This was probably just done to have the effect visible in the magic menu for a while
|
// This was probably just done to have the effect visible in the magic menu for a while
|
||||||
|
@ -177,7 +177,7 @@ namespace MWMechanics
|
||||||
|| effectIt->mEffectID == ESM::MagicEffect::RestoreAttribute
|
|| effectIt->mEffectID == ESM::MagicEffect::RestoreAttribute
|
||||||
|| effectIt->mEffectID == ESM::MagicEffect::RestoreSkill
|
|| effectIt->mEffectID == ESM::MagicEffect::RestoreSkill
|
||||||
)
|
)
|
||||||
applyInstantEffect(target, EffectKey(*effectIt), magnitude);
|
applyInstantEffect(target, caster, EffectKey(*effectIt), magnitude);
|
||||||
|
|
||||||
if (target.getClass().isActor() || magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration)
|
if (target.getClass().isActor() || magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration)
|
||||||
{
|
{
|
||||||
|
@ -220,7 +220,7 @@ namespace MWMechanics
|
||||||
mSourceName, caster.getRefData().getHandle());
|
mSourceName, caster.getRefData().getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CastSpell::applyInstantEffect(const MWWorld::Ptr &target, MWMechanics::EffectKey effect, float magnitude)
|
void CastSpell::applyInstantEffect(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, MWMechanics::EffectKey effect, float magnitude)
|
||||||
{
|
{
|
||||||
short effectId = effect.mId;
|
short effectId = effect.mId;
|
||||||
if (!target.getClass().isActor())
|
if (!target.getClass().isActor())
|
||||||
|
@ -232,11 +232,13 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
else if (effectId == ESM::MagicEffect::Open)
|
else if (effectId == ESM::MagicEffect::Open)
|
||||||
{
|
{
|
||||||
// TODO: This is a crime
|
|
||||||
if (target.getCellRef().mLockLevel <= magnitude)
|
if (target.getCellRef().mLockLevel <= magnitude)
|
||||||
{
|
{
|
||||||
if (target.getCellRef().mLockLevel > 0)
|
if (target.getCellRef().mLockLevel > 0)
|
||||||
|
{
|
||||||
MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock", 1.f, 1.f);
|
MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock", 1.f, 1.f);
|
||||||
|
MWBase::Environment::get().getMechanicsManager()->objectOpened(caster, target);
|
||||||
|
}
|
||||||
target.getCellRef().mLockLevel = 0;
|
target.getCellRef().mLockLevel = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -203,7 +203,7 @@ namespace MWMechanics
|
||||||
void inflict (const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
|
void inflict (const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
|
||||||
const ESM::EffectList& effects, ESM::RangeType range, bool reflected=false);
|
const ESM::EffectList& effects, ESM::RangeType range, bool reflected=false);
|
||||||
|
|
||||||
void applyInstantEffect (const MWWorld::Ptr& target, MWMechanics::EffectKey effect, float magnitude);
|
void applyInstantEffect (const MWWorld::Ptr& target, const MWWorld::Ptr& caster, MWMechanics::EffectKey effect, float magnitude);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,7 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
|
||||||
// Apply instant effects
|
// Apply instant effects
|
||||||
MWMechanics::CastSpell cast(actor, actor);
|
MWMechanics::CastSpell cast(actor, actor);
|
||||||
if (magnitude)
|
if (magnitude)
|
||||||
cast.applyInstantEffect(actor, effectIt->mEffectID, magnitude);
|
cast.applyInstantEffect(actor, actor, effectIt->mEffectID, magnitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magnitude)
|
if (magnitude)
|
||||||
|
|
Loading…
Reference in a new issue