From c4d11469105b6261acf46fe1e2bee7f035d809a2 Mon Sep 17 00:00:00 2001 From: WinterSolstice8 <60417494+wintersolstice8@users.noreply.github.com> Date: Sun, 15 Mar 2026 17:38:13 -0600 Subject: [PATCH] [core] Add CLuaWeaponskill for lua userdata type --- src/map/lua/CMakeLists.txt | 2 ++ src/map/lua/lua_weaponskill.cpp | 63 +++++++++++++++++++++++++++++++++ src/map/lua/lua_weaponskill.h | 53 +++++++++++++++++++++++++++ src/map/lua/luautils.cpp | 2 ++ src/map/lua/sol_bindings.cpp | 4 +++ src/map/lua/sol_bindings.h | 4 +++ 6 files changed, 128 insertions(+) create mode 100644 src/map/lua/lua_weaponskill.cpp create mode 100644 src/map/lua/lua_weaponskill.h diff --git a/src/map/lua/CMakeLists.txt b/src/map/lua/CMakeLists.txt index 31a84963c3c..f11b94dec67 100644 --- a/src/map/lua/CMakeLists.txt +++ b/src/map/lua/CMakeLists.txt @@ -29,6 +29,8 @@ set(LUA_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lua_treasure_pool.h ${CMAKE_CURRENT_SOURCE_DIR}/lua_trigger_area.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lua_trigger_area.h + ${CMAKE_CURRENT_SOURCE_DIR}/lua_weaponskill.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/lua_weaponskill.h ${CMAKE_CURRENT_SOURCE_DIR}/lua_zone.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lua_zone.h ${CMAKE_CURRENT_SOURCE_DIR}/luautils.cpp diff --git a/src/map/lua/lua_weaponskill.cpp b/src/map/lua/lua_weaponskill.cpp new file mode 100644 index 00000000000..cdc2d0f0900 --- /dev/null +++ b/src/map/lua/lua_weaponskill.cpp @@ -0,0 +1,63 @@ +/* +=========================================================================== + + opyright (c) 2026 LandSandBoat Dev Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + +#include "common/logging.h" + +#include "lua_weaponskill.h" +#include "weapon_skill.h" + +CLuaWeaponSkill::CLuaWeaponSkill(CWeaponSkill* PSkill) +: m_PLuaWeaponSkill(PSkill) +{ + if (PSkill == nullptr) + { + ShowError("CLuaWeaponSkill created with nullptr instead of valid CWeaponSkill*!"); + } +} + +bool CLuaWeaponSkill::isSingle() +{ + return !m_PLuaWeaponSkill->isAoE(); +} + +bool CLuaWeaponSkill::isAoE() +{ + return m_PLuaWeaponSkill->isAoE(); +} + +uint16 CLuaWeaponSkill::getID() +{ + return m_PLuaWeaponSkill->getID(); +} + +void CLuaWeaponSkill::Register() +{ + SOL_USERTYPE("CWeaponSkill", CLuaWeaponSkill); + SOL_REGISTER("isAoE", CLuaWeaponSkill::isAoE); + SOL_REGISTER("isSingle", CLuaWeaponSkill::isSingle); + SOL_REGISTER("getID", CLuaWeaponSkill::getID); +} + +std::ostream& operator<<(std::ostream& os, const CLuaWeaponSkill& weaponskill) +{ + std::string id = weaponskill.m_PLuaWeaponSkill ? std::to_string(weaponskill.m_PLuaWeaponSkill->getID()) : "nullptr"; + return os << "CLuaWeaponSkill(" << id << ")"; +} diff --git a/src/map/lua/lua_weaponskill.h b/src/map/lua/lua_weaponskill.h new file mode 100644 index 00000000000..e104e466993 --- /dev/null +++ b/src/map/lua/lua_weaponskill.h @@ -0,0 +1,53 @@ +/* +=========================================================================== + + Copyright (c) 2026 LandSandBoat Dev Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/ + +=========================================================================== +*/ + +#pragma once + +#include "common/cbasetypes.h" +#include "luautils.h" + +class CWeaponSkill; + +class CLuaWeaponSkill +{ + CWeaponSkill* m_PLuaWeaponSkill; + +public: + CLuaWeaponSkill(CWeaponSkill*); + + CWeaponSkill* GetWeaponSkill() const + { + return m_PLuaWeaponSkill; + } + + friend std::ostream& operator<<(std::ostream& out, const CLuaWeaponSkill& weaponskill); + + uint16 getID(); + bool isAoE(); + bool isSingle(); + + bool operator==(const CLuaWeaponSkill& other) const + { + return this->m_PLuaWeaponSkill == other.m_PLuaWeaponSkill; + } + + static void Register(); +}; diff --git a/src/map/lua/luautils.cpp b/src/map/lua/luautils.cpp index d4aa8c7ccc4..994b5519567 100644 --- a/src/map/lua/luautils.cpp +++ b/src/map/lua/luautils.cpp @@ -43,6 +43,7 @@ #include "lua_trade_container.h" #include "lua_treasure_pool.h" #include "lua_trigger_area.h" +#include "lua_weaponskill.h" #include "lua_zone.h" #include "ai/ai_container.h" @@ -350,6 +351,7 @@ void init(IPP mapIPP, bool isRunningInCI) CLuaLootContainer::Register(); CLuaMobSkill::Register(); CLuaPetSkill::Register(); + CLuaWeaponSkill::Register(); CLuaTriggerArea::Register(); CLuaSpell::Register(); CLuaStatusEffect::Register(); diff --git a/src/map/lua/sol_bindings.cpp b/src/map/lua/sol_bindings.cpp index bbcda081d70..85cbdf98dab 100644 --- a/src/map/lua/sol_bindings.cpp +++ b/src/map/lua/sol_bindings.cpp @@ -102,6 +102,10 @@ SOL_BIND_DEF(CLuaMobSkill, CMobSkill); #include "lua_petskill.h" SOL_BIND_DEF(CLuaPetSkill, CPetSkill); +#include "weapon_skill.h" +#include "lua_weaponskill.h" +SOL_BIND_DEF(CLuaWeaponSkill, CWeaponSkill); + #include "spell.h" #include "lua_spell.h" SOL_BIND_DEF(CLuaSpell, CSpell); diff --git a/src/map/lua/sol_bindings.h b/src/map/lua/sol_bindings.h index 4f8784bcd21..46797ae9762 100644 --- a/src/map/lua/sol_bindings.h +++ b/src/map/lua/sol_bindings.h @@ -146,6 +146,10 @@ class CLuaPetSkill; class CPetSkill; SOL_BIND_DEC(CLuaPetSkill, CPetSkill); +class CLuaWeaponSkillSkill; +class CWeaponSkill; +SOL_BIND_DEC(CLuaWeaponSkill, CWeaponSkill); + class CLuaSpell; class CSpell; SOL_BIND_DEC(CLuaSpell, CSpell);