You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwworld/actionequip.cpp

84 lines
2.6 KiB
C++

#include "actionequip.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include <components/compiler/locals.hpp>
#include "inventorystore.hpp"
#include "player.hpp"
#include "class.hpp"
namespace MWWorld
{
ActionEquip::ActionEquip (const MWWorld::Ptr& object) : Action (false, object)
{
}
void ActionEquip::executeImp (const Ptr& actor)
{
12 years ago
MWWorld::Ptr object = getTarget();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
// slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget());
// retrieve ContainerStoreIterator to the item
MWWorld::ContainerStoreIterator it = invStore.begin();
for (; it != invStore.end(); ++it)
{
12 years ago
if (*it == object)
{
break;
}
}
assert(it != invStore.end());
12 years ago
std::string npcRace = actor.get<ESM::NPC>()->mBase->mRace;
bool equipped = false;
12 years ago
switch(MWWorld::Class::get (object).canBeEquipped (actor, object))
{
case 0:
12 years ago
return;
12 years ago
case 2:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
12 years ago
break;
12 years ago
case 3:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
12 years ago
break;
12 years ago
}
// equip the item in the first free slot
for (std::vector<int>::const_iterator slot=slots.first.begin();
slot!=slots.first.end(); ++slot)
{
12 years ago
// if all slots are occupied, replace the last slot
if (slot == --slots.first.end())
{
invStore.equip(*slot, it);
equipped = true;
break;
}
if (invStore.getSlot(*slot) == invStore.end())
{
// slot is not occupied
invStore.equip(*slot, it);
equipped = true;
break;
}
}
12 years ago
std::string script = MWWorld::Class::get(object).getScript(object);
/* 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 != "")
12 years ago
(object).mRefData->getLocals().setVarByInt(script, "onpcequip", 1);
}
}