1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-31 01:20:23 +00:00

Make ActorActiveEffects:getEffect return an empty value and strip expired effects from __pairs

This commit is contained in:
Evil Eye 2024-01-06 14:14:29 +01:00
parent 21f177daac
commit 74a6c81d53
2 changed files with 11 additions and 9 deletions
apps/openmw/mwlua
files/lua_api/openmw

@ -769,8 +769,13 @@ namespace MWLua
sol::state_view lua(ts);
self.reset();
return sol::as_function([lua, self]() mutable -> std::pair<sol::object, sol::object> {
if (!self.isEnd())
while (!self.isEnd())
{
if (self.mIterator->second.getBase() == 0 && self.mIterator->second.getModifier() == 0.f)
{
self.advance();
continue;
}
ActiveEffect effect = ActiveEffect{ self.mIterator->first, self.mIterator->second };
auto result = sol::make_object(lua, effect);
@ -778,10 +783,7 @@ namespace MWLua
self.advance();
return { key, result };
}
else
{
return { sol::lua_nil, sol::lua_nil };
}
return { sol::lua_nil, sol::lua_nil };
});
};
@ -823,7 +825,7 @@ namespace MWLua
if (auto* store = effects.getStore())
if (auto effect = store->get(key))
return ActiveEffect{ key, effect.value() };
return sol::nullopt;
return ActiveEffect{ key, MWMechanics::EffectParam() };
};
// types.Actor.activeEffects(o):removeEffect(id, ?arg)

@ -210,14 +210,14 @@
-- end
-- @usage -- Check for a specific effect
-- local effect = Actor.activeEffects(self):getEffect(core.magic.EFFECT_TYPE.Telekinesis)
-- if effect then
-- if effect.magnitude ~= 0 then
-- print(effect.id..', attribute='..tostring(effect.affectedAttribute)..', skill='..tostring(effect.affectedSkill)..', magnitude='..tostring(effect.magnitude))
-- else
-- print('No Telekinesis effect')
-- end
-- @usage -- Check for a specific effect targeting a specific attribute.
-- local effect = Actor.activeEffects(self):getEffect(core.magic.EFFECT_TYPE.FortifyAttribute, core.ATTRIBUTE.Luck)
-- if effect then
-- if effect.magnitude ~= 0 then
-- print(effect.id..', attribute='..tostring(effect.affectedAttribute)..', skill='..tostring(effect.affectedSkill)..', magnitude='..tostring(effect.magnitude))
-- else
-- print('No Fortify Luck effect')
@ -229,7 +229,7 @@
-- @param self
-- @param #string effectId effect ID
-- @param #string extraParam Optional skill or attribute ID
-- @return openmw.core#ActiveEffect if such an effect is active, nil otherwise
-- @return openmw.core#ActiveEffect
---
-- Completely removes the active effect from the actor.