1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-31 06:32:39 +00:00

Merge branch 'lua_activation' into 'master'

Lua scripts can handle activation of mwscripted objects

See merge request OpenMW/openmw!3263
This commit is contained in:
psi29a 2023-07-25 21:23:20 +00:00
commit 94d8c50df2
8 changed files with 12 additions and 20 deletions

View File

@ -540,8 +540,6 @@ namespace MWBase
const osg::Vec3f& worldPos, float scale = 1.f, bool isMagicVFX = true)
= 0;
virtual void activate(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0;
/// @see MWWorld::WeatherManager::isInStorm
virtual bool isInStorm() const = 0;

View File

@ -274,6 +274,8 @@ namespace MWLua
});
api["_runStandardActivationAction"] = [context](const GObject& object, const GObject& actor) {
if (!object.ptr().getRefData().activate())
return;
context.mLuaManager->addAction(
[object, actor] {
const MWWorld::Ptr& objPtr = object.ptr();

View File

@ -3,6 +3,7 @@
#include <components/esm3/aisequence.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/class.hpp"
@ -44,7 +45,7 @@ namespace MWMechanics
{
// Note: we intentionally do not cancel package after activation here for backward compatibility with
// original engine.
MWBase::Environment::get().getWorld()->activate(target, actor);
MWBase::Environment::get().getLuaManager()->objectActivated(target, actor);
}
return false;
}

View File

@ -8,6 +8,7 @@
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/cellstore.hpp"
@ -265,8 +266,7 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor)
return;
// first check if obstacle is a door
static float distance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
float distance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
const MWWorld::Ptr door = getNearbyDoor(actor, distance);
if (!door.isEmpty() && canOpenDoors(actor))
{
@ -300,9 +300,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
if (mPathFinder.getPathSize() == 0)
return;
MWBase::World* world = MWBase::Environment::get().getWorld();
static float distance = world->getMaxActivationDistance();
float distance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
const MWWorld::Ptr door = getNearbyDoor(actor, distance);
if (door == MWWorld::Ptr())
return;
@ -314,7 +312,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
if (door.getCellRef().getTrap().empty() && !door.getCellRef().isLocked())
{
world->activate(door, actor);
MWBase::Environment::get().getLuaManager()->objectActivated(door, actor);
return;
}
@ -326,7 +324,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
MWWorld::Ptr keyPtr = invStore.search(keyId);
if (!keyPtr.isEmpty())
world->activate(door, actor);
MWBase::Environment::get().getLuaManager()->objectActivated(door, actor);
}
}

View File

@ -18,6 +18,7 @@
#include "../mwworld/worldmodel.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
@ -194,7 +195,7 @@ namespace MWWorld
if (!toActivate.getClass().hasToolTip(toActivate))
return;
MWBase::Environment::get().getWorld()->activate(toActivate, player);
MWBase::Environment::get().getLuaManager()->objectActivated(toActivate, player);
}
bool Player::wasTeleported() const

View File

@ -3707,13 +3707,6 @@ namespace MWWorld
mRendering->spawnEffect(model, textureOverride, worldPos, scale, isMagicVFX);
}
void World::activate(const Ptr& object, const Ptr& actor)
{
breakInvisibility(actor);
if (object.getRefData().activate())
MWBase::Environment::get().getLuaManager()->objectActivated(object, actor);
}
struct ResetActorsVisitor
{
World& mWorld;

View File

@ -624,8 +624,6 @@ namespace MWWorld
void spawnEffect(const std::string& model, const std::string& textureOverride, const osg::Vec3f& worldPos,
float scale = 1.f, bool isMagicVFX = true) override;
void activate(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) override;
/// @see MWWorld::WeatherManager::isInStorm
bool isInStorm() const override;

View File

@ -23,6 +23,7 @@ local handlersPerType = {}
handlersPerType[types.ESM4Door] = { ESM4DoorActivation }
local function onActivate(obj, actor)
types.Actor.activeEffects(actor):remove('invisibility')
local handlers = handlersPerObject[obj.id]
if handlers then
for i = #handlers, 1, -1 do