[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

@ -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);
}