forked from teamnwah/openmw-tes3coop
Bugfix #691 changes
This commit is contained in:
parent
194ca2584d
commit
7c22e123f4
10 changed files with 53 additions and 79 deletions
|
@ -292,25 +292,13 @@ namespace MWClass
|
|||
ref->mBase = record;
|
||||
}
|
||||
|
||||
bool Armor::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
int Armor::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
{
|
||||
MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc);
|
||||
|
||||
// slots that this item can be equipped in
|
||||
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item);
|
||||
|
||||
// retrieve ContainerStoreIterator to the item
|
||||
MWWorld::ContainerStoreIterator it = invStore.begin();
|
||||
for (; it != invStore.end(); ++it)
|
||||
{
|
||||
if (*it == item)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(it != invStore.end());
|
||||
|
||||
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
|
||||
|
||||
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
||||
|
@ -321,7 +309,7 @@ namespace MWClass
|
|||
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);
|
||||
if(race->mData.mFlags & ESM::Race::Beast)
|
||||
{
|
||||
std::vector<ESM::PartReference> parts = it->get<ESM::Armor>()->mBase->mParts.mParts;
|
||||
std::vector<ESM::PartReference> parts = item.get<ESM::Armor>()->mBase->mParts.mParts;
|
||||
|
||||
if(*slot == MWWorld::InventoryStore::Slot_Helmet)
|
||||
{
|
||||
|
@ -332,7 +320,7 @@ namespace MWClass
|
|||
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
||||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}");
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +333,7 @@ namespace MWClass
|
|||
{
|
||||
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
||||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage14}");
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -363,13 +351,12 @@ namespace MWClass
|
|||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
|
||||
{
|
||||
//unequip twohanded item
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
|
||||
return 3;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -67,7 +67,8 @@ namespace MWClass
|
|||
|
||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
|
||||
virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||
|
||||
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
|
||||
const;
|
||||
|
|
|
@ -238,25 +238,11 @@ namespace MWClass
|
|||
ref->mBase = record;
|
||||
}
|
||||
|
||||
bool Clothing::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
int Clothing::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
{
|
||||
MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc);
|
||||
|
||||
// slots that this item can be equipped in
|
||||
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item);
|
||||
|
||||
// retrieve ContainerStoreIterator to the item
|
||||
MWWorld::ContainerStoreIterator it = invStore.begin();
|
||||
for (; it != invStore.end(); ++it)
|
||||
{
|
||||
if (*it == item)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(it != invStore.end());
|
||||
|
||||
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
|
||||
|
||||
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
||||
|
@ -267,7 +253,7 @@ namespace MWClass
|
|||
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);
|
||||
if(race->mData.mFlags & ESM::Race::Beast)
|
||||
{
|
||||
std::vector<ESM::PartReference> parts = it->get<ESM::Clothing>()->mBase->mParts.mParts;
|
||||
std::vector<ESM::PartReference> parts = item.get<ESM::Clothing>()->mBase->mParts.mParts;
|
||||
|
||||
if(*slot == MWWorld::InventoryStore::Slot_Helmet)
|
||||
{
|
||||
|
@ -278,7 +264,7 @@ namespace MWClass
|
|||
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
||||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}");
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,13 +280,13 @@ namespace MWClass
|
|||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage15}");
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -61,7 +61,8 @@ namespace MWClass
|
|||
|
||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
|
||||
virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||
|
||||
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
|
||||
const;
|
||||
|
|
|
@ -384,48 +384,30 @@ namespace MWClass
|
|||
ref->mBase = record;
|
||||
}
|
||||
|
||||
bool Weapon::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
int Weapon::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
{
|
||||
MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc);
|
||||
|
||||
// slots that this item can be equipped in
|
||||
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(item).getEquipmentSlots(item);
|
||||
|
||||
// retrieve ContainerStoreIterator to the item
|
||||
MWWorld::ContainerStoreIterator it = invStore.begin();
|
||||
for (; it != invStore.end(); ++it)
|
||||
{
|
||||
if (*it == item)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(it != invStore.end());
|
||||
|
||||
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
|
||||
|
||||
// equip the item in the first free slot
|
||||
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
||||
slot!=slots.first.end(); ++slot)
|
||||
{
|
||||
if(*slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
||||
{
|
||||
if(it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
|
||||
it->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
|
||||
if(item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
|
||||
item.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
|
||||
{
|
||||
//unequip lefthand item
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
|
||||
return 2;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -67,7 +67,8 @@ namespace MWClass
|
|||
|
||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
|
||||
virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||
|
||||
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
|
||||
const;
|
||||
|
|
|
@ -43,8 +43,15 @@ namespace MWWorld
|
|||
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
||||
slot!=slots.first.end(); ++slot)
|
||||
{
|
||||
if(!MWWorld::Class::get(getTarget()).canEquip(actor,getTarget()))
|
||||
break;
|
||||
switch(MWWorld::Class::get (*it).canBeEquipped (actor, *it))
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case 2:
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
|
||||
case 3:
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
|
||||
}
|
||||
|
||||
// if all slots are occupied, replace the last slot
|
||||
if (slot == --slots.first.end())
|
||||
|
|
|
@ -259,9 +259,9 @@ namespace MWWorld
|
|||
throw std::runtime_error ("class can't be enchanted");
|
||||
}
|
||||
|
||||
bool Class::canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
int Class::canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const
|
||||
{
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Class::adjustPosition(const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -242,8 +242,8 @@ namespace MWWorld
|
|||
|
||||
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
|
||||
virtual bool canEquip(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
///< Return 0 if player cannot equip item. Unequip twohanded item if neccesary
|
||||
virtual int canBeEquipped(const MWWorld::Ptr &npc, const MWWorld::Ptr &item) const;
|
||||
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
|
||||
|
||||
virtual Ptr
|
||||
copyToCell(const Ptr &ptr, CellStore &cell) const;
|
||||
|
|
|
@ -131,6 +131,8 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
|||
void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc)
|
||||
{
|
||||
const MWMechanics::NpcStats& stats = MWWorld::Class::get(npc).getNpcStats(npc);
|
||||
MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc);
|
||||
|
||||
TSlots slots;
|
||||
initSlots (slots);
|
||||
|
||||
|
@ -184,8 +186,15 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc)
|
|||
}
|
||||
}
|
||||
|
||||
if(!MWWorld::Class::get (test).canEquip (npc, test))
|
||||
switch(MWWorld::Class::get (test).canBeEquipped (npc, test))
|
||||
{
|
||||
case 0:
|
||||
continue;
|
||||
case 2:
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
|
||||
case 3:
|
||||
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
|
||||
}
|
||||
|
||||
if (!itemsSlots.second) // if itemsSlots.second is true, item can stay stacked when equipped
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue