Skip to content

Commit

Permalink
badge & title system: improvements and created talkactions to manager…
Browse files Browse the repository at this point in the history
… title e badges.

summary: wip.
friend system: wip.
  • Loading branch information
elsongabriel committed Apr 15, 2024
1 parent f45c7f1 commit 5bb5d38
Show file tree
Hide file tree
Showing 16 changed files with 505 additions and 338 deletions.
33 changes: 33 additions & 0 deletions data/scripts/talkactions/god/manage_badge.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local addBadge = TalkAction("/addbadge")

function addBadge.onSay(player, words, param)
-- create log
logCommand(player, words, param)

if param == "" then
player:sendCancelMessage("Command param required.")
return true
end

local split = param:split(",")
if not split[2] then
player:sendCancelMessage("Insufficient parameters. Usage: /addbadge playerName, badgeID")
return true
end

local target = Player(split[1])
if not target then
player:sendCancelMessage("A player with that name is not online.")
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
local id = tonumber(split[2])
target:addBadge(id)
return true
end

addBadge:separator(" ")
addBadge:groupType("god")
addBadge:register()
68 changes: 68 additions & 0 deletions data/scripts/talkactions/god/manage_title.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local addTitle = TalkAction("/addtitle")

function addTitle.onSay(player, words, param)
-- create log
logCommand(player, words, param)

if param == "" then
player:sendCancelMessage("Command param required.")
return true
end

local split = param:split(",")
if not split[2] then
player:sendCancelMessage("Insufficient parameters. Usage: /addtitle playerName, badgeID")
return true
end

local target = Player(split[1])
if not target then
player:sendCancelMessage("A player with that name is not online.")
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
local id = tonumber(split[2])
target:addTitle(id)
return true
end

addTitle:separator(" ")
addTitle:groupType("god")
addTitle:register()

-----------------------------------------
local setTitle = TalkAction("/settitle")

function setTitle.onSay(player, words, param)
-- create log
logCommand(player, words, param)

if param == "" then
player:sendCancelMessage("Command param required.")
return true
end

local split = param:split(",")
if not split[2] then
player:sendCancelMessage("Insufficient parameters. Usage: /settitle playerName, badgeID")
return true
end

local target = Player(split[1])
if not target then
player:sendCancelMessage("A player with that name is not online.")
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
local id = tonumber(split[2])
target:setCurrentTitle(id)
return true
end

setTitle:separator(" ")
setTitle:groupType("god")
setTitle:register()
19 changes: 9 additions & 10 deletions src/creatures/players/cyclopedia/player_badge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool PlayerBadge::hasBadge(uint8_t id) const {
}

if (auto it = std::find_if(m_badgesUnlocked.begin(), m_badgesUnlocked.end(), [id](auto badge_it) {
return badge_it.first == id;
return badge_it.first.m_id == id;
});
it != m_badgesUnlocked.end()) {
return true;
Expand All @@ -38,36 +38,35 @@ bool PlayerBadge::add(uint8_t id, uint32_t timestamp /* = 0*/) {
return false;
}

const Badge &badge = g_game().getBadgeById(id);
const Badge &badge = g_game().getBadgeByIdOrName(id);
if (badge.m_id == 0) {
return false;
}

int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000);
getUnlockedKV()->set(std::to_string(badge.m_id), toSaveTimeStamp);
m_badgesUnlocked.push_back({ badge.m_id, toSaveTimeStamp });
getUnlockedKV()->set(badge.m_name, toSaveTimeStamp);
m_badgesUnlocked.push_back({ badge, toSaveTimeStamp });
m_badgesUnlocked.shrink_to_fit();
return true;
}

