Skip to content

Commit

Permalink
badge & title system: wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Apr 10, 2024
1 parent 5100679 commit 3855835
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 29 deletions.
4 changes: 4 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ loyaltyPointsPerPremiumDaySpent = 0
loyaltyPointsPerPremiumDayPurchased = 0
loyaltyBonusPercentageMultiplier = 1.0

-- Cyclopedia info
badgeSystemEnabled = true
titleSystemEnabled = true

-- Custom PvP system
-- NOTE: Rate is additive percent for each level and applied multiplicative to totalDamage
-- NOTE: Damage multipliers for each vocation are adjusted in data/XML/vocations.xml
Expand Down
1 change: 1 addition & 0 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void CanaryServer::loadModules() {
modulesLoadHelper((g_npcs().load(false, true)), "npc");

g_game().loadBoostedCreature();
// TODO g_game().initializeGameWorldHighscores();
g_ioBosstiary().loadBoostedBoss();
g_ioprey().initializeTaskHuntOptions();
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum ConfigKey_t : uint16_t {
AUTH_TYPE,
AUTOBANK,
AUTOLOOT,
BADGE_SYSTEM_ENABLED,
BESTIARY_KILL_MULTIPLIER,
BESTIARY_RATE_CHARM_SHOP_PRICE,
BIND_ONLY_GLOBAL_ADDRESS,
Expand Down Expand Up @@ -277,6 +278,7 @@ enum ConfigKey_t : uint16_t {
TIBIADROME_CONCOCTION_COOLDOWN,
TIBIADROME_CONCOCTION_DURATION,
TIBIADROME_CONCOCTION_TICK_TYPE,
TITLE_SYSTEM_ENABLED,
TOGGLE_ATTACK_SPEED_ONFIST,
TOGGLE_CHAIN_SYSTEM,
TOGGLE_DOWNLOAD_MAP,
Expand Down
2 changes: 2 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, ALLOW_RELOAD, "allowReload", false);
loadBoolConfig(L, AUTOBANK, "autoBank", false);
loadBoolConfig(L, AUTOLOOT, "autoLoot", false);
loadBoolConfig(L, BADGE_SYSTEM_ENABLED, "badgeSystemEnabled", true);
loadBoolConfig(L, BOOSTED_BOSS_SLOT, "boostedBossSlot", true);
loadBoolConfig(L, CLASSIC_ATTACK_SPEED, "classicAttackSpeed", false);
loadBoolConfig(L, CLEAN_PROTECTION_ZONES, "cleanProtectionZones", false);
Expand Down Expand Up @@ -139,6 +140,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, TASK_HUNTING_FREE_THIRD_SLOT, "taskHuntingFreeThirdSlot", false);
loadBoolConfig(L, TELEPORT_PLAYER_TO_VOCATION_ROOM, "teleportPlayerToVocationRoom", true);
loadBoolConfig(L, TELEPORT_SUMMONS, "teleportSummons", false);
loadBoolConfig(L, TITLE_SYSTEM_ENABLED, "titleSystemEnabled", true);
loadBoolConfig(L, TOGGLE_ATTACK_SPEED_ONFIST, "toggleAttackSpeedOnFist", false);
loadBoolConfig(L, TOGGLE_CHAIN_SYSTEM, "toggleChainSystem", true);
loadBoolConfig(L, TOGGLE_DOWNLOAD_MAP, "toggleDownloadMap", false);
Expand Down
1 change: 1 addition & 0 deletions src/creatures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target_sources(${PROJECT_NAME}_lib PRIVATE
players/storages/storages.cpp
players/player.cpp
players/achievement/player_achievement.cpp
players/cyclopedia/player_cyclopedia.cpp
players/wheel/player_wheel.cpp
players/wheel/wheel_gems.cpp
players/vocations/vocation.cpp
Expand Down
223 changes: 223 additions & 0 deletions src/creatures/players/cyclopedia/player_cyclopedia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]>
* 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/
*/

#include "pch.hpp"

#include "player_cyclopedia.hpp"

#include "creatures/players/player.hpp"
#include "game/game.hpp"
#include "kv/kv.hpp"

PlayerCyclopedia::PlayerCyclopedia(Player &player) :
m_player(player) { }

// Badge
bool PlayerCyclopedia::hasBadge(uint8_t id) {
if (auto it = std::find_if(badges.begin(), badges.end(), [id](uint8_t it) {
return it == id;
});
it != badges.end()) {
return true;
}

return false;
}

void PlayerCyclopedia::addBadge(uint8_t id) {
if (hasBadge(id)) {
return;
}

badges.emplace_back(id);
}

// Title
std::vector<uint8_t> PlayerCyclopedia::getTitles() const {
return titles;
}

uint8_t PlayerCyclopedia::getCurrentTitle() const {
return m_currentTitle;
}

std::string PlayerCyclopedia::getCurrentTitleName() const {
auto currentTitle = getCurrentTitle();
if (currentTitle == 0) {
return "";
}

auto title = g_game().getTitle(currentTitle);
return (m_player.getSex() == PLAYERSEX_MALE) ? title.maleName : title.femaleName;
}

void PlayerCyclopedia::setCurrentTitle(uint8_t id) {
if (id != 0 && !isTitleUnlocked(id)) {
return;
}

m_currentTitle = id;
}

void PlayerCyclopedia::addTitle(uint8_t id) {
if (isTitleUnlocked(id)) {
return;
}

titles.emplace_back(id);
}

bool PlayerCyclopedia::isTitleUnlocked(uint8_t id) const {
if (auto it = std::find_if(titles.begin(), titles.end(), [id](uint8_t title_it) {
return title_it == id;
});
it != titles.end()) {
return true;
}

return false;
}

// Death History
std::vector<RecentDeathEntry> PlayerCyclopedia::getDeathHistory() const {
return m_deathHistory;
}

void PlayerCyclopedia::insertDeathOnHistory(std::string cause, uint32_t timestamp) {
m_deathHistory.emplace_back(std::move(cause), timestamp);
}

std::vector<RecentPvPKillEntry> PlayerCyclopedia::getPvpKillsHistory() const {
return m_pvpKillsHistory;
}

void PlayerCyclopedia::insertPvpKillOnHistory(std::string cause, uint32_t timestamp, uint8_t status) {
m_pvpKillsHistory.emplace_back(std::move(cause), timestamp, status);
}

// Player summary region
// Get:
// std::vector<uint16_t> getHirelinsOutfitsObtained() const {
// return m_player.hirelingOutfitsObtained;
//}
//
// std::vector<uint8_t> getHirelinsJobsObtained() const {
// return hirelingJobsObtained;
//}
//
// std::map<Blessings_t, uint16_t> getBlessingsObtained() const {
// return blessingsObtained;
//}
//
// StashItemList getHouseItemsObtained() const {
// return houseItemsObtained;
//}
//
// uint16_t getXpBoostsObtained() const {
// return storeXpBoostsObtained;
//}
//
// uint16_t getRewardCollectionObtained() const {
// return dailyRewardCollectionsObtained;
//}
//
// uint16_t getHirelingsObtained() const {
// return hirelingsObtained;
//}
//
// uint16_t getPreyCardsObtained() const {
// return preyCardsObtained;
//}
//
// uint16_t getCharmsPointsObtained() const {
// return charmsObtained;
//}
//
// uint16_t getGoshnarTaintsObtained() const {
// return goshnarObtained;
//}
//
// uint16_t getDromePointsObtained() const {
// return dromeObtained;
//}
//
// uint16_t getLoginStreak() const {
// return loginStreak;
//}
//
// uint16_t getTaskHuntingPointsObtained() const {
// return taskHuntingPointsObtained;
//}
//
// uint16_t getMapAreaDiscoveredPercentage() const {
// return mapAreaDiscoveredPercentage;
//}
//
//// Player summary region
//// Set:
// void addHirelingOutfitObtained(uint16_t lookType) {
// hirelingOutfitsObtained.push_back(lookType);
// }
//
// void addHirelingJobsObtained(uint8_t jobId) {
// hirelingJobsObtained.push_back(jobId);
// }
//
// void addBlessingsObtained(Blessings_t id, uint16_t amount) {
// blessingsObtained[id] += amount;
// }
//
// void addHouseItemsObtained(uint16_t itemId, uint32_t amount) {
// houseItemsObtained[itemId] += amount;
// }
//
// void addXpBoostsObtained(uint16_t amount) {
// storeXpBoostsObtained += amount;
// }
//
// void addRewardCollectionObtained(uint16_t amount) {
// dailyRewardCollectionsObtained += amount;
// }
//
// void addHirelingsObtained(uint16_t amount) {
// hirelingsObtained += amount;
// }
//
// void addPreyCardsObtained(uint16_t amount) {
// preyCardsObtained += amount;
// }
//
// void addCharmsPointsObtained(uint16_t amount) {
// charmsObtained += amount;
// }
//
// void addGoshnarTaintsObtained(uint16_t amount) {
// goshnarObtained += amount;
// }
//
// void addDromePointsObtained(uint16_t amount) {
// dromeObtained += amount;
// }
//
// void addLoginStreak(uint16_t amount) {
// loginStreak += amount;
// }
//
// void addTaskHuntingPointsObtained(uint16_t amount) {
// taskHuntingPointsObtained += amount;
// }
//
// void addMapAreaDiscoveredPercentage(uint16_t amount) {
// mapAreaDiscoveredPercentage += amount;
// }
//

// std::map<uint8_t, std::vector<uint16_t>> getAccountLevelVocation() const {
// return accountLevelSummary;
// }
67 changes: 67 additions & 0 deletions src/creatures/players/cyclopedia/player_cyclopedia.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]>
* 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

