mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-09 12:25:17 -04:00
cleanup
This commit is contained in:
parent
40e9b2d707
commit
e4f0723a90
@ -270,14 +270,14 @@ namespace MWClass
|
||||
|
||||
std::pair<int, std::string_view> Weapon::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
|
||||
{
|
||||
if (hasItemHealth(ptr) && getItemHealth(ptr) == 0)
|
||||
return { 0, "#{sInventoryMessage1}" };
|
||||
|
||||
// Do not allow equip weapons from inventory during attack
|
||||
if (npc.isInCell() && MWBase::Environment::get().getWindowManager()->isGuiMode()
|
||||
&& MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc))
|
||||
return { 0, "#{sCantEquipWeapWarning}" };
|
||||
|
||||
if (hasItemHealth(ptr) && getItemHealth(ptr) == 0)
|
||||
return { 0, "#{sInventoryMessage1}" };
|
||||
|
||||
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
|
||||
|
||||
if (slots_.first.empty())
|
||||
|
@ -522,18 +522,25 @@ namespace MWGui
|
||||
}
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
bool canUse = true;
|
||||
auto type = ptr.getType();
|
||||
bool isWeaponOrArmor = type == ESM::Weapon::sRecordId || type == ESM::Armor::sRecordId;
|
||||
bool isBroken = ptr.getClass().hasItemHealth(ptr) && ptr.getCellRef().getCharge() == 0;
|
||||
|
||||
// We don't want to set OnPcEquip for items that need to be equipped; but cannot be equipped;
|
||||
if (!ptr.getClass().getEquipmentSlots(ptr).first.empty()
|
||||
&& ptr.getClass().canBeEquipped(ptr, player).first == 0)
|
||||
canUse = force && ptr.getClass().hasItemHealth(ptr) && ptr.getCellRef().getCharge() != 0;
|
||||
// In vanilla, broken armor or weapons cannot be equipped
|
||||
// tools with 0 charges is equippable
|
||||
if (isBroken && isWeaponOrArmor)
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
||||
return;
|
||||
}
|
||||
|
||||
bool canEquip = ptr.getClass().canBeEquipped(ptr, mPtr).first != 0;
|
||||
bool shouldSetOnPcEquip = canEquip || force;
|
||||
|
||||
// If the item has a script, set OnPCEquip or PCSkipEquip to 1
|
||||
if (!script.empty() && canUse)
|
||||
if (!script.empty() && shouldSetOnPcEquip)
|
||||
{
|
||||
// Ingredients, books and repair hammers must not have OnPCEquip set to 1 here
|
||||
auto type = ptr.getType();
|
||||
bool isBook = type == ESM::Book::sRecordId;
|
||||
if (!isBook && type != ESM::Ingredient::sRecordId && type != ESM::Repair::sRecordId)
|
||||
ptr.getRefData().getLocals().setVarByInt(script, "onpcequip", 1);
|
||||
@ -543,25 +550,7 @@ namespace MWGui
|
||||
}
|
||||
|
||||
std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force);
|
||||
|
||||
action->execute(player, !canUse);
|
||||
|
||||
if (mDragAndDrop->mIsOnDragAndDrop && mDragAndDrop->mItem.mBase == ptr)
|
||||
{
|
||||
if (canUse)
|
||||
{
|
||||
mDragAndDrop->finish();
|
||||
// If item is ingredient or potion don't stop drag and drop
|
||||
if ((ptr.getType() == ESM::Potion::sRecordId || ptr.getType() == ESM::Ingredient::sRecordId)
|
||||
&& mDragAndDrop->mDraggedCount > 1)
|
||||
{
|
||||
mSelectedItem = getModel()->getIndex(mDragAndDrop->mItem);
|
||||
dragItem(nullptr, mDragAndDrop->mDraggedCount - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
mDragAndDrop->drop(mTradeModel, mItemView);
|
||||
}
|
||||
action->execute(player);
|
||||
|
||||
// Handles partial equipping (final part)
|
||||
if (mEquippedStackableCount.has_value())
|
||||
@ -592,6 +581,16 @@ namespace MWGui
|
||||
{
|
||||
MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase;
|
||||
|
||||
auto canEquip = ptr.getClass().canBeEquipped(ptr, mPtr);
|
||||
if (canEquip.first == 0) // cannot equip
|
||||
{
|
||||
mDragAndDrop->drop(mTradeModel, mItemView); // also plays down sound
|
||||
MWBase::Environment::get().getWindowManager()->messageBox(canEquip.second);
|
||||
return;
|
||||
}
|
||||
|
||||
mDragAndDrop->finish();
|
||||
|
||||
if (mDragAndDrop->mSourceModel != mTradeModel)
|
||||
{
|
||||
// Move item to the player's inventory
|
||||
@ -615,6 +614,17 @@ namespace MWGui
|
||||
}
|
||||
|
||||
MWBase::Environment::get().getLuaManager()->useItem(ptr, MWMechanics::getPlayer(), false);
|
||||
|
||||
// If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1
|
||||
// item
|
||||
if ((ptr.getType() == ESM::Potion::sRecordId || ptr.getType() == ESM::Ingredient::sRecordId)
|
||||
&& mDragAndDrop->mDraggedCount > 1)
|
||||
{
|
||||
// Item can be provided from other window for example container.
|
||||
// But after DragAndDrop::startDrag item automaticly always gets to player inventory.
|
||||
mSelectedItem = getModel()->getIndex(mDragAndDrop->mItem);
|
||||
dragItem(nullptr, mDragAndDrop->mDraggedCount - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -395,11 +395,10 @@ namespace MWGui
|
||||
if (!equipmentSlots.empty())
|
||||
{
|
||||
const auto& itSlot = store.getSlot(equipmentSlots.front());
|
||||
// Morrowind.exe behaviour:
|
||||
// Only display item broken message if;
|
||||
// no item in the to-be-equipped slot
|
||||
// or broken quickkey item and currently equipped item id is different
|
||||
// It doesn't find a replacement
|
||||
// Morrowind.exe behavior:
|
||||
// Only display the "item is broken" message if:
|
||||
// - There is no item in the target equipment slot, or
|
||||
// - The quickkey item is broken and the currently equipped item has a different ID
|
||||
if (itSlot == store.end() || (item.getCellRef().getRefId() != itSlot->getCellRef().getRefId()))
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
||||
}
|
||||
|
@ -21,12 +21,11 @@ namespace MWWorld
|
||||
MWWorld::Ptr object = getTarget();
|
||||
MWWorld::InventoryStore& invStore = actor.getClass().getInventoryStore(actor);
|
||||
|
||||
if (object.getClass().hasItemHealth(object) && object.getCellRef().getCharge() == 0)
|
||||
if (actor != MWMechanics::getPlayer())
|
||||
{
|
||||
if (actor == MWMechanics::getPlayer())
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
||||
|
||||
return;
|
||||
// player logic is handled in InventoryWindow::useItem
|
||||
if (object.getClass().hasItemHealth(object) && object.getCellRef().getCharge() == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mForce)
|
||||
|
Loading…
x
Reference in New Issue
Block a user