mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-01 06:34:31 +00:00
Merge branch 'maluu-apa-bosku' into 'master'
Play down sound when equip fails Closes #7371 See merge request OpenMW/openmw!4248
This commit is contained in:
commit
3e711c30db
6 changed files with 46 additions and 47 deletions
|
|
@ -270,14 +270,14 @@ namespace MWClass
|
||||||
|
|
||||||
std::pair<int, std::string_view> Weapon::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
|
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
|
// Do not allow equip weapons from inventory during attack
|
||||||
if (npc.isInCell() && MWBase::Environment::get().getWindowManager()->isGuiMode()
|
if (npc.isInCell() && MWBase::Environment::get().getWindowManager()->isGuiMode()
|
||||||
&& MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc))
|
&& MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc))
|
||||||
return { 0, "#{sCantEquipWeapWarning}" };
|
return { 0, "#{sCantEquipWeapWarning}" };
|
||||||
|
|
||||||
|
if (hasItemHealth(ptr) && getItemHealth(ptr) == 0)
|
||||||
|
return { 0, "#{sInventoryMessage1}" };
|
||||||
|
|
||||||
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
|
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
|
||||||
|
|
||||||
if (slots_.first.empty())
|
if (slots_.first.empty())
|
||||||
|
|
|
||||||
|
|
@ -522,36 +522,25 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||||
|
auto type = ptr.getType();
|
||||||
|
bool isWeaponOrArmor = type == ESM::Weapon::sRecordId || type == ESM::Armor::sRecordId;
|
||||||
|
bool isBroken = ptr.getClass().hasItemHealth(ptr) && ptr.getCellRef().getCharge() == 0;
|
||||||
|
|
||||||
// early-out for items that need to be equipped, but can't be equipped: we don't want to set OnPcEquip in that
|
// In vanilla, broken armor or weapons cannot be equipped
|
||||||
// case
|
// tools with 0 charges is equippable
|
||||||
if (!ptr.getClass().getEquipmentSlots(ptr).first.empty())
|
if (isBroken && isWeaponOrArmor)
|
||||||
{
|
{
|
||||||
if (ptr.getClass().hasItemHealth(ptr) && ptr.getCellRef().getCharge() == 0)
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
||||||
{
|
return;
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
|
||||||
updateItemView();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!force)
|
|
||||||
{
|
|
||||||
auto canEquip = ptr.getClass().canBeEquipped(ptr, player);
|
|
||||||
|
|
||||||
if (canEquip.first == 0)
|
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox(canEquip.second);
|
|
||||||
updateItemView();
|
|
||||||
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 the item has a script, set OnPCEquip or PCSkipEquip to 1
|
||||||
if (!script.empty())
|
if (!script.empty() && shouldSetOnPcEquip)
|
||||||
{
|
{
|
||||||
// Ingredients, books and repair hammers must not have OnPCEquip set to 1 here
|
// Ingredients, books and repair hammers must not have OnPCEquip set to 1 here
|
||||||
auto type = ptr.getType();
|
|
||||||
bool isBook = type == ESM::Book::sRecordId;
|
bool isBook = type == ESM::Book::sRecordId;
|
||||||
if (!isBook && type != ESM::Ingredient::sRecordId && type != ESM::Repair::sRecordId)
|
if (!isBook && type != ESM::Ingredient::sRecordId && type != ESM::Repair::sRecordId)
|
||||||
ptr.getRefData().getLocals().setVarByInt(script, "onpcequip", 1);
|
ptr.getRefData().getLocals().setVarByInt(script, "onpcequip", 1);
|
||||||
|
|
@ -561,7 +550,7 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force);
|
std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force);
|
||||||
action->execute(player);
|
action->execute(player, !canEquip);
|
||||||
|
|
||||||
// Handles partial equipping (final part)
|
// Handles partial equipping (final part)
|
||||||
if (mEquippedStackableCount.has_value())
|
if (mEquippedStackableCount.has_value())
|
||||||
|
|
@ -592,6 +581,14 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase;
|
MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase;
|
||||||
|
|
||||||
|
auto [canEquipRes, canEquipMsg] = ptr.getClass().canBeEquipped(ptr, mPtr);
|
||||||
|
if (canEquipRes == 0) // cannot equip
|
||||||
|
{
|
||||||
|
mDragAndDrop->drop(mTradeModel, mItemView); // also plays down sound
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox(canEquipMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mDragAndDrop->finish();
|
mDragAndDrop->finish();
|
||||||
|
|
||||||
if (mDragAndDrop->mSourceModel != mTradeModel)
|
if (mDragAndDrop->mSourceModel != mTradeModel)
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,8 @@ namespace MWGui
|
||||||
case ESM::QuickKeys::Type::MagicItem:
|
case ESM::QuickKeys::Type::MagicItem:
|
||||||
{
|
{
|
||||||
MWWorld::Ptr item = *mKey[index].button->getUserData<MWWorld::Ptr>();
|
MWWorld::Ptr item = *mKey[index].button->getUserData<MWWorld::Ptr>();
|
||||||
// Make sure the item is available and is not broken
|
// Make sure the item is available
|
||||||
if (item.isEmpty() || item.getCellRef().getCount() < 1
|
if (item.isEmpty() || item.getCellRef().getCount() < 1)
|
||||||
|| (item.getClass().hasItemHealth(item) && item.getClass().getItemHealth(item) <= 0))
|
|
||||||
{
|
{
|
||||||
// Try searching for a compatible replacement
|
// Try searching for a compatible replacement
|
||||||
item = store.findReplacement(mKey[index].id);
|
item = store.findReplacement(mKey[index].id);
|
||||||
|
|
@ -384,23 +383,16 @@ namespace MWGui
|
||||||
if (it == store.end())
|
if (it == store.end())
|
||||||
item = nullptr;
|
item = nullptr;
|
||||||
|
|
||||||
// check the item is available and not broken
|
// check the quickkey item is available
|
||||||
if (item.isEmpty() || item.getCellRef().getCount() < 1
|
if (item.isEmpty() || item.getCellRef().getCount() < 1)
|
||||||
|| (item.getClass().hasItemHealth(item) && item.getClass().getItemHealth(item) <= 0))
|
|
||||||
{
|
{
|
||||||
item = store.findReplacement(key->id);
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sQuickMenu5} " + key->name);
|
||||||
|
return;
|
||||||
if (item.isEmpty() || item.getCellRef().getCount() < 1)
|
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sQuickMenu5} " + key->name);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key->type == ESM::QuickKeys::Type::Item)
|
if (key->type == ESM::QuickKeys::Type::Item)
|
||||||
{
|
{
|
||||||
if (!store.isEquipped(item))
|
if (!store.isEquipped(item.getCellRef().getRefId()))
|
||||||
MWBase::Environment::get().getWindowManager()->useItem(item);
|
MWBase::Environment::get().getWindowManager()->useItem(item);
|
||||||
MWWorld::ConstContainerStoreIterator rightHand
|
MWWorld::ConstContainerStoreIterator rightHand
|
||||||
= store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
= store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,11 @@ namespace MWWorld
|
||||||
MWWorld::Ptr object = getTarget();
|
MWWorld::Ptr object = getTarget();
|
||||||
MWWorld::InventoryStore& invStore = actor.getClass().getInventoryStore(actor);
|
MWWorld::InventoryStore& invStore = actor.getClass().getInventoryStore(actor);
|
||||||
|
|
||||||
if (object.getClass().hasItemHealth(object) && object.getCellRef().getCharge() == 0)
|
if (actor != MWMechanics::getPlayer())
|
||||||
{
|
{
|
||||||
if (actor == MWMechanics::getPlayer())
|
// player logic is handled in InventoryWindow::useItem
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}");
|
if (object.getClass().hasItemHealth(object) && object.getCellRef().getCharge() == 0)
|
||||||
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mForce)
|
if (!mForce)
|
||||||
|
|
|
||||||
|
|
@ -732,6 +732,16 @@ bool MWWorld::InventoryStore::isEquipped(const MWWorld::ConstPtr& item)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MWWorld::InventoryStore::isEquipped(const ESM::RefId& id)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MWWorld::InventoryStore::Slots; ++i)
|
||||||
|
{
|
||||||
|
if (getSlot(i) != end() && getSlot(i)->getCellRef().getRefId() == id)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool MWWorld::InventoryStore::isFirstEquip()
|
bool MWWorld::InventoryStore::isFirstEquip()
|
||||||
{
|
{
|
||||||
bool first = mFirstAutoEquip;
|
bool first = mFirstAutoEquip;
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ namespace MWWorld
|
||||||
///< \warning \a iterator can not be an end()-iterator, use unequip function instead
|
///< \warning \a iterator can not be an end()-iterator, use unequip function instead
|
||||||
|
|
||||||
bool isEquipped(const MWWorld::ConstPtr& item);
|
bool isEquipped(const MWWorld::ConstPtr& item);
|
||||||
|
bool isEquipped(const ESM::RefId& id);
|
||||||
///< Utility function, returns true if the given item is equipped in any slot
|
///< Utility function, returns true if the given item is equipped in any slot
|
||||||
|
|
||||||
void setSelectedEnchantItem(const ContainerStoreIterator& iterator);
|
void setSelectedEnchantItem(const ContainerStoreIterator& iterator);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue