From 16e47773cb2858878d5830fee4316338fd67b0bd Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Mon, 15 Apr 2024 22:59:55 -0300 Subject: [PATCH] fixes and removed commented code. --- src/canary_server.cpp | 3 +- .../players/cyclopedia/player_badge.hpp | 4 +- .../players/cyclopedia/player_cyclopedia.cpp | 4 + .../players/cyclopedia/player_cyclopedia.hpp | 7 +- .../players/cyclopedia/player_title.hpp | 1 + src/game/game.cpp | 11 +- src/game/game.hpp | 2 +- src/io/functions/iologindata_load_player.cpp | 1 + .../functions/core/game/game_functions.cpp | 92 -------- .../creatures/player/player_functions.cpp | 219 ------------------ .../creatures/player/player_functions.hpp | 20 -- src/server/network/protocol/protocolgame.cpp | 8 +- 12 files changed, 20 insertions(+), 352 deletions(-) diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 2bf02624a2d..f723e212b4d 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -374,10 +374,9 @@ void CanaryServer::loadModules() { modulesLoadHelper((g_npcs().load(false, true)), "npc"); g_game().loadBoostedCreature(); - // TODO: g_game().initializeCyclopedia(); - // TODO: verify g_game().initializeGameWorldHighscores(); g_ioBosstiary().loadBoostedBoss(); g_ioprey().initializeTaskHuntOptions(); + g_game().getCyclopediaStatistics(); } void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) { diff --git a/src/creatures/players/cyclopedia/player_badge.hpp b/src/creatures/players/cyclopedia/player_badge.hpp index 791fa2cecb5..8078db28f37 100644 --- a/src/creatures/players/cyclopedia/player_badge.hpp +++ b/src/creatures/players/cyclopedia/player_badge.hpp @@ -41,9 +41,9 @@ class PlayerBadge { public: explicit PlayerBadge(Player &player); - bool hasBadge(uint8_t id) const; + [[nodiscard]] bool hasBadge(uint8_t id) const; bool add(uint8_t id, uint32_t timestamp = 0); - std::vector> getUnlockedBadges() const; + [[nodiscard]] std::vector> getUnlockedBadges() const; void loadUnlockedBadges(); const std::shared_ptr &getUnlockedKV(); diff --git a/src/creatures/players/cyclopedia/player_cyclopedia.cpp b/src/creatures/players/cyclopedia/player_cyclopedia.cpp index 04ac4f1ec37..5261d2a2ca5 100644 --- a/src/creatures/players/cyclopedia/player_cyclopedia.cpp +++ b/src/creatures/players/cyclopedia/player_cyclopedia.cpp @@ -18,6 +18,10 @@ PlayerCyclopedia::PlayerCyclopedia(Player &player) : m_player(player) { } +void PlayerCyclopedia::loadSummaryData() { + // todo create player summary +} + void PlayerCyclopedia::addXpBoostsObtained(uint16_t amount) { m_storeXpBoosts += amount; } diff --git a/src/creatures/players/cyclopedia/player_cyclopedia.hpp b/src/creatures/players/cyclopedia/player_cyclopedia.hpp index 48f2e856011..0cb431847b2 100644 --- a/src/creatures/players/cyclopedia/player_cyclopedia.hpp +++ b/src/creatures/players/cyclopedia/player_cyclopedia.hpp @@ -36,9 +36,10 @@ class PlayerCyclopedia { public: explicit PlayerCyclopedia(Player &player); - Summary loadSummary() { + Summary getSummary() { return Summary(m_storeXpBoosts, m_dailyRewardCollections, m_hirelings, m_preyCards, m_charms, m_goshnar, m_drome, m_loginStreak, m_taskHuntingPoints, m_mapAreaDiscoveredPercentage, m_hirelingOutfits, m_hirelingJobs, m_blessings); } + void loadSummaryData(); void addXpBoostsObtained(uint16_t amount); void addRewardCollectionObtained(uint16_t amount); @@ -56,9 +57,9 @@ class PlayerCyclopedia { void addBlessingsObtained(Blessings_t id, uint16_t amount); // void addHouseItemsObtained(uint16_t itemId, uint32_t amount); - std::vector getDeathHistory() const; + [[nodiscard]] std::vector getDeathHistory() const; void insertDeathOnHistory(std::string cause, uint32_t timestamp); - std::vector getPvpKillsHistory() const; + [[nodiscard]] std::vector getPvpKillsHistory() const; void insertPvpKillOnHistory(std::string cause, uint32_t timestamp, uint8_t status); private: diff --git a/src/creatures/players/cyclopedia/player_title.hpp b/src/creatures/players/cyclopedia/player_title.hpp index bef11072a34..6f616db6d2e 100644 --- a/src/creatures/players/cyclopedia/player_title.hpp +++ b/src/creatures/players/cyclopedia/player_title.hpp @@ -76,6 +76,7 @@ namespace std { class PlayerTitle { public: explicit PlayerTitle(Player &player); + [[nodiscard]] bool isTitleUnlocked(uint8_t id) const; bool add(uint8_t id, uint32_t timestamp = 0); [[nodiscard]] std::vector> getUnlockedTitles() const; diff --git a/src/game/game.cpp b/src/game/game.cpp index f40352ff846..3b05387d5d6 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -8221,13 +8221,10 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { void Game::playerFriendSystemAction(std::shared_ptr player, uint8_t type, uint8_t titleId) { uint32_t playerGUID = player->getGUID(); - g_logger().info("ProtocolGame::parseFriendSystemAction 3"); if (type == 0x0E) { - g_logger().info("ProtocolGame::parseFriendSystemAction 4"); player->title()->setCurrentTitle(titleId); player->sendCyclopediaCharacterBaseInformation(); player->sendCyclopediaCharacterTitles(); - // player->sendCyclopediaCharacterTitles(player->title()->getUnlockedTitles()); return; } } @@ -10624,9 +10621,10 @@ std::map Game::getAchievements() { return m_achievements; } -// void Game::initializeCyclopedia() { -// -// } +void Game::getCyclopediaStatistics() { + g_logger().info("Loaded {} badges from Badge System", m_badges.size()); + g_logger().info("Loaded {} titles from Title system", m_titles.size()); +} Badge Game::getBadgeByIdOrName(uint8_t id, const std::string &name /*= ""*/) { if (id == 0 && name.empty()) { @@ -10649,7 +10647,6 @@ Title Game::getTitleByIdOrName(uint8_t id, const std::string &name /*= ""*/) { if (id == 0 && name.empty()) { return {}; } - g_logger().info("title searched: id {}, name {}", id, name); auto it = std::find_if(m_titles.begin(), m_titles.end(), [id, name](const Title &t) { return id != 0 ? t.m_id == id : t.m_maleName == name; }); diff --git a/src/game/game.hpp b/src/game/game.hpp index 0d4266e04f6..8cc84900df2 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -100,7 +100,7 @@ class Game { void forceRemoveCondition(uint32_t creatureId, ConditionType_t type, ConditionId_t conditionId); - // void initializeCyclopedia(); + void getCyclopediaStatistics(); /** * Load the main map diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 55174b5be44..03b1872bf9b 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -891,6 +891,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) player->achiev()->loadUnlockedAchievements(); player->badge()->loadUnlockedBadges(); player->title()->loadUnlockedTitles(); + player->cyclopedia()->loadSummaryData(); player->initializePrey(); player->initializeTaskHunting(); diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 3663505076f..4bf9e865805 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -907,95 +907,3 @@ int GameFunctions::luaGameGetAchievements(lua_State* L) { } return 1; } - -// int GameFunctions::luaGameGetAllMounts(lua_State *L) { -// // Game.getMounts() -// const auto &mounts = g_game().mounts.getMounts(); -// int index = 0; -// lua_createtable(L, mounts.size(), 0); -// for (const auto &mount: mounts) { -// lua_createtable(L, 0, 6); -// setField(L, "id", mount->id); -// setField(L, "clientId", mount->clientId); -// setField(L, "name", mount->name); -// setField(L, "speed", mount->speed); -// setField(L, "premium", mount->premium); -// setField(L, "type", mount->type); -// lua_rawseti(L, -2, ++index); -// } -// return 1; -// } -// -// int GameFunctions::luaGameGetAllOutfits(lua_State *L) { -// // Game.getOutfits(sex) -// int index = 0; -// const auto &outfits = Outfits::getInstance().getOutfits(static_cast(getNumber(L, 1, 1))); -// lua_createtable(L, outfits.size(), 0); -// for (const auto &outfit: outfits) { -// lua_createtable(L, 0, 5); -// setField(L, "lookType", outfit->lookType); -// setField(L, "name", outfit->name); -// setField(L, "unlocked", outfit->unlocked); -// setField(L, "premium", outfit->premium); -// setField(L, "from", outfit->from); -// lua_rawseti(L, -2, ++index); -// } -// return 1; -// } - -// 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; -// auto race = static_cast(getNumber(L, 1, 0)); -// for (const auto &mType_it: g_game().getBestiaryList()) { -// if (std::shared_ptr mType = g_monsters().getMonsterType(mType_it.second); -// mType && mType->info.bestiaryRace == race) { -// entries++; -// } -// } -// -// lua_pushnumber(L, entries); -// return 1; -// } - -// int GameFunctions::luaGameRegisterBadge(lua_State* L) { -// // Game.registerBadge(id, name, amount) -// if (lua_gettop(L) < 2) { -// reportErrorFunc("Badge can only be registered with all params."); -// lua_pushnil(L); -// } else { -// g_game().registerBadge(getNumber(L, 1), getString(L, 2), getNumber(L, 3)); -// pushBoolean(L, true); -// } -// return 1; -// } -// -// int GameFunctions::luaGameRegisterTitle(lua_State* L) { -// // Game.registerTitle(id, maleName, femaleName, type, description, permanent) -// if (lua_gettop(L) < 5) { -// reportErrorFunc("Title can only be registered with all params."); -// lua_pushnil(L); -// } else { -// uint16_t id = getNumber(L, 1); -// std::string maleName = getString(L, 2); -// std::string femaleName = getString(L, 3); -// std::string type = getString(L, 4); -// std::string description = getString(L, 5); -// bool permanent = getBoolean(L, 6); -// g_game().registerTitle(id, maleName, femaleName, type, description, permanent); -// pushBoolean(L, true); -// } -// return 1; -// } diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 7ec9fa517aa..853bc4aac04 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -4346,222 +4346,3 @@ int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) { pushBoolean(L, true); return 1; } - -// int PlayerFunctions::luaPlayerAddHirelingOutfitObtained(lua_State* L) { -// // player:addHirelingOutfitObtained(lookType) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addHirelingOutfitObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddHirelingJobsObtained(lua_State* L) { -// // player:addHirelingJobsObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addHirelingJobsObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddBlessingsObtained(lua_State* L) { -// // player:addBlessingsObtained(id, amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addBlessingsObtained(static_cast(getNumber(L, 2)), getNumber(L, 3)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddHouseItemsObtained(lua_State* L) { -// // player:addHouseItemsObtained(id, amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addHouseItemsObtained(getNumber(L, 2), getNumber(L, 3)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddXpBoostsObtained(lua_State* L) { -// // player:addXpBoostsObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addXpBoostsObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddRewardCollectionObtained(lua_State* L) { -// // player:addRewardCollectionObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addRewardCollectionObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddHirelingsObtained(lua_State* L) { -// // player:addHirelingsObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addHirelingsObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddPreyCardsObtained(lua_State* L) { -// // player:addPreyCardsObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addPreyCardsObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddLoginStreak(lua_State* L) { -// // player:addLoginStreak(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addLoginStreak(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddTaskHuntingPointsObtained(lua_State* L) { -// // player:addTaskHuntingPointsObtained(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addTaskHuntingPointsObtained(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerAddMapAreaDiscoveredPercentage(lua_State* L) { -// // player:addMapAreaDiscoveredPercentage(amount) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// player->addMapAreaDiscoveredPercentage(getNumber(L, 2)); -// pushBoolean(L, true); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerGetBestiaryRaceEntries(lua_State* L) { -// // player:getBestiaryRaceEntries(race) -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// lua_pushnumber(L, g_iobestiary().getBestiaryRaceUnlocked(player, static_cast(getNumber(L, 2, 0)))); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerGetLoginStreak(lua_State* L) { -// // player:getLoginStreak() -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// lua_pushnumber(L, player->getLoginStreak()); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerGetTaskHuntingPointsObtained(lua_State* L) { -// // player:getTaskHuntingPointsObtained() -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// lua_pushnumber(L, player->getTaskHuntingPointsObtained()); -// return 1; -// } -// -// int PlayerFunctions::luaPlayerGetMapAreaDiscoveredPercentage(lua_State* L) { -// // player:getMapAreaDiscoveredPercentage() -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// lua_pushnumber(L, player->getMapAreaDiscoveredPercentage()); -// return 1; -// } -// - -// int PlayerFunctions::luaPlayerGetAccountLevelVocation(lua_State* L) { -// // player:getAccountLevelVocation() -// Player* player = getUserdata(L, 1); -// if (!player) { -// lua_pushnil(L); -// return 1; -// } -// -// int index = 0; -// int size = 0; -// std::map> accountData = player->getAccountLevelVocation(); -// for (const auto data : accountData) { -// size += data.second.size(); -// } -// -// lua_createtable(L, size, 0); -// for (const auto data : accountData) { -// for (const auto level : data.second) { -// lua_createtable(L, 0, 2); -// setField(L, "vocation", data.first); -// setField(L, "level", level); -// lua_rawseti(L, -2, ++index); -// } -// } -// return 1; -// } diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index e638bed91a2..588b2ed4c5d 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -749,25 +749,5 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerGetTitles(lua_State* L); static int luaPlayerSetCurrentTitle(lua_State* L); - // static int luaPlayerAddHirelingOutfitObtained(lua_State* L); - // static int luaPlayerAddHirelingJobsObtained(lua_State* L); - // static int luaPlayerAddBlessingsObtained(lua_State* L); - // static int luaPlayerAddHouseItemsObtained(lua_State* L); - // static int luaPlayerAddXpBoostsObtained(lua_State* L); - // static int luaPlayerAddRewardCollectionObtained(lua_State* L); - // static int luaPlayerAddHirelingsObtained(lua_State* L); - // static int luaPlayerAddPreyCardsObtained(lua_State* L); - // static int luaPlayerAddLoginStreak(lua_State* L); - // static int luaPlayerAddTaskHuntingPointsObtained(lua_State* L); - // static int luaPlayerAddMapAreaDiscoveredPercentage(lua_State* L); - // - // static int luaPlayerGetLoginStreak(lua_State* L); - // static int luaPlayerGetTaskHuntingPointsObtained(lua_State* L); - // static int luaPlayerGetMapAreaDiscoveredPercentage(lua_State* L); - // - // static int luaPlayerGetBestiaryRaceEntries(lua_State* L); - // - // static int luaPlayerGetAccountLevelVocation(lua_State* L); - friend class CreatureFunctions; }; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 5aa6dbed992..5d12bb0eebb 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2058,10 +2058,8 @@ void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, std::s } void ProtocolGame::parseFriendSystemAction(NetworkMessage &msg) { - g_logger().info("ProtocolGame::parseFriendSystemAction 1"); uint8_t state = msg.getByte(); if (state == 0x0E) { - g_logger().info("ProtocolGame::parseFriendSystemAction 2"); uint8_t titleId = msg.getByte(); g_game().playerFriendSystemAction(player, state, titleId); } @@ -3836,7 +3834,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { msg.add(player->getExpBoostStamina()); // Remaining Store Xp Boost Time msg.add(0); // RemainingDailyRewardXpBoostTime - auto cyclopediaSummary = player->cyclopedia()->loadSummary(); + auto cyclopediaSummary = player->cyclopedia()->getSummary(); auto blessings = player->getBlessingNames(); msg.addByte(static_cast(blessings.size())); // getBlessingsObtained @@ -4027,15 +4025,13 @@ void ProtocolGame::sendCyclopediaCharacterTitles() { if (!player || oldProtocol) { return; } - g_logger().info("ProtocolGame::addBytes - sendCyclopediaCharacterTitles"); + auto titles = g_game().getTitles(); - g_logger().info("ProtocolGame::sendCyclopediaCharacterTitles - titles size: {}", titles.size()); NetworkMessage msg; msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_TITLES); msg.addByte(0x00); // 0x00 Here means 'no error' - msg.addByte(player->title()->getCurrentTitle()); msg.addByte(static_cast(titles.size())); std::string messageTitleName = "ProtocolGame::sendCyclopediaCharacterTitles - title.name";