Skip to content

Commit

Permalink
[FEATURE] Configurable in config.lua halfLossExp, halfLossSkilla and …
Browse files Browse the repository at this point in the history
…halfLossMagicLevel, thanks @dguprado
  • Loading branch information
jprzimba committed Nov 14, 2024
1 parent 320df9c commit 628a7dd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ freeQuestStage = 1
-- NOTE: Leave deathLosePercent as -1 if you want to use the default
-- death penalty formula. For the old formula, set it to 10. For
-- no skill/experience loss, set it to 0.
-- When `halfLoss*` is active, the player will lose 50% less experience, skills, and magic level upon death.
deathLosePercent = -1
halfLossExp = false
halfLossSkill = false
halfLossMagicLevel = false

-- Houses
-- NOTE: set housePriceEachSQM to -1 to disable the ingame buy house functionality
Expand Down
3 changes: 2 additions & 1 deletion markdowns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
- Updated monsters and npcs like Tibia RL ([Tryller](https://github.com/jprzimba)).
- Add items from Winter Update 2023 ([Tryller](https://github.com/jprzimba), [dguprado](https://github.com/dguprado)).
- Add V.I.P groups ([phacUFPE](https://github.com/phacUFPE)).
- Click to teleport, then use CTRL + directional keys to teleport gamemaster characters ([Tryller](https://github.com/jprzimba)).
- Added click teleport, then use CTRL + directional keys to teleport gamemaster characters ([Tryller](https://github.com/jprzimba)).
- Added new feature configurable in config.lua halfLossExp, halfLossSkilla and halfLossMagicLevel ([dguprado](https://github.com/dguprado), [Tryller](https://github.com/jprzimba)).

### Bug Fixes
- Fixed chain system. Now works properly for Mages and Paladins ([Tryller](https://github.com/jprzimba)).
Expand Down
5 changes: 4 additions & 1 deletion src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,8 @@ enum ConfigKey_t : uint16_t {
COMBAT_CHAIN_SKILL_FORMULA_DISTANCE,
COMBAT_CHAIN_SKILL_FORMULA_MISSILE,
COMBAT_CHAIN_SKILL_FORMULA_WANDS_AND_RODS,
ENABLE_SCREENSHOTS
ENABLE_SCREENSHOTS,
HALF_LOSS_EXP,
HALF_LOSS_SKILL,
HALF_LOSS_MAGIC,
};
3 changes: 3 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ bool ConfigManager::load() {
loadBoolConfig(L, XP_DISPLAY_MODE, "experienceDisplayRates", true);
loadBoolConfig(L, SURPRISE_BAGS, "dropSurpriseBagsFromMonsters", false);
loadBoolConfig(L, ENABLE_SCREENSHOTS, "enableScreenshots", true);
loadBoolConfig(L, HALF_LOSS_EXP, "halfLossExp", true);
loadBoolConfig(L, HALF_LOSS_SKILL, "halfLossSkill", true);
loadBoolConfig(L, HALF_LOSS_MAGIC, "halfLossMagicLevel", true);

loadFloatConfig(L, BESTIARY_RATE_CHARM_SHOP_PRICE, "bestiaryRateCharmShopPrice", 1.0);
loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9);
Expand Down
21 changes: 18 additions & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3509,7 +3509,12 @@ void Player::death(const std::shared_ptr<Creature> &lastHitCreature) {
}
}

lostMana = static_cast<uint64_t>(sumMana * deathLossPercent);
double magicLossPercent = deathLossPercent;
if (g_configManager().getBoolean(HALF_LOSS_MAGIC) && magicLossPercent > 0) {
magicLossPercent /= 2;
}

lostMana = static_cast<uint64_t>(sumMana * magicLossPercent);

while (lostMana > manaSpent && magLevel > 0) {
lostMana -= manaSpent;
Expand All @@ -3527,7 +3532,12 @@ void Player::death(const std::shared_ptr<Creature> &lastHitCreature) {
}

// Level loss
auto expLoss = static_cast<uint64_t>(std::ceil((experience * deathLossPercent) / 100.));
double expLossPercent = deathLossPercent / 100.;
if (g_configManager().getBoolean(HALF_LOSS_EXP) && expLossPercent > 0) {
expLossPercent /= 2;
}

auto expLoss = static_cast<uint64_t>(std::ceil((experience * expLossPercent)));
g_logger().debug("[{}] - experience lost {}", __FUNCTION__, expLoss);

g_events().eventPlayerOnLoseExperience(static_self_cast<Player>(), expLoss);
Expand All @@ -3546,7 +3556,12 @@ void Player::death(const std::shared_ptr<Creature> &lastHitCreature) {

sumSkillTries += skills[i].tries;

auto lostSkillTries = static_cast<uint32_t>(sumSkillTries * deathLossPercent);
double skillLossPercent = deathLossPercent;
if (g_configManager().getBoolean(HALF_LOSS_SKILL) && skillLossPercent > 0) {
skillLossPercent /= 2;
}

auto lostSkillTries = static_cast<uint32_t>(sumSkillTries * skillLossPercent);
while (lostSkillTries > skills[i].tries) {
lostSkillTries -= skills[i].tries;

Expand Down

0 comments on commit 628a7dd

Please sign in to comment.