diff --git a/CMakePresets.json b/CMakePresets.json index 92ef2d33c6a..5a0f11945e5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,7 +14,7 @@ "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "BUILD_STATIC_LIBRARY": "ON", - "SPEED_UP_BUILD_UNITY": "ON", + "SPEED_UP_BUILD_UNITY": "OFF", "OPTIONS_ENABLE_SCCACHE": "ON", "CMAKE_BUILD_TYPE": "RelWithDebInfo" } diff --git a/data/scripts/talkactions/god/add_skill.lua b/data/scripts/talkactions/god/add_skill.lua index f1c6244fba6..3dc8b4153fa 100644 --- a/data/scripts/talkactions/god/add_skill.lua +++ b/data/scripts/talkactions/god/add_skill.lua @@ -44,8 +44,7 @@ function addSkill.onSay(player, words, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Trim left local count = 1 if split[3] then diff --git a/data/scripts/talkactions/god/charms.lua b/data/scripts/talkactions/god/charms.lua index 14dde0a58d7..75d324cf4f1 100644 --- a/data/scripts/talkactions/god/charms.lua +++ b/data/scripts/talkactions/god/charms.lua @@ -19,8 +19,8 @@ function addCharm.onSay(player, words, param) player:sendCancelMessage("A player with that name is not online.") return true end - --trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + + split[2] = split[2]:trimSpace() -- Trim left player:sendCancelMessage("Added " .. split[2] .. " charm points to character '" .. target:getName() .. "'.") target:sendCancelMessage("Received " .. split[2] .. " charm points!") @@ -133,8 +133,8 @@ function setBestiary.onSay(player, words, param) return true end - split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left - split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left + split[2] = split[2]:trimSpace() --Trim left + split[3] = split[3]:trimSpace() --Trim left local monsterName = split[2] local mType = MonsterType(monsterName) diff --git a/data/scripts/talkactions/god/create_monster.lua b/data/scripts/talkactions/god/create_monster.lua index 924a0d0906d..44ee5c6fb86 100644 --- a/data/scripts/talkactions/god/create_monster.lua +++ b/data/scripts/talkactions/god/create_monster.lua @@ -73,20 +73,20 @@ function createMonster.onSay(player, words, param) local monsterName = split[1] local monsterCount = 0 if split[2] then - split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left + split[2] = split[2]:trimSpace() -- Trim left monsterCount = tonumber(split[2]) end local monsterForge = nil if split[3] then - split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left + split[3] = split[3]:trimSpace() -- Trim left monsterForge = split[3] end if monsterCount > 1 then local spawnRadius = 5 if split[4] then - split[4] = split[4]:gsub("^%s*(.-)$", "%1") --Trim left + split[4] = split[4]:trimSpace() -- Trim left spawnRadius = split[4] print(spawnRadius) end diff --git a/data/scripts/talkactions/god/manage_badge.lua b/data/scripts/talkactions/god/manage_badge.lua index f2899a0d592..bf65eff583a 100644 --- a/data/scripts/talkactions/god/manage_badge.lua +++ b/data/scripts/talkactions/god/manage_badge.lua @@ -21,8 +21,7 @@ function addBadge.onSay(player, words, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Trim left local id = tonumber(split[2]) target:addBadge(id) return true diff --git a/data/scripts/talkactions/god/manage_storage.lua b/data/scripts/talkactions/god/manage_storage.lua index 929ef7b4417..23f2798dc26 100644 --- a/data/scripts/talkactions/god/manage_storage.lua +++ b/data/scripts/talkactions/god/manage_storage.lua @@ -18,8 +18,7 @@ function Player.getStorageValueTalkaction(self, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Trim left -- Try to convert the second parameter to a number. If it's not a number, treat it as a storage name local storageKey = tonumber(split[2]) diff --git a/data/scripts/talkactions/god/manage_title.lua b/data/scripts/talkactions/god/manage_title.lua index cb4fb9acb29..0d14e8be77a 100644 --- a/data/scripts/talkactions/god/manage_title.lua +++ b/data/scripts/talkactions/god/manage_title.lua @@ -21,8 +21,7 @@ function addTitle.onSay(player, words, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Trim left local id = tonumber(split[2]) target:addTitle(id) return true @@ -56,8 +55,7 @@ function setTitle.onSay(player, words, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Trim left local id = tonumber(split[2]) target:setCurrentTitle(id) return true diff --git a/src/creatures/players/cyclopedia/player_badge.hpp b/src/creatures/players/cyclopedia/player_badge.hpp index 01c9dc0e63f..7bf28c0c302 100644 --- a/src/creatures/players/cyclopedia/player_badge.hpp +++ b/src/creatures/players/cyclopedia/player_badge.hpp @@ -9,7 +9,7 @@ #pragma once -#include "game/game_definitions.hpp" +#include "enums/player_cyclopedia.hpp" class Player; class KV; diff --git a/src/creatures/players/cyclopedia/player_title.cpp b/src/creatures/players/cyclopedia/player_title.cpp index fe6faeaa3d7..82f4f1cfa55 100644 --- a/src/creatures/players/cyclopedia/player_title.cpp +++ b/src/creatures/players/cyclopedia/player_title.cpp @@ -51,7 +51,7 @@ bool PlayerTitle::add(uint8_t id, uint32_t timestamp /* = 0*/) { return true; } -std::vector> PlayerTitle::getUnlockedTitles() const { +const std::vector> &PlayerTitle::getUnlockedTitles() { return m_titlesUnlocked; } @@ -196,7 +196,6 @@ bool PlayerTitle::checkLevel(uint32_t amount) { bool PlayerTitle::checkHighscore(uint8_t skill) { // todo cyclopledia return false; - // return g_game().getH() m_player.getLevel() >= amount; } bool PlayerTitle::checkBestiary(uint16_t race) { @@ -223,7 +222,7 @@ bool PlayerTitle::checkQuest(TitleStorage storage) { : m_player.getStorageValue(storage.key) == storage.value; } -bool PlayerTitle::checkOther(std::string name) { +bool PlayerTitle::checkOther(const std::string &name) { if (name == "Admirer of the Crown") { // todo return false; @@ -241,30 +240,3 @@ bool PlayerTitle::checkOther(std::string name) { } return false; } - -/*int GameFunctions::luaGameGetHighscoresLeaderId(lua_State* L) { -// Game.getHighscoresLeaderId(skill) -const auto highscoreVector = g_game().getHighscoreByCategory(static_cast(getNumber(L, 1, 0))); -if (highscoreVector.size() != 0) { - lua_pushnumber(L, highscoreVector.front().id); -} else { - lua_pushnumber(L, 0); -} - -return 1; -} - -int GameFunctions::luaGameGetBestiaryRaceAmount(lua_State* L) { -// Game.getBestiaryRaceAmount(race) -uint16_t entries = 0; -BestiaryType_t race = static_cast(getNumber(L, 1, 0)); -for (const auto mType_it : g_game().getBestiaryList()) { - if (const MonsterType *mType = g_monsters().getMonsterType(mType_it.second); - mType && mType->info.bestiaryRace == race) { - entries++; - } -} - -lua_pushnumber(L, entries); -return 1; -}*/ diff --git a/src/creatures/players/cyclopedia/player_title.hpp b/src/creatures/players/cyclopedia/player_title.hpp index 19c1c650235..6ebb2ad4c79 100644 --- a/src/creatures/players/cyclopedia/player_title.hpp +++ b/src/creatures/players/cyclopedia/player_title.hpp @@ -11,7 +11,7 @@ #include -#include "game/game_definitions.hpp" +#include "enums/player_cyclopedia.hpp" class Player; class KV; @@ -83,7 +83,7 @@ class PlayerTitle { [[nodiscard]] bool isTitleUnlocked(uint8_t id) const; bool add(uint8_t id, uint32_t timestamp = 0); - [[nodiscard]] std::vector> getUnlockedTitles() const; + const std::vector> &getUnlockedTitles(); [[nodiscard]] uint8_t getCurrentTitle() const; void setCurrentTitle(uint8_t id); [[nodiscard]] std::string getCurrentTitleName() const; @@ -102,7 +102,7 @@ class PlayerTitle { bool checkTask(uint32_t amount); bool checkMap(uint32_t amount); bool checkQuest(TitleStorage storage); - bool checkOther(std::string name); + bool checkOther(const std::string &name); private: // {title ID, time when it was unlocked} diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 17f4d10b2de..d220a1f7811 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -121,9 +121,10 @@ std::string Player::getDescription(int32_t lookDistance) { std::ostringstream s; std::string subjectPronoun = getSubjectPronoun(); capitalizeWords(subjectPronoun); + auto playerTitle = title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName()); if (lookDistance == -1) { - s << "yourself" << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName())) << "."; + s << "yourself" << playerTitle << "."; if (group->access) { s << " You are " << group->name << '.'; @@ -146,9 +147,7 @@ std::string Player::getDescription(int32_t lookDistance) { s << " (Level " << level << ')'; } - s << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName())); - - s << ". " << subjectPronoun; + s << playerTitle << ". " << subjectPronoun; if (group->access) { s << " " << getSubjectVerb() << " " << group->name << '.'; diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index a54c458bf76..24d0360f3bf 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -34,6 +34,7 @@ #include "creatures/npcs/npc.hpp" #include "game/bank/bank.hpp" #include "enums/object_category.hpp" +#include "enums/player_cyclopedia.hpp" #include "creatures/players/cyclopedia/player_badge.hpp" #include "creatures/players/cyclopedia/player_title.hpp" diff --git a/src/enums/player_cyclopedia.hpp b/src/enums/player_cyclopedia.hpp new file mode 100644 index 00000000000..2edcd988310 --- /dev/null +++ b/src/enums/player_cyclopedia.hpp @@ -0,0 +1,38 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#ifndef USE_PRECOMPILED_HEADERS + #include +#endif + +enum CyclopediaBadge_t : uint8_t { + ACCOUNT_AGE = 1, + LOYALTY, + ACCOUNT_ALL_LEVEL, + ACCOUNT_ALL_VOCATIONS, + TOURNAMENT_PARTICIPATION, + TOURNAMENT_POINTS, +}; + +enum CyclopediaTitle_t : uint8_t { + NOTHING = 0, + GOLD, + MOUNTS, + OUTFITS, + LEVEL, + HIGHSCORES, + BESTIARY, + LOGIN, + TASK, + MAP, + QUEST, + OTHERS, +}; diff --git a/src/game/game_definitions.hpp b/src/game/game_definitions.hpp index ea1622c494a..084cd98ab2a 100644 --- a/src/game/game_definitions.hpp +++ b/src/game/game_definitions.hpp @@ -61,30 +61,6 @@ enum LightState_t { LIGHT_STATE_SUNRISE, }; -enum CyclopediaBadge_t : uint8_t { - ACCOUNT_AGE = 1, - LOYALTY, - ACCOUNT_ALL_LEVEL, - ACCOUNT_ALL_VOCATIONS, - TOURNAMENT_PARTICIPATION, - TOURNAMENT_POINTS, -}; - -enum CyclopediaTitle_t : uint8_t { - NOTHING = 0, - GOLD, - MOUNTS, - OUTFITS, - LEVEL, - HIGHSCORES, - BESTIARY, - LOGIN, - TASK, - MAP, - QUEST, - OTHERS, -}; - enum CyclopediaCharacterInfoType_t : uint8_t { CYCLOPEDIA_CHARACTERINFO_BASEINFORMATION = 0, CYCLOPEDIA_CHARACTERINFO_GENERALSTATS = 1, diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 5858e3de560..250599705f9 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -4320,7 +4320,7 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { lua_createtable(L, static_cast(playerTitles.size()), 0); int index = 0; - for (auto title : playerTitles) { + for (const auto &title : playerTitles) { lua_pushnumber(L, title.first.m_id); lua_rawseti(L, -2, ++index); } diff --git a/src/server/server_definitions.hpp b/src/server/server_definitions.hpp index 3223b077bf0..b689f77eaee 100644 --- a/src/server/server_definitions.hpp +++ b/src/server/server_definitions.hpp @@ -120,7 +120,7 @@ struct HighscoreCharacter { rank(rank), level(level), vocation(vocation), - title(title) { } + title(std::move(title)) { } std::string name; uint64_t points;