From 3f4aca8a5d28f3fbea44607b4cb61e6a9198cab0 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sun, 20 Jun 2021 14:39:59 -0400 Subject: [PATCH] [WIP] Use EntityRef instead of CNSocket in ability handler --- src/Abilities.hpp | 11 ++++++++--- src/MobAI.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Abilities.hpp b/src/Abilities.hpp index 180234e..760ec56 100644 --- a/src/Abilities.hpp +++ b/src/Abilities.hpp @@ -3,7 +3,7 @@ #include "core/Core.hpp" #include "Combat.hpp" -typedef void (*PowerHandler)(CNSocket*, std::vector, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t); +typedef void (*PowerHandler)(EntityRef, std::vector, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t); struct Power { int16_t skillType; @@ -13,11 +13,16 @@ struct Power { Power(int16_t s, int32_t b, int16_t t, PowerHandler h) : skillType(s), bitFlag(b), timeBuffID(t), handler(h) {} - void handle(CNSocket *sock, std::vector targetData, int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount) { + void handle(EntityRef ref, std::vector targetData, int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount) { if (handler == nullptr) return; - handler(sock, targetData, nanoID, skillID, duration, amount, skillType, bitFlag, timeBuffID); + handler(ref, targetData, nanoID, skillID, duration, amount, skillType, bitFlag, timeBuffID); + } + + /* overload for non-nano abilities */ + void handle(EntityRef ref, std::vector targetData, int16_t skillID, int16_t duration, int16_t amount) { + handle(ref, targetData, -1, skillID, duration, amount); } }; diff --git a/src/MobAI.cpp b/src/MobAI.cpp index e396499..4808156 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -330,7 +330,7 @@ static void useAbilities(Mob *mob, time_t currTime) { for (auto& pwr : Abilities::Powers) if (pwr.skillType == Abilities::SkillTable[skillID].skillType) - pwr.handle(mob, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); + pwr.handle(mob->id, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); mob->skillStyle = -3; // eruption cooldown mob->nextAttack = currTime + 1000; return; @@ -353,7 +353,7 @@ static void useAbilities(Mob *mob, time_t currTime) { if (pwr.skillType == Abilities::SkillTable[skillID].skillType) { if (pwr.bitFlag != 0 && (plr->iConditionBitFlag & pwr.bitFlag)) return; // prevent debuffing a player twice - pwr.handle(mob, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); + pwr.handle(mob->id, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); } mob->nextAttack = currTime + (int)mob->data["m_iDelayTime"] * 100; return; @@ -409,7 +409,7 @@ void MobAI::enterCombat(CNSocket *sock, Mob *mob) { std::vector targetData = {1, mob->id, 0, 0, 0}; for (auto& pwr : Abilities::Powers) if (pwr.skillType == Abilities::SkillTable[skillID].skillType) - pwr.handle(mob, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); + pwr.handle(mob->id, targetData, skillID, Abilities::SkillTable[skillID].durationTime[0], Abilities::SkillTable[skillID].powerIntensity[0]); for (NPCEvent& event : NPCManager::NPCEvents) // trigger an ON_COMBAT if (event.trigger == ON_COMBAT && event.npcType == mob->type) @@ -772,7 +772,7 @@ static void retreatStep(Mob *mob, time_t currTime) { std::vector targetData = {1, 0, 0, 0, 0}; for (auto& pwr : Abilities::Powers) if (pwr.skillType == Abilities::SkillTable[110].skillType) - pwr.handle(mob, targetData, 110, Abilities::SkillTable[110].durationTime[0], Abilities::SkillTable[110].powerIntensity[0]); + pwr.handle(mob->id, targetData, 110, Abilities::SkillTable[110].durationTime[0], Abilities::SkillTable[110].powerIntensity[0]); // clear outlying debuffs clearDebuff(mob); }