/*
* Ascent MMORPG Server
* Copyright (C) 2005-2007 Ascent Team
*
* 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, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; 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, see .
*
*/
#include "StdAfx.h"
#define SPELL_CHANNEL_UPDATE_INTERVAL 1000
extern pSpellEffect SpellEffectsHandler[TOTAL_SPELL_EFFECTS];
void SpellCastTargets::read ( WorldPacket & data,uint64 caster )
{
m_unitTarget = m_itemTarget = 0;m_srcX = m_srcY = m_srcZ = m_destX = m_destY = m_destZ = 0;
m_strTarget = "";
data >> m_targetMask;
WoWGuid guid;
if(m_targetMask == TARGET_FLAG_SELF)
{
m_unitTarget = caster;
}
if(m_targetMask & (TARGET_FLAG_OBJECT | TARGET_FLAG_UNIT | TARGET_FLAG_CORPSE | TARGET_FLAG_CORPSE2))
{
data >> guid;
m_unitTarget = guid.GetOldGuid();
}
if(m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM))
{
data >> guid;
m_itemTarget = guid.GetOldGuid();
}
if(m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
{
data >> m_srcX >> m_srcY >> m_srcZ;
}
if(m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
data >> m_destX >> m_destY >> m_destZ;
}
if(m_targetMask & TARGET_FLAG_STRING)
{
data >> m_strTarget;
}
}
void SpellCastTargets::write ( WorldPacket& data)
{
data << m_targetMask;
if(m_targetMask == TARGET_FLAG_SELF || m_targetMask & (TARGET_FLAG_UNIT | TARGET_FLAG_CORPSE | TARGET_FLAG_CORPSE2 | TARGET_FLAG_OBJECT))
{
FastGUIDPack(data,m_unitTarget);
}
if(m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM))
{
FastGUIDPack(data,m_itemTarget);
}
if(m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
data << m_srcX << m_srcY << m_srcZ;
if(m_targetMask & TARGET_FLAG_DEST_LOCATION)
data << m_destX << m_destY << m_destZ;
if(m_targetMask & TARGET_FLAG_STRING)
data << m_strTarget;
}
Spell::Spell(Object* Caster, SpellEntry *info, bool triggered, Aura* aur)
{
ASSERT( Caster != NULL && info != NULL );
m_spellInfo = info;
m_caster = Caster;
duelSpell = false;
switch(Caster->GetTypeId())
{
case TYPEID_PLAYER:
{
g_caster=NULL;
i_caster=NULL;
u_caster=(Unit*)Caster;
p_caster=(Player*)Caster;
if(p_caster->DuelingWith)
duelSpell = true;
}break;
case TYPEID_UNIT:
{
g_caster=NULL;
i_caster=NULL;
p_caster=NULL;
u_caster=(Unit*)Caster;
if(u_caster->IsPet() && ((Pet*)u_caster)->GetPetOwner()->DuelingWith)
duelSpell = true;
}break;
case TYPEID_ITEM:
case TYPEID_CONTAINER:
{
g_caster=NULL;
u_caster=NULL;
p_caster=NULL;
i_caster=(Item*)Caster;
}break;
case TYPEID_GAMEOBJECT:
{
u_caster=NULL;
p_caster=NULL;
i_caster=NULL;
g_caster=(GameObject*)Caster;
}break;
default:
sLog.outDebug("[DEBUG][SPELL] Incompatible object type, please report this to the dev's");
break;
}
m_spellState = SPELL_STATE_NULL;
m_castPositionX = m_castPositionY = m_castPositionZ = 0;
// TriggerSpellId = 0;
// TriggerSpellTarget = 0;
m_triggeredSpell = triggered;
m_AreaAura = false;
m_triggeredByAura = aur;
damageToHit = 0;
castedItemId = 0;
m_usesMana = false;
failed = false;
bDurSet=false;
bRadSet[0]=false;
bRadSet[1]=false;
bRadSet[2]=false;
cancastresult = -1;
m_requiresCP=false;
unitTarget = NULL;
MissedTargets.clear();
itemTarget = NULL;
gameObjTarget = NULL;
playerTarget = NULL;
corpseTarget = NULL;
judgement = false;
add_damage = 0;
m_delayed = false;
pSpellId = 0;
item_to_delete = NULL;
}
Spell::~Spell()
{
if(u_caster && u_caster->GetCurrentSpell() == this)
u_caster->SetCurrentSpell(NULL);
if(cancastresult == -1 && !failed)
RemoveItems();
if(item_to_delete)
item_to_delete->GetOwner()->GetItemInterface()->SafeFullRemoveItemByGuid(item_to_delete->GetGUID());
}
//i might forget conditions here. Feel free to add them
bool Spell::IsStealthSpell()
{
//check if aura name is some stealth aura
if( m_spellInfo->EffectApplyAuraName[0]==16 ||
m_spellInfo->EffectApplyAuraName[1]==16 ||
m_spellInfo->EffectApplyAuraName[2]==16 )
return true;
return false;
}
//i might forget conditions here. Feel free to add them
bool Spell::IsInvisibilitySpell()
{
//check if aura name is some invisibility aura
if( m_spellInfo->EffectApplyAuraName[0]==18 ||
m_spellInfo->EffectApplyAuraName[1]==18 ||
m_spellInfo->EffectApplyAuraName[2]==18 )
return true;
return false;
}
void Spell::FillAllTargetsInArea(float srcx,float srcy,float srcz,uint32 ind)
{
FillAllTargetsInArea(&m_targetUnits[ind],srcx,srcy,srcz,GetRadius(ind));
}
void Spell::FillAllTargetsInArea(std::vector *tmpMap,float srcx,float srcy,float srcz, float range)
{
float r = range*range;
for(std::set