From ea033a97dd229d2ca715490a74847b50b482677a Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sat, 9 Sep 2023 11:59:13 -0700 Subject: [PATCH] reduce drain tickrate --- src/Abilities.cpp | 9 ++++++--- src/Abilities.hpp | 1 + src/Buffs.cpp | 7 ++++--- src/Buffs.hpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Abilities.cpp b/src/Abilities.cpp index bed931b..0859220 100644 --- a/src/Abilities.cpp +++ b/src/Abilities.cpp @@ -120,6 +120,7 @@ static SkillResult handleSkillBuff(SkillData* skill, int power, ICombatant* sour int timeBuffId = Abilities::getCSTBFromST(skill->skillType); SkillDrainType drainType = skill->drainType; + int combatLifetime = 0; if(!target->addBuff(timeBuffId, [drainType](EntityRef self, Buff* buff, int status, BuffStack* stack) { if(buff->id == ECSB_BOUNDINGBALL) { @@ -131,9 +132,11 @@ static SkillResult handleSkillBuff(SkillData* skill, int power, ICombatant* sour if(drainType == SkillDrainType::ACTIVE && status == ETBU_DEL) Buffs::timeBuffTimeout(self); }, - [](EntityRef self, Buff* buff, time_t currTime) { - if(buff->id == ECSB_BOUNDINGBALL) - Buffs::tickDrain(self, buff); // drain + [combatLifetime](EntityRef self, Buff* buff, time_t currTime) mutable { + if(buff->id == ECSB_BOUNDINGBALL && + combatLifetime % COMBAT_TICKS_PER_DRAIN_PROC == 0) + Buffs::tickDrain(self, buff, COMBAT_TICKS_PER_DRAIN_PROC); // drain + combatLifetime++; }, &passiveBuff)) return SkillResult(); // no result if already buffed diff --git a/src/Abilities.hpp b/src/Abilities.hpp index ef703b1..2470516 100644 --- a/src/Abilities.hpp +++ b/src/Abilities.hpp @@ -9,6 +9,7 @@ #include #include +const int COMBAT_TICKS_PER_DRAIN_PROC = 2; constexpr size_t MAX_SKILLRESULT_SIZE = sizeof(sSkillResult_BatteryDrain); enum class SkillType { diff --git a/src/Buffs.cpp b/src/Buffs.cpp index d407fac..179f1c6 100644 --- a/src/Buffs.cpp +++ b/src/Buffs.cpp @@ -169,12 +169,13 @@ void Buffs::timeBuffTimeout(EntityRef self) { NPCManager::sendToViewable(entity, &pkt, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT)); } -void Buffs::tickDrain(EntityRef self, Buff* buff) { +void Buffs::tickDrain(EntityRef self, Buff* buff, int mult) { if(self.kind != EntityKind::COMBAT_NPC && self.kind != EntityKind::MOB) return; // not implemented Entity* entity = self.getEntity(); ICombatant* combatant = dynamic_cast(entity); - int damage = combatant->takeDamage(buff->getLastSource(), combatant->getMaxHP() / 100); + int damage = combatant->getMaxHP() / 100 * mult; + int dealt = combatant->takeDamage(buff->getLastSource(), damage); size_t resplen = sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK) + sizeof(sSkillResult_Damage); assert(resplen < CN_PACKET_BUFFER_SIZE - 8); @@ -187,7 +188,7 @@ void Buffs::tickDrain(EntityRef self, Buff* buff) { pkt->iTB_ID = ECSB_BOUNDINGBALL; sSkillResult_Damage *drain = (sSkillResult_Damage*)(respbuf + sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK)); - drain->iDamage = damage; + drain->iDamage = dealt; drain->iHP = combatant->getCurrentHP(); drain->eCT = pkt->eCT; drain->iID = pkt->iID; diff --git a/src/Buffs.hpp b/src/Buffs.hpp index 8f395e1..178efb0 100644 --- a/src/Buffs.hpp +++ b/src/Buffs.hpp @@ -89,5 +89,5 @@ namespace Buffs { void timeBuffUpdate(EntityRef self, Buff* buff, int status, BuffStack* stack); void timeBuffTick(EntityRef self, Buff* buff); void timeBuffTimeout(EntityRef self); - void tickDrain(EntityRef self, Buff* buff); + void tickDrain(EntityRef self, Buff* buff, int mult); }