From 0f09808bc42b92dbcdebf0f02935b423fb2e12fd Mon Sep 17 00:00:00 2001 From: gsemaj Date: Tue, 25 Jul 2023 10:43:48 -0400 Subject: [PATCH] Get rid of cbf --- src/CustomCommands.cpp | 1 - src/Entities.cpp | 8 +++++++- src/Entities.hpp | 6 +++--- src/MobAI.cpp | 45 +++++++++++++----------------------------- src/MobAI.hpp | 4 ---- 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/CustomCommands.cpp b/src/CustomCommands.cpp index 217a33b..2021d32 100644 --- a/src/CustomCommands.cpp +++ b/src/CustomCommands.cpp @@ -678,7 +678,6 @@ static void whoisCommand(std::string full, std::vector& args, CNSoc Chat::sendServerMessage(sock, "[WHOIS] ID: " + std::to_string(npc->id)); Chat::sendServerMessage(sock, "[WHOIS] Type: " + std::to_string(npc->type)); Chat::sendServerMessage(sock, "[WHOIS] HP: " + std::to_string(npc->hp)); - Chat::sendServerMessage(sock, "[WHOIS] CBF: " + std::to_string(npc->cbf)); Chat::sendServerMessage(sock, "[WHOIS] EntityType: " + std::to_string((int)npc->kind)); Chat::sendServerMessage(sock, "[WHOIS] X: " + std::to_string(npc->x)); Chat::sendServerMessage(sock, "[WHOIS] Y: " + std::to_string(npc->y)); diff --git a/src/Entities.cpp b/src/Entities.cpp index 77b5e3f..bd97981 100644 --- a/src/Entities.cpp +++ b/src/Entities.cpp @@ -40,7 +40,7 @@ sNPCAppearanceData BaseNPC::getAppearanceData() { sNPCAppearanceData data = {}; data.iAngle = angle; data.iBarkerType = 0; // unused? - data.iConditionBitFlag = cbf; + data.iConditionBitFlag = 0; data.iHP = hp; data.iNPCType = type; data.iNPC_ID = id; @@ -50,6 +50,12 @@ sNPCAppearanceData BaseNPC::getAppearanceData() { return data; } +sNPCAppearanceData CombatNPC::getAppearanceData() { + sNPCAppearanceData data = BaseNPC::getAppearanceData(); + data.iConditionBitFlag = getCompositeCondition(); + return data; +} + /* * Entity coming into view. */ diff --git a/src/Entities.hpp b/src/Entities.hpp index 816fbbe..d84f756 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -73,7 +73,6 @@ public: int type; int hp; int angle; - int cbf; bool loopingPath = false; BaseNPC(int _A, uint64_t iID, int t, int _id) { @@ -81,7 +80,6 @@ public: type = t; hp = 400; angle = _A; - cbf = 0; id = _id; instanceID = iID; }; @@ -89,7 +87,7 @@ public: virtual void enterIntoViewOf(CNSocket *sock) override; virtual void disappearFromViewOf(CNSocket *sock) override; - sNPCAppearanceData getAppearanceData(); + virtual sNPCAppearanceData getAppearanceData(); }; struct CombatNPC : public BaseNPC, public ICombatant { @@ -118,6 +116,8 @@ struct CombatNPC : public BaseNPC, public ICombatant { transitionHandlers[AIState::INACTIVE] = {}; } + virtual sNPCAppearanceData getAppearanceData() override; + virtual bool isExtant() override { return hp > 0; } virtual bool addBuff(int buffId, BuffCallback onUpdate, BuffCallback onTick, BuffStack* stack) override; diff --git a/src/MobAI.cpp b/src/MobAI.cpp index 26552f1..42a12df 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -51,13 +51,13 @@ int Mob::takeDamage(EntityRef src, int amt) { } // wake up sleeping monster - if (cbf & CSB_BIT_MEZ) { - cbf &= ~CSB_BIT_MEZ; + if (hasBuff(ECSB_MEZ)) { + removeBuff(ECSB_MEZ); INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1); pkt1.eCT = 2; pkt1.iID = id; - pkt1.iConditionBitFlag = cbf; + pkt1.iConditionBitFlag = getCompositeCondition(); NPCManager::sendToViewable(this, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT)); } @@ -96,13 +96,12 @@ static std::pair lerp(int x1, int y1, int x2, int y2, int speed) { void MobAI::clearDebuff(Mob *mob) { mob->skillStyle = -1; - mob->cbf = 0; - mob->unbuffTimes.clear(); + mob->clearBuffs(false); INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1); pkt1.eCT = 2; pkt1.iID = mob->id; - pkt1.iConditionBitFlag = mob->cbf; + pkt1.iConditionBitFlag = mob->getCompositeCondition(); NPCManager::sendToViewable(mob, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT)); } @@ -555,7 +554,7 @@ void MobAI::combatStep(CombatNPC* npc, time_t currTime) { // drain if (self->skillStyle < 0 && (self->lastDrainTime == 0 || currTime - self->lastDrainTime >= 1000) - && self->cbf & CSB_BIT_BOUNDINGBALL) { + && self->hasBuff(ECSB_BOUNDINGBALL)) { drainMobHP(self, self->maxHealth / 20); // lose 5% every second self->lastDrainTime = currTime; } @@ -564,27 +563,13 @@ void MobAI::combatStep(CombatNPC* npc, time_t currTime) { if (self->hp <= 0) return; - // unbuffing - std::unordered_map::iterator it = self->unbuffTimes.begin(); - while (it != self->unbuffTimes.end()) { - - if (currTime >= it->second) { - self->cbf &= ~it->first; - - INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1); - pkt1.eCT = 2; - pkt1.iID = self->id; - pkt1.iConditionBitFlag = self->cbf; - NPCManager::sendToViewable(self, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT)); - - it = self->unbuffTimes.erase(it); - } else { - it++; - } - } + // tick buffs TODO abilities + //for(auto buffEntry : self->buffs) { + // buffEntry.second->combatTick(currTime); + //} // skip attack if stunned or asleep - if (self->cbf & (CSB_BIT_STUN|CSB_BIT_MEZ)) { + if (self->hasBuff(ECSB_STUN) || self->hasBuff(ECSB_MEZ)) { self->skillStyle = -1; // in this case we also reset the any outlying abilities the mob might be winding up. return; } @@ -609,7 +594,7 @@ void MobAI::combatStep(CombatNPC* npc, time_t currTime) { self->nextAttack = 0; // halve movement speed if snared - if (self->cbf & CSB_BIT_DN_MOVE_SPEED) + if (self->hasBuff(ECSB_DN_MOVE_SPEED)) self->speed /= 2; int targetX = plr->x; @@ -715,7 +700,7 @@ void MobAI::roamingStep(CombatNPC* npc, time_t currTime) { farY = std::clamp(farY, yStart, yStart + self->idleRange); // halve movement speed if snared - if (self->cbf & CSB_BIT_DN_MOVE_SPEED) + if (self->hasBuff(ECSB_DN_MOVE_SPEED)) self->speed /= 2; std::queue queue; @@ -788,7 +773,6 @@ void MobAI::onRoamStart(CombatNPC* npc, EntityRef src) { self->hp = self->maxHealth; self->killedTime = 0; self->nextAttack = 0; - self->cbf = 0; // cast a return home heal spell, this is the right way(tm) // TODO ABILITIES @@ -833,9 +817,8 @@ void MobAI::onDeath(CombatNPC* npc, EntityRef src) { Mob* self = (Mob*)npc; self->target = nullptr; - self->cbf = 0; self->skillStyle = -1; - self->unbuffTimes.clear(); + self->clearBuffs(true); self->killedTime = getTime(); // XXX: maybe introduce a shard-global time for each step? // check for the edge case where hitting the mob did not aggro it diff --git a/src/MobAI.hpp b/src/MobAI.hpp index 0941919..3e74d3f 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -21,8 +21,6 @@ namespace MobAI { } struct Mob : public CombatNPC { - // general - std::unordered_map unbuffTimes = {}; // dead time_t killedTime = 0; @@ -71,8 +69,6 @@ struct Mob : public CombatNPC { offsetX = 0; offsetY = 0; - cbf = 0; - // NOTE: there appear to be discrepancies in the dump hp = maxHealth;