|
|
|
@ -66,6 +66,35 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isOwned(const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim)
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::CellRef& cellref = target.getCellRef();
|
|
|
|
|
|
|
|
|
|
const std::string& owner = cellref.getOwner();
|
|
|
|
|
bool isOwned = !owner.empty() && owner != "player";
|
|
|
|
|
|
|
|
|
|
const std::string& faction = cellref.getFaction();
|
|
|
|
|
bool isFactionOwned = false;
|
|
|
|
|
if (!faction.empty() && ptr.getClass().isNpc())
|
|
|
|
|
{
|
|
|
|
|
const std::map<std::string, int>& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks();
|
|
|
|
|
auto found = factions.find(Misc::StringUtils::lowerCase(faction));
|
|
|
|
|
if (found == factions.end() || found->second < cellref.getFactionRank())
|
|
|
|
|
isFactionOwned = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& globalVariable = cellref.getGlobalVariable();
|
|
|
|
|
if (!globalVariable.empty() && MWBase::Environment::get().getWorld()->getGlobalInt(globalVariable))
|
|
|
|
|
{
|
|
|
|
|
isOwned = false;
|
|
|
|
|
isFactionOwned = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cellref.getOwner().empty())
|
|
|
|
|
victim = MWBase::Environment::get().getWorld()->searchPtr(cellref.getOwner(), true, false);
|
|
|
|
|
|
|
|
|
|
return isOwned || isFactionOwned;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
@ -881,35 +910,11 @@ namespace MWMechanics
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& owner = cellref.getOwner();
|
|
|
|
|
bool isOwned = !owner.empty() && owner != "player";
|
|
|
|
|
|
|
|
|
|
const std::string& faction = cellref.getFaction();
|
|
|
|
|
bool isFactionOwned = false;
|
|
|
|
|
if (!faction.empty() && ptr.getClass().isNpc())
|
|
|
|
|
{
|
|
|
|
|
const std::map<std::string, int>& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks();
|
|
|
|
|
std::map<std::string, int>::const_iterator found = factions.find(Misc::StringUtils::lowerCase(faction));
|
|
|
|
|
if (found == factions.end()
|
|
|
|
|
|| found->second < cellref.getFactionRank())
|
|
|
|
|
isFactionOwned = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& globalVariable = cellref.getGlobalVariable();
|
|
|
|
|
if (!globalVariable.empty() && MWBase::Environment::get().getWorld()->getGlobalInt(Misc::StringUtils::lowerCase(globalVariable)) == 1)
|
|
|
|
|
{
|
|
|
|
|
isOwned = false;
|
|
|
|
|
isFactionOwned = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cellref.getOwner().empty())
|
|
|
|
|
victim = MWBase::Environment::get().getWorld()->searchPtr(cellref.getOwner(), true, false);
|
|
|
|
|
|
|
|
|
|
// A special case for evidence chest - we should not allow to take items even if it is technically permitted
|
|
|
|
|
if (Misc::StringUtils::ciEqual(cellref.getRefId(), "stolen_goods"))
|
|
|
|
|
if (isOwned(ptr, target, victim))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return (!isOwned && !isFactionOwned);
|
|
|
|
|
// A special case for evidence chest - we should not allow to take items even if it is technically permitted
|
|
|
|
|
return !Misc::StringUtils::ciEqual(cellref.getRefId(), "stolen_goods");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MechanicsManager::sleepInBed(const MWWorld::Ptr &ptr, const MWWorld::Ptr &bed)
|
|
|
|
@ -941,9 +946,14 @@ namespace MWMechanics
|
|
|
|
|
void MechanicsManager::unlockAttempted(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr victim;
|
|
|
|
|
if (isAllowedToUse(ptr, item, victim))
|
|
|
|
|
return;
|
|
|
|
|
commitCrime(ptr, victim, OT_Trespassing, item.getCellRef().getFaction());
|
|
|
|
|
if (isOwned(ptr, item, victim))
|
|
|
|
|
{
|
|
|
|
|
// Note that attempting to unlock something that has ever been locked (even ESM::UnbreakableLock) is a crime even if it's already unlocked.
|
|
|
|
|
// Likewise, it's illegal to unlock something that has a trap but isn't otherwise locked.
|
|
|
|
|
const auto& cellref = item.getCellRef();
|
|
|
|
|
if(cellref.getLockLevel() || !cellref.getTrap().empty())
|
|
|
|
|
commitCrime(ptr, victim, OT_Trespassing, item.getCellRef().getFaction());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string, int> > MechanicsManager::getStolenItemOwners(const std::string& itemid)
|
|
|
|
|