Skip to content

Commit

Permalink
wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Apr 26, 2024
1 parent aa341a8 commit c78f2ce
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 9 deletions.
102 changes: 102 additions & 0 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ std::string PlayerTitle::getCurrentTitleName() const {
return (m_player.getSex() == PLAYERSEX_FEMALE && !title.m_femaleName.empty()) ? title.m_femaleName : title.m_maleName;
}

void PlayerTitle::checkAndUpdateNewTitles() {

loadUnlockedTitles();
}

void PlayerTitle::loadUnlockedTitles() {
const auto &unlockedTitles = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size());
Expand All @@ -99,3 +104,100 @@ const std::shared_ptr<KV> &PlayerTitle::getUnlockedKV() {

return m_titleUnlockedKV;
}

// Title Calculate Functions
bool PlayerTitle::checkGold(uint32_t amount) {
return m_player.getBankBalance() >= amount;
}

bool PlayerTitle::checkMount(uint32_t amount) {
uint8_t total = 0;
for (const auto &mount : g_game().mounts.getMounts()) {
if (m_player.hasMount(mount)) {
total = total++;
}
}
return total >= amount;
}

bool PlayerTitle::checkOutfit(uint32_t amount) {
return m_player.outfits.size() >= amount;
}

bool PlayerTitle::checkLevel(uint32_t amount) {
return m_player.getLevel() >= 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) {
return m_player.isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterTypeByRaceId(race));
}

bool PlayerTitle::checkLoginStreak(uint32_t amount) {
return static_cast<uint8_t>(m_player.kv()->scoped("daily-reward")->get("streak")->getNumber()) >= amount;
}

bool PlayerTitle::checkTask(uint32_t amount) {
return m_player.getTaskHuntingPoints() >= amount;
}

bool PlayerTitle::checkMap(uint32_t amount) {
// todo cyclopledia
return false;
}

bool PlayerTitle::checkQuest(TitleStorage storage) {
return !storage.kvKey.empty()
? m_player.kv()->get(storage.kvKey)->getNumber() == storage.value
: m_player.getStorageValue(storage.key) == storage.value;
}

bool PlayerTitle::checkOther(std::string name) {
if (name == "Admirer of the Crown") {
// todo
return false;
} else if (name == "Big Spender" && m_player.canWear(1211, 3) && m_player.canWear(1210, 3)) {
return true;
} else if (name == "Guild Leader" && m_player.getGuildRank()->level == 3) {
return true;
} else if (name == "Jack of all Taints") {
// todo
return false;
} else if (name == "Reigning Drome Champion") {
// todo
return false;
}
return false;
}

/*int GameFunctions::luaGameGetHighscoresLeaderId(lua_State* L) {
// Game.getHighscoresLeaderId(skill)
const auto highscoreVector = g_game().getHighscoreByCategory(static_cast<HighscoreCategories_t>(getNumber<uint16_t>(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<BestiaryType_t>(getNumber<uint16_t>(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;
}*/
22 changes: 18 additions & 4 deletions src/creatures/players/cyclopedia/player_title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class Player;
class KV;

struct TitleStorage {
uint32_t key;
uint16_t key = 0;
std::string kvKey;
uint32_t value;
bool kv = false;

TitleStorage() = default;

TitleStorage(uint32_t key, uint32_t value, bool kv) :
key(key), value(value), kv(kv) { }
TitleStorage(uint16_t key, const std::string kvKey, uint32_t value) :
key(key), kvKey(kvKey), value(value) { }
};

struct Title {
Expand Down Expand Up @@ -83,9 +83,23 @@ class PlayerTitle {
[[nodiscard]] uint8_t getCurrentTitle() const;
void setCurrentTitle(uint8_t id);
[[nodiscard]] std::string getCurrentTitleName() const;
void checkAndUpdateNewTitles();
void loadUnlockedTitles();
const std::shared_ptr<KV> &getUnlockedKV();

// Title Calculate Functions
bool checkGold(uint32_t amount);
bool checkMount(uint32_t amount);
bool checkOutfit(uint32_t amount);
bool checkLevel(uint32_t amount);
bool checkHighscore(uint8_t skill);
bool checkBestiary(uint16_t race);
bool checkLoginStreak(uint32_t amount);
bool checkTask(uint32_t amount);
bool checkMap(uint32_t amount);
bool checkQuest(TitleStorage storage);
bool checkOther(std::string name);

private:
// {title ID, time when it was unlocked}
std::shared_ptr<KV> m_titleUnlockedKV;
Expand Down
8 changes: 4 additions & 4 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ Game::Game() {
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),
Title(64, CyclopediaTitleType_t::QUEST, "Royal Bounacean Advisor", "Called to the court of Bounac by Kesar the Younger himself.", TitleStorage(1000, 1, false), true),
Title(65, CyclopediaTitleType_t::QUEST, "Time Traveller", "Anywhere in time or space.", TitleStorage(1000, 1, false), true),
Title(62, CyclopediaTitleType_t::QUEST, "Planegazer", "Followed the trail of the Planestrider to the end.", TitleStorage(1000, "", 1), 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), true),
Title(64, CyclopediaTitleType_t::QUEST, "Royal Bounacean Advisor", "Called to the court of Bounac by Kesar the Younger himself.", TitleStorage(1000, "", 1), true),
Title(65, CyclopediaTitleType_t::QUEST, "Time Traveller", "Anywhere in time or space.", TitleStorage(1000, "", 1), true),

Title(66, CyclopediaTitleType_t::OTHERS, "Admirer of the Crown", "Adjust your crown and handle it.", true),
Title(67, CyclopediaTitleType_t::OTHERS, "Big Spender", "Unlocked the full Golden Outfit.", true),
Expand Down
2 changes: 1 addition & 1 deletion src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr<Player> player)

player->achiev()->loadUnlockedAchievements();
player->badge()->checkAndUpdateNewBadges();
player->title()->loadUnlockedTitles();
player->title()->checkAndUpdateNewTitles();

player->initializePrey();
player->initializeTaskHunting();
Expand Down

0 comments on commit c78f2ce

Please sign in to comment.