Pass a 0-count object to onConsume instead of the record id

just_say_no_to_geode
uramer 3 years ago
parent c3c48f21d7
commit 3761e7b24e

@ -37,7 +37,7 @@ namespace MWBase
virtual void deregisterObject(const MWWorld::Ptr& ptr) = 0;
virtual void objectAddedToScene(const MWWorld::Ptr& ptr) = 0;
virtual void objectRemovedFromScene(const MWWorld::Ptr& ptr) = 0;
virtual void appliedToObject(const MWWorld::Ptr& toPtr, std::string_view recordId, const MWWorld::Ptr& fromPtr) = 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;
// TODO: notify LuaManager about other events
// virtual void objectOnHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object,

@ -1105,7 +1105,7 @@ namespace MWClass
MWBase::Environment::get().getWorld()->breakInvisibility(actor);
MWMechanics::CastSpell cast(actor, actor);
std::string recordId = consumable.getCellRef().getRefId();
MWBase::Environment::get().getLuaManager()->appliedToObject(actor, recordId, actor);
MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor);
actor.getClass().getContainerStore(actor).remove(consumable, 1, actor);
return cast.cast(recordId);
}

@ -177,7 +177,7 @@ namespace MWLua
else
{
static_assert(std::is_same_v<EventT, OnConsume>);
callEngineHandlers(mOnConsumeHandlers, arg.mRecordId);
callEngineHandlers(mOnConsumeHandlers, arg.mConsumable);
}
}, event);
}

@ -62,7 +62,7 @@ namespace MWLua
};
struct OnConsume
{
std::string mRecordId;
LObject mConsumable;
};
using EngineEvent = std::variant<OnActive, OnInactive, OnConsume, OnActivated>;

@ -374,9 +374,10 @@ namespace MWLua
mWorldView.getObjectRegistry()->deregisterPtr(ptr);
}
void LuaManager::appliedToObject(const MWWorld::Ptr& toPtr, std::string_view recordId, const MWWorld::Ptr& fromPtr)
void LuaManager::itemConsumed(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor)
{
mLocalEngineEvents.push_back({getId(toPtr), LocalScripts::OnConsume{std::string(recordId)}});
mWorldView.getObjectRegistry()->registerPtr(consumable);
mLocalEngineEvents.push_back({getId(actor), LocalScripts::OnConsume{LObject(getId(consumable), mWorldView.getObjectRegistry())}});
}
void LuaManager::objectActivated(const MWWorld::Ptr& object, const MWWorld::Ptr& actor)

@ -51,7 +51,7 @@ namespace MWLua
void registerObject(const MWWorld::Ptr& ptr) override;
void deregisterObject(const MWWorld::Ptr& ptr) override;
void inputEvent(const InputEvent& event) override { mInputEvents.push_back(event); }
void appliedToObject(const MWWorld::Ptr& toPtr, std::string_view recordId, const MWWorld::Ptr& fromPtr) override;
void itemConsumed(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) override;
void objectActivated(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) override;
MWBase::LuaManager::ActorControls* getActorControls(const MWWorld::Ptr&) const override;

@ -66,8 +66,10 @@ Engine handler is a function defined by a script, that can be called by the engi
| the item is placed to the actor's inventory, (2) count of
| the original item is set to zero, (3) and only then onActivated is
| called on the original item, so self.count is already zero.
* - onConsume(recordId)
- Called if `recordId` (e.g. a potion) is consumed.
* - onConsume(item)
- | Called on an actor when they consume an item (e.g. a potion).
| Similarly to onActivated, the item has already been removed
| from the actor's inventory, and the count was set to zero.
**Only for local scripts attached to a player**

Loading…
Cancel
Save