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 0c148ac commit dd80caf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
16 changes: 2 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8259,7 +8259,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_
player->sendCyclopediaCharacterBadges();
break;
case CYCLOPEDIA_CHARACTERINFO_TITLES:
player->sendCyclopediaCharacterTitles(getTitles());
player->sendCyclopediaCharacterTitles();
break;
default:
player->sendCyclopediaCharacterNoData(characterInfoType, 1);
Expand Down Expand Up @@ -10517,18 +10517,6 @@ std::unordered_set<Badge> Game::getBadges() {
return m_badges;
}

// void Game::registerTitle(uint8_t id, std::string maleName, std::string femaleName, std::string type, std::string description, bool permanent) {
// m_titles[id] = Title();
// m_titles[id].id = id;
// m_titles[id].maleName = maleName;
// m_titles[id].femaleName = femaleName;
// m_titles[id].type = type;
// m_titles[id].description = description;
// m_titles[id].permanent = permanent;
//
// m_titlesNames.emplace(id, maleName);
// }

const 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 All @@ -10539,6 +10527,6 @@ const Title Game::getTitleById(uint8_t id) {
return Title();
}

std::map<uint8_t, Title> Game::getTitles() {
std::unordered_set<Title> Game::getTitles() {
return m_titles;
}
4 changes: 2 additions & 2 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ class Game {
const 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);
// void registerTitle(uint8_t id, std::string maleName, std::string femaleName, std::string type, std::string description, bool permanent);
Title getTitleById(uint8_t id);
std::map<uint8_t, Title> getTitles();
std::unordered_set<Title> getTitles();

private:
std::map<uint16_t, Achievement> m_achievements;
Expand Down
16 changes: 8 additions & 8 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4291,7 +4291,7 @@ int PlayerFunctions::luaPlayerAddBadge(lua_State* L) {
return 1;
}

player->summary()->addBadge(getNumber<uint8_t>(L, 2, 0));
player->badge()->add(getNumber<uint8_t>(L, 2, 0));
pushBoolean(L, true);
return 1;
}
Expand All @@ -4304,7 +4304,7 @@ int PlayerFunctions::luaPlayerAddTitle(lua_State* L) {
return 1;
}

player->summary()->addTitle(getNumber<uint8_t>(L, 2, 0));
player->title()->add(getNumber<uint8_t>(L, 2, 0));
pushBoolean(L, true);
return 1;
}
Expand All @@ -4317,12 +4317,12 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) {
return 1;
}

int index = 0;
lua_createtable(L, player->summary()->getTitles().size(), 0);
for (const auto id : player->summary()->getTitles()) {
lua_pushnumber(L, id);
lua_rawseti(L, -2, ++index);
}
// if (auto item = player->title()->getUnlockedTitles()) {
// pushUserdata<Item>(L, item);
// setItemMetatable(L, -1, item);
// } else {
// pushBoolean(L, false);
// }
return 1;
}

Expand Down

0 comments on commit dd80caf

Please sign in to comment.