Skip to content

Commit

Permalink
feat: map shader support
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Apr 28, 2023
1 parent 4072489 commit 148baaa
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -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(<shader name>)
creature:setShader(<shader name>)
player:setMapShader(<shader name>)
creature:attachEffectById(<effect id>, <temporary>(true | false)) -- Temporary = does not save in character
```

Expand Down
1 change: 1 addition & 0 deletions data/creaturescripts/scripts/login.lua
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/luascript.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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<const Player>(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<Player>(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;
}
3 changes: 3 additions & 0 deletions src/luascript.h
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/player.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Condition*> getMuteConditions() const;

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/protocolgame.cpp
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/protocolgame.h
Expand Up @@ -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

Expand Down

0 comments on commit 148baaa

Please sign in to comment.