2012-05-16 14:08:55 +00:00
|
|
|
#include "actionequip.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2013-01-09 03:03:14 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2013-01-31 00:34:16 +00:00
|
|
|
#include <components/compiler/locals.hpp>
|
2012-07-03 10:30:50 +00:00
|
|
|
|
|
|
|
#include "inventorystore.hpp"
|
|
|
|
#include "player.hpp"
|
|
|
|
#include "class.hpp"
|
2012-05-16 14:08:55 +00:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
2012-09-04 13:27:10 +00:00
|
|
|
ActionEquip::ActionEquip (const MWWorld::Ptr& object) : Action (false, object)
|
2012-05-16 14:08:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:00:10 +00:00
|
|
|
void ActionEquip::executeImp (const Ptr& actor)
|
2012-05-16 14:08:55 +00:00
|
|
|
{
|
2013-01-09 02:16:17 +00:00
|
|
|
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
|
2012-05-16 14:08:55 +00:00
|
|
|
|
|
|
|
// slots that this item can be equipped in
|
2012-09-04 13:27:10 +00:00
|
|
|
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget());
|
2012-05-16 14:08:55 +00:00
|
|
|
|
|
|
|
// retrieve ContainerStoreIterator to the item
|
|
|
|
MWWorld::ContainerStoreIterator it = invStore.begin();
|
|
|
|
for (; it != invStore.end(); ++it)
|
|
|
|
{
|
2012-09-04 13:27:10 +00:00
|
|
|
if (*it == getTarget())
|
2012-05-16 14:08:55 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(it != invStore.end());
|
2013-02-02 12:24:28 +00:00
|
|
|
|
2013-01-09 03:03:14 +00:00
|
|
|
std::string npcRace = actor.get<ESM::NPC>()->mBase->mRace;
|
2012-05-16 14:08:55 +00:00
|
|
|
|
2013-01-31 00:34:16 +00:00
|
|
|
bool equipped = false;
|
|
|
|
|
2012-05-16 14:08:55 +00:00
|
|
|
// equip the item in the first free slot
|
|
|
|
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
|
|
|
slot!=slots.first.end(); ++slot)
|
|
|
|
{
|
2013-01-09 03:03:14 +00:00
|
|
|
|
2013-01-09 13:27:12 +00:00
|
|
|
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
|
2013-03-12 01:09:54 +00:00
|
|
|
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);
|
|
|
|
if(race->mData.mFlags & ESM::Race::Beast)
|
2013-01-09 03:03:14 +00:00
|
|
|
{
|
2013-03-12 01:02:59 +00:00
|
|
|
if(*slot == MWWorld::InventoryStore::Slot_Helmet)
|
|
|
|
{
|
2013-01-09 13:18:05 +00:00
|
|
|
std::vector<ESM::PartReference> parts;
|
|
|
|
if(it.getType() == MWWorld::ContainerStore::Type_Clothing)
|
|
|
|
parts = it->get<ESM::Clothing>()->mBase->mParts.mParts;
|
|
|
|
else
|
|
|
|
parts = it->get<ESM::Armor>()->mBase->mParts.mParts;
|
|
|
|
|
|
|
|
bool allow = true;
|
|
|
|
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
|
|
|
|
{
|
2013-02-02 12:24:28 +00:00
|
|
|
if((*itr).mPart == ESM::PRT_Head)
|
2013-01-09 13:18:05 +00:00
|
|
|
{
|
2013-01-09 13:27:12 +00:00
|
|
|
if(actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}", std::vector<std::string>());
|
2013-02-02 12:24:28 +00:00
|
|
|
|
2013-01-09 13:18:05 +00:00
|
|
|
allow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-02 12:24:28 +00:00
|
|
|
|
2013-01-09 13:18:05 +00:00
|
|
|
if(!allow)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-09 03:03:14 +00:00
|
|
|
if (*slot == MWWorld::InventoryStore::Slot_Boots)
|
2013-02-02 12:24:28 +00:00
|
|
|
{
|
2013-03-12 01:02:59 +00:00
|
|
|
bool allow = true;
|
|
|
|
std::vector<ESM::PartReference> parts;
|
|
|
|
if(it.getType() == MWWorld::ContainerStore::Type_Clothing)
|
|
|
|
parts = it->get<ESM::Clothing>()->mBase->mParts.mParts;
|
|
|
|
else
|
|
|
|
parts = it->get<ESM::Armor>()->mBase->mParts.mParts;
|
|
|
|
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
|
2013-01-09 13:18:05 +00:00
|
|
|
{
|
2013-03-12 01:02:59 +00:00
|
|
|
if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot)
|
2013-01-09 03:03:14 +00:00
|
|
|
{
|
2013-03-12 01:02:59 +00:00
|
|
|
allow = false;
|
|
|
|
// Only notify the player, not npcs
|
|
|
|
if(actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
|
|
|
{
|
|
|
|
if(it.getType() == MWWorld::ContainerStore::Type_Clothing){ // It's shoes
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage15}", std::vector<std::string>());
|
|
|
|
}
|
|
|
|
|
|
|
|
else // It's boots
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage14}", std::vector<std::string>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-01-09 03:03:14 +00:00
|
|
|
}
|
2013-01-09 13:18:05 +00:00
|
|
|
}
|
2013-03-12 01:02:59 +00:00
|
|
|
|
|
|
|
if(!allow)
|
|
|
|
break;
|
2013-01-09 03:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-16 14:08:55 +00:00
|
|
|
// if all slots are occupied, replace the last slot
|
|
|
|
if (slot == --slots.first.end())
|
|
|
|
{
|
|
|
|
invStore.equip(*slot, it);
|
2013-01-31 00:34:16 +00:00
|
|
|
equipped = true;
|
2012-05-16 14:08:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invStore.getSlot(*slot) == invStore.end())
|
|
|
|
{
|
|
|
|
// slot is not occupied
|
|
|
|
invStore.equip(*slot, it);
|
2013-01-31 00:34:16 +00:00
|
|
|
equipped = true;
|
2012-05-16 14:08:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-31 00:34:16 +00:00
|
|
|
|
2013-01-31 17:46:16 +00:00
|
|
|
std::string script = MWWorld::Class::get(*it).getScript(*it);
|
|
|
|
|
|
|
|
/* Set OnPCEquip Variable on item's script, if the player is equipping it, and it has a script with that variable declared */
|
|
|
|
if(equipped && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && script != "")
|
2013-02-03 13:27:27 +00:00
|
|
|
(*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 1);
|
2012-05-16 14:08:55 +00:00
|
|
|
}
|
|
|
|
}
|