Lua: Add effects to potionRecord, ingredientRecord

revert-6246b479
Zackhasacat 2 years ago committed by psi29a
parent 578a8d0357
commit 611a6429a9

@ -1,5 +1,6 @@
#include "types.hpp"
#include <components/esm3/loadalch.hpp>
#include <components/esm3/loadingr.hpp>
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
@ -43,5 +44,21 @@ namespace MWLua
record["weight"]
= sol::readonly_property([](const ESM::Ingredient& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Ingredient& rec) -> int { return rec.mData.mValue; });
record["effects"] = sol::readonly_property([context](const ESM::Ingredient& rec) -> sol::table {
sol::table res(context.mLua->sol(), sol::create);
for (size_t i = 0; i < 4; ++i)
{
if (rec.mData.mEffectID[i] < 0)
continue;
ESM::ENAMstruct effect;
effect.mEffectID = rec.mData.mEffectID[i];
effect.mSkill = rec.mData.mSkills[i];
effect.mAttribute = rec.mData.mAttributes[i];
effect.mRange = ESM::RT_Self;
effect.mArea = 0;
res[i + 1] = effect;
}
return res;
});
}
}

@ -30,9 +30,11 @@ namespace
potion.mScript = ESM::RefId::deserializeText(scriptId);
potion.mData.mWeight = rec["weight"];
potion.mData.mValue = rec["value"];
// Note: The list of effects is not yet present in openmw.types.Potion,
// so we don't map it here either.
sol::table effectsTable = rec["effects"];
size_t numEffects = effectsTable.size();
potion.mEffects.mList.resize(numEffects);
for (size_t i = 0; i < numEffects; ++i)
potion.mEffects.mList[i] = LuaUtil::cast<ESM::ENAMstruct>(effectsTable[i + 1]);
return potion;
}
}
@ -66,5 +68,11 @@ namespace MWLua
= sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mScript.serializeText(); });
record["weight"] = sol::readonly_property([](const ESM::Potion& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Potion& rec) -> int { return rec.mData.mValue; });
record["effects"] = sol::readonly_property([context](const ESM::Potion& rec) -> sol::table {
sol::table res(context.mLua->sol(), sol::create);
for (size_t i = 0; i < rec.mEffects.mList.size(); ++i)
res[i + 1] = rec.mEffects.mList[i]; // ESM::ENAMstruct (effect params)
return res;
});
}
}

@ -27,7 +27,7 @@ namespace ESM
{
float mWeight;
int mValue;
int mEffectID[4]; // Effect, 0 or -1 means none
int mEffectID[4]; // Effect, -1 means none
int mSkills[4]; // SkillEnum related to effect
int mAttributes[4]; // Attribute related to effect
};

@ -944,6 +944,7 @@
-- @field #string icon VFS path to the icon
-- @field #number weight
-- @field #number value
-- @field #list<openmw.core#MagicEffectWithParam> effects The effects (@{#list<openmw.core#MagicEffectWithParam>}) of the ingredient
--- @{#Lockable} functions
@ -1126,6 +1127,7 @@
-- @field #string icon VFS path to the icon
-- @field #number weight
-- @field #number value
-- @field #list<openmw.core#MagicEffectWithParam> effects The effects (@{#list<openmw.core#MagicEffectWithParam>}) of the potion

Loading…
Cancel
Save