Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adventurer's blessing #2043

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2742,24 +2742,28 @@
}
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;

Check warning on line 2757 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] reported by reviewdog 🐶 The scope of the variable 'maxBlessing' can be reduced. Raw Output: src/creatures/players/player.cpp:2757:The scope of the variable 'maxBlessing' can be reduced.
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 @@ -7799,3 +7803,30 @@

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 @@ -2952,4 +2952,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
Loading