Skip to content

Commit

Permalink
badge & title system: fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Apr 12, 2024
1 parent fd8981d commit eea4844
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
22 changes: 11 additions & 11 deletions data/scripts/lib/register_titles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ Functions:
TitleSystem:questFunction(player, storage, isKv)
]]

for _, titleTable in pairs(TITLES) do
if type(titleTable) == "table" and #titleTable > 0 then
for __, item in pairs(titleTable) do
if item.id then
local title = not item.names and { male = item.name, female = item.name } or { male = item.names.male, female = item.names.female }
logger.trace("[Title System registration] - Registering title '{}' with id '{}'", title.male, title.id)
Game.registerTitle(item.id, title.male, title.female, item.description, item.permanent)
end
end
end
end
--for _, titleTable in pairs(TITLES) do
-- if type(titleTable) == "table" and #titleTable > 0 then
-- for __, item in pairs(titleTable) do
-- if item.id then
-- local title = not item.names and { male = item.name, female = item.name } or { male = item.names.male, female = item.names.female }
-- logger.trace("[Title System registration] - Registering title '{}' with id '{}'", title.male, title.id)
-- Game.registerTitle(item.id, title.male, title.female, item.description, item.permanent)
-- end
-- end
-- end
--end

---- Gold section
--TitleSystem.goldFunction = function(player, amount)
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool PlayerTitle::isTitleUnlocked(uint8_t id) const {
}

