1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 19:49:54 +00:00
openmw-tes3mp/apps/openmw/mwworld/actionequip.cpp
scrawl 7983b07b10 Get bk_treasuryreport script to work properly:
- OnPcEquip needs to be set on *using* any item, not just equipping
 - Handle PcSkipEquip
 - Execute item's script once immediately after setting OnPcEquip
 - Do not set OnPcEquip when an item that has skipped equipping sets pcskipequip back to 0 and gets equipped
2014-01-13 06:20:18 +01:00

84 lines
2.5 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)
{
MWWorld::Ptr object = getTarget();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
std::pair <int, std::string> result = MWWorld::Class::get (object).canBeEquipped (object, actor);
// display error message if the player tried to equip something
if (!result.second.empty() && actor == MWBase::Environment::get().getWorld()->getPlayerPtr())
MWBase::Environment::get().getWindowManager()->messageBox(result.second);
switch(result.first)
{
case 0:
return;
case 2:
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedLeft, actor);
break;
case 3:
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, actor);
break;
}
// 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)
{
if (*it == object)
{
break;
}
}
assert(it != invStore.end());
bool equipped = false;
// equip the item in the first free slot
for (std::vector<int>::const_iterator slot=slots_.first.begin();
slot!=slots_.first.end(); ++slot)
{
// if the item is equipped already, nothing to do
if (invStore.getSlot(*slot) == it)
return;
// if all slots are occupied, replace the last slot
if (slot == --slots_.first.end())
{
invStore.equip(*slot, it, actor);
equipped = true;
break;
}
if (invStore.getSlot(*slot) == invStore.end())
{
// slot is not occupied
invStore.equip(*slot, it, actor);
equipped = true;
break;
}
}
}
}