diff --git a/README.md b/README.md index cda7152..30f13da 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,13 @@ The Forgotten Server is a free and open-source MMORPG server emulator written in ### Features - Attached Effect Support -- Shader Support +- Shader Support (Creature, Item, Map) #### sample ```lua item:setShader() creature:setShader() +player:setMapShader() creature:attachEffectById(, (true | false)) -- Temporary = does not save in character ``` diff --git a/data/creaturescripts/scripts/login.lua b/data/creaturescripts/scripts/login.lua index 076d256..6b4f3c3 100644 --- a/data/creaturescripts/scripts/login.lua +++ b/data/creaturescripts/scripts/login.lua @@ -34,6 +34,7 @@ function onLogin(player) player:attachEffectById(7) player:attachEffectById(8) player:attachEffectById(9, true) -- Temporary Effect + player:setMapShader('Map - Heat', true) end -- Events diff --git a/src/luascript.cpp b/src/luascript.cpp index 3893ed2..8fee35c 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -2858,6 +2858,9 @@ void LuaScriptInterface::registerFunctions() registerMethod("Player", "hasSecureMode", luaPlayerHasSecureMode); registerMethod("Player", "getFightMode", luaPlayerGetFightMode); + registerMethod("Player", "getMapShader", luaPlayerGetMapShader); + registerMethod("Player", "setMapShader", luaPlayerSetMapShader); + // Monster registerClass("Monster", "Creature", luaMonsterCreate); registerMetaMethod("Monster", "__eq", luaUserdataCompare); @@ -17066,3 +17069,38 @@ int LuaScriptInterface::luaCreatureSetShader(lua_State* L) pushBoolean(L, true); return 1; } + + +int LuaScriptInterface::luaPlayerGetMapShader(lua_State* L) +{ + // player:getMapShader() + const auto* player = getUserdata(L, 1); + if (player) { + pushString(L, player->getMapShader()); + } else { + lua_pushnil(L); + } + + return 1; +} + +int LuaScriptInterface::luaPlayerSetMapShader(lua_State* L) +{ + // player:setMapShader(shaderName, [temporary]) + auto* player = getUserdata(L, 1); + if (!player) { + lua_pushnil(L); + return 1; + } + + const auto& shaderName = getString(L, 2); + bool temp = getBoolean(L, 3, false); + + if (!temp) + player->setMapShader(shaderName); + + player->sendMapShader(shaderName); + + pushBoolean(L, true); + return 1; +} \ No newline at end of file diff --git a/src/luascript.h b/src/luascript.h index 4bfbb12..454e3be 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -1044,6 +1044,9 @@ class LuaScriptInterface static int luaPlayerHasSecureMode(lua_State* L); static int luaPlayerGetFightMode(lua_State* L); + static int luaPlayerGetMapShader(lua_State* L); + static int luaPlayerSetMapShader(lua_State* L); + // Monster static int luaMonsterCreate(lua_State* L); diff --git a/src/player.h b/src/player.h index 84ba34f..0c0281e 100644 --- a/src/player.h +++ b/src/player.h @@ -1033,6 +1033,12 @@ class Player final : public Creature, public Cylinder } } + void sendMapShader(const std::string & shaderName) { + if (client) { + client->sendMapShader(shaderName); + } + } + //event methods void onUpdateTileItem(const Tile * tile, const Position & pos, const Item * oldItem, const ItemType & oldType, const Item * newItem, const ItemType & newType) override; @@ -1601,6 +1607,9 @@ class Player final : public Creature, public Cylinder asyncOngoingTasks &= ~flags; } + std::string getMapShader() const { return mapShader; } + void setMapShader(const std::string & shaderName) { mapShader = shaderName; } + private: std::vector getMuteConditions() const; @@ -1679,6 +1688,7 @@ class Player final : public Creature, public Cylinder std::string name; std::string guildNick; + std::string mapShader; Skill skills[SKILL_LAST + 1]; LightInfo itemsLight; diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index b6595d5..1a8e147 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -6637,3 +6637,10 @@ void ProtocolGame::sendShader(const Creature * creature, const std::string & sha playermsg.addString(shaderName); writeToOutputBuffer(playermsg); } + +void ProtocolGame::sendMapShader(const std::string & shaderName) { + playermsg.reset(); + playermsg.addByte(0x37); + playermsg.addString(shaderName); + writeToOutputBuffer(playermsg); +} \ No newline at end of file diff --git a/src/protocolgame.h b/src/protocolgame.h index 34a5374..87fd5d9 100644 --- a/src/protocolgame.h +++ b/src/protocolgame.h @@ -447,6 +447,7 @@ class ProtocolGame final : public Protocol void sendAttachedEffect(const Creature* creature, uint16_t effectId); void sendDetachEffect(const Creature* creature, uint16_t effectId); void sendShader(const Creature* creature, const std::string& shaderName); + void sendMapShader(const std::string& shaderName); //Help functions