rendered paste bodyvoid Aura::Update(uint32 diff)
{
if (m_duration > 0)
{
m_duration -= diff;
if (m_duration < 0)
m_duration = 0;
m_timeCla -= diff;
Unit* caster = GetCaster();
if(caster && m_timeCla <= 0)
{
Powers powertype = caster->getPowerType();
int32 manaPerSecond = GetSpellProto()->manaPerSecond;
int32 manaPerSecondPerLevel = uint32(GetSpellProto()->manaPerSecondPerLevel*caster->getLevel());
m_timeCla = 1000;
caster->ModifyPower(powertype,-manaPerSecond);
caster->ModifyPower(powertype,-manaPerSecondPerLevel);
}
if(caster && m_target->isAlive() && m_target->HasFlag(UNIT_FIELD_FLAGS,(UNIT_STAT_FLEEING<<16)))
{
int q = rand() % 80;
if(q == 8)
m_fearMoveAngle += (float)(urand(45, 90));
else if(q == 23)
m_fearMoveAngle -= (float)(urand(45, 90));
// If the m_target is player,and if the speed is too slow,change it :P
float speed = m_target->GetSpeed(MOVE_RUN);
// Speed modifier, may need to find correct one
float mod = m_target->GetTypeId() != TYPEID_PLAYER ? 10 : 6;
float pos_x = m_target->GetPositionX();
float pos_y = m_target->GetPositionY();
uint32 mapid = m_target->GetMapId();
float pos_z = MapManager::Instance().GetBaseMap(mapid)->GetHeight(pos_x,pos_y, m_target->GetPositionZ());
// Control the max Distance; 28 for temp.
if(m_target->IsWithinDistInMap(caster, 28))
{
// float x = m_target->GetPositionX() - (speed*cosf(m_fearMoveAngle))/mod;
// float y = m_target->GetPositionY() - (speed*sinf(m_fearMoveAngle))/mod;
// float z = MapManager::Instance().GetBaseMap(mapid)->GetHeight(x,y, m_target->GetPositionZ());
float x = m_target->GetPositionX();
float y = m_target->GetPositionY();
float z = m_target->GetPositionZ();
if((z<=pos_z+1.3 && z>=pos_z-1.3) && m_target->IsWithinLOS(x,y,z))
{
m_target->SendMonsterMove(x,y,z,0,true,(diff*2));
if(m_target->GetTypeId() != TYPEID_PLAYER)
MapManager::Instance().GetMap(m_target->GetMapId(), m_target)->CreatureRelocation((Creature*)m_target,x,y,z,m_target->GetOrientation());
}
else
{
m_fearMoveAngle += 120;
// x = m_target->GetPositionX() + (speed*sinf(m_fearMoveAngle))/mod;
// y = m_target->GetPositionY() + (speed*cosf(m_fearMoveAngle))/mod;
// z = MapManager::Instance().GetBaseMap(mapid)->GetHeight(x,y, m_target->GetPositionZ());
x = m_target->GetPositionX();
y = m_target->GetPositionY();
z = m_target->GetPositionZ();
if((z<=pos_z+1.3 && z>=pos_z-1.3) && m_target->IsWithinLOS(x,y,z))
{
m_target->SendMonsterMove(x,y,z,0,true,(diff*2));
if(m_target->GetTypeId() != TYPEID_PLAYER)
MapManager::Instance().GetMap(m_target->GetMapId(), m_target)->CreatureRelocation((Creature*)m_target,x,y,z,m_target->GetOrientation());
}
}
}
}
}
if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
{
m_periodicTimer -= diff;
if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
{
if( m_modifier.m_auraname == SPELL_AURA_MOD_REGEN ||
m_modifier.m_auraname == SPELL_AURA_MOD_POWER_REGEN ||
// Cannibalize, eating items and other spells
m_modifier.m_auraname == SPELL_AURA_OBS_MOD_HEALTH ||
// Eating items and other spells
m_modifier.m_auraname == SPELL_AURA_OBS_MOD_MANA ||
m_modifier.m_auraname == SPELL_AURA_MOD_MANA_REGEN )
{
ApplyModifier(true);
return;
}
// update before applying (aura can be removed in TriggerSpell or PeriodicAuraLog calls)
m_periodicTimer += m_modifier.periodictime;
if(m_isTrigger)
{
TriggerSpell();
}
else
{
if(Unit* caster = GetCaster())
caster->PeriodicAuraLog(m_target, GetSpellProto(), &m_modifier,GetEffIndex());
else
m_target->PeriodicAuraLog(m_target, GetSpellProto(), &m_modifier,GetEffIndex());
}
}
}
}