diff options
| author | joschiwald <joschiwald.trinity@gmail.com> | 2018-01-27 21:47:37 +0100 |
|---|---|---|
| committer | joschiwald <joschiwald.trinity@gmail.com> | 2018-01-27 23:02:46 +0100 |
| commit | 6226189a1687e1a2b4fb5a490031c22b5f334dc6 (patch) | |
| tree | d48fbc4a586203c0c4ae3721697d3428773e9e00 /src/server/game/Spells/SpellEffects.cpp | |
| parent | f963b8a225a70e7007536d5d4787483a2cade978 (diff) | |
Core/Entities: Created factory methods to create new areatriggers, creatures and gameobjects
Diffstat (limited to 'src/server/game/Spells/SpellEffects.cpp')
| -rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 124 |
1 files changed, 53 insertions, 71 deletions
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index e81d7ef9b8c..eaab7d32b80 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3069,10 +3069,6 @@ void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; - uint32 gameobject_id = effectInfo->MiscValue; - - GameObject* pGameObj = new GameObject(); - WorldObject* target = focusObject; if (!target) target = m_caster; @@ -3084,32 +3080,30 @@ void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE); Map* map = target->GetMap(); - + Position pos = Position(x, y, z, target->GetOrientation()); QuaternionData rot = QuaternionData::fromEulerAnglesZYX(target->GetOrientation(), 0.f, 0.f); - if (!pGameObj->Create(gameobject_id, map, Position(x, y, z, target->GetOrientation()), rot, 255, GO_STATE_READY)) - { - delete pGameObj; + GameObject* go = GameObject::CreateGameObject(effectInfo->MiscValue, map, pos, rot, 255, GO_STATE_READY); + if (!go) return; - } - pGameObj->CopyPhaseFrom(m_caster); + go->CopyPhaseFrom(m_caster); int32 duration = m_spellInfo->CalcDuration(m_caster); - pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); - pGameObj->SetSpellId(m_spellInfo->Id); + go->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); + go->SetSpellId(m_spellInfo->Id); - ExecuteLogEffectSummonObject(effIndex, pGameObj); + ExecuteLogEffectSummonObject(effIndex, go); // Wild object not have owner and check clickable by players - map->AddToMap(pGameObj); + map->AddToMap(go); - if (pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP) + if (go->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP) if (Player* player = m_caster->ToPlayer()) if (Battleground* bg = player->GetBattleground()) - bg->SetDroppedFlagGUID(pGameObj->GetGUID(), player->GetTeam() == ALLIANCE ? TEAM_HORDE: TEAM_ALLIANCE); + bg->SetDroppedFlagGUID(go->GetGUID(), player->GetTeam() == ALLIANCE ? TEAM_HORDE: TEAM_ALLIANCE); - if (GameObject* linkedTrap = pGameObj->GetLinkedTrap()) + if (GameObject* linkedTrap = go->GetLinkedTrap()) { linkedTrap->CopyPhaseFrom(m_caster); @@ -3633,10 +3627,7 @@ void Spell::EffectDuel(SpellEffIndex effIndex) } //CREATE DUEL FLAG OBJECT - GameObject* pGameObj = new GameObject(); - - uint32 gameobject_id = effectInfo->MiscValue; - + Map* map = m_caster->GetMap(); Position const pos = { m_caster->GetPositionX() + (unitTarget->GetPositionX() - m_caster->GetPositionX()) / 2, @@ -3644,31 +3635,29 @@ void Spell::EffectDuel(SpellEffIndex effIndex) m_caster->GetPositionZ(), m_caster->GetOrientation() }; + QuaternionData rot = QuaternionData::fromEulerAnglesZYX(pos.GetOrientation(), 0.f, 0.f); - Map* map = m_caster->GetMap(); - if (!pGameObj->Create(gameobject_id, map, pos, QuaternionData::fromEulerAnglesZYX(pos.GetOrientation(), 0.f, 0.f), 0, GO_STATE_READY)) - { - delete pGameObj; + GameObject* go = GameObject::CreateGameObject(effectInfo->MiscValue, map, pos, rot, 0, GO_STATE_READY); + if (!go) return; - } - pGameObj->CopyPhaseFrom(m_caster); + go->CopyPhaseFrom(m_caster); - pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction()); - pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1); + go->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction()); + go->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1); int32 duration = m_spellInfo->CalcDuration(m_caster); - pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); - pGameObj->SetSpellId(m_spellInfo->Id); + go->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); + go->SetSpellId(m_spellInfo->Id); - ExecuteLogEffectSummonObject(effIndex, pGameObj); + ExecuteLogEffectSummonObject(effIndex, go); - m_caster->AddGameObject(pGameObj); - map->AddToMap(pGameObj); + m_caster->AddGameObject(go); + map->AddToMap(go); //END // Send request WorldPackets::Duel::DuelRequested packet; - packet.ArbiterGUID = pGameObj->GetGUID(); + packet.ArbiterGUID = go->GetGUID(); packet.RequestedByGUID = caster->GetGUID(); packet.RequestedByWowAccount = caster->GetSession()->GetAccountGUID(); @@ -3693,8 +3682,8 @@ void Spell::EffectDuel(SpellEffIndex effIndex) duel2->isMounted = (GetSpellInfo()->Id == 62875); // Mounted Duel target->duel = duel2; - caster->SetGuidValue(PLAYER_DUEL_ARBITER, pGameObj->GetGUID()); - target->SetGuidValue(PLAYER_DUEL_ARBITER, pGameObj->GetGUID()); + caster->SetGuidValue(PLAYER_DUEL_ARBITER, go->GetGUID()); + target->SetGuidValue(PLAYER_DUEL_ARBITER, go->GetGUID()); sScriptMgr->OnPlayerDuelRequest(target, caster); } @@ -3955,7 +3944,6 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; - uint32 go_id = effectInfo->MiscValue; uint8 slot = effectInfo->Effect - SPELL_EFFECT_SUMMON_OBJECT_SLOT1; ObjectGuid guid = m_caster->m_ObjectSlot[slot]; if (!guid.IsEmpty()) @@ -3970,8 +3958,6 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) m_caster->m_ObjectSlot[slot].Clear(); } - GameObject* go = new GameObject(); - float x, y, z; // If dest location if present if (m_targets.HasDst()) @@ -3981,15 +3967,16 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE); Map* map = m_caster->GetMap(); - if (!go->Create(go_id, map, Position(x, y, z, m_caster->GetOrientation()), QuaternionData::fromEulerAnglesZYX(m_caster->GetOrientation(), 0.f, 0.f), 255, GO_STATE_READY)) - { - delete go; + Position pos = Position(x, y, z, m_caster->GetOrientation()); + QuaternionData rot = QuaternionData::fromEulerAnglesZYX(m_caster->GetOrientation(), 0.f, 0.f); + + GameObject* go = GameObject::CreateGameObject(effectInfo->MiscValue, map, pos, rot, 255, GO_STATE_READY); + if (!go) return; - } go->CopyPhaseFrom(m_caster); - //pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()); + //go->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()); int32 duration = m_spellInfo->CalcDuration(m_caster); go->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); go->SetSpellId(m_spellInfo->Id); @@ -4632,7 +4619,6 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) } GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(name_id); - if (!goinfo) { TC_LOG_ERROR("sql.sql", "Gameobject (Entry: %u) does not exist and is not created by spell (ID: %u) cast.", name_id, m_spellInfo->Id); @@ -4664,17 +4650,14 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) if (goinfo->type == GAMEOBJECT_TYPE_RITUAL) m_caster->GetPosition(fx, fy, fz); - GameObject* pGameObj = new GameObject(); - Position pos = { fx, fy, fz, m_caster->GetOrientation() }; QuaternionData rot = QuaternionData::fromEulerAnglesZYX(m_caster->GetOrientation(), 0.f, 0.f); - if (!pGameObj->Create(name_id, cMap, pos, rot, 255, GO_STATE_READY)) - { - delete pGameObj; + + GameObject* go = GameObject::CreateGameObject(name_id, cMap, pos, rot, 255, GO_STATE_READY); + if (!go) return; - } - pGameObj->CopyPhaseFrom(m_caster); + go->CopyPhaseFrom(m_caster); int32 duration = m_spellInfo->CalcDuration(m_caster); @@ -4682,11 +4665,11 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) { case GAMEOBJECT_TYPE_FISHINGNODE: { - pGameObj->SetFaction(m_caster->getFaction()); - ObjectGuid bobberGuid = pGameObj->GetGUID(); + go->SetFaction(m_caster->getFaction()); + ObjectGuid bobberGuid = go->GetGUID(); // client requires fishing bobber guid in channel object slot 0 to be usable m_caster->SetDynamicStructuredValue(UNIT_DYNAMIC_FIELD_CHANNEL_OBJECTS, 0, &bobberGuid); - m_caster->AddGameObject(pGameObj); // will removed at spell cancel + m_caster->AddGameObject(go); // will removed at spell cancel // end time of range when possible catch fish (FISHING_BOBBER_READY_TIME..GetDuration(m_spellInfo)) // start time == fish-FISHING_BOBBER_READY_TIME (0..GetDuration(m_spellInfo)-FISHING_BOBBER_READY_TIME) @@ -4706,13 +4689,13 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) { if (m_caster->GetTypeId() == TYPEID_PLAYER) { - pGameObj->AddUniqueUse(m_caster->ToPlayer()); - m_caster->AddGameObject(pGameObj); // will be removed at spell cancel + go->AddUniqueUse(m_caster->ToPlayer()); + m_caster->AddGameObject(go); // will be removed at spell cancel } break; } case GAMEOBJECT_TYPE_DUEL_ARBITER: // 52991 - m_caster->AddGameObject(pGameObj); + m_caster->AddGameObject(go); break; case GAMEOBJECT_TYPE_FISHINGHOLE: case GAMEOBJECT_TYPE_CHEST: @@ -4720,22 +4703,22 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) break; } - pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); + go->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0); - pGameObj->SetOwnerGUID(m_caster->GetGUID()); + go->SetOwnerGUID(m_caster->GetGUID()); - //pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()); - pGameObj->SetSpellId(m_spellInfo->Id); + //go->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()); + go->SetSpellId(m_spellInfo->Id); - ExecuteLogEffectSummonObject(effIndex, pGameObj); + ExecuteLogEffectSummonObject(effIndex, go); TC_LOG_DEBUG("spells", "AddObject at SpellEfects.cpp EffectTransmitted"); - //m_caster->AddGameObject(pGameObj); - //m_ObjToDel.push_back(pGameObj); + //m_caster->AddGameObject(go); + //m_ObjToDel.push_back(go); - cMap->AddToMap(pGameObj); + cMap->AddToMap(go); - if (GameObject* linkedTrap = pGameObj->GetLinkedTrap()) + if (GameObject* linkedTrap = go->GetLinkedTrap()) { linkedTrap->CopyPhaseFrom(m_caster); @@ -5491,9 +5474,8 @@ void Spell::EffectCreateAreaTrigger(SpellEffIndex /*effIndex*/) return; int32 duration = GetSpellInfo()->CalcDuration(GetCaster()); - AreaTrigger* areaTrigger = new AreaTrigger(); - if (!areaTrigger->CreateAreaTrigger(effectInfo->MiscValue, GetCaster(), nullptr, GetSpellInfo(), destTarget->GetPosition(), duration, m_SpellVisual, m_castId)) - delete areaTrigger; + + AreaTrigger::CreateAreaTrigger(effectInfo->MiscValue, GetCaster(), nullptr, GetSpellInfo(), destTarget->GetPosition(), duration, m_SpellVisual, m_castId); } void Spell::EffectRemoveTalent(SpellEffIndex /*effIndex*/) |
