diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b4a8bdac80..9a19c3e1d6 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -62,7 +62,7 @@ add_openmw_dir (mwlua luamanagerimp object worldview userdataserializer eventqueue luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings - types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator + types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwlua/types/book.cpp b/apps/openmw/mwlua/types/book.cpp new file mode 100644 index 0000000000..9d34a2026e --- /dev/null +++ b/apps/openmw/mwlua/types/book.cpp @@ -0,0 +1,52 @@ +#include "types.hpp" + +#include + +#include + +#include "../luabindings.hpp" + +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + +namespace MWLua +{ + void addBookBindings(sol::table book, const Context& context) + { + sol::table skill(context.mLua->sol(), sol::create); + book["SKILL"] = LuaUtil::makeStrictReadOnly(skill); + for (int id = ESM::Skill::Block; id < ESM::Skill::Length; ++id) + { + std::string skillName = Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id]); + skill[skillName] = skillName; + } + + const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); + book["record"] = sol::overload( + [](const Object& obj) -> const ESM::Book* { return obj.ptr().get()->mBase; }, + [store](const std::string& recordId) -> const ESM::Book* { return store->find(recordId); }); + sol::usertype record = context.mLua->sol().new_usertype("ESM3_Book"); + record[sol::meta_function::to_string] = [](const ESM::Book& rec) { return "ESM3_Book[" + rec.mId + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mId; }); + record["name"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mName; }); + record["model"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mModel; }); + record["mwscript"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mScript; }); + record["icon"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mIcon; }); + record["text"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mText; }); + record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mEnchant; }); + record["isScroll"] = sol::readonly_property([](const ESM::Book& rec) -> bool { return rec.mData.mIsScroll; }); + record["value"] = sol::readonly_property([](const ESM::Book& rec) -> int { return rec.mData.mValue; }); + record["weight"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mWeight; }); + record["enchantCapacity"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mEnchant * 0.1f; }); + record["skill"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional + { + if (rec.mData.mSkillId >= 0) + return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[rec.mData.mSkillId]); + else + return sol::nullopt; + }); + } +} diff --git a/apps/openmw/mwlua/types/types.cpp b/apps/openmw/mwlua/types/types.cpp index bc707059e8..5330526edb 100644 --- a/apps/openmw/mwlua/types/types.cpp +++ b/apps/openmw/mwlua/types/types.cpp @@ -160,7 +160,6 @@ namespace MWLua addType(ObjectTypeName::Player, {ESM::REC_INTERNAL_PLAYER}, ObjectTypeName::NPC); addType(ObjectTypeName::Armor, {ESM::REC_ARMO}, ObjectTypeName::Item); - addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item); addType(ObjectTypeName::Clothing, {ESM::REC_CLOT}, ObjectTypeName::Item); addType(ObjectTypeName::Ingredient, {ESM::REC_INGR}, ObjectTypeName::Item); addType(ObjectTypeName::Light, {ESM::REC_LIGH}, ObjectTypeName::Item); @@ -173,6 +172,7 @@ namespace MWLua addType(ObjectTypeName::Repair, {ESM::REC_REPA}, ObjectTypeName::Item); addActivatorBindings(addType(ObjectTypeName::Activator, {ESM::REC_ACTI}), context); + addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}), context); addContainerBindings(addType(ObjectTypeName::Container, {ESM::REC_CONT}), context); addDoorBindings(addType(ObjectTypeName::Door, {ESM::REC_DOOR}), context); addType(ObjectTypeName::Static, {ESM::REC_STAT}); diff --git a/apps/openmw/mwlua/types/types.hpp b/apps/openmw/mwlua/types/types.hpp index 8373162995..f92644f443 100644 --- a/apps/openmw/mwlua/types/types.hpp +++ b/apps/openmw/mwlua/types/types.hpp @@ -25,6 +25,7 @@ namespace MWLua // used in initTypesPackage void addActivatorBindings(sol::table activator, const Context& context); + void addBookBindings(sol::table book, const Context& context); void addContainerBindings(sol::table container, const Context& context); void addDoorBindings(sol::table door, const Context& context); void addActorBindings(sol::table actor, const Context& context); diff --git a/apps/openmw/mwlua/types/weapon.cpp b/apps/openmw/mwlua/types/weapon.cpp index 87ae984cf9..594e447f00 100644 --- a/apps/openmw/mwlua/types/weapon.cpp +++ b/apps/openmw/mwlua/types/weapon.cpp @@ -55,7 +55,7 @@ namespace MWLua record["health"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mHealth; }); record["speed"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mSpeed; }); record["reach"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mReach; }); - record["enchant"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mEnchant * 0.1f; }); + record["enchantCapacity"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mEnchant * 0.1f; }); record["chopMinDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mChop[0]; }); record["chopMaxDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mChop[1]; }); record["slashMinDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mSlash[0]; }); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 257d926b50..d9a4d36439 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -532,6 +532,60 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- Book.SKILL +-- @type BookSKILL +-- @field #string acrobatics "acrobatics" +-- @field #string alchemy "alchemy" +-- @field #string alteration "alteration" +-- @field #string armorer "armorer" +-- @field #string athletics "athletics" +-- @field #string axe "axe" +-- @field #string block "block" +-- @field #string bluntWeapon "bluntweapon" +-- @field #string conjuration "conjuration" +-- @field #string destruction "destruction" +-- @field #string enchant "enchant" +-- @field #string handToHand "handtohand" +-- @field #string heavyArmor "heavyarmor" +-- @field #string illusion "illusion" +-- @field #string lightArmor "lightarmor" +-- @field #string longBlade "longblade" +-- @field #string marksman "marksman" +-- @field #string mediumArmor "mediumarmor" +-- @field #string mercantile "mercantile" +-- @field #string mysticism "mysticism" +-- @field #string restoration "restoration" +-- @field #string security "security" +-- @field #string shortBlade "shortblade" +-- @field #string sneak "sneak" +-- @field #string spear "spear" +-- @field #string speechcraft "speechcraft" +-- @field #string unarmored "unarmored" + +--- @{#BookSKILL} +-- @field [parent=#Book] #BookSKILL SKILL + +--- +-- Returns the read-only @{#BookRecord} of a book +-- @function [parent=#Book] record +-- @param #any objectOrRecordId +-- @return #BookRecord + +--- +-- @type BookRecord +-- @field #string id The record ID of the book +-- @field #string name Name of the book +-- @field #string model VFS path to the model +-- @field #string mwscript MWScript on this book (can be empty) +-- @field #string icon VFS path to the icon +-- @field #string enchant The enchantment ID of this book (can be empty) +-- @field #string text The text content of the book +-- @field #number weight +-- @field #number value +-- @field #string skill The skill that this book teaches. See @{#Book.SKILL} +-- @field #boolean isScroll +-- @field #number enchantCapacity + --- @{#Clothing} functions @@ -670,7 +724,7 @@ -- @field #number health -- @field #number speed -- @field #number reach --- @field #number enchant +-- @field #number enchantCapacity -- @field #number chopMinDamage -- @field #number chopMaxDamage -- @field #number slashMinDamage