Skip to content

Commit

Permalink
fixes merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed May 7, 2024
1 parent 5bc7d47 commit 6ebf1ad
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ 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().logCyclopediaStats();
Expand Down
1 change: 1 addition & 0 deletions src/creatures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_sources(${PROJECT_NAME}_lib PRIVATE
players/player.cpp
players/achievement/player_achievement.cpp
players/cyclopedia/player_badge.cpp
players/cyclopedia/player_title.cpp
players/wheel/player_wheel.cpp
players/wheel/wheel_gems.cpp
players/vocations/vocation.cpp
Expand Down
18 changes: 9 additions & 9 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool PlayerTitle::add(uint8_t id, uint32_t timestamp /* = 0*/) {
return false;
}

const Title &title = g_game().getTitleByIdOrName(id);
const Title &title = g_game().getTitleById(id);
if (title.m_id == 0) {
return false;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ std::string PlayerTitle::getCurrentTitleName() const {
return "";
}

auto title = g_game().getTitleByIdOrName(currentTitle);
auto title = g_game().getTitleById(currentTitle);
if (title.m_id == 0) {
return "";
}
Expand Down Expand Up @@ -103,9 +103,9 @@ void PlayerTitle::checkAndUpdateNewTitles() {
}
break;
case CyclopediaTitle_t::HIGHSCORES:
// if (checkHighscore(title.m_skill)) {
// add(title.m_id);
// }
// if (checkHighscore(title.m_skill)) {
// add(title.m_id);
// }
break;
case CyclopediaTitle_t::BESTIARY:
if (checkBestiary(title.m_race)) {
Expand All @@ -123,9 +123,9 @@ void PlayerTitle::checkAndUpdateNewTitles() {
}
break;
case CyclopediaTitle_t::MAP:
// if (checkMap(title.m_amount)) {
// add(title.m_id);
// }
// if (checkMap(title.m_amount)) {
// add(title.m_id);
// }
break;
case CyclopediaTitle_t::QUEST:
if (checkQuest(title.m_storage)) {
Expand All @@ -149,7 +149,7 @@ void PlayerTitle::loadUnlockedTitles() {
const auto &unlockedTitles = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size());
for (const auto &titleName : unlockedTitles) {
const Title &title = g_game().getTitleByIdOrName(0, titleName);
const Title &title = g_game().getTitleByName(titleName);
if (title.m_id == 0) {
g_logger().error("[{}] - Title {} not found.", __FUNCTION__, titleName);
continue;
Expand Down
15 changes: 14 additions & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"
#include "creatures/players/storages/storages.hpp"
#include "game/game.hpp"
#include "game/modal_window/modal_window.hpp"
Expand Down Expand Up @@ -51,6 +52,7 @@ Player::Player(ProtocolGame_ptr p) :
m_wheelPlayer = std::make_unique<PlayerWheel>(*this);
m_playerAchievement = std::make_unique<PlayerAchievement>(*this);
m_playerBadge = std::make_unique<PlayerBadge>(*this);
m_playerTitle = std::make_unique<PlayerTitle>(*this);
}

Player::~Player() {
Expand Down Expand Up @@ -121,7 +123,7 @@ std::string Player::getDescription(int32_t lookDistance) {
capitalizeWords(subjectPronoun);

if (lookDistance == -1) {
s << "yourself.";
s << "yourself" << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName())) << ".";

if (group->access) {
s << " You are " << group->name << '.';
Expand All @@ -144,6 +146,8 @@ std::string Player::getDescription(int32_t lookDistance) {
s << " (Level " << level << ')';
}

s << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName()));

s << ". " << subjectPronoun;

if (group->access) {
Expand Down Expand Up @@ -7968,6 +7972,15 @@ const std::unique_ptr<PlayerBadge> &Player::badge() const {
return m_playerBadge;
}

// Title interface
std::unique_ptr<PlayerTitle> &Player::title() {
return m_playerTitle;
}

const std::unique_ptr<PlayerTitle> &Player::title() const {
return m_playerTitle;
}

void Player::sendLootMessage(const std::string &message) const {
auto party = getParty();
if (!party) {
Expand Down
9 changes: 9 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "game/bank/bank.hpp"
#include "enums/object_category.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"

class House;
class NetworkMessage;
Expand All @@ -51,12 +52,14 @@ class Spell;
class PlayerWheel;
class PlayerAchievement;
class PlayerBadge;
class PlayerTitle;
class Spectators;
class Account;

struct ModalWindow;
struct Achievement;
struct Badge;
struct Title;

struct ForgeHistory {
ForgeAction_t actionType = ForgeAction_t::FUSION;
Expand Down Expand Up @@ -2609,6 +2612,10 @@ class Player final : public Creature, public Cylinder, public Bankable {
std::unique_ptr<PlayerBadge> &badge();
const std::unique_ptr<PlayerBadge> &badge() const;

// Player title interface
std::unique_ptr<PlayerTitle> &title();
const std::unique_ptr<PlayerTitle> &title() const;

void sendLootMessage(const std::string &message) const;

std::shared_ptr<Container> getLootPouch();
Expand Down Expand Up @@ -3005,10 +3012,12 @@ class Player final : public Creature, public Cylinder, public Bankable {
friend class IOLoginDataSave;
friend class PlayerAchievement;
friend class PlayerBadge;
friend class PlayerTitle;

std::unique_ptr<PlayerWheel> m_wheelPlayer;
std::unique_ptr<PlayerAchievement> m_playerAchievement;
std::unique_ptr<PlayerBadge> m_playerBadge;
std::unique_ptr<PlayerTitle> m_playerTitle;

std::mutex quickLootMutex;

Expand Down
40 changes: 35 additions & 5 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"
#include "creatures/npcs/npc.hpp"
#include "server/network/webhook/webhook.hpp"
#include "server/network/protocol/protocollogin.hpp"
Expand Down Expand Up @@ -8246,10 +8247,9 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) {
void Game::playerFriendSystemAction(std::shared_ptr<Player> player, uint8_t type, uint8_t titleId) {
uint32_t playerGUID = player->getGUID();
if (type == 0x0E) {
// todo in titles system PR
// player->title()->setCurrentTitle(titleId);
// player->sendCyclopediaCharacterBaseInformation();
// player->sendCyclopediaCharacterTitles();
player->title()->setCurrentTitle(titleId);
player->sendCyclopediaCharacterBaseInformation();
player->sendCyclopediaCharacterTitles();
return;
}
}
Expand Down Expand Up @@ -10645,7 +10645,7 @@ std::map<uint16_t, Achievement> Game::getAchievements() {

void Game::logCyclopediaStats() {
g_logger().info("Loaded {} badges from Badge System", m_badges.size());
// todo in title system: g_logger().info("Loaded {} titles from Title system", m_titles.size());
g_logger().info("Loaded {} titles from Title system", m_titles.size());
}

std::unordered_set<Badge> Game::getBadges() {
Expand Down Expand Up @@ -10677,3 +10677,33 @@ Badge Game::getBadgeByName(const std::string &name) {
}
return {};
}

std::unordered_set<Title> Game::getTitles() {
return m_titles;
}

Title Game::getTitleById(uint8_t id) {
if (id == 0) {
return {};
}
auto it = std::find_if(m_titles.begin(), m_titles.end(), [id](const Title &t) {
return t.m_id == id;
});
if (it != m_titles.end()) {
return *it;
}
return {};
}

Title Game::getTitleByName(const std::string &name) {
if (name.empty()) {
return {};
}
auto it = std::find_if(m_titles.begin(), m_titles.end(), [name](const Title &t) {
return t.m_maleName == name;
});
if (it != m_titles.end()) {
return *it;
}
return {};
}
5 changes: 4 additions & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Spectators;
struct Achievement;
struct HighscoreCategory;
struct Badge;
struct Title;

static constexpr uint16_t SERVER_BEAT = 0x32;
static constexpr int32_t EVENT_MS = 10000;
Expand Down Expand Up @@ -727,13 +728,15 @@ class Game {
Badge getBadgeByName(const std::string &name);

std::unordered_set<Title> getTitles();
Title getTitleByIdOrName(uint8_t id, const std::string &name = "");
Title getTitleById(uint8_t id);
Title getTitleByName(const std::string &name);

private:
std::map<uint16_t, Achievement> m_achievements;
std::map<std::string, uint16_t> m_achievementsNameToId;

std::unordered_set<Badge> m_badges;
std::unordered_set<Title> m_titles;

std::vector<HighscoreCategory> m_highscoreCategories;
std::unordered_map<uint8_t, std::string> m_highscoreCategoriesNames;
Expand Down
2 changes: 1 addition & 1 deletion src/game/game_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum CyclopediaBadge_t : uint8_t {
TOURNAMENT_POINTS,
};

enum class CyclopediaTitle_t : uint8_t {
enum CyclopediaTitle_t : uint8_t {
NOTHING = 0,
GOLD,
MOUNTS,
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "lua/callbacks/events_callbacks.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"
#include "map/spectators.hpp"

// Game
Expand Down
52 changes: 52 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"
#include "game/game.hpp"
#include "io/iologindata.hpp"
#include "io/ioprey.hpp"
Expand Down Expand Up @@ -4293,3 +4294,54 @@ int PlayerFunctions::luaPlayerAddBadge(lua_State* L) {
pushBoolean(L, true);
return 1;
}

int PlayerFunctions::luaPlayerAddTitle(lua_State* L) {
// player:addTitle(id)
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
return 1;
}

player->title()->add(getNumber<uint8_t>(L, 2, 0));
pushBoolean(L, true);
return 1;
}

int PlayerFunctions::luaPlayerGetTitles(lua_State* L) {
// player:getTitles()
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
return 1;
}

auto playerTitles = player->title()->getUnlockedTitles();
lua_createtable(L, static_cast<int>(playerTitles.size()), 0);

int index = 0;
for (auto title : playerTitles) {
lua_pushnumber(L, title.first.m_id);
lua_rawseti(L, -2, ++index);
}
return 1;
}

int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) {
// player:setCurrentTitle(id)
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
return 1;
}

const auto &title = g_game().getTitleByIdOrName(getNumber<uint8_t>(L, 2, 0));
if (title.m_id == 0) {
reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND));
return 1;
}

player->title()->setCurrentTitle(title.m_id);
pushBoolean(L, true);
return 1;
}
9 changes: 9 additions & 0 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ class PlayerFunctions final : LuaScriptInterface {
// Badge Functions
registerMethod(L, "Player", "addBadge", PlayerFunctions::luaPlayerAddBadge);

// Title Functions
registerMethod(L, "Player", "addTitle", PlayerFunctions::luaPlayerAddTitle);
registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles);
registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle);

GroupFunctions::init(L);
GuildFunctions::init(L);
MountFunctions::init(L);
Expand Down Expand Up @@ -723,5 +728,9 @@ class PlayerFunctions final : LuaScriptInterface {

static int luaPlayerAddBadge(lua_State* L);

static int luaPlayerAddTitle(lua_State* L);
static int luaPlayerGetTitles(lua_State* L);
static int luaPlayerSetCurrentTitle(lua_State* L);

friend class CreatureFunctions;
};
Loading

0 comments on commit 6ebf1ad

Please sign in to comment.