mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Merge branch 'fix_use' into 'master'
Fix regression added in !3354: Set `force` to false when applying UseItem from inventory. See merge request OpenMW/openmw!3422
This commit is contained in:
commit
ed022a6c14
@ -51,7 +51,7 @@ namespace MWBase
|
||||
virtual void objectTeleported(const MWWorld::Ptr& ptr) = 0;
|
||||
virtual void itemConsumed(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) = 0;
|
||||
virtual void objectActivated(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0;
|
||||
virtual void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0;
|
||||
virtual void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, bool force) = 0;
|
||||
virtual void exteriorCreated(MWWorld::CellStore& cell) = 0;
|
||||
virtual void questUpdated(const ESM::RefId& questId, int stage) = 0;
|
||||
|
||||
|
@ -601,7 +601,7 @@ namespace MWGui
|
||||
}
|
||||
}
|
||||
else
|
||||
MWBase::Environment::get().getLuaManager()->useItem(ptr, MWMechanics::getPlayer());
|
||||
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
|
||||
|
@ -71,7 +71,7 @@ namespace MWLua
|
||||
MWWorld::Ptr actor = getPtr(event.mActor);
|
||||
if (actor.isEmpty() || obj.isEmpty())
|
||||
return;
|
||||
mGlobalScripts.onUseItem(GObject(obj), GObject(actor));
|
||||
mGlobalScripts.onUseItem(GObject(obj), GObject(actor), event.mForce);
|
||||
}
|
||||
|
||||
void operator()(const OnConsume& event) const
|
||||
|
@ -40,6 +40,7 @@ namespace MWLua
|
||||
{
|
||||
ESM::RefNum mActor;
|
||||
ESM::RefNum mObject;
|
||||
bool mForce;
|
||||
};
|
||||
struct OnConsume
|
||||
{
|
||||
|
@ -40,7 +40,10 @@ namespace MWLua
|
||||
{
|
||||
callEngineHandlers(mOnActivateHandlers, obj, actor);
|
||||
}
|
||||
void onUseItem(const GObject& obj, const GObject& actor) { callEngineHandlers(mOnUseItemHandlers, obj, actor); }
|
||||
void onUseItem(const GObject& obj, const GObject& actor, bool force)
|
||||
{
|
||||
callEngineHandlers(mOnUseItemHandlers, obj, actor, force);
|
||||
}
|
||||
void onNewExterior(const GCell& cell) { callEngineHandlers(mOnNewExteriorHandlers, cell); }
|
||||
|
||||
private:
|
||||
|
@ -330,16 +330,16 @@ namespace MWLua
|
||||
},
|
||||
"_runStandardActivationAction");
|
||||
};
|
||||
api["_runStandardUseAction"] = [context](const GObject& object, const GObject& actor) {
|
||||
api["_runStandardUseAction"] = [context](const GObject& object, const GObject& actor, bool force) {
|
||||
context.mLuaManager->addAction(
|
||||
[object, actor] {
|
||||
[object, actor, force] {
|
||||
const MWWorld::Ptr& actorPtr = actor.ptr();
|
||||
const MWWorld::Ptr& objectPtr = object.ptr();
|
||||
if (actorPtr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
MWBase::Environment::get().getWindowManager()->useItem(objectPtr, true);
|
||||
MWBase::Environment::get().getWindowManager()->useItem(objectPtr, force);
|
||||
else
|
||||
{
|
||||
std::unique_ptr<MWWorld::Action> action = objectPtr.getClass().use(objectPtr, true);
|
||||
std::unique_ptr<MWWorld::Action> action = objectPtr.getClass().use(objectPtr, force);
|
||||
action->execute(actorPtr, true);
|
||||
}
|
||||
},
|
||||
|
@ -77,9 +77,9 @@ namespace MWLua
|
||||
{
|
||||
mEngineEvents.addToQueue(EngineEvents::OnActivate{ getId(actor), getId(object) });
|
||||
}
|
||||
void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) override
|
||||
void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, bool force) override
|
||||
{
|
||||
mEngineEvents.addToQueue(EngineEvents::OnUseItem{ getId(actor), getId(object) });
|
||||
mEngineEvents.addToQueue(EngineEvents::OnUseItem{ getId(actor), getId(object), force });
|
||||
}
|
||||
void exteriorCreated(MWWorld::CellStore& cell) override
|
||||
{
|
||||
|
@ -20,14 +20,14 @@ Examples:
|
||||
|
||||
**UseItem**
|
||||
|
||||
Any script can send global event ``UseItem`` with arguments ``object`` and ``actor``.
|
||||
Any script can send global event ``UseItem`` with arguments ``object``, ``actor``, and optional boolean ``force``.
|
||||
The actor will use (e.g. equip or consume) the object. The object should be in the actor's inventory.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: Lua
|
||||
|
||||
core.sendGlobalEvent('UseItem', {object = potion, actor = player})
|
||||
core.sendGlobalEvent('UseItem', {object = potion, actor = player, force = true})
|
||||
|
||||
UI events
|
||||
---------
|
||||
|
@ -4,11 +4,12 @@ local world = require('openmw.world')
|
||||
local handlersPerObject = {}
|
||||
local handlersPerType = {}
|
||||
|
||||
local function useItem(obj, actor)
|
||||
local function useItem(obj, actor, force)
|
||||
local options = { force = force or false }
|
||||
local handlers = handlersPerObject[obj.id]
|
||||
if handlers then
|
||||
for i = #handlers, 1, -1 do
|
||||
if handlers[i](obj, actor) == false then
|
||||
if handlers[i](obj, actor, options) == false then
|
||||
return -- skip other handlers
|
||||
end
|
||||
end
|
||||
@ -16,12 +17,12 @@ local function useItem(obj, actor)
|
||||
handlers = handlersPerType[obj.type]
|
||||
if handlers then
|
||||
for i = #handlers, 1, -1 do
|
||||
if handlers[i](obj, actor) == false then
|
||||
if handlers[i](obj, actor, options) == false then
|
||||
return -- skip other handlers
|
||||
end
|
||||
end
|
||||
end
|
||||
world._runStandardUseAction(obj, actor)
|
||||
world._runStandardUseAction(obj, actor, force)
|
||||
end
|
||||
|
||||
return {
|
||||
@ -53,7 +54,7 @@ return {
|
||||
version = 0,
|
||||
|
||||
--- Add new use action handler for a specific object.
|
||||
-- If `handler(object, actor)` returns false, other handlers for
|
||||
-- If `handler(object, actor, options)` returns false, other handlers for
|
||||
-- the same object (including type handlers) will be skipped.
|
||||
-- @function [parent=#ItemUsage] addHandlerForObject
|
||||
-- @param openmw.core#GameObject obj The object.
|
||||
@ -68,7 +69,7 @@ return {
|
||||
end,
|
||||
|
||||
--- Add new use action handler for a type of objects.
|
||||
-- If `handler(object, actor)` returns false, other handlers for
|
||||
-- If `handler(object, actor, options)` returns false, other handlers for
|
||||
-- the same object (including type handlers) will be skipped.
|
||||
-- @function [parent=#ItemUsage] addHandlerForType
|
||||
-- @param #any type A type from the `openmw.types` package.
|
||||
@ -91,7 +92,7 @@ return {
|
||||
if not data.actor or not types.Actor.objectIsInstance(data.actor) then
|
||||
error('UseItem: invalid argument "actor"')
|
||||
end
|
||||
useItem(data.object, data.actor)
|
||||
useItem(data.object, data.actor, data.force)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user