diff --git a/data/modules/scripts/blessings/blessings.lua b/data/modules/scripts/blessings/blessings.lua index c7c1ce42a72..94eaede5fbd 100644 --- a/data/modules/scripts/blessings/blessings.lua +++ b/data/modules/scripts/blessings/blessings.lua @@ -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 } @@ -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 diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 47789f5ba18..93ed56500d2 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -2742,24 +2742,28 @@ void Player::death(std::shared_ptr 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(); @@ -7799,3 +7803,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()); + } +} diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index a33c538c814..d02db1c2342 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -2952,4 +2952,6 @@ class Player final : public Creature, public Cylinder, public Bankable { void removeEmptyRewards(); bool hasOtherRewardContainerOpen(const std::shared_ptr container) const; + + void checkAndShowBlessingMessage(); }; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 357c85521fb..ac707124661 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -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) {