diff options
author | Vincent_Michael <Vincent_Michael@gmx.de> | 2013-03-21 22:00:01 +0100 |
---|---|---|
committer | Vincent_Michael <Vincent_Michael@gmx.de> | 2013-03-21 22:00:01 +0100 |
commit | 15a249e28c3a6fbd44c964e48052651580caceb7 (patch) | |
tree | 98b076e969b482d7914f37040efcb595bbca556b /src | |
parent | 41822a8ed392357aed43e52135a51456b0a42f96 (diff) | |
parent | d05aac03ae4b4b9df765ed89adef25235c9639e9 (diff) |
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
Conflicts:
src/server/game/Entities/Pet/Pet.cpp
src/server/game/Entities/Pet/Pet.h
src/server/scripts/EasternKingdoms/zone_burning_steppes.cpp
src/server/scripts/EasternKingdoms/zone_stormwind_city.cpp
src/server/scripts/Kalimdor/zone_azshara.cpp
Diffstat (limited to 'src')
56 files changed, 1116 insertions, 503 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 4200c086275..da0551390d1 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -24,26 +24,28 @@ struct TSpellSummary void SummonList::DoZoneInCombat(uint32 entry) { - for (iterator i = begin(); i != end();) + for (StorageType::iterator i = storage_.begin(); i != storage_.end();) { Creature* summon = Unit::GetCreature(*me, *i); ++i; if (summon && summon->IsAIEnabled - && (!entry || summon->GetEntry() == entry)) + && (!entry || summon->GetEntry() == entry)) + { summon->AI()->DoZoneInCombat(); + } } } void SummonList::DespawnEntry(uint32 entry) { - for (iterator i = begin(); i != end();) + for (StorageType::iterator i = storage_.begin(); i != storage_.end();) { Creature* summon = Unit::GetCreature(*me, *i); if (!summon) - erase(i++); + i = storage_.erase(i); else if (summon->GetEntry() == entry) { - erase(i++); + i = storage_.erase(i); summon->DespawnOrUnsummon(); } else @@ -53,33 +55,29 @@ void SummonList::DespawnEntry(uint32 entry) void SummonList::DespawnAll() { - while (!empty()) + while (!storage_.empty()) { - Creature* summon = Unit::GetCreature(*me, *begin()); - if (!summon) - erase(begin()); - else - { - erase(begin()); + Creature* summon = Unit::GetCreature(*me, storage_.front()); + storage_.pop_front(); + if (summon) summon->DespawnOrUnsummon(); - } } } void SummonList::RemoveNotExisting() { - for (iterator i = begin(); i != end();) + for (StorageType::iterator i = storage_.begin(); i != storage_.end();) { if (Unit::GetCreature(*me, *i)) ++i; else - erase(i++); + i = storage_.erase(i); } } bool SummonList::HasEntry(uint32 entry) const { - for (const_iterator i = begin(); i != end(); ++i) + for (StorageType::const_iterator i = storage_.begin(); i != storage_.end(); ++i) { Creature* summon = Unit::GetCreature(*me, *i); if (summon && summon->GetEntry() == entry) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index 5098d353cac..8634355b974 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -24,39 +24,93 @@ #include "CreatureAIImpl.h" #include "InstanceScript.h" -#define CAST_PLR(a) (dynamic_cast<Player*>(a)) -#define CAST_CRE(a) (dynamic_cast<Creature*>(a)) #define CAST_AI(a, b) (dynamic_cast<a*>(b)) class InstanceScript; -class SummonList : public std::list<uint64> +class SummonList { - public: - explicit SummonList(Creature* creature) : me(creature) {} - void Summon(Creature* summon) { push_back(summon->GetGUID()); } - void Despawn(Creature* summon) { remove(summon->GetGUID()); } - void DespawnEntry(uint32 entry); - void DespawnAll(); +public: + typedef std::list<uint64> StorageType; + typedef StorageType::iterator iterator; + typedef StorageType::const_iterator const_iterator; + typedef StorageType::size_type size_type; + typedef StorageType::value_type value_type; + + explicit SummonList(Creature* creature) + : me(creature) + { } + + // And here we see a problem of original inheritance approach. People started + // to exploit presence of std::list members, so I have to provide wrappers + + iterator begin() + { + return storage_.begin(); + } + + const_iterator begin() const + { + return storage_.begin(); + } - template <class Predicate> void DoAction(int32 info, Predicate& predicate, uint16 max = 0) + iterator end() + { + return storage_.end(); + } + + const_iterator end() const + { + return storage_.end(); + } + + iterator erase(iterator i) + { + return storage_.erase(i); + } + + bool empty() const + { + return storage_.empty(); + } + + size_type size() const + { + return storage_.size(); + } + + void Summon(Creature const* summon) { storage_.push_back(summon->GetGUID()); } + void Despawn(Creature const* summon) { storage_.remove(summon->GetGUID()); } + void DespawnEntry(uint32 entry); + void DespawnAll(); + + template <typename T> + void DespawnIf(T const &predicate) + { + storage_.remove_if(predicate); + } + + template <class Predicate> + void DoAction(int32 info, Predicate& predicate, uint16 max = 0) + { + // We need to use a copy of SummonList here, otherwise original SummonList would be modified + StorageType listCopy = storage_; + Trinity::Containers::RandomResizeList<uint64, Predicate>(listCopy, predicate, max); + for (StorageType::iterator i = listCopy.begin(); i != listCopy.end(); ) { - // We need to use a copy of SummonList here, otherwise original SummonList would be modified - std::list<uint64> listCopy = *this; - Trinity::Containers::RandomResizeList<uint64, Predicate>(listCopy, predicate, max); - for (iterator i = listCopy.begin(); i != listCopy.end(); ) - { - Creature* summon = Unit::GetCreature(*me, *i++); - if (summon && summon->IsAIEnabled) - summon->AI()->DoAction(info); - } + Creature* summon = Unit::GetCreature(*me, *i++); + if (summon && summon->IsAIEnabled) + summon->AI()->DoAction(info); } + } - void DoZoneInCombat(uint32 entry = 0); - void RemoveNotExisting(); - bool HasEntry(uint32 entry) const; - private: - Creature* me; + void DoZoneInCombat(uint32 entry = 0); + void RemoveNotExisting(); + bool HasEntry(uint32 entry) const; + +private: + Creature* me; + StorageType storage_; }; class EntryCheckPredicate diff --git a/src/server/game/Entities/Creature/TemporarySummon.cpp b/src/server/game/Entities/Creature/TemporarySummon.cpp index eb7c0e7da6c..d23af7e215f 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.cpp +++ b/src/server/game/Entities/Creature/TemporarySummon.cpp @@ -37,6 +37,11 @@ Unit* TempSummon::GetSummoner() const return m_summonerGUID ? ObjectAccessor::GetUnit(*this, m_summonerGUID) : NULL; } +Creature* TempSummon::GetSummonerCreatureBase() const +{ + return m_summonerGUID ? ObjectAccessor::GetCreature(*this, m_summonerGUID) : NULL; +} + void TempSummon::Update(uint32 diff) { Creature::Update(diff); @@ -274,8 +279,8 @@ void TempSummon::RemoveFromWorld() Creature::RemoveFromWorld(); } -Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : TempSummon(properties, owner, isWorldObject) -, m_owner(owner) +Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) + : TempSummon(properties, owner, isWorldObject), m_owner(owner) { ASSERT(m_owner); m_unitTypeMask |= UNIT_MASK_MINION; @@ -288,10 +293,10 @@ void Minion::InitStats(uint32 duration) SetReactState(REACT_PASSIVE); - SetCreatorGUID(m_owner->GetGUID()); - setFaction(m_owner->getFaction()); + SetCreatorGUID(GetOwner()->GetGUID()); + setFaction(GetOwner()->getFaction()); - m_owner->SetMinion(this, true); + GetOwner()->SetMinion(this, true); } void Minion::RemoveFromWorld() @@ -299,7 +304,7 @@ void Minion::RemoveFromWorld() if (!IsInWorld()) return; - m_owner->SetMinion(this, false); + GetOwner()->SetMinion(this, false); TempSummon::RemoveFromWorld(); } @@ -324,9 +329,9 @@ void Guardian::InitStats(uint32 duration) { Minion::InitStats(duration); - InitStatsForLevel(m_owner->getLevel()); + InitStatsForLevel(GetOwner()->getLevel()); - if (m_owner->GetTypeId() == TYPEID_PLAYER && HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN)) + if (GetOwner()->GetTypeId() == TYPEID_PLAYER && HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN)) m_charmInfo->InitCharmCreateSpells(); SetReactState(REACT_AGGRESSIVE); @@ -336,30 +341,32 @@ void Guardian::InitSummon() { TempSummon::InitSummon(); - if (m_owner->GetTypeId() == TYPEID_PLAYER - && m_owner->GetMinionGUID() == GetGUID() - && !m_owner->GetCharmGUID()) - m_owner->ToPlayer()->CharmSpellInitialize(); + if (GetOwner()->GetTypeId() == TYPEID_PLAYER + && GetOwner()->GetMinionGUID() == GetGUID() + && !GetOwner()->GetCharmGUID()) + { + GetOwner()->ToPlayer()->CharmSpellInitialize(); + } } -Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false) //maybe true? +Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner) + : Minion(properties, owner, false) //maybe true? { - ASSERT(owner->GetTypeId() == TYPEID_PLAYER); - m_owner = (Player*)owner; + ASSERT(m_owner->GetTypeId() == TYPEID_PLAYER); m_unitTypeMask |= UNIT_MASK_PUPPET; } void Puppet::InitStats(uint32 duration) { Minion::InitStats(duration); - SetLevel(m_owner->getLevel()); + SetLevel(GetOwner()->getLevel()); SetReactState(REACT_PASSIVE); } void Puppet::InitSummon() { Minion::InitSummon(); - if (!SetCharmedBy(m_owner, CHARM_TYPE_POSSESS)) + if (!SetCharmedBy(GetOwner(), CHARM_TYPE_POSSESS)) ASSERT(false); } diff --git a/src/server/game/Entities/Creature/TemporarySummon.h b/src/server/game/Entities/Creature/TemporarySummon.h index a28874c51e7..46f5c1300a4 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.h +++ b/src/server/game/Entities/Creature/TemporarySummon.h @@ -50,6 +50,7 @@ class TempSummon : public Creature void SetTempSummonType(TempSummonType type); void SaveToDB(uint32 /*mapid*/, uint8 /*spawnMask*/, uint32 /*phaseMask*/) {} Unit* GetSummoner() const; + Creature* GetSummonerCreatureBase() const; uint64 GetSummonerGUID() const { return m_summonerGUID; } TempSummonType const& GetSummonType() { return m_type; } uint32 GetTimer() { return m_timer; } @@ -68,7 +69,7 @@ class Minion : public TempSummon Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject); void InitStats(uint32 duration); void RemoveFromWorld(); - Unit* GetOwner() { return m_owner; } + Unit* GetOwner() const { return m_owner; } float GetFollowAngle() const { return m_followAngle; } void SetFollowAngle(float angle) { m_followAngle = angle; } bool IsPetGhoul() const {return GetEntry() == 26125;} // Ghoul may be guardian or pet @@ -96,7 +97,7 @@ class Guardian : public Minion void UpdateAttackPowerAndDamage(bool ranged = false); void UpdateDamagePhysical(WeaponAttackType attType); - int32 GetBonusDamage() { return m_bonusSpellDamage; } + int32 GetBonusDamage() const { return m_bonusSpellDamage; } void SetBonusDamage(int32 damage); protected: int32 m_bonusSpellDamage; @@ -111,8 +112,6 @@ class Puppet : public Minion void InitSummon(); void Update(uint32 time); void RemoveFromWorld(); - protected: - Player* m_owner; }; class ForcedUnsummonDelayEvent : public BasicEvent diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 77e8093b861..2d598d78236 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -36,10 +36,11 @@ #define PET_XP_FACTOR 0.05f Pet::Pet(Player* owner, PetType type) : Guardian(NULL, owner, true), - m_usedTalentCount(0), m_removed(false), m_owner(owner), - m_petType(type), m_duration(0), + m_usedTalentCount(0), m_removed(false), m_petType(type), m_duration(0), m_auraRaidUpdateMask(0), m_loading(false), m_declinedname(NULL) { + ASSERT(m_owner->GetTypeId() == TYPEID_PLAYER); + m_unitTypeMask |= UNIT_MASK_PET; if (type == HUNTER_PET) m_unitTypeMask |= UNIT_MASK_HUNTER_PET; @@ -93,7 +94,7 @@ void Pet::RemoveFromWorld() } } -bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool current) +bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool current) { m_loading = true; @@ -116,12 +117,12 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c stmt->setUInt32(0, ownerid); stmt->setUInt8(1, uint8(PET_SAVE_AS_CURRENT)); } - else if (petentry) + else if (petEntry) { - // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) + // known petEntry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY_AND_SLOT_2); stmt->setUInt32(0, ownerid); - stmt->setUInt32(1, petentry); + stmt->setUInt32(1, petEntry); stmt->setUInt8(2, uint8(PET_SAVE_AS_CURRENT)); stmt->setUInt8(3, uint8(PET_SAVE_LAST_STABLE_SLOT)); } @@ -145,38 +146,36 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c Field* fields = result->Fetch(); // update for case of current pet "slot = 0" - petentry = fields[1].GetUInt32(); - if (!petentry) + petEntry = fields[1].GetUInt32(); + if (!petEntry) return false; - uint32 summon_spell_id = fields[14].GetUInt32(); - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summon_spell_id); - - bool is_temporary_summoned = spellInfo && spellInfo->GetDuration() > 0; + uint32 summonSpellId = fields[14].GetUInt32(); + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summonSpellId); - // check temporary summoned pets like mage water elemental - if (current && is_temporary_summoned) + bool isTemporarySummon = spellInfo && spellInfo->GetDuration() > 0; + if (current && isTemporarySummon) return false; - PetType pet_type = PetType(fields[15].GetUInt8()); - if (pet_type == HUNTER_PET) + PetType petType = PetType(fields[15].GetUInt8()); + if (petType == HUNTER_PET) { - CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petentry); + CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petEntry); if (!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets())) return false; } - uint32 pet_number = fields[0].GetUInt32(); + uint32 petId = fields[0].GetUInt32(); if (current && owner->IsPetNeedBeTemporaryUnsummoned()) { - owner->SetTemporaryUnsummonedPetNumber(pet_number); + owner->SetTemporaryUnsummonedPetNumber(petId); return false; } Map* map = owner->GetMap(); uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET); - if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number)) + if (!Create(guid, map, owner->GetPhaseMask(), petEntry, petId)) return false; float px, py, pz; @@ -190,9 +189,9 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c return false; } - setPetType(pet_type); + setPetType(petType); setFaction(owner->getFaction()); - SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); + SetUInt32Value(UNIT_CREATED_BY_SPELL, summonSpellId); CreatureTemplate const* cinfo = GetCreatureTemplate(); if (cinfo->type == CREATURE_TYPE_CRITTER) @@ -201,7 +200,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c return true; } - m_charmInfo->SetPetNumber(pet_number, IsPermanentPetFor(owner)); + m_charmInfo->SetPetNumber(petId, IsPermanentPetFor(owner)); SetDisplayId(fields[3].GetUInt32()); SetNativeDisplayId(fields[3].GetUInt32()); @@ -286,13 +285,13 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c // Send fake summon spell cast - this is needed for correct cooldown application for spells // Example: 46584 - without this cooldown (which should be set always when pet is loaded) isn't set clientside /// @todo pets should be summoned from real cast instead of just faking it? - if (summon_spell_id) + if (summonSpellId) { WorldPacket data(SMSG_SPELL_GO, (8+8+4+4+2)); data.append(owner->GetPackGUID()); data.append(owner->GetPackGUID()); data << uint8(0); - data << uint32(summon_spell_id); + data << uint32(summonSpellId); data << uint32(256); // CAST_FLAG_UNKNOWN3 data << uint32(0); owner->SendMessageToSet(&data, true); @@ -307,7 +306,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c _LoadAuras(timediff); // load action bar, if data broken will fill later by default spells. - if (!is_temporary_summoned) + if (!isTemporarySummon) { m_charmInfo->LoadPetActionBar(fields[12].GetString()); @@ -332,7 +331,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c if (getPetType() == HUNTER_PET) { - stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PET_DECLINED_NAME); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PET_DECLINED_NAME); stmt->setUInt32(0, owner->GetGUIDLow()); stmt->setUInt32(1, GetCharmInfo()->GetPetNumber()); PreparedQueryResult result = CharacterDatabase.Query(stmt); @@ -351,7 +350,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c //set last used pet number (for use in BG's) if (owner->GetTypeId() == TYPEID_PLAYER && isControlled() && !isTemporarySummoned() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET)) - owner->ToPlayer()->SetLastPetNumber(pet_number); + owner->ToPlayer()->SetLastPetNumber(petId); m_loading = false; @@ -653,7 +652,7 @@ void Creature::Regenerate(Powers power) void Pet::Remove(PetSaveMode mode, bool returnreagent) { - m_owner->RemovePet(this, mode, returnreagent); + GetOwner()->RemovePet(this, mode, returnreagent); } void Pet::GivePetXP(uint32 xp) @@ -759,8 +758,8 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas { sLog->outDebug(LOG_FILTER_PETS, "Pet::CreateBaseForTamed"); uint32 guid=sObjectMgr->GenerateLowGuid(HIGHGUID_PET); - uint32 pet_number = sObjectMgr->GeneratePetNumber(); - if (!Create(guid, map, phaseMask, cinfo->Entry, pet_number)) + uint32 petId = sObjectMgr->GeneratePetNumber(); + if (!Create(guid, map, phaseMask, cinfo->Entry, petId)) return false; setPowerType(POWER_FOCUS); @@ -1468,8 +1467,8 @@ bool Pet::learnSpell(uint32 spell_id) { WorldPacket data(SMSG_PET_LEARNED_SPELL, 4); data << uint32(spell_id); - m_owner->GetSession()->SendPacket(&data); - m_owner->PetSpellInitialize(); + GetOwner()->GetSession()->SendPacket(&data); + GetOwner()->PetSpellInitialize(); } return true; } @@ -1521,7 +1520,7 @@ bool Pet::unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab) { WorldPacket data(SMSG_PET_REMOVED_SPELL, 4); data << uint32(spell_id); - m_owner->GetSession()->SendPacket(&data); + GetOwner()->GetSession()->SendPacket(&data); } return true; } @@ -1859,13 +1858,13 @@ bool Pet::IsPermanentPetFor(Player* owner) const } } -bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number) +bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 petId) { ASSERT(map); SetMap(map); SetPhaseMask(phaseMask, false); - Object::_Create(guidlow, pet_number, HIGHGUID_PET); + Object::_Create(guidlow, petId, HIGHGUID_PET); m_DBTableGuid = guidlow; m_originalEntry = Entry; @@ -2026,3 +2025,8 @@ void Pet::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs) if (Player* owner = GetOwner()) owner->GetSession()->SendPacket(&data); } + +Player* Pet::GetOwner() const +{ + return Minion::GetOwner()->ToPlayer(); +} diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index 6c879ba9eaa..975b97adce3 100644 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -142,9 +142,9 @@ class Pet : public Guardian bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) - Player* GetOwner() const { return m_owner; } + Player* GetOwner() const; + protected: - Player* m_owner; PetType m_petType; int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) uint64 m_auraRaidUpdateMask; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index b78c632dd08..806026d9715 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -14722,22 +14722,16 @@ void Player::SendPreparedQuest(uint64 guid) if (questMenu.Empty()) return; - QuestMenuItem const& qmi0 = questMenu.GetItem(0); - - uint32 icon = qmi0.QuestIcon; - // single element case if (questMenu.GetMenuItemCount() == 1) { - // Auto open -- maybe also should verify there is no greeting + QuestMenuItem const& qmi0 = questMenu.GetItem(0); uint32 questId = qmi0.QuestId; - Quest const* quest = sObjectMgr->GetQuestTemplate(questId); - if (quest) + // Auto open -- maybe also should verify there is no greeting + if (Quest const* quest = sObjectMgr->GetQuestTemplate(questId)) { - if (icon == 4 && !GetQuestRewardStatus(questId)) - PlayerTalkClass->SendQuestGiverRequestItems(quest, guid, CanRewardQuest(quest, false), true); - else if (icon == 4) + if (qmi0.QuestIcon == 4) PlayerTalkClass->SendQuestGiverRequestItems(quest, guid, CanRewardQuest(quest, false), true); // Send completable on repeatable and autoCompletable quest if player don't have quest /// @todo verify if check for !quest->IsDaily() is really correct (possibly not) diff --git a/src/server/game/Entities/Totem/Totem.cpp b/src/server/game/Entities/Totem/Totem.cpp index 07aa28ecee0..9526d8755a5 100644 --- a/src/server/game/Entities/Totem/Totem.cpp +++ b/src/server/game/Entities/Totem/Totem.cpp @@ -35,7 +35,7 @@ Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(prop void Totem::Update(uint32 time) { - if (!m_owner->isAlive() || !isAlive()) + if (!GetOwner()->isAlive() || !isAlive()) { UnSummon(); // remove self return; @@ -55,19 +55,19 @@ void Totem::Update(uint32 time) void Totem::InitStats(uint32 duration) { // client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem - if (m_owner->GetTypeId() == TYPEID_PLAYER - && m_Properties->Slot >= SUMMON_SLOT_TOTEM - && m_Properties->Slot < MAX_TOTEM_SLOT) + if (GetOwner()->GetTypeId() == TYPEID_PLAYER + && m_Properties->Slot >= SUMMON_SLOT_TOTEM + && m_Properties->Slot < MAX_TOTEM_SLOT) { WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4); data << uint8(m_Properties->Slot - 1); data << uint64(GetGUID()); data << uint32(duration); data << uint32(GetUInt32Value(UNIT_CREATED_BY_SPELL)); - m_owner->ToPlayer()->SendDirectMessage(&data); + GetOwner()->ToPlayer()->SendDirectMessage(&data); // set display id depending on caster's race - SetDisplayId(m_owner->GetModelForTotem(PlayerTotemType(m_Properties->Id))); + SetDisplayId(GetOwner()->GetModelForTotem(PlayerTotemType(m_Properties->Id))); } Minion::InitStats(duration); @@ -82,7 +82,7 @@ void Totem::InitStats(uint32 duration) m_duration = duration; - SetLevel(m_owner->getLevel()); + SetLevel(GetOwner()->getLevel()); } void Totem::InitSummon() @@ -111,21 +111,21 @@ void Totem::UnSummon(uint32 msTime) // clear owner's totem slot for (int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i) { - if (m_owner->m_SummonSlot[i] == GetGUID()) + if (GetOwner()->m_SummonSlot[i] == GetGUID()) { - m_owner->m_SummonSlot[i] = 0; + GetOwner()->m_SummonSlot[i] = 0; break; } } - m_owner->RemoveAurasDueToSpell(GetSpell(), GetGUID()); + GetOwner()->RemoveAurasDueToSpell(GetSpell(), GetGUID()); // Remove Sentry Totem Aura if (GetEntry() == SENTRY_TOTEM_ENTRY) - m_owner->RemoveAurasDueToSpell(SENTRY_TOTEM_SPELLID); + GetOwner()->RemoveAurasDueToSpell(SENTRY_TOTEM_SPELLID); //remove aura all party members too - if (Player* owner = m_owner->ToPlayer()) + if (Player* owner = GetOwner()->ToPlayer()) { owner->SendAutoRepeatCancel(this); diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 9644d4d5a6c..53f9c702f7a 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -180,11 +180,6 @@ Transport::~Transport() (*itr)->SetTransport(NULL); GetMap()->AddObjectToRemoveList(*itr); } - - m_NPCPassengerSet.clear(); - - m_WayPoints.clear(); - m_passengers.clear(); } bool Transport::Create(uint32 guidlow, uint32 entry, uint32 mapid, float x, float y, float z, float ang, uint32 animprogress, uint32 dynflags) @@ -553,7 +548,7 @@ void Transport::Update(uint32 p_diff) else { Relocate(m_curr->second.x, m_curr->second.y, m_curr->second.z, GetAngle(m_next->second.x, m_next->second.y) + float(M_PI)); - UpdateNPCPositions(); // COME BACK MARKER + UpdatePassengerPositions(); // COME BACK MARKER } sScriptMgr->OnRelocate(this, m_curr->first, m_curr->second.mapid, m_curr->second.x, m_curr->second.y, m_curr->second.z); @@ -685,10 +680,10 @@ void Transport::UpdatePosition(MovementInfo* mi) float transport_z = mi->pos.m_positionZ - mi->t_pos.m_positionZ; Relocate(transport_x, transport_y, transport_z, transport_o); - UpdateNPCPositions(); + UpdatePassengerPositions(); } -void Transport::UpdateNPCPositions() +void Transport::UpdatePassengerPositions() { for (CreatureSet::iterator itr = m_NPCPassengerSet.begin(); itr != m_NPCPassengerSet.end(); ++itr) { @@ -704,7 +699,7 @@ void Transport::UpdateNPCPositions() } } -void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& o) +void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& o) const { float inx = x, iny = y, inz = z, ino = o; o = GetOrientation() + ino; @@ -713,7 +708,7 @@ void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& z = GetPositionZ() + inz; } -void Transport::CalculatePassengerOffset(float& x, float& y, float& z, float& o) +void Transport::CalculatePassengerOffset(float& x, float& y, float& z, float& o) const { o -= GetOrientation(); z -= GetPositionZ(); diff --git a/src/server/game/Entities/Transport/Transport.h b/src/server/game/Entities/Transport/Transport.h index d3bc3732b08..bae09335f62 100644 --- a/src/server/game/Entities/Transport/Transport.h +++ b/src/server/game/Entities/Transport/Transport.h @@ -47,13 +47,13 @@ class Transport : public GameObject, public TransportBase CreatureSet m_NPCPassengerSet; uint32 AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim=0); void UpdatePosition(MovementInfo* mi); - void UpdateNPCPositions(); + void UpdatePassengerPositions(); /// This method transforms supplied transport offsets into global coordinates - void CalculatePassengerPosition(float& x, float& y, float& z, float& o); + void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const; /// This method transforms supplied global coordinates into local offsets - void CalculatePassengerOffset(float& x, float& y, float& z, float& o); + void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const; void BuildStartMovePacket(Map const* targetMap); void BuildStopMovePacket(Map const* targetMap); diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp index 0f4d0a94409..093faf36f14 100644 --- a/src/server/game/Entities/Vehicle/Vehicle.cpp +++ b/src/server/game/Entities/Vehicle/Vehicle.cpp @@ -674,7 +674,7 @@ uint8 Vehicle::GetAvailableSeatCount() const return ret; } -void Vehicle::CalculatePassengerPosition(float& x, float& y, float& z, float& o) +void Vehicle::CalculatePassengerPosition(float& x, float& y, float& z, float& o) const { float inx = x, iny = y, inz = z, ino = o; o = GetBase()->GetOrientation() + ino; @@ -683,7 +683,7 @@ void Vehicle::CalculatePassengerPosition(float& x, float& y, float& z, float& o) z = GetBase()->GetPositionZ() + inz; } -void Vehicle::CalculatePassengerOffset(float& x, float& y, float& z, float& o) +void Vehicle::CalculatePassengerOffset(float& x, float& y, float& z, float& o) const { o -= GetBase()->GetOrientation(); z -= GetBase()->GetPositionZ(); @@ -840,7 +840,7 @@ bool VehicleJoinEvent::Execute(uint64, uint32) if (Target->GetBase()->GetTypeId() == TYPEID_UNIT && Passenger->GetTypeId() == TYPEID_PLAYER && Seat->second.SeatInfo->m_flags & VEHICLE_SEAT_FLAG_CAN_CONTROL) - ASSERT(Target->GetBase()->SetCharmedBy(Passenger, CHARM_TYPE_VEHICLE)) // SMSG_CLIENT_CONTROL + ASSERT(Target->GetBase()->SetCharmedBy(Passenger, CHARM_TYPE_VEHICLE)); // SMSG_CLIENT_CONTROL Passenger->SendClearTarget(); // SMSG_BREAK_TARGET Passenger->SetControlled(true, UNIT_STATE_ROOT); // SMSG_FORCE_ROOT - In some cases we send SMSG_SPLINE_MOVE_ROOT here (for creatures) @@ -853,10 +853,10 @@ bool VehicleJoinEvent::Execute(uint64, uint32) init.SetTransportEnter(); init.Launch(); - if (Target->GetBase()->GetTypeId() == TYPEID_UNIT) + if (Creature* creature = Target->GetBase()->ToCreature()) { - if (Target->GetBase()->ToCreature()->IsAIEnabled) - Target->GetBase()->ToCreature()->AI()->PassengerBoarded(Passenger, Seat->first, true); + if (creature->IsAIEnabled) + creature->AI()->PassengerBoarded(Passenger, Seat->first, true); sScriptMgr->OnAddPassenger(Target, Passenger, Seat->first); diff --git a/src/server/game/Entities/Vehicle/Vehicle.h b/src/server/game/Entities/Vehicle/Vehicle.h index 67975490ecc..3e4a2fd3a78 100644 --- a/src/server/game/Entities/Vehicle/Vehicle.h +++ b/src/server/game/Entities/Vehicle/Vehicle.h @@ -89,10 +89,10 @@ class Vehicle : public TransportBase void InitMovementInfoForBase(); /// This method transforms supplied transport offsets into global coordinates - void CalculatePassengerPosition(float& x, float& y, float& z, float& o); + void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const; /// This method transforms supplied global coordinates into local offsets - void CalculatePassengerOffset(float& x, float& y, float& z, float& o); + void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const; void RemovePendingEvent(VehicleJoinEvent* e); void RemovePendingEventsForSeat(int8 seatId); diff --git a/src/server/game/Entities/Vehicle/VehicleDefines.h b/src/server/game/Entities/Vehicle/VehicleDefines.h index d7df1b44b99..9db8c15f697 100644 --- a/src/server/game/Entities/Vehicle/VehicleDefines.h +++ b/src/server/game/Entities/Vehicle/VehicleDefines.h @@ -99,14 +99,16 @@ typedef std::map<int8, VehicleSeat> SeatMap; class TransportBase { - public: - virtual ~TransportBase() { } +protected: + TransportBase() { } + virtual ~TransportBase() { } - /// This method transforms supplied transport offsets into global coordinates - virtual void CalculatePassengerPosition(float& x, float& y, float& z, float& o) = 0; +public: + /// This method transforms supplied transport offsets into global coordinates + virtual void CalculatePassengerPosition(float& x, float& y, float& z, float& o) const = 0; - /// This method transforms supplied global coordinates into local offsets - virtual void CalculatePassengerOffset(float& x, float& y, float& z, float& o) = 0; + /// This method transforms supplied global coordinates into local offsets + virtual void CalculatePassengerOffset(float& x, float& y, float& z, float& o) const = 0; }; #endif diff --git a/src/server/scripts/EasternKingdoms/BlackrockDepths/blackrock_depths.cpp b/src/server/scripts/EasternKingdoms/BlackrockDepths/blackrock_depths.cpp index 0cbeec50f98..d0c0ded2267 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockDepths/blackrock_depths.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockDepths/blackrock_depths.cpp @@ -981,9 +981,9 @@ public: if (HasEscortState(STATE_ESCORT_ESCORTING)) return; - if (who->GetTypeId() == TYPEID_PLAYER) + if (Player* player = who->ToPlayer()) { - if (CAST_PLR(who)->GetQuestStatus(4322) == QUEST_STATUS_INCOMPLETE) + if (player->GetQuestStatus(4322) == QUEST_STATUS_INCOMPLETE) { float Radius = 10.0f; if (me->IsWithinDistInMap(who, Radius)) diff --git a/src/server/scripts/EasternKingdoms/Gnomeregan/gnomeregan.cpp b/src/server/scripts/EasternKingdoms/Gnomeregan/gnomeregan.cpp index 558ffaf7135..cd4eaa78e9d 100644 --- a/src/server/scripts/EasternKingdoms/Gnomeregan/gnomeregan.cpp +++ b/src/server/scripts/EasternKingdoms/Gnomeregan/gnomeregan.cpp @@ -569,7 +569,8 @@ public: return; if (Unit* summon = me->ToTempSummon()->GetSummoner()) - CAST_CRE(summon)->AI()->SetData(2, 1); + if (Creature* creature = summon->ToCreature()) + creature->AI()->SetData(2, 1); } void UpdateAI(uint32 /*diff*/) @@ -586,8 +587,8 @@ public: return; if (Unit* summoner = me->ToTempSummon()->GetSummoner()) - if (Creature* summonerCre = summoner->ToCreature()) - summonerCre->AI()->SetData(2, 2); + if (Creature* creature = summoner->ToCreature()) + creature->AI()->SetData(2, 2); } }; diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp index 4ef91b93b43..e2227c3f304 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp @@ -145,9 +145,9 @@ public: void KilledUnit(Unit* who) { - Unit* pMalchezaar = Unit::GetUnit(*me, malchezaar); - if (pMalchezaar) - CAST_CRE(pMalchezaar)->AI()->KilledUnit(who); + if (Unit* unit = Unit::GetUnit(*me, malchezaar)) + if (Creature* creature = unit->ToCreature()) + creature->AI()->KilledUnit(who); } void SpellHit(Unit* /*who*/, const SpellInfo* spell) diff --git a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp index d3cb21c75f0..abaf900508c 100644 --- a/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletEnclave/chapter1.cpp @@ -651,19 +651,22 @@ public: { if (Unit* charmer = who->GetCharmer()) { - if (charmer->GetTypeId() == TYPEID_PLAYER) + if (Player* player = charmer->ToPlayer()) { // for quest Into the Realm of Shadows(12687) - if (me->GetEntry() == 28788 && CAST_PLR(charmer)->GetQuestStatus(12687) == QUEST_STATUS_INCOMPLETE) + if (me->GetEntry() == 28788 && player->GetQuestStatus(12687) == QUEST_STATUS_INCOMPLETE) { - CAST_PLR(charmer)->GroupEventHappens(12687, me); + player->GroupEventHappens(12687, me); charmer->RemoveAurasDueToSpell(SPELL_EFFECT_OVERTAKE); - CAST_CRE(who)->DespawnOrUnsummon(); - //CAST_CRE(who)->Respawn(true); + if (Creature* creature = who->ToCreature()) + { + creature->DespawnOrUnsummon(); + //creature->Respawn(true); + } } - if (CAST_PLR(charmer)->HasAura(SPELL_REALM_OF_SHADOWS)) - charmer->RemoveAurasDueToSpell(SPELL_REALM_OF_SHADOWS); + if (player->HasAura(SPELL_REALM_OF_SHADOWS)) + player->RemoveAurasDueToSpell(SPELL_REALM_OF_SHADOWS); } } } @@ -753,17 +756,18 @@ public: { if (Unit* owner = who->GetOwner()) { - if (owner->GetTypeId() == TYPEID_PLAYER) + if (Player* player = owner->ToPlayer()) { - if (CAST_PLR(owner)->GetQuestStatus(12698) == QUEST_STATUS_INCOMPLETE) - CAST_CRE(who)->CastSpell(owner, 52517, true); + Creature* creature = who->ToCreature(); + if (player->GetQuestStatus(12698) == QUEST_STATUS_INCOMPLETE) + creature->CastSpell(owner, 52517, true); /// @todo Creatures must not be removed, but, must instead // stand next to Gothik and be commanded into the pit // and dig into the ground. - CAST_CRE(who)->DespawnOrUnsummon(); + creature->DespawnOrUnsummon(); - if (CAST_PLR(owner)->GetQuestStatus(12698) == QUEST_STATUS_COMPLETE) + if (player->GetQuestStatus(12698) == QUEST_STATUS_COMPLETE) owner->RemoveAllMinionsByEntry(NPC_GHOSTS); } } diff --git a/src/server/scripts/EasternKingdoms/ScarletEnclave/zone_the_scarlet_enclave.cpp b/src/server/scripts/EasternKingdoms/ScarletEnclave/zone_the_scarlet_enclave.cpp index a2c21ebbb1f..3f95d8d0aee 100644 --- a/src/server/scripts/EasternKingdoms/ScarletEnclave/zone_the_scarlet_enclave.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletEnclave/zone_the_scarlet_enclave.cpp @@ -76,8 +76,7 @@ public: Player* player = NULL; if (me->isSummon()) if (Unit* summoner = me->ToTempSummon()->GetSummoner()) - if (summoner->GetTypeId() == TYPEID_PLAYER) - player = CAST_PLR(summoner); + player = summoner->ToPlayer(); if (!player) phase = 3; diff --git a/src/server/scripts/EasternKingdoms/Stratholme/stratholme.cpp b/src/server/scripts/EasternKingdoms/Stratholme/stratholme.cpp index 7208bbbee03..f12a9c33ea9 100644 --- a/src/server/scripts/EasternKingdoms/Stratholme/stratholme.cpp +++ b/src/server/scripts/EasternKingdoms/Stratholme/stratholme.cpp @@ -151,14 +151,15 @@ public: void SpellHit(Unit* caster, const SpellInfo* spell) { - if (caster->GetTypeId() == TYPEID_PLAYER) - { - if (!Tagged && spell->Id == SPELL_EGAN_BLASTER && CAST_PLR(caster)->GetQuestStatus(QUEST_RESTLESS_SOUL) == QUEST_STATUS_INCOMPLETE) - { - Tagged = true; - Tagger = caster->GetGUID(); - } - } + if (Tagged || spell->Id != SPELL_EGAN_BLASTER) + return; + + Player* player = caster->ToPlayer(); + if (!player || player->GetQuestStatus(QUEST_RESTLESS_SOUL) != QUEST_STATUS_INCOMPLETE) + return; + + Tagged = true; + Tagger = caster->GetGUID(); } void JustSummoned(Creature* summoned) @@ -180,10 +181,13 @@ public: { if (Unit* temp = Unit::GetUnit(*me, Tagger)) { - CAST_PLR(temp)->KilledMonsterCredit(ENTRY_RESTLESS, me->GetGUID()); + if (Player* player = temp->ToPlayer()) + player->KilledMonsterCredit(ENTRY_RESTLESS, me->GetGUID()); me->Kill(me); } - } else Die_Timer -= diff; + } + else + Die_Timer -= diff; } } }; diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp index 332baa29b51..6fa7e94e55e 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp @@ -274,9 +274,9 @@ class boss_hexlord_malacrass : public CreatureScript for (uint8 i = 0; i < 4; ++i) { - Unit* Temp = Unit::GetUnit(*me, AddGUID[i]); - if (Temp && Temp->isAlive()) - CAST_CRE(Temp)->AI()->AttackStart(me->getVictim()); + Creature* creature = Unit::GetCreature(*me, AddGUID[i]); + if (creature && creature->isAlive()) + creature->AI()->AttackStart(me->getVictim()); else { EnterEvadeMode(); diff --git a/src/server/scripts/EasternKingdoms/zone_eversong_woods.cpp b/src/server/scripts/EasternKingdoms/zone_eversong_woods.cpp index ce62de8b368..c148d485e1a 100644 --- a/src/server/scripts/EasternKingdoms/zone_eversong_woods.cpp +++ b/src/server/scripts/EasternKingdoms/zone_eversong_woods.cpp @@ -243,11 +243,11 @@ public: summonerGuid = summonerguid; } - void KilledUnit(Unit* Killed) + void KilledUnit(Unit* unit) { - if (Killed->GetTypeId() == TYPEID_PLAYER) - if (CAST_PLR(Killed)->GetQuestStatus(QUEST_SECOND_TRIAL) == QUEST_STATUS_INCOMPLETE) - CAST_PLR(Killed)->FailQuest(QUEST_SECOND_TRIAL); + if (Player* player = unit->ToPlayer()) + if (player->GetQuestStatus(QUEST_SECOND_TRIAL) == QUEST_STATUS_INCOMPLETE) + player->FailQuest(QUEST_SECOND_TRIAL); } void JustDied(Unit* killer); @@ -577,7 +577,7 @@ public: { if (!Progress && who->GetTypeId() == TYPEID_PLAYER && me->IsWithinDistInMap(who, 10.0f)) { - if (CAST_PLR(who)->GetQuestStatus(QUEST_POWERING_OUR_DEFENSES) == QUEST_STATUS_INCOMPLETE) + if (who->ToPlayer()->GetQuestStatus(QUEST_POWERING_OUR_DEFENSES) == QUEST_STATUS_INCOMPLETE) { PlayerGUID = who->GetGUID(); WaveTimer = 1000; @@ -596,7 +596,7 @@ public: { if (PlayerGUID && !Completed) if (Player* player = Unit::GetPlayer(*me, PlayerGUID)) - CAST_PLR(player)->FailQuest(QUEST_POWERING_OUR_DEFENSES); + player->FailQuest(QUEST_POWERING_OUR_DEFENSES); } void UpdateAI(uint32 diff) @@ -607,7 +607,7 @@ public: Completed = true; if (PlayerGUID) if (Player* player = Unit::GetPlayer(*me, PlayerGUID)) - CAST_PLR(player)->CompleteQuest(QUEST_POWERING_OUR_DEFENSES); + player->CompleteQuest(QUEST_POWERING_OUR_DEFENSES); me->DealDamage(me, me->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); me->RemoveCorpse(); diff --git a/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp b/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp index 0703f95a22c..1a9aabcda57 100644 --- a/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp +++ b/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp @@ -138,8 +138,7 @@ public: me->SetWalk(true); break; case 30: - if (player->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(player)->GroupEventHappens(QUEST_ESCAPE_FROM_THE_CATACOMBS, me); + player->GroupEventHappens(QUEST_ESCAPE_FROM_THE_CATACOMBS, me); break; case 32: me->SetOrientation(2.978281f); diff --git a/src/server/scripts/EasternKingdoms/zone_silvermoon_city.cpp b/src/server/scripts/EasternKingdoms/zone_silvermoon_city.cpp index fd36a02b8a5..0e7472fc63b 100644 --- a/src/server/scripts/EasternKingdoms/zone_silvermoon_city.cpp +++ b/src/server/scripts/EasternKingdoms/zone_silvermoon_city.cpp @@ -88,19 +88,22 @@ public: } } - void SpellHit(Unit* Hitter, const SpellInfo* Spellkind) + void SpellHit(Unit* caster, const SpellInfo* Spellkind) { - if ((Spellkind->Id == SPELL_SHIMMERING_VESSEL) && !spellHit && - (Hitter->GetTypeId() == TYPEID_PLAYER) && (CAST_PLR(Hitter)->IsActiveQuest(QUEST_REDEEMING_THE_DEAD))) - { - CAST_PLR(Hitter)->AreaExploredOrEventHappens(QUEST_REDEEMING_THE_DEAD); - DoCast(me, SPELL_REVIVE_SELF); - me->SetStandState(UNIT_STAND_STATE_STAND); - me->SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0); - //me->RemoveAllAuras(); - Talk(SAY_HEAL); - spellHit = true; - } + if (Spellkind->Id != SPELL_SHIMMERING_VESSEL || spellHit) + return; + + Player* player = caster->ToPlayer(); + if (!player || !player->IsActiveQuest(QUEST_REDEEMING_THE_DEAD)) + return; + + player->AreaExploredOrEventHappens(QUEST_REDEEMING_THE_DEAD); + DoCast(me, SPELL_REVIVE_SELF); + me->SetStandState(UNIT_STAND_STATE_STAND); + me->SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0); + //me->RemoveAllAuras(); + Talk(SAY_HEAL); + spellHit = true; } }; }; diff --git a/src/server/scripts/EasternKingdoms/zone_stranglethorn_vale.cpp b/src/server/scripts/EasternKingdoms/zone_stranglethorn_vale.cpp index c11e850cbc8..66fb4819175 100644 --- a/src/server/scripts/EasternKingdoms/zone_stranglethorn_vale.cpp +++ b/src/server/scripts/EasternKingdoms/zone_stranglethorn_vale.cpp @@ -64,10 +64,12 @@ public: void SpellHit(Unit* caster, const SpellInfo* spell) { - if (caster->GetTypeId() == TYPEID_PLAYER) + if (bReset || spell->Id != 3607) + return; + + if (Player* player = caster->ToPlayer()) { - //Yenniku's Release - if (!bReset && CAST_PLR(caster)->GetQuestStatus(592) == QUEST_STATUS_INCOMPLETE && spell->Id == 3607) + if (player->GetQuestStatus(592) == QUEST_STATUS_INCOMPLETE) //Yenniku's Release { me->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_STUN); me->CombatStop(); //stop combat @@ -78,7 +80,6 @@ public: Reset_Timer = 60000; } } - return; } void EnterCombat(Unit* /*who*/) {} @@ -94,14 +95,14 @@ public: me->setFaction(28); //troll, bloodscalp return; } - else Reset_Timer -= diff; + + Reset_Timer -= diff; if (me->isInCombat() && me->getVictim()) { - if (me->getVictim()->GetTypeId() == TYPEID_PLAYER) + if (Player* player = me->getVictim()->ToPlayer()) { - Unit* victim = me->getVictim(); - if (CAST_PLR(victim)->GetTeam() == HORDE) + if (player->GetTeam() == HORDE) { me->CombatStop(); me->DeleteThreatList(); diff --git a/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp b/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp index 1831d9f7ff1..0692330b87a 100644 --- a/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp +++ b/src/server/scripts/EasternKingdoms/zone_western_plaguelands.cpp @@ -190,46 +190,47 @@ public: void MoveInLineOfSight(Unit* who) { - if (!who || who->GetTypeId() != TYPEID_PLAYER) + if (!who) + return; + + Player* player = who->ToPlayer(); + if (!player) return; - if (who->GetTypeId() == TYPEID_PLAYER) + switch (me->GetAreaId()) { - switch (me->GetAreaId()) - { - case 199: //felstone - if (CAST_PLR(who)->GetQuestStatus(5216) == QUEST_STATUS_INCOMPLETE || - CAST_PLR(who)->GetQuestStatus(5229) == QUEST_STATUS_INCOMPLETE) - { - me->SummonCreature(11075, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); - DoDie(); - } - break; - case 200: //dalson - if (CAST_PLR(who)->GetQuestStatus(5219) == QUEST_STATUS_INCOMPLETE || - CAST_PLR(who)->GetQuestStatus(5231) == QUEST_STATUS_INCOMPLETE) - { - me->SummonCreature(11077, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); - DoDie(); - } - break; - case 201: //gahrron - if (CAST_PLR(who)->GetQuestStatus(5225) == QUEST_STATUS_INCOMPLETE || - CAST_PLR(who)->GetQuestStatus(5235) == QUEST_STATUS_INCOMPLETE) - { - me->SummonCreature(11078, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); - DoDie(); - } - break; - case 202: //writhing - if (CAST_PLR(who)->GetQuestStatus(5222) == QUEST_STATUS_INCOMPLETE || - CAST_PLR(who)->GetQuestStatus(5233) == QUEST_STATUS_INCOMPLETE) - { - me->SummonCreature(11076, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); - DoDie(); - } - break; - } + case 199: //felstone + if (player->GetQuestStatus(5216) == QUEST_STATUS_INCOMPLETE || + player->GetQuestStatus(5229) == QUEST_STATUS_INCOMPLETE) + { + me->SummonCreature(11075, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); + DoDie(); + } + break; + case 200: //dalson + if (player->GetQuestStatus(5219) == QUEST_STATUS_INCOMPLETE || + player->GetQuestStatus(5231) == QUEST_STATUS_INCOMPLETE) + { + me->SummonCreature(11077, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); + DoDie(); + } + break; + case 201: //gahrron + if (player->GetQuestStatus(5225) == QUEST_STATUS_INCOMPLETE || + player->GetQuestStatus(5235) == QUEST_STATUS_INCOMPLETE) + { + me->SummonCreature(11078, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); + DoDie(); + } + break; + case 202: //writhing + if (player->GetQuestStatus(5222) == QUEST_STATUS_INCOMPLETE || + player->GetQuestStatus(5233) == QUEST_STATUS_INCOMPLETE) + { + me->SummonCreature(11076, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000); + DoDie(); + } + break; } } }; @@ -267,7 +268,8 @@ public: return; if (me->FindNearestGameObject(GO_BEACON_TORCH, 10.0f)) - CAST_PLR(who)->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); + if (Player* player = who->ToPlayer()) + player->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); } }; }; diff --git a/src/server/scripts/EasternKingdoms/zone_wetlands.cpp b/src/server/scripts/EasternKingdoms/zone_wetlands.cpp index c8a1fc2b2b4..ea7b995e8cf 100644 --- a/src/server/scripts/EasternKingdoms/zone_wetlands.cpp +++ b/src/server/scripts/EasternKingdoms/zone_wetlands.cpp @@ -116,8 +116,7 @@ public: { if (Player* player = GetPlayerForEscort()) { - if (player->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(player)->GroupEventHappens(QUEST_MISSING_DIPLO_PT11, me); + player->GroupEventHappens(QUEST_MISSING_DIPLO_PT11, me); uiDamage = 0; diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp index 3f186c96d40..a7d4a7087f8 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp @@ -960,12 +960,12 @@ void hyjalAI::WaypointReached(uint32 waypointId) DoCast(me, SPELL_MASS_TELEPORT, false); if (me->GetEntry() == THRALL && DummyGuid) { - Unit* Dummy = Unit::GetUnit(*me, DummyGuid); - if (Dummy) + if (Creature* creature = Unit::GetCreature(*me, DummyGuid)) { - CAST_AI(hyjalAI, CAST_CRE(Dummy)->AI())->DoMassTeleport = true; - CAST_AI(hyjalAI, CAST_CRE(Dummy)->AI())->MassTeleportTimer = 20000; - Dummy->CastSpell(me, SPELL_MASS_TELEPORT, false); + hyjalAI* ai = CAST_AI(hyjalAI, creature->AI()); + ai->DoMassTeleport = true; + ai->MassTeleportTimer = 20000; + creature->CastSpell(me, SPELL_MASS_TELEPORT, false); } } //do some talking diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp index adb89ba5a69..630c379e71e 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjal_trash.cpp @@ -191,7 +191,7 @@ hyjal_trashAI::hyjal_trashAI(Creature* creature) : npc_escortAI(creature) void hyjal_trashAI::DamageTaken(Unit* done_by, uint32 &damage) { - if (done_by->GetTypeId() == TYPEID_PLAYER || (done_by->GetTypeId() == TYPEID_UNIT && CAST_CRE(done_by)->isPet())) + if (done_by->GetTypeId() == TYPEID_PLAYER || done_by->isPet()) { damageTaken += damage; if (instance) diff --git a/src/server/scripts/Kalimdor/RazorfenKraul/razorfen_kraul.cpp b/src/server/scripts/Kalimdor/RazorfenKraul/razorfen_kraul.cpp index 7cb78718e2a..55e81f1408f 100644 --- a/src/server/scripts/Kalimdor/RazorfenKraul/razorfen_kraul.cpp +++ b/src/server/scripts/Kalimdor/RazorfenKraul/razorfen_kraul.cpp @@ -119,8 +119,7 @@ public: case 45: Talk(SAY_WIN, player->GetGUID()); me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER); - if (player->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(player)->GroupEventHappens(QUEST_WILLIX_THE_IMPORTER, me); + player->GroupEventHappens(QUEST_WILLIX_THE_IMPORTER, me); break; case 46: Talk(SAY_END, player->GetGUID()); @@ -143,7 +142,7 @@ public: void JustDied(Unit* /*killer*/) { if (Player* player = GetPlayerForEscort()) - CAST_PLR(player)->FailQuest(QUEST_WILLIX_THE_IMPORTER); + player->FailQuest(QUEST_WILLIX_THE_IMPORTER); } }; diff --git a/src/server/scripts/Kalimdor/zone_durotar.cpp b/src/server/scripts/Kalimdor/zone_durotar.cpp index 77e78199a41..6b82ee99f0a 100644 --- a/src/server/scripts/Kalimdor/zone_durotar.cpp +++ b/src/server/scripts/Kalimdor/zone_durotar.cpp @@ -72,10 +72,13 @@ public: void SpellHit(Unit* caster, const SpellInfo* spell) { - if (spell->Id == SPELL_AWAKEN_PEON && caster->GetTypeId() == TYPEID_PLAYER - && CAST_PLR(caster)->GetQuestStatus(QUEST_LAZY_PEONS) == QUEST_STATUS_INCOMPLETE) + if (spell->Id != SPELL_AWAKEN_PEON) + return; + + Player* player = caster->ToPlayer(); + if (player && player->GetQuestStatus(QUEST_LAZY_PEONS) == QUEST_STATUS_INCOMPLETE) { - caster->ToPlayer()->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); + player->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); Talk(SAY_SPELL_HIT, caster->GetGUID()); me->RemoveAllAuras(); if (GameObject* Lumberpile = me->FindNearestGameObject(GO_LUMBERPILE, 20)) diff --git a/src/server/scripts/Kalimdor/zone_tanaris.cpp b/src/server/scripts/Kalimdor/zone_tanaris.cpp index 327d85fd2ff..7e4a1d980db 100644 --- a/src/server/scripts/Kalimdor/zone_tanaris.cpp +++ b/src/server/scripts/Kalimdor/zone_tanaris.cpp @@ -83,15 +83,17 @@ public: void SendItem(Unit* receiver) { - if (CAST_PLR(receiver)->HasItemCount(11169, 1, false) && - CAST_PLR(receiver)->HasItemCount(11172, 11, false) && - CAST_PLR(receiver)->HasItemCount(11173, 1, false) && - !CAST_PLR(receiver)->HasItemCount(11522, 1, true)) + Player* player = receiver->ToPlayer(); + + if (player && player->HasItemCount(11169, 1, false) && + player->HasItemCount(11172, 11, false) && + player->HasItemCount(11173, 1, false) && + !player->HasItemCount(11522, 1, true)) { ItemPosCountVec dest; - uint8 msg = CAST_PLR(receiver)->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 11522, 1, NULL); + uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 11522, 1, NULL); if (msg == EQUIP_ERR_OK) - CAST_PLR(receiver)->StoreNewItem(dest, 11522, 1, true); + player->StoreNewItem(dest, 11522, 1, true); } } @@ -250,9 +252,9 @@ public: if (HasEscortState(STATE_ESCORT_ESCORTING)) return; - if (who->GetTypeId() == TYPEID_PLAYER) + if (Player* player = who->ToPlayer()) { - if (who->HasAura(34877) && CAST_PLR(who)->GetQuestStatus(10277) == QUEST_STATUS_INCOMPLETE) + if (who->HasAura(34877) && player->GetQuestStatus(10277) == QUEST_STATUS_INCOMPLETE) { float Radius = 10.0f; if (me->IsWithinDistInMap(who, Radius)) diff --git a/src/server/scripts/Kalimdor/zone_the_barrens.cpp b/src/server/scripts/Kalimdor/zone_the_barrens.cpp index bdbd278ce89..d21ca8c9427 100644 --- a/src/server/scripts/Kalimdor/zone_the_barrens.cpp +++ b/src/server/scripts/Kalimdor/zone_the_barrens.cpp @@ -380,14 +380,16 @@ public: void MoveInLineOfSight(Unit* who) { - if (!who || (!who->isAlive())) + if (!who || !who->isAlive() || EventInProgress) return; - if (me->IsWithinDistInMap(who, 10.0f) && (who->GetTypeId() == TYPEID_PLAYER) && CAST_PLR(who)->GetQuestStatus(1719) == QUEST_STATUS_INCOMPLETE && !EventInProgress) - { - PlayerGUID = who->GetGUID(); - EventInProgress = true; - } + if (who->GetTypeId() == TYPEID_PLAYER && me->IsWithinDistInMap(who, 10.0f)) + if (Player* player = who->ToPlayer()) + if (player->GetQuestStatus(1719) == QUEST_STATUS_INCOMPLETE) + { + PlayerGUID = who->GetGUID(); + EventInProgress = true; + } } void KilledUnit(Unit* /*victim*/) { } diff --git a/src/server/scripts/Kalimdor/zone_winterspring.cpp b/src/server/scripts/Kalimdor/zone_winterspring.cpp index 06f01033a25..2b68c0a2cb6 100644 --- a/src/server/scripts/Kalimdor/zone_winterspring.cpp +++ b/src/server/scripts/Kalimdor/zone_winterspring.cpp @@ -19,17 +19,20 @@ /* ScriptData SDName: Winterspring SD%Complete: Almost Completely Emptied -SDComment: Vendor Rivern Frostwind. +SDComment: Vendor Rivern Frostwind. Quest Support 4901 SDCategory: Winterspring EndScriptData */ /* ContentData npc_rivern_frostwind +npc_ranshalla +go_elune_fire EndContentData */ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "ScriptedGossip.h" +#include "ScriptedEscortAI.h" #include "Player.h" #include "WorldSession.h" @@ -63,10 +66,562 @@ public: return true; } +}; + +enum Says +{ + // Escort texts + SAY_QUEST_START = 0, + SAY_ENTER_OWL_THICKET = 1, + SAY_REACH_TORCH = 2, + SAY_AFTER_TORCH = 3, + SAY_REACH_ALTAR_1 = 4, + SAY_REACH_ALTAR_2 = 5, + + // After lighting the altar cinematic + SAY_RANSHALLA_ALTAR_1 = 6, + SAY_RANSHALLA_ALTAR_2 = 7, + SAY_PRIESTESS_ALTAR_3 = 8, + SAY_PRIESTESS_ALTAR_4 = 9, + SAY_RANSHALLA_ALTAR_5 = 10, + SAY_RANSHALLA_ALTAR_6 = 11, + SAY_PRIESTESS_ALTAR_7 = 12, + SAY_PRIESTESS_ALTAR_8 = 13, + SAY_PRIESTESS_ALTAR_9 = 14, + SAY_PRIESTESS_ALTAR_10 = 15, + SAY_PRIESTESS_ALTAR_11 = 16, + SAY_PRIESTESS_ALTAR_12 = 17, + SAY_PRIESTESS_ALTAR_13 = 18, + SAY_PRIESTESS_ALTAR_14 = 19, + SAY_VOICE_ALTAR_15 = 20, + SAY_PRIESTESS_ALTAR_16 = 21, + SAY_PRIESTESS_ALTAR_17 = 22, + SAY_PRIESTESS_ALTAR_18 = 23, + SAY_PRIESTESS_ALTAR_19 = 24, + SAY_PRIESTESS_ALTAR_20 = 25, + SAY_PRIESTESS_ALTAR_21 = 26, + SAY_RANSHALLA_END_1 = 27, + SAY_RANSHALLA_END_2 = 28, + + EMOTE_CHANT_SPELL = 29, +}; + +enum Spells +{ + SPELL_LIGHT_TORCH = 18953, // channeled spell by Ranshalla while waiting for the torches / altar +}; + +enum NPCs +{ + NPC_RANSHALLA = 10300, + NPC_PRIESTESS_ELUNE = 12116, + NPC_VOICE_ELUNE = 12152, + NPC_GUARDIAN_ELUNE = 12140, +}; + +enum GOs +{ + GO_ELUNE_ALTAR = 177404, + GO_ELUNE_FIRE = 177417, + GO_ELUNE_GEM = 177414, // is respawned in script + GO_ELUNE_LIGHT = 177415, // are respawned in script +}; + +enum Quests +{ + QUEST_GUARDIANS_ALTAR = 4901, +}; + +enum Dummies +{ + NPC_PRIESTESS_DATA_1 = -1, // dummy member for the first priestess (right) + NPC_PRIESTESS_DATA_2 = -2, // dummy member for the second priestess (left) + DATA_MOVE_PRIESTESS = -3, // dummy member to check the priestess movement + DATA_EVENT_END = -4, // dummy member to indicate the event end + + EVENT_RESUME = 1, // trigger rest of event +}; + +// DialogueHelper (imported from SD) + +struct DialogueEntry +{ + int32 TextEntry; ///< To be said text entry + int32 SayerEntry; ///< Entry of the mob who should say + uint32 SayTimer; ///< Time delay until next text of array is said (0 stops) +}; + +class DialogueHelper +{ +public: + // The array MUST be terminated by {0,0,0} + DialogueHelper(DialogueEntry const* dialogueArray) : + _dialogueArray(dialogueArray), + _currentEntry(NULL), + _actionTimer(0), + _isFirstSide(true) + {} + // The array MUST be terminated by {0,0,0,0,0} + + /// Function to initialize the dialogue helper for instances. If not used with instances, GetSpeakerByEntry MUST be overwritten to obtain the speakers + /// Set if take first entries or second entries + + void StartNextDialogueText(int32 textEntry) + { + // Find textEntry + bool found = false; + + for (DialogueEntry const* entry = _dialogueArray; entry->TextEntry; ++entry) + { + if (entry->TextEntry == textEntry) + { + _currentEntry = entry; + found = true; + break; + } + } + + if (!found) + { + return; + } + + DoNextDialogueStep(); + } + + void DialogueUpdate(uint32 diff) + { + if (_actionTimer) + { + if (_actionTimer <= diff) + DoNextDialogueStep(); + else + _actionTimer -= diff; + } + } + +protected: + /// Will be called when a dialogue step was done + virtual void JustDidDialogueStep(int32 /*entry*/) {} + /// Will be called to get a speaker, MUST be implemented if not used in instances + virtual Creature* GetSpeakerByEntry(int32 /*entry*/) { return NULL; } +private: + void DoNextDialogueStep() + { + // Last Dialogue Entry done? + if (_currentEntry && !_currentEntry->TextEntry) + { + _actionTimer = 0; + return; + } + + // Get Text, SpeakerEntry and Timer + int32 textEntry = _currentEntry->TextEntry; + uint32 sayerEntry = _currentEntry->SayerEntry; + _actionTimer = _currentEntry->SayTimer; + + // Simulate Case + if (sayerEntry && textEntry >= 0) + { + // Use Speaker if directly provided + if (Creature* speaker = GetSpeakerByEntry(sayerEntry)) + speaker->AI()->Talk(textEntry); + } + + JustDidDialogueStep(_currentEntry->TextEntry); + + // Increment position + ++_currentEntry; + } + + DialogueEntry const* _dialogueArray; + DialogueEntry const* _currentEntry; + + uint32 _actionTimer; + bool _isFirstSide; +}; + +const DialogueEntry introDialogue[] = +{ + {SAY_REACH_ALTAR_1, NPC_RANSHALLA, 2000}, + {SAY_REACH_ALTAR_2, NPC_RANSHALLA, 3000}, + {NPC_RANSHALLA, 0, 0}, // start the altar channeling + {SAY_PRIESTESS_ALTAR_3, NPC_PRIESTESS_DATA_2, 1000}, + {SAY_PRIESTESS_ALTAR_4, NPC_PRIESTESS_DATA_1, 4000}, + {SAY_RANSHALLA_ALTAR_5, NPC_RANSHALLA, 4000}, + {SAY_RANSHALLA_ALTAR_6, NPC_RANSHALLA, 4000}, // start the escort here + {SAY_PRIESTESS_ALTAR_7, NPC_PRIESTESS_DATA_2, 4000}, + {SAY_PRIESTESS_ALTAR_8, NPC_PRIESTESS_DATA_2, 5000}, // show the gem + {GO_ELUNE_GEM, 0, 5000}, + {SAY_PRIESTESS_ALTAR_9, NPC_PRIESTESS_DATA_1, 4000}, // move priestess 1 near me + {NPC_PRIESTESS_DATA_1, 0, 3000}, + {SAY_PRIESTESS_ALTAR_10, NPC_PRIESTESS_DATA_1, 5000}, + {SAY_PRIESTESS_ALTAR_11, NPC_PRIESTESS_DATA_1, 4000}, + {SAY_PRIESTESS_ALTAR_12, NPC_PRIESTESS_DATA_1, 5000}, + {SAY_PRIESTESS_ALTAR_13, NPC_PRIESTESS_DATA_1, 8000}, // summon voice and guard of elune + {NPC_VOICE_ELUNE, 0, 12000}, + {SAY_VOICE_ALTAR_15, NPC_VOICE_ELUNE, 5000}, // move priestess 2 near me + {NPC_PRIESTESS_DATA_2, 0, 3000}, + {SAY_PRIESTESS_ALTAR_16, NPC_PRIESTESS_DATA_2, 4000}, + {SAY_PRIESTESS_ALTAR_17, NPC_PRIESTESS_DATA_2, 6000}, + {SAY_PRIESTESS_ALTAR_18, NPC_PRIESTESS_DATA_1, 5000}, + {SAY_PRIESTESS_ALTAR_19, NPC_PRIESTESS_DATA_1, 3000}, // move the owlbeast + {NPC_GUARDIAN_ELUNE, 0, 2000}, + {SAY_PRIESTESS_ALTAR_20, NPC_PRIESTESS_DATA_1, 4000}, // move the first priestess up + {SAY_PRIESTESS_ALTAR_21, NPC_PRIESTESS_DATA_2, 10000}, // move second priestess up + {DATA_MOVE_PRIESTESS, 0, 6000}, // despawn the gem + {DATA_EVENT_END, 0, 2000}, // turn towards the player + {SAY_RANSHALLA_END_2, NPC_RANSHALLA, 0}, + {0, 0, 0}, +}; + +static Position wingThicketLocations[] = +{ + {5515.98f, -4903.43f, 846.30f, 4.58f}, // 0 right priestess summon loc + {5501.94f, -4920.20f, 848.69f, 6.15f}, // 1 left priestess summon loc + {5497.35f, -4906.49f, 850.83f, 2.76f}, // 2 guard of elune summon loc + {5518.38f, -4913.47f, 845.57f, 0.00f}, // 3 right priestess move loc + {5510.36f, -4921.17f, 846.33f, 0.00f}, // 4 left priestess move loc + {5511.31f, -4913.82f, 847.17f, 0.00f}, // 5 guard of elune move loc + {5518.51f, -4917.56f, 845.23f, 0.00f}, // 6 right priestess second move loc + {5514.40f, -4921.16f, 845.49f, 0.00f} // 7 left priestess second move loc +}; + +/*##### +# npc_ranshalla +#####*/ + +class npc_ranshalla : public CreatureScript +{ +public: + npc_ranshalla() : CreatureScript("npc_ranshalla") { } + bool OnQuestAccept(Player* player, Creature* creature, Quest const* quest) + { + if (quest->GetQuestId() == QUEST_GUARDIANS_ALTAR) + { + creature->AI()->Talk(SAY_QUEST_START); + creature->setFaction(FACTION_ESCORT_A_NEUTRAL_PASSIVE); + + if (npc_ranshallaAI* escortAI = dynamic_cast<npc_ranshallaAI*>(creature->AI())) + escortAI->Start(false, false, player->GetGUID(), quest); + + return true; + } + + return false; + } + CreatureAI* GetAI(Creature* creature) const + { + return new npc_ranshallaAI(creature); + } + + struct npc_ranshallaAI : public npc_escortAI, private DialogueHelper + { + npc_ranshallaAI(Creature* creature) : npc_escortAI(creature), + DialogueHelper(introDialogue) + { + Reset(); + } + + uint32 _delayTimer; + + uint64 _firstPriestessGUID; + uint64 _secondPriestessGUID; + uint64 _guardEluneGUID; + uint64 _voiceEluneGUID; + uint64 _altarGUID; + + void Reset() + { + _delayTimer = 0; + } + + // Called when the player activates the torch / altar + void DoContinueEscort(bool isAltarWaypoint = false) + { + me->InterruptNonMeleeSpells(false); + + if (isAltarWaypoint) + Talk(SAY_RANSHALLA_ALTAR_1); + else + Talk(SAY_AFTER_TORCH); + + _delayTimer = 2000; + } + + // Called when Ranshalla starts to channel on a torch / altar + void DoChannelTorchSpell(bool isAltarWaypoint = false) + { + // Check if we are using the fire or the altar and remove the no_interact flag + if (isAltarWaypoint) + { + if (GameObject* go = GetClosestGameObjectWithEntry(me, GO_ELUNE_ALTAR, 10.0f)) + { + go->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE); + me->SetFacingToObject(go); + _altarGUID = go->GetGUID(); + } + } + else if (GameObject* go = GetClosestGameObjectWithEntry(me, GO_ELUNE_FIRE, 10.0f)) + go->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE); + + // Yell and set escort to pause + Talk(SAY_REACH_TORCH); + Talk(EMOTE_CHANT_SPELL); + SetEscortPaused(true); + DoCast(me, SPELL_LIGHT_TORCH); + } + + void DoSummonPriestess() + { + // Summon 2 Elune priestess and make each of them move to a different spot + if (Creature* priestess = me->SummonCreature(NPC_PRIESTESS_ELUNE, wingThicketLocations[0].m_positionX, wingThicketLocations[0].m_positionY, wingThicketLocations[0].m_positionZ, wingThicketLocations[0].m_orientation, TEMPSUMMON_CORPSE_DESPAWN, 0)) + { + priestess->GetMotionMaster()->MovePoint(0, wingThicketLocations[3].m_positionX, wingThicketLocations[3].m_positionY, wingThicketLocations[3].m_positionZ); + _firstPriestessGUID = priestess->GetGUID(); + } + if (Creature* priestess = me->SummonCreature(NPC_PRIESTESS_ELUNE, wingThicketLocations[1].m_positionX, wingThicketLocations[1].m_positionY, wingThicketLocations[1].m_positionZ, wingThicketLocations[1].m_orientation, TEMPSUMMON_CORPSE_DESPAWN, 0)) + { + // Left priestess should have a distinct move point because she is the one who starts the dialogue at point reach + priestess->GetMotionMaster()->MovePoint(1, wingThicketLocations[4].m_positionX, wingThicketLocations[4].m_positionY, wingThicketLocations[4].m_positionZ); + _secondPriestessGUID = priestess->GetGUID(); + } + } + + void SummonedMovementInform(Creature* summoned, uint32 type, uint32 pointId) + { + if (type != POINT_MOTION_TYPE || summoned->GetEntry() != NPC_PRIESTESS_ELUNE || pointId != 1) + return; + + // Start the dialogue when the priestess reach the altar (they should both reach the point in the same time) + StartNextDialogueText(SAY_PRIESTESS_ALTAR_3); + } + + void WaypointReached(uint32 pointId) + { + switch(pointId) + { + case 3: + Talk(SAY_ENTER_OWL_THICKET); + break; + case 10: // Cavern 1 + case 15: // Cavern 2 + case 20: // Cavern 3 + case 25: // Cavern 4 + case 36: // Cavern 5 + DoChannelTorchSpell(); + break; + case 39: + StartNextDialogueText(SAY_REACH_ALTAR_1); + SetEscortPaused(true); + break; + case 41: + { + // Search for all nearest lights and respawn them + std::list<GameObject*> eluneLights; + GetGameObjectListWithEntryInGrid(eluneLights, me, GO_ELUNE_LIGHT, 20.0f); + for (std::list<GameObject*>::const_iterator itr = eluneLights.begin(); itr != eluneLights.end(); ++itr) + { + if ((*itr)->isSpawned()) + continue; + + (*itr)->SetRespawnTime(115); + (*itr)->Refresh(); + } + + if (GameObject* altar = me->GetMap()->GetGameObject(_altarGUID)) + me->SetFacingToObject(altar); + break; + } + case 42: + // Summon the 2 priestess + SetEscortPaused(true); + DoSummonPriestess(); + Talk(SAY_RANSHALLA_ALTAR_2); + events.ScheduleEvent(EVENT_RESUME,2000); + break; + case 44: + // Stop the escort and turn towards the altar + SetEscortPaused(true); + if (GameObject* altar = me->GetMap()->GetGameObject(_altarGUID)) + me->SetFacingToObject(altar); + break; + } + } + + void JustDidDialogueStep(int32 entry) + { + switch (entry) + { + case NPC_RANSHALLA: + // Start the altar channeling + DoChannelTorchSpell(true); + break; + case SAY_RANSHALLA_ALTAR_6: + SetEscortPaused(false); + break; + case SAY_PRIESTESS_ALTAR_8: + // make the gem respawn + if (GameObject* gem = GetClosestGameObjectWithEntry(me, GO_ELUNE_GEM, 10.0f)) + { + if (gem->isSpawned()) + break; + + gem->SetRespawnTime(90); + gem->Refresh(); + } + break; + case SAY_PRIESTESS_ALTAR_9: + // move near the escort npc + if (Creature* priestess = me->GetMap()->GetCreature(_firstPriestessGUID)) + priestess->GetMotionMaster()->MovePoint(0, wingThicketLocations[6].m_positionX, wingThicketLocations[6].m_positionY, wingThicketLocations[6].m_positionZ); + break; + case SAY_PRIESTESS_ALTAR_13: + // summon the Guardian of Elune + if (Creature* guard = me->SummonCreature(NPC_GUARDIAN_ELUNE, wingThicketLocations[2].m_positionX, wingThicketLocations[2].m_positionY, wingThicketLocations[2].m_positionZ, wingThicketLocations[2].m_orientation, TEMPSUMMON_CORPSE_DESPAWN, 0)) + { + guard->GetMotionMaster()->MovePoint(0, wingThicketLocations[5].m_positionX, wingThicketLocations[5].m_positionY, wingThicketLocations[5].m_positionZ); + _guardEluneGUID = guard->GetGUID(); + } + // summon the Voice of Elune + if (GameObject* altar = me->GetMap()->GetGameObject(_altarGUID)) + { + if (Creature* voice = me->SummonCreature(NPC_VOICE_ELUNE, altar->GetPositionX(), altar->GetPositionY(), altar->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 30000)) + _voiceEluneGUID = voice->GetGUID(); + } + break; + case SAY_VOICE_ALTAR_15: + // move near the escort npc and continue dialogue + if (Creature* priestess = me->GetMap()->GetCreature(_secondPriestessGUID)) + { + priestess->AI()->Talk(SAY_PRIESTESS_ALTAR_14); + priestess->GetMotionMaster()->MovePoint(0, wingThicketLocations[7].m_positionX, wingThicketLocations[7].m_positionY, wingThicketLocations[7].m_positionZ); + } + break; + case SAY_PRIESTESS_ALTAR_19: + // make the voice of elune leave + if (Creature* guard = me->GetMap()->GetCreature(_guardEluneGUID)) + { + guard->GetMotionMaster()->MovePoint(0, wingThicketLocations[2].m_positionX, wingThicketLocations[2].m_positionY, wingThicketLocations[2].m_positionZ); + guard->DespawnOrUnsummon(4000); + } + break; + case SAY_PRIESTESS_ALTAR_20: + // make the first priestess leave + if (Creature* priestess = me->GetMap()->GetCreature(_firstPriestessGUID)) + { + priestess->GetMotionMaster()->MovePoint(0, wingThicketLocations[0].m_positionX, wingThicketLocations[0].m_positionY, wingThicketLocations[0].m_positionZ); + priestess->DespawnOrUnsummon(4000); + } + break; + case SAY_PRIESTESS_ALTAR_21: + // make the second priestess leave + if (Creature* priestess = me->GetMap()->GetCreature(_secondPriestessGUID)) + { + priestess->GetMotionMaster()->MovePoint(0, wingThicketLocations[1].m_positionX, wingThicketLocations[1].m_positionY, wingThicketLocations[1].m_positionZ); + priestess->DespawnOrUnsummon(4000); + } + break; + case DATA_EVENT_END: + // Turn towards the player + if (Player* player = GetPlayerForEscort()) + { + me->SetFacingToObject(player); + Talk(SAY_RANSHALLA_END_1, player->GetGUID()); + } + break; + case SAY_RANSHALLA_END_2: + // Turn towards the altar and kneel - quest complete + if (GameObject* altar = me->GetMap()->GetGameObject(_altarGUID)) + { + me->SetFacingToObject(altar); + altar->ResetDoorOrButton(); + } + me->SetStandState(UNIT_STAND_STATE_KNEEL); + if (Player* player = GetPlayerForEscort()) + { + player->GroupEventHappens(QUEST_GUARDIANS_ALTAR, me); + Talk(SAY_RANSHALLA_END_2, player->GetGUID()); + } + me->DespawnOrUnsummon(4000); + break; + } + } + + Creature* GetSpeakerByEntry(int32 entry) + { + switch (entry) + { + case NPC_RANSHALLA: + return me; + case NPC_VOICE_ELUNE: + return me->GetMap()->GetCreature(_voiceEluneGUID); + case NPC_PRIESTESS_DATA_1: + return me->GetMap()->GetCreature(_firstPriestessGUID); + case NPC_PRIESTESS_DATA_2: + return me->GetMap()->GetCreature(_secondPriestessGUID); + default: + return NULL; + } + + } + + void UpdateEscortAI(const uint32 diff) + { + DialogueUpdate(diff); + + if (_delayTimer) + { + if (_delayTimer <= diff) + { + SetEscortPaused(false); + _delayTimer = 0; + } + else + _delayTimer -= diff; + } + events.Update(diff); + if (events.ExecuteEvent() == EVENT_RESUME) + StartNextDialogueText(SAY_PRIESTESS_ALTAR_3); + + npc_escortAI::UpdateEscortAI(diff); + } + private: + EventMap events; + }; +}; + +/*##### +# go_elune_fire +#####*/ + +class go_elune_fire : public GameObjectScript +{ +public: + go_elune_fire() : GameObjectScript("go_elune_fire") { } + bool OnGossipHello(Player* /*player*/, GameObject* go) + { + // Check if we are using the torches or the altar + bool isAltar = false; + + if (go->GetEntry() == GO_ELUNE_ALTAR) + isAltar = true; + + if (Creature* ranshalla = GetClosestCreatureWithEntry(go, NPC_RANSHALLA, 10.0f)) + { + if (npc_ranshalla::npc_ranshallaAI* escortAI = dynamic_cast<npc_ranshalla::npc_ranshallaAI*>(ranshalla->AI())) + escortAI->DoContinueEscort(isAltar); + } + go->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE); + + return false; + } }; void AddSC_winterspring() { new npc_rivern_frostwind(); + new npc_ranshalla(); + new go_elune_fire(); } diff --git a/src/server/scripts/Northrend/DraktharonKeep/boss_trollgore.cpp b/src/server/scripts/Northrend/DraktharonKeep/boss_trollgore.cpp index 3dcac3f68dc..2438273dcba 100644 --- a/src/server/scripts/Northrend/DraktharonKeep/boss_trollgore.cpp +++ b/src/server/scripts/Northrend/DraktharonKeep/boss_trollgore.cpp @@ -185,7 +185,7 @@ public: void JustSummoned(Creature* summon) { - lSummons.push_back(summon->GetGUID()); + lSummons.Summon(summon); if (summon->AI()) summon->AI()->AttackStart(me); } diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp index e377f5f8d07..cab02c9ca75 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_professor_putricide.cpp @@ -687,7 +687,7 @@ class boss_professor_putricide : public CreatureScript me->SetFacingToObject(face); me->HandleEmoteCommand(EMOTE_ONESHOT_KNEEL); Talk(SAY_TRANSFORM_2); - summons.remove_if(AbominationDespawner(me)); + summons.DespawnIf(AbominationDespawner(me)); events.ScheduleEvent(EVENT_RESUME_ATTACK, 8500, 0, PHASE_COMBAT_3); break; default: diff --git a/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp b/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp index 878107ab35d..0e5941138a6 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp @@ -89,11 +89,10 @@ class boss_sapphiron : public CreatureScript struct boss_sapphironAI : public BossAI { - boss_sapphironAI(Creature* creature) : BossAI(creature, BOSS_SAPPHIRON) - , _phase(PHASE_NULL) - { - _map = me->GetMap(); - } + boss_sapphironAI(Creature* creature) : + BossAI(creature, BOSS_SAPPHIRON), _phase(PHASE_NULL), + _map(me->GetMap()) + { } void InitializeAI() { diff --git a/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp b/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp index 47e39574690..d861343116f 100644 --- a/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp +++ b/src/server/scripts/Northrend/Nexus/EyeOfEternity/boss_malygos.cpp @@ -621,7 +621,7 @@ public: { VehicleCheckPredicate pred; summons.DoAction(ACTION_DELAYED_DESPAWN, pred); - summons.remove_if(pred); + summons.DespawnIf(pred); summons.DespawnAll(); } else if (_phase == PHASE_THREE) diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp index 33a14aaa3df..3299148ea43 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_freya.cpp @@ -287,7 +287,6 @@ class boss_freya : public CreatureScript void Reset() { _Reset(); - summons.clear(); trioWaveCount = 0; trioWaveController = 0; waveCount = 0; @@ -494,7 +493,7 @@ class boss_freya : public CreatureScript { for (uint8 n = 0; n < 3; ++n) { - summons.remove(Elemental[n][i]->GetGUID()); + summons.Despawn(Elemental[n][i]); Elemental[n][i]->DespawnOrUnsummon(5000); trioDefeated[i] = true; Elemental[n][i]->CastSpell(me, SPELL_REMOVE_10STACK, true); @@ -625,7 +624,7 @@ class boss_freya : public CreatureScript case NPC_ANCIENT_WATER_SPIRIT: case NPC_STORM_LASHER: ElementalGUID[trioWaveController][trioWaveCount] = summoned->GetGUID(); - summons.push_back(summoned->GetGUID()); + summons.Summon(summoned); ++trioWaveController; if (trioWaveController > 2) trioWaveController = 0; @@ -633,7 +632,7 @@ class boss_freya : public CreatureScript case NPC_DETONATING_LASHER: case NPC_ANCIENT_CONSERVATOR: default: - summons.push_back(summoned->GetGUID()); + summons.Summon(summoned); break; } @@ -654,12 +653,12 @@ class boss_freya : public CreatureScript summoned->CastSpell(me, SPELL_REMOVE_2STACK, true); summoned->CastSpell(who, SPELL_DETONATE, true); summoned->DespawnOrUnsummon(5000); - summons.remove(summoned->GetGUID()); + summons.Despawn(summoned); break; case NPC_ANCIENT_CONSERVATOR: summoned->CastSpell(me, SPELL_REMOVE_25STACK, true); summoned->DespawnOrUnsummon(5000); - summons.remove(summoned->GetGUID()); + summons.Despawn(summoned); break; } } diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp index b970dc6d7ab..0f99ea9cc2d 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_hodir.cpp @@ -821,7 +821,7 @@ class npc_hodir_mage : public CreatureScript void SummonedCreatureDespawn(Creature* summoned) { if (summoned->GetEntry() == NPC_TOASTY_FIRE) - summons.remove(summoned->GetGUID()); + summons.Despawn(summoned); } void UpdateAI(uint32 diff) diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_kologarn.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_kologarn.cpp index 5e94fc2ee5d..47fe7c8f80a 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_kologarn.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_kologarn.cpp @@ -219,7 +219,7 @@ class boss_kologarn : public CreatureScript summon->CastSpell(me, SPELL_FOCUSED_EYEBEAM_VISUAL_RIGHT, true); break; case NPC_RUBBLE: - summons.push_back(summon->GetGUID()); + summons.Summon(summon); // absence of break intended default: return; diff --git a/src/server/scripts/Northrend/UtgardeKeep/UtgardeKeep/boss_skarvald_dalronn.cpp b/src/server/scripts/Northrend/UtgardeKeep/UtgardeKeep/boss_skarvald_dalronn.cpp index ef7ad659a24..75f643286b2 100644 --- a/src/server/scripts/Northrend/UtgardeKeep/UtgardeKeep/boss_skarvald_dalronn.cpp +++ b/src/server/scripts/Northrend/UtgardeKeep/UtgardeKeep/boss_skarvald_dalronn.cpp @@ -113,7 +113,7 @@ public: { Unit* dalronn = Unit::GetUnit(*me, instance->GetData64(DATA_DALRONN)); if (dalronn && dalronn->isDead()) - CAST_CRE(dalronn)->Respawn(); + dalronn->ToCreature()->Respawn(); instance->SetData(DATA_SKARVALD_DALRONN_EVENT, NOT_STARTED); } @@ -280,7 +280,7 @@ public: { Unit* skarvald = Unit::GetUnit(*me, instance->GetData64(DATA_SKARVALD)); if (skarvald && skarvald->isDead()) - CAST_CRE(skarvald)->Respawn(); + skarvald->ToCreature()->Respawn(); instance->SetData(DATA_SKARVALD_DALRONN_EVENT, NOT_STARTED); } diff --git a/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp b/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp index cfb3c03b12c..db70177f8a0 100644 --- a/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp +++ b/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp @@ -306,7 +306,7 @@ public: { summoned->SetSpeed(MOVE_RUN, 0.3f); summoned->GetMotionMaster()->MoveFollow(me, 0, 0); - m_waterElements.push_back(summoned->GetGUID()); + m_waterElements.Summon(summoned); instance->SetData64(DATA_ADD_TRASH_MOB, summoned->GetGUID()); } } @@ -315,7 +315,7 @@ public: { if (summoned) { - m_waterElements.remove(summoned->GetGUID()); + m_waterElements.Despawn(summoned); instance->SetData64(DATA_DEL_TRASH_MOB, summoned->GetGUID()); } } diff --git a/src/server/scripts/Northrend/zone_borean_tundra.cpp b/src/server/scripts/Northrend/zone_borean_tundra.cpp index fef900e1dfd..6fb1079d94c 100644 --- a/src/server/scripts/Northrend/zone_borean_tundra.cpp +++ b/src/server/scripts/Northrend/zone_borean_tundra.cpp @@ -79,11 +79,11 @@ public: void SpellHit(Unit* caster, const SpellInfo* spell) { - if (phase) + if (phase || spell->Id != SPELL_SET_CART) return; - if (spell->Id == SPELL_SET_CART && caster->GetTypeId() == TYPEID_PLAYER - && CAST_PLR(caster)->GetQuestStatus(11897) == QUEST_STATUS_INCOMPLETE) + Player* player = caster->ToPlayer(); + if (player && player->GetQuestStatus(11897) == QUEST_STATUS_INCOMPLETE) { phase = 1; casterGuid = caster->GetGUID(); @@ -190,7 +190,7 @@ public: if (owner->GetTypeId() == TYPEID_PLAYER) { owner->CastSpell(owner, 46231, true); - CAST_CRE(who)->DespawnOrUnsummon(); + who->ToCreature()->DespawnOrUnsummon(); } } } @@ -419,7 +419,7 @@ public: me->SetReactState(REACT_PASSIVE); - switch (CAST_PLR(me->GetOwner())->GetTeamId()) + switch (me->GetOwner()->ToPlayer()->GetTeamId()) { case TEAM_ALLIANCE: me->setFaction(FACTION_ESCORT_A_NEUTRAL_ACTIVE); @@ -475,23 +475,18 @@ public: { ScriptedAI::MoveInLineOfSight(who); - if (who->GetTypeId() != TYPEID_UNIT) + if (who->GetEntry() != NPC_JENNY || !who->HasAura(SPELL_CRATES_CARRIED)) + return; + + Unit* owner = who->GetOwner(); + if (!owner || !me->IsWithinDistInMap(who, 10.0f)) return; - if (who->GetEntry() == NPC_JENNY && me->IsWithinDistInMap(who, 10.0f)) + if (Player* player = owner->ToPlayer()) { - if (Unit* owner = who->GetOwner()) - { - if (owner->GetTypeId() == TYPEID_PLAYER) - { - if (who->HasAura(SPELL_CRATES_CARRIED)) - { - owner->CastSpell(owner, SPELL_GIVE_JENNY_CREDIT, true); // Maybe is not working. - CAST_PLR(owner)->CompleteQuest(QUEST_LOADER_UP); - CAST_CRE(who)->DisappearAndDie(); - } - } - } + owner->CastSpell(owner, SPELL_GIVE_JENNY_CREDIT, true); // Maybe is not working. + player->CompleteQuest(QUEST_LOADER_UP); + who->ToCreature()->DisappearAndDie(); } } }; @@ -569,8 +564,8 @@ public: if (TempSummon* summon = me->ToTempSummon()) if (summon->isSummon()) if (Unit* temp = summon->GetSummoner()) - if (temp->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(temp)->KilledMonsterCredit(me->GetEntry(), 0); + if (Player* player = temp->ToPlayer()) + player->KilledMonsterCredit(me->GetEntry(), 0); if (GameObject* go_caribou = me->GetMap()->GetGameObject(go_caribouGUID)) go_caribou->SetGoState(GO_STATE_READY); @@ -1268,7 +1263,7 @@ public: if (me->isSummon()) if (Unit* summoner = me->ToTempSummon()->GetSummoner()) - CAST_AI(npc_thassarian::npc_thassarianAI, CAST_CRE(summoner)->AI())->arthasInPosition = true; + CAST_AI(npc_thassarian::npc_thassarianAI, summoner->ToCreature()->AI())->arthasInPosition = true; } }; @@ -1300,7 +1295,7 @@ public: me->CastSpell(me, SPELL_STUN, true); if (me->isSummon()) if (Unit* summoner = me->ToTempSummon()->GetSummoner()) - CAST_AI(npc_thassarian::npc_thassarianAI, CAST_CRE(summoner)->AI())->arlosInPosition = true; + CAST_AI(npc_thassarian::npc_thassarianAI, summoner->ToCreature()->AI())->arlosInPosition = true; } }; @@ -1357,7 +1352,7 @@ public: if (me->isSummon()) if (Unit* summoner = me->ToTempSummon()->GetSummoner()) - CAST_AI(npc_thassarian::npc_thassarianAI, CAST_CRE(summoner)->AI())->talbotInPosition = true; + CAST_AI(npc_thassarian::npc_thassarianAI, summoner->ToCreature()->AI())->talbotInPosition = true; } void UpdateAI(uint32 uiDiff) diff --git a/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp b/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp index e990a6f6825..5d18026c1ca 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_illidan.cpp @@ -2264,7 +2264,7 @@ public: if (CheckTimer <= diff) { GETUNIT(Illidan, IllidanGUID); - if (!Illidan || CAST_CRE(Illidan)->IsInEvadeMode()) + if (!Illidan || Illidan->ToCreature()->IsInEvadeMode()) { me->SetVisible(false); me->setDeathState(JUST_DIED); diff --git a/src/server/scripts/Outland/BlackTemple/boss_teron_gorefiend.cpp b/src/server/scripts/Outland/BlackTemple/boss_teron_gorefiend.cpp index 5eb9ffcabc8..1681ecfb00e 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_teron_gorefiend.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_teron_gorefiend.cpp @@ -349,10 +349,10 @@ public: { /*float x, y, z; ghost->GetPosition(x, y, z); - Creature* control = me->SummonCreature(CREATURE_GHOST, x, y, z, 0, TEMPSUMMON_TIMED_DESAWN, 30000); - if (control) + if (Creature* control = me->SummonCreature(CREATURE_GHOST, x, y, z, 0, TEMPSUMMON_TIMED_DESAWN, 30000)) { - CAST_PLR(ghost)->Possess(control); + if (Player* player = ghost->ToPlayer()) + player->Possess(control); ghost->DealDamage(ghost, ghost->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); }*/ diff --git a/src/server/scripts/Outland/BlackTemple/illidari_council.cpp b/src/server/scripts/Outland/BlackTemple/illidari_council.cpp index d63e8ee20b0..57b7d484004 100644 --- a/src/server/scripts/Outland/BlackTemple/illidari_council.cpp +++ b/src/server/scripts/Outland/BlackTemple/illidari_council.cpp @@ -305,7 +305,7 @@ public: { Unit* member = Unit::GetUnit(*me, Council[i]); if (member && member->isAlive()) - CAST_CRE(member)->AI()->AttackStart(target); + member->ToCreature()->AI()->AttackStart(target); } } diff --git a/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_fathomlord_karathress.cpp b/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_fathomlord_karathress.cpp index b9df26d11c6..38f02622e5a 100644 --- a/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_fathomlord_karathress.cpp +++ b/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_fathomlord_karathress.cpp @@ -542,27 +542,31 @@ public: if (Spitfire_Timer <= diff) { DoCast(me, SPELL_SPITFIRE_TOTEM); - Unit* SpitfireTotem = Unit::GetUnit(*me, CREATURE_SPITFIRE_TOTEM); - if (SpitfireTotem) - { - CAST_CRE(SpitfireTotem)->AI()->AttackStart(me->getVictim()); - } + if (Unit* SpitfireTotem = Unit::GetUnit(*me, CREATURE_SPITFIRE_TOTEM)) + SpitfireTotem->ToCreature()->AI()->AttackStart(me->getVictim()); + Spitfire_Timer = 60000; - } else Spitfire_Timer -= diff; + } + else + Spitfire_Timer -= diff; //PoisonCleansing_Timer if (PoisonCleansing_Timer <= diff) { DoCast(me, SPELL_POISON_CLEANSING_TOTEM); PoisonCleansing_Timer = 30000; - } else PoisonCleansing_Timer -= diff; + } + else + PoisonCleansing_Timer -= diff; //Earthbind_Timer if (Earthbind_Timer <= diff) { DoCast(me, SPELL_EARTHBIND_TOTEM); Earthbind_Timer = 45000; - } else Earthbind_Timer -= diff; + } + else + Earthbind_Timer -= diff; DoMeleeAttackIfReady(); } @@ -665,17 +669,19 @@ public: { //DoCast(me, SPELL_SUMMON_CYCLONE); // Doesn't work Cyclone_Timer = 30000+rand()%10000; - Creature* Cyclone = me->SummonCreature(CREATURE_CYCLONE, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), float(rand()%5), TEMPSUMMON_TIMED_DESPAWN, 15000); - if (Cyclone) + + if (Creature* Cyclone = me->SummonCreature(CREATURE_CYCLONE, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), float(rand()%5), TEMPSUMMON_TIMED_DESPAWN, 15000)) { - CAST_CRE(Cyclone)->SetObjectScale(3.0f); + Cyclone->ToCreature()->SetObjectScale(3.0f); Cyclone->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); Cyclone->setFaction(me->getFaction()); Cyclone->CastSpell(Cyclone, SPELL_CYCLONE_CYCLONE, true); if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0)) Cyclone->AI()->AttackStart(target); } - } else Cyclone_Timer -= diff; + } + else + Cyclone_Timer -= diff; //Heal_Timer if (Heal_Timer <= diff) @@ -684,14 +690,14 @@ public: Unit* unit = NULL; while (unit == NULL || !unit->isAlive()) - { unit = selectAdvisorUnit(); - } if (unit && unit->isAlive()) DoCast(unit, SPELL_HEAL); Heal_Timer = 60000; - } else Heal_Timer -= diff; + } + else + Heal_Timer -= diff; DoMeleeAttackIfReady(); } diff --git a/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_lady_vashj.cpp b/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_lady_vashj.cpp index 19b57509093..ae63ed67af1 100644 --- a/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_lady_vashj.cpp +++ b/src/server/scripts/Outland/CoilfangReservoir/SerpentShrine/boss_lady_vashj.cpp @@ -786,7 +786,7 @@ public: { // check if vashj is death Unit* Vashj = Unit::GetUnit(*me, instance->GetData64(DATA_LADYVASHJ)); - if (!Vashj || (Vashj && !Vashj->isAlive()) || (Vashj && CAST_AI(boss_lady_vashj::boss_lady_vashjAI, CAST_CRE(Vashj)->AI())->Phase != 3)) + if (!Vashj || !Vashj->isAlive() || CAST_AI(boss_lady_vashj::boss_lady_vashjAI, Vashj->ToCreature()->AI())->Phase != 3) { // remove me->setDeathState(DEAD); @@ -796,7 +796,9 @@ public: } CheckTimer = 1000; - } else CheckTimer -= diff; + } + else + CheckTimer -= diff; } }; diff --git a/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warbringer_omrogg.cpp b/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warbringer_omrogg.cpp index ac261cc5936..89a585e415f 100644 --- a/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warbringer_omrogg.cpp +++ b/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warbringer_omrogg.cpp @@ -306,7 +306,7 @@ class boss_warbringer_omrogg : public CreatureScript pLeftHead->AI()->Talk(YELL_DIE_L); - CAST_AI(mob_omrogg_heads::mob_omrogg_headsAI, CAST_CRE(pRightHead)->AI())->DoDeathYell(); + CAST_AI(mob_omrogg_heads::mob_omrogg_headsAI, pRightHead->ToCreature()->AI())->DoDeathYell(); if (instance) instance->SetData(TYPE_OMROGG, DONE); diff --git a/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warchief_kargath_bladefist.cpp b/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warchief_kargath_bladefist.cpp index 13f47b276ef..2cfe73ea719 100644 --- a/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warchief_kargath_bladefist.cpp +++ b/src/server/scripts/Outland/HellfireCitadel/ShatteredHalls/boss_warchief_kargath_bladefist.cpp @@ -167,9 +167,9 @@ class boss_warchief_kargath_bladefist : public CreatureScript Unit* temp = Unit::GetUnit(*me, *itr); if (temp && temp->isAlive()) { - (*temp).GetMotionMaster()->Clear(true); + temp->GetMotionMaster()->Clear(true); me->DealDamage(temp, temp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); - CAST_CRE(temp)->RemoveCorpse(); + temp->ToCreature()->RemoveCorpse(); } } adds.clear(); @@ -179,9 +179,9 @@ class boss_warchief_kargath_bladefist : public CreatureScript Unit* temp = Unit::GetUnit(*me, *itr); if (temp && temp->isAlive()) { - (*temp).GetMotionMaster()->Clear(true); + temp->GetMotionMaster()->Clear(true); me->DealDamage(temp, temp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); - CAST_CRE(temp)->RemoveCorpse(); + temp->ToCreature()->RemoveCorpse(); } } assassins.clear(); diff --git a/src/server/scripts/Outland/zone_nagrand.cpp b/src/server/scripts/Outland/zone_nagrand.cpp index fd193aa4835..148bfeaeefe 100644 --- a/src/server/scripts/Outland/zone_nagrand.cpp +++ b/src/server/scripts/Outland/zone_nagrand.cpp @@ -339,17 +339,15 @@ public: if (!who) return; - if (who->GetTypeId() == TYPEID_PLAYER) + Player* player = who->ToPlayer(); + if (player && player->GetQuestStatus(10085) == QUEST_STATUS_INCOMPLETE) { - if (CAST_PLR(who)->GetQuestStatus(10085) == QUEST_STATUS_INCOMPLETE) + uint32 creditMarkerId = me->GetEntry(); + if (creditMarkerId >= 18840 && creditMarkerId <= 18843) { - uint32 creditMarkerId = me->GetEntry(); - if ((creditMarkerId >= 18840) && (creditMarkerId <= 18843)) - { - // 18840: Sunspring, 18841: Laughing, 18842: Garadar, 18843: Bleeding - if (!CAST_PLR(who)->GetReqKillOrCastCurrentCount(10085, creditMarkerId)) - CAST_PLR(who)->KilledMonsterCredit(creditMarkerId, me->GetGUID()); - } + // 18840: Sunspring, 18841: Laughing, 18842: Garadar, 18843: Bleeding + if (!player->GetReqKillOrCastCurrentCount(10085, creditMarkerId)) + player->KilledMonsterCredit(creditMarkerId, me->GetGUID()); } } } diff --git a/src/server/scripts/Outland/zone_netherstorm.cpp b/src/server/scripts/Outland/zone_netherstorm.cpp index 779ab3261ed..c0adddd51fc 100644 --- a/src/server/scripts/Outland/zone_netherstorm.cpp +++ b/src/server/scripts/Outland/zone_netherstorm.cpp @@ -118,36 +118,33 @@ public: if (someplayer) { - Unit* p = Unit::GetUnit(*me, someplayer); - if (p && p->GetTypeId() == TYPEID_PLAYER) + if (Player* player = ObjectAccessor::GetPlayer(*me, someplayer)) { switch (me->GetEntry()) { case ENTRY_BNAAR_C_CONSOLE: - CAST_PLR(p)->FailQuest(10299); - CAST_PLR(p)->FailQuest(10329); + player->FailQuest(10299); + player->FailQuest(10329); break; case ENTRY_CORUU_C_CONSOLE: - CAST_PLR(p)->FailQuest(10321); - CAST_PLR(p)->FailQuest(10330); + player->FailQuest(10321); + player->FailQuest(10330); break; case ENTRY_DURO_C_CONSOLE: - CAST_PLR(p)->FailQuest(10322); - CAST_PLR(p)->FailQuest(10338); + player->FailQuest(10322); + player->FailQuest(10338); break; case ENTRY_ARA_C_CONSOLE: - CAST_PLR(p)->FailQuest(10323); - CAST_PLR(p)->FailQuest(10365); + player->FailQuest(10323); + player->FailQuest(10365); break; } } } if (goConsole) - { if (GameObject* go = GameObject::GetGameObject(*me, goConsole)) go->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE); - } } void DoWaveSpawnForCreature(Creature* creature) @@ -275,27 +272,30 @@ public: Talk(EMOTE_COMPLETE); if (someplayer) { - Unit* u = Unit::GetUnit(*me, someplayer); - if (u && u->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(u)->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); + if (Player* player = ObjectAccessor::GetPlayer(*me, someplayer)) + player->KilledMonsterCredit(me->GetEntry(), me->GetGUID()); DoCast(me, SPELL_DISABLE_VISUAL); } + if (goConsole) - { if (GameObject* go = GameObject::GetGameObject(*me, goConsole)) go->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE); - } + ++Phase; break; } - } else Event_Timer -= diff; + } + else + Event_Timer -= diff; if (Wave) { if (Wave_Timer <= diff) { DoWaveSpawnForCreature(me); - } else Wave_Timer -= diff; + } + else + Wave_Timer -= diff; } } }; diff --git a/src/server/scripts/Outland/zone_shadowmoon_valley.cpp b/src/server/scripts/Outland/zone_shadowmoon_valley.cpp index b8f96e373f3..644fd71e7a2 100644 --- a/src/server/scripts/Outland/zone_shadowmoon_valley.cpp +++ b/src/server/scripts/Outland/zone_shadowmoon_valley.cpp @@ -1377,20 +1377,19 @@ public: { case TYPEID_UNIT: if (Unit* owner = killer->GetOwner()) - if (owner->GetTypeId() == TYPEID_PLAYER) - CAST_PLR(owner)->GroupEventHappens(QUEST_BATTLE_OF_THE_CRIMSON_WATCH, me); + if (Player* player = owner->ToPlayer()) + player->GroupEventHappens(QUEST_BATTLE_OF_THE_CRIMSON_WATCH, me); break; case TYPEID_PLAYER: - CAST_PLR(killer)->GroupEventHappens(QUEST_BATTLE_OF_THE_CRIMSON_WATCH, me); + if (Player* player = killer->ToPlayer()) + player->GroupEventHappens(QUEST_BATTLE_OF_THE_CRIMSON_WATCH, me); break; default: break; } if (Creature* LordIllidan = (Unit::GetCreature(*me, LordIllidanGUID))) - { LordIllidan->AI()->EnterEvadeMode(); - } } }; }; @@ -1865,10 +1864,9 @@ public: Summoned->setFaction(ENRAGED_SOUL_FRIENDLY); Summoned->GetMotionMaster()->MovePoint(0, totemOspirits->GetPositionX(), totemOspirits->GetPositionY(), Summoned->GetPositionZ()); - Unit* Owner = totemOspirits->GetOwner(); - if (Owner && Owner->GetTypeId() == TYPEID_PLAYER) - // DoCast(Owner, credit); -- not working! - CAST_PLR(Owner)->KilledMonsterCredit(credit, 0); + if (Unit* owner = totemOspirits->GetOwner()) + if (Player* player = owner->ToPlayer()) + player->KilledMonsterCredit(credit, 0); DoCast(totemOspirits, SPELL_SOUL_CAPTURED); } } diff --git a/src/server/scripts/Outland/zone_shattrath_city.cpp b/src/server/scripts/Outland/zone_shattrath_city.cpp index 14553be0ef4..95ba9476905 100644 --- a/src/server/scripts/Outland/zone_shattrath_city.cpp +++ b/src/server/scripts/Outland/zone_shattrath_city.cpp @@ -167,10 +167,9 @@ public: void DamageTaken(Unit* done_by, uint32 &damage) { - if (done_by->GetTypeId() == TYPEID_PLAYER) - if (me->HealthBelowPctDamaged(20, damage)) + if (done_by->GetTypeId() == TYPEID_PLAYER && me->HealthBelowPctDamaged(20, damage)) { - CAST_PLR(done_by)->GroupEventHappens(QUEST_10004, me); + done_by->ToPlayer()->GroupEventHappens(QUEST_10004, me); damage = 0; EnterEvadeMode(); } @@ -410,20 +409,18 @@ public: if (HasEscortState(STATE_ESCORT_ESCORTING)) return; - if (who->GetTypeId() == TYPEID_PLAYER) + Player* player = who->ToPlayer(); + if (player && player->GetQuestStatus(10211) == QUEST_STATUS_INCOMPLETE) { - if (CAST_PLR(who)->GetQuestStatus(10211) == QUEST_STATUS_INCOMPLETE) + float Radius = 10.0f; + if (me->IsWithinDistInMap(who, Radius)) { - float Radius = 10.0f; - if (me->IsWithinDistInMap(who, Radius)) - { - Start(false, false, who->GetGUID()); - } + Start(false, false, who->GetGUID()); } } } - void Reset() {} + void Reset() { } }; }; @@ -477,17 +474,16 @@ public: me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); me->setFaction(1194); - Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20); - if (Creepjack) + if (Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20)) { - CAST_CRE(Creepjack)->AI()->EnterEvadeMode(); + Creepjack->ToCreature()->AI()->EnterEvadeMode(); Creepjack->setFaction(1194); Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } - Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20); - if (Malone) + + if (Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20)) { - CAST_CRE(Malone)->AI()->EnterEvadeMode(); + Malone->ToCreature()->AI()->EnterEvadeMode(); Malone->setFaction(1194); Malone->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } @@ -561,18 +557,17 @@ public: me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); me->RemoveAllAuras(); - Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20); - if (Creepjack) + if (Unit* Creepjack = me->FindNearestCreature(NPC_CREEPJACK, 20)) { - CAST_CRE(Creepjack)->AI()->EnterEvadeMode(); + Creepjack->ToCreature()->AI()->EnterEvadeMode(); Creepjack->setFaction(1194); Creepjack->GetMotionMaster()->MoveTargetedHome(); Creepjack->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } - Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20); - if (Malone) + + if (Unit* Malone = me->FindNearestCreature(NPC_MALONE, 20)) { - CAST_CRE(Malone)->AI()->EnterEvadeMode(); + Malone->ToCreature()->AI()->EnterEvadeMode(); Malone->setFaction(1194); Malone->GetMotionMaster()->MoveTargetedHome(); Malone->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); @@ -583,9 +578,8 @@ public: me->DeleteThreatList(); me->CombatStop(); me->GetMotionMaster()->MoveTargetedHome(); - Player* player = Unit::GetPlayer(*me, PlayerGUID); - if (player) - CAST_PLR(player)->GroupEventHappens(QUEST_WBI, me); + if (Player* player = Unit::GetPlayer(*me, PlayerGUID)) + player->GroupEventHappens(QUEST_WBI, me); } DoMeleeAttackIfReady(); } diff --git a/src/server/scripts/Outland/zone_terokkar_forest.cpp b/src/server/scripts/Outland/zone_terokkar_forest.cpp index caa31ed472c..85a45193931 100644 --- a/src/server/scripts/Outland/zone_terokkar_forest.cpp +++ b/src/server/scripts/Outland/zone_terokkar_forest.cpp @@ -98,10 +98,11 @@ public: void DamageTaken(Unit* done_by, uint32 &damage) { - if (done_by->GetTypeId() == TYPEID_PLAYER) - if (me->HealthBelowPctDamaged(30, damage)) + Player* player = done_by->ToPlayer(); + + if (player && me->HealthBelowPctDamaged(30, damage)) { - if (Group* group = CAST_PLR(done_by)->GetGroup()) + if (Group* group = player->GetGroup()) { for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -115,11 +116,11 @@ public: CanDoQuest = true; } } - } else - if (CAST_PLR(done_by)->GetQuestStatus(QUEST_DONTKILLTHEFATONE) == QUEST_STATUS_INCOMPLETE && - CAST_PLR(done_by)->GetReqKillOrCastCurrentCount(QUEST_DONTKILLTHEFATONE, 18260) == 10) + } + else if (player->GetQuestStatus(QUEST_DONTKILLTHEFATONE) == QUEST_STATUS_INCOMPLETE && + player->GetReqKillOrCastCurrentCount(QUEST_DONTKILLTHEFATONE, 18260) == 10) { - CAST_PLR(done_by)->AreaExploredOrEventHappens(QUEST_DONTKILLTHEFATONE); + player->AreaExploredOrEventHappens(QUEST_DONTKILLTHEFATONE); CanDoQuest = true; } } @@ -229,20 +230,13 @@ public: if (HasEscortState(STATE_ESCORT_ESCORTING)) return; - if (who->GetTypeId() == TYPEID_PLAYER) - { - if (CAST_PLR(who)->GetQuestStatus(10898) == QUEST_STATUS_INCOMPLETE) - { - float Radius = 10.0f; - if (me->IsWithinDistInMap(who, Radius)) - { - Start(false, false, who->GetGUID()); - } - } - } + Player* player = who->ToPlayer(); + if (player && player->GetQuestStatus(10898) == QUEST_STATUS_INCOMPLETE) + if (me->IsWithinDistInMap(who, 10.0f)) + Start(false, false, who->GetGUID()); } - void Reset() {} + void Reset() { } void UpdateAI(uint32 diff) { diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index 4c913d8c42e..59d49f50c8d 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -761,40 +761,41 @@ public: void SpellHit(Unit* caster, SpellInfo const* spell) { - if (caster->GetTypeId() == TYPEID_PLAYER && me->isAlive() && spell->Id == 20804) - { - if ((CAST_PLR(caster)->GetQuestStatus(6624) == QUEST_STATUS_INCOMPLETE) || (CAST_PLR(caster)->GetQuestStatus(6622) == QUEST_STATUS_INCOMPLETE)) - if (DoctorGUID) - if (Creature* doctor = Unit::GetCreature(*me, DoctorGUID)) - CAST_AI(npc_doctor::npc_doctorAI, doctor->AI())->PatientSaved(me, CAST_PLR(caster), Coord); + Player* player = caster->ToPlayer(); + if (!player || !me->isAlive() || spell->Id != 20804) + return; - //make not selectable - me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); + if (player->GetQuestStatus(6624) == QUEST_STATUS_INCOMPLETE || player->GetQuestStatus(6622) == QUEST_STATUS_INCOMPLETE) + if (DoctorGUID) + if (Creature* doctor = Unit::GetCreature(*me, DoctorGUID)) + CAST_AI(npc_doctor::npc_doctorAI, doctor->AI())->PatientSaved(me, player, Coord); - //regen health - me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); + //make not selectable + me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); - //stand up - me->SetUInt32Value(UNIT_FIELD_BYTES_1, UNIT_STAND_STATE_STAND); + //regen health + me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); - Talk(SAY_DOC); + //stand up + me->SetUInt32Value(UNIT_FIELD_BYTES_1, UNIT_STAND_STATE_STAND); - uint32 mobId = me->GetEntry(); - me->SetWalk(false); + Talk(SAY_DOC); - switch (mobId) - { - case 12923: - case 12924: - case 12925: - me->GetMotionMaster()->MovePoint(0, H_RUNTOX, H_RUNTOY, H_RUNTOZ); - break; - case 12936: - case 12937: - case 12938: - me->GetMotionMaster()->MovePoint(0, A_RUNTOX, A_RUNTOY, A_RUNTOZ); - break; - } + uint32 mobId = me->GetEntry(); + me->SetWalk(false); + + switch (mobId) + { + case 12923: + case 12924: + case 12925: + me->GetMotionMaster()->MovePoint(0, H_RUNTOX, H_RUNTOY, H_RUNTOZ); + break; + case 12936: + case 12937: + case 12938: + me->GetMotionMaster()->MovePoint(0, A_RUNTOX, A_RUNTOY, A_RUNTOZ); + break; } } @@ -1749,52 +1750,53 @@ public: void ReceiveEmote(Player* player, uint32 emote) { me->HandleEmoteCommand(emote); - Unit* own = me->GetOwner(); - if (!own || own->GetTypeId() != TYPEID_PLAYER || CAST_PLR(own)->GetTeam() != player->GetTeam()) - return; - if (emote == TEXT_EMOTE_KISS) + Unit* owner = me->GetOwner(); + if (emote != TEXT_EMOTE_KISS || owner || owner->GetTypeId() != TYPEID_PLAYER || + owner->ToPlayer()->GetTeam() != player->GetTeam()) { - std::string whisp = ""; - switch (rand() % 8) - { - case 0: - whisp.append(SAY_RANDOM_MOJO0); - break; - case 1: - whisp.append(SAY_RANDOM_MOJO1); - break; - case 2: - whisp.append(SAY_RANDOM_MOJO2); - break; - case 3: - whisp.append(SAY_RANDOM_MOJO3); - break; - case 4: - whisp.append(SAY_RANDOM_MOJO4); - break; - case 5: - whisp.append(SAY_RANDOM_MOJO5); - break; - case 6: - whisp.append(SAY_RANDOM_MOJO6a); - whisp.append(player->GetName()); - whisp.append(SAY_RANDOM_MOJO6b); - break; - case 7: - whisp.append(SAY_RANDOM_MOJO7); - break; - } + return; + } - me->MonsterWhisper(whisp.c_str(), player->GetGUID()); - if (victimGUID) - if (Player* victim = Unit::GetPlayer(*me, victimGUID)) - victim->RemoveAura(43906);//remove polymorph frog thing - me->AddAura(43906, player);//add polymorph frog thing - victimGUID = player->GetGUID(); - DoCast(me, 20372, true);//tag.hearts - me->GetMotionMaster()->MoveFollow(player, 0, 0); - hearts = 15000; + std::string whisp = ""; + switch (rand() % 8) + { + case 0: + whisp.append(SAY_RANDOM_MOJO0); + break; + case 1: + whisp.append(SAY_RANDOM_MOJO1); + break; + case 2: + whisp.append(SAY_RANDOM_MOJO2); + break; + case 3: + whisp.append(SAY_RANDOM_MOJO3); + break; + case 4: + whisp.append(SAY_RANDOM_MOJO4); + break; + case 5: + whisp.append(SAY_RANDOM_MOJO5); + break; + case 6: + whisp.append(SAY_RANDOM_MOJO6a); + whisp.append(player->GetName()); + whisp.append(SAY_RANDOM_MOJO6b); + break; + case 7: + whisp.append(SAY_RANDOM_MOJO7); + break; } + + me->MonsterWhisper(whisp.c_str(), player->GetGUID()); + if (victimGUID) + if (Player* victim = Unit::GetPlayer(*me, victimGUID)) + victim->RemoveAura(43906); // remove polymorph frog thing + me->AddAura(43906, player); // add polymorph frog thing + victimGUID = player->GetGUID(); + DoCast(me, 20372, true); // tag.hearts + me->GetMotionMaster()->MoveFollow(player, 0, 0); + hearts = 15000; } }; |