[11322] Get rid of redundant CalculateSpellDuration calls, calculate once in Spell::prepare

Also fix despawn time calculation of dynamic objects.
This commit is contained in:
zergtmn 2011-04-07 13:32:00 +06:00
parent 28375e295e
commit 0dfcbf8051
4 changed files with 16 additions and 25 deletions

View file

@ -388,6 +388,7 @@ Spell::Spell( Unit* caster, SpellEntry const *info, bool triggered, ObjectGuid o
m_powerCost = 0; // setup to correct value in Spell::prepare, don't must be used before.
m_casttime = 0; // setup to correct value in Spell::prepare, don't must be used before.
m_timer = 0; // will set to cast time in prepare
m_duration = 0;
m_needAliveTargetMask = 0;
@ -2812,6 +2813,7 @@ void Spell::prepare(SpellCastTargets const* targets, Aura* triggeredByAura)
// calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
m_casttime = GetSpellCastTime(m_spellInfo, this);
m_duration = CalculateSpellDuration(m_spellInfo, m_caster);
// set timer base at cast time
ReSetTimer();
@ -3153,15 +3155,10 @@ void Spell::cast(bool skipCheck)
void Spell::handle_immediate()
{
// start channeling if applicable
if(IsChanneledSpell(m_spellInfo))
if (IsChanneledSpell(m_spellInfo) && m_duration > 0)
{
int32 duration = CalculateSpellDuration(m_spellInfo, m_caster);
if (duration > 0)
{
m_spellState = SPELL_STATE_CASTING;
SendChannelStart(duration);
}
m_spellState = SPELL_STATE_CASTING;
SendChannelStart(m_duration);
}
// process immediate effects (items, ground, etc.) also initialize some variables

View file

@ -513,6 +513,7 @@ class Spell
WeaponAttackType m_attackType; // For weapon based attack
uint32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
int32 m_duration;
bool m_canReflect; // can reflect this spell?
bool m_autoRepeat;
uint8 m_runesState;

View file

@ -3995,9 +3995,8 @@ void Spell::EffectPersistentAA(SpellEffectIndex eff_idx)
if (Player* modOwner = m_caster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius);
int32 duration = GetSpellDuration(m_spellInfo);
DynamicObject* dynObj = new DynamicObject;
if (!dynObj->Create(m_caster->GetMap()->GenerateLocalLowGuid(HIGHGUID_DYNAMICOBJECT), m_caster, m_spellInfo->Id, eff_idx, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, duration, radius))
if (!dynObj->Create(m_caster->GetMap()->GenerateLocalLowGuid(HIGHGUID_DYNAMICOBJECT), m_caster, m_spellInfo->Id, eff_idx, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, m_duration, radius))
{
delete dynObj;
return;
@ -4514,19 +4513,15 @@ void Spell::DoSummon(SpellEffectIndex eff_idx)
uint32 level = m_caster->getLevel();
Pet* spawnCreature = new Pet(SUMMON_PET);
int32 duration = CalculateSpellDuration(m_spellInfo, m_caster);
if (m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
{
// Summon in dest location
if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
spawnCreature->Relocate(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, -m_caster->GetOrientation());
// set timer for unsummon
if (duration > 0)
spawnCreature->SetDuration(duration);
if (m_duration > 0)
spawnCreature->SetDuration(m_duration);
return;
}
@ -4549,8 +4544,8 @@ void Spell::DoSummon(SpellEffectIndex eff_idx)
spawnCreature->SetSummonPoint(pos);
// set timer for unsummon
if (duration > 0)
spawnCreature->SetDuration(duration);
if (m_duration > 0)
spawnCreature->SetDuration(m_duration);
spawnCreature->SetOwnerGuid(m_caster->GetObjectGuid());
spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
@ -4966,7 +4961,6 @@ void Spell::DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction)
float center_z = m_targets.m_destZ;
float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[eff_idx]));
int32 duration = CalculateSpellDuration(m_spellInfo, m_caster);
int32 amount = damage > 0 ? damage : 1;
@ -5003,8 +4997,8 @@ void Spell::DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction)
spawnCreature->SetSummonPoint(pos);
if (duration > 0)
spawnCreature->SetDuration(duration);
if (m_duration > 0)
spawnCreature->SetDuration(m_duration);
//spawnCreature->SetName(""); // generated by client
spawnCreature->SetOwnerGuid(m_caster->GetObjectGuid());
@ -7637,8 +7631,7 @@ void Spell::DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc)
pTotem->SetOwner(m_caster);
pTotem->SetTypeBySummonSpell(m_spellInfo); // must be after Create call where m_spells initialized
int32 duration = CalculateSpellDuration(m_spellInfo, m_caster);
pTotem->SetDuration(duration);
pTotem->SetDuration(m_duration);
if (damage) // if not spell info, DB values used
{
@ -7664,7 +7657,7 @@ void Spell::DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc)
WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
data << uint8(slot);
data << pTotem->GetObjectGuid();
data << uint32(duration);
data << uint32(m_duration);
data << uint32(m_spellInfo->Id);
((Player*)m_caster)->SendDirectMessage(&data);
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11321"
#define REVISION_NR "11322"
#endif // __REVISION_NR_H__