diff options
Diffstat (limited to 'src/game/TemporarySummon.cpp')
-rw-r--r-- | src/game/TemporarySummon.cpp | 162 |
1 files changed, 125 insertions, 37 deletions
diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index 77fbfa439e5..07ab36c40d8 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -22,12 +22,13 @@ #include "Log.h" #include "ObjectAccessor.h" #include "CreatureAI.h" +#include "ObjectMgr.h" -TempSummon::TempSummon( uint64 summoner ) : -Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner) -, m_properties(NULL) +TempSummon::TempSummon(SummonPropertiesEntry const *properties, Unit *owner) : +Creature(), m_type(TEMPSUMMON_MANUAL_DESPAWN), m_timer(0), m_lifetime(0) +, m_Properties(properties), m_summonerGUID(owner->GetGUID()) { - m_isSummon = true; + m_summonMask |= SUMMON_MASK_SUMMON; } void TempSummon::Update( uint32 diff ) @@ -159,66 +160,153 @@ void TempSummon::Update( uint32 diff ) Creature::Update( diff ); } -void TempSummon::Summon(TempSummonType type, uint32 lifetime) +void TempSummon::InitSummon(uint32 duration) { - m_type = type; - m_timer = lifetime; - m_lifetime = lifetime; + m_timer = duration; + m_lifetime = duration; - GetMap()->Add((Creature*)this); + if(m_type == TEMPSUMMON_MANUAL_DESPAWN) + m_type = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN; AIM_Initialize(); + + if(!m_Properties) + return; + + Unit* owner = GetSummoner(); + if(uint32 slot = m_Properties->Slot) + { + --slot; + if(owner) + { + if(owner->m_TotemSlot[slot] && owner->m_TotemSlot[slot] != GetGUID()) + { + Creature *OldTotem = ObjectAccessor::GetCreature(*this, owner->m_TotemSlot[slot]); + if(OldTotem && OldTotem->isSummon()) + ((TempSummon*)OldTotem)->UnSummon(); + } + owner->m_TotemSlot[slot] = GetGUID(); + } + } } -void TempSummon::UnSummon() +void TempSummon::SetTempSummonType(TempSummonType type) { - CleanupsBeforeDelete(); - AddObjectToRemoveList(); + m_type = type; +} +void TempSummon::UnSummon() +{ Unit* owner = GetSummoner(); if(owner) { if(owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->IsAIEnabled) ((Creature*)owner)->AI()->SummonedCreatureDespawn(this); - if(!m_properties) - return; - - if(uint32 slot = m_properties->Slot) + if(m_Properties) { - --slot; - owner->m_TotemSlot[slot] = 0; + if(uint32 slot = m_Properties->Slot) + { + --slot; + if(owner->m_TotemSlot[slot] = GetGUID()) + owner->m_TotemSlot[slot] = 0; + } } } + + CleanupsBeforeDelete(); + AddObjectToRemoveList(); } -void TempSummon::SetSummonProperties(SummonPropertiesEntry const *properties) +void TempSummon::SaveToDB() { - if(!properties) - return; +} + +Guardian::Guardian(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner) +, m_owner(owner) +{ + m_summonMask |= SUMMON_MASK_GUARDIAN; + InitCharmInfo(); +} + +bool Guardian::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 pet_number) +{ + SetMapId(map->GetId()); + SetInstanceId(map->GetInstanceId()); + SetPhaseMask(phaseMask,false); + + Object::_Create(guidlow, pet_number, HIGHGUID_PET); + + m_DBTableGuid = guidlow; + m_originalEntry = Entry; - m_properties = properties; + if(!InitEntry(Entry)) + return false; - if(uint32 slot = m_properties->Slot) + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE); + + return true; +} + +void Guardian::InitSummon(uint32 duration) +{ + TempSummon::InitSummon(duration); + + SetReactState(REACT_AGGRESSIVE); + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0); + + SetOwnerGUID(m_owner->GetGUID()); + SetCreatorGUID(m_owner->GetGUID()); + SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, m_owner->getFaction()); + m_owner->AddGuardian(this); + SetUInt32Value(UNIT_FIELD_BYTES_0, 2048); + + if(m_owner->GetTypeId() == TYPEID_PLAYER) { - --slot; - Unit* owner = GetSummoner(); - if(owner) - { - if(owner->m_TotemSlot[slot] && owner->m_TotemSlot[slot] != GetGUID()) - { - Creature *OldTotem = ObjectAccessor::GetCreature(*this, owner->m_TotemSlot[slot]); - if(OldTotem && OldTotem->isSummon()) - ((TempSummon*)OldTotem)->UnSummon(); - } - owner->m_TotemSlot[slot] = GetGUID(); - } + m_owner->SetUInt64Value(UNIT_FIELD_SUMMON, GetGUID()); + m_charmInfo->InitCharmCreateSpells(); + //charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true); + ((Player*)m_owner)->CharmSpellInitialize(); } +} - AIM_Initialize(); +void Guardian::InitStatsForLevel(uint32 petlevel) +{ + SetLevel(petlevel); + switch(GetEntry()) + { + case 1964: //force of nature + SetCreateHealth(30 + 30*petlevel); + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 2.5f - (petlevel / 2))); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 2.5f + (petlevel / 2))); + break; + case 15352: //earth elemental 36213 + SetCreateHealth(100 + 120*petlevel); + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4))); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4))); + break; + case 15438: //fire elemental + SetCreateHealth(40*petlevel); + SetCreateMana(28 + 10*petlevel); + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 4 - petlevel)); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 4 + petlevel)); + break; + default: + SetCreateMana(28 + 10*petlevel); + SetCreateHealth(28 + 30*petlevel); + // FIXME: this is wrong formula, possible each guardian pet have own damage formula + //these formula may not be correct; however, it is designed to be close to what it should be + //this makes dps 0.5 of pets level + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4))); + //damage range is then petlevel / 2 + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4))); + break; + } } -void TempSummon::SaveToDB() +void Guardian::UnSummon() { + m_owner->m_Guardians.erase(GetGUID()); + TempSummon::UnSummon(); } |