From eb3abf2556791842ddc816ad152e26ae6f923d23 Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 19 Feb 2009 18:30:03 -0600 Subject: *Fix a crash caused by summon_type_possess. --HG-- branch : trunk --- src/game/SpellEffects.cpp | 54 +++++++++++------------------------------------ 1 file changed, 12 insertions(+), 42 deletions(-) (limited to 'src/game/SpellEffects.cpp') diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 92a73ffbdb4..a1b5c7cb84e 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3683,18 +3683,6 @@ void Spell::EffectSummonGuardian(uint32 i) for(int32 count = 0; count < amount; ++count) { - Pet* spawnCreature = new Pet(GUARDIAN_PET); - spawnCreature->setActive(m_caster->isActive()); - - Map *map = m_caster->GetMap(); - uint32 pet_number = objmgr.GeneratePetNumber(); - if(!spawnCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map,m_spellInfo->EffectMiscValue[i], pet_number)) - { - sLog.outError("no such creature entry %u",m_spellInfo->EffectMiscValue[i]); - delete spawnCreature; - return; - } - float px, py, pz; // If dest location if present if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION) @@ -3712,47 +3700,27 @@ void Spell::EffectSummonGuardian(uint32 i) } // Summon if dest location not present near caster else - m_caster->GetClosePoint(px,py,pz,spawnCreature->GetObjectSize()); + m_caster->GetClosePoint(px,py,pz,m_caster->GetObjectSize()); - spawnCreature->Relocate(px,py,pz,m_caster->GetOrientation()); - - if(!spawnCreature->IsPositionValid()) - { - sLog.outError("ERROR: Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)", - spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY()); - delete spawnCreature; + Pet *spawnCreature = ((Player*)m_originalCaster)->SummonPet(m_spellInfo->EffectMiscValue[i], px, py, pz, m_caster->GetOrientation(), GUARDIAN_PET, duration); + if(!spawnCreature) return; - } - if(duration > 0) - spawnCreature->SetDuration(duration); - - spawnCreature->SetOwnerGUID(m_originalCaster->GetGUID()); spawnCreature->setPowerType(POWER_MANA); spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS , 0); - spawnCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,m_originalCaster->getFaction()); spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS,0); spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1,0); spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0); - spawnCreature->SetCreatorGUID(m_originalCaster->GetGUID()); spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id); spawnCreature->InitStatsForLevel(level); - spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false); - - spawnCreature->AIM_Initialize(); - - if(m_originalCaster->GetTypeId()==TYPEID_PLAYER) - ((Player*)m_originalCaster)->AddGuardian(spawnCreature); - - map->Add((Creature*)spawnCreature); } } void Spell::EffectSummonPossessed(uint32 i) { - uint32 creatureEntry = m_spellInfo->EffectMiscValue[i]; - if(!creatureEntry) + uint32 entry = m_spellInfo->EffectMiscValue[i]; + if(!entry) return; if(m_caster->GetTypeId() != TYPEID_PLAYER) @@ -3760,15 +3728,17 @@ void Spell::EffectSummonPossessed(uint32 i) uint32 level = m_caster->getLevel(); - float px, py, pz; - m_caster->GetClosePoint(px, py, pz, DEFAULT_WORLD_OBJECT_SIZE); + float x, y, z; + m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE); int32 duration = GetSpellDuration(m_spellInfo); - TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_OR_DEAD_DESPAWN; + Pet* pet = ((Player*)m_caster)->SummonPet(entry, x, y, z, m_caster->GetOrientation(), POSSESSED_PET, duration); + if(!pet) + return; - Creature* c = m_caster->SummonCreature(creatureEntry, px, py, pz, m_caster->GetOrientation(), summonType, duration); - if(c) c->SetCharmedOrPossessedBy(m_caster, true); + pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id); + pet->SetCharmedOrPossessedBy(m_caster, true); } void Spell::EffectTeleUnitsFaceCaster(uint32 i) -- cgit v1.2.3 From 956c828bf56f06b5c25ff20d760ad41be2642a51 Mon Sep 17 00:00:00 2001 From: megamage Date: Fri, 20 Feb 2009 08:22:15 -0600 Subject: *Fix a crash caused by summon guardian effect. --HG-- branch : trunk --- src/game/SpellEffects.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/game/SpellEffects.cpp') diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index a1b5c7cb84e..ac5beb11343 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3637,9 +3637,16 @@ void Spell::EffectSummonGuardian(uint32 i) return; } - // trigger - if(!m_originalCaster || m_originalCaster->GetTypeId() != TYPEID_PLAYER - && !((Creature*)m_originalCaster)->isTotem()/*m_spellInfo->Id == 40276*/) + Player *caster = NULL; + if(m_originalCaster) + { + if(m_originalCaster->GetTypeId() == TYPEID_PLAYER) + caster = (Player*)m_originalCaster; + else if(((Creature*)m_originalCaster)->isTotem()) + caster = m_originalCaster->GetCharmerOrOwnerPlayerOrPlayerItself(); + } + + if(!caster) { EffectSummonWild(i); return; @@ -3651,20 +3658,20 @@ void Spell::EffectSummonGuardian(uint32 i) // Search old Guardian only for players (if casted spell not have duration or cooldown) // FIXME: some guardians have control spell applied and controlled by player and anyway player can't summon in this time // so this code hack in fact - if( m_originalCaster->GetTypeId() == TYPEID_PLAYER && (duration <= 0 || GetSpellRecoveryTime(m_spellInfo)==0) ) - if(((Player*)m_originalCaster)->HasGuardianWithEntry(pet_entry)) + if(duration <= 0 || GetSpellRecoveryTime(m_spellInfo)==0) + if(caster->HasGuardianWithEntry(pet_entry)) return; // find old guardian, ignore summon // in another case summon new - uint32 level = m_originalCaster->getLevel(); + uint32 level = caster->getLevel(); // level of pet summoned using engineering item based at engineering skill level - if(m_originalCaster->GetTypeId()==TYPEID_PLAYER && m_CastItem) + if(m_CastItem) { ItemPrototype const *proto = m_CastItem->GetProto(); if(proto && proto->RequiredSkill == SKILL_ENGINERING) { - uint16 skill202 = ((Player*)m_originalCaster)->GetSkillValue(SKILL_ENGINERING); + uint16 skill202 = caster->GetSkillValue(SKILL_ENGINERING); if(skill202) { level = skill202/5; @@ -3702,7 +3709,7 @@ void Spell::EffectSummonGuardian(uint32 i) else m_caster->GetClosePoint(px,py,pz,m_caster->GetObjectSize()); - Pet *spawnCreature = ((Player*)m_originalCaster)->SummonPet(m_spellInfo->EffectMiscValue[i], px, py, pz, m_caster->GetOrientation(), GUARDIAN_PET, duration); + Pet *spawnCreature = caster->SummonPet(m_spellInfo->EffectMiscValue[i], px, py, pz, m_caster->GetOrientation(), GUARDIAN_PET, duration); if(!spawnCreature) return; -- cgit v1.2.3