mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-18 18:40:06 +00:00
Clear selected enchanted item and/or spell with actor.clearSelectedCastable()
This commit is contained in:
parent
4fbf42b145
commit
7113db8b97
@ -24,6 +24,7 @@
|
|||||||
#include "../mwmechanics/spellutil.hpp"
|
#include "../mwmechanics/spellutil.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
#include "../mwworld/inventorystore.hpp"
|
||||||
#include "../mwworld/worldmodel.hpp"
|
#include "../mwworld/worldmodel.hpp"
|
||||||
|
|
||||||
#include "localscripts.hpp"
|
#include "localscripts.hpp"
|
||||||
@ -615,17 +616,43 @@ namespace MWLua
|
|||||||
context.mLuaManager->addAction([obj = Object(ptr), spellId]() {
|
context.mLuaManager->addAction([obj = Object(ptr), spellId]() {
|
||||||
const MWWorld::Ptr& ptr = obj.ptr();
|
const MWWorld::Ptr& ptr = obj.ptr();
|
||||||
auto& stats = ptr.getClass().getCreatureStats(ptr);
|
auto& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
|
|
||||||
|
if (spellId.empty())
|
||||||
|
{
|
||||||
|
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||||
|
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
||||||
|
else
|
||||||
|
stats.getSpells().setSelectedSpell(ESM::RefId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!stats.getSpells().hasSpell(spellId))
|
if (!stats.getSpells().hasSpell(spellId))
|
||||||
throw std::runtime_error("Actor doesn't know spell " + spellId.toDebugString());
|
throw std::runtime_error("Actor doesn't know spell " + spellId.toDebugString());
|
||||||
|
|
||||||
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||||
{
|
{
|
||||||
int chance = 0;
|
int chance = MWMechanics::getSpellSuccessChance(spellId, ptr);
|
||||||
if (!spellId.empty())
|
|
||||||
chance = MWMechanics::getSpellSuccessChance(spellId, ptr);
|
|
||||||
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, chance);
|
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, chance);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ptr.getClass().getCreatureStats(ptr).getSpells().setSelectedSpell(spellId);
|
stats.getSpells().setSelectedSpell(spellId);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
actor["clearSelectedCastable"] = [context](const SelfObject& o) {
|
||||||
|
if (!o.ptr().getClass().isActor())
|
||||||
|
throw std::runtime_error("Actor expected");
|
||||||
|
context.mLuaManager->addAction([obj = Object(o.ptr())]() {
|
||||||
|
const MWWorld::Ptr& ptr = obj.ptr();
|
||||||
|
auto& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
|
if (ptr.getClass().hasInventoryStore(ptr))
|
||||||
|
{
|
||||||
|
MWWorld::InventoryStore& inventory = ptr.getClass().getInventoryStore(ptr);
|
||||||
|
inventory.setSelectedEnchantItem(inventory.end());
|
||||||
|
}
|
||||||
|
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||||
|
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();
|
||||||
|
else
|
||||||
|
stats.getSpells().setSelectedSpell(ESM::RefId());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,6 +161,11 @@
|
|||||||
-- @param openmw.core#GameObject actor
|
-- @param openmw.core#GameObject actor
|
||||||
-- @param openmw.core#Spell spell Spell (can be nil)
|
-- @param openmw.core#Spell spell Spell (can be nil)
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Clears the actor's selected castable(spell or enchanted item)
|
||||||
|
-- @function [parent=#Actor] clearSelectedCastable
|
||||||
|
-- @param openmw.core#GameObject actor
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Get currently selected enchanted item
|
-- Get currently selected enchanted item
|
||||||
-- @function [parent=#Actor] getSelectedEnchantedItem
|
-- @function [parent=#Actor] getSelectedEnchantedItem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user