From b4bab425f5b505b2a50cacc3b1a33622e6e26c7f Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sat, 8 Apr 2017 02:06:49 -0400 Subject: [PATCH] Refactor OP_BeginCast into it's own function --- zone/attack.cpp | 9 +-------- zone/mob.h | 1 + zone/spells.cpp | 42 +++++++++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/zone/attack.cpp b/zone/attack.cpp index c292a0e91..47e082747 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -3901,14 +3901,7 @@ void Mob::TrySpellProc(const EQEmu::ItemInstance *inst, const EQEmu::ItemData *w Log(Logs::Detail, Logs::Combat, "Spell proc %d procing spell %d (%.2f percent chance)", i, SpellProcs[i].spellID, chance); - auto outapp = new EQApplicationPacket(OP_BeginCast,sizeof(BeginCast_Struct)); - BeginCast_Struct* begincast = (BeginCast_Struct*)outapp->pBuffer; - begincast->caster_id = GetID(); - begincast->spell_id = SpellProcs[i].spellID; - begincast->cast_time = 0; - outapp->priority = 3; - entity_list.QueueCloseClients(this, outapp, false, RuleI(Range, SpellMessages), 0, true); - safe_delete(outapp); + SendBeginCast(SpellProcs[i].spellID, 0); ExecWeaponProc(nullptr, SpellProcs[i].spellID, on, SpellProcs[i].level_override); CheckNumHitsRemaining(NumHit::OffensiveSpellProcs, 0, SpellProcs[i].base_spellID); diff --git a/zone/mob.h b/zone/mob.h index 81ef7d14a..7e3535a73 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -279,6 +279,7 @@ public: uint32 inventory_slot = 0xFFFFFFFF, int16 resist_adjust = 0); bool SpellFinished(uint16 spell_id, Mob *target, EQEmu::CastingSlot slot = EQEmu::CastingSlot::Item, uint16 mana_used = 0, uint32 inventory_slot = 0xFFFFFFFF, int16 resist_adjust = 0, bool isproc = false, int level_override = -1); + void SendBeginCast(uint16 spell_id, uint32 casttime); virtual bool SpellOnTarget(uint16 spell_id, Mob* spelltar, bool reflect = false, bool use_resist_adjust = false, int16 resist_adjust = 0, bool isproc = false, int level_override = -1); virtual bool SpellEffect(Mob* caster, uint16 spell_id, float partial = 100, int level_override = -1); diff --git a/zone/spells.cpp b/zone/spells.cpp index 4544246a3..f7258e1dd 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -477,23 +477,8 @@ bool Mob::DoCastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot, // now tell the people in the area -- we ALWAYS want to send this, even instant cast spells. // The only time this is skipped is for NPC innate procs and weapon procs. Procs from buffs // oddly still send this. Since those cases don't reach here, we don't need to check them - if (slot != CastingSlot::Discipline) { - auto outapp = new EQApplicationPacket(OP_BeginCast,sizeof(BeginCast_Struct)); - BeginCast_Struct* begincast = (BeginCast_Struct*)outapp->pBuffer; - begincast->caster_id = GetID(); - begincast->spell_id = spell_id; - begincast->cast_time = orgcasttime; // client calculates reduced time by itself - outapp->priority = 3; - entity_list.QueueCloseClients( - this, /* Sender */ - outapp, /* Packet */ - false, /* Ignore Sender */ - RuleI(Range, BeginCast), - 0, /* Skip this Mob */ - true /* Packet ACK */ - ); //IsClient() ? FILTER_PCSPELLS : FILTER_NPCSPELLS); - safe_delete(outapp); - } + if (slot != CastingSlot::Discipline) + SendBeginCast(spell_id, orgcasttime); // cast time is 0, just finish it right now and be done with it if(cast_time == 0) { @@ -536,6 +521,29 @@ bool Mob::DoCastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot, return(true); } +void Mob::SendBeginCast(uint16 spell_id, uint32 casttime) +{ + auto outapp = new EQApplicationPacket(OP_BeginCast, sizeof(BeginCast_Struct)); + auto begincast = (BeginCast_Struct *)outapp->pBuffer; + + begincast->caster_id = GetID(); + begincast->spell_id = spell_id; + begincast->cast_time = casttime; // client calculates reduced time by itself + + outapp->priority = 3; + + entity_list.QueueCloseClients( + this, /* Sender */ + outapp, /* Packet */ + false, /* Ignore Sender */ + RuleI(Range, BeginCast), + 0, /* Skip this Mob */ + true /* Packet ACK */ + ); //IsClient() ? FILTER_PCSPELLS : FILTER_NPCSPELLS); + + safe_delete(outapp); +} + /* * Some failures should be caught before the spell finishes casting * This is especially helpful to clients when they cast really long things