diff options
author | megamage <none@none> | 2009-05-02 19:24:22 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-05-02 19:24:22 -0500 |
commit | 122d94494523bd9e7fe8fabbacd11c08dbaba8f8 (patch) | |
tree | 54a52abd8d6bb27f72f9090a4e9fd78d14f69cab | |
parent | abe9b27ee44dd8484b8b8992bba742480f4ab33a (diff) |
*Update summon system.
*Fix the bug that shaman cannot summon fire elemental.
*Fix the bug that totem meters cannot be displayed.
--HG--
branch : trunk
-rw-r--r-- | src/game/Creature.h | 9 | ||||
-rw-r--r-- | src/game/Level2.cpp | 4 | ||||
-rw-r--r-- | src/game/Object.cpp | 5 | ||||
-rw-r--r-- | src/game/Pet.cpp | 2 | ||||
-rw-r--r-- | src/game/Player.cpp | 2 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 13 | ||||
-rw-r--r-- | src/game/TemporarySummon.cpp | 39 | ||||
-rw-r--r-- | src/game/TemporarySummon.h | 18 | ||||
-rw-r--r-- | src/game/Totem.cpp | 26 | ||||
-rw-r--r-- | src/game/Totem.h | 3 | ||||
-rw-r--r-- | src/game/Unit.cpp | 75 | ||||
-rw-r--r-- | src/game/Unit.h | 8 |
12 files changed, 115 insertions, 89 deletions
diff --git a/src/game/Creature.h b/src/game/Creature.h index 2dfc0d8a0cf..36cfee78c5f 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -141,10 +141,11 @@ enum SummonMask { SUMMON_MASK_NONE = 0x00000000, SUMMON_MASK_SUMMON = 0x00000001, - SUMMON_MASK_GUARDIAN = 0x00000002, - SUMMON_MASK_TOTEM = 0x00000004, - SUMMON_MASK_PET = 0x00000008, - SUMMON_MASK_VEHICLE = 0x00000010, + SUMMON_MASK_MINION = 0x00000002, + SUMMON_MASK_GUARDIAN = 0x00000004, + SUMMON_MASK_TOTEM = 0x00000008, + SUMMON_MASK_PET = 0x00000010, + SUMMON_MASK_VEHICLE = 0x00000020, }; // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 136156d44dd..bc83aa7a352 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -1883,7 +1883,7 @@ bool ChatHandler::HandleNpcTameCommand(const char* /*args*/) pet->SetUInt32Value(UNIT_FIELD_LEVEL, level); // caster have pet now - player->SetGuardian(pet, true); + player->SetMinion(pet, true); pet->SavePetToDB(PET_SAVE_AS_CURRENT); player->PetSpellInitialize(); @@ -4406,7 +4406,7 @@ bool ChatHandler::HandleCreatePetCommand(const char* args) // visual effect for levelup pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()); - player->SetGuardian(pet, true); + player->SetMinion(pet, true); pet->SavePetToDB(PET_SAVE_AS_CURRENT); player->PetSpellInitialize(); diff --git a/src/game/Object.cpp b/src/game/Object.cpp index af024de0896..cec9c50b71e 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1614,6 +1614,8 @@ TempSummon *Map::SummonCreature(uint32 entry, float x, float y, float z, float a || properties->Type == SUMMON_TYPE_VEHICLE || properties->Type == SUMMON_TYPE_VEHICLE2) mask = SUMMON_MASK_VEHICLE; + else if(properties->Type == SUMMON_TYPE_MINIPET) + mask = SUMMON_MASK_MINION; } uint32 phase = PHASEMASK_NORMAL, team = 0; @@ -1630,6 +1632,7 @@ TempSummon *Map::SummonCreature(uint32 entry, float x, float y, float z, float a case SUMMON_MASK_SUMMON: summon = new TempSummon (properties, summoner); break; case SUMMON_MASK_GUARDIAN: summon = new Guardian (properties, summoner); break; case SUMMON_MASK_TOTEM: summon = new Totem (properties, summoner); break; + case SUMMON_MASK_MINION: summon = new Minion (properties, summoner); break; default: return NULL; } if(!summon->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), this, phase, entry, team)) @@ -1776,7 +1779,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy pet->SetUInt32Value(UNIT_FIELD_BYTES_1,0); pet->InitStatsForLevel(getLevel()); - SetGuardian(pet, true); + SetMinion(pet, true); switch(petType) { diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 070de6e5899..9f861a91b89 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -262,7 +262,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool } map->Add((Creature*)this); - owner->SetGuardian(this, true); + owner->SetMinion(this, true); m_resetTalentsCost = fields[17].GetUInt32(); m_resetTalentsTime = fields[18].GetUInt64(); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 0510fca231c..2f3b21f8621 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -16524,7 +16524,7 @@ void Player::RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent) break; } - SetGuardian(pet, false); + SetMinion(pet, false); pet->CleanupsBeforeDelete(); pet->AddObjectToRemoveList(); diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 33beae157d5..c3d4b226cb4 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3264,8 +3264,6 @@ void Spell::EffectSummonType(uint32 i) if(!summon || !summon->isTotem()) return; - summon->SetOwner(m_originalCaster, true); - if(damage) // if not spell info, DB values used { summon->SetMaxHealth(damage); @@ -3288,19 +3286,14 @@ void Spell::EffectSummonType(uint32 i) case SUMMON_TYPE_MINIPET: { summon = m_caster->GetMap()->SummonCreature(entry, x, y, z, m_caster->GetOrientation(), properties, duration, m_originalCaster); - if(!summon) + if(!summon || !summon->HasSummonMask(SUMMON_MASK_MINION)) return; - summon->SetOwner(m_originalCaster, true); - summon->SetCreatorGUID(m_originalCaster->GetGUID()); - summon->setFaction(m_originalCaster->getFaction()); - //summon->InitPetCreateSpells(); // e.g. disgusting oozeling has a create spell as summon... summon->SetMaxHealth(1); summon->SetHealth(1); summon->SetLevel(1); - summon->SetReactState(REACT_PASSIVE); summon->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); summon->GetMotionMaster()->MoveTargetedHome(); @@ -3960,7 +3953,7 @@ void Spell::EffectTameCreature(uint32 /*i*/) pet->SetUInt32Value(UNIT_FIELD_LEVEL, level); // caster have pet now - m_caster->SetGuardian(pet, true); + m_caster->SetMinion(pet, true); if(m_caster->GetTypeId() == TYPEID_PLAYER) { @@ -6440,7 +6433,7 @@ void Spell::SummonGuardian(uint32 entry, SummonPropertiesEntry const *properties { Unit *caster = m_originalCaster; if(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()) - caster = caster->GetOwner(); + caster = ((Totem*)caster)->GetOwner(); if(!caster) return; diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index cfbc2a65920..b5ef539ab0c 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -284,37 +284,46 @@ bool TempSummon::SetOwner(Unit *owner, bool apply) return true; } -Guardian::Guardian(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner) -, m_owner(owner), m_bonusdamage(0) +Minion::Minion(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner) +, m_owner(owner) { - m_summonMask |= SUMMON_MASK_GUARDIAN; - InitCharmInfo(); + m_summonMask |= SUMMON_MASK_MINION; } -void Guardian::InitSummon(uint32 duration) +void Minion::InitSummon(uint32 duration) { TempSummon::InitSummon(duration); - SetReactState(REACT_AGGRESSIVE); + SetReactState(REACT_PASSIVE); SetCreatorGUID(m_owner->GetGUID()); setFaction(m_owner->getFaction()); - if(m_owner->GetTypeId() == TYPEID_PLAYER) - { - m_charmInfo->InitCharmCreateSpells(); - //((Player*)m_owner)->CharmSpellInitialize(); - } - - m_owner->SetGuardian(this, true); + m_owner->SetMinion(this, true); } -void Guardian::RemoveFromWorld() +void Minion::RemoveFromWorld() { if(!IsInWorld()) return; - m_owner->SetGuardian(this, false); + m_owner->SetMinion(this, false); TempSummon::RemoveFromWorld(); } +Guardian::Guardian(SummonPropertiesEntry const *properties, Unit *owner) : Minion(properties, owner) +, m_bonusdamage(0) +{ + m_summonMask |= SUMMON_MASK_GUARDIAN; + InitCharmInfo(); +} + +void Guardian::InitSummon(uint32 duration) +{ + if(m_owner->GetTypeId() == TYPEID_PLAYER) + m_charmInfo->InitCharmCreateSpells(); + + Minion::InitSummon(duration); + + SetReactState(REACT_AGGRESSIVE); +} diff --git a/src/game/TemporarySummon.h b/src/game/TemporarySummon.h index c4f24d93273..16980b30a8d 100644 --- a/src/game/TemporarySummon.h +++ b/src/game/TemporarySummon.h @@ -46,21 +46,27 @@ class TempSummon : public Creature uint64 m_summonerGUID; }; -class Guardian : public TempSummon +class Minion : public TempSummon { public: - Guardian(SummonPropertiesEntry const *properties, Unit *owner); - bool Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 pet_number); + Minion(SummonPropertiesEntry const *properties, Unit *owner); void InitSummon(uint32 duration); void RemoveFromWorld(); + Unit *GetOwner() { return m_owner; } + protected: + Unit *m_owner; +}; + +class Guardian : public Minion +{ + public: + Guardian(SummonPropertiesEntry const *properties, Unit *owner); + void InitSummon(uint32 duration); bool InitStatsForLevel(uint32 level); int32 GetBonusDamage() { return m_bonusdamage; } void SetBonusDamage(int32 damage) { m_bonusdamage = damage; } - - Unit *GetOwner() { return m_owner; } protected: - Unit *m_owner; int32 m_bonusdamage; }; diff --git a/src/game/Totem.cpp b/src/game/Totem.cpp index 1b23b40fa37..5f1a044d4df 100644 --- a/src/game/Totem.cpp +++ b/src/game/Totem.cpp @@ -26,7 +26,7 @@ #include "ObjectMgr.h" #include "SpellMgr.h" -Totem::Totem(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner) +Totem::Totem(SummonPropertiesEntry const *properties, Unit *owner) : Minion(properties, owner) { m_summonMask |= SUMMON_MASK_TOTEM; m_duration = 0; @@ -35,8 +35,7 @@ Totem::Totem(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon( void Totem::Update( uint32 time ) { - Unit *owner = GetOwner(); - if (!owner || !owner->isAlive() || !isAlive()) + if (!m_owner->isAlive() || !isAlive()) { UnSummon(); // remove self return; @@ -55,15 +54,13 @@ void Totem::Update( uint32 time ) void Totem::InitSummon(uint32 duration) { - Unit *owner = GetOwner(); - if(!owner) - return; + Minion::InitSummon(duration); CreatureInfo const *cinfo = GetCreatureInfo(); - if (owner->GetTypeId()==TYPEID_PLAYER && cinfo) + if (m_owner->GetTypeId()==TYPEID_PLAYER && cinfo) { uint32 modelid = 0; - if(((Player*)owner)->GetTeam() == HORDE) + if(((Player*)m_owner)->GetTeam() == HORDE) { if(cinfo->Modelid_H1) modelid = cinfo->Modelid_H1; @@ -80,7 +77,7 @@ void Totem::InitSummon(uint32 duration) if (modelid) SetDisplayId(modelid); else - sLog.outErrorDb("Totem::Summon: Missing modelid information for entry %u, team %u, totem will use default values.",GetEntry(),((Player*)owner)->GetTeam()); + sLog.outErrorDb("Totem::Summon: Missing modelid information for entry %u, team %u, totem will use default values.",GetEntry(),((Player*)m_owner)->GetTeam()); } WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8); @@ -95,9 +92,7 @@ void Totem::InitSummon(uint32 duration) m_duration = duration; - SetCreatorGUID(owner->GetGUID()); - setFaction(owner->getFaction()); - SetLevel(owner->getLevel()); + SetLevel(m_owner->getLevel()); // Get spell casted by totem SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell()); @@ -107,8 +102,6 @@ void Totem::InitSummon(uint32 duration) if (GetSpellCastTime(totemSpell)) m_type = TOTEM_ACTIVE; } - - TempSummon::InitSummon(duration); } void Totem::UnSummon() @@ -154,11 +147,6 @@ void Totem::UnSummon() AddObjectToRemoveList(); } -Unit *Totem::GetOwner() -{ - return GetSummoner(); -} - bool Totem::IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const { // TODO: possibly all negative auras immuned? diff --git a/src/game/Totem.h b/src/game/Totem.h index 4738e5d00b7..4287ddc50e6 100644 --- a/src/game/Totem.h +++ b/src/game/Totem.h @@ -31,7 +31,7 @@ enum TotemType #define SENTRY_TOTEM_ENTRY 3968 -class Totem : public TempSummon +class Totem : public Minion { public: explicit Totem(SummonPropertiesEntry const *properties, Unit *owner); @@ -41,7 +41,6 @@ class Totem : public TempSummon void UnSummon(); uint32 GetSpell() const { return m_spells[0]; } uint32 GetTotemDuration() const { return m_duration; } - Unit *GetOwner(); TotemType GetTotemType() const { return m_type; } bool UpdateStats(Stats /*stat*/) { return true; } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 3142e742dcf..4eac618dd18 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8090,6 +8090,21 @@ Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() const return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL; } +Minion *Unit::GetFirstMinion() const +{ + if(uint64 pet_guid = GetMinionGUID()) + { + if(Creature* pet = ObjectAccessor::GetCreatureOrPetOrVehicle(*this, pet_guid)) + if(pet->HasSummonMask(SUMMON_MASK_MINION)) + return (Minion*)pet; + + sLog.outError("Unit::GetFirstMinion: Minion %u not exist.",GUID_LOPART(pet_guid)); + const_cast<Unit*>(this)->SetMinionGUID(0); + } + + return NULL; +} + Guardian* Unit::GetGuardianPet() const { if(uint64 pet_guid = GetPetGUID()) @@ -8098,7 +8113,7 @@ Guardian* Unit::GetGuardianPet() const if(pet->HasSummonMask(SUMMON_MASK_GUARDIAN)) return (Guardian*)pet; - sLog.outError("Unit::GetGuardianPet: Pet %u not exist.",GUID_LOPART(pet_guid)); + sLog.outError("Unit::GetGuardianPet: Guardian %u not exist.",GUID_LOPART(pet_guid)); const_cast<Unit*>(this)->SetPetGUID(0); } @@ -8119,44 +8134,54 @@ Unit* Unit::GetCharm() const return NULL; } -void Unit::SetGuardian(Guardian* guardian, bool apply) +void Unit::SetMinion(Minion *minion, bool apply) { - sLog.outDebug("SetGuardian %u for %u, apply %u", guardian->GetEntry(), GetEntry(), apply); + sLog.outDebug("SetMinion %u for %u, apply %u", minion->GetEntry(), GetEntry(), apply); if(apply) { - if(!guardian->SetOwner(this, true)) + if(!minion->SetOwner(this, true)) return; - m_Controlled.insert(guardian); + m_Controlled.insert(minion); - if(guardian->isPet() || guardian->m_Properties && guardian->m_Properties->Category == SUMMON_CATEGORY_PET) + // Can only have one pet. If a new one is summoned, dismiss the old one. + if(minion->isPet() || minion->m_Properties && minion->m_Properties->Category == SUMMON_CATEGORY_PET) { if(Guardian* oldPet = GetGuardianPet()) { - if(oldPet != guardian && (oldPet->isPet() || guardian->isPet() || oldPet->GetEntry() != guardian->GetEntry())) + if(oldPet != minion && (oldPet->isPet() || minion->isPet() || oldPet->GetEntry() != minion->GetEntry())) { - // remove existing guardian pet + // remove existing minion pet if(oldPet->isPet()) ((Pet*)oldPet)->Remove(PET_SAVE_AS_CURRENT); else oldPet->UnSummon(); - SetPetGUID(guardian->GetGUID()); - SetGuardianGUID(0); + SetPetGUID(minion->GetGUID()); + SetMinionGUID(0); } } else { - SetPetGUID(guardian->GetGUID()); - SetGuardianGUID(0); + SetPetGUID(minion->GetGUID()); + SetMinionGUID(0); } } - if(AddUInt64Value(UNIT_FIELD_SUMMON, guardian->GetGUID())) + // Check priority. + if(Minion *oldMinion = GetFirstMinion()) + { + if(minion->HasSummonMask(SUMMON_MASK_GUARDIAN) + && !oldMinion->HasSummonMask(SUMMON_MASK_GUARDIAN)) + SetMinionGUID(0); + } + + // Set first minion + if(AddUInt64Value(UNIT_FIELD_SUMMON, minion->GetGUID())) { - if(GetTypeId() == TYPEID_PLAYER && !GetCharmGUID()) + if(GetTypeId() == TYPEID_PLAYER && !GetCharmGUID() && minion->HasSummonMask(SUMMON_MASK_GUARDIAN)) { - if(guardian->isPet()) + if(minion->isPet()) ((Player*)this)->PetSpellInitialize(); else ((Player*)this)->CharmSpellInitialize(); @@ -8165,28 +8190,28 @@ void Unit::SetGuardian(Guardian* guardian, bool apply) // FIXME: hack, speed must be set only at follow if(HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP)) - guardian->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + minion->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); - if(GetTypeId() == TYPEID_PLAYER && guardian->HasSummonMask(SUMMON_MASK_PET)) + if(GetTypeId() == TYPEID_PLAYER && minion->HasSummonMask(SUMMON_MASK_PET)) for(int i = 0; i < MAX_MOVE_TYPE; ++i) - guardian->SetSpeed(UnitMoveType(i), m_speed_rate[i], true); + minion->SetSpeed(UnitMoveType(i), m_speed_rate[i], true); } else { - if(!guardian->SetOwner(this, false)) + if(!minion->SetOwner(this, false)) return; - m_Controlled.erase(guardian); + m_Controlled.erase(minion); - if(guardian->isPet() || guardian->m_Properties && guardian->m_Properties->Category == SUMMON_CATEGORY_PET) + if(minion->isPet() || minion->m_Properties && minion->m_Properties->Category == SUMMON_CATEGORY_PET) { - if(GetPetGUID() == guardian->GetGUID()) + if(GetPetGUID() == minion->GetGUID()) SetPetGUID(0); } - if(RemoveUInt64Value(UNIT_FIELD_SUMMON, guardian->GetGUID())) + if(RemoveUInt64Value(UNIT_FIELD_SUMMON, minion->GetGUID())) { - //Check if there is another guardian + //Check if there is another minion for(ControlList::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr) { if(GetCharmGUID() == (*itr)->GetGUID()) @@ -8197,7 +8222,7 @@ void Unit::SetGuardian(Guardian* guardian, bool apply) if(AddUInt64Value(UNIT_FIELD_SUMMON, (*itr)->GetGUID())) { //show another pet bar if there is no charm bar - if(GetTypeId() == TYPEID_PLAYER && !GetCharmGUID()) + if(GetTypeId() == TYPEID_PLAYER && !GetCharmGUID() && ((Creature*)(*itr))->HasSummonMask(SUMMON_MASK_GUARDIAN)) { if(((Creature*)(*itr))->isPet()) ((Player*)this)->PetSpellInitialize(); diff --git a/src/game/Unit.h b/src/game/Unit.h index 82c7eb88695..8100da3358e 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -313,6 +313,7 @@ class Item; class Pet; class Path; class PetAura; +class Minion; class Guardian; class UnitAI; class Transport; @@ -1220,8 +1221,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); } uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); } void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); } - uint64 GetGuardianGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); } - void SetGuardianGUID(uint64 guid) { SetUInt64Value(UNIT_FIELD_SUMMON, guid); } + uint64 GetMinionGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); } + void SetMinionGUID(uint64 guid) { SetUInt64Value(UNIT_FIELD_SUMMON, guid); } uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); } void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); } uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); } @@ -1242,6 +1243,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject Unit* GetOwner() const; Guardian *GetGuardianPet() const; + Minion *GetFirstMinion() const; Unit* GetCharmer() const; Unit* GetCharm() const; Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); } @@ -1254,7 +1256,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject } Player* GetCharmerOrOwnerPlayerOrPlayerItself() const; - void SetGuardian(Guardian* target, bool apply); + void SetMinion(Minion *minion, bool apply); void SetCharm(Unit* target, bool apply); Unit* GetNextRandomRaidMemberOrPet(float radius); void SetCharmedOrPossessedBy(Unit* charmer, bool possess); |