2013-05-19 16:40:37 +00:00
|
|
|
#include "security.hpp"
|
|
|
|
|
2016-10-24 08:43:27 +00:00
|
|
|
#include "../mwmp/Main.hpp"
|
2016-12-16 08:59:15 +00:00
|
|
|
#include "../mwmp/Networking.hpp"
|
2017-02-06 15:40:32 +00:00
|
|
|
#include "../mwmp/WorldEvent.hpp"
|
2016-10-24 08:43:27 +00:00
|
|
|
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
#include <components/misc/rng.hpp>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2013-05-19 16:40:37 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2013-08-12 23:19:33 +00:00
|
|
|
#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
|
|
|
{
|
2014-05-22 18:37:22 +00:00
|
|
|
CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor);
|
|
|
|
NpcStats& npcStats = actor.getClass().getNpcStats(actor);
|
2015-03-08 04:42:07 +00:00
|
|
|
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
|
|
|
{
|
2015-08-04 15:33:34 +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;
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
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();
|
|
|
|
|
2015-03-08 04:42:07 +00:00
|
|
|
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
|
|
|
{
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_OBJECT_UNLOCK packet every time an object is unlocked
|
|
|
|
*/
|
2017-02-23 07:18:48 +00:00
|
|
|
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent();
|
|
|
|
worldEvent->cell = *lock.getCell()->getCell();
|
2017-01-28 10:34:45 +00:00
|
|
|
|
|
|
|
mwmp::WorldObject worldObject;
|
|
|
|
worldObject.refId = lock.getCellRef().getRefId();
|
|
|
|
worldObject.refNumIndex = lock.getCellRef().getRefNum().mIndex;
|
2017-04-04 08:07:16 +00:00
|
|
|
worldObject.mpNum = lock.getCellRef().getMpNum();
|
2017-02-23 07:18:48 +00:00
|
|
|
worldEvent->addObject(worldObject);
|
2017-03-06 09:44:08 +00:00
|
|
|
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->setEvent(worldEvent);
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send();
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-10-24 08:43:27 +00:00
|
|
|
|
2014-05-22 18:37:22 +00:00
|
|
|
lock.getClass().unlock(lock);
|
2013-05-19 17:48:51 +00:00
|
|
|
resultMessage = "#{sLockSuccess}";
|
|
|
|
resultSound = "Open Lock";
|
2014-05-22 18:37:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
int uses = lockpick.getClass().getItemHealth(lockpick);
|
|
|
|
--uses;
|
|
|
|
lockpick.getCellRef().setCharge(uses);
|
|
|
|
if (!uses)
|
2013-08-12 23:19:33 +00:00
|
|
|
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
|
|
|
{
|
2014-05-25 12:13:07 +00:00
|
|
|
if (trap.getCellRef().getTrap() == "")
|
2013-05-19 16:40:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
float probeQuality = probe.get<ESM::Probe>()->mBase->mData.mQuality;
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(trap.getCellRef().getTrap());
|
2015-03-08 04:42:07 +00:00
|
|
|
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();
|
|
|
|
|
2015-03-08 04:42:07 +00:00
|
|
|
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
|
|
|
{
|
2014-05-25 12:13:07 +00:00
|
|
|
trap.getCellRef().setTrap("");
|
2013-05-19 17:48:51 +00:00
|
|
|
|
|
|
|
resultSound = "Disarm Trap";
|
|
|
|
resultMessage = "#{sTrapSuccess}";
|
2014-05-22 18:37:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
int uses = probe.getClass().getItemHealth(probe);
|
|
|
|
--uses;
|
|
|
|
probe.getCellRef().setCharge(uses);
|
|
|
|
if (!uses)
|
2013-08-12 23:19:33 +00:00
|
|
|
probe.getContainerStore()->remove(probe, 1, mActor);
|
2013-05-19 16:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|