std::vector<std::pair<uint8_t, uint32_t>> PlayerBadge::getUnlockedBadges() const {
std::vector<std::pair<Badge, uint32_t>> PlayerBadge::getUnlockedBadges() const {
return m_badgesUnlocked;
}

void PlayerBadge::loadUnlockedBadges() {
const auto &unlockedBadges = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked badges: {}", __FUNCTION__, unlockedBadges.size());
for (const auto &strBadgeId : unlockedBadges) {
auto id = static_cast<uint8_t>(std::stoul(strBadgeId));
const Badge &badge = g_game().getBadgeById(static_cast<uint8_t>(id));
for (const auto &badgeName : unlockedBadges) {
const Badge &badge = g_game().getBadgeByIdOrName(0, badgeName);
if (badge.m_id == 0) {
g_logger().error("[{}] - Badge {} not found.", __FUNCTION__, strBadgeId);
g_logger().error("[{}] - Badge {} not found.", __FUNCTION__, badgeName);
continue;
}

g_logger().debug("[{}] - Badge {} found for player {}.", __FUNCTION__, badge.m_name, m_player.getName());

m_badgesUnlocked.push_back({ badge.m_id, getUnlockedKV()->get(strBadgeId)->getNumber() });
m_badgesUnlocked.push_back({ badge, getUnlockedKV()->get(badgeName)->getNumber() });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/cyclopedia/player_badge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class PlayerBadge {

bool hasBadge(uint8_t id) const;
bool add(uint8_t id, uint32_t timestamp = 0);
std::vector<std::pair<uint8_t, uint32_t>> getUnlockedBadges() const;
std::vector<std::pair<Badge, uint32_t>> getUnlockedBadges() const;
void loadUnlockedBadges();
const std::shared_ptr<KV> &getUnlockedKV();

private:
// {badge ID, time when it was unlocked}
std::shared_ptr<KV> m_badgeUnlockedKV;
std::vector<std::pair<uint8_t, uint32_t>> m_badgesUnlocked;
std::vector<std::pair<Badge, uint32_t>> m_badgesUnlocked;
Player &m_player;
};
183 changes: 67 additions & 116 deletions src/creatures/players/cyclopedia/player_cyclopedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,66 @@
PlayerCyclopedia::PlayerCyclopedia(Player &player) :
m_player(player) { }

// Death History
void PlayerCyclopedia::addXpBoostsObtained(uint16_t amount) {
m_storeXpBoosts += amount;
}

void PlayerCyclopedia::addRewardCollectionObtained(uint16_t amount) {
m_dailyRewardCollections += amount;
}

void PlayerCyclopedia::addHirelingsObtained(uint16_t amount) {
m_hirelings += amount;
}

void PlayerCyclopedia::addPreyCardsObtained(uint16_t amount) {
m_preyCards += amount;
}

void PlayerCyclopedia::addCharmsPointsObtained(uint16_t amount) {
m_charms += amount;
}

void PlayerCyclopedia::addGoshnarTaintsObtained(uint16_t amount) {
m_goshnar += amount;
}

void PlayerCyclopedia::addDromePointsObtained(uint16_t amount) {
m_drome += amount;
}

void PlayerCyclopedia::addLoginStreak(uint16_t amount) {
m_loginStreak += amount;
}

void PlayerCyclopedia::addTaskHuntingPointsObtained(uint16_t amount) {
m_taskHuntingPoints += amount;
}

void PlayerCyclopedia::addMapAreaDiscoveredPercentage(uint16_t amount) {
m_mapAreaDiscoveredPercentage += amount;
}

void PlayerCyclopedia::addHirelingOutfitObtained(uint16_t lookType) {
m_hirelingOutfits.push_back(lookType);
}

void PlayerCyclopedia::addHirelingJobsObtained(uint8_t jobId) {
m_hirelingJobs.push_back(jobId);
}

void PlayerCyclopedia::addBlessingsObtained(Blessings_t id, uint16_t amount) {
m_blessings[id] += amount;
}

// void PlayerCyclopedia::addHouseItemsObtained(uint16_t itemId, uint32_t amount) {
// m_houseItems[itemId] += amount;
// }

// std::map<uint8_t, std::vector<uint16_t>> PlayerCyclopedia::getAccountLevelVocation() const {
// return accountLevelSummary;
// }

std::vector<RecentDeathEntry> PlayerCyclopedia::getDeathHistory() const {
return m_deathHistory;
}
Expand All @@ -35,123 +94,15 @@ void PlayerCyclopedia::insertPvpKillOnHistory(std::string cause, uint32_t timest
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);
// const std::shared_ptr<KV> &PlayerTitle::getSummary(std::string &key) {
// return m_player.kv()->scoped("titles")->scoped("summary")->get(key);
// }
//
// void addHirelingJobsObtained(uint8_t jobId) {
// hirelingJobsObtained.push_back(jobId);
// uint16_t PlayerAchievement::getPoints() const {
// return m_player.kv()->scoped("achievements")->get("points")->getNumber();
// }
//
// 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;
// void PlayerAchievement::addPoints(uint16_t toAddPoints) {
// auto oldPoints = getPoints();
// m_player.kv()->scoped("achievements")->set("points", oldPoints + toAddPoints);
// }
Loading

0 comments on commit 5bb5d38

Please sign in to comment.