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

feat: defense boost for hazard system #1999

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
1 change: 1 addition & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ hazardCriticalInterval = 2000
hazardCriticalChance = 750
hazardCriticalMultiplier = 25
hazardDamageMultiplier = 200
hazardDefenseMultiplier = 0
hazardDodgeMultiplier = 85
hazardPodsDropMultiplier = 87
hazardPodsTimeToDamage = 2000
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/scripts/hazard/primal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local hazard = Hazard.new({
crit = true,
dodge = true,
damageBoost = true,
defenseBoost = true,
})

hazard:register()
Expand Down
50 changes: 40 additions & 10 deletions data/libs/hazard_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
instance.name = prototype.name
instance.from = prototype.from
instance.to = prototype.to
instance.minLevel = prototype.minLevel or 1
instance.maxLevel = prototype.maxLevel
instance.storageMax = prototype.storageMax ---@deprecated
instance.storageCurrent = prototype.storageCurrent ---@deprecated
instance.crit = prototype.crit
instance.dodge = prototype.dodge
instance.damageBoost = prototype.damageBoost
instance.defenseBoost = prototype.defenseBoost

instance.zone = Zone(instance.name)
if instance.from and instance.to then
Expand Down Expand Up @@ -41,19 +43,43 @@
end

if hazardPoints == -1 then
hazardPoints = 1
hazardPoints = self.minLevel
end

return hazardPlayer, hazardPoints
end

function Hazard:getCurrentLevel(players)
local hazardPlayer = nil

Check warning on line 53 in data/libs/hazard_lib.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] data/libs/hazard_lib.lua#L53

variable 'hazardPlayer' is never accessed
Raw output
data/libs/hazard_lib.lua:53:8: variable 'hazardPlayer' is never accessed
local hazardPoints = -1
for _, player in ipairs(players) do
local playerHazardPoints = self:getPlayerCurrentLevel(player)

if playerHazardPoints < hazardPoints or hazardPoints == -1 then
hazardPlayer = player
hazardPoints = playerHazardPoints
end
end

if hazardPoints == -1 then
hazardPoints = self.minLevel
end

return hazardPoints
end

function Hazard:getPlayerCurrentLevel(player)
if self.storageCurrent then
local fromStorage = player:getStorageValue(self.storageCurrent)
return fromStorage <= 0 and 1 or fromStorage
return fromStorage <= 0 and self.minLevel or fromStorage
end
local fromKV = player:kv():scoped(self.name):get("currentLevel") or 1
return fromKV <= 0 and 1 or fromKV
local fromKV = player:kv():scoped(self.name):get("current-level") or self.minLevel
return fromKV <= 0 and self.minLevel or fromKV
end

function Hazard:getPlayerMaxLevelEver(player)
local fromKV = player:kv():scoped(self.name):get("max-level-set") or self.minLevel
return fromKV <= 0 and self.minLevel or fromKV
end

function Hazard:setPlayerCurrentLevel(player, level)
Expand All @@ -64,7 +90,11 @@
if self.storageCurrent then
player:setStorageValue(self.storageCurrent, level)
else
player:kv():scoped(self.name):set("currentLevel", level)
player:kv():scoped(self.name):set("current-level", level)
local maxEver = player:kv():scoped(self.name):get("max-level-set") or self.minLevel
if level > maxEver then
player:kv():scoped(self.name):set("max-level-set", level)
end
end
local zones = player:getZones()
if not zones then
Expand All @@ -86,11 +116,10 @@
function Hazard:getPlayerMaxLevel(player)
if self.storageMax then
local fromStorage = player:getStorageValue(self.storageMax)
return fromStorage <= 0 and 1 or fromStorage
return fromStorage <= 0 and self.minLevel or fromStorage
end
local fromKV = player:kv():scoped(self.name):get("maxLevel") or 1

return fromKV <= 0 and 1 or fromKV
local fromKV = player:kv():scoped(self.name):get("max-level") or self.minLevel
return fromKV <= 0 and self.minLevel or fromKV
end

function Hazard:levelUp(player)
Expand All @@ -110,7 +139,7 @@
player:setStorageValue(self.storageMax, level)
return
end
player:kv():scoped(self.name):set("maxLevel", level)
player:kv():scoped(self.name):set("max-level", level)
end

