1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 20:29:57 +00:00

Merge branch 'inactiveeffects' into 'master'

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

Closes #7440

See merge request OpenMW/openmw!3735
This commit is contained in:
psi29a 2024-01-09 08:58:42 +00:00
commit 5bd2020c23
2 changed files with 11 additions and 9 deletions

View file

@ -769,8 +769,13 @@ namespace MWLua
sol::state_view lua(ts); sol::state_view lua(ts);
self.reset(); self.reset();
return sol::as_function([lua, self]() mutable -> std::pair<sol::object, sol::object> { 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 }; ActiveEffect effect = ActiveEffect{ self.mIterator->first, self.mIterator->second };
auto result = sol::make_object(lua, effect); auto result = sol::make_object(lua, effect);
@ -778,10 +783,7 @@ namespace MWLua
self.advance(); self.advance();
return { key, result }; 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* store = effects.getStore())
if (auto effect = store->get(key)) if (auto effect = store->get(key))
return ActiveEffect{ key, effect.value() }; return ActiveEffect{ key, effect.value() };
return sol::nullopt; return ActiveEffect{ key, MWMechanics::EffectParam() };
}; };
// types.Actor.activeEffects(o):removeEffect(id, ?arg) // types.Actor.activeEffects(o):removeEffect(id, ?arg)

View file

@ -210,14 +210,14 @@
-- end -- end
-- @usage -- Check for a specific effect -- @usage -- Check for a specific effect
-- local effect = Actor.activeEffects(self):getEffect(core.magic.EFFECT_TYPE.Telekinesis) -- 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)) -- print(effect.id..', attribute='..tostring(effect.affectedAttribute)..', skill='..tostring(effect.affectedSkill)..', magnitude='..tostring(effect.magnitude))
-- else -- else
-- print('No Telekinesis effect') -- print('No Telekinesis effect')
-- end -- end
-- @usage -- Check for a specific effect targeting a specific attribute. -- @usage -- Check for a specific effect targeting a specific attribute.
-- local effect = Actor.activeEffects(self):getEffect(core.magic.EFFECT_TYPE.FortifyAttribute, core.ATTRIBUTE.Luck) -- 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)) -- print(effect.id..', attribute='..tostring(effect.affectedAttribute)..', skill='..tostring(effect.affectedSkill)..', magnitude='..tostring(effect.magnitude))
-- else -- else
-- print('No Fortify Luck effect') -- print('No Fortify Luck effect')
@ -229,7 +229,7 @@
-- @param self -- @param self
-- @param #string effectId effect ID -- @param #string effectId effect ID
-- @param #string extraParam Optional skill or attribute 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. -- Completely removes the active effect from the actor.