From 611a6429a9ae982ffa6cba8c1173de3ca21c646a Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 20 Jun 2023 10:00:05 +0000 Subject: [PATCH] Lua: Add effects to potionRecord, ingredientRecord --- apps/openmw/mwlua/types/ingredient.cpp | 17 +++++++++++++++++ apps/openmw/mwlua/types/potion.cpp | 14 +++++++++++--- components/esm3/loadingr.hpp | 2 +- files/lua_api/openmw/types.lua | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwlua/types/ingredient.cpp b/apps/openmw/mwlua/types/ingredient.cpp index 69b4a670fb..cbf1b317f0 100644 --- a/apps/openmw/mwlua/types/ingredient.cpp +++ b/apps/openmw/mwlua/types/ingredient.cpp @@ -1,5 +1,6 @@ #include "types.hpp" +#include #include #include #include @@ -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; + }); } } diff --git a/apps/openmw/mwlua/types/potion.cpp b/apps/openmw/mwlua/types/potion.cpp index 3ab15f2691..31e309ad76 100644 --- a/apps/openmw/mwlua/types/potion.cpp +++ b/apps/openmw/mwlua/types/potion.cpp @@ -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(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; + }); } } diff --git a/components/esm3/loadingr.hpp b/components/esm3/loadingr.hpp index d6b1b18c32..02b237f386 100644 --- a/components/esm3/loadingr.hpp +++ b/components/esm3/loadingr.hpp @@ -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 }; diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 30237deec5..c6650a3541 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -944,6 +944,7 @@ -- @field #string icon VFS path to the icon -- @field #number weight -- @field #number value +-- @field #list effects The effects (@{#list}) 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 effects The effects (@{#list}) of the potion