aboutsummaryrefslogtreecommitdiff
path: root/src/game/TemporarySummon.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/game/TemporarySummon.cpp
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'src/game/TemporarySummon.cpp')
-rw-r--r--src/game/TemporarySummon.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp
index 05ae270dabd..0b31eea9707 100644
--- a/src/game/TemporarySummon.cpp
+++ b/src/game/TemporarySummon.cpp
@@ -17,11 +17,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#include "Log.h"
#include "ObjectAccessor.h"
#include "CreatureAI.h"
#include "ObjectMgr.h"
#include "TemporarySummon.h"
+
TempSummon::TempSummon(SummonPropertiesEntry const *properties, Unit *owner) :
Creature(), m_type(TEMPSUMMON_MANUAL_DESPAWN), m_timer(0), m_lifetime(0)
, m_Properties(properties)
@@ -29,13 +31,16 @@ Creature(), m_type(TEMPSUMMON_MANUAL_DESPAWN), m_timer(0), m_lifetime(0)
m_summonerGUID = owner ? owner->GetGUID() : 0;
m_unitTypeMask |= UNIT_MASK_SUMMON;
}
+
Unit* TempSummon::GetSummoner() const
{
return m_summonerGUID ? ObjectAccessor::GetUnit(*this, m_summonerGUID) : NULL;
}
+
void TempSummon::Update( uint32 diff )
{
Creature::Update(diff);
+
if (m_deathState == DEAD)
{
UnSummon();
@@ -52,6 +57,7 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
m_timer -= diff;
break;
}
@@ -64,12 +70,15 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
m_timer -= diff;
}
else if (m_timer != m_lifetime)
m_timer = m_lifetime;
+
break;
}
+
case TEMPSUMMON_CORPSE_TIMED_DESPAWN:
{
if ( m_deathState == CORPSE)
@@ -79,6 +88,7 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
m_timer -= diff;
}
break;
@@ -91,6 +101,7 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
break;
}
case TEMPSUMMON_DEAD_DESPAWN:
@@ -110,6 +121,7 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
if (!isInCombat())
{
if (m_timer <= diff)
@@ -132,6 +144,7 @@ void TempSummon::Update( uint32 diff )
UnSummon();
return;
}
+
if (!isInCombat() && isAlive() )
{
if (m_timer <= diff)
@@ -152,14 +165,19 @@ void TempSummon::Update( uint32 diff )
break;
}
}
+
void TempSummon::InitStats(uint32 duration)
{
assert(!isPet());
+
m_timer = duration;
m_lifetime = duration;
+
if(m_type == TEMPSUMMON_MANUAL_DESPAWN)
m_type = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
+
Unit *owner = GetSummoner();
+
if(owner && isTrigger() && m_spells[0])
{
setFaction(owner->getFaction());
@@ -167,8 +185,10 @@ void TempSummon::InitStats(uint32 duration)
if(owner->GetTypeId() == TYPEID_PLAYER)
m_ControlledByPlayer = true;
}
+
if(!m_Properties)
return;
+
if(owner)
{
if(uint32 slot = m_Properties->Slot)
@@ -182,11 +202,13 @@ void TempSummon::InitStats(uint32 duration)
owner->m_SummonSlot[slot] = GetGUID();
}
}
+
if(m_Properties->Faction)
setFaction(m_Properties->Faction);
else if(IsVehicle()) // properties should be vehicle
setFaction(owner->getFaction());
}
+
void TempSummon::InitSummon()
{
Unit* owner = GetSummoner();
@@ -198,10 +220,12 @@ void TempSummon::InitSummon()
AI()->IsSummonedBy(owner);
}
}
+
void TempSummon::SetTempSummonType(TempSummonType type)
{
m_type = type;
}
+
void TempSummon::UnSummon()
{
//assert(!isPet());
@@ -211,15 +235,19 @@ void TempSummon::UnSummon()
assert(!IsInWorld());
return;
}
+
Unit* owner = GetSummoner();
if(owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->IsAIEnabled)
((Creature*)owner)->AI()->SummonedCreatureDespawn(this);
+
AddObjectToRemoveList();
}
+
void TempSummon::RemoveFromWorld()
{
if(!IsInWorld())
return;
+
if(m_Properties)
{
if(uint32 slot = m_Properties->Slot)
@@ -231,13 +259,17 @@ void TempSummon::RemoveFromWorld()
}
}
}
+
//if(GetOwnerGUID())
// sLog.outError("Unit %u has owner guid when removed from world", GetEntry());
+
Creature::RemoveFromWorld();
}
+
void TempSummon::SaveToDB()
{
}
+
Minion::Minion(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner)
, m_owner(owner)
{
@@ -245,25 +277,33 @@ Minion::Minion(SummonPropertiesEntry const *properties, Unit *owner) : TempSummo
m_unitTypeMask |= UNIT_MASK_MINION;
m_followAngle = PET_FOLLOW_ANGLE;
}
+
void Minion::InitStats(uint32 duration)
{
TempSummon::InitStats(duration);
+
SetReactState(REACT_PASSIVE);
+
SetCreatorGUID(m_owner->GetGUID());
setFaction(m_owner->getFaction());
+
m_owner->SetMinion(this, true);
}
+
void Minion::RemoveFromWorld()
{
if(!IsInWorld())
return;
+
m_owner->SetMinion(this, false);
TempSummon::RemoveFromWorld();
}
+
bool Minion::IsGuardianPet() const
{
return isPet() || m_Properties && m_Properties->Category == SUMMON_CATEGORY_PET;
}
+
Guardian::Guardian(SummonPropertiesEntry const *properties, Unit *owner) : Minion(properties, owner)
, m_bonusdamage(0)
{
@@ -274,40 +314,50 @@ Guardian::Guardian(SummonPropertiesEntry const *properties, Unit *owner) : Minio
InitCharmInfo();
}
}
+
void Guardian::InitStats(uint32 duration)
{
Minion::InitStats(duration);
+
InitStatsForLevel(m_owner->getLevel());
+
if(m_owner->GetTypeId() == TYPEID_PLAYER && HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
m_charmInfo->InitCharmCreateSpells();
+
SetReactState(REACT_AGGRESSIVE);
}
+
void Guardian::InitSummon()
{
TempSummon::InitSummon();
+
if(m_owner->GetTypeId() == TYPEID_PLAYER
&& m_owner->GetMinionGUID() == GetGUID()
&& !m_owner->GetCharmGUID())
((Player*)m_owner)->CharmSpellInitialize();
}
+
Puppet::Puppet(SummonPropertiesEntry const *properties, Unit *owner) : Minion(properties, owner)
{
assert(owner->GetTypeId() == TYPEID_PLAYER);
m_owner = (Player*)owner;
m_unitTypeMask |= UNIT_MASK_PUPPET;
}
+
void Puppet::InitStats(uint32 duration)
{
Minion::InitStats(duration);
SetLevel(m_owner->getLevel());
SetReactState(REACT_PASSIVE);
}
+
void Puppet::InitSummon()
{
Minion::InitSummon();
if (!SetCharmedBy(m_owner, CHARM_TYPE_POSSESS))
assert(false);
}
+
void Puppet::Update(uint32 time)
{
Minion::Update(time);
@@ -321,10 +371,12 @@ void Puppet::Update(uint32 time)
}
}
}
+
void Puppet::RemoveFromWorld()
{
if(!IsInWorld())
return;
+
RemoveCharmedBy(NULL);
Minion::RemoveFromWorld();
}