if (auto it = std::find_if(m_titlesUnlocked.begin(), m_titlesUnlocked.end(), [id](auto title_it) {
return title_it == id;
return title_it.first == id;
});
it != m_titlesUnlocked.end()) {
return true;
Expand Down Expand Up @@ -81,7 +81,7 @@ void PlayerTitle::loadUnlockedTitles() {
g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size());
for (const auto &uTitle : unlockedTitles) {
auto id = static_cast<uint8_t>(std::stoul(uTitle));
const Title &title = g_game().getTitleById(static_cast<uint8_t>(id));
const Title &title = g_game().getTitleById(id);
if (title.m_id == 0) {
g_logger().error("[{}] - Title {} not found.", __FUNCTION__, uTitle);
continue;
Expand Down
9 changes: 3 additions & 6 deletions src/creatures/players/cyclopedia/player_title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ struct TitleStorage {
};

struct Title {
uint8_t m_id;
CyclopediaTitleType_t m_type;
uint8_t m_id = 0;
CyclopediaTitleType_t m_type = CyclopediaTitleType_t::NOTHING;
std::string m_maleName;
std::string m_femaleName = "";
std::string m_femaleName;
std::string m_description;
uint32_t m_amount = 0;
bool m_permanent = false;
Expand All @@ -37,9 +37,6 @@ struct Title {

Title() = default;

Title(uint8_t id, CyclopediaTitleType_t type, const std::string &maleName, const std::string &description, uint32_t amount) :
m_id(id), m_type(type), m_maleName(maleName), m_description(description), m_amount(amount) { }

Title(uint8_t id, CyclopediaTitleType_t type, const std::string &maleName, const std::string &description, uint32_t amount, bool permanent) :
m_id(id), m_type(type), m_maleName(maleName), m_description(description), m_amount(amount),
m_permanent(permanent) { }
Expand Down
14 changes: 7 additions & 7 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ std::string Player::getDescription(int32_t lookDistance) {
s << " You are a " << loyaltyTitle << ".";
}

if (summary()->getCurrentTitle() != 0) {
s << " You are a " << summary()->getCurrentTitleName() << ".";
if (title()->getCurrentTitle() != 0) {
s << " You are a " << title()->getCurrentTitleName() << ".";
}

if (isVip()) {
Expand Down Expand Up @@ -171,8 +171,8 @@ std::string Player::getDescription(int32_t lookDistance) {
s << " " << subjectPronoun << " " << getSubjectVerb() << " " << article << " " << loyaltyTitle << ".";
}

if (summary()->getCurrentTitle() != 0) {
s << " " << subjectPronoun << " " << getSubjectVerb() << " a " << summary()->getCurrentTitleName() << ".";
if (title()->getCurrentTitle() != 0) {
s << " " << subjectPronoun << " " << getSubjectVerb() << " a " << title()->getCurrentTitleName() << ".";
}

if (isVip()) {
Expand Down Expand Up @@ -2864,9 +2864,9 @@ void Player::death(std::shared_ptr<Creature> lastHitCreature) {
description << "Killed " << getName() << '.';
CyclopediaCharacterInfo_RecentKillStatus_t status = unfairFightReduction != 100 ? CYCLOPEDIA_CHARACTERINFO_RECENTKILLSTATUS_UNJUSTIFIED : CYCLOPEDIA_CHARACTERINFO_RECENTKILLSTATUS_JUSTIFIED;
if (lastHitCreature && lastHitCreature->getPlayer()) {
lastHitCreature->getPlayer()->summary()->insertPvpKillOnHistory(std::move(description.str()), OTSYS_TIME() / 1000, status);
lastHitCreature->getPlayer()->cyclopedia()->insertPvpKillOnHistory(std::move(description.str()), OTSYS_TIME() / 1000, status);
} else if (lastHitCreature && lastHitCreature->getMaster() && lastHitCreature->getMaster()->getPlayer()) {
lastHitCreature->getMaster()->getPlayer()->summary()->insertPvpKillOnHistory(std::move(description.str()), OTSYS_TIME() / 1000, status);
lastHitCreature->getMaster()->getPlayer()->cyclopedia()->insertPvpKillOnHistory(std::move(description.str()), OTSYS_TIME() / 1000, status);
}
} else {
description << "Died at Level " << getLevel() << " by";
Expand All @@ -2883,7 +2883,7 @@ void Player::death(std::shared_ptr<Creature> lastHitCreature) {
}
description << '.';

getPlayer()->summary()->insertDeathOnHistory(std::move(description.str()), OTSYS_TIME() / 1000);
getPlayer()->cyclopedia()->insertDeathOnHistory(std::move(description.str()), OTSYS_TIME() / 1000);
}

sendStats();
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,9 @@ class Player final : public Creature, public Cylinder, public Bankable {
client->sendCyclopediaCharacterBadges();
}
}
void sendCyclopediaCharacterTitles(std::map<uint8_t, Title> titles) {
void sendCyclopediaCharacterTitles() {
if (client) {
client->sendCyclopediaCharacterTitles(titles);
client->sendCyclopediaCharacterTitles();
}
}
void sendHighscoresNoData() {
Expand Down
4 changes: 2 additions & 2 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10503,7 +10503,7 @@ std::map<uint16_t, Achievement> Game::getAchievements() {
//
// }

const Badge Game::getBadgeById(uint8_t id) {
Badge Game::getBadgeById(uint8_t id) {
auto it = std::find_if(m_badges.begin(), m_badges.end(), [id](const Badge &b) {
return b.m_id == id;
});
Expand All @@ -10517,7 +10517,7 @@ std::unordered_set<Badge> Game::getBadges() {
return m_badges;
}

const Title Game::getTitleById(uint8_t id) {
Title Game::getTitleById(uint8_t id) {
auto it = std::find_if(m_titles.begin(), m_titles.end(), [id](const Title &t) {
return t.m_id == id;
});
Expand Down
26 changes: 13 additions & 13 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class Game {
std::map<uint16_t, Achievement> getAchievements();

// void registerBadge(uint8_t id, std::string name, uint16_t amount);
const Badge getBadgeById(uint8_t id);
Badge getBadgeById(uint8_t id);
std::unordered_set<Badge> getBadges();

// void registerTitle(uint8_t id, std::string maleName, std::string femaleName, std::string type, std::string description, bool permanent);
Expand Down Expand Up @@ -764,9 +764,9 @@ class Game {
std::map<uint8_t, std::string> m_badgesNames;

std::unordered_set<Title> m_titles = {
Title(1, CyclopediaTitleType_t::GOLD, "Gold Hoarder", "Earned at least 1,000,000 gold.", 1000000),
Title(2, CyclopediaTitleType_t::GOLD, "Platinum Hoarder", "Earned at least 10,000,000 gold.", 10000000),
Title(3, CyclopediaTitleType_t::GOLD, "Crystal Hoarder", "Earned at least 100,000,000 gold.", 100000000),
Title(1, CyclopediaTitleType_t::GOLD, "Gold Hoarder", "Earned at least 1,000,000 gold.", 1000000, false),
Title(2, CyclopediaTitleType_t::GOLD, "Platinum Hoarder", "Earned at least 10,000,000 gold.", 10000000, false),
Title(3, CyclopediaTitleType_t::GOLD, "Crystal Hoarder", "Earned at least 100,000,000 gold.", 100000000, false),

Title(4, CyclopediaTitleType_t::MOUNTS, "Beaststrider (Grade 1)", "Unlocked 10 or more Mounts.", 10, true),
Title(5, CyclopediaTitleType_t::MOUNTS, "Beaststrider (Grade 2)", "Unlocked 20 or more Mounts.", 20, true),
Expand All @@ -780,13 +780,13 @@ class Game {
Title(12, CyclopediaTitleType_t::OUTFITS, "Tibia's Topmodel (Grade 4)", "Unlocked 40 or more Outfits.", 40, true),
Title(13, CyclopediaTitleType_t::OUTFITS, "Tibia's Topmodel (Grade 5)", "Unlocked 50 or more Outfits.", 50, true),

Title(14, CyclopediaTitleType_t::LEVEL, "Trolltrasher", "Reached level 50.", 50),
Title(15, CyclopediaTitleType_t::LEVEL, "Cyclopscamper", "Reached level 100.", 100),
Title(16, CyclopediaTitleType_t::LEVEL, "Dragondouser", "Reached level 200.", 200),
Title(17, CyclopediaTitleType_t::LEVEL, "Demondoom", "Reached level 300.", 300),
Title(18, CyclopediaTitleType_t::LEVEL, "Drakenbane", "Reached level 400.", 400),
Title(19, CyclopediaTitleType_t::LEVEL, "Silencer", "Reached level 500.", 500),
Title(20, CyclopediaTitleType_t::LEVEL, "Exalted", "Reached level 1000.", 1000),
Title(14, CyclopediaTitleType_t::LEVEL, "Trolltrasher", "Reached level 50.", 50, false),
Title(15, CyclopediaTitleType_t::LEVEL, "Cyclopscamper", "Reached level 100.", 100, false),
Title(16, CyclopediaTitleType_t::LEVEL, "Dragondouser", "Reached level 200.", 200, false),
Title(17, CyclopediaTitleType_t::LEVEL, "Demondoom", "Reached level 300.", 300, false),
Title(18, CyclopediaTitleType_t::LEVEL, "Drakenbane", "Reached level 400.", 400, false),
Title(19, CyclopediaTitleType_t::LEVEL, "Silencer", "Reached level 500.", 500, false),
Title(20, CyclopediaTitleType_t::LEVEL, "Exalted", "Reached level 1000.", 1000, false),

Title(21, CyclopediaTitleType_t::HIGHSCORES, "Legend of Fishing", "", "Highest fishing level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::FISHING)),
Title(22, CyclopediaTitleType_t::HIGHSCORES, "Legend of Magic", "", "Highest magic level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::MAGIC_LEVEL)),
Expand Down Expand Up @@ -831,8 +831,8 @@ class Game {
Title(58, CyclopediaTitleType_t::TASK, "Competent Beastslayer", "Invested 320,000 tasks points.", 320000, true),
Title(59, CyclopediaTitleType_t::TASK, "Feared Bountyhunter", "Invested 430,000 tasks points.", 430000, true),

Title(60, CyclopediaTitleType_t::MAP, "Dedicated Entrepreneur", "Explored 50% of all the map areas.", 50),
Title(61, CyclopediaTitleType_t::MAP, "Globetrotter", "Explored all map areas.", 100),
Title(60, CyclopediaTitleType_t::MAP, "Dedicated Entrepreneur", "Explored 50% of all the map areas.", 50, false),
Title(61, CyclopediaTitleType_t::MAP, "Globetrotter", "Explored all map areas.", 100, false),

Title(62, CyclopediaTitleType_t::QUEST, "Planegazer", "Followed the trail of the Planestrider to the end.", TitleStorage(1000, 1, false), true),
Title(63, CyclopediaTitleType_t::QUEST, "Hero of Bounac", "You prevailed during the battle of Bounac and broke the siege that held Bounac's people in its firm grasp.", TitleStorage(1000, 1, false), true),
Expand Down
3 changes: 2 additions & 1 deletion src/game/game_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ enum class CyclopediaBadgeType_t : uint8_t {
};

enum class CyclopediaTitleType_t : uint8_t {
GOLD = 1,
NOTHING = 0,
GOLD,
MOUNTS,
OUTFITS,
LEVEL,
Expand Down
24 changes: 13 additions & 11 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3900,10 +3900,10 @@ void ProtocolGame::sendCyclopediaCharacterInspection() {
msg.addString(player->getVocation()->getVocName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getVocation()->getVocName()");

// Player title
if (player->summary()->getCurrentTitle() != 0) {
if (player->title()->getCurrentTitle() != 0) {
playerDescriptionSize++;
msg.addString("Title", "ProtocolGame::sendCyclopediaCharacterInspection - Title");
msg.addString(player->summary()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->summary()->getCurrentTitleName()");
msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->title()->getCurrentTitleName()");
}

// Loyalty title
Expand Down Expand Up @@ -3989,7 +3989,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() {
auto badgesSizePosition = msg.getBufferPosition();
msg.skipBytes(1);
for (const auto &badge : g_game().getBadges()) {
if (player->summary()->hasBadge(badge.m_id)) {
if (player->badge()->hasBadge(badge.m_id)) {
msg.add<uint32_t>(badge.m_id);
msg.addString(badge.m_name, "ProtocolGame::sendCyclopediaCharacterBadges - name");
badgesSize++;
Expand All @@ -4001,25 +4001,27 @@ void ProtocolGame::sendCyclopediaCharacterBadges() {
writeToOutputBuffer(msg);
}

void ProtocolGame::sendCyclopediaCharacterTitles(std::map<uint8_t, Title> titles) {
void ProtocolGame::sendCyclopediaCharacterTitles() {
if (!player || oldProtocol) {
return;
}

auto titles = g_game().getTitles();

NetworkMessage msg;
msg.addByte(0xDA);
msg.addByte(CYCLOPEDIA_CHARACTERINFO_TITLES);
msg.addByte(0x00); // 0x00 Here means 'no error'
msg.addByte(player->summary()->getCurrentTitle());
msg.addByte(player->title()->getCurrentTitle());
msg.addByte(static_cast<uint8_t>(titles.size()));
std::string messageTitleName = "ProtocolGame::sendCyclopediaCharacterTitles - title.name";
std::string messageTitleDesc = "ProtocolGame::sendCyclopediaCharacterTitles - title.description";
for (const auto title : titles) {
msg.addByte(title.first);
msg.addString(player->getSex() == PLAYERSEX_MALE ? title.second.maleName : title.second.femaleName, messageTitleName);
msg.addString(title.second.description, messageTitleDesc);
msg.addByte(title.second.permanent ? 0x01 : 0x00);
msg.addByte(player->achiev()->isUnlocked(title.first) ? 0x01 : 0x00);
for (const auto &title : titles) {
msg.addByte(title.m_id);
msg.addString(player->getSex() == PLAYERSEX_MALE ? title.m_maleName : title.m_femaleName, messageTitleName);
msg.addString(title.m_description, messageTitleDesc);
msg.addByte(title.m_permanent ? 0x01 : 0x00);
msg.addByte(player->title()->isTitleUnlocked(title.m_id) ? 0x01 : 0x00);
}

writeToOutputBuffer(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocolgame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class ProtocolGame final : public Protocol {
void sendCyclopediaCharacterStoreSummary();
void sendCyclopediaCharacterInspection();
void sendCyclopediaCharacterBadges();
void sendCyclopediaCharacterTitles(std::map<uint8_t, Title> titles);
void sendCyclopediaCharacterTitles();

void sendCreatureWalkthrough(std::shared_ptr<Creature> creature, bool walkthrough);
void sendCreatureShield(std::shared_ptr<Creature> creature);
Expand Down

0 comments on commit eea4844

Please sign in to comment.