function Hazard:isInZone(position)
Expand Down Expand Up @@ -181,6 +210,7 @@
monster:hazardCrit(hazard.crit)
monster:hazardDodge(hazard.dodge)
monster:hazardDamageBoost(hazard.damageBoost)
monster:hazardDefenseBoost(hazard.defenseBoost)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum ConfigKey_t : uint16_t {
HAZARD_CRITICAL_INTERVAL,
HAZARD_CRITICAL_MULTIPLIER,
HAZARD_DAMAGE_MULTIPLIER,
HAZARD_DEFENSE_MULTIPLIER,
HAZARD_DODGE_MULTIPLIER,
HAZARD_EXP_BONUS_MULTIPLIER,
HAZARD_LOOT_BONUS_MULTIPLIER,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ bool ConfigManager::load() {
loadIntConfig(L, HAZARD_CRITICAL_CHANCE, "hazardCriticalChance", 750);
loadIntConfig(L, HAZARD_CRITICAL_MULTIPLIER, "hazardCriticalMultiplier", 25);
loadIntConfig(L, HAZARD_DAMAGE_MULTIPLIER, "hazardDamageMultiplier", 200);
loadIntConfig(L, HAZARD_DEFENSE_MULTIPLIER, "hazardDefenseMultiplier", 0);
loadIntConfig(L, HAZARD_DODGE_MULTIPLIER, "hazardDodgeMultiplier", 85);
loadIntConfig(L, HAZARD_PODS_DROP_MULTIPLIER, "hazardPodsDropMultiplier", 87);
loadIntConfig(L, HAZARD_PODS_TIME_TO_DAMAGE, "hazardPodsTimeToDamage", 2000);
Expand Down
3 changes: 3 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ BlockType_t Creature::blockHit(std::shared_ptr<Creature> attacker, CombatType_t

mitigateDamage(combatType, blockType, damage);

if (damage != 0) {
onTakeDamage(attacker, damage);
}
onAttacked();
return blockType;
}
Expand Down
1 change: 1 addition & 0 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ class Creature : virtual public Thing, public SharedObject {
virtual void onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> target);
virtual void onAttackedCreatureBlockHit(BlockType_t) { }
virtual void onBlockHit() { }
virtual void onTakeDamage(std::shared_ptr<Creature>, int32_t) { }
virtual void onChangeZone(ZoneType_t zone);
virtual void onAttackedCreatureChangeZone(ZoneType_t zone);
virtual void onIdleStatus();
Expand Down
7 changes: 7 additions & 0 deletions src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ class Monster final : public Creature {
void setHazardSystemDamageBoost(bool value) {
hazardDamageBoost = value;
}
bool getHazardSystemDefenseBoost() const {
return hazardDefenseBoost;
}
void setHazardSystemDefenseBoost(bool value) {
hazardDefenseBoost = value;
}
// Hazard end

void updateTargetList();
Expand Down Expand Up @@ -391,6 +397,7 @@ class Monster final : public Creature {
bool hazardCrit = false;
bool hazardDodge = false;
bool hazardDamageBoost = false;
bool hazardDefenseBoost = false;

void onCreatureEnter(std::shared_ptr<Creature> creature);
void onCreatureLeave(std::shared_ptr<Creature> creature);
Expand Down
14 changes: 14 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,9 @@ void Player::onBlockHit() {
}
}

void Player::onTakeDamage(std::shared_ptr<Creature> attacker, int32_t damage) {
}

void Player::onAttackedCreatureBlockHit(BlockType_t blockType) {
lastAttackBlockType = blockType;

Expand Down Expand Up @@ -7725,6 +7728,17 @@ void Player::parseAttackDealtHazardSystem(CombatDamage &damage, std::shared_ptr<
return;
}
}
if (monster->getHazardSystemDefenseBoost()) {
stage = points * static_cast<uint16_t>(g_configManager().getNumber(HAZARD_DEFENSE_MULTIPLIER, __FUNCTION__));
if (stage != 0) {
damage.exString = "(hazard -" + std::to_string(stage / 100) + "%)";
damage.primary.value -= static_cast<int32_t>(std::ceil((static_cast<double>(damage.primary.value) * stage) / 10000));
if (damage.secondary.value != 0) {
damage.secondary.value -= static_cast<int32_t>(std::ceil((static_cast<double>(damage.secondary.value) * stage) / 10000));
}
return;
}
}
}

/*******************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
void onGainSharedExperience(uint64_t gainExp, std::shared_ptr<Creature> target);
void onAttackedCreatureBlockHit(BlockType_t blockType) override;
void onBlockHit() override;
void onTakeDamage(std::shared_ptr<Creature> attacker, int32_t damage) override;
void onChangeZone(ZoneType_t zone) override;
void onAttackedCreatureChangeZone(ZoneType_t zone) override;
void onIdleStatus() override;
Expand Down
19 changes: 18 additions & 1 deletion src/lua/functions/creatures/monster/monster_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,24 @@ int MonsterFunctions::luaMonsterHazardDamageBoost(lua_State* L) {
pushBoolean(L, monster->getHazardSystemDamageBoost());
} else {
monster->setHazardSystemDamageBoost(hazardDamageBoost);
pushBoolean(L, monster->getHazardSystemCrit());
pushBoolean(L, monster->getHazardSystemDamageBoost());
}
} else {
lua_pushnil(L);
}
return 1;
}

int MonsterFunctions::luaMonsterHazardDefenseBoost(lua_State* L) {
// get: monster:hazardDefenseBoost() ; set: monster:hazardDefenseBoost(hazardDefenseBoost)
std::shared_ptr<Monster> monster = getUserdataShared<Monster>(L, 1);
bool hazardDefenseBoost = getBoolean(L, 2, false);
if (monster) {
if (lua_gettop(L) == 1) {
pushBoolean(L, monster->getHazardSystemDefenseBoost());
} else {
monster->setHazardSystemDefenseBoost(hazardDefenseBoost);
pushBoolean(L, monster->getHazardSystemDefenseBoost());
}
} else {
lua_pushnil(L);
Expand Down
2 changes: 2 additions & 0 deletions src/lua/functions/creatures/monster/monster_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MonsterFunctions final : LuaScriptInterface {
registerMethod(L, "Monster", "hazardCrit", MonsterFunctions::luaMonsterHazardCrit);
registerMethod(L, "Monster", "hazardDodge", MonsterFunctions::luaMonsterHazardDodge);
registerMethod(L, "Monster", "hazardDamageBoost", MonsterFunctions::luaMonsterHazardDamageBoost);
registerMethod(L, "Monster", "hazardDefenseBoost", MonsterFunctions::luaMonsterHazardDefenseBoost);

CharmFunctions::init(L);
LootFunctions::init(L);
Expand Down Expand Up @@ -120,6 +121,7 @@ class MonsterFunctions final : LuaScriptInterface {
static int luaMonsterHazardCrit(lua_State* L);
static int luaMonsterHazardDodge(lua_State* L);
static int luaMonsterHazardDamageBoost(lua_State* L);
static int luaMonsterHazardDefenseBoost(lua_State* L);

friend class CreatureFunctions;
};
Loading