Skip to content

Commit

Permalink
wip bless counting and improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed May 24, 2024
1 parent 7c0a3ab commit 834a686
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion data/modules/scripts/blessings/blessings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Blessings.sendBlessDialog = function(player)
msg:addU16(Blessings.BitWiseTable[v.id])
msg:addByte(player:getBlessingCount(v.id))
if player:getClient().version > 1200 then
msg:addByte(0) -- Store Blessings Count
msg:addByte(player:getBlessingCount(v.id, true)) -- Store Blessings Count
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,12 @@ class Player final : public Creature, public Cylinder, public Bankable {
bool hasBlessing(uint8_t index) const {
return blessings[index - 1] != 0;
}
uint8_t getBlessingCount(uint8_t index) const {
return blessings[index - 1];
uint8_t getBlessingCount(uint8_t index, bool storeCount = false) const {
if (!storeCount) {
return blessings[index - 1];
}
auto amount = kv()->scoped("summary")->scoped("blessings")->scoped(fmt::format("{}", index))->get("amount");
return amount ? static_cast<uint8_t>(amount->getNumber()) : 0;
}
std::string getBlessingsName() const;

Expand Down
4 changes: 1 addition & 3 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr<Player> player, DBResu
}

for (int i = 1; i <= 8; i++) {
std::ostringstream ss;
ss << "blessings" << i;
player->addBlessing(static_cast<uint8_t>(i), static_cast<uint8_t>(result->getNumber<uint16_t>(ss.str())));
player->addBlessing(static_cast<uint8_t>(i), static_cast<uint8_t>(result->getNumber<uint16_t>(fmt::format("blessings{}", i))));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2733,15 +2733,15 @@ int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) {
}

int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) {
// player:getBlessingCount(index)
// player:getBlessingCount(index[, storeCount = false])
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
uint8_t index = getNumber<uint8_t>(L, 2);
if (index == 0) {
index = 1;
}

if (player) {
lua_pushnumber(L, player->getBlessingCount(index));
lua_pushnumber(L, player->getBlessingCount(index, getBoolean(L, 3, false)));
} else {
lua_pushnil(L);
}
Expand Down
33 changes: 24 additions & 9 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,15 +3977,29 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() {

// getBlessingsObtained
auto blessingNames = player->getBlessingNames();
std::vector<std::pair<Blessings_t, std::string>> orderedBlessings;
for (const auto &bless : blessingNames) {
orderedBlessings.emplace_back(bless.first, bless.second);
}
std::sort(orderedBlessings.begin(), orderedBlessings.end(), [](const std::pair<Blessings_t, std::string> &a, const std::pair<Blessings_t, std::string> &b) {
return a.first < b.first;
});

msg.addByte(static_cast<uint8_t>(blessingNames.size()));
auto blessingsObtained = player->cyclopedia()->getResult(static_cast<uint8_t>(Summary_t::BLESSINGS));
for (const auto &bName_it : blessingNames) {
msg.addString(bName_it.second, "ProtocolGame::sendCyclopediaCharacterStoreSummary - blessing.name");
uint16_t blessAmount = 0;
auto it = std::find_if(blessingsObtained.begin(), blessingsObtained.end(), [&bName_it](const auto &b_it) {
return b_it.first == bName_it.first;
});
msg.addByte((it != blessingsObtained.end()) ? static_cast<uint16_t>(it->second) : 0x00);
// auto blessingsObtained = player->cyclopedia()->getResult(static_cast<uint8_t>(Summary_t::BLESSINGS));
for (const auto &bless : orderedBlessings) {
g_logger().info("bless: {} - {}", bless.first, bless.second);
msg.addString(bless.second, "ProtocolGame::sendCyclopediaCharacterStoreSummary - blessing.name");
uint8_t blessingIndex = bless.first - 1;
msg.addByte((blessingIndex < player->blessings.size()) ? static_cast<uint16_t>(player->blessings[blessingIndex]) : 0);

// msg.addByte(static_cast<uint16_t>(player->blessings[bless.first - 1]));
// msg.addByte(std::find(player->blessings.begin(), player->blessings.end(), )//player->getBlessingCount(bless.first));
// uint16_t blessAmount = 0;
// auto it = std::find_if(blessingsObtained.begin(), blessingsObtained.end(), [&bName_it](const auto &b_it) {
// return b_it.first == bName_it.first;
// });
// msg.addByte((it != blessingsObtained.end()) ? static_cast<uint16_t>(it->second) : 0x00);
}

uint8_t preySlotsUnlocked = 0;
Expand Down Expand Up @@ -4015,7 +4029,8 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() {
}
msg.addByte(m_hSkills.size());
for (const auto &id : m_hSkills) {
msg.addByte(id);
msg.add<uint16_t>(id - 1000);
// msg.addByte(id);
}

// std::vector<uint16_t> m_hOutfits;
Expand Down

0 comments on commit 834a686

Please sign in to comment.