class Player;

struct PlayerTitle {
PlayerTitle() { }

uint16_t id = 0;
std::string maleName;
std::string femaleName;
std::string description;
bool permanent = false;
};

class PlayerCyclopedia {
public:
explicit PlayerCyclopedia(Player &player);
bool hasBadge(uint8_t id);
void addBadge(uint8_t id);

std::vector<uint8_t> getTitles() const;
uint8_t getCurrentTitle() const;
std::string getCurrentTitleName() const;
void setCurrentTitle(uint8_t id);
void addTitle(uint8_t id);
bool isTitleUnlocked(uint8_t id) const;

std::vector<RecentDeathEntry> getDeathHistory() const;
std::vector<RecentPvPKillEntry> getPvpKillsHistory() const;
void insertDeathOnHistory(std::string cause, uint32_t timestamp);
void insertPvpKillOnHistory(std::string cause, uint32_t timestamp, uint8_t status);

private:
Player &m_player;

std::vector<uint8_t> badges;
std::vector<uint8_t> titles;
uint8_t m_currentTitle;

// std::vector<uint16_t> hirelingOutfitsObtained;
// std::vector<uint8_t> hirelingJobsObtained;
// std::map<Blessings_t, uint16_t> blessingsObtained;
// StashItemList houseItemsObtained;
// uint16_t storeXpBoostsObtained = 0;
// uint16_t dailyRewardCollectionsObtained = 0;
// uint16_t hirelingsObtained = 0;
// uint16_t preyCardsObtained = 0;
// uint16_t charmsObtained = 0;
// uint16_t goshnarObtained = 0;
// uint16_t dromeObtained = 0;
// uint16_t loginStreak = 0;
// uint16_t taskHuntingPointsObtained = 0;
// uint16_t mapAreaDiscoveredPercentage = 0;

std::vector<RecentDeathEntry> m_deathHistory;
std::vector<RecentPvPKillEntry> m_pvpKillsHistory;
std::map<uint8_t, std::vector<uint16_t>> m_accountLevelSummary;
};
Loading

0 comments on commit 3855835

Please sign in to comment.