mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Merge branch 'delicious_souls' into 'master'
Unify soulgem check See merge request OpenMW/openmw!2339
This commit is contained in:
commit
da2a72599f
@ -143,7 +143,7 @@ namespace MWClass
|
||||
countString = " (" + std::to_string(count) + ")";
|
||||
|
||||
std::string_view name = getName(ptr);
|
||||
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
|
||||
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count) + MWGui::ToolTips::getSoulString(ptr.getCellRef());
|
||||
info.icon = ref->mBase->mIcon;
|
||||
|
||||
std::string text;
|
||||
@ -204,9 +204,7 @@ namespace MWClass
|
||||
|
||||
std::unique_ptr<MWWorld::Action> Miscellaneous::use (const MWWorld::Ptr& ptr, bool force) const
|
||||
{
|
||||
const std::string_view soulgemPrefix = "misc_soulgem";
|
||||
|
||||
if (Misc::StringUtils::ciStartsWith(ptr.getCellRef().getRefId(), soulgemPrefix))
|
||||
if (isSoulGem(ptr))
|
||||
return std::make_unique<MWWorld::ActionSoulgem>(ptr);
|
||||
|
||||
return std::make_unique<MWWorld::NullAction>();
|
||||
@ -231,4 +229,9 @@ namespace MWClass
|
||||
return ref->mBase->mData.mIsKey != 0;
|
||||
}
|
||||
|
||||
bool Miscellaneous::isSoulGem(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
return Misc::StringUtils::ciStartsWith(ptr.getCellRef().getRefId(), "misc_soulgem");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ namespace MWClass
|
||||
bool isKey (const MWWorld::ConstPtr &ptr) const override;
|
||||
|
||||
bool isGold (const MWWorld::ConstPtr& ptr) const override;
|
||||
|
||||
bool isSoulGem(const MWWorld::ConstPtr& ptr) const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -172,13 +172,9 @@ void soulTrap(const MWWorld::Ptr& creature)
|
||||
MWWorld::ContainerStore& container = caster.getClass().getContainerStore(caster);
|
||||
MWWorld::ContainerStoreIterator gem = container.end();
|
||||
float gemCapacity = std::numeric_limits<float>::max();
|
||||
std::string soulgemFilter = "misc_soulgem"; // no other way to check for soulgems? :/
|
||||
for (MWWorld::ContainerStoreIterator it = container.begin(MWWorld::ContainerStore::Type_Miscellaneous);
|
||||
it != container.end(); ++it)
|
||||
for (auto it = container.begin(MWWorld::ContainerStore::Type_Miscellaneous); it != container.end(); ++it)
|
||||
{
|
||||
const std::string& id = it->getCellRef().getRefId();
|
||||
if (id.size() >= soulgemFilter.size()
|
||||
&& id.substr(0,soulgemFilter.size()) == soulgemFilter)
|
||||
if (it->getClass().isSoulGem(*it))
|
||||
{
|
||||
float thisGemCapacity = it->get<ESM::Miscellaneous>()->mBase->mData.mValue * fSoulgemMult;
|
||||
if (thisGemCapacity >= creatureSoulValue && thisGemCapacity < gemCapacity
|
||||
|
@ -303,55 +303,35 @@ namespace MWScript
|
||||
runtime.pop();
|
||||
|
||||
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
|
||||
MWWorld::ContainerStoreIterator it = invStore.begin();
|
||||
auto found = invStore.end();
|
||||
const auto& store = MWBase::Environment::get().getWorld()->getStore();
|
||||
|
||||
// With soul gems we prefer filled ones.
|
||||
|
||||
const std::string soulgemPrefix = "misc_soulgem";
|
||||
|
||||
if (Misc::StringUtils::ciStartsWith(item, soulgemPrefix))
|
||||
for (auto it = invStore.begin(); it != invStore.end(); ++it)
|
||||
{
|
||||
it = invStore.end();
|
||||
|
||||
for (auto it_any = invStore.begin(); it_any != invStore.end(); ++it_any)
|
||||
if (Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item))
|
||||
{
|
||||
if (::Misc::StringUtils::ciEqual(it_any->getCellRef().getRefId(), item))
|
||||
{
|
||||
if (!it_any->getCellRef().getSoul().empty() &&
|
||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().search(it_any->getCellRef().getSoul()))
|
||||
{
|
||||
it = it_any;
|
||||
break;
|
||||
}
|
||||
else if (it == invStore.end())
|
||||
it = it_any;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (; it != invStore.end(); ++it)
|
||||
{
|
||||
if (::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item))
|
||||
found = it;
|
||||
const std::string& soul = it->getCellRef().getSoul();
|
||||
if (!it->getClass().isSoulGem(*it) || (!soul.empty() && store.get<ESM::Creature>().search(soul)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it == invStore.end())
|
||||
if (found == invStore.end())
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), item, 1);
|
||||
it = ptr.getClass().getContainerStore (ptr).add (ref.getPtr(), 1, ptr, false);
|
||||
MWWorld::ManualRef ref(store, item, 1);
|
||||
found = ptr.getClass().getContainerStore(ptr).add(ref.getPtr(), 1, ptr, false);
|
||||
Log(Debug::Warning) << "Implicitly adding one " << item <<
|
||||
" to the inventory store of " << ptr.getCellRef().getRefId() <<
|
||||
" to fulfill the requirements of Equip instruction";
|
||||
}
|
||||
|
||||
if (ptr == MWMechanics::getPlayer())
|
||||
MWBase::Environment::get().getWindowManager()->useItem(*it, true);
|
||||
MWBase::Environment::get().getWindowManager()->useItem(*found, true);
|
||||
else
|
||||
{
|
||||
std::unique_ptr<MWWorld::Action> action = it->getClass().use(*it, true);
|
||||
std::unique_ptr<MWWorld::Action> action = found->getClass().use(*found, true);
|
||||
action->execute(ptr, true);
|
||||
}
|
||||
}
|
||||
|
@ -293,6 +293,8 @@ namespace MWWorld
|
||||
|
||||
virtual bool isGold(const MWWorld::ConstPtr& ptr) const { return false; }
|
||||
|
||||
virtual bool isSoulGem(const MWWorld::ConstPtr& ptr) const { return false; }
|
||||
|
||||
virtual bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const { return true; }
|
||||
///< Return whether this class of object can be activated with telekinesis
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user