Skip to content

Commit

Permalink
fix: adventurer's blessing (#2043)
Browse files Browse the repository at this point in the history
Players will get the adventurer's blessing until reach the
'adventurersBlessingLevel' level config from your server.
Players in Rookgaard (without vocation) ignore this validation, and be
like a player without blessing.

- Fixed and improved adventurer's blessing.
- Improvement of PR #1743
  • Loading branch information
elsongabriel authored Dec 28, 2023
1 parent 8e9d9bf commit 9e4c822
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
6 changes: 3 additions & 3 deletions data/modules/scripts/blessings/blessings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Blessings.Credits = {
}

Blessings.Config = {
AdventurerBlessingLevel = 0, -- Free full bless until level
AdventurerBlessingLevel = configManager.getNumber(configKeys.ADVENTURERSBLESSING_LEVEL), -- Free full bless until level
HasToF = false, -- Enables/disables twist of fate
InquisitonBlessPriceMultiplier = 1.1, -- Bless price multiplied by henricus
SkulledDeathLoseStoreItem = true, -- Destroy all items on store when dying with red/blackskull
InventoryGlowOnFiveBless = true, -- Glow in yellow inventory items when the player has 5 or more bless,
InventoryGlowOnFiveBless = configManager.getBoolean(configKeys.INVENTORY_GLOW), -- Glow in yellow inventory items when the player has 5 or more bless,
Debug = false, -- Prin debug messages in console if enabled
}

Expand Down Expand Up @@ -260,7 +260,7 @@ Blessings.doAdventurerBlessing = function(player)
end
player:addMissingBless(true, true)

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You received adventurers blessings for you being level lower than " .. Blessings.Config.AdventurerBlessingLevel .. "!")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have adventurer's blessings for being level lower than " .. Blessings.Config.AdventurerBlessingLevel .. "!")
player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
return true
end
Expand Down
57 changes: 44 additions & 13 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,24 +2745,28 @@ void Player::death(std::shared_ptr<Creature> lastHitCreature) {
}
sendTextMessage(MESSAGE_EVENT_ADVANCE, deathType.str());

auto adventurerBlessingLevel = g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL, __FUNCTION__);
auto willNotLoseBless = getLevel() < adventurerBlessingLevel && getVocationId() > VOCATION_NONE;

std::string bless = getBlessingsName();
std::ostringstream blesses;
if (bless.length() == 0) {
blesses << "You weren't protected with any blessings.";
std::ostringstream blessOutput;
if (willNotLoseBless) {
blessOutput << fmt::format("You still have adventurer's blessings for being level lower than {}!", adventurerBlessingLevel);
} else {
blesses << "You were blessed with " << bless;
}
sendTextMessage(MESSAGE_EVENT_ADVANCE, blesses.str());
bless.empty() ? blessOutput << "You weren't protected with any blessings."
: blessOutput << "You were blessed with " << bless;

// Make player lose bless
uint8_t maxBlessing = 8;
if (pvpDeath && hasBlessing(1)) {
removeBlessing(1, 1); // Remove TOF only
} else {
for (int i = 2; i <= maxBlessing; i++) {
removeBlessing(i, 1);
// Make player lose bless
uint8_t maxBlessing = 8;
if (pvpDeath && hasBlessing(1)) {
removeBlessing(1, 1); // Remove TOF only
} else {
for (int i = 2; i <= maxBlessing; i++) {
removeBlessing(i, 1);
}
}
}
sendTextMessage(MESSAGE_EVENT_ADVANCE, blessOutput.str());

sendStats();
sendSkills();
Expand Down Expand Up @@ -7813,3 +7817,30 @@ bool Player::hasPermittedConditionInPZ() const {

return hasPermittedCondition;
}

void Player::checkAndShowBlessingMessage() {
auto adventurerBlessingLevel = g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL, __FUNCTION__);
auto willNotLoseBless = getLevel() < adventurerBlessingLevel && getVocationId() > VOCATION_NONE;
std::string bless = getBlessingsName();
std::ostringstream blessOutput;

if (willNotLoseBless) {
auto addedBless = false;
for (uint8_t i = 2; i <= 6; i++) {
if (!hasBlessing(i)) {
addBlessing(i, 1);
addedBless = true;
}
}
sendBlessStatus();
if (addedBless) {
blessOutput << fmt::format("You have received adventurer's blessings for being level lower than {}!\nYou are still blessed with {}", adventurerBlessingLevel, bless);
}
} else {
bless.empty() ? blessOutput << "You lost all your blessings." : blessOutput << "You are still blessed with " << bless;
}

if (!blessOutput.str().empty()) {
sendTextMessage(MESSAGE_EVENT_ADVANCE, blessOutput.str());
}
}
2 changes: 2 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,4 +2953,6 @@ class Player final : public Creature, public Cylinder, public Bankable {

void removeEmptyRewards();
bool hasOtherRewardContainerOpen(const std::shared_ptr<Container> container) const;

void checkAndShowBlessingMessage();
};
14 changes: 1 addition & 13 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,19 +946,7 @@ void ProtocolGame::addBless() {
if (!player) {
return;
}

std::string bless = player->getBlessingsName();
std::ostringstream lostBlesses;
(bless.length() == 0) ? lostBlesses << "You lost all your blessings." : lostBlesses << "You are still blessed with " << bless;
player->sendTextMessage(MESSAGE_EVENT_ADVANCE, lostBlesses.str());
if (player->getLevel() < g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL, __FUNCTION__) && player->getVocationId() > VOCATION_NONE) {
for (uint8_t i = 2; i <= 6; i++) {
if (!player->hasBlessing(i)) {
player->addBlessing(i, 1);
}
}
sendBlessStatus();
}
player->checkAndShowBlessingMessage();
}

void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyte) {
Expand Down

0 comments on commit 9e4c822

Please sign in to comment.