1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 21:19:57 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/security.cpp

133 lines
4.8 KiB
C++
Raw Normal View History

2013-05-19 16:40:37 +00:00
#include "security.hpp"
#include "../mwmp/Main.hpp"
2016-12-16 08:59:15 +00:00
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/cellstore.hpp"
2015-04-22 15:58:55 +00:00
#include <components/misc/rng.hpp>
2013-05-19 16:40:37 +00:00
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/esmstore.hpp"
2013-05-19 16:40:37 +00:00
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
2014-01-10 20:26:24 +00:00
#include "../mwbase/mechanicsmanager.hpp"
2013-05-19 16:40:37 +00:00
#include "npcstats.hpp"
#include "creaturestats.hpp"
namespace MWMechanics
{
2013-05-19 21:19:48 +00:00
Security::Security(const MWWorld::Ptr &actor)
2013-05-20 10:42:11 +00:00
: mActor(actor)
2013-05-19 21:19:48 +00:00
{
CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor);
NpcStats& npcStats = actor.getClass().getNpcStats(actor);
mAgility = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Agility).getModified());
mLuck = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Luck).getModified());
mSecuritySkill = static_cast<float>(npcStats.getSkill(ESM::Skill::Security).getModified());
2013-05-19 21:19:48 +00:00
mFatigueTerm = creatureStats.getFatigueTerm();
}
void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick,
2013-05-19 17:48:51 +00:00
std::string& resultMessage, std::string& resultSound)
2013-05-19 16:40:37 +00:00
{
if (!(lock.getCellRef().getLockLevel() > 0) || !lock.getClass().canLock(lock)) //If it's unlocked back out immediately
2013-05-19 16:40:37 +00:00
return;
int lockStrength = lock.getCellRef().getLockLevel();
2013-05-19 16:40:37 +00:00
float pickQuality = lockpick.get<ESM::Lockpick>()->mBase->mData.mQuality;
float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPickLockMult")->getFloat();
float x = 0.2f * mAgility + 0.1f * mLuck + mSecuritySkill;
2013-05-19 21:19:48 +00:00
x *= pickQuality * mFatigueTerm;
2013-05-19 16:40:37 +00:00
x += fPickLockMult * lockStrength;
2013-05-19 17:48:51 +00:00
resultSound = "Open Lock Fail";
2013-05-19 16:40:37 +00:00
if (x <= 0)
2013-05-19 17:48:51 +00:00
resultMessage = "#{sLockImpossible}";
2013-05-19 16:40:37 +00:00
else
{
2014-01-10 20:26:24 +00:00
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, lock);
2015-04-22 15:58:55 +00:00
if (Misc::Rng::roll0to99() <= x)
2013-05-19 16:40:37 +00:00
{
// Added by tes3mp
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *lock.getCell()->getCell();
mwmp::WorldObject worldObject;
worldObject.refId = lock.getCellRef().getRefId();
worldObject.refNumIndex = lock.getCellRef().getRefNum().mIndex;
event->addObject(worldObject);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(event);
delete event;
event = nullptr;
lock.getClass().unlock(lock);
2013-05-19 17:48:51 +00:00
resultMessage = "#{sLockSuccess}";
resultSound = "Open Lock";
mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, 1);
2013-05-19 16:40:37 +00:00
}
2013-05-19 17:48:51 +00:00
else
resultMessage = "#{sLockFail}";
2013-05-19 16:40:37 +00:00
}
int uses = lockpick.getClass().getItemHealth(lockpick);
--uses;
lockpick.getCellRef().setCharge(uses);
if (!uses)
lockpick.getContainerStore()->remove(lockpick, 1, mActor);
2013-05-19 16:40:37 +00:00
}
2013-05-19 21:19:48 +00:00
void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe,
2013-05-19 17:48:51 +00:00
std::string& resultMessage, std::string& resultSound)
2013-05-19 16:40:37 +00:00
{
if (trap.getCellRef().getTrap() == "")
2013-05-19 16:40:37 +00:00
return;
float probeQuality = probe.get<ESM::Probe>()->mBase->mData.mQuality;
const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(trap.getCellRef().getTrap());
int trapSpellPoints = trapSpell->mData.mCost;
2013-05-19 16:40:37 +00:00
float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTrapCostMult")->getFloat();
float x = 0.2f * mAgility + 0.1f * mLuck + mSecuritySkill;
2013-05-19 16:40:37 +00:00
x += fTrapCostMult * trapSpellPoints;
2013-05-19 21:19:48 +00:00
x *= probeQuality * mFatigueTerm;
2013-05-19 16:40:37 +00:00
2013-05-19 17:48:51 +00:00
resultSound = "Disarm Trap Fail";
2013-05-19 16:40:37 +00:00
if (x <= 0)
2013-05-19 17:48:51 +00:00
resultMessage = "#{sTrapImpossible}";
2013-05-19 16:40:37 +00:00
else
{
2014-01-10 20:26:24 +00:00
MWBase::Environment::get().getMechanicsManager()->objectOpened(mActor, trap);
2015-04-22 15:58:55 +00:00
if (Misc::Rng::roll0to99() <= x)
2013-05-19 16:40:37 +00:00
{
trap.getCellRef().setTrap("");
2013-05-19 17:48:51 +00:00
resultSound = "Disarm Trap";
resultMessage = "#{sTrapSuccess}";
mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, 0);
2013-05-19 16:40:37 +00:00
}
2013-05-19 17:48:51 +00:00
else
resultMessage = "#{sTrapFail}";
2013-05-19 16:40:37 +00:00
}
int uses = probe.getClass().getItemHealth(probe);
--uses;
probe.getCellRef().setCharge(uses);
if (!uses)
probe.getContainerStore()->remove(probe, 1, mActor);
2013-05-19 16:40:37 +00:00
}
}