Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
5985 lines (5202 sloc) 182 KB
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
General outline of spell casting process
1.
a) Client clicks a spell bar gem, ability, or item. client_process.cpp
gets the op and calls CastSpell() with all the relevant info including
cast time.
b) NPC does CastSpell() from AI
2.
a) CastSpell() determines there is a cast time and sets some state keeping
flags to be used to check the progress of casting and finish it later.
b) CastSpell() sees there's no cast time, and calls CastedSpellFinished()
Go to step 4.
3.
SpellProcess() notices that the spell casting timer which was set by
CastSpell() is expired, and calls CastedSpellFinished()
4.
CastedSpellFinished() checks some timed spell specific things, like
wether to interrupt or not, due to movement or melee. If successful
SpellFinished() is called.
5.
SpellFinished() checks some things like LoS, reagents, target and
figures out what's going to get hit by this spell based on its type.
6.
a) Single target spell, SpellOnTarget() is called.
b) AE spell, Entity::AESpell() is called.
c) Group spell, Group::CastGroupSpell()/SpellOnTarget() is called as
needed.
7.
SpellOnTarget() may or may not call SpellEffect() to cause effects to
the target
8.
If this was timed, CastedSpellFinished() will restore the client's
spell bar gems.
Most user code should call CastSpell(), with a 0 casting time if needed,
and not SpellFinished().
*/
#include "../common/bodytypes.h"
#include "../common/classes.h"
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "../common/item_instance.h"
#include "../common/rulesys.h"
#include "../common/skills.h"
#include "../common/spdat.h"
#include "../common/string_util.h"
#include "../common/data_verification.h"
#include "../common/misc_functions.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "worldserver.h"
#include "fastmath.h"
#include <assert.h>
#include <math.h>
#include <algorithm>
#ifndef WIN32
#include <stdlib.h>
#include "../common/unix.h"
#endif
#ifdef _GOTFRAGS
#include "../common/packet_dump_file.h"
#endif
#ifdef BOTS
#include "bot.h"
#endif
#include "mob_movement_manager.h"
extern Zone* zone;
extern volatile bool is_zone_loaded;
extern WorldServer worldserver;
extern FastMath g_Math;
using EQEmu::spells::CastingSlot;
// this is run constantly for every mob
void Mob::SpellProcess()
{
// check the rapid recast prevention timer
if(delaytimer == true && spellend_timer.Check())
{
spellend_timer.Disable();
delaytimer = false;
return;
}
// a timed spell is finished casting
if (casting_spell_id != 0 && casting_spell_checks && spellend_timer.Check())
{
spellend_timer.Disable();
delaytimer = false;
CastedSpellFinished(casting_spell_id, casting_spell_targetid, casting_spell_slot,
casting_spell_mana, casting_spell_inventory_slot, casting_spell_resist_adjust);
}
}
void NPC::SpellProcess()
{
Mob::SpellProcess();
if (swarm_timer.Check()) {
DepopSwarmPets();
}
}
///////////////////////////////////////////////////////////////////////////////
// functions related to begin/finish casting, fizzling etc
//
// only CastSpell and DoCastSpell should be setting casting_spell_id.
// basically casting_spell_id is only set when casting a triggered spell from
// the spell bar gems, an ability, or an item. note that it's actually set
// even if it's a 0 cast time, but then the spell is finished right after and
// it's unset. this is ok, since the 0 cast time spell is still a triggered
// one.
// the rule is you can cast one triggered (usually timed) spell at a time
// but things like SpellFinished() can run concurrent with a triggered cast
// to allow procs to work
bool Mob::CastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot,
int32 cast_time, int32 mana_cost, uint32* oSpellWillFinish, uint32 item_slot,
uint32 timer, uint32 timer_duration, int16 *resist_adjust,
uint32 aa_id)
{
LogSpells("CastSpell called for spell [{}] ([{}]) on entity [{}], slot [{}], time [{}], mana [{}], from item slot [{}]",
(IsValidSpell(spell_id))?spells[spell_id].name:"UNKNOWN SPELL", spell_id, target_id, static_cast<int>(slot), cast_time, mana_cost, (item_slot==0xFFFFFFFF)?999:item_slot);
if(casting_spell_id == spell_id)
ZeroCastingVars();
if
(
!IsValidSpell(spell_id) ||
casting_spell_id ||
delaytimer ||
spellend_timer.Enabled() ||
IsStunned() ||
IsFeared() ||
IsMezzed() ||
(IsSilenced() && !IsDiscipline(spell_id)) ||
(IsAmnesiad() && IsDiscipline(spell_id))
)
{
LogSpells("Spell casting canceled: not able to cast now. Valid? [{}], casting [{}], waiting? [{}], spellend? [{}], stunned? [{}], feared? [{}], mezed? [{}], silenced? [{}], amnesiad? [{}]",
IsValidSpell(spell_id), casting_spell_id, delaytimer, spellend_timer.Enabled(), IsStunned(), IsFeared(), IsMezzed(), IsSilenced(), IsAmnesiad() );
if(IsSilenced() && !IsDiscipline(spell_id))
MessageString(Chat::Red, SILENCED_STRING);
if(IsAmnesiad() && IsDiscipline(spell_id))
MessageString(Chat::Red, MELEE_SILENCE);
if(IsClient())
CastToClient()->SendSpellBarEnable(spell_id);
if(casting_spell_id && IsNPC())
CastToNPC()->AI_Event_SpellCastFinished(false, static_cast<uint16>(casting_spell_slot));
return(false);
}
//It appears that the Sanctuary effect is removed by a check on the client side (keep this however for redundancy)
if (spellbonuses.Sanctuary && (spells[spell_id].targettype != ST_Self && GetTarget() != this) || IsDetrimentalSpell(spell_id))
BuffFadeByEffect(SE_Sanctuary);
if(IsClient()){
int chance = CastToClient()->GetFocusEffect(focusFcMute, spell_id);//Client only
if (zone->random.Roll(chance)) {
MessageString(Chat::Red, SILENCED_STRING);
if(IsClient())
CastToClient()->SendSpellBarEnable(spell_id);
return(false);
}
}
if(IsDetrimentalSpell(spell_id) && !zone->CanDoCombat()){
MessageString(Chat::Red, SPELL_WOULDNT_HOLD);
if(IsClient())
CastToClient()->SendSpellBarEnable(spell_id);
if(casting_spell_id && IsNPC())
CastToNPC()->AI_Event_SpellCastFinished(false, static_cast<uint16>(casting_spell_slot));
return(false);
}
//cannot cast under divine aura
if(DivineAura()) {
LogSpells("Spell casting canceled: cannot cast while Divine Aura is in effect");
InterruptSpell(173, 0x121, false);
return(false);
}
if (spellbonuses.NegateIfCombat)
BuffFadeByEffect(SE_NegateIfCombat);
if(IsClient() && GetTarget() && IsHarmonySpell(spell_id))
{
for(int i = 0; i < EFFECT_COUNT; i++) {
// not important to check limit on SE_Lull as it doesnt have one and if the other components won't land, then SE_Lull wont either
if (spells[spell_id].effectid[i] == SE_ChangeFrenzyRad || spells[spell_id].effectid[i] == SE_Harmony) {
if((spells[spell_id].max[i] != 0 && GetTarget()->GetLevel() > spells[spell_id].max[i]) || GetTarget()->GetSpecialAbility(IMMUNE_PACIFY)) {
InterruptSpell(CANNOT_AFFECT_NPC, 0x121, spell_id);
return(false);
}
}
}
}
if (HasActiveSong() && IsBardSong(spell_id)) {
LogSpells("Casting a new song while singing a song. Killing old song [{}]", bardsong);
//Note: this does NOT tell the client
_StopSong();
}
//Added to prevent MQ2 exploitation of equipping normally-unequippable/clickable items with effects and clicking them for benefits.
if(item_slot && IsClient() && (slot == CastingSlot::Item || slot == CastingSlot::PotionBelt))
{
EQEmu::ItemInstance *itm = CastToClient()->GetInv().GetItem(item_slot);
int bitmask = 1;
bitmask = bitmask << (CastToClient()->GetClass() - 1);
if( itm && itm->GetItem()->Classes != 65535 ) {
if ((itm->GetItem()->Click.Type == EQEmu::item::ItemEffectEquipClick) && !(itm->GetItem()->Classes & bitmask)) {
if (CastToClient()->ClientVersion() < EQEmu::versions::ClientVersion::SoF) {
// They are casting a spell from an item that requires equipping but shouldn't let them equip it
LogError("HACKER: [{}] (account: [{}]) attempted to click an equip-only effect on item [{}] (id: [{}]) which they shouldn't be able to equip!",
CastToClient()->GetCleanName(), CastToClient()->AccountName(), itm->GetItem()->Name, itm->GetItem()->ID);
database.SetHackerFlag(CastToClient()->AccountName(), CastToClient()->GetCleanName(), "Clicking equip-only item with an invalid class");
}
else {
MessageString(Chat::Red, MUST_EQUIP_ITEM);
}
return(false);
}
if ((itm->GetItem()->Click.Type == EQEmu::item::ItemEffectClick2) && !(itm->GetItem()->Classes & bitmask)) {
if (CastToClient()->ClientVersion() < EQEmu::versions::ClientVersion::SoF) {
// They are casting a spell from an item that they don't meet the race/class requirements to cast
LogError("HACKER: [{}] (account: [{}]) attempted to click a race/class restricted effect on item [{}] (id: [{}]) which they shouldn't be able to click!",
CastToClient()->GetCleanName(), CastToClient()->AccountName(), itm->GetItem()->Name, itm->GetItem()->ID);
database.SetHackerFlag(CastToClient()->AccountName(), CastToClient()->GetCleanName(), "Clicking race/class restricted item with an invalid class");
}
else {
if (CastToClient()->ClientVersion() >= EQEmu::versions::ClientVersion::RoF)
{
// Line 181 in eqstr_us.txt was changed in RoF+
Message(Chat::Yellow, "Your race, class, or deity cannot use this item.");
}
else
{
MessageString(Chat::Red, CANNOT_USE_ITEM);
}
}
return(false);
}
}
if (itm && (itm->GetItem()->Click.Type == EQEmu::item::ItemEffectEquipClick) && item_slot > EQEmu::invslot::EQUIPMENT_END){
if (CastToClient()->ClientVersion() < EQEmu::versions::ClientVersion::SoF) {
// They are attempting to cast a must equip clicky without having it equipped
LogError("HACKER: [{}] (account: [{}]) attempted to click an equip-only effect on item [{}] (id: [{}]) without equiping it!", CastToClient()->GetCleanName(), CastToClient()->AccountName(), itm->GetItem()->Name, itm->GetItem()->ID);
database.SetHackerFlag(CastToClient()->AccountName(), CastToClient()->GetCleanName(), "Clicking equip-only item without equiping it");
}
else {
MessageString(Chat::Red, MUST_EQUIP_ITEM);
}
return(false);
}
}
if(IsClient()) {
char temp[64];
sprintf(temp, "%d", spell_id);
if (parse->EventPlayer(EVENT_CAST_BEGIN, CastToClient(), temp, 0) != 0)
return false;
} else if(IsNPC()) {
char temp[64];
sprintf(temp, "%d", spell_id);
parse->EventNPC(EVENT_CAST_BEGIN, CastToNPC(), nullptr, temp, 0);
}
//To prevent NPC ghosting when spells are cast from scripts
if (IsNPC() && IsMoving() && cast_time > 0) {
StopNavigation();
}
if(resist_adjust)
{
return(DoCastSpell(spell_id, target_id, slot, cast_time, mana_cost, oSpellWillFinish, item_slot, timer, timer_duration, *resist_adjust, aa_id));
}
else
{
return(DoCastSpell(spell_id, target_id, slot, cast_time, mana_cost, oSpellWillFinish, item_slot, timer, timer_duration, spells[spell_id].ResistDiff, aa_id));
}
}
//
// the order of things here is intentional and important. make sure you
// understand the whole spell casting process and the flags that are passed
// around if you're gonna modify this
//
// this is the 2nd phase of CastSpell, broken up like this to make it easier
// to repeat a spell for bard songs
//
bool Mob::DoCastSpell(uint16 spell_id, uint16 target_id, CastingSlot slot,
int32 cast_time, int32 mana_cost, uint32* oSpellWillFinish,
uint32 item_slot, uint32 timer, uint32 timer_duration,
int16 resist_adjust, uint32 aa_id)
{
Mob* pMob = nullptr;
int32 orgcasttime;
if(!IsValidSpell(spell_id)) {
InterruptSpell();
return(false);
}
const SPDat_Spell_Struct &spell = spells[spell_id];
LogSpells("DoCastSpell called for spell [{}] ([{}]) on entity [{}], slot [{}], time [{}], mana [{}], from item [{}]",
spell.name, spell_id, target_id, static_cast<int>(slot), cast_time, mana_cost, item_slot==0xFFFFFFFF?999:item_slot);
casting_spell_id = spell_id;
casting_spell_slot = slot;
casting_spell_inventory_slot = item_slot;
if(casting_spell_timer != 0xFFFFFFFF)
{
casting_spell_timer = timer;
casting_spell_timer_duration = timer_duration;
}
casting_spell_aa_id = aa_id;
// check for fizzle
// note that CheckFizzle itself doesn't let NPCs fizzle,
// but this code allows for it.
if (slot < CastingSlot::MaxGems && !CheckFizzle(spell_id)) {
int fizzle_msg = IsBardSong(spell_id) ? MISS_NOTE : SPELL_FIZZLE;
uint32 use_mana = ((spells[spell_id].mana) / 4);
LogSpells("Spell casting canceled: fizzled. [{}] mana has been consumed", use_mana);
// fizzle 1/4 the mana away
Mob::SetMana(GetMana() - use_mana); // We send StopCasting which will update mana
StopCasting();
MessageString(Chat::SpellFailure, fizzle_msg);
/**
* Song Failure message
*/
entity_list.FilteredMessageCloseString(
this,
true,
RuleI(Range, SpellMessages),
Chat::SpellFailure,
(IsClient() ? FilterPCSpells : FilterNPCSpells),
(fizzle_msg == MISS_NOTE ? MISSED_NOTE_OTHER : SPELL_FIZZLE_OTHER),
/*
MessageFormat: You miss a note, bringing your song to a close! (if missed note)
MessageFormat: A missed note brings %1's song to a close!
MessageFormat: %1's spell fizzles!
*/
GetName()
);
TryTriggerOnValueAmount(false, true);
return(false);
}
SaveSpellLoc();
LogSpells("Casting [{}] Started at ({},{},{})", spell_id, m_SpellLocation.x, m_SpellLocation.y, m_SpellLocation.z);
// if this spell doesn't require a target, or if it's an optional target
// and a target wasn't provided, then it's us; unless TGB is on and this
// is a TGB compatible spell.
if((IsGroupSpell(spell_id) ||
spell.targettype == ST_AEClientV1 ||
spell.targettype == ST_Self ||
spell.targettype == ST_AECaster ||
spell.targettype == ST_Ring ||
spell.targettype == ST_Beam ||
spell.targettype == ST_TargetOptional) && target_id == 0)
{
LogSpells("Spell [{}] auto-targeted the caster. Group? [{}], target type [{}]", spell_id, IsGroupSpell(spell_id), spell.targettype);
target_id = GetID();
}
if(cast_time <= -1) {
// save the non-reduced cast time to use in the packet
cast_time = orgcasttime = spell.cast_time;
// if there's a cast time, check if they have a modifier for it
if(cast_time) {
cast_time = GetActSpellCasttime(spell_id, cast_time);
}
}
else
orgcasttime = cast_time;
// we checked for spells not requiring targets above
if(target_id == 0) {
LogSpells("Spell Error: no target. spell=[{}]", spell_id);
if(IsClient()) {
//clients produce messages... npcs should not for this case
MessageString(Chat::Red, SPELL_NEED_TAR);
InterruptSpell();
} else {
InterruptSpell(0, 0, 0); //the 0 args should cause no messages
}
return(false);
}
// ok now we know the target
casting_spell_targetid = target_id;
// We don't get actual mana cost here, that's done when we consume the mana
if (mana_cost == -1)
mana_cost = spell.mana;
// mana is checked for clients on the frontend. we need to recheck it for NPCs though
// If you're at full mana, let it cast even if you dont have enough mana
// we calculated this above, now enforce it
if(mana_cost > 0 && slot != CastingSlot::Item)
{
int my_curmana = GetMana();
int my_maxmana = GetMaxMana();
if(my_curmana < mana_cost) // not enough mana
{
//this is a special case for NPCs with no mana...
if(IsNPC() && my_curmana == my_maxmana)
{
mana_cost = 0;
} else {
LogSpells("Spell Error not enough mana spell=[{}] mymana=[{}] cost=[{}]\n", spell_id, my_curmana, mana_cost);
if(IsClient()) {
//clients produce messages... npcs should not for this case
MessageString(Chat::Red, INSUFFICIENT_MANA);
InterruptSpell();
} else {
InterruptSpell(0, 0, 0); //the 0 args should cause no messages
}
return(false);
}
}
}
if(mana_cost > GetMana())
mana_cost = GetMana();
// we know our mana cost now
casting_spell_mana = mana_cost;
casting_spell_resist_adjust = resist_adjust;
LogSpells("Spell [{}]: Casting time [{}] (orig [{}]), mana cost [{}]",
spell_id, cast_time, orgcasttime, mana_cost);
// 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)
SendBeginCast(spell_id, orgcasttime);
// cast time is 0, just finish it right now and be done with it
if(cast_time == 0) {
if (!DoCastingChecks()) {
StopCasting();
return false;
}
CastedSpellFinished(spell_id, target_id, slot, mana_cost, item_slot, resist_adjust);
return(true);
}
cast_time = mod_cast_time(cast_time);
// ok we know it has a cast time so we can start the timer now
spellend_timer.Start(cast_time);
if (IsAIControlled())
{
SetRunAnimSpeed(0);
pMob = entity_list.GetMob(target_id);
if (pMob && this != pMob)
FaceTarget(pMob);
}
// if we got here we didn't fizzle, and are starting our cast
if (oSpellWillFinish)
*oSpellWillFinish = Timer::GetCurrentTime() + cast_time + 100;
if (IsClient() && slot == CastingSlot::Item && item_slot != 0xFFFFFFFF) {
auto item = CastToClient()->GetInv().GetItem(item_slot);
if (item && item->GetItem())
MessageString(Chat::Spells, BEGINS_TO_GLOW, item->GetItem()->Name);
}
if (!DoCastingChecks()) {
StopCasting();
return false;
}
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
* If this passes it sets casting_spell_checks to true which is checked in
* SpellProcess(), if a situation ever arises where a spell is delayed by these
* it's probably doing something wrong.
*/
bool Mob::DoCastingChecks()
{
if (!IsClient() || (IsClient() && CastToClient()->GetGM())) {
casting_spell_checks = true;
return true;
}
uint16 spell_id = casting_spell_id;
Mob *spell_target = entity_list.GetMob(casting_spell_targetid);
if (RuleB(Spells, BuffLevelRestrictions)) {
// casting_spell_targetid is guaranteed to be what we went, check for ST_Self for now should work though
if (spell_target && spells[spell_id].targettype != ST_Self && !spell_target->CheckSpellLevelRestriction(spell_id)) {
LogSpells("Spell [{}] failed: recipient did not meet the level restrictions", spell_id);
if (!IsBardSong(spell_id))
MessageString(Chat::SpellFailure, SPELL_TOO_POWERFUL);
return false;
}
}
if (spells[spell_id].zonetype == 1 && !zone->CanCastOutdoor()) {
MessageString(Chat::Red, CAST_OUTDOORS);
return false;
}
if (IsEffectInSpell(spell_id, SE_Levitate) && !zone->CanLevitate()) {
Message(Chat::Red, "You can't levitate in this zone.");
return false;
}
if(zone->IsSpellBlocked(spell_id, glm::vec3(GetPosition()))) {
const char *msg = zone->GetSpellBlockedMessage(spell_id, glm::vec3(GetPosition()));
if (msg) {
Message(Chat::Red, msg);
return false;
} else {
Message(Chat::Red, "You can't cast this spell here.");
return false;
}
}
if (IsClient() && spells[spell_id].EndurTimerIndex > 0 && casting_spell_slot < CastingSlot::MaxGems)
if (!CastToClient()->IsLinkedSpellReuseTimerReady(spells[spell_id].EndurTimerIndex))
return false;
casting_spell_checks = true;
return true;
}
uint16 Mob::GetSpecializeSkillValue(uint16 spell_id) const {
switch(spells[spell_id].skill) {
case EQEmu::skills::SkillAbjuration:
return(GetSkill(EQEmu::skills::SkillSpecializeAbjure));
case EQEmu::skills::SkillAlteration:
return(GetSkill(EQEmu::skills::SkillSpecializeAlteration));
case EQEmu::skills::SkillConjuration:
return(GetSkill(EQEmu::skills::SkillSpecializeConjuration));
case EQEmu::skills::SkillDivination:
return(GetSkill(EQEmu::skills::SkillSpecializeDivination));
case EQEmu::skills::SkillEvocation:
return(GetSkill(EQEmu::skills::SkillSpecializeEvocation));
default:
//wtf...
break;
}
return(0);
}
void Client::CheckSpecializeIncrease(uint16 spell_id) {
// These are not active because CheckIncreaseSkill() already does so.
// It's such a rare occurance that adding them here is wasted..(ref only)
/*
if (IsDead() || IsUnconscious())
return;
if (IsAIControlled())
return;
*/
switch(spells[spell_id].skill) {
case EQEmu::skills::SkillAbjuration:
CheckIncreaseSkill(EQEmu::skills::SkillSpecializeAbjure, nullptr);
break;
case EQEmu::skills::SkillAlteration:
CheckIncreaseSkill(EQEmu::skills::SkillSpecializeAlteration, nullptr);
break;
case EQEmu::skills::SkillConjuration:
CheckIncreaseSkill(EQEmu::skills::SkillSpecializeConjuration, nullptr);
break;
case EQEmu::skills::SkillDivination:
CheckIncreaseSkill(EQEmu::skills::SkillSpecializeDivination, nullptr);
break;
case EQEmu::skills::SkillEvocation:
CheckIncreaseSkill(EQEmu::skills::SkillSpecializeEvocation, nullptr);
break;
default:
//wtf...
break;
}
}
void Client::CheckSongSkillIncrease(uint16 spell_id){
// These are not active because CheckIncreaseSkill() already does so.
// It's such a rare occurance that adding them here is wasted..(ref only)
/*
if (IsDead() || IsUnconscious())
return;
if (IsAIControlled())
return;
*/
switch(spells[spell_id].skill)
{
case EQEmu::skills::SkillSinging:
CheckIncreaseSkill(EQEmu::skills::SkillSinging, nullptr, -15);
break;
case EQEmu::skills::SkillPercussionInstruments:
if(this->itembonuses.percussionMod > 0) {
if (GetRawSkill(EQEmu::skills::SkillPercussionInstruments) > 0) // no skill increases if not trained in the instrument
CheckIncreaseSkill(EQEmu::skills::SkillPercussionInstruments, nullptr, -15);
else
MessageString(Chat::Red,NO_INSTRUMENT_SKILL); // tell the client that they need instrument training
}
else
CheckIncreaseSkill(EQEmu::skills::SkillSinging, nullptr, -15);
break;
case EQEmu::skills::SkillStringedInstruments:
if(this->itembonuses.stringedMod > 0) {
if (GetRawSkill(EQEmu::skills::SkillStringedInstruments) > 0)
CheckIncreaseSkill(EQEmu::skills::SkillStringedInstruments, nullptr, -15);
else
MessageString(Chat::Red,NO_INSTRUMENT_SKILL);
}
else
CheckIncreaseSkill(EQEmu::skills::SkillSinging, nullptr, -15);
break;
case EQEmu::skills::SkillWindInstruments:
if(this->itembonuses.windMod > 0) {
if (GetRawSkill(EQEmu::skills::SkillWindInstruments) > 0)
CheckIncreaseSkill(EQEmu::skills::SkillWindInstruments, nullptr, -15);
else
MessageString(Chat::Red,NO_INSTRUMENT_SKILL);
}
else
CheckIncreaseSkill(EQEmu::skills::SkillSinging, nullptr, -15);
break;
case EQEmu::skills::SkillBrassInstruments:
if(this->itembonuses.brassMod > 0) {
if (GetRawSkill(EQEmu::skills::SkillBrassInstruments) > 0)
CheckIncreaseSkill(EQEmu::skills::SkillBrassInstruments, nullptr, -15);
else
MessageString(Chat::Red,NO_INSTRUMENT_SKILL);
}
else
CheckIncreaseSkill(EQEmu::skills::SkillSinging, nullptr, -15);
break;
default:
break;
}
}
/*
returns true if spell is successful, false if it fizzled.
only works for clients, npcs shouldn't be fizzling..
new algorithm thats closer to live eq (i hope)
TODO: Add aa skills, item mods, reduced the chance to fizzle
*/
bool Mob::CheckFizzle(uint16 spell_id)
{
return(true);
}
bool Client::CheckFizzle(uint16 spell_id)
{
// GMs don't fizzle
if (GetGM()) return(true);
uint8 no_fizzle_level = 0;
//Live AA - Spell Casting Expertise, Mastery of the Past
no_fizzle_level = aabonuses.MasteryofPast + itembonuses.MasteryofPast + spellbonuses.MasteryofPast;
if (spells[spell_id].classes[GetClass()-1] < no_fizzle_level)
return true;
//is there any sort of focus that affects fizzling?
int par_skill;
int act_skill;
par_skill = spells[spell_id].classes[GetClass()-1] * 5 - 10;//IIRC even if you are lagging behind the skill levels you don't fizzle much
if (par_skill > 235)
par_skill = 235;
par_skill += spells[spell_id].classes[GetClass()-1]; // maximum of 270 for level 65 spell
act_skill = GetSkill(spells[spell_id].skill);
act_skill += GetLevel(); // maximum of whatever the client can cheat
act_skill += itembonuses.adjusted_casting_skill + spellbonuses.adjusted_casting_skill + aabonuses.adjusted_casting_skill;
LogSpells("Adjusted casting skill: [{}]+[{}]+[{}]+[{}]+[{}]=[{}]", GetSkill(spells[spell_id].skill), GetLevel(), itembonuses.adjusted_casting_skill, spellbonuses.adjusted_casting_skill, aabonuses.adjusted_casting_skill, act_skill);
//spell specialization
float specialize = GetSpecializeSkillValue(spell_id);
if(specialize > 0) {
switch(GetAA(aaSpellCastingMastery)){
case 1:
specialize = specialize * 1.05;
break;
case 2:
specialize = specialize * 1.15;
break;
case 3:
specialize = specialize * 1.3;
break;
}
if(((specialize/6.0f) + 15.0f) < zone->random.Real(0, 100)) {
specialize *= SPECIALIZE_FIZZLE / 200.0f;
} else {
specialize = 0.0f;
}
}
// == 0 --> on par
// > 0 --> skill is lower, higher chance of fizzle
// < 0 --> skill is better, lower chance of fizzle
// the max that diff can be is +- 235
float diff = par_skill + static_cast<float>(spells[spell_id].basediff) - act_skill;
// if you have high int/wis you fizzle less, you fizzle more if you are stupid
if(GetClass() == BARD)
{
diff -= (GetCHA() - 110) / 20.0;
}
else if (GetCasterClass() == 'W')
{
diff -= (GetWIS() - 125) / 20.0;
}
else if (GetCasterClass() == 'I')
{
diff -= (GetINT() - 125) / 20.0;
}
// base fizzlechance is lets say 5%, we can make it lower for AA skills or whatever
float basefizzle = 10;
float fizzlechance = basefizzle - specialize + diff / 5.0;
// always at least 1% chance to fail or 5% to succeed
fizzlechance = fizzlechance < 1 ? 1 : (fizzlechance > 95 ? 95 : fizzlechance);
float fizzle_roll = zone->random.Real(0, 100);
LogSpells("Check Fizzle [{}] spell [{}] fizzlechance: [{}] diff: [{}] roll: [{}]", GetName(), spell_id, fizzlechance, diff, fizzle_roll);
if(fizzle_roll > fizzlechance)
return(true);
return(false);
}
void Mob::ZeroCastingVars()
{
// zero out the state keeping vars
attacked_count = 0;
spellend_timer.Disable();
casting_spell_id = 0;
casting_spell_targetid = 0;
casting_spell_slot = CastingSlot::Gem1;
casting_spell_mana = 0;
casting_spell_inventory_slot = 0;
casting_spell_timer = 0;
casting_spell_timer_duration = 0;
casting_spell_resist_adjust = 0;
casting_spell_checks = false;
casting_spell_aa_id = 0;
delaytimer = false;
}
void Mob::InterruptSpell(uint16 spellid)
{
if (spellid == SPELL_UNKNOWN)
spellid = casting_spell_id;
InterruptSpell(0, 0x121, spellid);
}
// color not used right now
void Mob::InterruptSpell(uint16 message, uint16 color, uint16 spellid)
{
EQApplicationPacket *outapp = nullptr;
uint16 message_other;
bool bard_song_mode = false; //has the bard song gone to auto repeat mode
if (spellid == SPELL_UNKNOWN) {
if(bardsong) {
spellid = bardsong;
bard_song_mode = true;
} else {
spellid = casting_spell_id;
}
}
if(casting_spell_id && IsNPC()) {
CastToNPC()->AI_Event_SpellCastFinished(false, static_cast<uint16>(casting_spell_slot));
}
if(casting_spell_aa_id && IsClient()) { //Rest AA Timer on failed cast
CastToClient()->MessageString(Chat::SpellFailure, ABILITY_FAILED);
CastToClient()->ResetAlternateAdvancementTimer(casting_spell_aa_id);
}
ZeroCastingVars(); // resets all the state keeping stuff
LogSpells("Spell [{}] has been interrupted", spellid);
if(!spellid)
return;
if (bardsong || IsBardSong(casting_spell_id))
_StopSong();
if(bard_song_mode) {
return;
}
if(!message)
message = IsBardSong(spellid) ? SONG_ENDS_ABRUPTLY : INTERRUPT_SPELL;
// clients need some packets
if (IsClient() && message != SONG_ENDS)
{
// the interrupt message
outapp = new EQApplicationPacket(OP_InterruptCast, sizeof(InterruptCast_Struct));
InterruptCast_Struct* ic = (InterruptCast_Struct*) outapp->pBuffer;
ic->messageid = message;
ic->spawnid = GetID();
outapp->priority = 5;
CastToClient()->QueuePacket(outapp);
safe_delete(outapp);
SendSpellBarEnable(spellid);
}
// notify people in the area
// first figure out what message others should get
switch(message)
{
case SONG_ENDS:
message_other = SONG_ENDS_OTHER;
break;
case SONG_ENDS_ABRUPTLY:
message_other = SONG_ENDS_ABRUPTLY_OTHER;
break;
case MISS_NOTE:
message_other = MISSED_NOTE_OTHER;
break;
case SPELL_FIZZLE:
message_other = SPELL_FIZZLE_OTHER;
break;
default:
message_other = INTERRUPT_SPELL_OTHER;
}
// this is the actual message, it works the same as a formatted message
outapp = new EQApplicationPacket(OP_InterruptCast, sizeof(InterruptCast_Struct) + strlen(GetCleanName()) + 1);
InterruptCast_Struct* ic = (InterruptCast_Struct*) outapp->pBuffer;
ic->messageid = message_other;
ic->spawnid = GetID();
strcpy(ic->message, GetCleanName());
entity_list.QueueCloseClients(this, outapp, true, RuleI(Range, SongMessages), 0, true, IsClient() ? FilterPCSpells : FilterNPCSpells);
safe_delete(outapp);
}
// this is like interrupt, just it doesn't spam interrupt packets to everyone
// There are a few cases where this is what live does :P
void Mob::StopCasting()
{
if (casting_spell_id && IsNPC()) {
CastToNPC()->AI_Event_SpellCastFinished(false, static_cast<uint16>(casting_spell_slot));
}
if (IsClient()) {
auto c = CastToClient();
if (casting_spell_aa_id) { //Rest AA Timer on failed cast
c->MessageString(Chat::SpellFailure, ABILITY_FAILED);
c->ResetAlternateAdvancementTimer(casting_spell_aa_id);
}
auto outapp = new EQApplicationPacket(OP_ManaChange, sizeof(ManaChange_Struct));
auto mc = (ManaChange_Struct *)outapp->pBuffer;
mc->new_mana = GetMana();
mc->stamina = GetEndurance();
mc->spell_id = casting_spell_id;
mc->keepcasting = 0;
c->FastQueuePacket(&outapp);
}
ZeroCastingVars();
}
// this is called after the timer is up and the spell is finished
// casting. everything goes through here, including items with zero cast time
// only to be used from SpellProcess
// NOTE: do not put range checking, etc into this function. this should
// just check timed spell specific things before passing off to SpellFinished
// which figures out proper targets etc
void Mob::CastedSpellFinished(uint16 spell_id, uint32 target_id, CastingSlot slot,
uint16 mana_used, uint32 inventory_slot, int16 resist_adjust)
{
bool IsFromItem = false;
if(IsClient() && slot != CastingSlot::Item && slot != CastingSlot::PotionBelt && spells[spell_id].recast_time > 1000) { // 10 is item
if(!CastToClient()->GetPTimers().Expired(&database, pTimerSpellStart + spell_id, false)) {
//should we issue a message or send them a spell gem packet?
MessageString(Chat::Red, SPELL_RECAST);
LogSpells("Casting of [{}] canceled: spell reuse timer not expired", spell_id);
StopCasting();
return;
}
}
if(IsClient() && (slot == CastingSlot::Item || slot == CastingSlot::PotionBelt))
{
IsFromItem = true;
EQEmu::ItemInstance *itm = CastToClient()->GetInv().GetItem(inventory_slot);
if(itm && itm->GetItem()->RecastDelay > 0)
{
if(!CastToClient()->GetPTimers().Expired(&database, (pTimerItemStart + itm->GetItem()->RecastType), false)) {
MessageString(Chat::Red, SPELL_RECAST);
LogSpells("Casting of [{}] canceled: item spell reuse timer not expired", spell_id);
StopCasting();
return;
}
}
}
if(!IsValidSpell(spell_id))
{
LogSpells("Casting of [{}] canceled: invalid spell id", spell_id);
InterruptSpell();
return;
}
// prevent rapid recast - this can happen if somehow the spell gems
// become desynced and the player casts again.
if(IsClient())
{
if(delaytimer)
{
LogSpells("Casting of [{}] canceled: recast too quickly", spell_id);
Message(Chat::Red, "You are unable to focus.");
InterruptSpell();
return;
}
}
// make sure they aren't somehow casting 2 timed spells at once
if (casting_spell_id != spell_id)
{
LogSpells("Casting of [{}] canceled: already casting", spell_id);
MessageString(Chat::Red,ALREADY_CASTING);
InterruptSpell();
return;
}
bool bard_song_mode = false;
bool regain_conc = false;
Mob *spell_target = entity_list.GetMob(target_id);
// here we do different things if this is a bard casting a bard song from
// a spell bar slot
if(GetClass() == BARD) // bard's can move when casting any spell...
{
if (IsBardSong(spell_id)) {
if(spells[spell_id].buffduration == 0xFFFF) {
LogSpells("Bard song [{}] not applying bard logic because duration. dur=[{}], recast=[{}]", spells[spell_id].buffduration);
} else {
// So long recast bard songs need special bard logic, although the effects don't repulse like other songs
// This is basically a hack to get that effect
// You can hold down the long recast spells, but you only get the effects once
// TODO fuck bards.
if (spells[spell_id].recast_time == 0) {
bardsong = spell_id;
bardsong_slot = slot;
//NOTE: theres a lot more target types than this to think about...
if (spell_target == nullptr || (spells[spell_id].targettype != ST_Target && spells[spell_id].targettype != ST_AETarget))
bardsong_target_id = GetID();
else
bardsong_target_id = spell_target->GetID();
bardsong_timer.Start(6000);
}
LogSpells("Bard song [{}] started: slot [{}], target id [{}]", bardsong, (int) bardsong_slot, bardsong_target_id);
bard_song_mode = true;
}
}
}
else // not bard, check movement
{
// if has been attacked, or moved while casting
// check for regain concentration
if
(
attacked_count > 0 ||
GetX() != GetSpellX() ||
GetY() != GetSpellY()
)
{
// modify the chance based on how many times they were hit
// but cap it so it's not that large a factor
if(attacked_count > 15) attacked_count = 15;
float channelchance, distance_moved, d_x, d_y, distancemod;
if(IsClient())
{
float channelbonuses = 0.0f;
//AA that effect Spell channel chance are no longer on live. http://everquest.allakhazam.com/history/patches-2006-2.html
//No harm in maintaining the effects regardless, since we do check for channel chance.
if (IsFromItem)
channelbonuses += spellbonuses.ChannelChanceItems + itembonuses.ChannelChanceItems + aabonuses.ChannelChanceItems;
else
channelbonuses += spellbonuses.ChannelChanceSpells + itembonuses.ChannelChanceSpells + aabonuses.ChannelChanceSpells;
// max 93% chance at 252 skill
channelchance = 30 + GetSkill(EQEmu::skills::SkillChanneling) / 400.0f * 100;
channelchance -= attacked_count * 2;
channelchance += channelchance * channelbonuses / 100.0f;
}
#ifdef BOTS
else if(IsBot()) {
float channelbonuses = 0.0f;
if (IsFromItem)
channelbonuses += spellbonuses.ChannelChanceItems + itembonuses.ChannelChanceItems + aabonuses.ChannelChanceItems;
else
channelbonuses += spellbonuses.ChannelChanceSpells + itembonuses.ChannelChanceSpells + aabonuses.ChannelChanceSpells;
// max 93% chance at 252 skill
channelchance = 30 + GetSkill(EQEmu::skills::SkillChanneling) / 400.0f * 100;
channelchance -= attacked_count * 2;
channelchance += channelchance * channelbonuses / 100.0f;
}
#endif //BOTS
else {
// NPCs are just hard to interrupt, otherwise they get pwned
channelchance = 85;
channelchance -= attacked_count;
}
// as you get farther from your casting location,
// it gets squarely harder to regain concentration
if(GetX() != GetSpellX() || GetY() != GetSpellY())
{
d_x = std::abs(std::abs(GetX()) - std::abs(GetSpellX()));
d_y = std::abs(std::abs(GetY()) - std::abs(GetSpellY()));
if(d_x < 5 && d_y < 5)
{
//avoid the square root...
distance_moved = d_x * d_x + d_y * d_y;
// if you moved 1 unit, that's 25% off your chance to regain.
// if you moved 2, you lose 100% off your chance
distancemod = distance_moved * 25;
channelchance -= distancemod;
}
else
{
channelchance = 0;
}
}
LogSpells("Checking Interruption: spell x: [{}] spell y: [{}] cur x: [{}] cur y: [{}] channelchance [{}] channeling skill [{}]\n", GetSpellX(), GetSpellY(), GetX(), GetY(), channelchance, GetSkill(EQEmu::skills::SkillChanneling));
if(!spells[spell_id].uninterruptable && zone->random.Real(0, 100) > channelchance) {
LogSpells("Casting of [{}] canceled: interrupted", spell_id);
InterruptSpell();
return;
}
// if we got here, we regained concentration
regain_conc = true;
MessageString(Chat::Spells, REGAIN_AND_CONTINUE);
entity_list.MessageCloseString(
this,
true,
RuleI(Range, SpellMessages),
Chat::Spells,
OTHER_REGAIN_CAST,
this->GetCleanName());
}
}
// Check for consumables and Reagent focus items
// first check for component reduction
if(IsClient()) {
int reg_focus = CastToClient()->GetFocusEffect(focusReagentCost,spell_id);//Client only
if(zone->random.Roll(reg_focus)) {
LogSpells("Spell [{}]: Reagent focus item prevented reagent consumption ([{}] chance)", spell_id, reg_focus);
} else {
if(reg_focus > 0)
LogSpells("Spell [{}]: Reagent focus item failed to prevent reagent consumption ([{}] chance)", spell_id, reg_focus);
Client *c = this->CastToClient();
int component, component_count, inv_slot_id;
bool missingreags = false;
for(int t_count = 0; t_count < 4; t_count++) {
component = spells[spell_id].components[t_count];
component_count = spells[spell_id].component_counts[t_count];
if (component == -1)
continue;
// bard components are requirements for a certain instrument type, not a specific item
if(bard_song_mode) {
bool HasInstrument = true;
int InstComponent = spells[spell_id].NoexpendReagent[0];
switch (InstComponent) {
case -1:
continue; // no instrument required, go to next component
// percussion songs (13000 = hand drum)
case 13000:
if(itembonuses.percussionMod == 0) { // check for the appropriate instrument type
HasInstrument = false;
c->MessageString(Chat::Red, SONG_NEEDS_DRUM); // send an error message if missing
}
break;
// wind songs (13001 = wooden flute)
case 13001:
if(itembonuses.windMod == 0) {
HasInstrument = false;
c->MessageString(Chat::Red, SONG_NEEDS_WIND);
}
break;
// string songs (13011 = lute)
case 13011:
if(itembonuses.stringedMod == 0) {
HasInstrument = false;
c->MessageString(Chat::Red, SONG_NEEDS_STRINGS);
}
break;
// brass songs (13012 = horn)
case 13012:
if(itembonuses.brassMod == 0) {
HasInstrument = false;
c->MessageString(Chat::Red, SONG_NEEDS_BRASS);
}
break;
default: // some non-instrument component. Let it go, but record it in the log
LogSpells("Something odd happened: Song [{}] required component [{}]", spell_id, component);
}
if(!HasInstrument) { // if the instrument is missing, log it and interrupt the song
LogSpells("Song [{}]: Canceled. Missing required instrument [{}]", spell_id, component);
if(c->GetGM())
c->Message(Chat::White, "Your GM status allows you to finish casting even though you're missing a required instrument.");
else {
InterruptSpell();
return;
}
}
} // end bard component section
// handle the components for traditional casters
else {
if (!RuleB(Character, PetsUseReagents) && IsEffectInSpell(spell_id, SE_SummonPet)) {
//bypass reagent cost
}
else if(c->GetInv().HasItem(component, component_count, invWhereWorn|invWherePersonal) == -1) // item not found
{
if (!missingreags)
{
c->MessageString(Chat::Red, MISSING_SPELL_COMP);
missingreags=true;
}
const EQEmu::ItemData *item = database.GetItem(component);
if(item) {
c->MessageString(Chat::Red, MISSING_SPELL_COMP_ITEM, item->Name);
LogSpells("Spell [{}]: Canceled. Missing required reagent [{}] ([{}])", spell_id, item->Name, component);
}
else {
char TempItemName[64];
strcpy((char*)&TempItemName, "UNKNOWN");
LogSpells("Spell [{}]: Canceled. Missing required reagent [{}] ([{}])", spell_id, TempItemName, component);
}
}
} // end bard/not bard ifs
} // end reagent loop
if (missingreags) {
if(c->GetGM())
c->Message(Chat::White, "Your GM status allows you to finish casting even though you're missing required components.");
else {
InterruptSpell();
return;
}
}
else if (!RuleB(Character, PetsUseReagents) && IsEffectInSpell(spell_id, SE_SummonPet)) {
//bypass reagent cost
}
else if (!bard_song_mode)
{
int noexpend;
for(int t_count = 0; t_count < 4; t_count++) {
component = spells[spell_id].components[t_count];
noexpend = spells[spell_id].NoexpendReagent[t_count];
if (component == -1 || noexpend == component)
continue;
component_count = spells[spell_id].component_counts[t_count];
LogSpells("Spell [{}]: Consuming [{}] of spell component item id [{}]", spell_id, component_count, component);
// Components found, Deleting
// now we go looking for and deleting the items one by one
for(int s = 0; s < component_count; s++)
{
inv_slot_id = c->GetInv().HasItem(component, 1, invWhereWorn|invWherePersonal);
if(inv_slot_id != -1)
{
c->DeleteItemInInventory(inv_slot_id, 1, true);
}
else
{ // some kind of error in the code if this happens
c->Message(Chat::Red, "ERROR: reagent item disappeared while processing?");
}
}
}
} // end missingreags/consumption
} // end `focus did not help us`
} // end IsClient() for reagents
// this is common to both bard and non bard
// if this was cast from an inventory slot, check out the item that's there
int16 DeleteChargeFromSlot = -1;
if(IsClient() && (slot == CastingSlot::Item || slot == CastingSlot::PotionBelt)
&& inventory_slot != 0xFFFFFFFF) // 10 is an item
{
bool fromaug = false;
const EQEmu::ItemInstance* inst = CastToClient()->GetInv()[inventory_slot];
EQEmu::ItemData* augitem = nullptr;
uint32 recastdelay = 0;
uint32 recasttype = 0;
while (true) {
if (inst == nullptr)
break;
for (int r = EQEmu::invaug::SOCKET_BEGIN; r <= EQEmu::invaug::SOCKET_END; r++) {
const EQEmu::ItemInstance* aug_i = inst->GetAugment(r);
if (!aug_i)
continue;
const EQEmu::ItemData* aug = aug_i->GetItem();
if (!aug)
continue;
if (aug->Click.Effect == spell_id)
{
recastdelay = aug_i->GetItem()->RecastDelay;
recasttype = aug_i->GetItem()->RecastType;
fromaug = true;
break;
}
}
break;
}
//Test the aug recast delay
if(IsClient() && fromaug && recastdelay > 0)
{
if(!CastToClient()->GetPTimers().Expired(&database, (pTimerItemStart + recasttype), false)) {
MessageString(Chat::Red, SPELL_RECAST);
LogSpells("Casting of [{}] canceled: item spell reuse timer not expired", spell_id);
StopCasting();
return;
}
else
{
//Can we start the timer here? I don't see why not.
CastToClient()->GetPTimers().Start((pTimerItemStart + recasttype), recastdelay);
database.UpdateItemRecastTimestamps(CastToClient()->CharacterID(), recasttype,
CastToClient()->GetPTimers().Get(pTimerItemStart + recasttype)->GetReadyTimestamp());
}
}
if (inst && inst->IsClassCommon() && (inst->GetItem()->Click.Effect == spell_id) && inst->GetCharges() || fromaug)
{
//const ItemData* item = inst->GetItem();
int16 charges = inst->GetItem()->MaxCharges;
if(fromaug) { charges = -1; } //Don't destroy the parent item
if(charges > -1) { // charged item, expend a charge
LogSpells("Spell [{}]: Consuming a charge from item [{}] ([{}]) which had [{}]/[{}] charges", spell_id, inst->GetItem()->Name, inst->GetItem()->ID, inst->GetCharges(), inst->GetItem()->MaxCharges);
DeleteChargeFromSlot = inventory_slot;
} else {
LogSpells("Spell [{}]: Cast from unlimited charge item [{}] ([{}]) ([{}] charges)", spell_id, inst->GetItem()->Name, inst->GetItem()->ID, inst->GetItem()->MaxCharges);
}
}
else
{
LogSpells("Item used to cast spell [{}] was missing from inventory slot [{}] after casting!", spell_id, inventory_slot);
Message(Chat::Red, "Casting Error: Active casting item not found in inventory slot %i", inventory_slot);
InterruptSpell();
return;
}
}
// we're done casting, now try to apply the spell
if( !SpellFinished(spell_id, spell_target, slot, mana_used, inventory_slot, resist_adjust) )
{
LogSpells("Casting of [{}] canceled: SpellFinished returned false", spell_id);
// most of the cases we return false have a message already or are logic errors that shouldn't happen
// if there are issues I guess we can do something else, but this should work
StopCasting();
return;
}
if(IsClient()) {
CheckNumHitsRemaining(NumHit::MatchingSpells);
TrySympatheticProc(target, spell_id);
}
TryTwincast(this, target, spell_id);
TryTriggerOnCast(spell_id, 0);
if(DeleteChargeFromSlot >= 0)
CastToClient()->DeleteItemInInventory(DeleteChargeFromSlot, 1, true);
//
// at this point the spell has successfully been cast
//
if(IsClient()) {
char temp[64];
sprintf(temp, "%d", spell_id);
parse->EventPlayer(EVENT_CAST, CastToClient(), temp, 0);
} else if(IsNPC()) {
char temp[64];
sprintf(temp, "%d", spell_id);
parse->EventNPC(EVENT_CAST, CastToNPC(), nullptr, temp, 0);
}
if(bard_song_mode)
{
if(IsClient())
{
Client *c = CastToClient();
c->CheckSongSkillIncrease(spell_id);
if (spells[spell_id].EndurTimerIndex > 0 && slot < CastingSlot::MaxGems)
c->SetLinkedSpellReuseTimer(spells[spell_id].EndurTimerIndex, spells[spell_id].recast_time / 1000);
c->MemorizeSpell(static_cast<uint32>(slot), spell_id, memSpellSpellbar);
}
LogSpells("Bard song [{}] should be started", spell_id);
}
else
{
if(IsClient())
{
Client *c = CastToClient();
SendSpellBarEnable(spell_id);
// this causes the delayed refresh of the spell bar gems
if (spells[spell_id].EndurTimerIndex > 0 && slot < CastingSlot::MaxGems)
c->SetLinkedSpellReuseTimer(spells[spell_id].EndurTimerIndex, spells[spell_id].recast_time / 1000);
c->MemorizeSpell(static_cast<uint32>(slot), spell_id, memSpellSpellbar);
// this tells the client that casting may happen again
SetMana(GetMana());
// skills
if (EQEmu::skills::IsCastingSkill(spells[spell_id].skill)) {
c->CheckIncreaseSkill(spells[spell_id].skill, nullptr);
// increased chance of gaining channel skill if you regained concentration
c->CheckIncreaseSkill(EQEmu::skills::SkillChanneling, nullptr, regain_conc ? 5 : 0);
c->CheckSpecializeIncrease(spell_id);
}
}
}
// there should be no casting going on now
ZeroCastingVars();
// set the rapid recast timer for next time around
// Why do we have this? It mostly just causes issues when things are working correctly
// It also needs to be <users's ping to not cause issues
delaytimer = true;
spellend_timer.Start(10, true);
LogSpells("Spell casting of [{}] is finished", spell_id);
}
bool Mob::DetermineSpellTargets(uint16 spell_id, Mob *&spell_target, Mob *&ae_center, CastAction_type &CastAction, CastingSlot slot, bool isproc)
{
/*
The basic types of spells:
Single target - some might be undead only, self only, etc, but these
all affect the target of the caster.
AE around caster - these affect entities close to the caster, and have
no target.
AE around target - these have a target, and affect the target as well as
entities close to the target.
AE on location - this is a tricky one that is cast on a mob target but
has a special AE duration that keeps it recasting every 2.5 sec on the
same location. These work the same as AE around target spells, except
the target is a special beacon that's created when the spell is cast
Group - the caster is always affected, but there's more
targetgroupbuffs on - these affect the target and the target's group.
targetgroupbuffs off - no target, affects the caster's group.
Group Teleport - the caster plus his group are affected. these cannot
be targeted.
I think the string ID SPELL_NEED_TAR is wrong, it dosent seem to show up.
*/
// during this switch, this variable gets set to one of these things
// and that causes the spell to be executed differently
bodyType target_bt = BT_Humanoid;
SpellTargetType targetType = spells[spell_id].targettype;
bodyType mob_body = spell_target ? spell_target->GetBodyType() : BT_Humanoid;
if(IsPlayerIllusionSpell(spell_id)
&& spell_target != nullptr // null ptr crash safeguard
&& !spell_target->IsNPC() // still self only if NPC targetted
&& IsClient()
&& (IsGrouped() // still self only if not grouped
|| IsRaidGrouped())
&& (HasProjectIllusion())){
LogAA("Project Illusion overwrote target caster: [{}] spell id: [{}] was ON", GetName(), spell_id);
targetType = ST_GroupClientAndPet;
}
// NPC innate procs override the target type to single target.
// Yes. This code will cause issues if they have the proc as innate AND on a weapon. Oh well.
if (isproc && IsNPC() && CastToNPC()->GetInnateProcSpellID() == spell_id)
targetType = ST_Target;
if (spell_target && !spell_target->PassCastRestriction(true, spells[spell_id].CastRestriction)){
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
//Must be out of combat. (If Beneficial checks casters combat state, Deterimental checks targets)
if (!spells[spell_id].InCombat && spells[spell_id].OutofCombat) {
if (IsDetrimentalSpell(spell_id)) {
if (spell_target &&
((spell_target->IsNPC() && spell_target->IsEngaged()) ||
(spell_target->IsClient() && spell_target->CastToClient()->GetAggroCount()))) {
MessageString(Chat::Red, SPELL_NO_EFFECT); // Unsure correct string
return false;
}
}
else if (IsBeneficialSpell(spell_id)) {
if ((IsNPC() && IsEngaged()) || (IsClient() && CastToClient()->GetAggroCount())) {
if (IsDiscipline(spell_id))
MessageString(Chat::Red, NO_ABILITY_IN_COMBAT);
else
MessageString(Chat::Red, NO_CAST_IN_COMBAT);
return false;
}
}
}
// Must be in combat. (If Beneficial checks casters combat state, Deterimental checks targets)
else if (spells[spell_id].InCombat && !spells[spell_id].OutofCombat) {
if (IsDetrimentalSpell(spell_id)) {
if (spell_target &&
((spell_target->IsNPC() && !spell_target->IsEngaged()) ||
(spell_target->IsClient() && !spell_target->CastToClient()->GetAggroCount()))) {
MessageString(Chat::Red, SPELL_NO_EFFECT); // Unsure correct string
return false;
}
}
else if (IsBeneficialSpell(spell_id)) {
if ((IsNPC() && !IsEngaged()) || (IsClient() && !CastToClient()->GetAggroCount())) {
if (IsDiscipline(spell_id))
MessageString(Chat::Red, NO_ABILITY_OUT_OF_COMBAT);
else
MessageString(Chat::Red, NO_CAST_OUT_OF_COMBAT);
return false;
}
}
}
switch (targetType)
{
// single target spells
case ST_Self:
{
spell_target = this;
CastAction = SingleTarget;
break;
}
case ST_TargetOptional:
{
if(!spell_target)
spell_target = this;
CastAction = SingleTarget;
break;
}
// target required for these
case ST_Undead: {
if(!spell_target || (
mob_body != BT_SummonedUndead
&& mob_body != BT_Undead
&& mob_body != BT_Vampire
)
)
{
//invalid target
LogSpells("Spell [{}] canceled: invalid target of body type [{}] (undead)", spell_id, mob_body);
if(!spell_target)
MessageString(Chat::Red,SPELL_NEED_TAR);
else
MessageString(Chat::Red,CANNOT_AFFECT_NPC);
return false;
}
CastAction = SingleTarget;
break;
}
case ST_Summoned: {
if(!spell_target || (mob_body != BT_Summoned && mob_body != BT_Summoned2 && mob_body != BT_Summoned3))
{
//invalid target
LogSpells("Spell [{}] canceled: invalid target of body type [{}] (summoned)", spell_id, mob_body);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
CastAction = SingleTarget;
break;
}
case ST_SummonedPet:
{
if(!spell_target || (spell_target != GetPet()) ||
(mob_body != BT_Summoned && mob_body != BT_Summoned2 && mob_body != BT_Summoned3 && mob_body != BT_Animal))
{
LogSpells("Spell [{}] canceled: invalid target of body type [{}] (summoned pet)",
spell_id, mob_body);
MessageString(Chat::Red, SPELL_NEED_TAR);
return false;
}
CastAction = SingleTarget;
break;
}
//single body type target spells...
//this is a little hackish, but better than duplicating code IMO
case ST_Plant: if(target_bt == BT_Humanoid) target_bt = BT_Plant;
case ST_Dragon: if(target_bt == BT_Humanoid) target_bt = BT_Dragon;
case ST_Giant: if(target_bt == BT_Humanoid) target_bt = BT_Giant;
case ST_Animal: if(target_bt == BT_Humanoid) target_bt = BT_Animal;
// check for special case body types (Velious dragons/giants)
if(mob_body == BT_RaidGiant) mob_body = BT_Giant;
if(mob_body == BT_VeliousDragon) mob_body = BT_Dragon;
{
if(!spell_target || mob_body != target_bt)
{
//invalid target
LogSpells("Spell [{}] canceled: invalid target of body type [{}] (want body Type [{}])", spell_id, mob_body, target_bt);
if(!spell_target)
MessageString(Chat::Red,SPELL_NEED_TAR);
else
MessageString(Chat::Red,CANNOT_AFFECT_NPC);
return false;
}
CastAction = SingleTarget;
break;
}
case ST_Tap:
case ST_LDoNChest_Cursed:
case ST_Target: {
if(IsLDoNObjectSpell(spell_id))
{
if(!spell_target)
{
LogSpells("Spell [{}] canceled: invalid target (ldon object)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
else
{
if(!spell_target->IsNPC())
{
LogSpells("Spell [{}] canceled: invalid target (normal)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
if(spell_target->GetClass() != LDON_TREASURE)
{
LogSpells("Spell [{}] canceled: invalid target (normal)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
}
}
if(!spell_target)
{
LogSpells("Spell [{}] canceled: invalid target (normal)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false; // can't cast these unless we have a target
}
CastAction = SingleTarget;
break;
}
case ST_Corpse:
{
if(!spell_target || !spell_target->IsPlayerCorpse())
{
LogSpells("Spell [{}] canceled: invalid target (corpse)", spell_id);
uint32 message = ONLY_ON_CORPSES;
if(!spell_target) message = SPELL_NEED_TAR;
else if(!spell_target->IsCorpse()) message = ONLY_ON_CORPSES;
else if(!spell_target->IsPlayerCorpse()) message = CORPSE_NOT_VALID;
MessageString(Chat::Red, message);
return false;
}
CastAction = SingleTarget;
break;
}
case ST_Pet:
{
spell_target = GetPet();
if(!spell_target)
{
LogSpells("Spell [{}] canceled: invalid target (no pet)", spell_id);
MessageString(Chat::Red,NO_PET);
return false; // can't cast these unless we have a target
}
CastAction = SingleTarget;
break;
}
case ST_AEBard:
case ST_AECaster:
case ST_AEClientV1:
{
spell_target = nullptr;
ae_center = this;
CastAction = AECaster;
break;
}
case ST_HateList:
{
spell_target = nullptr;
ae_center = this;
CastAction = CAHateList;
break;
}
case ST_AETargetHateList:
{
if (spells[spell_id].range > 0)
{
if(!spell_target)
return false;
ae_center = spell_target;
CastAction = AETarget;
}
else {
spell_target = nullptr;
ae_center = this;
CastAction = CAHateList;
}
break;
}
case ST_AreaClientOnly:
case ST_AreaNPCOnly:
{
if (spells[spell_id].range > 0)
{
if(!spell_target)
return false;
ae_center = spell_target;
CastAction = AETarget;
}
else {
spell_target = nullptr;
ae_center = this;
CastAction = AECaster;
}
break;
}
case ST_UndeadAE: //should only affect undead...
case ST_SummonedAE:
case ST_TargetAETap:
case ST_AETarget:
case ST_TargetAENoPlayersPets:
{
if(!spell_target)
{
LogSpells("Spell [{}] canceled: invalid target (AOE)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
ae_center = spell_target;
CastAction = AETarget;
break;
}
// Group spells
case ST_GroupTeleport:
case ST_Group:
case ST_GroupNoPets:
{
if(IsClient() && CastToClient()->TGB() && IsTGBCompatibleSpell(spell_id) && (slot != CastingSlot::Item || RuleB(Spells, AllowItemTGB))) {
if( (!target) ||
(target->IsNPC() && !(target->GetOwner() && target->GetOwner()->IsClient())) ||
(target->IsCorpse()) )
spell_target = this;
else
spell_target = target;
} else {
spell_target = this;
}
if (spell_target && spell_target->IsPet() && spells[spell_id].targettype == ST_GroupNoPets){
MessageString(Chat::Red,NO_CAST_ON_PET);
return false;
}
CastAction = GroupSpell;
break;
}
case ST_GroupClientAndPet:
{
if(!spell_target)
{
LogSpells("Spell [{}] canceled: invalid target (Group Required: Single Target)", spell_id);
MessageString(Chat::Red,SPELL_NEED_TAR);
return false;
}
if(spell_target != this)
{
if(spell_target == GetPet())
{
CastAction = SingleTarget;
}
else if(spell_target == GetOwner())
{
CastAction = SingleTarget;
}
else
{
uint32 group_id_caster = 0;
uint32 group_id_target = 0;
if(IsClient())
{
if(IsGrouped())
{
if (Group* group = GetGroup()) {
group_id_caster = group->GetID();
}
}
else if(IsRaidGrouped())
{
if (Raid* raid = GetRaid()) {
uint32 group_id = raid->GetGroup(CastToClient());
group_id_caster = (group_id == 0xFFFFFFFF) ? 0 : (group_id + 1);
}
}
}
else if(IsPet())
{
Mob *owner = GetOwner();
if(owner->IsGrouped())
{
if (Group* group = owner->GetGroup()) {
group_id_caster = group->GetID();
}
}
else if(owner->IsRaidGrouped())
{
if (Raid* raid = owner->GetRaid()) {
uint32 group_id = raid->GetGroup(owner->CastToClient());
group_id_caster = (group_id == 0xFFFFFFFF) ? 0 : (group_id + 1);
}
}
}
#ifdef BOTS
else if(IsBot())
{
if(IsGrouped())
{
group_id_caster = GetGroup()->GetID();
}
else if(IsRaidGrouped())
{
if(GetOwner())
group_id_caster = (GetRaid()->GetGroup(GetOwner()->CastToClient()) == 0xFFFF) ? 0 : (GetRaid()->GetGroup(GetOwner()->CastToClient()) + 1);
}
}
#endif //BOTS
if(spell_target->IsClient())
{
if(spell_target->IsGrouped())
{
if (Group* group = spell_target->GetGroup()) {
group_id_target = group->GetID();
}
}
else if(spell_target->IsRaidGrouped())
{
if (Raid* raid = spell_target->GetRaid()) {
uint32 group_id = raid->GetGroup(spell_target->CastToClient());
group_id_target = (group_id == 0xFFFFFFFF) ? 0 : (group_id + 1);
}
}
}
else if(spell_target->IsPet())
{
Mob *owner = spell_target->GetOwner();
if(owner->IsGrouped())
{
if (Group* group = owner->GetGroup()) {
group_id_target = group->GetID();
}
}
else if(owner->IsRaidGrouped())
{
if (Raid* raid = owner->GetRaid()) {
uint32 group_id = raid->GetGroup(owner->CastToClient());
group_id_target = (group_id == 0xFFFFFFFF) ? 0 : (group_id + 1);
}
}
}
#ifdef BOTS
else if(spell_target->IsBot())
{
if(spell_target->IsGrouped())
{
group_id_target = spell_target->GetGroup()->GetID();
}
else if(spell_target->IsRaidGrouped())
{
if(spell_target->GetOwner())
group_id_target = (spell_target->GetRaid()->GetGroup(spell_target->GetOwner()->CastToClient()) == 0xFFFF) ? 0 : (spell_target->GetRaid()->GetGroup(spell_target->GetOwner()->CastToClient()) + 1);
}
}
#endif //BOTS
if(group_id_caster == 0 || group_id_target == 0)
{
LogSpells("Spell [{}] canceled: Attempted to cast a Single Target Group spell on a ungrouped member", spell_id);
MessageString(Chat::Red, TARGET_GROUP_MEMBER);
return false;
}
if(group_id_caster != group_id_target)
{
LogSpells("Spell [{}] canceled: Attempted to cast a Single Target Group spell on a ungrouped member", spell_id);
MessageString(Chat::Red, TARGET_GROUP_MEMBER);
return false;
}
CastAction = SingleTarget;
}
}
else
{
CastAction = SingleTarget;
}
break;
}
case ST_Directional:
CastAction = DirectionalAE;
spell_target = nullptr;
ae_center = nullptr;
break;
case ST_TargetsTarget:
{
Mob *spell_target_tot = spell_target ? spell_target->GetTarget() : nullptr;
if(!spell_target_tot)
return false;
//Verfied from live - Target's Target needs to be in combat range to recieve the effect
if (!this->CombatRange(spell_target))
return false;
spell_target = spell_target_tot;
CastAction = SingleTarget;
break;
}
case ST_PetMaster:
{
Mob *owner = nullptr;
if (IsPet())
owner = GetOwner();
else if ((IsNPC() && CastToNPC()->GetSwarmOwner()))
owner = entity_list.GetMobID(CastToNPC()->GetSwarmOwner());
if (!owner)
return false;
spell_target = owner;
CastAction = SingleTarget;
break;
}
case ST_Beam:
{
CastAction = Beam;
spell_target = nullptr;
ae_center = nullptr;
break;
}
case ST_Ring:
{
CastAction = TargetRing;
spell_target = nullptr;
ae_center = nullptr;
break;
}
default:
{
LogSpells("I dont know Target Type: [{}] Spell: ([{}]) [{}]", spells[spell_id].targettype, spell_id, spells[spell_id].name);
Message(0, "I dont know Target Type: %d Spell: (%d) %s", spells[spell_id].targettype, spell_id, spells[spell_id].name);
CastAction = CastActUnknown;
break;
}
}
return(true);
}
// only used from CastedSpellFinished, and procs
// we can't interrupt in this, or anything called from this!
// if you need to abort the casting, return false
bool Mob::SpellFinished(uint16 spell_id, Mob *spell_target, CastingSlot slot, uint16 mana_used,
uint32 inventory_slot, int16 resist_adjust, bool isproc, int level_override)
{
//EQApplicationPacket *outapp = nullptr;
Mob *ae_center = nullptr;
if(!IsValidSpell(spell_id))
return false;
if( spells[spell_id].zonetype == 1 && !zone->CanCastOutdoor()){
if(IsClient()){
if(!CastToClient()->GetGM()){
MessageString(Chat::Red, CAST_OUTDOORS);
return false;
}
}
}
if(IsEffectInSpell(spell_id, SE_Levitate) && !zone->CanLevitate()){
if(IsClient()){
if(!CastToClient()->GetGM()){
Message(Chat::Red, "You can't levitate in this zone.");
return false;
}
}
}
if(IsClient() && !CastToClient()->GetGM()){
if(zone->IsSpellBlocked(spell_id, glm::vec3(GetPosition()))){
const char *msg = zone->GetSpellBlockedMessage(spell_id, glm::vec3(GetPosition()));
if(msg){
Message(Chat::Red, msg);
return false;
}
else{
Message(Chat::Red, "You can't cast this spell here.");
return false;
}
}
}
if (IsClient() && CastToClient()->GetGM()){
if (zone->IsSpellBlocked(spell_id, glm::vec3(GetPosition()))){
LogSpells("GM Cast Blocked Spell: [{}] (ID [{}])", GetSpellName(spell_id), spell_id);
}
}
if
(
this->IsClient() &&
(zone->GetZoneID() == 183 || zone->GetZoneID() == 184) && // load
CastToClient()->Admin() < 80
)
{
if
(
IsEffectInSpell(spell_id, SE_Gate) ||
IsEffectInSpell(spell_id, SE_Translocate) ||
IsEffectInSpell(spell_id, SE_Teleport)
)
{
Message(0, "The Gods brought you here, only they can send you away.");
return false;
}
}
//determine the type of spell target we have
CastAction_type CastAction;
if(!DetermineSpellTargets(spell_id, spell_target, ae_center, CastAction, slot, isproc))
return(false);
LogSpells("Spell [{}]: target type [{}], target [{}], AE center [{}]", spell_id, CastAction, spell_target?spell_target->GetName():"NONE", ae_center?ae_center->GetName():"NONE");
// if a spell has the AEDuration flag, it becomes an AE on target
// spell that's recast every 2500 msec for AEDuration msec. There are
// spells of all kinds of target types that do this, strangely enough
// TODO: finish this
if(IsAEDurationSpell(spell_id)) {
// the spells are AE target, but we aim them on a beacon
Mob *beacon_loc = spell_target ? spell_target : this;
auto beacon = new Beacon(beacon_loc, spells[spell_id].AEDuration);
entity_list.AddBeacon(beacon);
LogSpells("Spell [{}]: AE duration beacon created, entity id [{}]", spell_id, beacon->GetName());
spell_target = nullptr;
ae_center = beacon;
CastAction = AECaster;
}
// check line of sight to target if it's a detrimental spell
if(!spells[spell_id].npc_no_los && spell_target && IsDetrimentalSpell(spell_id) && !CheckLosFN(spell_target) && !IsHarmonySpell(spell_id) && spells[spell_id].targettype != ST_TargetOptional)
{
LogSpells("Spell [{}]: cannot see target [{}]", spell_id, spell_target->GetName());
MessageString(Chat::Red,CANT_SEE_TARGET);
return false;
}
// check to see if target is a caster mob before performing a mana tap
if(spell_target && IsManaTapSpell(spell_id)) {
if(spell_target->GetCasterClass() == 'N') {
MessageString(Chat::Red, TARGET_NO_MANA);
return false;
}
}
//range check our target, if we have one and it is not us
float range = spells[spell_id].range + GetRangeDistTargetSizeMod(spell_target);
if(IsClient() && CastToClient()->TGB() && IsTGBCompatibleSpell(spell_id) && IsGroupSpell(spell_id))
range = spells[spell_id].aoerange;
range = GetActSpellRange(spell_id, range);
if(IsPlayerIllusionSpell(spell_id)
&& IsClient()
&& (HasProjectIllusion())){
range = 100;
}
if(spell_target != nullptr && spell_target != this) {
//casting a spell on somebody but ourself, make sure they are in range
float dist2 = DistanceSquared(m_Position, spell_target->GetPosition());
float range2 = range * range;
float min_range2 = spells[spell_id].min_range * spells[spell_id].min_range;
if(dist2 > range2) {
//target is out of range.
LogSpells("Spell [{}]: Spell target is out of range (squared: [{}] > [{}])", spell_id, dist2, range2);
MessageString(Chat::Red, TARGET_OUT_OF_RANGE);
return(false);
}
else if (dist2 < min_range2){
//target is too close range.
LogSpells("Spell [{}]: Spell target is too close (squared: [{}] < [{}])", spell_id, dist2, min_range2);
MessageString(Chat::Red, TARGET_TOO_CLOSE);
return(false);
}
spell_target->CalcSpellPowerDistanceMod(spell_id, dist2);
}
//AE Duration spells were ignoring distance check from item clickies
if(ae_center != nullptr && ae_center != this) {
//casting a spell on somebody but ourself, make sure they are in range
float dist2 = DistanceSquared(m_Position, ae_center->GetPosition());
float range2 = range * range;
float min_range2 = spells[spell_id].min_range * spells[spell_id].min_range;
if(dist2 > range2) {
//target is out of range.
LogSpells("Spell [{}]: Spell target is out of range (squared: [{}] > [{}])", spell_id, dist2, range2);
MessageString(Chat::Red, TARGET_OUT_OF_RANGE);
return(false);
}
else if (dist2 < min_range2){
//target is too close range.
LogSpells("Spell [{}]: Spell target is too close (squared: [{}] < [{}])", spell_id, dist2, min_range2);
MessageString(Chat::Red, TARGET_TOO_CLOSE);
return(false);
}
ae_center->CalcSpellPowerDistanceMod(spell_id, dist2);
}
//
// Switch #2 - execute the spell
//
switch(CastAction)
{
default:
case CastActUnknown:
case SingleTarget:
{
#ifdef BOTS
if(IsBot()) {
bool StopLogic = false;
if(!this->CastToBot()->DoFinishedSpellSingleTarget(spell_id, spell_target, slot, StopLogic))
return false;
if(StopLogic)
break;
}
#endif //BOTS
if(spell_target == nullptr) {
LogSpells("Spell [{}]: Targeted spell, but we have no target", spell_id);
return(false);
}
if (isproc) {
SpellOnTarget(spell_id, spell_target, false, true, resist_adjust, true, level_override);
} else {
if (spells[spell_id].targettype == ST_TargetOptional){
if (!TrySpellProjectile(spell_target, spell_id))
return false;
}
else if(!SpellOnTarget(spell_id, spell_target, false, true, resist_adjust, false, level_override)) {
if(IsBuffSpell(spell_id) && IsBeneficialSpell(spell_id)) {
// Prevent mana usage/timers being set for beneficial buffs
if(casting_spell_aa_id)
InterruptSpell();
return false;
}
}
}
if(IsPlayerIllusionSpell(spell_id)
&& IsClient()
&& (HasProjectIllusion())){
LogAA("Effect Project Illusion for [{}] on spell id: [{}] was ON", GetName(), spell_id);
SetProjectIllusion(false);
}
else{
LogAA("Effect Project Illusion for [{}] on spell id: [{}] was OFF", GetName(), spell_id);
}
break;
}
case AECaster:
case AETarget:
{
#ifdef BOTS
if(IsBot()) {
bool StopLogic = false;
if(!this->CastToBot()->DoFinishedSpellAETarget(spell_id, spell_target, slot, StopLogic))
return false;
if(StopLogic)
break;
}
#endif //BOTS
// we can't cast an AE spell without something to center it on
assert(ae_center != nullptr);
if(ae_center->IsBeacon()) {
// special ae duration spell
ae_center->CastToBeacon()->AELocationSpell(this, spell_id, resist_adjust);
} else {
// unsure if we actually need this? Need to find some spell examples
if(ae_center && ae_center == this && IsBeneficialSpell(spell_id))
SpellOnTarget(spell_id, this);
// NPCs should never be affected by an AE they cast. PB AEs shouldn't affect caster either
// I don't think any other cases that get here matter
bool affect_caster = !IsNPC() && spells[spell_id].targettype != ST_AECaster;
if (spells[spell_id].targettype == ST_AETargetHateList)
hate_list.SpellCast(this, spell_id, spells[spell_id].aoerange, ae_center);
else
entity_list.AESpell(this, ae_center, spell_id, affect_caster, resist_adjust);
}
break;
}
case GroupSpell:
{
#ifdef BOTS
if(IsBot()) {
bool StopLogic = false;
if(!this->CastToBot()->DoFinishedSpellGroupTarget(spell_id, spell_target, slot, StopLogic))
return false;
if(StopLogic)
break;
}
#endif //BOTS
// We hold off turning MBG off so we can still use it to calc the mana cost
if(spells[spell_id].can_mgb && HasMGB())
{
SpellOnTarget(spell_id, this);
entity_list.MassGroupBuff(this, this, spell_id, true);
}
else
{
// at this point spell_target is a member of the other group, or the
// caster if they're not using TGB
// NOTE: this will always hit the caster, plus the target's group so
// it can affect up to 7 people if the targeted group is not our own
// Allow pets who cast group spells to affect the group.
if (spell_target->IsPetOwnerClient() && IsPetOwnerClient()){
Mob* owner = spell_target->GetOwner();
if (owner)
spell_target = owner;
}
if(spell_target->IsGrouped())
{
Group *target_group = entity_list.GetGroupByMob(spell_target);
if(target_group)
{
target_group->CastGroupSpell(this, spell_id);
}
}
else if(spell_target->IsRaidGrouped() && spell_target->IsClient())
{
Raid *target_raid = entity_list.GetRaidByClient(spell_target->CastToClient());
uint32 gid = 0xFFFFFFFF;
if(target_raid){
gid = target_raid->GetGroup(spell_target->GetName());
if(gid < 12)
target_raid->CastGroupSpell(this, spell_id, gid);
else
SpellOnTarget(spell_id, spell_target);
}
}
else
{
// if target is grouped, CastGroupSpell will cast it on the caster
// too, but if not then we have to do that here.
if(spell_target != this){
SpellOnTarget(spell_id, this);
#ifdef GROUP_BUFF_PETS
//pet too
if (spells[spell_id].targettype != ST_GroupNoPets && GetPet() && HasPetAffinity() && !GetPet()->IsCharmed())
SpellOnTarget(spell_id, GetPet());
#endif
}
SpellOnTarget(spell_id, spell_target);
#ifdef GROUP_BUFF_PETS
//pet too
if (spells[spell_id].targettype != ST_GroupNoPets && spell_target->GetPet() && HasPetAffinity() && !spell_target->GetPet()->IsCharmed())
SpellOnTarget(spell_id, spell_target->GetPet());
#endif
}
}
break;
}
case CAHateList:
{
if(!IsClient())
{
hate_list.SpellCast(this, spell_id, spells[spell_id].range > spells[spell_id].aoerange ? spells[spell_id].range : spells[spell_id].aoerange);
}
break;
}
case DirectionalAE:
{
ConeDirectional(spell_id, resist_adjust);
break;
}
case Beam:
{
BeamDirectional(spell_id, resist_adjust);
break;
}
case TargetRing:
{
entity_list.AESpell(this, nullptr, spell_id, false, resist_adjust);
break;
}
}
DoAnim(spells[spell_id].CastingAnim, 0, true, IsClient() ? FilterPCSpells : FilterNPCSpells);
// Set and send the nimbus effect if this spell has one
int NimbusEffect = GetNimbusEffect(spell_id);
if(NimbusEffect) {
if(!IsNimbusEffectActive(NimbusEffect)) {
SendSpellEffect(NimbusEffect, 500, 0, 1, 3000, true);
}
}
bool mgb = HasMGB() && spells[spell_id].can_mgb;
// if this was a spell slot or an ability use up the mana for it
if(slot != CastingSlot::Item && slot != CastingSlot::PotionBelt && mana_used > 0)
{
mana_used = GetActSpellCost(spell_id, mana_used);
if (mgb) {
mana_used *= 2;
}
// clamp if we some how got focused above our current mana
if (GetMana() < mana_used)
mana_used = GetMana();
LogSpells("Spell [{}]: consuming [{}] mana", spell_id, mana_used);
if (!DoHPToManaCovert(mana_used)) {
SetMana(GetMana() - mana_used);
TryTriggerOnValueAmount(false, true);
}
}
// one may want to check if this is a disc or not, but we actually don't, there are non disc stuff that have end cost
// lets not consume end for custom items that have disc procs.
// One might also want to filter out USE_ITEM_SPELL_SLOT, but DISCIPLINE_SPELL_SLOT are both #defined to the same thing ...
if (spells[spell_id].EndurCost && !isproc) {
auto end_cost = spells[spell_id].EndurCost;
if (mgb)
end_cost *= 2;
SetEndurance(GetEndurance() - EQEmu::ClampUpper(end_cost, GetEndurance()));
TryTriggerOnValueAmount(false, false, true);
}
if (mgb)
SetMGB(false);
//set our reuse timer on long ass reuse_time spells...
if(IsClient() && !isproc)
{
if(casting_spell_aa_id) {
AA::Rank *rank = zone->GetAlternateAdvancementRank(casting_spell_aa_id);
if(rank && rank->base_ability) {
ExpendAlternateAdvancementCharge(rank->base_ability->id);
}
}
else if(spell_id == casting_spell_id && casting_spell_timer != 0xFFFFFFFF)
{
//aa new todo: aa expendable charges here
CastToClient()->GetPTimers().Start(casting_spell_timer, casting_spell_timer_duration);
LogSpells("Spell [{}]: Setting custom reuse timer [{}] to [{}]", spell_id, casting_spell_timer, casting_spell_timer_duration);
}
else if(spells[spell_id].recast_time > 1000 && !spells[spell_id].IsDisciplineBuff) {
int recast = spells[spell_id].recast_time/1000;
if (spell_id == SPELL_LAY_ON_HANDS) //lay on hands
{
recast -= GetAA(aaFervrentBlessing) * 420;
}
else if (spell_id == SPELL_HARM_TOUCH || spell_id == SPELL_HARM_TOUCH2) //harm touch
{
recast -= GetAA(aaTouchoftheWicked) * 420;
}
int reduction = CastToClient()->GetFocusEffect(focusReduceRecastTime, spell_id);//Client only
if(reduction)
recast -= reduction;
LogSpells("Spell [{}]: Setting long reuse timer to [{}] s (orig [{}])", spell_id, recast, spells[spell_id].recast_time);
CastToClient()->GetPTimers().Start(pTimerSpellStart + spell_id, recast);
}
}
if(IsClient() && (slot == CastingSlot::Item || slot == CastingSlot::PotionBelt))
{
EQEmu::ItemInstance *itm = CastToClient()->GetInv().GetItem(inventory_slot);
if(itm && itm->GetItem()->RecastDelay > 0){
auto recast_type = itm->GetItem()->RecastType;
CastToClient()->GetPTimers().Start((pTimerItemStart + recast_type), itm->GetItem()->RecastDelay);
database.UpdateItemRecastTimestamps(
CastToClient()->CharacterID(), recast_type,
CastToClient()->GetPTimers().Get(pTimerItemStart + recast_type)->GetReadyTimestamp());
auto outapp = new EQApplicationPacket(OP_ItemRecastDelay, sizeof(ItemRecastDelay_Struct));
ItemRecastDelay_Struct *ird = (ItemRecastDelay_Struct *)outapp->pBuffer;
ird->recast_delay = itm->GetItem()->RecastDelay;
ird->recast_type = recast_type;
CastToClient()->QueuePacket(outapp);
safe_delete(outapp);
}
}
if(IsNPC())
CastToNPC()->AI_Event_SpellCastFinished(true, static_cast<uint16>(slot));
return true;
}
/*
* handle bard song pulses...
*
* we make several assumptions that SpellFinished does not:
* - there are no AEDuration (beacon) bard songs
* - there are no recourse spells on bard songs
* - there is no long recast delay on bard songs
*
* return false to stop the song
*/
bool Mob::ApplyNextBardPulse(uint16 spell_id, Mob *spell_target, CastingSlot slot) {
if(slot == CastingSlot::Item) {
//bard songs should never come from items...
LogSpells("Bard Song Pulse [{}]: Supposidly cast from an item. Killing song", spell_id);
return(false);
}
//determine the type of spell target we have
Mob *ae_center = nullptr;
CastAction_type CastAction;
if(!DetermineSpellTargets(spell_id, spell_target, ae_center, CastAction, slot)) {
LogSpells("Bard Song Pulse [{}]: was unable to determine target. Stopping", spell_id);
return(false);
}
if(ae_center != nullptr && ae_center->IsBeacon()) {
LogSpells("Bard Song Pulse [{}]: Unsupported Beacon NPC AE spell", spell_id);
return(false);
}
//use mana, if this spell has a mana cost
int mana_used = spells[spell_id].mana;
if(mana_used > 0) {
if(mana_used > GetMana()) {
//ran out of mana... this calls StopSong() for us
LogSpells("Ran out of mana while singing song [{}]", spell_id);
return(false);
}
LogSpells("Bard Song Pulse [{}]: consuming [{}] mana (have [{}])", spell_id, mana_used, GetMana());
SetMana(GetMana() - mana_used);
}
// check line of sight to target if it's a detrimental spell
if(spell_target && IsDetrimentalSpell(spell_id) && !CheckLosFN(spell_target))
{
LogSpells("Bard Song Pulse [{}]: cannot see target [{}]", spell_target->GetName());
MessageString(Chat::Red, CANT_SEE_TARGET);
return(false);
}
//range check our target, if we have one and it is not us
float range = 0.00f;
range = GetActSpellRange(spell_id, spells[spell_id].range, true);
if(spell_target != nullptr && spell_target != this) {
//casting a spell on somebody but ourself, make sure they are in range
float dist2 = DistanceSquared(m_Position, spell_target->GetPosition());
float range2 = range * range;
if(dist2 > range2) {
//target is out of range.
LogSpells("Bard Song Pulse [{}]: Spell target is out of range (squared: [{}] > [{}])", spell_id, dist2, range2);
MessageString(Chat::Red, TARGET_OUT_OF_RANGE);
return(false);
}
}
//
// Switch #2 - execute the spell
//
switch(CastAction)
{
default:
case CastActUnknown:
case SingleTarget:
{
if(spell_target == nullptr) {
LogSpells("Bard Song Pulse [{}]: Targeted spell, but we have no target", spell_id);
return(false);
}
LogSpells("Bard Song Pulse: Targeted. spell [{}], target [{}]", spell_id, spell_target->GetName());
spell_target->BardPulse(spell_id, this);
break;
}
case AECaster:
{
if(IsBeneficialSpell(spell_id))
SpellOnTarget(spell_id, this);
bool affect_caster = !IsNPC(); //NPC AE spells do not affect the NPC caster
entity_list.AEBardPulse(this, this, spell_id, affect_caster);
break;
}
case AETarget:
{
// we can't cast an AE spell without something to center it on
if(ae_center == nullptr) {
LogSpells("Bard Song Pulse [{}]: AE Targeted spell, but we have no target", spell_id);
return(false);
}
// regular PB AE or targeted AE spell - spell_target is null if PB
if(spell_target) { // this must be an AETarget spell
// affect the target too
spell_target->BardPulse(spell_id, this);
LogSpells("Bard Song Pulse: spell [{}], AE target [{}]", spell_id, spell_target->GetName());
} else {
LogSpells("Bard Song Pulse: spell [{}], AE with no target", spell_id);
}
bool affect_caster = !IsNPC(); //NPC AE spells do not affect the NPC caster
entity_list.AEBardPulse(this, ae_center, spell_id, affect_caster);
break;
}
case GroupSpell:
{
if(spell_target->IsGrouped()) {
LogSpells("Bard Song Pulse: spell [{}], Group targeting group of [{}]", spell_id, spell_target->GetName());
Group *target_group = entity_list.GetGroupByMob(spell_target);
if(target_group)
target_group->GroupBardPulse(this, spell_id);
}
else if(spell_target->IsRaidGrouped() && spell_target->IsClient()) {
LogSpells("Bard Song Pulse: spell [{}], Raid group targeting raid group of [{}]", spell_id, spell_target->GetName());
Raid *r = entity_list.GetRaidByClient(spell_target->CastToClient());
if(r){
uint32 gid = r->GetGroup(spell_target->GetName());
if(gid < 12){
r->GroupBardPulse(this, spell_id, gid);
}
else{
BardPulse(spell_id, this);
#ifdef GROUP_BUFF_PETS
if (GetPet() && HasPetAffinity() && !GetPet()->IsCharmed())
GetPet()->BardPulse(spell_id, this);
#endif
}
}
}
else {
LogSpells("Bard Song Pulse: spell [{}], Group target without group. Affecting caster", spell_id);
BardPulse(spell_id, this);
#ifdef GROUP_BUFF_PETS
if (GetPet() && HasPetAffinity() && !GetPet()->IsCharmed())
GetPet()->BardPulse(spell_id, this);
#endif
}
break;
}
}
//do we need to do this???
DoAnim(spells[spell_id].CastingAnim, 0, true, IsClient() ? FilterPCSpells : FilterNPCSpells);
if(IsClient())
CastToClient()->CheckSongSkillIncrease(spell_id);
return(true);
}
void Mob::BardPulse(uint16 spell_id, Mob *caster) {
int buffs_i;
int buff_count = GetMaxTotalSlots();
for (buffs_i = 0; buffs_i < buff_count; buffs_i++) {
if(buffs[buffs_i].spellid != spell_id)
continue;
if(buffs[buffs_i].casterid != caster->GetID()) {
LogSpells("Bard Pulse for [{}]: found buff from caster [{}] and we are pulsing for [{}] are there two bards playing the same song???", spell_id, buffs[buffs_i].casterid, caster->GetID());
return;
}
//extend the spell if it will expire before the next pulse
if(buffs[buffs_i].ticsremaining <= 3) {
buffs[buffs_i].ticsremaining += 3;
LogSpells("Bard Song Pulse [{}]: extending duration in slot [{}] to [{}] tics", spell_id, buffs_i, buffs[buffs_i].ticsremaining);
}
//should we send this buff update to the client... seems like it would
//be a lot of traffic for no reason...
//this may be the wrong packet...
if(IsClient()) {
auto packet = new EQApplicationPacket(OP_Action, sizeof(Action_Struct));
Action_Struct* action = (Action_Struct*) packet->pBuffer;
action->source = caster->GetID();
action->target = GetID();
action->spell = spell_id;
action->force = spells[spell_id].pushback;
action->hit_heading = GetHeading();
action->hit_pitch = spells[spell_id].pushup;
action->instrument_mod = caster->GetInstrumentMod(spell_id);
action->effect_flag = 0;
action->spell_level = action->level = buffs[buffs_i].casterlevel;
action->type = DamageTypeSpell;
entity_list.QueueCloseClients(this, packet, false, RuleI(Range, SongMessages), 0, true, IsClient() ? FilterPCSpells : FilterNPCSpells);
action->effect_flag = 4;
if(!IsEffectInSpell(spell_id, SE_BindAffinity))
{
CastToClient()->QueuePacket(packet);
}
auto message_packet = new EQApplicationPacket(OP_Damage, sizeof(CombatDamage_Struct));
CombatDamage_Struct *cd = (CombatDamage_Struct *)message_packet->pBuffer;
cd->target = action->target;
cd->source = action->source;
cd->type = DamageTypeSpell;
cd->spellid = action->spell;
cd->force = action->force;
cd->hit_heading = action->hit_heading;
cd->hit_pitch = action->hit_pitch;
cd->damage = 0;
if(!IsEffectInSpell(spell_id, SE_BindAffinity))
{
entity_list.QueueCloseClients(this, message_packet, false, RuleI(Range, SongMessages), 0, true, IsClient() ? FilterPCSpells : FilterNPCSpells);
}
safe_delete(message_packet);
safe_delete(packet);
}
//we are done...
return;
}
LogSpells("Bard Song Pulse [{}]: Buff not found, reapplying spell", spell_id);
//this spell is not affecting this mob, apply it.
caster->SpellOnTarget(spell_id, this);
}
///////////////////////////////////////////////////////////////////////////////
// buff related functions
// returns how many _ticks_ the buff will last.
// a tick is 6 seconds
// this is the place to figure out random duration buffs like fear and charm.
// both the caster and target mobs are passed in, so different behavior can
// even be created depending on the types of mobs involved
//
// right now this is just an outline, working on this..
int Mob::CalcBuffDuration(Mob *caster, Mob *target, uint16 spell_id, int32 caster_level_override)
{
int formula, duration;
if(!IsValidSpell(spell_id) || (!caster && !target))
return 0;
if(!caster && !target)
return 0;
// if we have at least one, we can make do, we'll just pretend they're the same
if(!caster)
caster = target;
if(!target)
target = caster;
formula = spells[spell_id].buffdurationformula;
duration = spells[spell_id].buffduration;
int castlevel = caster->GetCasterLevel(spell_id);
if(caster_level_override > 0)
castlevel = caster_level_override;
int res = CalcBuffDuration_formula(castlevel, formula, duration);
if (caster == target && (target->aabonuses.IllusionPersistence || target->spellbonuses.IllusionPersistence ||
target->itembonuses.IllusionPersistence) &&
spell_id != 287 && spell_id != 601 && IsEffectInSpell(spell_id, SE_Illusion))
res = 10000; // ~16h override
res = mod_buff_duration(res, caster, target, spell_id);
LogSpells("Spell [{}]: Casting level [{}], formula [{}], base_duration [{}]: result [{}]",
spell_id, castlevel, formula, duration, res);
return res;
}
// the generic formula calculations
int CalcBuffDuration_formula(int level, int formula, int duration)
{
int temp;
switch (formula) {
case 1:
temp = level > 3 ? level / 2 : 1;
break;
case 2:
temp = level > 3 ? level / 2 + 5 : 6;
break;
case 3:
temp = 30 * level;
break;
case 4: // only used by 'LowerElement'
temp = 50;
break;
case 5:
temp = 2;
break;
case 6:
temp = level / 2 + 2;
break;
case 7:
temp = level;
break;
case 8:
temp = level + 10;
break;
case 9:
temp = 2 * level + 10;
break;
case 10:
temp = 3 * level + 10;
break;
case 11:
temp = 30 * (level + 3);
break;
case 12:
temp = level > 7 ? level / 4 : 1;
break;
case 13:
temp = 4 * level + 10;
break;
case 14:
temp = 5 * (level + 2);
break;
case 15:
temp = 10 * (level + 10);
break;
case 50: // Permanent. Cancelled by casting/combat for perm invis, non-lev zones for lev, curing poison/curse
// counters, etc.
return -1;
case 51: // Permanent. Cancelled when out of range of aura.
return -4;
default:
// the client function has another bool parameter that if true returns -2 -- unsure
if (formula < 200)
return 0;
temp = formula;
break;
}
if (duration && duration < temp)
temp = duration;
return temp;
}
// helper function for AddBuff to determine stacking
// spellid1 is the spell already worn, spellid2 is the one trying to be cast
// returns:
// 0 if not the same type, no action needs to be taken
// 1 if spellid1 should be removed (overwrite)
// -1 if they can't stack and spellid2 should be stopped
//currently, a spell will not land if it would overwrite a better spell on any effect
//if all effects are better or the same, we overwrite, else we do nothing
int Mob::CheckStackConflict(uint16 spellid1, int caster_level1, uint16 spellid2, int caster_level2, Mob* caster1, Mob* caster2, int buffslot)
{
const SPDat_Spell_Struct &sp1 = spells[spellid1];
const SPDat_Spell_Struct &sp2 = spells[spellid2];
int i, effect1, effect2, sp1_value, sp2_value;
int blocked_effect, blocked_below_value, blocked_slot;
int overwrite_effect, overwrite_below_value, overwrite_slot;
LogSpells("Check Stacking on old [{}] ([{}]) @ lvl [{}] (by [{}]) vs. new [{}] ([{}]) @ lvl [{}] (by [{}])", sp1.name, spellid1, caster_level1, (caster1==nullptr)?"Nobody":caster1->GetName(), sp2.name, spellid2, caster_level2, (caster2==nullptr)?"Nobody":caster2->GetName());
if (spellid1 == spellid2 ) {
if (!IsStackableDot(spellid1) && !IsEffectInSpell(spellid1, SE_ManaBurn)) { // mana burn spells we need to use the stacking command blocks live actually checks those first, we should probably rework to that too
if (caster_level1 > caster_level2) { // cur buff higher level than new
if (IsEffectInSpell(spellid1, SE_ImprovedTaunt)) {
LogSpells("SE_ImprovedTaunt level exception, overwriting");
return 1;
} else {
LogSpells("Spells the same but existing is higher level, stopping");
return -1;
}
} else {
LogSpells("Spells the same but newer is higher or equal level, overwriting");
return 1;
}
} else if (spellid1 == 2751) {
LogSpells("Blocking spell because manaburn does not stack with itself");
return -1;
}
}
int modval = mod_spell_stack(spellid1, caster_level1, caster1, spellid2, caster_level2, caster2);
if(modval < 2) { return(modval); }
/*
One of these is a bard song and one isn't and they're both beneficial so they should stack.
*/
if(IsBardSong(spellid1) != IsBardSong(spellid2))
{
if(!IsDetrimentalSpell(spellid1) && !IsDetrimentalSpell(spellid2))
{
LogSpells("[{}] and [{}] are beneficial, and one is a bard song, no action needs to be taken", sp1.name, sp2.name);
return (0);
}
}
bool effect_match = true; // Figure out if we're identical in effects on all slots.
if (spellid1 != spellid2) {
for (i = 0; i < EFFECT_COUNT; i++) {
// we don't want this optimization for mana burns
if (sp1.effectid[i] != sp2.effectid[i] || sp1.effectid[i] == SE_ManaBurn) {
effect_match = false;
break;
}
}
} else if (IsEffectInSpell(spellid1, SE_ManaBurn)) {
LogSpells("We have a Mana Burn spell that is the same, they won't stack");
return -1;
}
// check for special stacking overwrite in spell2 against effects in spell1
// If all of the effects match they are the same line and shouldn't care for these checks
if (!effect_match) {
for(i = 0; i < EFFECT_COUNT; i++)
{
effect1 = sp1.effectid[i];
effect2 = sp2.effectid[i];
if (spellbonuses.Screech == 1) {
if (effect2 == SE_Screech && sp2.base[i] == -1) {
MessageString(Chat::SpellFailure, SCREECH_BUFF_BLOCK, sp2.name);
return -1;
}
}
/*Buff stacking prevention spell effects (446 - 449) works as follows... If B prevent A, if C prevent B, if D prevent C.
If checking same type ie A vs A, which ever effect base value is higher will take hold.
Special check is added to make sure the buffs stack properly when applied from fade on duration effect, since the buff
is not fully removed at the time of the trgger*/
if (spellbonuses.AStacker[0]) {
if ((effect2 == SE_AStacker) && (sp2.effectid[i] <= spellbonuses.AStacker[1]))
return -1;
}
if (spellbonuses.BStacker[0]) {
if ((effect2 == SE_BStacker) && (sp2.effectid[i] <= spellbonuses.BStacker[1]))
return -1;
if ((effect2 == SE_AStacker) && (!IsCastonFadeDurationSpell(spellid1) && buffs[buffslot].ticsremaining != 1 && IsEffectInSpell(spellid1, SE_BStacker)))
return -1;
}
if (spellbonuses.CStacker[0]) {
if ((effect2 == SE_CStacker) && (sp2.effectid[i] <= spellbonuses.CStacker[1]))
return -1;
if ((effect2 == SE_BStacker) && (!IsCastonFadeDurationSpell(spellid1) && buffs[buffslot].ticsremaining != 1 && IsEffectInSpell(spellid1, SE_CStacker)))
return -1;
}
if (spellbonuses.DStacker[0]) {
if ((effect2 == SE_DStacker) && (sp2.effectid[i] <= spellbonuses.DStacker[1]))
return -1;
if ((effect2 == SE_CStacker) && (!IsCastonFadeDurationSpell(spellid1) && buffs[buffslot].ticsremaining != 1 && IsEffectInSpell(spellid1, SE_DStacker)))
return -1;
}
if(effect2 == SE_StackingCommand_Overwrite)
{
overwrite_effect = sp2.base[i];
overwrite_slot = sp2.formula[i] - 201; //they use base 1 for slots, we use base 0
overwrite_below_value = sp2.max[i];
if(sp1.effectid[overwrite_slot] == overwrite_effect)
{
sp1_value = CalcSpellEffectValue(spellid1, overwrite_slot, caster_level1);
LogSpells("[{}] ([{}]) overwrites existing spell if effect [{}] on slot [{}] is below [{}]. Old spell has value [{}] on that slot/effect. [{}]",
sp2.name, spellid2, overwrite_effect, overwrite_slot, overwrite_below_value, sp1_value, (sp1_value < overwrite_below_value)?"Overwriting":"Not overwriting");
if(sp1_value < overwrite_below_value)
{
LogSpells("Overwrite spell because sp1_value < overwrite_below_value");
return 1; // overwrite spell if its value is less
}
} else {
LogSpells("[{}] ([{}]) overwrites existing spell if effect [{}] on slot [{}] is below [{}], but we do not have that effect on that slot. Ignored",
sp2.name, spellid2, overwrite_effect, overwrite_slot, overwrite_below_value);
}
} else if (effect1 == SE_StackingCommand_Block)
{
blocked_effect = sp1.base[i];
blocked_slot = sp1.formula[i] - 201;
blocked_below_value = sp1.max[i];
if (sp2.effectid[blocked_slot] == blocked_effect)
{
sp2_value = CalcSpellEffectValue(spellid2, blocked_slot, caster_level2);
LogSpells("[{}] ([{}]) blocks effect [{}] on slot [{}] below [{}]. New spell has value [{}] on that slot/effect. [{}]",
sp1.name, spellid1, blocked_effect, blocked_slot, blocked_below_value, sp2_value, (sp2_value < blocked_below_value)?"Blocked":"Not blocked");
if (sp2_value < blocked_below_value)
{
LogSpells("Blocking spell because sp2_Value < blocked_below_value");
return -1; //blocked
}
} else {
LogSpells("[{}] ([{}]) blocks effect [{}] on slot [{}] below [{}], but we do not have that effect on that slot. Ignored",
sp1.name, spellid1, blocked_effect, blocked_slot, blocked_below_value);
}
}
}
} else {
LogSpells("[{}] ([{}]) and [{}] ([{}]) appear to be in the same line, skipping Stacking Overwrite/Blocking checks",
sp1.name, spellid1, sp2.name, spellid2);
}
bool sp1_detrimental = IsDetrimentalSpell(spellid1);
bool sp2_detrimental = IsDetrimentalSpell(spellid2);
bool sp_det_mismatch;
if(sp1_detrimental == sp2_detrimental)
sp_det_mismatch = false;
else
sp_det_mismatch = true;
// now compare matching effects
// arbitration takes place if 2 spells have the same effect at the same
// effect slot, otherwise they're stackable, even if it's the same effect
bool will_overwrite = false;
bool values_equal = true;
for(i = 0; i < EFFECT_COUNT; i++)
{
if(IsBlankSpellEffect(spellid1, i) || IsBlankSpellEffect(spellid2, i))
continue;
effect1 = sp1.effectid[i];
effect2 = sp2.effectid[i];
/*
Quick check, are the effects the same, if so then
keep going else ignore it for stacking purposes.
*/
if(effect1 != effect2)
continue;
if (IsBardOnlyStackEffect(effect1) && GetSpellLevel(spellid1, BARD) != 255 &&
GetSpellLevel(spellid2, BARD) != 255)
continue;
// big ol' list according to the client, wasn't that nice!
if (IsEffectIgnoredInStacking(effect1))
continue;
// negative AC affects are skipped. Ex. Sun's Corona and Glacier Breath should stack
// There may be more SPAs we need to add here ....
// The client does just check base rather than calculating the affect change value.
if ((effect1 == SE_ArmorClass || effect1 == SE_ACv2) && sp2.base[i] < 0)
continue;
/*
If target is a npc and caster1 and caster2 exist
If Caster1 isn't the same as Caster2 and the effect is a DoT then ignore it.
*/
if(IsNPC() && caster1 && caster2 && caster1 != caster2) {
if(effect1 == SE_CurrentHP && sp1_detrimental && sp2_detrimental) {
LogSpells("Both casters exist and are not the same, the effect is a detrimental dot, moving on");
continue;
}
}
if(effect1 == SE_CompleteHeal){ //SE_CompleteHeal never stacks or overwrites ever, always block.
LogSpells("Blocking spell because complete heal never stacks or overwries");
return (-1);
}
/*
If the spells aren't the same
and the effect is a dot we can go ahead and stack it
*/
if(effect1 == SE_CurrentHP && spellid1 != spellid2 && sp1_detrimental && sp2_detrimental) {
LogSpells("The spells are not the same and it is a detrimental dot, passing");
continue;
}
sp1_value = CalcSpellEffectValue(spellid1, i, caster_level1);
sp2_value = CalcSpellEffectValue(spellid2, i, caster_level2);
// some spells are hard to compare just on value. attack speed spells
// have a value that's a percentage for instance
if
(
effect1 == SE_AttackSpeed ||
effect1 == SE_AttackSpeed2
)
{
sp1_value -= 100;
sp2_value -= 100;
}
if(sp1_value < 0)
sp1_value = 0 - sp1_value;
if(sp2_value < 0)
sp2_value = 0 - sp2_value;
if(sp2_value < sp1_value) {
LogSpells("Spell [{}] (value [{}]) is not as good as [{}] (value [{}]). Rejecting [{}]",
sp2.name, sp2_value, sp1.name, sp1_value, sp2.name);
return -1; // can't stack
}
if (sp2_value != sp1_value)
values_equal = false;
//we dont return here... a better value on this one effect dosent mean they are
//all better...
LogSpells("Spell [{}] (value [{}]) is not as good as [{}] (value [{}]). We will overwrite [{}] if there are no other conflicts",
sp1.name, sp1_value, sp2.name, sp2_value, sp1.name);
will_overwrite = true;
}
//if we get here, then none of the values on the new spell are "worse"
//so now we see if this new spell is any better, or if its not related at all
if(will_overwrite) {
if (values_equal && effect_match && !IsGroupSpell(spellid2) && IsGroupSpell(spellid1)) {
LogSpells("[{}] ([{}]) appears to be the single target version of [{}] ([{}]), rejecting",
sp2.name, spellid2, sp1.name, spellid1);
return -1;
}
LogSpells("Stacking code decided that [{}] should overwrite [{}]", sp2.name, sp1.name);
return(1);
}
LogSpells("Stacking code decided that [{}] is not affected by [{}]", sp2.name, sp1.name);
return 0;
}
// Check Spell Level Restrictions
// returns true if they meet the restrictions, false otherwise
// derived from http://samanna.net/eq.general/buffs.shtml
// spells 1-50: no restrictons
// 51-65: SpellLevel/2+15
// 66+ Group Spells 62, Single Target 61
bool Mob::CheckSpellLevelRestriction(uint16 spell_id)
{
return true;
}
bool Client::CheckSpellLevelRestriction(uint16 spell_id)
{
int SpellLevel = GetMinLevel(spell_id);
// Only check for beneficial buffs
if (IsBuffSpell(spell_id) && IsBeneficialSpell(spell_id)) {
if (SpellLevel > 65) {
if (IsGroupSpell(spell_id) && GetLevel() < 62)
return false;
else if (GetLevel() < 61)
return false;
} else if (SpellLevel > 50) { // 51-65
if (GetLevel() < (SpellLevel / 2 + 15))
return false;
}
}
return true;
}
uint32 Mob::GetFirstBuffSlot(bool disc, bool song)
{
return 0;
}
uint32 Mob::GetLastBuffSlot(bool disc, bool song)
{
return GetCurrentBuffSlots();
}
uint32 Client::GetFirstBuffSlot(bool disc, bool song)
{
if (song)
return GetMaxBuffSlots();
if (disc)
return GetMaxBuffSlots() + GetMaxSongSlots();
return 0;
}
uint32 Client::GetLastBuffSlot(bool disc, bool song)
{
if (song)
return GetMaxBuffSlots() + GetCurrentSongSlots();
if (disc)
return GetMaxBuffSlots() + GetMaxSongSlots() + GetCurrentDiscSlots();
return GetCurrentBuffSlots();
}
bool Mob::HasDiscBuff()
{
int slot = GetFirstBuffSlot(true, false);
return buffs[slot].spellid != SPELL_UNKNOWN;
}
// returns the slot the buff was added to, -1 if it wasn't added due to
// stacking problems, and -2 if this is not a buff
// if caster is null, the buff will be added with the caster level being
// the level of the mob
int Mob::AddBuff(Mob *caster, uint16 spell_id, int duration, int32 level_override)
{
int buffslot, ret, caster_level, emptyslot = -1;
bool will_overwrite = false;
std::vector<int> overwrite_slots;
if (level_override > 0)
caster_level = level_override;
else
caster_level = caster ? caster->GetCasterLevel(spell_id) : GetCasterLevel(spell_id);
if (duration == 0) {
duration = CalcBuffDuration(caster, this, spell_id);
if (caster && duration > 0) // negatives are perma buffs
duration = caster->GetActSpellDuration(spell_id, duration);
}
if (duration == 0) {
LogSpells("Buff [{}] failed to add because its duration came back as 0", spell_id);
return -2; // no duration? this isn't a buff
}
LogSpells("Trying to add buff [{}] cast by [{}] (cast level [{}]) with duration [{}]",
spell_id, caster?caster->GetName():"UNKNOWN", caster_level, duration);
// first we loop through everything checking that the spell
// can stack with everything. this is to avoid stripping the spells
// it would overwrite, and then hitting a buff we can't stack with.
// we also check if overwriting will occur. this is so after this loop
// we can determine if there will be room for this buff
int buff_count = GetMaxTotalSlots();
uint32 start_slot = GetFirstBuffSlot(IsDisciplineBuff(spell_id), spells[spell_id].short_buff_box);
uint32 end_slot = GetLastBuffSlot(IsDisciplineBuff(spell_id), spells[spell_id].short_buff_box);
for (buffslot = 0; buffslot < buff_count; buffslot++) {
const Buffs_Struct &curbuf = buffs[buffslot];
if (curbuf.spellid != SPELL_UNKNOWN) {
// there's a buff in this slot
ret = CheckStackConflict(curbuf.spellid, curbuf.casterlevel, spell_id,
caster_level, entity_list.GetMobID(curbuf.casterid), caster, buffslot);
if (ret == -1) { // stop the spell
LogSpells("Adding buff [{}] failed: stacking prevented by spell [{}] in slot [{}] with caster level [{}]",
spell_id, curbuf.spellid, buffslot, curbuf.casterlevel);
if (caster && caster->IsClient() && RuleB(Client, UseLiveBlockedMessage)) {
caster->Message(Chat::Red, "Your %s did not take hold on %s. (Blocked by %s.)", spells[spell_id].name, this->GetName(), spells[curbuf.spellid].name);
}
return -1;
}
if (ret == 1) { // set a flag to indicate that there will be overwriting
LogSpells("Adding buff [{}] will overwrite spell [{}] in slot [{}] with caster level [{}]",
spell_id, curbuf.spellid, buffslot, curbuf.casterlevel);
// If this is the first buff it would override, use its slot
if (!will_overwrite && !IsDisciplineBuff(spell_id))
emptyslot = buffslot;
will_overwrite = true;
overwrite_slots.push_back(buffslot);
}
} else {
if (emptyslot == -1) {
if (buffslot >= start_slot && buffslot < end_slot) {
emptyslot = buffslot;
}
}
}
}
// we didn't find an empty slot to put it in, and it's not overwriting
// anything so there must not be any room left.
if (emptyslot == -1 && !will_overwrite) {
if (IsDetrimentalSpell(spell_id)) {//Sucks to be you, bye bye one of your buffs
for (buffslot = 0; buffslot < buff_count; buffslot++) {
const Buffs_Struct &curbuf = buffs[buffslot];
if (IsBeneficialSpell(curbuf.spellid)) {
LogSpells("No slot for detrimental buff [{}], so we are overwriting a beneficial buff [{}] in slot [{}]",
spell_id, curbuf.spellid, buffslot);
BuffFadeBySlot(buffslot, false);
emptyslot = buffslot;
break;
}
}
if(emptyslot == -1) {
LogSpells("Unable to find a buff slot for detrimental buff [{}]", spell_id);
return -1;
}
} else {
LogSpells("Unable to find a buff slot for beneficial buff [{}]", spell_id);
return -1;
}
}
// at this point we know that this buff will stick, but we have
// to remove some other buffs already worn if will_overwrite is true
if (will_overwrite) {
std::vector<int>::iterator cur, end;
cur = overwrite_slots.begin();
end = overwrite_slots.end();
for (; cur != end; ++cur) {
// strip spell
BuffFadeBySlot(*cur, false);
// if we hadn't found a free slot before, or if this is earlier
// we use it
if (emptyslot == -1 || (*cur < emptyslot && !IsDisciplineBuff(spell_id)))
emptyslot = *cur;
}
}
// now add buff at emptyslot
assert(buffs[emptyslot].spellid == SPELL_UNKNOWN); // sanity check
buffs[emptyslot].spellid = spell_id;
buffs[emptyslot].casterlevel = caster_level;
if (caster && !caster->IsAura()) // maybe some other things we don't want to ...
strcpy(buffs[emptyslot].caster_name, caster->GetCleanName());
else
memset(buffs[emptyslot].caster_name, 0, 64);
buffs[emptyslot].casterid = caster ? caster->GetID() : 0;
buffs[emptyslot].ticsremaining = duration;
buffs[emptyslot].counters = CalculateCounters(spell_id);
buffs[emptyslot].numhits = spells[spell_id].numhits;
buffs[emptyslot].client = caster ? caster->IsClient() : 0;
buffs[emptyslot].persistant_buff = 0;
buffs[emptyslot].caston_x = 0;
buffs[emptyslot].caston_y = 0;
buffs[emptyslot].caston_z = 0;
buffs[emptyslot].dot_rune = 0;
buffs[emptyslot].ExtraDIChance = 0;
buffs[emptyslot].RootBreakChance = 0;
buffs[emptyslot].instrument_mod = caster ? caster->GetInstrumentMod(spell_id) : 10;
if (level_override > 0) {
buffs[emptyslot].UpdateClient = true;
} else {
if (buffs[emptyslot].ticsremaining > (1 + CalcBuffDuration_formula(caster_level, spells[spell_id].buffdurationformula, spells[spell_id].buffduration)))
buffs[emptyslot].UpdateClient = true;
}
LogSpells("Buff [{}] added to slot [{}] with caster level [{}]", spell_id, emptyslot, caster_level);
if (IsPet() && GetOwner() && GetOwner()->IsClient())
SendPetBuffsToClient();
if((IsClient() && !CastToClient()->GetPVP()) ||
(IsPet() && GetOwner() && GetOwner()->IsClient() && !GetOwner()->CastToClient()->GetPVP()) ||
#ifdef BOTS
(IsBot() && GetOwner() && GetOwner()->IsClient() && !GetOwner()->CastToClient()->GetPVP()) ||
#endif
(IsMerc() && GetOwner() && GetOwner()->IsClient() && !GetOwner()->CastToClient()->GetPVP()))
{
EQApplicationPacket *outapp = MakeBuffsPacket();
entity_list.QueueClientsByTarget(this, outapp, false, nullptr, true, false, EQEmu::versions::maskSoDAndLater);
if(IsClient() && GetTarget() == this)
CastToClient()->QueuePacket(outapp);
safe_delete(outapp);
}
if (IsNPC()) {
EQApplicationPacket *outapp = MakeBuffsPacket();
entity_list.QueueClientsByTarget(this, outapp, false, nullptr, true, false, EQEmu::versions::maskSoDAndLater, true);
safe_delete(outapp);
}
// recalculate bonuses since we stripped/added buffs
CalcBonuses();
return emptyslot;
}
// used by some MobAI stuff
// NOT USED BY SPELL CODE
// note that this should not be used for determining which slot to place a
// buff into
// returns -1 on stack failure, -2 if all slots full, the slot number if the buff should overwrite another buff, or a free buff slot
int Mob::CanBuffStack(uint16 spellid, uint8 caster_level, bool iFailIfOverwrite)
{
int i, ret, firstfree = -2;
LogAI("Checking if buff [{}] cast at level [{}] can stack on me.[{}]", spellid, caster_level, iFailIfOverwrite?" failing if we would overwrite something":"");
int buff_count = GetMaxTotalSlots();
for (i=0; i < buff_count; i++)
{
const Buffs_Struct &curbuf = buffs[i];
// no buff in this slot
if (curbuf.spellid == SPELL_UNKNOWN)
{
// if we haven't found a free slot, this is the first one so save it
if(firstfree == -2)
firstfree = i;
continue;
}
if(curbuf.spellid == spellid)
return(-1); //do not recast a buff we already have on, we recast fast enough that we dont need to refresh our buffs
// there's a buff in this slot
ret = CheckStackConflict(curbuf.spellid, curbuf.casterlevel, spellid, caster_level, nullptr, nullptr, i);
if(ret == 1) {
// should overwrite current slot
if(iFailIfOverwrite) {
LogAI("Buff [{}] would overwrite [{}] in slot [{}], reporting stack failure", spellid, curbuf.spellid, i);
return(-1);
}
if(firstfree == -2)
firstfree = i;
}
if(ret == -1) {
LogAI("Buff [{}] would conflict with [{}] in slot [{}], reporting stack failure", spellid, curbuf.spellid, i);
return -1; // stop the spell, can't stack it
}
}
LogAI("Reporting that buff [{}] could successfully be placed into slot [{}]", spellid, firstfree);
return firstfree;
}
///////////////////////////////////////////////////////////////////////////////
// spell effect related functions
//
// this is actually applying a spell cast from 'this' on 'spelltar'
// it performs pvp checking and applies resists, etc then it
// passes it to SpellEffect which causes effects to the target
//
// this is called by these functions:
// Mob::SpellFinished
// Entity::AESpell (called by Mob::SpellFinished)
// Group::CastGroupSpell (called by Mob::SpellFinished)
//
// also note you can't interrupt the spell here. at this point it's going
// and if you don't want effects just return false. interrupting here will
// break stuff
//
bool Mob::SpellOnTarget(uint16 spell_id, Mob *spelltar, bool reflect, bool use_resist_adjust, int16 resist_adjust,
bool isproc, int level_override)
{
// well we can't cast a spell on target without a target
if(!spelltar)
{
LogSpells("Unable to apply spell [{}] without a target", spell_id);
Message(Chat::Red, "SOT: You must have a target for this spell.");
return false;
}
if(spelltar->IsClient() && spelltar->CastToClient()->IsHoveringForRespawn())
return false;
if(IsDetrimentalSpell(spell_id) && !IsAttackAllowed(spelltar, true) && !IsResurrectionEffects(spell_id)) {
if(!IsClient() || !CastToClient()->GetGM()) {
MessageString(Chat::SpellFailure, SPELL_NO_HOLD);
return false;
}
}
EQApplicationPacket *action_packet = nullptr, *message_packet = nullptr;
float spell_effectiveness;
if(!IsValidSpell(spell_id))
return false;
// these target types skip pcnpc only check (according to dev quotes)
// other AE spells this is redundant, oh well
// 1 = PCs, 2 = NPCs
if (spells[spell_id].pcnpc_only_flag && spells[spell_id].targettype != ST_AETargetHateList &&
spells[spell_id].targettype != ST_HateList) {
if (spells[spell_id].pcnpc_only_flag == 1 && !spelltar->IsClient() && !spelltar->IsMerc())
return false;
else if (spells[spell_id].pcnpc_only_flag == 2 && (spelltar->IsClient() || spelltar->IsMerc()))
return false;
}
uint16 caster_level = level_override > 0 ? level_override : GetCasterLevel(spell_id);
LogSpells("Casting spell [{}] on [{}] with effective caster level [{}]", spell_id, spelltar->GetName(), caster_level);
// Actual cast action - this causes the caster animation and the particles
// around the target
// we do this first, that way we get the particles even if the spell
// doesn't land due to pvp protection
// note: this packet is sent again if the spell is successful, with a flag
// set
action_packet = new EQApplicationPacket(OP_Action, sizeof(Action_Struct));
Action_Struct* action = (Action_Struct*) action_packet->pBuffer;
// select source
if(IsClient() && CastToClient()->GMHideMe())
{
action->source = spelltar->GetID();
}
else
{
action->source = GetID();
// this is a hack that makes detrimental buffs work client to client
// TODO figure out how to do this right
if
(
IsDetrimentalSpell(spell_id) &&
IsClient() &&
spelltar->IsClient()
)
{
action->source = spelltar->GetID();
}
}
// select target
if // Bind Sight line of spells
(
spell_id == 500 || // bind sight
spell_id == 407 // cast sight
)
{
action->target = GetID();
}
else
{
action->target = spelltar->GetID();
}
action->spell_level = action->level = caster_level; // caster level, for animation only
action->type = 231; // 231 means a spell
action->spell = spell_id;
action->force = spells[spell_id].pushback;
action->hit_heading = GetHeading();
action->hit_pitch = spells[spell_id].pushup;
action->instrument_mod = GetInstrumentMod(spell_id);
action->effect_flag = 0;
if(spelltar != this && spelltar->IsClient()) // send to target
spelltar->CastToClient()->QueuePacket(action_packet);
if(IsClient()) // send to caster
CastToClient()->QueuePacket(action_packet);
// send to people in the area, ignoring caster and target
entity_list.QueueCloseClients(
spelltar, /* Sender */
action_packet, /* Packet */
true, /* Ignore Sender */
RuleI(Range, SpellMessages),
this, /* Skip this Mob */
true, /* Packet ACK */
(spelltar->IsClient() ? FilterPCSpells : FilterNPCSpells) /* EQ Filter Type: (8 or 9) */
);
/* Send the EVENT_CAST_ON event */
if(spelltar->IsNPC())
{
char temp1[100];
sprintf(temp1, "%d", spell_id);
parse->EventNPC(EVENT_CAST_ON, spelltar->CastToNPC(), this, temp1, 0);
}
else if (spelltar->IsClient())
{
char temp1[100];
sprintf(temp1, "%d", spell_id);
parse->EventPlayer(EVENT_CAST_ON, spelltar->CastToClient(),temp1, 0);
}
mod_spell_cast(spell_id, spelltar, reflect, use_resist_adjust, resist_adjust, isproc);
// now check if the spell is allowed to land
if (RuleB(Spells, EnableBlockedBuffs)) {
// We return true here since the caster's client should act like normal
if (spelltar->IsBlockedBuff(spell_id)) {
LogSpells("Spell [{}] not applied to [{}] as it is a Blocked Buff",
spell_id, spelltar->GetName());
safe_delete(action_packet);
return true;
}
if (spelltar->IsPet() && spelltar->GetOwner() &&
spelltar->GetOwner()->IsBlockedPetBuff(spell_id)) {
LogSpells("Spell [{}] not applied to [{}] ([{}]'s pet) as it is a Pet Blocked Buff",
spell_id, spelltar->GetName(), spelltar->GetOwner()->GetName());
safe_delete(action_packet);
return true;
}
}
// invuln mobs can't be affected by any spells, good or bad
if(spelltar->GetInvul() || spelltar->DivineAura()) {
LogSpells("Casting spell [{}] on [{}] aborted: they are invulnerable", spell_id, spelltar->GetName());
safe_delete(action_packet);
return false;
}
//cannot hurt untargetable mobs
bodyType bt = spelltar->GetBodyType();
if(bt == BT_NoTarget || bt == BT_NoTarget2) {
if (RuleB(Pets, UnTargetableSwarmPet)) {
if (spelltar->IsNPC()) {
if (!spelltar->CastToNPC()->GetSwarmOwner()) {
LogSpells("Casting spell [{}] on [{}] aborted: they are untargetable", spell_id, spelltar->GetName());
safe_delete(action_packet);
return(false);
}
} else {
LogSpells("Casting spell [{}] on [{}] aborted: they are untargetable", spell_id, spelltar->GetName());
safe_delete(action_packet);
return(false);
}
} else {
LogSpells("Casting spell [{}] on [{}] aborted: they are untargetable", spell_id, spelltar->GetName());
safe_delete(action_packet);
return(false);
}
}
// Prevent double invising, which made you uninvised
// Not sure if all 3 should be stacking
if(IsEffectInSpell(spell_id, SE_Invisibility))
{
if(spelltar->invisible)
{
spelltar->MessageString(Chat::SpellFailure, ALREADY_INVIS, GetCleanName());
safe_delete(action_packet);
return false;
}
}
if(IsEffectInSpell(spell_id, SE_InvisVsUndead))
{
if(spelltar->invisible_undead)
{
spelltar->MessageString(Chat::SpellFailure, ALREADY_INVIS, GetCleanName());
safe_delete(action_packet);
return false;
}
}
if(IsEffectInSpell(spell_id, SE_InvisVsAnimals))
{
if(spelltar->invisible_animals)
{
spelltar->MessageString(Chat::SpellFailure, ALREADY_INVIS, GetCleanName());
safe_delete(action_packet);
return false;
}
}
if(!(IsClient() && CastToClient()->GetGM()) && !IsHarmonySpell(spell_id)) // GMs can cast on anything
{
// Beneficial spells check
if(IsBeneficialSpell(spell_id))
{
if(IsClient() && //let NPCs do beneficial spells on anybody if they want, should be the job of the AI, not the spell code to prevent this from going wrong
spelltar != this)
{
Client* pClient = nullptr;
Raid* pRaid = nullptr;
Group* pBasicGroup = nullptr;
uint32 nGroup = 0; //raid group
Client* pClientTarget = nullptr;
Raid* pRaidTarget = nullptr;
Group* pBasicGroupTarget = nullptr;
uint32 nGroupTarget = 0; //raid group
Client* pClientTargetPet = nullptr;
Raid* pRaidTargetPet = nullptr;
Group* pBasicGroupTargetPet = nullptr;
uint32 nGroupTargetPet = 0; //raid group
const uint32 cnWTF = 0xFFFFFFFF + 1; //this should be zero unless on 64bit? forced uint64?
//Caster client pointers
pClient = this->CastToClient();
pRaid = entity_list.GetRaidByClient(pClient);
pBasicGroup = entity_list.GetGroupByMob(this);
if(pRaid)
nGroup = pRaid->GetGroup(pClient) + 1;
//Target client pointers
if(spelltar->IsClient())
{
pClientTarget = spelltar->CastToClient();
pRaidTarget = entity_list.GetRaidByClient(pClientTarget);
pBasicGroupTarget = entity_list.GetGroupByMob(spelltar);
if(pRaidTarget)
nGroupTarget = pRaidTarget->GetGroup(pClientTarget) + 1;
}
if(spelltar->IsPet())
{
Mob *owner = spelltar->GetOwner();
if(owner->IsClient())
{
pClientTargetPet = owner->CastToClient();
pRaidTargetPet = entity_list.GetRaidByClient(pClientTargetPet);
pBasicGroupTargetPet = entity_list.GetGroupByMob(owner);
if(pRaidTargetPet)
nGroupTargetPet = pRaidTargetPet->GetGroup(pClientTargetPet) + 1;
}
}
if((!IsAllianceSpellLine(spell_id) && !IsBeneficialAllowed(spelltar)) ||
(IsGroupOnlySpell(spell_id) &&
!(
(pBasicGroup && ((pBasicGroup == pBasicGroupTarget) || (pBasicGroup == pBasicGroupTargetPet))) || //Basic Group
((nGroup != cnWTF) && ((nGroup == nGroupTarget) || (nGroup == nGroupTargetPet))) || //Raid group
(spelltar == GetPet()) //should be able to cast grp spells on self and pet despite grped status.
)
)
)
{
if(spells[spell_id].targettype == ST_AEBard) {
//if it was a beneficial AE bard song don't spam the window that it would not hold
LogSpells("Beneficial ae bard song [{}] can't take hold [{}] -> [{}], IBA? [{}]", spell_id, GetName(), spelltar->GetName(), IsBeneficialAllowed(spelltar));
} else {
LogSpells("Beneficial spell [{}] can't take hold [{}] -> [{}], IBA? [{}]", spell_id, GetName(), spelltar->GetName(), IsBeneficialAllowed(spelltar));
MessageString(Chat::SpellFailure, SPELL_NO_HOLD);
}
safe_delete(action_packet);
return false;
}
}
}
else if ( !IsAttackAllowed(spelltar, true) && !IsResurrectionEffects(spell_id)) // Detrimental spells - PVP check
{
LogSpells("Detrimental spell [{}] can't take hold [{}] -> [{}]", spell_id, GetName(), spelltar->GetName());
spelltar->MessageString(Chat::SpellFailure, YOU_ARE_PROTECTED, GetCleanName());
safe_delete(action_packet);
return false;
}
}
// ok at this point the spell is permitted to affect the target,
// but we need to check special cases and resists
// check immunities
if(spelltar->IsImmuneToSpell(spell_id, this))
{
//the above call does the message to the client if needed
LogSpells("Spell [{}] can't take hold due to immunity [{}] -> [{}]", spell_id, GetName(), spelltar->GetName());
safe_delete(action_packet);
return false;
}
//check for AE_Undead
if(spells[spell_id].targettype == ST_UndeadAE){
if(spelltar->GetBodyType() != BT_SummonedUndead &&
spelltar->GetBodyType() != BT_Undead &&
spelltar->GetBodyType() != BT_Vampire)
{
safe_delete(action_packet);
return false;
}
}
// Block next spell effect should be used up first(since its blocking the next spell)
if(CanBlockSpell()) {
int buff_count = GetMaxTotalSlots();
int focus = 0;
for (int b=0; b < buff_count; b++) {
if(IsEffectInSpell(buffs[b].spellid, SE_BlockNextSpellFocus)) {
focus = CalcFocusEffect(focusBlockNextSpell, buffs[b].spellid, spell_id);
if(focus) {
CheckNumHitsRemaining(NumHit::MatchingSpells, b);
MessageString(Chat::SpellFailure, SPELL_WOULDNT_HOLD);
safe_delete(action_packet);
return false;
}
}
}
}
// Reflect
if(spelltar && spelltar->TryReflectSpell(spell_id) && !reflect && IsDetrimentalSpell(spell_id) && this != spelltar) {
int reflect_chance = 0;
switch(RuleI(Spells, ReflectType))
{
case 0:
break;
case 1:
{
if(spells[spell_id].targettype == ST_Target) {
for(int y = 0; y < 16; y++) {
if(spells[spell_id].classes[y] < 255)
reflect_chance = 1;
}
}
break;
}
case 2:
{
for(int y = 0; y < 16; y++) {
if(spells[spell_id].classes[y] < 255)
reflect_chance = 1;
}
break;
}
case 3:
{
if(spells[spell_id].targettype == ST_Target)
reflect_chance = 1;
break;
}
case 4:
reflect_chance = 1;
default:
break;
}
if (reflect_chance) {
if (RuleB(Spells, ReflectMessagesClose)) {
entity_list.MessageCloseString(
this, /* Sender */
false, /* Skip Sender */
RuleI(Range, SpellMessages), /* Range */
Chat::Spells, /* Type */
SPELL_REFLECT, /* String ID */
GetCleanName(), /* Message 1 */
spelltar->GetCleanName() /* Message 2 */
);
}
else {
MessageString(Chat::Spells, SPELL_REFLECT, GetCleanName(), spelltar->GetCleanName());
}
CheckNumHitsRemaining(NumHit::ReflectSpell);
// caster actually appears to change
// ex. During OMM fight you click your reflect mask and you get the recourse from the reflected
// spell
spelltar->SpellOnTarget(spell_id, this, true, use_resist_adjust, resist_adjust);
safe_delete(action_packet);
return false;
}
}
// resist check - every spell can be resisted, beneficial or not
// add: ok this isn't true, eqlive's spell data is fucked up, buffs are
// not all unresistable, so changing this to only check certain spells
if(IsResistableSpell(spell_id))
{
spelltar->BreakInvisibleSpells(); //Any detrimental spell cast on you will drop invisible (can be AOE, non damage ect).
if (IsCharmSpell(spell_id) || IsMezSpell(spell_id) || IsFearSpell(spell_id))
spell_effectiveness = spelltar->ResistSpell(spells[spell_id].resisttype, spell_id, this, use_resist_adjust, resist_adjust, true, false, false, level_override);
else
spell_effectiveness = spelltar->ResistSpell(spells[spell_id].resisttype, spell_id, this, use_resist_adjust, resist_adjust, false, false, false, level_override);
if(spell_effectiveness < 100)
{
if(spell_effectiveness == 0 || !IsPartialCapableSpell(spell_id) )
{
LogSpells("Spell [{}] was completely resisted by [{}]", spell_id, spelltar->GetName());
if (spells[spell_id].resisttype == RESIST_PHYSICAL){
MessageString(Chat::SpellFailure, PHYSICAL_RESIST_FAIL,spells[spell_id].name);
spelltar->MessageString(Chat::SpellFailure, YOU_RESIST, spells[spell_id].name);
}
else {
MessageString(Chat::SpellFailure, TARGET_RESISTED, spells[spell_id].name);
spelltar->MessageString(Chat::SpellFailure, YOU_RESIST, spells[spell_id].name);
}
if (spelltar->IsAIControlled()) {
int32 aggro = CheckAggroAmount(spell_id, spelltar);
if (aggro > 0) {
if (!IsHarmonySpell(spell_id))
spelltar->AddToHateList(this, aggro);
else if (!spelltar->PassCharismaCheck(this, spell_id))
spelltar->AddToHateList(this, aggro);
} else {
int newhate = spelltar->GetHateAmount(this) + aggro;
spelltar->SetHateAmountOnEnt(this, std::max(1, newhate));
}
}
if (spelltar->IsClient()){
spelltar->CastToClient()->BreakSneakWhenCastOn(this, true);
spelltar->CastToClient()->BreakFeignDeathWhenCastOn(true);
}
spelltar->CheckNumHitsRemaining(NumHit::IncomingSpells);
CheckNumHitsRemaining(NumHit::OutgoingSpells);