diff options
Diffstat (limited to 'src')
101 files changed, 1283 insertions, 1833 deletions
diff --git a/src/server/authserver/Server/AuthSocket.cpp b/src/server/authserver/Server/AuthSocket.cpp index 1b0800e48ae..7b2ad044eb9 100755 --- a/src/server/authserver/Server/AuthSocket.cpp +++ b/src/server/authserver/Server/AuthSocket.cpp @@ -27,6 +27,7 @@ #include "AuthSocket.h" #include "AuthCodes.h" #include "SHA1.h" +#include "openssl/crypto.h" #define ChunkSize 2048 diff --git a/src/server/collision/BoundingIntervalHierarchy.h b/src/server/collision/BoundingIntervalHierarchy.h index 0dc597e98bc..cb6158e94eb 100755 --- a/src/server/collision/BoundingIntervalHierarchy.h +++ b/src/server/collision/BoundingIntervalHierarchy.h @@ -88,6 +88,7 @@ class BIH { if (primitives.empty()) return; + buildData dat; dat.maxPrims = leafSize; dat.numPrims = primitives.size(); diff --git a/src/server/collision/Models/WorldModel.cpp b/src/server/collision/Models/WorldModel.cpp index 55aad9bb029..118ae098c25 100644 --- a/src/server/collision/Models/WorldModel.cpp +++ b/src/server/collision/Models/WorldModel.cpp @@ -362,6 +362,7 @@ namespace VMAP { if (triangles.empty()) return false; + GModelRayCallback callback(triangles, vertices); meshTree.intersectRay(ray, callback, distance, stopAtFirstHit); return callback.hit; @@ -470,6 +471,7 @@ namespace VMAP { if (groupModels.empty()) return false; + WModelAreaCallback callback(groupModels, down); groupTree.intersectPoint(p, callback); if (callback.hit != groupModels.end()) @@ -488,6 +490,7 @@ namespace VMAP { if (groupModels.empty()) return false; + WModelAreaCallback callback(groupModels, down); groupTree.intersectPoint(p, callback); if (callback.hit != groupModels.end()) diff --git a/src/server/game/AI/EventAI/CreatureEventAI.cpp b/src/server/game/AI/EventAI/CreatureEventAI.cpp index 62d7a1f4f58..be0dd8c3679 100755 --- a/src/server/game/AI/EventAI/CreatureEventAI.cpp +++ b/src/server/game/AI/EventAI/CreatureEventAI.cpp @@ -1177,9 +1177,8 @@ inline Unit* CreatureEventAI::GetTargetByType(uint32 target, Unit* actionInvoker Unit* CreatureEventAI::DoSelectLowestHpFriendly(float range, uint32 minHPDiff) { - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Unit* unit = NULL; @@ -1199,9 +1198,8 @@ Unit* CreatureEventAI::DoSelectLowestHpFriendly(float range, uint32 minHPDiff) void CreatureEventAI::DoFindFriendlyCC(std::list<Creature*>& _list, float range) { - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::FriendlyCCedInRange u_check(me, range); @@ -1209,14 +1207,13 @@ void CreatureEventAI::DoFindFriendlyCC(std::list<Creature*>& _list, float range) TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::FriendlyCCedInRange>, GridTypeMapContainer > grid_creature_searcher(searcher); - cell.Visit(p, grid_creature_searcher, *me->GetMap()); + cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range); } void CreatureEventAI::DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid) { - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::FriendlyMissingBuffInRange u_check(me, range, spellid); @@ -1224,7 +1221,7 @@ void CreatureEventAI::DoFindFriendlyMissingBuff(std::list<Creature*>& _list, flo TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::FriendlyMissingBuffInRange>, GridTypeMapContainer > grid_creature_searcher(searcher); - cell.Visit(p, grid_creature_searcher, *me->GetMap()); + cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range); } // ********************************* diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 2322e88d105..953bbf7521a 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -363,16 +363,15 @@ Player* ScriptedAI::GetPlayerAtMinimumRange(float minimumRange) { Player* player = NULL; - CellPair pair(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord pair(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::PlayerAtMinimumRangeAway check(me, minimumRange); Trinity::PlayerSearcher<Trinity::PlayerAtMinimumRangeAway> searcher(me, player, check); TypeContainerVisitor<Trinity::PlayerSearcher<Trinity::PlayerAtMinimumRangeAway>, GridTypeMapContainer> visitor(searcher); - cell.Visit(pair, visitor, *(me->GetMap())); + cell.Visit(pair, visitor, *me->GetMap(), *me, minimumRange); return player; } diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index f210f077fdd..06c1570ccd9 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -218,7 +218,7 @@ void npc_escortAI::UpdateAI(uint32 const diff) if (m_bCanReturnToStart) { float fRetX, fRetY, fRetZ; - me->GetRespawnCoord(fRetX, fRetY, fRetZ); + me->GetRespawnPosition(fRetX, fRetY, fRetZ); me->GetMotionMaster()->MovePoint(POINT_HOME, fRetX, fRetY, fRetZ); diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 54c69080c41..143cb1f0ec1 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -2877,10 +2877,11 @@ uint32 SmartScript::DoChat(int8 id, uint64 whisperGuid) Unit* SmartScript::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) { - if (!me) return NULL; - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + if (!me) + return NULL; + + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Unit* unit = NULL; @@ -2896,10 +2897,11 @@ Unit* SmartScript::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) void SmartScript::DoFindFriendlyCC(std::list<Creature*>& _list, float range) { - if (!me) return; - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + if (!me) + return; + + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::FriendlyCCedInRange u_check(me, range); @@ -2907,15 +2909,16 @@ void SmartScript::DoFindFriendlyCC(std::list<Creature*>& _list, float range) TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::FriendlyCCedInRange>, GridTypeMapContainer > grid_creature_searcher(searcher); - cell.Visit(p, grid_creature_searcher, *me->GetMap()); + cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range); } void SmartScript::DoFindFriendlyMissingBuff(std::list<Creature*>& list, float range, uint32 spellid) { - if (!me) return; - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + if (!me) + return; + + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::FriendlyMissingBuffInRange u_check(me, range, spellid); @@ -2923,7 +2926,7 @@ void SmartScript::DoFindFriendlyMissingBuff(std::list<Creature*>& list, float ra TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::FriendlyMissingBuffInRange>, GridTypeMapContainer > grid_creature_searcher(searcher); - cell.Visit(p, grid_creature_searcher, *me->GetMap()); + cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range); } void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry) diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index aa4eeb602c0..03d04f4b3df 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -155,33 +155,31 @@ class SmartScript { GameObject* gameObject = NULL; - CellPair p(Trinity::ComputeCellPair(searchObject->GetPositionX(), searchObject->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid); Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(searchObject, gameObject, goCheck); TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > objectChecker(checker); - cell.Visit(p, objectChecker, *searchObject->GetMap()); + cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); return gameObject; } Creature* FindCreatureNear(WorldObject* searchObject, uint32 guid) const { - Creature* crea = NULL; - CellPair p(Trinity::ComputeCellPair(searchObject->GetPositionX(), searchObject->GetPositionY())); + Creature* creature = NULL; + CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::CreatureWithDbGUIDCheck target_check(searchObject, guid); - Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(searchObject, crea, target_check); + Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(searchObject, creature, target_check); TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); - cell.Visit(p, unit_checker, *searchObject->GetMap()); + cell.Visit(p, unit_checker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); - return crea; + return creature; } ObjectListMap* mTargetStorage; diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index fca4df12587..30f66925060 100755 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -666,10 +666,9 @@ void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement) // if player is in world he can tell his friends about new achievement else if (GetPlayer()->IsInWorld()) { - CellPair p = Trinity::ComputeCellPair(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AchievementChatBuilder say_builder(*GetPlayer(), CHAT_MSG_ACHIEVEMENT, LANG_ACHIEVEMENT_EARNED, achievement->ID); diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 339f2ebba3b..38fa2643601 100755 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -437,7 +437,7 @@ inline void Battleground::_ProcessJoin(uint32 diff) { m_Events |= BG_STARTING_EVENT_1; - if(!FindBgMap()) + if (!FindBgMap()) { sLog->outError("Battleground::_ProcessJoin: map (map id: %u, instance id: %u) is not created!", m_MapId, m_InstanceID); EndNow(); diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.h b/src/server/game/Battlegrounds/BattlegroundQueue.h index 10bff57a251..6b19c23ca68 100755 --- a/src/server/game/Battlegrounds/BattlegroundQueue.h +++ b/src/server/game/Battlegrounds/BattlegroundQueue.h @@ -103,6 +103,7 @@ class BattlegroundQueue class SelectionPool { public: + SelectionPool(): PlayerCount(0) {}; void Init(); bool AddGroup(GroupQueueInfo* ginfo, uint32 desiredCount); bool KickGroup(uint32 size); diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 8d03530c7f9..7d6e9f7a004 100755 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -1224,7 +1224,7 @@ GameObject* ChatHandler::GetNearbyGameObject() GameObject* obj = NULL; Trinity::NearestGameObjectCheck check(*pl); Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectCheck> searcher(pl, obj, check); - pl->VisitNearbyGridObject(999, searcher); + pl->VisitNearbyGridObject(SIZE_OF_GRIDS, searcher); return obj; } @@ -1240,15 +1240,14 @@ GameObject* ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid if (!obj && sObjectMgr->GetGOData(lowguid)) // guid is DB guid of object { // search near player then - CellPair p(Trinity::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(pl->GetPositionX(), pl->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::GameObjectWithDbGUIDCheck go_check(*pl, lowguid); Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(pl, obj, go_check); TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > object_checker(checker); - cell.Visit(p, object_checker, *pl->GetMap()); + cell.Visit(p, object_checker, *pl->GetMap(), *pl, pl->GetGridActivationRange()); } return obj; diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index e76cbfcc76b..9dda89a6972 100755 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -1859,6 +1859,12 @@ bool ChatHandler::HandleDamageCommand(const char * args) return false; } + if (target->GetTypeId() == TYPEID_PLAYER) + { + if (HasLowerSecurity((Player*)target, 0, false)) + return false; + } + if (!target->isAlive()) return true; @@ -2671,7 +2677,7 @@ bool ChatHandler::HandleResetAllCommand(const char * args) CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin); - ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true); + ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, *HashMapHolder<Player>::GetLock(), true); HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr) itr->second->SetAtLoginFlag(atLogin); @@ -3470,16 +3476,15 @@ bool ChatHandler::HandleRespawnCommand(const char* /*args*/) return true; } - CellPair p(Trinity::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(pl->GetPositionX(), pl->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::RespawnDo u_do; Trinity::WorldObjectWorker<Trinity::RespawnDo> worker(pl, u_do); TypeContainerVisitor<Trinity::WorldObjectWorker<Trinity::RespawnDo>, GridTypeMapContainer > obj_worker(worker); - cell.Visit(p, obj_worker, *pl->GetMap()); + cell.Visit(p, obj_worker, *pl->GetMap(), *pl, pl->GetGridActivationRange()); return true; } diff --git a/src/server/game/Entities/Corpse/Corpse.cpp b/src/server/game/Entities/Corpse/Corpse.cpp index cdd5d61b1c9..31cc21659c9 100755 --- a/src/server/game/Entities/Corpse/Corpse.cpp +++ b/src/server/game/Entities/Corpse/Corpse.cpp @@ -95,7 +95,7 @@ bool Corpse::Create(uint32 guidlow, Player* owner) SetFloatValue(OBJECT_FIELD_SCALE_X, 1); SetUInt64Value(CORPSE_FIELD_OWNER, owner->GetGUID()); - m_grid = Trinity::ComputeGridPair(GetPositionX(), GetPositionY()); + _gridCoord = Trinity::ComputeGridCoord(GetPositionX(), GetPositionY()); return true; } @@ -211,7 +211,7 @@ bool Corpse::LoadFromDB(uint32 guid, Field* fields) return false; } - m_grid = Trinity::ComputeGridPair(GetPositionX(), GetPositionY()); + _gridCoord = Trinity::ComputeGridCoord(GetPositionX(), GetPositionY()); return true; } diff --git a/src/server/game/Entities/Corpse/Corpse.h b/src/server/game/Entities/Corpse/Corpse.h index bd68eb688f5..2e45606b88f 100755 --- a/src/server/game/Entities/Corpse/Corpse.h +++ b/src/server/game/Entities/Corpse/Corpse.h @@ -70,8 +70,8 @@ class Corpse : public WorldObject, public GridObject<Corpse> void ResetGhostTime() { m_time = time(NULL); } CorpseType GetType() const { return m_type; } - GridPair const& GetGrid() const { return m_grid; } - void SetGrid(GridPair const& grid) { m_grid = grid; } + GridCoord const& GetGridCoord() const { return _gridCoord; } + void SetGridCoord(GridCoord const& gridCoord) { _gridCoord = gridCoord; } Loot loot; // remove insignia ONLY at BG Player* lootRecipient; @@ -88,7 +88,7 @@ class Corpse : public WorldObject, public GridObject<Corpse> private: CorpseType m_type; time_t m_time; - GridPair m_grid; // gride for corpse position for fast search + GridCoord _gridCoord; // gride for corpse position for fast search }; #endif diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 833fcd44554..3d6eaf1a198 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -137,14 +137,13 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) return true; } -Creature::Creature(): Unit(), +Creature::Creature(): Unit(), MapCreature(), lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLowGUID(0), m_PlayerDamageReq(0), m_lootMoney(0), m_lootRecipient(0), m_lootRecipientGroup(0), m_corpseRemoveTime(0), m_respawnTime(0), m_respawnDelay(300), m_corpseDelay(60), m_respawnradius(0.0f), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m_equipmentId(0), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_regenHealth(true), m_AI_locked(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), -m_creatureInfo(NULL), m_creatureData(NULL), m_formation(NULL), -MapCreature() +m_creatureInfo(NULL), m_creatureData(NULL), m_formation(NULL) { m_regenTimer = CREATURE_REGEN_INTERVAL; m_valuesCount = UNIT_END; @@ -246,7 +245,7 @@ void Creature::RemoveCorpse(bool setSpawnTime) m_respawnTime = time(NULL) + respawnDelay; float x, y, z, o; - GetRespawnCoord(x, y, z, &o); + GetRespawnPosition(x, y, z, &o); SetHomePosition(x, y, z, o); GetMap()->CreatureRelocation(this, x, y, z, o); } @@ -660,9 +659,8 @@ void Creature::DoFleeToGetAssistance() { Creature* creature = NULL; - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::NearestAssistCreatureInCreatureRangeCheck u_check(this, getVictim(), radius); Trinity::CreatureLastSearcher<Trinity::NearestAssistCreatureInCreatureRangeCheck> searcher(this, creature, u_check); @@ -1761,9 +1759,8 @@ SpellInfo const* Creature::reachWithSpellCure(Unit* pVictim) // select nearest hostile unit within the given distance (regardless of threat list). Unit* Creature::SelectNearestTarget(float dist) const { - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Unit* target = NULL; @@ -1788,9 +1785,8 @@ Unit* Creature::SelectNearestTarget(float dist) const // select nearest hostile unit within the given attack distance (i.e. distance is ignored if > than ATTACK_DISTANCE), regardless of threat list. Unit* Creature::SelectNearestTargetInAttackDistance(float dist) const { - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Unit* target = NULL; @@ -1851,9 +1847,8 @@ void Creature::CallAssistance() std::list<Creature*> assistList; { - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AnyAssistCreatureInRangeCheck u_check(this, getVictim(), radius); @@ -1879,22 +1874,21 @@ void Creature::CallAssistance() } } -void Creature::CallForHelp(float fRadius) +void Creature::CallForHelp(float radius) { - if (fRadius <= 0.0f || !getVictim() || isPet() || isCharmed()) + if (radius <= 0.0f || !getVictim() || isPet() || isCharmed()) return; - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - Trinity::CallOfHelpCreatureInRangeDo u_do(this, getVictim(), fRadius); + Trinity::CallOfHelpCreatureInRangeDo u_do(this, getVictim(), radius); Trinity::CreatureWorker<Trinity::CallOfHelpCreatureInRangeDo> worker(this, u_do); TypeContainerVisitor<Trinity::CreatureWorker<Trinity::CallOfHelpCreatureInRangeDo>, GridTypeMapContainer > grid_creature_searcher(worker); - cell.Visit(p, grid_creature_searcher, *GetMap(), *this, fRadius); + cell.Visit(p, grid_creature_searcher, *GetMap(), *this, radius); } bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /*= true*/) const @@ -2206,7 +2200,7 @@ time_t Creature::GetRespawnTimeEx() const return now; } -void Creature::GetRespawnCoord(float &x, float &y, float &z, float* ori, float* dist) const +void Creature::GetRespawnPosition(float &x, float &y, float &z, float* ori, float* dist) const { if (m_DBTableGuid) { diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 5a3c80234d8..9f5d8ec202e 100755 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -456,7 +456,7 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; } void Update(uint32 time); // overwrited Unit::Update - void GetRespawnCoord(float &x, float &y, float &z, float* ori = NULL, float* dist =NULL) const; + void GetRespawnPosition(float &x, float &y, float &z, float* ori = NULL, float* dist =NULL) const; uint32 GetEquipmentId() const { return GetCreatureInfo()->equipmentId; } void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; } diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 2f353285806..a894ee16c2d 100755 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -16,26 +16,14 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Common.h" -#include "QuestDef.h" #include "GameObjectAI.h" #include "ObjectMgr.h" #include "GroupMgr.h" #include "PoolMgr.h" #include "SpellMgr.h" -#include "Spell.h" -#include "UpdateMask.h" -#include "Opcodes.h" -#include "WorldPacket.h" #include "World.h" -#include "DatabaseEnv.h" -#include "LootMgr.h" -#include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "CellImpl.h" -#include "InstanceScript.h" -#include "Battleground.h" -#include "Util.h" #include "OutdoorPvPMgr.h" #include "BattlegroundAV.h" #include "ScriptMgr.h" @@ -73,15 +61,21 @@ GameObject::GameObject() : WorldObject(), m_goValue(new GameObjectValue), m_AI(N GameObject::~GameObject() { delete m_goValue; + delete m_AI; //if (m_uint32Values) // field array can be not exist if GameOBject not loaded // CleanupsBeforeDelete(); } bool GameObject::AIM_Initialize() { + if (m_AI) + delete m_AI; m_AI = FactorySelector::SelectGameObjectAI(this); - if (!m_AI) return false; + + if (!m_AI) + return false; + m_AI->InitializeAI(); return true; } @@ -608,10 +602,12 @@ void GameObject::Delete() { SetLootState(GO_NOT_READY); if (GetOwnerGUID()) + { if (Unit* owner = GetOwner()) owner->RemoveGameObject(this, false); else //! Owner not in world anymore SetOwnerGUID(0); + } ASSERT (!GetOwnerGUID()); SendObjectDeSpawnAnim(GetGUID()); @@ -935,9 +931,8 @@ void GameObject::TriggeringLinkedGameObject(uint32 trapEntry, Unit* target) GameObject* trapGO = NULL; { // using original GO distance - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::NearestGameObjectEntryInObjectRangeCheck go_check(*target, trapEntry, range); Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectEntryInObjectRangeCheck> checker(this, trapGO, go_check); @@ -955,9 +950,8 @@ GameObject* GameObject::LookupFishingHoleAround(float range) { GameObject* ok = NULL; - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::NearestGameObjectFishingHole u_check(*this, range); Trinity::GameObjectSearcher<Trinity::NearestGameObjectFishingHole> checker(this, ok, u_check); @@ -1539,12 +1533,11 @@ void GameObject::Use(Unit* user) { case 179785: // Silverwing Flag case 179786: // Warsong Flag - // check if it's correct bg - if (bg->IsRandom() ? bg->GetTypeID(true) : bg->GetTypeID(false) == BATTLEGROUND_WS) + if (bg->GetTypeID(true) == BATTLEGROUND_WS) bg->EventPlayerClickedOnFlag(player, this); break; case 184142: // Netherstorm Flag - if (bg->IsRandom() ? bg->GetTypeID(true) : bg->GetTypeID(false) == BATTLEGROUND_EY) + if (bg->GetTypeID(true) == BATTLEGROUND_EY) bg->EventPlayerClickedOnFlag(player, this); break; } diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp index d3832ad9151..07275166130 100755 --- a/src/server/game/Entities/Item/Item.cpp +++ b/src/server/game/Entities/Item/Item.cpp @@ -1194,25 +1194,23 @@ bool Item::IsRefundExpired() return (GetPlayedTime() > 2*HOUR); } -void Item::SetSoulboundTradeable(AllowedLooterSet* allowedLooters, Player* currentOwner, bool apply) +void Item::SetSoulboundTradeable(AllowedLooterSet& allowedLooters) { - if (apply) - { - SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); - allowedGUIDs = *allowedLooters; - } - else - { - RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); - if (allowedGUIDs.empty()) - return; + SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); + allowedGUIDs = allowedLooters; +} - allowedGUIDs.clear(); - SetState(ITEM_CHANGED, currentOwner); - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_BOP_TRADE); - stmt->setUInt32(0, GetGUIDLow()); - CharacterDatabase.Execute(stmt); - } +void Item::ClearSoulboundTradeable(Player* currentOwner) +{ + RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_BOP_TRADEABLE); + if (allowedGUIDs.empty()) + return; + + allowedGUIDs.clear(); + SetState(ITEM_CHANGED, currentOwner); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_BOP_TRADE); + stmt->setUInt32(0, GetGUIDLow()); + CharacterDatabase.Execute(stmt); } bool Item::CheckSoulboundTradeExpire() @@ -1220,7 +1218,7 @@ bool Item::CheckSoulboundTradeExpire() // called from owner's update - GetOwner() MUST be valid if (GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + 2*HOUR < GetOwner()->GetTotalPlayedTime()) { - SetSoulboundTradeable(NULL, GetOwner(), false); + ClearSoulboundTradeable(GetOwner()); return true; // remove from tradeable list } diff --git a/src/server/game/Entities/Item/Item.h b/src/server/game/Entities/Item/Item.h index b872b354ea7..4a72e7fea2b 100755 --- a/src/server/game/Entities/Item/Item.h +++ b/src/server/game/Entities/Item/Item.h @@ -352,7 +352,8 @@ class Item : public Object bool IsRefundExpired(); // Soulbound trade system - void SetSoulboundTradeable(AllowedLooterSet* allowedLooters, Player* currentOwner, bool apply); + void SetSoulboundTradeable(AllowedLooterSet& allowedLooters); + void ClearSoulboundTradeable(Player* currentOwner); bool CheckSoulboundTradeExpire(); void BuildUpdate(UpdateDataMapType&); diff --git a/src/server/game/Entities/Item/ItemPrototype.h b/src/server/game/Entities/Item/ItemPrototype.h index 155673edbaa..03212c129fd 100755 --- a/src/server/game/Entities/Item/ItemPrototype.h +++ b/src/server/game/Entities/Item/ItemPrototype.h @@ -729,7 +729,6 @@ struct ItemTemplate bool IsWeaponVellum() const { return Class == ITEM_CLASS_TRADE_GOODS && SubClass == ITEM_SUBCLASS_WEAPON_ENCHANTMENT; } bool IsArmorVellum() const { return Class == ITEM_CLASS_TRADE_GOODS && SubClass == ITEM_SUBCLASS_ARMOR_ENCHANTMENT; } bool IsConjuredConsumable() const { return Class == ITEM_CLASS_CONSUMABLE && (Flags & ITEM_PROTO_FLAG_CONJURED); } - }; // Benchmarked: Faster than std::map (insert/find) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index c55892c6f82..3bbe06dd4fb 100755 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1868,10 +1868,9 @@ namespace Trinity void WorldObject::MonsterSay(const char* text, uint32 language, uint64 TargetGuid) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::MonsterCustomChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, text, language, TargetGuid); @@ -1883,10 +1882,9 @@ void WorldObject::MonsterSay(const char* text, uint32 language, uint64 TargetGui void WorldObject::MonsterSay(int32 textId, uint32 language, uint64 TargetGuid) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, textId, language, TargetGuid); @@ -1898,10 +1896,9 @@ void WorldObject::MonsterSay(int32 textId, uint32 language, uint64 TargetGuid) void WorldObject::MonsterYell(const char* text, uint32 language, uint64 TargetGuid) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::MonsterCustomChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, text, language, TargetGuid); @@ -1913,10 +1910,9 @@ void WorldObject::MonsterYell(const char* text, uint32 language, uint64 TargetGu void WorldObject::MonsterYell(int32 textId, uint32 language, uint64 TargetGuid) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId, language, TargetGuid); @@ -1948,10 +1944,9 @@ void WorldObject::MonsterTextEmote(const char* text, uint64 TargetGuid, bool IsB void WorldObject::MonsterTextEmote(int32 textId, uint64 TargetGuid, bool IsBossEmote) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::MonsterChatBuilder say_build(*this, IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, textId, LANG_UNIVERSAL, TargetGuid); @@ -2393,32 +2388,30 @@ GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range) const return go; } -void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange) const +void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>& gameobjectList, uint32 entry, float maxSearchRange) const { - CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY())); + CellCoord pair(Trinity::ComputeCellCoord(this->GetPositionX(), this->GetPositionY())); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - Trinity::AllGameObjectsWithEntryInRange check(this, uiEntry, fMaxSearchRange); - Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange> searcher(this, lList, check); + Trinity::AllGameObjectsWithEntryInRange check(this, entry, maxSearchRange); + Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange> searcher(this, gameobjectList, check); TypeContainerVisitor<Trinity::GameObjectListSearcher<Trinity::AllGameObjectsWithEntryInRange>, GridTypeMapContainer> visitor(searcher); - cell.Visit(pair, visitor, *(this->GetMap())); + cell.Visit(pair, visitor, *(this->GetMap()), *this, maxSearchRange); } -void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange) const +void WorldObject::GetCreatureListWithEntryInGrid(std::list<Creature*>& creatureList, uint32 entry, float maxSearchRange) const { - CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY())); + CellCoord pair(Trinity::ComputeCellCoord(this->GetPositionX(), this->GetPositionY())); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - Trinity::AllCreaturesOfEntryInRange check(this, uiEntry, fMaxSearchRange); - Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(this, lList, check); + Trinity::AllCreaturesOfEntryInRange check(this, entry, maxSearchRange); + Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(this, creatureList, check); TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> visitor(searcher); - cell.Visit(pair, visitor, *(this->GetMap())); + cell.Visit(pair, visitor, *(this->GetMap()), *this, maxSearchRange); } /* @@ -2529,9 +2522,8 @@ void WorldObject::GetNearPoint(WorldObject const* /*searcher*/, float &x, float // adding used positions around object { - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::NearUsedPosDo u_do(*this, searcher, absAngle, selector); @@ -2826,9 +2818,8 @@ struct WorldObjectChangeAccumulator void WorldObject::BuildUpdate(UpdateDataMapType& data_map) { - CellPair p = Trinity::ComputeCellPair(GetPositionX(), GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); WorldObjectChangeAccumulator notifier(*this, data_map); TypeContainerVisitor<WorldObjectChangeAccumulator, WorldTypeMapContainer > player_notifier(notifier); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 7bcd785554e..dfcf6a3cfa4 100755 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -793,9 +793,9 @@ class WorldObject : public Object, public WorldLocation bool isActiveObject() const { return m_isActive; } void setActive(bool isActiveObject); void SetWorldObject(bool apply); - template<class NOTIFIER> void VisitNearbyObject(const float &radius, NOTIFIER ¬ifier) const { if (IsInWorld()) GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); } - template<class NOTIFIER> void VisitNearbyGridObject(const float &radius, NOTIFIER ¬ifier) const { if (IsInWorld()) GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); } - template<class NOTIFIER> void VisitNearbyWorldObject(const float &radius, NOTIFIER ¬ifier) const { if (IsInWorld()) GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); } + template<class NOTIFIER> void VisitNearbyObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); } + template<class NOTIFIER> void VisitNearbyGridObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); } + template<class NOTIFIER> void VisitNearbyWorldObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); } #ifdef MAP_BASED_RAND_GEN int32 irand(int32 min, int32 max) const { return int32 (GetMap()->mtRand.randInt(max - min)) + min; } diff --git a/src/server/game/Entities/Object/Updates/UpdateMask.h b/src/server/game/Entities/Object/Updates/UpdateMask.h index 09bc0b4cc80..abe3c299062 100755 --- a/src/server/game/Entities/Object/Updates/UpdateMask.h +++ b/src/server/game/Entities/Object/Updates/UpdateMask.h @@ -72,6 +72,9 @@ class UpdateMask UpdateMask& operator = (const UpdateMask& mask) { + if (this == &mask) + return *this; + SetCount(mask.mCount); memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 203f52ca7c5..27713586b54 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1148,7 +1148,7 @@ bool Player::Create(uint32 guidlow, CharacterCreateInfo* createInfo) } } - for (PlayerCreateInfoItems::const_iterator item_id_itr = info->item.begin(); item_id_itr != info->item.end(); ++item_id_itr++) + for (PlayerCreateInfoItems::const_iterator item_id_itr = info->item.begin(); item_id_itr != info->item.end(); ++item_id_itr) StoreNewItemInBestSlots(item_id_itr->item_id, item_id_itr->item_amount); // bags and main-hand weapon must equipped at this moment @@ -2456,7 +2456,7 @@ void Player::RegenerateAll() // Runes act as cooldowns, and they don't need to send any data if (getClass() == CLASS_DEATH_KNIGHT) - for (uint32 i = 0; i < MAX_RUNES; ++i) + for (uint8 i = 0; i < MAX_RUNES; ++i) if (uint32 cd = GetRuneCooldown(i)) SetRuneCooldown(i, (cd > m_regenTimer) ? cd - m_regenTimer : 0); @@ -2860,7 +2860,6 @@ void Player::SetGMVisible(bool on) if (on) { m_ExtraFlags &= ~PLAYER_EXTRA_GM_INVISIBLE; //remove flag - m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER); } else @@ -5063,7 +5062,7 @@ void Player::BuildPlayerRepop() StopMirrorTimers(); //disable timers(bars) - SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, (float)1.0f); //see radius of death player? + SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, float(1.0f)); //see radius of death player? // set and clear other SetByteValue(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_ALWAYS_STAND); @@ -9533,7 +9532,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid) // End Round (timer), better explain this by example, eg. ends in 19:59 -> A:BC data << uint32(0xde9) << uint32(0x0); // 16 3561 C data << uint32(0xde8) << uint32(0x0); // 17 3560 B - data << uint32(0xde7) << uint32(0x0); // 18 3559 A + data << uint32(0xde7) << uint32(0x0); // 18 3559 A data << uint32(0xe35) << uint32(0x0); // 19 3637 East g - Horde control data << uint32(0xe34) << uint32(0x0); // 20 3636 West g - Horde control data << uint32(0xe33) << uint32(0x0); // 21 3635 South g - Horde control @@ -11898,8 +11897,14 @@ void Player::RemoveAmmo() UpdateDamagePhysical(RANGED_ATTACK); } +Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId) +{ + AllowedLooterSet allowedLooters; + return StoreNewItem(dest, item, update, randomPropertyId, allowedLooters); +} + // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case. -Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet* allowedLooters) +Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet& allowedLooters) { uint32 count = 0; for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr) @@ -11919,16 +11924,18 @@ Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update if (proto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_NO_DELAY_USE && proto->Spells[i].SpellId > 0) // On obtain trigger CastSpell(this, proto->Spells[i].SpellId, true, pItem); - if (allowedLooters && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound()) + if (allowedLooters.size() > 1 && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound()) { - pItem->SetSoulboundTradeable(allowedLooters, this, true); + pItem->SetSoulboundTradeable(allowedLooters); pItem->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime()); m_itemSoulboundTradeable.push_back(pItem); // save data std::ostringstream ss; - for (AllowedLooterSet::iterator itr = allowedLooters->begin(); itr != allowedLooters->end(); ++itr) - ss << *itr << ' '; + AllowedLooterSet::const_iterator itr = allowedLooters.begin(); + ss << *itr; + for (++itr; itr != allowedLooters.end(); ++itr) + ss << ' ' << *itr; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_ITEM_BOP_TRADE); stmt->setUInt32(0, pItem->GetGUIDLow()); @@ -12051,7 +12058,7 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool pItem->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); pItem->SetState(ITEM_REMOVED, this); } @@ -12168,7 +12175,7 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) pItem->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); pItem->SetState(ITEM_REMOVED, this); pItem2->SetState(ITEM_CHANGED, this); @@ -12388,7 +12395,7 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) RemoveItemDurations(pItem); pItem->SetNotRefundable(this); - pItem->SetSoulboundTradeable(NULL, this, false); + pItem->ClearSoulboundTradeable(this); RemoveTradeableItem(pItem); const ItemTemplate* proto = pItem->GetTemplate(); @@ -13335,17 +13342,17 @@ void Player::UpdateSoulboundTradeItems() { if (!*itr) { - itr = m_itemSoulboundTradeable.erase(itr++); + m_itemSoulboundTradeable.erase(itr++); continue; } if ((*itr)->GetOwnerGUID() != GetGUID()) { - itr = m_itemSoulboundTradeable.erase(itr++); + m_itemSoulboundTradeable.erase(itr++); continue; } if ((*itr)->CheckSoulboundTradeExpire()) { - itr = m_itemSoulboundTradeable.erase(itr++); + m_itemSoulboundTradeable.erase(itr++); continue; } ++itr; @@ -13591,7 +13598,7 @@ void Player::ApplyEnchantment(Item* item, EnchantmentSlot slot, bool apply, bool } } } - // Cast custom spell vs all equal basepoints getted from enchant_amount + // Cast custom spell vs all equal basepoints got from enchant_amount if (basepoints) CastCustomSpell(this, enchant_spell_id, &basepoints, &basepoints, &basepoints, true, item); else @@ -14581,8 +14588,7 @@ bool Player::CanCompleteQuest(uint32 quest_id) if (!qInfo) return false; - RewardedQuestSet::iterator rewItr = m_RewardedQuests.find(quest_id); - if (!qInfo->IsRepeatable() && rewItr != m_RewardedQuests.end()) + if (!qInfo->IsRepeatable() && m_RewardedQuests.find(quest_id) != m_RewardedQuests.end()) return false; // not allow re-complete quest // auto complete quest @@ -14911,8 +14917,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver, if (log_slot < MAX_QUEST_LOG_SIZE) SetQuestSlot(log_slot, 0); - RewardedQuestSet::const_iterator rewItr = m_RewardedQuests.find(quest_id); - bool rewarded = (rewItr != m_RewardedQuests.end()); + bool rewarded = (m_RewardedQuests.find(quest_id) != m_RewardedQuests.end()); // Not give XP in case already completed once repeatable quest uint32 XP = rewarded ? 0 : uint32(quest->XPValue(this)*sWorld->getRate(RATE_XP_QUEST)); @@ -15661,11 +15666,11 @@ void Player::GroupEventHappens(uint32 questId, WorldObject const* pEventObject) { for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) { - Player* pGroupGuy = itr->getSource(); + Player* player = itr->getSource(); // for any leave or dead (with not released body) group member at appropriate distance - if (pGroupGuy && pGroupGuy->IsAtGroupRewardDistance(pEventObject) && !pGroupGuy->GetCorpse()) - pGroupGuy->AreaExploredOrEventHappens(questId); + if (player && player->IsAtGroupRewardDistance(pEventObject) && !player->GetCorpse()) + player->AreaExploredOrEventHappens(questId); } } else @@ -17474,7 +17479,7 @@ Item* Player::_LoadItem(SQLTransaction& trans, uint32 zoneId, uint32 timeDiff, F AllowedLooterSet looters; for (Tokens::iterator itr = GUIDlist.begin(); itr != GUIDlist.end(); ++itr) looters.insert(atol(*itr)); - item->SetSoulboundTradeable(&looters, this, true); + item->SetSoulboundTradeable(looters); m_itemSoulboundTradeable.push_back(item); } else @@ -19795,7 +19800,7 @@ void Player::RemoveSpellMods(Spell* spell) for (uint8 i=0; i<MAX_SPELLMOD; ++i) { - for (SpellModList::iterator itr = m_spellMods[i].begin(); itr != m_spellMods[i].end();) + for (SpellModList::const_iterator itr = m_spellMods[i].begin(); itr != m_spellMods[i].end();) { SpellModifier* mod = *itr; ++itr; @@ -19827,8 +19832,7 @@ void Player::DropModCharge(SpellModifier* mod, Spell* spell) if (spell && mod->ownerAura && mod->charges > 0) { - --mod->charges; - if (mod->charges == 0) + if (--mod->charges == 0) mod->charges = -1; spell->m_appliedMods.insert(mod->ownerAura); @@ -21496,7 +21500,7 @@ void Player::SendInitialPacketsBeforeAddToMap() data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4); data << uint32(secsToTimeBitFields(sWorld->GetGameTime())); - data << (float)0.01666667f; // game speed + data << float(0.01666667f); // game speed data << uint32(0); // added in 3.1.2 GetSession()->SendPacket(&data); @@ -21541,7 +21545,7 @@ void Player::SendInitialPacketsAfterAddToMap() if (HasAuraType(SPELL_AURA_MOD_STUN)) SetMovement(MOVE_ROOT); - // manual send package (have code in HandleEffect(this, AURA_EFFECT_HANDLE_SEND_FOR_CLIENT, true); that don't must be re-applied. + // manual send package (have code in HandleEffect(this, AURA_EFFECT_HANDLE_SEND_FOR_CLIENT, true); that must not be re-applied. if (HasAuraType(SPELL_AURA_MOD_ROOT)) { WorldPacket data2(SMSG_FORCE_MOVE_ROOT, 10); @@ -22320,27 +22324,27 @@ bool Player::GetsRecruitAFriendBonus(bool forXP) { for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) { - Player* pGroupGuy = itr->getSource(); - if (!pGroupGuy) + Player* player = itr->getSource(); + if (!player) continue; - if (!pGroupGuy->IsAtRecruitAFriendDistance(this)) + if (!player->IsAtRecruitAFriendDistance(this)) continue; // member (alive or dead) or his corpse at req. distance if (forXP) { // level must be allowed to get RaF bonus - if (pGroupGuy->getLevel() > sWorld->getIntConfig(CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL)) + if (player->getLevel() > sWorld->getIntConfig(CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL)) continue; // level difference must be small enough to get RaF bonus, UNLESS we are lower level - if (pGroupGuy->getLevel() < getLevel()) - if (uint8(getLevel() - pGroupGuy->getLevel()) > sWorld->getIntConfig(CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL_DIFFERENCE)) + if (player->getLevel() < getLevel()) + if (uint8(getLevel() - player->getLevel()) > sWorld->getIntConfig(CONFIG_MAX_RECRUIT_A_FRIEND_BONUS_PLAYER_LEVEL_DIFFERENCE)) continue; } - bool ARecruitedB = (pGroupGuy->GetSession()->GetRecruiterId() == GetSession()->GetAccountId()); - bool BRecruitedA = (GetSession()->GetRecruiterId() == pGroupGuy->GetSession()->GetAccountId()); + bool ARecruitedB = (player->GetSession()->GetRecruiterId() == GetSession()->GetAccountId()); + bool BRecruitedA = (GetSession()->GetRecruiterId() == player->GetSession()->GetAccountId()); if (ARecruitedB || BRecruitedA) { recruitAFriend = true; @@ -22368,16 +22372,16 @@ void Player::RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject* pRewar { for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) { - Player* pGroupGuy = itr->getSource(); - if (!pGroupGuy) + Player* player = itr->getSource(); + if (!player) continue; - if (!pGroupGuy->IsAtGroupRewardDistance(pRewardSource)) + if (!player->IsAtGroupRewardDistance(pRewardSource)) continue; // member (alive or dead) or his corpse at req. distance // quest objectives updated only for alive group member or dead but with not released body - if (pGroupGuy->isAlive()|| !pGroupGuy->GetCorpse()) - pGroupGuy->KilledMonsterCredit(creature_id, creature_guid); + if (player->isAlive()|| !player->GetCorpse()) + player->KilledMonsterCredit(creature_id, creature_guid); } } else // if (!group) @@ -22779,10 +22783,6 @@ bool ItemPosCount::isContainedIn(ItemPosCountVec const& vec) const return false; } -// *********************************** -// -------------TRINITY--------------- -// *********************************** - void Player::StopCastingBindSight() { if (WorldObject* target = GetViewpoint()) @@ -23128,7 +23128,7 @@ void Player::InitRunes() m_runes->runeState = 0; m_runes->lastUsedRune = RUNE_BLOOD; - for (uint32 i = 0; i < MAX_RUNES; ++i) + for (uint8 i = 0; i < MAX_RUNES; ++i) { SetBaseRune(i, runeSlotTypes[i]); // init base types SetCurrentRune(i, runeSlotTypes[i]); // init current types @@ -23137,13 +23137,13 @@ void Player::InitRunes() m_runes->SetRuneState(i); } - for (uint32 i = 0; i < NUM_RUNE_TYPES; ++i) + for (uint8 i = 0; i < NUM_RUNE_TYPES; ++i) SetFloatValue(PLAYER_RUNE_REGEN_1 + i, 0.1f); } bool Player::IsBaseRuneSlotsOnCooldown(RuneType runeType) const { - for (uint32 i = 0; i < MAX_RUNES; ++i) + for (uint8 i = 0; i < MAX_RUNES; ++i) if (GetBaseRune(i) == runeType && GetRuneCooldown(i) == 0) return false; @@ -23202,8 +23202,8 @@ void Player::StoreLootItem(uint8 lootSlot, Loot* loot) InventoryResult msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, item->itemid, item->count); if (msg == EQUIP_ERR_OK) { - AllowedLooterSet* looters = item->GetAllowedLooters(); - Item* newitem = StoreNewItem(dest, item->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + Item* newitem = StoreNewItem(dest, item->itemid, true, item->randomPropertyId, looters); if (qitem) { @@ -24716,7 +24716,7 @@ float Player::GetAverageItemLevel() if (m_items[i] && m_items[i]->GetTemplate()) sum += m_items[i]->GetTemplate()->GetItemLevelIncludingQuality(); - count++; + ++count; } return ((float)sum) / count; diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index a5067a66d55..7d0803a4c8a 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -743,8 +743,8 @@ enum RestType enum DuelCompleteType { DUEL_INTERRUPTED = 0, - DUEL_WON = 1, - DUEL_FLED = 2 + DUEL_WON = 1, + DUEL_FLED = 2 }; enum TeleportToOptions @@ -1269,8 +1269,8 @@ class Player : public Unit, public GridObject<Player> bool HasItemTotemCategory(uint32 TotemCategory) const; InventoryResult CanUseItem(ItemTemplate const* pItem) const; InventoryResult CanUseAmmo(uint32 item) const; - - Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0, AllowedLooterSet* allowedLooters = NULL); + Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0); + Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet &allowedLooters); Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update); Item* EquipNewItem(uint16 pos, uint32 item, bool update); Item* EquipItem(uint16 pos, Item* pItem, bool update); diff --git a/src/server/game/Entities/Totem/Totem.cpp b/src/server/game/Entities/Totem/Totem.cpp index 10c54720350..97629e802d4 100755 --- a/src/server/game/Entities/Totem/Totem.cpp +++ b/src/server/game/Entities/Totem/Totem.cpp @@ -86,9 +86,10 @@ void Totem::InitStats(uint32 duration) void Totem::InitSummon() { - // use AddAura instead of CastSpell - this in fact should be an AddSpell equivalent for creatures, but nothing like that exists so far. if (m_type == TOTEM_PASSIVE) - AddAura(GetSpell(), this); + { + CastSpell(this, GetSpell(), true); + } // Some totems can have both instant effect and passive spell if (GetSpell(1)) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 6439229de9c..c88f18d9131 100755 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4425,14 +4425,26 @@ int32 Unit::GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const { + std::map<SpellGroup, int32> SameEffectSpellGroup; float multiplier = 1.0f; AuraEffectList const& mTotalAuraList = GetAuraEffectsByType(auratype); for (AuraEffectList::const_iterator i = mTotalAuraList.begin(); i != mTotalAuraList.end(); ++i) { - if ((*i)->GetMiscValue()& misc_mask) - AddPctN(multiplier, (*i)->GetAmount()); + if (((*i)->GetMiscValue() & misc_mask)) + { + // Check if the Aura Effect has a the Same Effect Stack Rule and if so, use the highest amount of that SpellGroup + // If the Aura Effect does not have this Stack Rule, it returns false so we can add to the multiplier as usual + if (!sSpellMgr->AddSameEffectStackRuleSpellGroups((*i)->GetSpellInfo(), (*i)->GetAmount(), SameEffectSpellGroup)) + AddPctN(multiplier, (*i)->GetAmount()); + } + } + // Add the highest of the Same Effect Stack Rule SpellGroups to the multiplier + for (std::map<SpellGroup, int32>::const_iterator itr = SameEffectSpellGroup.begin(); itr != SameEffectSpellGroup.end(); ++itr) + { + AddPctN(multiplier, itr->second); } + return multiplier; } @@ -10599,11 +10611,6 @@ uint32 Unit::SpellDamageBonus(Unit* victim, SpellInfo const* spellProto, uint32 AddPctF(TakenTotalMod, std::max(mod, float((*i)->GetAmount()))); } break; - // Ebon Plague - case 1933: - if ((*i)->GetMiscValue() & (spellProto ? spellProto->GetSchoolMask() : 0)) - AddPctN(TakenTotalMod, (*i)->GetAmount()); - break; } } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index d35298b9963..064542bb013 100755 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1503,6 +1503,20 @@ class Unit : public WorldObject } virtual uint32 GetShieldBlockValue() const =0; + uint32 GetShieldBlockValue(uint32 soft_cap, uint32 hard_cap) const + { + uint32 value = GetShieldBlockValue(); + if (value >= hard_cap) + { + value = (soft_cap + hard_cap) / 2; + } + else if (value > soft_cap) + { + value = soft_cap + ((value - soft_cap) / 2); + } + + return value; + } uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; } uint32 GetDefenseSkillValue(Unit const* target = NULL) const; uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const; diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index cb42b898406..2570e50c55a 100755 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -1172,7 +1172,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id) // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use spawn coords to spawn - if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) + if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY)) { Creature* creature = new Creature; //sLog->outDebug("Spawning creature %u", *itr); @@ -1201,7 +1201,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid - if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) + if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //sLog->outDebug("Spawning gameobject %u", *itr); diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index f98702d4393..84d27efc8d9 100755 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -165,9 +165,9 @@ Unit* ObjectAccessor::FindUnit(uint64 guid) Player* ObjectAccessor::FindPlayerByName(const char* name) { - ACE_GUARD_RETURN(LockType, g, *HashMapHolder<Player>::GetLock(), NULL); - HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer(); - for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter) + ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock(), NULL); + HashMapHolder<Player>::MapType const& m = GetPlayers(); + for (HashMapHolder<Player>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter) if (iter->second->IsInWorld() && strcmp(name, iter->second->GetName()) == 0) return iter->second; @@ -176,9 +176,9 @@ Player* ObjectAccessor::FindPlayerByName(const char* name) void ObjectAccessor::SaveAllPlayers() { - ACE_GUARD(LockType, g, *HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer(); - for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr) + ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock()); + HashMapHolder<Player>::MapType const& m = GetPlayers(); + for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) itr->second->SaveToDB(); } @@ -216,8 +216,8 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse) return; // build mapid*cellid -> guid_set map - CellPair cell_pair = Trinity::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); - uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY()); + uint32 cell_id = (cellCoord.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; sObjectMgr->DeleteCorpseCellData(corpse->GetMapId(), cell_id, GUID_LOPART(corpse->GetOwnerGUID())); @@ -237,20 +237,20 @@ void ObjectAccessor::AddCorpse(Corpse* corpse) i_player2corpse[corpse->GetOwnerGUID()] = corpse; // build mapid*cellid -> guid_set map - CellPair cell_pair = Trinity::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); - uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY()); + uint32 cell_id = (cellCoord.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; sObjectMgr->AddCorpseCellData(corpse->GetMapId(), cell_id, GUID_LOPART(corpse->GetOwnerGUID()), corpse->GetInstanceId()); } } -void ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map) +void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map) { ACE_GUARD(LockType, g, i_corpseGuard); for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter) { - if (iter->second->GetGrid() == gridpair) + if (iter->second->GetGridCoord() == gridpair) { // verify, if the corpse in our instance (add only corpses which are) if (map->Instanceable()) @@ -301,7 +301,7 @@ Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia for (uint8 i = OBJECT_FIELD_TYPE + 1; i < CORPSE_END; ++i) // don't overwrite guid and object type bones->SetUInt32Value(i, corpse->GetUInt32Value(i)); - bones->SetGrid(corpse->GetGrid()); + bones->SetGridCoord(corpse->GetGridCoord()); // bones->m_time = m_time; // don't overwrite time // bones->m_type = m_type; // don't overwrite type bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation()); @@ -380,7 +380,7 @@ void ObjectAccessor::UnloadAll() /// Define the static members of HashMapHolder template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap; -template <class T> ACE_Thread_Mutex HashMapHolder<T>::i_lock; +template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock; /// Global definitions for the hashmap storage diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h index a9be8b4971f..ae88ae3673f 100755 --- a/src/server/game/Globals/ObjectAccessor.h +++ b/src/server/game/Globals/ObjectAccessor.h @@ -48,23 +48,23 @@ class HashMapHolder public: typedef UNORDERED_MAP<uint64, T*> MapType; - typedef ACE_Thread_Mutex LockType; + typedef ACE_RW_Thread_Mutex LockType; static void Insert(T* o) { - ACE_GUARD(LockType, Guard, i_lock); + ACE_WRITE_GUARD(LockType, Guard, i_lock); m_objectMap[o->GetGUID()] = o; } static void Remove(T* o) { - ACE_GUARD(LockType, Guard, i_lock); + ACE_WRITE_GUARD(LockType, Guard, i_lock); m_objectMap.erase(o->GetGUID()); } static T* Find(uint64 guid) { - ACE_GUARD_RETURN(LockType, Guard, i_lock, NULL); + ACE_READ_GUARD_RETURN(LockType, Guard, i_lock, NULL); typename MapType::iterator itr = m_objectMap.find(guid); return (itr != m_objectMap.end()) ? itr->second : NULL; } @@ -155,15 +155,15 @@ class ObjectAccessor if (!obj || obj->GetMapId() != mapid) return NULL; - CellPair p = Trinity::ComputeCellPair(x, y); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(x, y); + if (!p.IsCoordValid()) { sLog->outError("ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord); return NULL; } - CellPair q = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if (q.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || q.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord q = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + if (!q.IsCoordValid()) { sLog->outError("ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord); return NULL; @@ -198,22 +198,22 @@ class ObjectAccessor Player* FindPlayerByName(const char* name); // when using this, you must use the hashmapholder's lock - HashMapHolder<Player>::MapType& GetPlayers() + HashMapHolder<Player>::MapType const& GetPlayers() const { return HashMapHolder<Player>::GetContainer(); } // when using this, you must use the hashmapholder's lock - HashMapHolder<Creature>::MapType& GetCreatures() - { - return HashMapHolder<Creature>::GetContainer(); - } + //HashMapHolder<Creature>::MapType& GetCreatures() + //{ + // return HashMapHolder<Creature>::GetContainer(); + //} - // when using this, you must use the hashmapholder's lock - HashMapHolder<GameObject>::MapType& GetGameObjects() - { - return HashMapHolder<GameObject>::GetContainer(); - } + //// when using this, you must use the hashmapholder's lock + //HashMapHolder<GameObject>::MapType& GetGameObjects() + //{ + // return HashMapHolder<GameObject>::GetContainer(); + //} template<class T> void AddObject(T* object) { @@ -250,7 +250,7 @@ class ObjectAccessor Corpse* GetCorpseForPlayerGUID(uint64 guid); void RemoveCorpse(Corpse* corpse); void AddCorpse(Corpse* corpse); - void AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map); + void AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map); Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false); void RemoveOldCorpses(); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index ae7e2d57991..e1ff0821bf8 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -1568,8 +1568,8 @@ void ObjectMgr::AddCreatureToGrid(uint32 guid, CreatureData const* data) { if (mask & 1) { - CellPair cell_pair = Trinity::ComputeCellPair(data->posX, data->posY); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(data->posX, data->posY); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids& cell_guids = mMapObjectGuids[MAKE_PAIR32(data->mapid, i)][cell_id]; cell_guids.creatures.insert(guid); @@ -1584,8 +1584,8 @@ void ObjectMgr::RemoveCreatureFromGrid(uint32 guid, CreatureData const* data) { if (mask & 1) { - CellPair cell_pair = Trinity::ComputeCellPair(data->posX, data->posY); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(data->posX, data->posY); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids& cell_guids = mMapObjectGuids[MAKE_PAIR32(data->mapid, i)][cell_id]; cell_guids.creatures.erase(guid); @@ -1627,7 +1627,7 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float // Spawn if necessary (loaded grids only) // We use spawn coords to spawn - if (!map->Instanceable() && map->IsLoaded(x, y)) + if (!map->Instanceable() && map->IsGridLoaded(x, y)) { GameObject* go = new GameObject; if (!go->LoadFromDB(guid, map)) @@ -1663,7 +1663,7 @@ bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos) if (Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(mapId))) { // We use spawn coords to spawn - if (!map->Instanceable() && map->IsLoaded(data.posX, data.posY)) + if (!map->Instanceable() && map->IsGridLoaded(data.posX, data.posY)) { Creature* creature = new Creature; if (!creature->LoadFromDB(guid, map)) @@ -1880,8 +1880,8 @@ void ObjectMgr::AddGameobjectToGrid(uint32 guid, GameObjectData const* data) { if (mask & 1) { - CellPair cell_pair = Trinity::ComputeCellPair(data->posX, data->posY); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(data->posX, data->posY); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids& cell_guids = mMapObjectGuids[MAKE_PAIR32(data->mapid, i)][cell_id]; cell_guids.gameobjects.insert(guid); @@ -1896,8 +1896,8 @@ void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data { if (mask & 1) { - CellPair cell_pair = Trinity::ComputeCellPair(data->posX, data->posY); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord = Trinity::ComputeCellCoord(data->posX, data->posY); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids& cell_guids = mMapObjectGuids[MAKE_PAIR32(data->mapid, i)][cell_id]; cell_guids.gameobjects.erase(guid); diff --git a/src/server/game/Grids/Cells/Cell.h b/src/server/game/Grids/Cells/Cell.h index a7fd879358e..13bb0afc494 100755 --- a/src/server/game/Grids/Cells/Cell.h +++ b/src/server/game/Grids/Cells/Cell.h @@ -29,87 +29,34 @@ class Map; class WorldObject; -enum District -{ - UPPER_DISTRICT = 1, - LOWER_DISTRICT = 1 << 1, - LEFT_DISTRICT = 1 << 2, - RIGHT_DISTRICT = 1 << 3, - CENTER_DISTRICT = 1 << 4, - UPPER_LEFT_DISTRICT = (UPPER_DISTRICT | LEFT_DISTRICT), - UPPER_RIGHT_DISTRICT = (UPPER_DISTRICT | RIGHT_DISTRICT), - LOWER_LEFT_DISTRICT = (LOWER_DISTRICT | LEFT_DISTRICT), - LOWER_RIGHT_DISTRICT = (LOWER_DISTRICT | RIGHT_DISTRICT), - ALL_DISTRICT = (UPPER_DISTRICT | LOWER_DISTRICT | LEFT_DISTRICT | RIGHT_DISTRICT | CENTER_DISTRICT) -}; - struct CellArea { - CellArea() : right_offset(0), left_offset(0), upper_offset(0), lower_offset(0) {} - CellArea(int right, int left, int upper, int lower) : right_offset(right), left_offset(left), upper_offset(upper), lower_offset(lower) {} - bool operator!() const { return !right_offset && !left_offset && !upper_offset && !lower_offset; } + CellArea() {} + CellArea(CellCoord low, CellCoord high) : low_bound(low), high_bound(high) {} + + bool operator!() const { return low_bound == high_bound; } - void ResizeBorders(CellPair& begin_cell, CellPair& end_cell) const + void ResizeBorders(CellCoord& begin_cell, CellCoord& end_cell) const { - begin_cell << left_offset; - begin_cell -= lower_offset; - end_cell >> right_offset; - end_cell += upper_offset; + begin_cell = low_bound; + end_cell = high_bound; } - int right_offset; - int left_offset; - int upper_offset; - int lower_offset; + CellCoord low_bound; + CellCoord high_bound; }; struct Cell { Cell() { data.All = 0; } - Cell(const Cell &cell) { data.All = cell.data.All; } - explicit Cell(CellPair const& p); - - void operator|=(Cell &cell) - { - data.Part.reserved = 0; - cell.data.Part.reserved = 0; - uint32 x, y, old_x, old_y; - Compute(x, y); - cell.Compute(old_x, old_y); - - if (std::abs(int(x-old_x)) > 1 || std::abs(int(y-old_y)) > 1) - { - data.Part.reserved = ALL_DISTRICT; - cell.data.Part.reserved = ALL_DISTRICT; - return; - } - - if (x < old_x) - { - data.Part.reserved |= LEFT_DISTRICT; - cell.data.Part.reserved |= RIGHT_DISTRICT; - } - else if (old_x < x) - { - data.Part.reserved |= RIGHT_DISTRICT; - cell.data.Part.reserved |= LEFT_DISTRICT; - } - if (y < old_y) - { - data.Part.reserved |= UPPER_DISTRICT; - cell.data.Part.reserved |= LOWER_DISTRICT; - } - else if (old_y < y) - { - data.Part.reserved |= LOWER_DISTRICT; - cell.data.Part.reserved |= UPPER_DISTRICT; - } - } + Cell(Cell const& cell) { data.All = cell.data.All; } + explicit Cell(CellCoord const& p); + explicit Cell(float x, float y); void Compute(uint32 &x, uint32 &y) const { - x = data.Part.grid_x*MAX_NUMBER_OF_CELLS + data.Part.cell_x; - y = data.Part.grid_y*MAX_NUMBER_OF_CELLS + data.Part.cell_y; + x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x; + y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y; } bool DiffCell(const Cell &cell) const @@ -131,21 +78,21 @@ struct Cell bool NoCreate() const { return data.Part.nocreate; } void SetNoCreate() { data.Part.nocreate = 1; } - CellPair cellPair() const + CellCoord GetCellCoord() const { - return CellPair( - data.Part.grid_x*MAX_NUMBER_OF_CELLS+data.Part.cell_x, - data.Part.grid_y*MAX_NUMBER_OF_CELLS+data.Part.cell_y); + return CellCoord( + data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x, + data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y); } - Cell& operator=(const Cell &cell) + Cell& operator=(Cell const& cell) { this->data.All = cell.data.All; return *this; } - bool operator == (const Cell &cell) const { return (data.All == cell.data.All); } - bool operator != (const Cell &cell) const { return !operator == (cell); } + bool operator == (Cell const& cell) const { return (data.All == cell.data.All); } + bool operator != (Cell const& cell) const { return !operator == (cell); } union { struct @@ -160,15 +107,13 @@ struct Cell uint32 All; } data; - template<class T, class CONTAINER> void Visit(const CellPair&, TypeContainerVisitor<T, CONTAINER> &visitor, Map &) const; - template<class T, class CONTAINER> void Visit(const CellPair&, TypeContainerVisitor<T, CONTAINER> &visitor, Map &, const WorldObject&, float) const; - template<class T, class CONTAINER> void Visit(const CellPair&, TypeContainerVisitor<T, CONTAINER> &visitor, Map &, float, float, float) const; + template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map &, WorldObject const&, float) const; + template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map &, float, float, float) const; - static CellArea CalculateCellArea(const WorldObject &obj, float radius); static CellArea CalculateCellArea(float x, float y, float radius); private: - template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, const CellPair&, const CellPair&) const; + template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const; }; #endif diff --git a/src/server/game/Grids/Cells/CellImpl.h b/src/server/game/Grids/Cells/CellImpl.h index d36892ffcb0..af697b9f21d 100755..100644 --- a/src/server/game/Grids/Cells/CellImpl.h +++ b/src/server/game/Grids/Cells/CellImpl.h @@ -25,7 +25,7 @@ #include "Map.h" #include "Object.h" -inline Cell::Cell(CellPair const& p) +inline Cell::Cell(CellCoord const& p) { data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS; @@ -35,143 +35,35 @@ inline Cell::Cell(CellPair const& p) data.Part.reserved = 0; } -template<class T, class CONTAINER> -inline void -Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const -{ - if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) - return; - - uint16 district = (District)this->data.Part.reserved; - if (district == CENTER_DISTRICT) - { - m.Visit(*this, visitor); - return; - } - - // set up the cell range based on the district - // the overloaded operators handle range checking - CellPair begin_cell = standing_cell; - CellPair end_cell = standing_cell; - - switch (district) - { - case ALL_DISTRICT: - { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell >> 1; end_cell += 1; // lower right - break; - } - case UPPER_LEFT_DISTRICT: - { - begin_cell << 1; begin_cell -= 1; // upper left - break; - } - case UPPER_RIGHT_DISTRICT: - { - begin_cell -= 1; // up - end_cell >> 1; // right - break; - } - case LOWER_LEFT_DISTRICT: - { - begin_cell << 1; // left - end_cell += 1; // down - break; - } - case LOWER_RIGHT_DISTRICT: - { - end_cell >> 1; end_cell += 1; // lower right - break; - } - case LEFT_DISTRICT: - { - begin_cell -= 1; // up - end_cell >> 1; end_cell += 1; // lower right - break; - } - case RIGHT_DISTRICT: - { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell += 1; // down - break; - } - case UPPER_DISTRICT: - { - begin_cell << 1; begin_cell -= 1; // upper left - end_cell >> 1; // right - break; - } - case LOWER_DISTRICT: - { - begin_cell << 1; // left - end_cell >> 1; end_cell += 1; // lower right - break; - } - default: - { - ASSERT(false); - break; - } - } - - // loop the cell range - for (uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++) - { - for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; y++) - { - CellPair cell_pair(x, y); - Cell r_zone(cell_pair); - r_zone.data.Part.nocreate = this->data.Part.nocreate; - m.Visit(r_zone, visitor); - } - } -} - -inline int CellHelper(const float radius) -{ - if (radius < 1.0f) - return 0; - - return (int)ceilf(radius/SIZE_OF_GRID_CELL); -} - -inline CellArea Cell::CalculateCellArea(const WorldObject &obj, float radius) +inline Cell::Cell(float x, float y) { - return Cell::CalculateCellArea(obj.GetPositionX(), obj.GetPositionY(), radius); + CellCoord p = Trinity::ComputeCellCoord(x, y); + data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; + data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS; + data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS; + data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS; + data.Part.nocreate = 0; + data.Part.reserved = 0; } inline CellArea Cell::CalculateCellArea(float x, float y, float radius) { if (radius <= 0.0f) - return CellArea(); - - //lets calculate object coord offsets from cell borders. - //TODO: add more correct/generic method for this task - const float x_offset = (x - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; - const float y_offset = (y - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; - - const float x_val = floor(x_offset + CENTER_GRID_CELL_ID + 0.5f); - const float y_val = floor(y_offset + CENTER_GRID_CELL_ID + 0.5f); - - const float x_off = (x_offset - x_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - const float y_off = (y_offset - y_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; + { + CellCoord center = Trinity::ComputeCellCoord(x, y).normalize(); + return CellArea(center, center); + } - const float tmp_diff = radius - CENTER_GRID_CELL_OFFSET; - //lets calculate upper/lower/right/left corners for cell search - int right = CellHelper(tmp_diff + x_off); - int left = CellHelper(tmp_diff - x_off); - int upper = CellHelper(tmp_diff + y_off); - int lower = CellHelper(tmp_diff - y_off); + CellCoord centerX = Trinity::ComputeCellCoord(x - radius, y - radius).normalize(); + CellCoord centerY = Trinity::ComputeCellCoord(x + radius, y + radius).normalize(); - return CellArea(right, left, upper, lower); + return CellArea(centerX, centerY); } template<class T, class CONTAINER> -inline void -Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, float radius, float x_off, float y_off) const +inline void Cell::Visit(CellCoord const& standing_cell, TypeContainerVisitor<T, CONTAINER>& visitor, Map& map, float radius, float x_off, float y_off) const { - if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + if (!standing_cell.IsCoordValid()) return; //no jokes here... Actually placing ASSERT() here was good idea, but @@ -179,7 +71,7 @@ Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &v //maybe it is better to just return when radius <= 0.0f? if (radius <= 0.0f) { - m.Visit(*this, visitor); + map.Visit(*this, visitor); return; } //lets limit the upper value for search radius @@ -191,57 +83,51 @@ Cell::Visit(const CellPair& standing_cell, TypeContainerVisitor<T, CONTAINER> &v //if radius fits inside standing cell if (!area) { - m.Visit(*this, visitor); + map.Visit(*this, visitor); return; } - CellPair begin_cell = standing_cell; - CellPair end_cell = standing_cell; - - area.ResizeBorders(begin_cell, end_cell); //visit all cells, found in CalculateCellArea() //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle //currently this technique works with MAX_NUMBER_OF_CELLS 16 and higher, with lower values //there are nothing to optimize because SIZE_OF_GRID_CELL is too big... - if (((end_cell.x_coord - begin_cell.x_coord) > 4) && ((end_cell.y_coord - begin_cell.y_coord) > 4)) + if (((area.high_bound.x_coord - area.low_bound.x_coord) > 4) && ((area.high_bound.y_coord - area.low_bound.y_coord) > 4)) { - VisitCircle(visitor, m, begin_cell, end_cell); + VisitCircle(visitor, map, area.low_bound, area.high_bound); return; } //ALWAYS visit standing cell first!!! Since we deal with small radiuses //it is very essential to call visitor for standing cell firstly... - m.Visit(*this, visitor); + map.Visit(*this, visitor); // loop the cell range - for (uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) + for (uint32 x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x) { - for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) + for (uint32 y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y) { - CellPair cell_pair(x, y); + CellCoord cellCoord(x, y); //lets skip standing cell since we already visited it - if (cell_pair != standing_cell) + if (cellCoord != standing_cell) { - Cell r_zone(cell_pair); + Cell r_zone(cellCoord); r_zone.data.Part.nocreate = this->data.Part.nocreate; - m.Visit(r_zone, visitor); + map.Visit(r_zone, visitor); } } } } template<class T, class CONTAINER> -inline void -Cell::Visit(const CellPair& l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const WorldObject &obj, float radius) const +inline void Cell::Visit(CellCoord const& standing_cell, TypeContainerVisitor<T, CONTAINER>& visitor, Map& map, WorldObject const& obj, float radius) const { //we should increase search radius by object's radius, otherwise //we could have problems with huge creatures, which won't attack nearest players etc - Visit(l, visitor, m, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY()); + Visit(standing_cell, visitor, map, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY()); } template<class T, class CONTAINER> -inline void -Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const CellPair& begin_cell, const CellPair& end_cell) const +inline void Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER>& visitor, Map& map, CellCoord const& begin_cell, CellCoord const& end_cell) const { //here is an algorithm for 'filling' circum-squared octagon uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f); @@ -254,10 +140,10 @@ Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const Cel { for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) { - CellPair cell_pair(x, y); - Cell r_zone(cell_pair); + CellCoord cellCoord(x, y); + Cell r_zone(cellCoord); r_zone.data.Part.nocreate = this->data.Part.nocreate; - m.Visit(r_zone, visitor); + map.Visit(r_zone, visitor); } } @@ -278,16 +164,16 @@ Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER> &visitor, Map &m, const Cel { //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom //e.g. filling 2 trapezoids after filling central cell strip... - CellPair cell_pair_left(x_start - step, y); - Cell r_zone_left(cell_pair_left); + CellCoord cellCoord_left(x_start - step, y); + Cell r_zone_left(cellCoord_left); r_zone_left.data.Part.nocreate = this->data.Part.nocreate; - m.Visit(r_zone_left, visitor); + map.Visit(r_zone_left, visitor); //right trapezoid cell visit - CellPair cell_pair_right(x_end + step, y); - Cell r_zone_right(cell_pair_right); + CellCoord cellCoord_right(x_end + step, y); + Cell r_zone_right(cellCoord_right); r_zone_right.data.Part.nocreate = this->data.Part.nocreate; - m.Visit(r_zone_right, visitor); + map.Visit(r_zone_right, visitor); } } } diff --git a/src/server/game/Grids/Grid.h b/src/server/game/Grids/Grid.h index a6e1316718e..a90915d49f0 100755 --- a/src/server/game/Grids/Grid.h +++ b/src/server/game/Grids/Grid.h @@ -72,26 +72,26 @@ class Grid /** Refreshes/update the grid. This required for remote grids. */ - void RefreshGrid(void) { /* TBI */} + //void RefreshGrid(void) { /* TBI */} /** Locks a grid. Any object enters must wait until the grid is unlock. */ - void LockGrid(void) { /* TBI */ } + //void LockGrid(void) { /* TBI */ } /** Unlocks the grid. */ - void UnlockGrid(void) { /* TBI */ } + //void UnlockGrid(void) { /* TBI */ } - /** Grid visitor for grid objects - */ - template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor) + // Visit grid objects + template<class T> + void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor) { visitor.Visit(i_container); } - /** Grid visitor for world objects - */ - template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor) + // Visit world objects + template<class T> + void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor) { visitor.Visit(i_objects); } diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 66eabf77400..44e2588ef81 100755..100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -71,21 +71,27 @@ typedef NGrid<MAX_NUMBER_OF_CELLS, Player, AllWorldObjectTypes, AllGridObjectTyp typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer; typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer; -template<const unsigned int LIMIT> +template<uint32 LIMIT> struct CoordPair { - CoordPair(uint32 x=0, uint32 y=0) : x_coord(x), y_coord(y) {} - CoordPair(const CoordPair<LIMIT> &obj) : x_coord(obj.x_coord), y_coord(obj.y_coord) {} - bool operator == (const CoordPair<LIMIT> &obj) const { return (obj.x_coord == x_coord && obj.y_coord == y_coord); } - bool operator != (const CoordPair<LIMIT> &obj) const { return !operator == (obj); } - CoordPair<LIMIT>& operator=(const CoordPair<LIMIT> &obj) + CoordPair(uint32 x=0, uint32 y=0) + : x_coord(x) + , y_coord(y) + {} + + CoordPair(const CoordPair<LIMIT> &obj) + : x_coord(obj.x_coord) + , y_coord(obj.y_coord) + {} + + CoordPair<LIMIT> & operator=(const CoordPair<LIMIT> &obj) { x_coord = obj.x_coord; y_coord = obj.y_coord; return *this; } - void operator<<(const uint32 val) + void dec_x(uint32 val) { if (x_coord > val) x_coord -= val; @@ -93,15 +99,15 @@ struct CoordPair x_coord = 0; } - void operator>>(const uint32 val) + void inc_x(uint32 val) { - if (x_coord+val < LIMIT) + if (x_coord + val < LIMIT) x_coord += val; else x_coord = LIMIT - 1; } - void operator-=(const uint32 val) + void dec_y(uint32 val) { if (y_coord > val) y_coord -= val; @@ -109,20 +115,44 @@ struct CoordPair y_coord = 0; } - void operator+=(const uint32 val) + void inc_y(uint32 val) { - if (y_coord+val < LIMIT) + if (y_coord + val < LIMIT) y_coord += val; else y_coord = LIMIT - 1; } + bool IsCoordValid() const + { + return x_coord < LIMIT && y_coord < LIMIT; + } + + CoordPair& normalize() + { + x_coord = std::min(x_coord, LIMIT - 1); + y_coord = std::min(y_coord, LIMIT - 1); + return *this; + } + uint32 x_coord; uint32 y_coord; }; -typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridPair; -typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellPair; +template<uint32 LIMIT> +bool operator==(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2) +{ + return (p1.x_coord == p2.x_coord && p1.y_coord == p2.y_coord); +} + +template<uint32 LIMIT> +bool operator!=(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2) +{ + return !(p1 == p2); +} + +typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridCoord; +typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellCoord; namespace Trinity { @@ -138,17 +168,17 @@ namespace Trinity return RET_TYPE(x_val, y_val); } - inline GridPair ComputeGridPair(float x, float y) + inline GridCoord ComputeGridCoord(float x, float y) { - return Compute<GridPair, CENTER_GRID_ID>(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS); + return Compute<GridCoord, CENTER_GRID_ID>(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS); } - inline CellPair ComputeCellPair(float x, float y) + inline CellCoord ComputeCellCoord(float x, float y) { - return Compute<CellPair, CENTER_GRID_CELL_ID>(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL); + return Compute<CellCoord, CENTER_GRID_CELL_ID>(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL); } - inline CellPair ComputeCellPair(float x, float y, float &x_off, float &y_off) + inline CellCoord ComputeCellCoord(float x, float y, float &x_off, float &y_off) { double x_offset = (double(x) - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; double y_offset = (double(y) - CENTER_GRID_CELL_OFFSET)/SIZE_OF_GRID_CELL; @@ -157,7 +187,7 @@ namespace Trinity int y_val = int(y_offset + CENTER_GRID_CELL_ID + 0.5f); x_off = (float(x_offset) - x_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; y_off = (float(y_offset) - y_val + CENTER_GRID_CELL_ID) * SIZE_OF_GRID_CELL; - return CellPair(x_val, y_val); + return CellCoord(x_val, y_val); } inline void NormalizeMapCoord(float &c) diff --git a/src/server/game/Grids/GridLoader.h b/src/server/game/Grids/GridLoader.h index 0e762d3a07e..43564c920e2 100755 --- a/src/server/game/Grids/GridLoader.h +++ b/src/server/game/Grids/GridLoader.h @@ -30,6 +30,8 @@ GridLoader manages the grid (both local and remote). */ +//I cannot see why this cannot be replaced by a Grid::Visit +/* #include "Define.h" #include "Grid.h" #include "TypeContainerVisitor.h" @@ -44,8 +46,7 @@ class GridLoader { public: - /** Loads the grid - */ + // Loads the grid template<class LOADER> void Load(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader) { @@ -54,8 +55,7 @@ class GridLoader grid.UnlockGrid(); } - /** Stop the grid - */ + // Stop the grid template<class STOPER> void Stop(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper) { @@ -63,8 +63,8 @@ class GridLoader stoper.Stop(grid); grid.UnlockGrid(); } - /** Unloads the grid - */ + + // Unloads the grid template<class UNLOADER> void Unload(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader) { @@ -73,5 +73,6 @@ class GridLoader grid.UnlockGrid(); } }; +*/ #endif diff --git a/src/server/game/Grids/GridStates.cpp b/src/server/game/Grids/GridStates.cpp index 91bb926fd02..fd5e3c68a51 100755 --- a/src/server/game/Grids/GridStates.cpp +++ b/src/server/game/Grids/GridStates.cpp @@ -22,23 +22,24 @@ #include "Log.h" void -InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 /*x*/, const uint32 /*y*/, const uint32) const +InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32) const { } void -ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 x, const uint32 y, const uint32 t_diff) const +ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 t_diff) const { // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle info.UpdateTimeTracker(t_diff); if (info.getTimeTracker().Passed()) { - if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(x, y)) + if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(grid)) { - ObjectGridStoper stoper(grid); - stoper.StopN(); + ObjectGridStoper worker; + TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer> visitor(worker); + grid.VisitAllGrids(visitor); grid.SetGridState(GRID_STATE_IDLE); - sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to IDLE state", x, y, m.GetId()); + sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to IDLE state", grid.getX(), grid.getY(), m.GetId()); } else { @@ -48,24 +49,24 @@ ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 x, co } void -IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32 x, const uint32 y, const uint32) const +IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32) const { m.ResetGridExpiry(grid); grid.SetGridState(GRID_STATE_REMOVAL); - sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to REMOVAL state", x, y, m.GetId()); + sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to REMOVAL state", grid.getX(), grid.getY(), m.GetId()); } void -RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 x, const uint32 y, const uint32 t_diff) const +RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 t_diff) const { if (!info.getUnloadLock()) { info.UpdateTimeTracker(t_diff); if (info.getTimeTracker().Passed()) { - if (!m.UnloadGrid(x, y, false)) + if (!m.UnloadGrid(grid, false)) { - sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", x, y, m.GetId()); + sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", grid.getX(), grid.getY(), m.GetId()); m.ResetGridExpiry(grid); } } diff --git a/src/server/game/Grids/GridStates.h b/src/server/game/Grids/GridStates.h index 81bf749b63f..78f70356608 100755 --- a/src/server/game/Grids/GridStates.h +++ b/src/server/game/Grids/GridStates.h @@ -40,35 +40,31 @@ class GridState void setMagic() { i_Magic = MAGIC_TESTVAL; } unsigned int i_Magic; #endif - virtual void Update(Map &, NGridType&, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const = 0; + virtual void Update(Map &, NGridType&, GridInfo &, const uint32 t_diff) const = 0; }; class InvalidState : public GridState { public: - - void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const; + void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const; }; class ActiveState : public GridState { public: - - void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const; + void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const; }; class IdleState : public GridState { public: - - void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const; + void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const; }; class RemovalState : public GridState { public: - - void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const; + void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const; }; #endif diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index cd2345e439d..b814fd386a5 100755 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -69,7 +69,7 @@ typedef enum template < -unsigned int N, +uint32 N, class ACTIVE_OBJECT, class WORLD_OBJECT_TYPES, class GRID_OBJECT_TYPES @@ -77,7 +77,6 @@ class GRID_OBJECT_TYPES class NGrid { public: - typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType; NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) : i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false) @@ -85,17 +84,15 @@ class NGrid i_GridInfo = GridInfo(expiry, unload); } - const GridType& operator()(unsigned short x, unsigned short y) const + GridType& GetGridType(const uint32 x, const uint32 y) { - ASSERT(x < N); - ASSERT(y < N); + ASSERT(x < N && y < N); return i_cells[x][y]; } - GridType& operator()(unsigned short x, unsigned short y) + GridType const& GetGridType(const uint32 x, const uint32 y) const { - ASSERT(x < N); - ASSERT(y < N); + ASSERT(x < N && y < N); return i_cells[x][y]; } @@ -125,54 +122,50 @@ class NGrid template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { - getGridType(x, y).AddWorldObject(obj); + GetGridType(x, y).AddWorldObject(obj); } template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { - getGridType(x, y).RemoveWorldObject(obj); + GetGridType(x, y).RemoveWorldObject(obj); } - template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) + template<class SPECIFIC_OBJECT> void AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { - for (unsigned int x=0; x < N; ++x) - for (unsigned int y=0; y < N; ++y) - getGridType(x, y).Visit(visitor); + GetGridType(x, y).AddGridObject(obj); } - template<class T, class TT> void Visit(const uint32 x, const uint32 y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) + template<class SPECIFIC_OBJECT> void RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { - getGridType(x, y).Visit(visitor); + GetGridType(x, y).RemoveGridObject(obj); } - unsigned int ActiveObjectsInGrid(void) const + // Visit all Grids (cells) in NGrid (grid) + template<class T, class TT> + void VisitAllGrids(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) { - unsigned int count=0; - for (unsigned int x=0; x < N; ++x) - for (unsigned int y=0; y < N; ++y) - count += i_cells[x][y].ActiveObjectsInGrid(); - return count; + for (uint32 x = 0; x < N; ++x) + for (uint32 y = 0; y < N; ++y) + GetGridType(x, y).Visit(visitor); } - template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) + // Visit a single Grid (cell) in NGrid (grid) + template<class T, class TT> + void VisitGrid(const uint32 x, const uint32 y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor) { - return getGridType(x, y).AddGridObject(obj); + GetGridType(x, y).Visit(visitor); } - template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) + unsigned int ActiveObjectsInGrid(void) const { - return getGridType(x, y).RemoveGridObject(obj); + unsigned int count=0; + for (unsigned int x=0; x < N; ++x) + for (unsigned int y=0; y < N; ++y) + count += i_cells[x][y].ActiveObjectsInGrid(); + return count; } private: - - GridType& getGridType(const uint32 x, const uint32 y) - { - ASSERT(x < N); - ASSERT(y < N); - return i_cells[x][y]; - } - uint32 i_gridId; GridInfo i_GridInfo; GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> > i_Reference; diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.cpp b/src/server/game/Grids/Notifiers/GridNotifiers.cpp index dc938859e92..0377713a520 100755 --- a/src/server/game/Grids/Notifiers/GridNotifiers.cpp +++ b/src/server/game/Grids/Notifiers/GridNotifiers.cpp @@ -215,7 +215,7 @@ void DelayedUnitRelocation::Visit(PlayerMapType &m) if (player != viewPoint && !viewPoint->IsPositionValid()) continue; - CellPair pair2(Trinity::ComputeCellPair(viewPoint->GetPositionX(), viewPoint->GetPositionY())); + CellCoord pair2(Trinity::ComputeCellCoord(viewPoint->GetPositionX(), viewPoint->GetPositionY())); Cell cell2(pair2); //cell.SetNoCreate(); need load cells around viewPoint or player, that's why its commented diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 0cd15143cee..af86af25db5 100755 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -81,9 +81,9 @@ namespace Trinity { Map &i_map; Cell &cell; - CellPair &p; + CellCoord &p; const float i_radius; - DelayedUnitRelocation(Cell &c, CellPair &pair, Map &map, float radius) : + DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius) : i_map(map), cell(c), p(pair), i_radius(radius) {} template<class T> void Visit(GridRefManager<T> &) {} void Visit(CreatureMapType &); diff --git a/src/server/game/Grids/ObjectGridLoader.cpp b/src/server/game/Grids/ObjectGridLoader.cpp index ee488f404dc..a696e02fdec 100755 --- a/src/server/game/Grids/ObjectGridLoader.cpp +++ b/src/server/game/Grids/ObjectGridLoader.cpp @@ -28,26 +28,7 @@ #include "CellImpl.h" #include "CreatureAI.h" -class ObjectGridRespawnMover -{ - public: - ObjectGridRespawnMover() {} - - void Move(GridType &grid); - - template<class T> void Visit(GridRefManager<T> &) {} - void Visit(CreatureMapType &m); -}; - -void -ObjectGridRespawnMover::Move(GridType &grid) -{ - TypeContainerVisitor<ObjectGridRespawnMover, GridTypeMapContainer > mover(*this); - grid.Visit(mover); -} - -void -ObjectGridRespawnMover::Visit(CreatureMapType &m) +void ObjectGridEvacuator::Visit(CreatureMapType &m) { // creature in unloading grid can have respawn point in another grid // if it will be unloaded then it will not respawn in original grid until unload/load original grid @@ -82,19 +63,19 @@ class ObjectWorldLoader uint32 i_corpses; }; -template<class T> void ObjectGridLoader::SetObjectCell(T* /*obj*/, CellPair const& /*cell_pair*/) +template<class T> void ObjectGridLoader::SetObjectCell(T* /*obj*/, CellCoord const& /*cellCoord*/) { } -template<> void ObjectGridLoader::SetObjectCell(Creature* obj, CellPair const& cell_pair) +template<> void ObjectGridLoader::SetObjectCell(Creature* obj, CellCoord const& cellCoord) { - Cell cell(cell_pair); + Cell cell(cellCoord); obj->SetCurrentCell(cell); } template <class T> -void AddObjectHelper(CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map, T *obj) +void AddObjectHelper(CellCoord &cell, GridRefManager<T> &m, uint32 &count, Map* map, T *obj) { obj->GetGridRef().link(&m, obj); ObjectGridLoader::SetObjectCell(obj, cell); @@ -106,7 +87,7 @@ void AddObjectHelper(CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* m } template <class T> -void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map) +void LoadHelper(CellGuidSet const& guid_set, CellCoord &cell, GridRefManager<T> &m, uint32 &count, Map* map) { for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid) { @@ -123,7 +104,7 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> & } } -void LoadHelper(CellCorpseSet const& cell_corpses, CellPair &cell, CorpseMapType &m, uint32 &count, Map* map) +void LoadHelper(CellCorpseSet const& cell_corpses, CellCoord &cell, CorpseMapType &m, uint32 &count, Map* map) { if (cell_corpses.empty()) return; @@ -154,12 +135,12 @@ ObjectGridLoader::Visit(GameObjectMapType &m) { uint32 x = (i_cell.GridX()*MAX_NUMBER_OF_CELLS) + i_cell.CellX(); uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); - CellPair cell_pair(x, y); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord(x, y); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cell_id); - LoadHelper(cell_guids.gameobjects, cell_pair, m, i_gameObjects, i_map); + LoadHelper(cell_guids.gameobjects, cellCoord, m, i_gameObjects, i_map); } void @@ -167,12 +148,12 @@ ObjectGridLoader::Visit(CreatureMapType &m) { uint32 x = (i_cell.GridX()*MAX_NUMBER_OF_CELLS) + i_cell.CellX(); uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); - CellPair cell_pair(x, y); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord(x, y); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cell_id); - LoadHelper(cell_guids.creatures, cell_pair, m, i_creatures, i_map); + LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map); } void @@ -180,28 +161,12 @@ ObjectWorldLoader::Visit(CorpseMapType &m) { uint32 x = (i_cell.GridX()*MAX_NUMBER_OF_CELLS) + i_cell.CellX(); uint32 y = (i_cell.GridY()*MAX_NUMBER_OF_CELLS) + i_cell.CellY(); - CellPair cell_pair(x, y); - uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + CellCoord cellCoord(x, y); + uint32 cell_id = (cellCoord.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cellCoord.x_coord; // corpses are always added to spawn mode 0 and they are spawned by their instance id CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), 0, cell_id); - LoadHelper(cell_guids.corpses, cell_pair, m, i_corpses, i_map); -} - -void -ObjectGridLoader::Load(GridType &grid) -{ - { - TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer > loader(*this); - grid.Visit(loader); - } - - { - ObjectWorldLoader wloader(*this); - TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer > loader(wloader); - grid.Visit(loader); - i_corpses = wloader.i_corpses; - } + LoadHelper(cell_guids.corpses, cellCoord, m, i_corpses, i_map); } void ObjectGridLoader::LoadN(void) @@ -214,35 +179,27 @@ void ObjectGridLoader::LoadN(void) for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y) { i_cell.data.Part.cell_y = y; - GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader; - loader.Load(i_grid(x, y), *this); - } - } - sLog->outDebug(LOG_FILTER_MAPS, "%u GameObjects, %u Creatures, and %u Corpses/Bones loaded for grid %u on map %u", i_gameObjects, i_creatures, i_corpses, i_grid.GetGridId(), i_map->GetId()); -} -void ObjectGridUnloader::MoveToRespawnN() -{ - for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x) - { - for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y) - { - ObjectGridRespawnMover mover; - mover.Move(i_grid(x, y)); + //Load creatures and game objects + { + TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer> visitor(*this); + i_grid.VisitGrid(x, y, visitor); + } + + //Load corpses (not bones) + { + ObjectWorldLoader worker(*this); + TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer> visitor(worker); + i_grid.VisitGrid(x, y, visitor); + i_corpses += worker.i_corpses; + } } } -} - -void -ObjectGridUnloader::Unload(GridType &grid) -{ - TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer > unloader(*this); - grid.Visit(unloader); + sLog->outDebug(LOG_FILTER_MAPS, "%u GameObjects, %u Creatures, and %u Corpses/Bones loaded for grid %u on map %u", i_gameObjects, i_creatures, i_corpses, i_grid.GetGridId(), i_map->GetId()); } template<class T> -void -ObjectGridUnloader::Visit(GridRefManager<T> &m) +void ObjectGridUnloader::Visit(GridRefManager<T> &m) { while (!m.isEmpty()) { @@ -255,15 +212,7 @@ ObjectGridUnloader::Visit(GridRefManager<T> &m) } } -void -ObjectGridStoper::Stop(GridType &grid) -{ - TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer > stoper(*this); - grid.Visit(stoper); -} - -void -ObjectGridStoper::Visit(CreatureMapType &m) +void ObjectGridStoper::Visit(CreatureMapType &m) { // stop any fights at grid de-activation and remove dynobjects created at cast by creatures for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter) @@ -278,23 +227,14 @@ ObjectGridStoper::Visit(CreatureMapType &m) } } -void -ObjectGridCleaner::Stop(GridType &grid) -{ - TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer > stoper(*this); - grid.Visit(stoper); -} - -void -ObjectGridCleaner::Visit(CreatureMapType &m) +void ObjectGridCleaner::Visit(CreatureMapType &m) { for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter) iter->getSource()->CleanupsBeforeDelete(); } template<class T> -void -ObjectGridCleaner::Visit(GridRefManager<T> &m) +void ObjectGridCleaner::Visit(GridRefManager<T> &m) { for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) iter->getSource()->RemoveFromWorld(); diff --git a/src/server/game/Grids/ObjectGridLoader.h b/src/server/game/Grids/ObjectGridLoader.h index 5fc5dc47e71..411cae10a90 100755 --- a/src/server/game/Grids/ObjectGridLoader.h +++ b/src/server/game/Grids/ObjectGridLoader.h @@ -36,7 +36,6 @@ class ObjectGridLoader : i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses (0) {} - void Load(GridType &grid); void Visit(GameObjectMapType &m); void Visit(CreatureMapType &m); void Visit(CorpseMapType &) const {} @@ -44,7 +43,7 @@ class ObjectGridLoader void LoadN(void); - template<class T> static void SetObjectCell(T* obj, CellPair const& cellPair); + template<class T> static void SetObjectCell(T* obj, CellCoord const& cellCoord); private: Cell i_cell; @@ -55,79 +54,34 @@ class ObjectGridLoader uint32 i_corpses; }; -class ObjectGridUnloader +//Stop the creatures before unloading the NGrid +class ObjectGridStoper { public: - ObjectGridUnloader(NGridType &grid) : i_grid(grid) {} - - void MoveToRespawnN(); - void UnloadN() - { - for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x) - { - for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y) - { - GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader; - loader.Unload(i_grid(x, y), *this); - } - } - } - - void Unload(GridType &grid); - template<class T> void Visit(GridRefManager<T> &m); - private: - NGridType &i_grid; + void Visit(CreatureMapType &m); + template<class T> void Visit(GridRefManager<T> &) {} }; -class ObjectGridStoper +//Move the foreign creatures back to respawn positions before unloading the NGrid +class ObjectGridEvacuator { public: - ObjectGridStoper(NGridType &grid) : i_grid(grid) {} - - void StopN() - { - for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x) - { - for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y) - { - GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader; - loader.Stop(i_grid(x, y), *this); - } - } - } - - void Stop(GridType &grid); void Visit(CreatureMapType &m); - - template<class NONACTIVE> void Visit(GridRefManager<NONACTIVE> &) {} - private: - NGridType &i_grid; + template<class T> void Visit(GridRefManager<T> &) {} }; +//Clean up and remove from world class ObjectGridCleaner { public: - ObjectGridCleaner(NGridType &grid) : i_grid(grid) {} - - void CleanN() - { - for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x) - { - for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y) - { - GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader; - loader.Stop(i_grid(x, y), *this); - } - } - } - - void Stop(GridType &grid); void Visit(CreatureMapType &m); template<class T> void Visit(GridRefManager<T> &); - private: - NGridType &i_grid; }; -typedef GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> GridLoaderType; +//Delete objects before deleting NGrid +class ObjectGridUnloader +{ + public: + template<class T> void Visit(GridRefManager<T> &m); +}; #endif - diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 0442172b0fd..5f73485c06e 100755 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -1052,8 +1052,8 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet* looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); } else { @@ -1105,8 +1105,8 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet* looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, (looters->size() > 1) ? looters : NULL); + AllowedLooterSet looters = item->GetAllowedLooters(); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); } else { @@ -2065,4 +2065,5 @@ void Group::ToggleGroupMemberFlag(member_witerator slot, uint8 flag, bool apply) slot->flags |= flag; else slot->flags &= ~flag; -}
\ No newline at end of file +} + diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index b9b9ed281fa..f0e21f7f709 100755 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -141,34 +141,36 @@ void InstanceScript::AddDoor(GameObject* door, bool add) for (DoorInfoMap::iterator itr = lower; itr != upper; ++itr) { + DoorInfo const& data = itr->second; + if (add) { - itr->second.bossInfo->door[itr->second.type].insert(door); - switch (itr->second.boundary) + data.bossInfo->door[data.type].insert(door); + switch (data.boundary) { default: case BOUNDARY_NONE: break; case BOUNDARY_N: case BOUNDARY_S: - itr->second.bossInfo->boundary[itr->second.boundary] = door->GetPositionX(); + data.bossInfo->boundary[data.boundary] = door->GetPositionX(); break; case BOUNDARY_E: case BOUNDARY_W: - itr->second.bossInfo->boundary[itr->second.boundary] = door->GetPositionY(); + data.bossInfo->boundary[data.boundary] = door->GetPositionY(); break; case BOUNDARY_NW: case BOUNDARY_SE: - itr->second.bossInfo->boundary[itr->second.boundary] = door->GetPositionX() + door->GetPositionY(); + data.bossInfo->boundary[data.boundary] = door->GetPositionX() + door->GetPositionY(); break; case BOUNDARY_NE: case BOUNDARY_SW: - itr->second.bossInfo->boundary[itr->second.boundary] = door->GetPositionX() - door->GetPositionY(); + data.bossInfo->boundary[data.boundary] = door->GetPositionX() - door->GetPositionY(); break; } } else - itr->second.bossInfo->door[itr->second.type].erase(door); + data.bossInfo->door[data.type].erase(door); } if (add) diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index b0adeb03784..10ae786a7d6 100755 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -149,7 +149,7 @@ struct LootItem bool AllowedForPlayer(Player const* player) const; void AddAllowedLooter(Player const* player); - AllowedLooterSet* GetAllowedLooters() { return &allowedGUIDs; } + const AllowedLooterSet & GetAllowedLooters() const { return allowedGUIDs; } }; struct QuestItem diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 89049f39127..ebeac025f1d 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -141,9 +141,9 @@ void Map::LoadMap(int gx, int gy, bool reload) // load grid map for base map if (!m_parentMap->GridMaps[gx][gy]) - m_parentMap->EnsureGridCreated(GridPair(63-gx, 63-gy)); + m_parentMap->EnsureGridCreated(GridCoord(63-gx, 63-gy)); - ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridPair(gx, gy)); + ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridCoord(gx, gy)); GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy]; return; } @@ -202,11 +202,11 @@ void Map::DeleteStateMachine() } Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent): -i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), i_InstanceId(InstanceId), +_creatureToMoveLock(false), i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), i_InstanceId(InstanceId), m_unloadTimer(0), m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_VisibilityNotifyPeriod(DEFAULT_VISIBILITY_NOTIFY_PERIOD), m_activeNonPlayersIter(m_activeNonPlayers.end()), i_gridExpiry(expiry), -i_scriptLock(false), _creatureToMoveLock(false) +i_scriptLock(false) { m_parentMap = (_parent ? _parent : this); for (unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx) @@ -234,73 +234,66 @@ void Map::InitVisibilityDistance() // Template specialization of utility methods template<class T> -void Map::AddToGrid(T* obj, NGridType *grid, Cell const& cell) +void Map::AddToGrid(T* obj, Cell const& cell) { + NGridType* grid = getNGrid(cell.GridX(), cell.GridY()); if (obj->m_isWorldObject) - (*grid)(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj); else - (*grid)(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj); } template<> -void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell) +void Map::AddToGrid(Creature* obj, Cell const& cell) { + NGridType* grid = getNGrid(cell.GridX(), cell.GridY()); if (obj->m_isWorldObject) - (*grid)(cell.CellX(), cell.CellY()).AddWorldObject(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).AddWorldObject(obj); else - (*grid)(cell.CellX(), cell.CellY()).AddGridObject(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj); obj->SetCurrentCell(cell); } template<class T> -void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell) +void Map::RemoveFromGrid(T* obj, Cell const& cell) { + NGridType* grid = getNGrid(cell.GridX(), cell.GridY()); if (obj->m_isWorldObject) - (*grid)(cell.CellX(), cell.CellY()).template RemoveWorldObject<T>(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).template RemoveWorldObject<T>(obj); else - (*grid)(cell.CellX(), cell.CellY()).template RemoveGridObject<T>(obj); + grid->GetGridType(cell.CellX(), cell.CellY()).template RemoveGridObject<T>(obj); } template<class T> void Map::SwitchGridContainers(T* obj, bool on) { - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + if (!p.IsCoordValid()) { sLog->outError("Map::SwitchGridContainers: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; } Cell cell(p); - if (!loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y))) + if (!IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y))) return; sLog->outStaticDebug("Switch object " UI64FMTD " from grid[%u, %u] %u", obj->GetGUID(), cell.data.Part.grid_x, cell.data.Part.grid_y, on); NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY()); ASSERT(ngrid != NULL); - GridType &grid = (*ngrid)(cell.CellX(), cell.CellY()); + GridType &grid = ngrid->GetGridType(cell.CellX(), cell.CellY()); if (on) { grid.RemoveGridObject<T>(obj); grid.AddWorldObject<T>(obj); - /*if (!grid.RemoveGridObject<T>(obj, obj->GetGUID()) - || !grid.AddWorldObject<T>(obj, obj->GetGUID())) - { - ASSERT(false); - }*/ } else { grid.RemoveWorldObject<T>(obj); grid.AddGridObject<T>(obj); - /*if (!grid.RemoveWorldObject<T>(obj, obj->GetGUID()) - || !grid.AddGridObject<T>(obj, obj->GetGUID())) - { - ASSERT(false); - }*/ } obj->m_isWorldObject = on; } @@ -322,8 +315,9 @@ void Map::DeleteFromWorld(Player* pl) delete pl; } -void -Map::EnsureGridCreated(const GridPair &p) +//Create NGrid so the object can be added to it +//But object data is not loaded here +void Map::EnsureGridCreated(const GridCoord &p) { if (!getNGrid(p.x_coord, p.y_coord)) { @@ -350,8 +344,8 @@ Map::EnsureGridCreated(const GridPair &p) } } -void -Map::EnsureGridLoadedAtEnter(const Cell &cell, Player* player) +//Load NGrid and make it active +void Map::EnsureGridLoadedForActiveObject(const Cell &cell, WorldObject* object) { EnsureGridLoaded(cell); NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); @@ -360,23 +354,16 @@ Map::EnsureGridLoadedAtEnter(const Cell &cell, Player* player) // refresh grid state & timer if (grid->GetGridState() != GRID_STATE_ACTIVE) { - if (player) - { - sLog->outStaticDebug("Player %s enter cell[%u, %u] triggers loading of grid[%u, %u] on map %u", player->GetName(), cell.CellX(), cell.CellY(), cell.GridX(), cell.GridY(), GetId()); - } - else - { - sLog->outStaticDebug("Active object nearby triggers loading of grid [%u, %u] on map %u", cell.GridX(), cell.GridY(), GetId()); - } - + sLog->outStaticDebug("Active object "UI64FMTD" triggers loading of grid [%u, %u] on map %u", object->GetGUID(), cell.GridX(), cell.GridY(), GetId()); ResetGridExpiry(*grid, 0.1f); grid->SetGridState(GRID_STATE_ACTIVE); } } +//Create NGrid and load the object data in it bool Map::EnsureGridLoaded(const Cell &cell) { - EnsureGridCreated(GridPair(cell.GridX(), cell.GridY())); + EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY())); NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); ASSERT(grid != NULL); @@ -390,7 +377,7 @@ bool Map::EnsureGridLoaded(const Cell &cell) loader.LoadN(); // Add resurrectable corpses to world object list in grid - sObjectAccessor->AddCorpsesToGrid(GridPair(cell.GridX(), cell.GridY()), (*grid)(cell.CellX(), cell.CellY()), this); + sObjectAccessor->AddCorpsesToGrid(GridCoord(cell.GridX(), cell.GridY()), grid->GetGridType(cell.CellX(), cell.CellY()), this); return true; } @@ -399,17 +386,15 @@ bool Map::EnsureGridLoaded(const Cell &cell) void Map::LoadGrid(float x, float y) { - CellPair pair = Trinity::ComputeCellPair(x, y); - Cell cell(pair); - EnsureGridLoaded(cell); + EnsureGridLoaded(Cell(x, y)); } bool Map::AddToMap(Player* player) { // Check if we are adding to correct map ASSERT (player->GetMap() == this); - CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY()); + if (!p.IsCoordValid()) { sLog->outError("Map::Add: Player (GUID: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); return false; @@ -418,10 +403,8 @@ bool Map::AddToMap(Player* player) player->SetMap(this); Cell cell(p); - EnsureGridLoadedAtEnter(cell, player); - NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); - ASSERT(grid != NULL); - AddToGrid(player, grid, cell); + EnsureGridLoadedForActiveObject(cell, player); + AddToGrid(player, cell); player->AddToWorld(); @@ -436,7 +419,7 @@ bool Map::AddToMap(Player* player) } template<class T> -void Map::InitializeObject(T* obj) +void Map::InitializeObject(T* /*obj*/) { } @@ -450,8 +433,8 @@ template<class T> void Map::AddToMap(T *obj) { - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + if (!p.IsCoordValid()) { sLog->outError("Map::Add: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; @@ -465,14 +448,11 @@ Map::AddToMap(T *obj) } if (obj->isActiveObject()) - EnsureGridLoadedAtEnter(cell); + EnsureGridLoadedForActiveObject(cell, obj); else - EnsureGridCreated(GridPair(cell.GridX(), cell.GridY())); - - NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); - ASSERT(grid != NULL); + EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY())); - AddToGrid(obj, grid, cell); + AddToGrid(obj, cell); //obj->SetMap(this); obj->AddToWorld(); InitializeObject(obj); @@ -487,29 +467,23 @@ Map::AddToMap(T *obj) obj->UpdateObjectVisibility(true); } -bool Map::loaded(const GridPair &p) const +bool Map::IsGridLoaded(const GridCoord &p) const { return (getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord)); } void Map::VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer> &gridVisitor, TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer> &worldVisitor) { - CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY())); - - // Check for correctness of standing_cell, it also avoids problems with update_cell - if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + // Check for valid position + if (!obj->IsPositionValid()) return; - // the overloaded operators handle range checking - // so there's no need for range checking inside the loop - CellPair begin_cell(standing_cell), end_cell(standing_cell); - //lets update mobs/objects in ALL visible cells around object! - CellArea area = Cell::CalculateCellArea(*obj, obj->GetGridActivationRange()); - area.ResizeBorders(begin_cell, end_cell); + // Update mobs/objects in ALL visible cells around object! + CellArea area = Cell::CalculateCellArea(obj->GetPositionX(), obj->GetPositionY(), obj->GetGridActivationRange()); - for (uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) + for (uint32 x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x) { - for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) + for (uint32 y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y) { // marked cells are those that have been visited // don't visit the same cell twice @@ -518,11 +492,10 @@ void Map::VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::Obj continue; markCell(cell_id); - CellPair pair(x, y); + CellCoord pair(x, y); Cell cell(pair); - cell.data.Part.reserved = CENTER_DISTRICT; - cell.Visit(pair, gridVisitor, *this); - cell.Visit(pair, worldVisitor, *this); + Visit(cell, gridVisitor); + Visit(cell, worldVisitor); } } } @@ -620,8 +593,8 @@ void Map::ProcessRelocationNotifies(const uint32 diff) uint32 gx = grid->getX(), gy = grid->getY(); - CellPair cell_min(gx*MAX_NUMBER_OF_CELLS, gy*MAX_NUMBER_OF_CELLS); - CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); + CellCoord cell_min(gx*MAX_NUMBER_OF_CELLS, gy*MAX_NUMBER_OF_CELLS); + CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); for (uint32 x = cell_min.x_coord; x < cell_max.x_coord; ++x) { @@ -631,7 +604,7 @@ void Map::ProcessRelocationNotifies(const uint32 diff) if (!isCellMarked(cell_id)) continue; - CellPair pair(x, y); + CellCoord pair(x, y); Cell cell(pair); cell.SetNoCreate(); @@ -661,8 +634,8 @@ void Map::ProcessRelocationNotifies(const uint32 diff) uint32 gx = grid->getX(), gy = grid->getY(); - CellPair cell_min(gx*MAX_NUMBER_OF_CELLS, gy*MAX_NUMBER_OF_CELLS); - CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); + CellCoord cell_min(gx*MAX_NUMBER_OF_CELLS, gy*MAX_NUMBER_OF_CELLS); + CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); for (uint32 x = cell_min.x_coord; x < cell_max.x_coord; ++x) { @@ -672,7 +645,7 @@ void Map::ProcessRelocationNotifies(const uint32 diff) if (!isCellMarked(cell_id)) continue; - CellPair pair(x, y); + CellCoord pair(x, y); Cell cell(pair); cell.SetNoCreate(); Visit(cell, grid_notifier); @@ -687,8 +660,8 @@ void Map::RemoveFromMap(Player* player, bool remove) player->RemoveFromWorld(); SendRemoveTransports(player); - CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY()); + if (!p.IsCoordValid()) sLog->outCrash("Map::Remove: Player is in invalid cell!"); else { @@ -698,11 +671,8 @@ void Map::RemoveFromMap(Player* player, bool remove) else { sLog->outStaticDebug("Remove player %s from grid[%u, %u]", player->GetName(), cell.GridX(), cell.GridY()); - NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); - ASSERT(grid != NULL); - player->UpdateObjectVisibility(true); - RemoveFromGrid(player, grid, cell); + RemoveFromGrid(player, cell); } } @@ -720,20 +690,17 @@ Map::RemoveFromMap(T *obj, bool remove) if (obj->isActiveObject()) RemoveFromActive(obj); - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + if (!p.IsCoordValid()) sLog->outError("Map::Remove: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); else { Cell cell(p); - if (loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y))) + if (IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y))) { sLog->outStaticDebug("Remove object " UI64FMTD " from grid[%u, %u]", obj->GetGUID(), cell.data.Part.grid_x, cell.data.Part.grid_y); - NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); - ASSERT(grid != NULL); - obj->UpdateObjectVisibility(true); - RemoveFromGrid(obj, grid, cell); + RemoveFromGrid(obj, cell); } } @@ -753,11 +720,8 @@ Map::PlayerRelocation(Player* player, float x, float y, float z, float orientati { ASSERT(player); - CellPair old_val = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - CellPair new_val = Trinity::ComputeCellPair(x, y); - - Cell old_cell(old_val); - Cell new_cell(new_val); + Cell old_cell(player->GetPositionX(), player->GetPositionY()); + Cell new_cell(x, y); player->Relocate(x, y, z, orientation); @@ -765,14 +729,12 @@ Map::PlayerRelocation(Player* player, float x, float y, float z, float orientati { sLog->outStaticDebug("Player %s relocation grid[%u, %u]cell[%u, %u]->grid[%u, %u]cell[%u, %u]", player->GetName(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); - NGridType* oldGrid = getNGrid(old_cell.GridX(), old_cell.GridY()); - RemoveFromGrid(player, oldGrid, old_cell); + RemoveFromGrid(player, old_cell); if (old_cell.DiffGrid(new_cell)) - EnsureGridLoadedAtEnter(new_cell, player); + EnsureGridLoadedForActiveObject(new_cell, player); - NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY()); - AddToGrid(player, newGrid, new_cell); + AddToGrid(player, new_cell); } player->UpdateObjectVisibility(false); @@ -784,9 +746,7 @@ Map::CreatureRelocation(Creature* creature, float x, float y, float z, float ang ASSERT(CheckGridIntegrity(creature, false)); Cell old_cell = creature->GetCurrentCell(); - - CellPair new_val = Trinity::ComputeCellPair(x, y); - Cell new_cell(new_val); + Cell new_cell(x, y); if (!respawnRelocationOnFail && !getNGrid(new_cell.GridX(), new_cell.GridY())) return; @@ -815,7 +775,7 @@ void Map::AddCreatureToMoveList(Creature* c, float x, float y, float z, float an if (_creatureToMoveLock) //can this happen? return; - if(c->_moveState == CREATURE_CELL_MOVE_NONE) + if (c->_moveState == CREATURE_CELL_MOVE_NONE) _creaturesToMove.push_back(c); c->SetNewCellPosition(x, y, z, ang); } @@ -825,7 +785,7 @@ void Map::RemoveCreatureFromMoveList(Creature* c) if (_creatureToMoveLock) //can this happen? return; - if(c->_moveState == CREATURE_CELL_MOVE_ACTIVE) + if (c->_moveState == CREATURE_CELL_MOVE_ACTIVE) c->_moveState = CREATURE_CELL_MOVE_INACTIVE; } @@ -849,11 +809,11 @@ void Map::MoveAllCreaturesInMoveList() continue; // do move or do move to respawn or remove creature if previous all fail - if (CreatureCellRelocation(c, Cell(Trinity::ComputeCellPair(c->_newPosition.m_positionX, c->_newPosition.m_positionY)))) + if (CreatureCellRelocation(c, Cell(c->_newPosition.m_positionX, c->_newPosition.m_positionY))) { // update pos c->Relocate(c->_newPosition); - //CreatureRelocationNotify(c, new_cell, new_cell.cellPair()); + //CreatureRelocationNotify(c, new_cell, new_cell.cellCoord()); c->UpdateObjectVisibility(false); } else @@ -895,8 +855,8 @@ bool Map::CreatureCellRelocation(Creature* c, Cell new_cell) sLog->outDebug(LOG_FILTER_MAPS, "Creature (GUID: %u Entry: %u) moved in grid[%u, %u] from cell[%u, %u] to cell[%u, %u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c, getNGrid(old_cell.GridX(), old_cell.GridY()), old_cell); - AddToGrid(c, getNGrid(new_cell.GridX(), new_cell.GridY()), new_cell); + RemoveFromGrid(c, old_cell); + AddToGrid(c, new_cell); } else { @@ -911,28 +871,28 @@ bool Map::CreatureCellRelocation(Creature* c, Cell new_cell) // in diff. grids but active creature if (c->isActiveObject()) { - EnsureGridLoadedAtEnter(new_cell); + EnsureGridLoadedForActiveObject(new_cell, c); #ifdef TRINITY_DEBUG sLog->outDebug(LOG_FILTER_MAPS, "Active creature (GUID: %u Entry: %u) moved from grid[%u, %u]cell[%u, %u] to grid[%u, %u]cell[%u, %u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c, getNGrid(old_cell.GridX(), old_cell.GridY()), old_cell); - AddToGrid(c, getNGrid(new_cell.GridX(), new_cell.GridY()), new_cell); + RemoveFromGrid(c, old_cell); + AddToGrid(c, new_cell); return true; } // in diff. loaded grid normal creature - if (loaded(GridPair(new_cell.GridX(), new_cell.GridY()))) + if (IsGridLoaded(GridCoord(new_cell.GridX(), new_cell.GridY()))) { #ifdef TRINITY_DEBUG sLog->outDebug(LOG_FILTER_MAPS, "Creature (GUID: %u Entry: %u) moved from grid[%u, %u]cell[%u, %u] to grid[%u, %u]cell[%u, %u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c, getNGrid(old_cell.GridX(), old_cell.GridY()), old_cell); - EnsureGridCreated(GridPair(new_cell.GridX(), new_cell.GridY())); - AddToGrid(c, getNGrid(new_cell.GridX(), new_cell.GridY()), new_cell); + RemoveFromGrid(c, old_cell); + EnsureGridCreated(GridCoord(new_cell.GridX(), new_cell.GridY())); + AddToGrid(c, new_cell); return true; } @@ -947,12 +907,11 @@ bool Map::CreatureCellRelocation(Creature* c, Cell new_cell) bool Map::CreatureRespawnRelocation(Creature* c, bool diffGridOnly) { float resp_x, resp_y, resp_z, resp_o; - c->GetRespawnCoord(resp_x, resp_y, resp_z, &resp_o); - CellPair resp_val = Trinity::ComputeCellPair(resp_x, resp_y); - Cell resp_cell(resp_val); + c->GetRespawnPosition(resp_x, resp_y, resp_z, &resp_o); + Cell resp_cell(resp_x, resp_y); //creature will be unloaded with grid - if(diffGridOnly && !c->GetCurrentCell().DiffGrid(resp_cell)) + if (diffGridOnly && !c->GetCurrentCell().DiffGrid(resp_cell)) return true; c->CombatStop(); @@ -967,7 +926,7 @@ bool Map::CreatureRespawnRelocation(Creature* c, bool diffGridOnly) { c->Relocate(resp_x, resp_y, resp_z, resp_o); c->GetMotionMaster()->Initialize(); // prevent possible problems with default move generators - //CreatureRelocationNotify(c, resp_cell, resp_cell.cellPair()); + //CreatureRelocationNotify(c, resp_cell, resp_cell.GetCellCoord()); c->UpdateObjectVisibility(false); return true; } @@ -975,19 +934,17 @@ bool Map::CreatureRespawnRelocation(Creature* c, bool diffGridOnly) return false; } -bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll) +bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll) { - NGridType *grid = getNGrid(x, y); - ASSERT(grid != NULL); + const uint32 x = ngrid.getX(); + const uint32 y = ngrid.getY(); { - if (!unloadAll && ActiveObjectsNearGrid(x, y)) + if (!unloadAll && ActiveObjectsNearGrid(ngrid)) return false; sLog->outDebug(LOG_FILTER_MAPS, "Unloading grid[%u, %u] for map %u", x, y, GetId()); - ObjectGridUnloader unloader(*grid); - if (!unloadAll) { // Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids @@ -995,22 +952,31 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll) MoveAllCreaturesInMoveList(); // move creatures to respawn grids if this is diff.grid or to remove list - unloader.MoveToRespawnN(); + ObjectGridEvacuator worker; + TypeContainerVisitor<ObjectGridEvacuator, GridTypeMapContainer> visitor(worker); + ngrid.VisitAllGrids(visitor); // Finish creature moves, remove and delete all creatures with delayed remove before unload MoveAllCreaturesInMoveList(); } - ObjectGridCleaner cleaner(*grid); - cleaner.CleanN(); + { + ObjectGridCleaner worker; + TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer> visitor(worker); + ngrid.VisitAllGrids(visitor); + } RemoveAllObjectsInRemoveList(); - unloader.UnloadN(); + { + ObjectGridUnloader worker; + TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer> visitor(worker); + ngrid.VisitAllGrids(visitor); + } ASSERT(i_objectsToRemove.empty()); - delete grid; + delete &ngrid; setNGrid(NULL, x, y); } int gx = (MAX_NUMBER_OF_GRIDS - 1) - x; @@ -1030,7 +996,7 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll) VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gx, gy); } else - ((MapInstanced*)m_parentMap)->RemoveGridMapReference(GridPair(gx, gy)); + ((MapInstanced*)m_parentMap)->RemoveGridMapReference(GridCoord(gx, gy)); GridMaps[gx][gy] = NULL; } @@ -1064,7 +1030,7 @@ void Map::UnloadAll() { NGridType &grid(*i->getSource()); ++i; - UnloadGrid(grid.getX(), grid.getY(), true); // deletes the grid and removes it from the GridRefManager + UnloadGrid(grid, true); // deletes the grid and removes it from the GridRefManager } } @@ -1589,7 +1555,7 @@ inline GridMap* Map::GetGrid(float x, float y) int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y // ensure GridMap is loaded - EnsureGridCreated(GridPair(63-gx, 63-gy)); + EnsureGridCreated(GridCoord(63-gx, 63-gy)); return GridMaps[gx][gy]; } @@ -1858,7 +1824,7 @@ bool Map::IsInWater(float x, float y, float pZ, LiquidData* data) const LiquidData liquid_status; LiquidData* liquid_ptr = data ? data : &liquid_status; if (getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, liquid_ptr)) - return true; + return true; } return false; } @@ -1876,9 +1842,7 @@ bool Map::IsUnderWater(float x, float y, float z) const bool Map::CheckGridIntegrity(Creature* c, bool moved) const { Cell const& cur_cell = c->GetCurrentCell(); - - CellPair xy_val = Trinity::ComputeCellPair(c->GetPositionX(), c->GetPositionY()); - Cell xy_cell(xy_val); + Cell xy_cell(c->GetPositionX(), c->GetPositionY()); if (xy_cell != cur_cell) { sLog->outDebug(LOG_FILTER_MAPS, "Creature (GUID: %u) X: %f Y: %f (%s) is in grid[%u, %u]cell[%u, %u] instead of grid[%u, %u]cell[%u, %u]", @@ -1897,20 +1861,18 @@ const char* Map::GetMapName() const return i_mapEntry ? i_mapEntry->name[sWorld->GetDefaultDbcLocale()] : "UNNAMEDMAP\x0"; } -void Map::UpdateObjectVisibility(WorldObject* obj, Cell cell, CellPair cellpair) +void Map::UpdateObjectVisibility(WorldObject* obj, Cell cell, CellCoord cellpair) { - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::VisibleChangesNotifier notifier(*obj); TypeContainerVisitor<Trinity::VisibleChangesNotifier, WorldTypeMapContainer > player_notifier(notifier); cell.Visit(cellpair, player_notifier, *this, *obj, obj->GetVisibilityRange()); } -void Map::UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpair) +void Map::UpdateObjectsVisibilityFor(Player* player, Cell cell, CellCoord cellpair) { Trinity::VisibleNotifier notifier(*player); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<Trinity::VisibleNotifier, WorldTypeMapContainer > world_notifier(notifier); TypeContainerVisitor<Trinity::VisibleNotifier, GridTypeMapContainer > grid_notifier(notifier); @@ -2027,7 +1989,7 @@ void Map::DelayedUpdate(const uint32 t_diff) GridInfo* info = i->getSource()->getGridInfoRef(); ++i; // The update might delete the map and we need the next map before the iterator gets invalid ASSERT(grid->GetGridState() >= 0 && grid->GetGridState() < MAX_GRID_STATE); - si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, grid->getX(), grid->getY(), t_diff); + si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, t_diff); } } } @@ -2130,28 +2092,25 @@ void Map::SendToPlayers(WorldPacket const* data) const itr->getSource()->GetSession()->SendPacket(data); } -bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const +bool Map::ActiveObjectsNearGrid(NGridType const& ngrid) const { - ASSERT(x < MAX_NUMBER_OF_GRIDS); - ASSERT(y < MAX_NUMBER_OF_GRIDS); - - CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); - CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); + CellCoord cell_min(ngrid.getX() * MAX_NUMBER_OF_CELLS, ngrid.getY() * MAX_NUMBER_OF_CELLS); + CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); //we must find visible range in cells so we unload only non-visible cells... float viewDist = GetVisibilityRange(); int cell_range = (int)ceilf(viewDist / SIZE_OF_GRID_CELL) + 1; - cell_min << cell_range; - cell_min -= cell_range; - cell_max >> cell_range; - cell_max += cell_range; + cell_min.dec_x(cell_range); + cell_min.dec_y(cell_range); + cell_max.inc_x(cell_range); + cell_max.inc_y(cell_range); for (MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) { Player* plr = iter->getSource(); - CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(plr->GetPositionX(), plr->GetPositionY()); if ((cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord)) return true; @@ -2161,7 +2120,7 @@ bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const { WorldObject* obj = *iter; - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); if ((cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord)) return true; @@ -2178,13 +2137,13 @@ void Map::AddToActive(Creature* c) if (!c->isPet() && c->GetDBTableGUIDLow()) { float x, y, z; - c->GetRespawnCoord(x, y, z); - GridPair p = Trinity::ComputeGridPair(x, y); + c->GetRespawnPosition(x, y, z); + GridCoord p = Trinity::ComputeGridCoord(x, y); if (getNGrid(p.x_coord, p.y_coord)) getNGrid(p.x_coord, p.y_coord)->incUnloadActiveLock(); else { - GridPair p2 = Trinity::ComputeGridPair(c->GetPositionX(), c->GetPositionY()); + GridCoord p2 = Trinity::ComputeGridCoord(c->GetPositionX(), c->GetPositionY()); sLog->outError("Active creature (GUID: %u Entry: %u) added to grid[%u, %u] but spawn grid[%u, %u] was not loaded.", c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord); } @@ -2199,13 +2158,13 @@ void Map::RemoveFromActive(Creature* c) if (!c->isPet() && c->GetDBTableGUIDLow()) { float x, y, z; - c->GetRespawnCoord(x, y, z); - GridPair p = Trinity::ComputeGridPair(x, y); + c->GetRespawnPosition(x, y, z); + GridCoord p = Trinity::ComputeGridCoord(x, y); if (getNGrid(p.x_coord, p.y_coord)) getNGrid(p.x_coord, p.y_coord)->decUnloadActiveLock(); else { - GridPair p2 = Trinity::ComputeGridPair(c->GetPositionX(), c->GetPositionY()); + GridCoord p2 = Trinity::ComputeGridCoord(c->GetPositionX(), c->GetPositionY()); sLog->outError("Active creature (GUID: %u Entry: %u) removed from grid[%u, %u] but spawn grid[%u, %u] was not loaded.", c->GetGUIDLow(), c->GetEntry(), p.x_coord, p.y_coord, p2.x_coord, p2.y_coord); } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index fd58fd0cc72..053759a3ab3 100755 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -263,20 +263,19 @@ class Map : public GridRefManager<NGridType> bool IsRemovalGrid(float x, float y) const { - GridPair p = Trinity::ComputeGridPair(x, y); + GridCoord p = Trinity::ComputeGridCoord(x, y); return !getNGrid(p.x_coord, p.y_coord) || getNGrid(p.x_coord, p.y_coord)->GetGridState() == GRID_STATE_REMOVAL; } - bool IsLoaded(float x, float y) const + bool IsGridLoaded(float x, float y) const { - GridPair p = Trinity::ComputeGridPair(x, y); - return loaded(p); + return IsGridLoaded(Trinity::ComputeGridCoord(x, y)); } - bool GetUnloadLock(const GridPair &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); } - void SetUnloadLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); } + bool GetUnloadLock(const GridCoord &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); } + void SetUnloadLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); } void LoadGrid(float x, float y); - bool UnloadGrid(const uint32 x, const uint32 y, bool pForce); + bool UnloadGrid(NGridType& ngrid, bool pForce); virtual void UnloadAll(); void ResetGridExpiry(NGridType &grid, float factor = 1) const @@ -371,8 +370,8 @@ class Map : public GridRefManager<NGridType> void AddObjectToSwitchList(WorldObject* obj, bool on); virtual void DelayedUpdate(const uint32 diff); - void UpdateObjectVisibility(WorldObject* obj, Cell cell, CellPair cellpair); - void UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpair); + void UpdateObjectVisibility(WorldObject* obj, Cell cell, CellCoord cellpair); + void UpdateObjectsVisibilityFor(Player* player, Cell cell, CellCoord cellpair); void resetMarkedCells() { marked_cells.reset(); } bool isCellMarked(uint32 pCellId) { return marked_cells.test(pCellId); } @@ -380,7 +379,7 @@ class Map : public GridRefManager<NGridType> bool HavePlayers() const { return !m_mapRefManager.isEmpty(); } uint32 GetPlayersCountExceptGMs() const; - bool ActiveObjectsNearGrid(uint32 x, uint32 y) const; + bool ActiveObjectsNearGrid(NGridType const& ngrid) const; void AddWorldObject(WorldObject* obj) { i_worldObjects.insert(obj); } void RemoveWorldObject(WorldObject* obj) { i_worldObjects.erase(obj); } @@ -420,8 +419,8 @@ class Map : public GridRefManager<NGridType> GameObject* GetGameObject(uint64 guid); DynamicObject* GetDynamicObject(uint64 guid); - MapInstanced* ToMainstanced(){ if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); else return NULL; } - const MapInstanced* ToMainstanced() const { if (Instanceable()) return (const MapInstanced*)((MapInstanced*)this); else return NULL; } + MapInstanced* ToMapInstanced(){ if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); else return NULL; } + const MapInstanced* ToMapInstanced() const { if (Instanceable()) return (const MapInstanced*)((MapInstanced*)this); else return NULL; } InstanceMap* ToInstanceMap(){ if (IsDungeon()) return reinterpret_cast<InstanceMap*>(this); else return NULL; } const InstanceMap* ToInstanceMap() const { if (IsDungeon()) return (const InstanceMap*)((InstanceMap*)this); else return NULL; } @@ -443,13 +442,14 @@ class Map : public GridRefManager<NGridType> template<class T> void InitializeObject(T* obj); void AddCreatureToMoveList(Creature* c, float x, float y, float z, float ang); void RemoveCreatureFromMoveList(Creature* c); + bool _creatureToMoveLock; std::vector<Creature*> _creaturesToMove; - bool loaded(const GridPair &) const; - void EnsureGridCreated(const GridPair &); + bool IsGridLoaded(const GridCoord &) const; + void EnsureGridCreated(const GridCoord &); bool EnsureGridLoaded(Cell const&); - void EnsureGridLoadedAtEnter(Cell const&, Player* player = NULL); + void EnsureGridLoadedForActiveObject(Cell const&, WorldObject* object); void buildNGridLinkage(NGridType* pNGridType) { pNGridType->link(this); } @@ -458,8 +458,7 @@ class Map : public GridRefManager<NGridType> NGridType* getNGrid(uint32 x, uint32 y) const { - ASSERT(x < MAX_NUMBER_OF_GRIDS); - ASSERT(y < MAX_NUMBER_OF_GRIDS); + ASSERT(x < MAX_NUMBER_OF_GRIDS && y < MAX_NUMBER_OF_GRIDS); return i_grids[x][y]; } @@ -471,7 +470,7 @@ class Map : public GridRefManager<NGridType> void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff); protected: - void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } + void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } ACE_Thread_Mutex Lock; @@ -524,10 +523,10 @@ class Map : public GridRefManager<NGridType> // Type specific code for add/remove to/from grid template<class T> - void AddToGrid(T*, NGridType *, Cell const&); + void AddToGrid(T* object, Cell const& cell); template<class T> - void RemoveFromGrid(T*, NGridType *, Cell const&); + void RemoveFromGrid(T* object, Cell const& cell); template<class T> void DeleteFromWorld(T*); @@ -616,28 +615,25 @@ class BattlegroundMap : public Map }; template<class T, class CONTAINER> -inline void -Map::Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor) +inline void Map::Visit(Cell const& cell, TypeContainerVisitor<T, CONTAINER>& visitor) { const uint32 x = cell.GridX(); const uint32 y = cell.GridY(); const uint32 cell_x = cell.CellX(); const uint32 cell_y = cell.CellY(); - if (!cell.NoCreate() || loaded(GridPair(x, y))) + if (!cell.NoCreate() || IsGridLoaded(GridCoord(x, y))) { EnsureGridLoaded(cell); - getNGrid(x, y)->Visit(cell_x, cell_y, visitor); + getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor); } } template<class NOTIFIER> -inline void -Map::VisitAll(const float &x, const float &y, float radius, NOTIFIER ¬ifier) +inline void Map::VisitAll(float const& x, float const& y, float radius, NOTIFIER& notifier) { - CellPair p(Trinity::ComputeCellPair(x, y)); + CellCoord p(Trinity::ComputeCellCoord(x, y)); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier); @@ -648,12 +644,10 @@ Map::VisitAll(const float &x, const float &y, float radius, NOTIFIER ¬ifier) // should be used with Searcher notifiers, tries to search world if nothing found in grid template<class NOTIFIER> -inline void -Map::VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER ¬ifier) +inline void Map::VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER ¬ifier) { - CellPair p(Trinity::ComputeCellPair(x, y)); + CellCoord p(Trinity::ComputeCellCoord(x, y)); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier); @@ -666,12 +660,10 @@ Map::VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER ¬ } template<class NOTIFIER> -inline void -Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER ¬ifier) +inline void Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER ¬ifier) { - CellPair p(Trinity::ComputeCellPair(x, y)); + CellCoord p(Trinity::ComputeCellCoord(x, y)); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier); @@ -679,12 +671,10 @@ Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER ¬ifier } template<class NOTIFIER> -inline void -Map::VisitGrid(const float &x, const float &y, float radius, NOTIFIER ¬ifier) +inline void Map::VisitGrid(const float &x, const float &y, float radius, NOTIFIER ¬ifier) { - CellPair p(Trinity::ComputeCellPair(x, y)); + CellCoord p(Trinity::ComputeCellCoord(x, y)); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier); diff --git a/src/server/game/Maps/MapInstanced.h b/src/server/game/Maps/MapInstanced.h index 1913f0add51..af303ed0e9e 100755 --- a/src/server/game/Maps/MapInstanced.h +++ b/src/server/game/Maps/MapInstanced.h @@ -43,17 +43,17 @@ class MapInstanced : public Map Map* FindMap(uint32 InstanceId) const { return _FindMap(InstanceId); } bool DestroyInstance(InstancedMaps::iterator &itr); - void AddGridMapReference(const GridPair &p) + void AddGridMapReference(const GridCoord &p) { ++GridMapReference[p.x_coord][p.y_coord]; - SetUnloadReferenceLock(GridPair(63-p.x_coord, 63-p.y_coord), true); + SetUnloadReferenceLock(GridCoord(63-p.x_coord, 63-p.y_coord), true); } - void RemoveGridMapReference(GridPair const& p) + void RemoveGridMapReference(GridCoord const& p) { --GridMapReference[p.x_coord][p.y_coord]; if (!GridMapReference[p.x_coord][p.y_coord]) - SetUnloadReferenceLock(GridPair(63-p.x_coord, 63-p.y_coord), false); + SetUnloadReferenceLock(GridCoord(63-p.x_coord, 63-p.y_coord), false); } InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; } diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 0b7abacad28..8b1c69362f2 100755 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -292,7 +292,7 @@ void MapManager::DoDelayedMovesAndRemoves() bool MapManager::ExistMapAndVMap(uint32 mapid, float x, float y) { - GridPair p = Trinity::ComputeGridPair(x, y); + GridCoord p = Trinity::ComputeGridCoord(x, y); int gx=63-p.x_coord; int gy=63-p.y_coord; diff --git a/src/server/game/Miscellaneous/SharedDefines.h b/src/server/game/Miscellaneous/SharedDefines.h index 380af30c175..c9fa9346860 100755 --- a/src/server/game/Miscellaneous/SharedDefines.h +++ b/src/server/game/Miscellaneous/SharedDefines.h @@ -409,7 +409,7 @@ enum SpellAttr3 enum SpellAttr4 { SPELL_ATTR4_UNK0 = 0x00000001, // 0 - SPELL_ATTR4_UNK1 = 0x00000002, // 1 proc on finishing move? + SPELL_ATTR4_PROC_ONLY_ON_DUMMY = 0x00000002, // 1 proc only on SPELL_EFFECT_DUMMY? SPELL_ATTR4_UNK2 = 0x00000004, // 2 SPELL_ATTR4_UNK3 = 0x00000008, // 3 SPELL_ATTR4_UNK4 = 0x00000010, // 4 This will no longer cause guards to attack on use?? diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index 35c19a6a62f..bbef60aa5e7 100755 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -260,7 +260,7 @@ void PoolGroup<Quest>::Despawn1Object(uint32 quest_id) QuestRelations::iterator lastElement = questMap->upper_bound(itr->second); for (; qitr != lastElement; ++qitr) { - if (qitr->first == itr->second) + if (qitr->first == itr->second && qitr->second == itr->first) { questMap->erase(qitr); // iterator is now no more valid break; // but we can exit loop since the element is found @@ -279,7 +279,7 @@ void PoolGroup<Quest>::Despawn1Object(uint32 quest_id) QuestRelations::iterator lastElement = questMap->upper_bound(itr->second); for (; qitr != lastElement; ++qitr) { - if (qitr->first == itr->second) + if (qitr->first == itr->second && qitr->second == itr->first) { questMap->erase(qitr); // iterator is now no more valid break; // but we can exit loop since the element is found @@ -361,7 +361,7 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj) // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use spawn coords to spawn - if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) + if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY)) { Creature* creature = new Creature; //sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid); @@ -387,7 +387,7 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid - if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) + if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid); diff --git a/src/server/game/Quests/QuestDef.cpp b/src/server/game/Quests/QuestDef.cpp index a1a1f5d5cac..9650afb60e2 100755 --- a/src/server/game/Quests/QuestDef.cpp +++ b/src/server/game/Quests/QuestDef.cpp @@ -205,6 +205,11 @@ int32 Quest::GetRewOrReqMoney() const return int32(RewOrReqMoney * sWorld->getRate(RATE_DROP_MONEY)); } +bool Quest::IsAutoComplete() const +{ + return QuestMethod == 0 || HasFlag(QUEST_FLAGS_AUTOCOMPLETE); +} + bool Quest::IsAllowedInRaid() const { if (IsRaidQuest()) diff --git a/src/server/game/Quests/QuestDef.h b/src/server/game/Quests/QuestDef.h index 61d492ce88c..90e52660160 100755 --- a/src/server/game/Quests/QuestDef.h +++ b/src/server/game/Quests/QuestDef.h @@ -246,7 +246,7 @@ class Quest uint32 GetQuestStartScript() const { return QuestStartScript; } uint32 GetQuestCompleteScript() const { return QuestCompleteScript; } bool IsRepeatable() const { return QuestFlags & QUEST_TRINITY_FLAGS_REPEATABLE; } - bool IsAutoComplete() const { return QuestMethod ? false : true; } + bool IsAutoComplete() const; uint32 GetFlags() const { return QuestFlags; } bool IsDaily() const { return QuestFlags & QUEST_FLAGS_DAILY; } bool IsWeekly() const { return QuestFlags & QUEST_FLAGS_WEEKLY; } diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp index b141f889196..88c9795e896 100755 --- a/src/server/game/Scripting/MapScripts.cpp +++ b/src/server/game/Scripting/MapScripts.cpp @@ -266,21 +266,20 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, const Script } } -inline GameObject* Map::_FindGameObject(WorldObject* pSearchObject, uint32 guid) const +inline GameObject* Map::_FindGameObject(WorldObject* searchObject, uint32 guid) const { - GameObject* pGameObject = NULL; + GameObject* gameobject = NULL; - CellPair p(Trinity::ComputeCellPair(pSearchObject->GetPositionX(), pSearchObject->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - Trinity::GameObjectWithDbGUIDCheck goCheck(*pSearchObject, guid); - Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(pSearchObject, pGameObject, goCheck); + Trinity::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid); + Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(searchObject, gameobject, goCheck); TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > objectChecker(checker); - cell.Visit(p, objectChecker, *pSearchObject->GetMap()); + cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); - return pGameObject; + return gameobject; } /// Process queued scripts @@ -818,15 +817,14 @@ void Map::ScriptsProcess() { WorldObject* wSource = dynamic_cast <WorldObject*> (source); - CellPair p(Trinity::ComputeCellPair(wSource->GetPositionX(), wSource->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(wSource->GetPositionX(), wSource->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::CreatureWithDbGUIDCheck target_check(wSource, step.script->CallScript.CreatureEntry); Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(wSource, cTarget, target_check); TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); - cell.Visit(p, unit_checker, *wSource->GetMap()); + cell.Visit(p, unit_checker, *wSource->GetMap(), *wSource, wSource->GetGridActivationRange()); } else //check hashmap holders { diff --git a/src/server/game/Server/Protocol/Handlers/CalendarHandler.cpp b/src/server/game/Server/Protocol/Handlers/CalendarHandler.cpp index 8f32ac84cb8..4c6ec6571a4 100755 --- a/src/server/game/Server/Protocol/Handlers/CalendarHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CalendarHandler.cpp @@ -25,12 +25,14 @@ #include "Opcodes.h" #include "Player.h" -void WorldSession::HandleCalendarGetCalendar(WorldPacket & /*recv_data*/) +void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recv_data*/) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_CALENDAR"); // empty + uint64 guid = _player->GetGUID(); + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); - time_t cur_time = time(NULL); + time_t cur_time = time_t(time(NULL)); + sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR [" UI64FMTD "]", guid); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 4+4*0+4+4*0+4+4); data << uint32(0); // invite count @@ -58,48 +60,52 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket & /*recv_data*/) } */ - data << uint32(0); // unk - data << uint32(secsToTimeBitFields(cur_time)); // current time + data << uint32(cur_time); // server time + data << uint32(secsToTimeBitFields(cur_time)); // server time uint32 counter = 0; size_t p_counter = data.wpos(); - data << uint32(counter); // instance save count + data << uint32(counter); // instance save count - for (int i = 0; i < MAX_DIFFICULTY; ++i) - { + for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) for (Player::BoundInstancesMap::const_iterator itr = _player->m_boundInstances[i].begin(); itr != _player->m_boundInstances[i].end(); ++itr) - { if (itr->second.perm) { - InstanceSave* save = itr->second.save; + InstanceSave const* save = itr->second.save; data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(save->GetResetTime() - cur_time); - data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id + data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id ++counter; } - } - } data.put<uint32>(p_counter, counter); - data << uint32(1135753200); // unk (28.12.2005 12:00) + data << uint32(1135753200); // unk (28.12.2005 07:00) counter = 0; p_counter = data.wpos(); - data << uint32(counter); // raid reset count + data << uint32(counter); // raid reset count + std::set<uint32> sentMaps; + ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap(); for (ResetTimeByMapDifficultyMap::const_iterator itr = resets.begin(); itr != resets.end(); ++itr) { - uint32 mapid = PAIR32_LOPART(itr->first); - MapEntry const* mapEnt = sMapStore.LookupEntry(mapid); - if (!mapEnt || !mapEnt->IsRaid()) + uint32 mapId = PAIR32_LOPART(itr->first); + + if (sentMaps.find(mapId) != sentMaps.end()) + continue; + + MapEntry const* mapEntry = sMapStore.LookupEntry(mapId); + if (!mapEntry || !mapEntry->IsRaid()) continue; - data << uint32(mapid); + sentMaps.insert(mapId); + + data << uint32(mapId); data << uint32(itr->second - cur_time); - data << uint32(mapEnt->unk_time); + data << uint32(mapEntry->unk_time); ++counter; } @@ -126,17 +132,16 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket & /*recv_data*/) } */ - sLog->outDebug(LOG_FILTER_NETWORKIO, "Sending calendar"); SendPacket(&data); } -void WorldSession::HandleCalendarGetEvent(WorldPacket &recv_data) +void WorldSession::HandleCalendarGetEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_EVENT"); recv_data.read_skip<uint64>(); // unk } -void WorldSession::HandleCalendarGuildFilter(WorldPacket &recv_data) +void WorldSession::HandleCalendarGuildFilter(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GUILD_FILTER"); recv_data.read_skip<uint32>(); // unk1 @@ -144,13 +149,13 @@ void WorldSession::HandleCalendarGuildFilter(WorldPacket &recv_data) recv_data.read_skip<uint32>(); // unk3 } -void WorldSession::HandleCalendarArenaTeam(WorldPacket &recv_data) +void WorldSession::HandleCalendarArenaTeam(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_ARENA_TEAM"); recv_data.read_skip<uint32>(); // unk } -void WorldSession::HandleCalendarAddEvent(WorldPacket &recv_data) +void WorldSession::HandleCalendarAddEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_ADD_EVENT"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -185,7 +190,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket &recv_data) //} } -void WorldSession::HandleCalendarUpdateEvent(WorldPacket &recv_data) +void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_UPDATE_EVENT"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -203,7 +208,7 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket &recv_data) //recv_data >> uint32 } -void WorldSession::HandleCalendarRemoveEvent(WorldPacket &recv_data) +void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_REMOVE_EVENT"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -214,7 +219,7 @@ void WorldSession::HandleCalendarRemoveEvent(WorldPacket &recv_data) } -void WorldSession::HandleCalendarCopyEvent(WorldPacket &recv_data) +void WorldSession::HandleCalendarCopyEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_COPY_EVENT"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -225,7 +230,7 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket &recv_data) } -void WorldSession::HandleCalendarEventInvite(WorldPacket &recv_data) +void WorldSession::HandleCalendarEventInvite(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_INVITE"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -238,7 +243,7 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket &recv_data) } -void WorldSession::HandleCalendarEventRsvp(WorldPacket &recv_data) +void WorldSession::HandleCalendarEventRsvp(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_RSVP"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -249,7 +254,7 @@ void WorldSession::HandleCalendarEventRsvp(WorldPacket &recv_data) } -void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket &recv_data) +void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_REMOVE_INVITE"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -260,7 +265,7 @@ void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket &recv_data) //recv_data >> uint64 } -void WorldSession::HandleCalendarEventStatus(WorldPacket &recv_data) +void WorldSession::HandleCalendarEventStatus(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_STATUS"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -272,7 +277,7 @@ void WorldSession::HandleCalendarEventStatus(WorldPacket &recv_data) //recv_data >> uint32 } -void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket &recv_data) +void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_MODERATOR_STATUS"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -284,7 +289,7 @@ void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket &recv_data) //recv_data >> uint32 } -void WorldSession::HandleCalendarComplain(WorldPacket &recv_data) +void WorldSession::HandleCalendarComplain(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_COMPLAIN"); recv_data.rfinish(); // set to end to avoid warnings spam @@ -294,7 +299,7 @@ void WorldSession::HandleCalendarComplain(WorldPacket &recv_data) //recv_data >> uint64 } -void WorldSession::HandleCalendarGetNumPending(WorldPacket & /*recv_data*/) +void WorldSession::HandleCalendarGetNumPending(WorldPacket& /*recv_data*/) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_NUM_PENDING"); // empty diff --git a/src/server/game/Server/Protocol/Handlers/ChatHandler.cpp b/src/server/game/Server/Protocol/Handlers/ChatHandler.cpp index 83d92df4f7a..70dc0ace8eb 100755 --- a/src/server/game/Server/Protocol/Handlers/ChatHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/ChatHandler.cpp @@ -566,10 +566,9 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket & recv_data) Unit* unit = ObjectAccessor::GetUnit(*_player, guid); - CellPair p = Trinity::ComputeCellPair(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()); + CellCoord p = Trinity::ComputeCellCoord(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::EmoteChatBuilder emote_builder(*GetPlayer(), text_emote, emoteNum, unit); diff --git a/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp b/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp index eca466436be..f4e3af72892 100755 --- a/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/ItemHandler.cpp @@ -1341,7 +1341,7 @@ void WorldSession::HandleSocketOpcode(WorldPacket& recv_data) _player->ToggleMetaGemsActive(slot, true); //turn on all metagems (except for target item) - itemTarget->SetSoulboundTradeable(NULL, _player, false); // clear tradeable flag + itemTarget->ClearSoulboundTradeable(_player); // clear tradeable flag } void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPacket& recv_data) diff --git a/src/server/game/Server/Protocol/Handlers/LootHandler.cpp b/src/server/game/Server/Protocol/Handlers/LootHandler.cpp index 83d3fad3b21..05b4afc99e7 100755 --- a/src/server/game/Server/Protocol/Handlers/LootHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/LootHandler.cpp @@ -489,10 +489,10 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPacket & recv_data) } // list of players allowed to receive this item in trade - AllowedLooterSet* looters = item.GetAllowedLooters(); + AllowedLooterSet looters = item.GetAllowedLooters(); // not move item from loot to target inventory - Item* newitem = target->StoreNewItem(dest, item.itemid, true, item.randomPropertyId, (looters->size() > 1) ? looters : NULL); + Item* newitem = target->StoreNewItem(dest, item.itemid, true, item.randomPropertyId, looters); target->SendNewItem(newitem, uint32(item.count), false, false, true); target->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, item.itemid, item.count); target->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE, pLoot->loot_type, item.count); diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index 1b0cef69c04..971e0b89c0f 100755 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -239,8 +239,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket & recv_data) data << uint32(matchcount); // placeholder, count of players matching criteria data << uint32(displaycount); // placeholder, count of players displayed - ACE_GUARD(ACE_Thread_Mutex, g, *HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType& m = sObjectAccessor->GetPlayers(); + ACE_READ_GUARD(HashMapHolder<Player>::LockType, g, *HashMapHolder<Player>::GetLock()); + HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { if (AccountMgr::IsPlayerAccount(security)) diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 9cb2b1cbe3f..32e65ca7e3f 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -999,6 +999,7 @@ void WorldSession::ProcessQueryCallbacks() HandleCharCreateCallback(pResult, _charCreateCallback.GetParam()); // Don't call FreeResult() here, the callback handler will do that depending on the events in the callback chain } + //! HandlePlayerLoginOpcode if (_charLoginCallback.ready()) { diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 2337f2a34b2..a28e3fca2ab 100755 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -223,10 +223,10 @@ class WorldSession void SizeError(WorldPacket const& packet, uint32 size) const; - void ReadAddonsInfo(WorldPacket &data); + void ReadAddonsInfo(WorldPacket& data); void SendAddonsInfo(); - void ReadMovementInfo(WorldPacket &data, MovementInfo* mi); + void ReadMovementInfo(WorldPacket& data, MovementInfo* mi); void WriteMovementInfo(WorldPacket* data, MovementInfo* mi); void SendPacket(WorldPacket const* packet); @@ -282,7 +282,7 @@ class WorldSession void SendTrainerList(uint64 guid); void SendTrainerList(uint64 guid, const std::string& strTitle); - void SendListInventory(uint64 vendorGuid); + void SendListInventory(uint64 guid); void SendShowBank(uint64 guid); void SendTabardVendorActivate(uint64 guid); void SendSpiritResurrect(); @@ -381,9 +381,7 @@ class WorldSession } bool IsConnectionIdle() const { - if (m_timeOutTime <= 0 && !m_inQueue) - return true; - return false; + return (m_timeOutTime <= 0 && !m_inQueue); } // Recruit-A-Friend Handling @@ -421,11 +419,11 @@ class WorldSession void HandleInspectHonorStatsOpcode(WorldPacket& recvPacket); void HandleMoveWaterWalkAck(WorldPacket& recvPacket); - void HandleFeatherFallAck(WorldPacket &recv_data); + void HandleFeatherFallAck(WorldPacket& recv_data); - void HandleMoveHoverAck(WorldPacket & recv_data); + void HandleMoveHoverAck(WorldPacket& recv_data); - void HandleMountSpecialAnimOpcode(WorldPacket &recvdata); + void HandleMountSpecialAnimOpcode(WorldPacket& recvdata); // character view void HandleShowingHelmOpcode(WorldPacket& recv_data); @@ -438,7 +436,7 @@ class WorldSession void HandleMoveKnockBackAck(WorldPacket& recvPacket); void HandleMoveTeleportAck(WorldPacket& recvPacket); - void HandleForceSpeedChangeAck(WorldPacket & recv_data); + void HandleForceSpeedChangeAck(WorldPacket& recv_data); void HandlePingOpcode(WorldPacket& recvPacket); void HandleAuthSessionOpcode(WorldPacket& recvPacket); @@ -483,10 +481,10 @@ class WorldSession void HandleAreaTriggerOpcode(WorldPacket& recvPacket); - void HandleSetFactionAtWar(WorldPacket & recv_data); - void HandleSetFactionCheat(WorldPacket & recv_data); - void HandleSetWatchedFactionOpcode(WorldPacket & recv_data); - void HandleSetFactionInactiveOpcode(WorldPacket & recv_data); + void HandleSetFactionAtWar(WorldPacket& recv_data); + void HandleSetFactionCheat(WorldPacket& recv_data); + void HandleSetWatchedFactionOpcode(WorldPacket& recv_data); + void HandleSetFactionInactiveOpcode(WorldPacket& recv_data); void HandleUpdateAccountData(WorldPacket& recvPacket); void HandleRequestAccountData(WorldPacket& recvPacket); @@ -507,17 +505,17 @@ class WorldSession void HandleMoveWorldportAckOpcode(); // for server-side calls void HandleMovementOpcodes(WorldPacket& recvPacket); - void HandleSetActiveMoverOpcode(WorldPacket &recv_data); - void HandleMoveNotActiveMover(WorldPacket &recv_data); - void HandleDismissControlledVehicle(WorldPacket &recv_data); - void HandleRequestVehicleExit(WorldPacket &recv_data); - void HandleChangeSeatsOnControlledVehicle(WorldPacket &recv_data); - void HandleMoveTimeSkippedOpcode(WorldPacket &recv_data); + void HandleSetActiveMoverOpcode(WorldPacket& recv_data); + void HandleMoveNotActiveMover(WorldPacket& recv_data); + void HandleDismissControlledVehicle(WorldPacket& recv_data); + void HandleRequestVehicleExit(WorldPacket& recv_data); + void HandleChangeSeatsOnControlledVehicle(WorldPacket& recv_data); + void HandleMoveTimeSkippedOpcode(WorldPacket& recv_data); - void HandleRequestRaidInfoOpcode(WorldPacket & recv_data); + void HandleRequestRaidInfoOpcode(WorldPacket& recv_data); - void HandleBattlefieldStatusOpcode(WorldPacket &recv_data); - void HandleBattleMasterHelloOpcode(WorldPacket &recv_data); + void HandleBattlefieldStatusOpcode(WorldPacket& recv_data); + void HandleBattleMasterHelloOpcode(WorldPacket& recv_data); void HandleGroupInviteOpcode(WorldPacket& recvPacket); //void HandleGroupCancelOpcode(WorldPacket& recvPacket); @@ -527,17 +525,17 @@ class WorldSession void HandleGroupUninviteGuidOpcode(WorldPacket& recvPacket); void HandleGroupSetLeaderOpcode(WorldPacket& recvPacket); void HandleGroupDisbandOpcode(WorldPacket& recvPacket); - void HandleOptOutOfLootOpcode(WorldPacket &recv_data); + void HandleOptOutOfLootOpcode(WorldPacket& recv_data); void HandleLootMethodOpcode(WorldPacket& recvPacket); - void HandleLootRoll(WorldPacket &recv_data); - void HandleRequestPartyMemberStatsOpcode(WorldPacket &recv_data); - void HandleRaidTargetUpdateOpcode(WorldPacket & recv_data); - void HandleRaidReadyCheckOpcode(WorldPacket & recv_data); - void HandleRaidReadyCheckFinishedOpcode(WorldPacket & recv_data); - void HandleGroupRaidConvertOpcode(WorldPacket & recv_data); - void HandleGroupChangeSubGroupOpcode(WorldPacket & recv_data); - void HandleGroupAssistantLeaderOpcode(WorldPacket & recv_data); - void HandlePartyAssignmentOpcode(WorldPacket & recv_data); + void HandleLootRoll(WorldPacket& recv_data); + void HandleRequestPartyMemberStatsOpcode(WorldPacket& recv_data); + void HandleRaidTargetUpdateOpcode(WorldPacket& recv_data); + void HandleRaidReadyCheckOpcode(WorldPacket& recv_data); + void HandleRaidReadyCheckFinishedOpcode(WorldPacket& recv_data); + void HandleGroupRaidConvertOpcode(WorldPacket& recv_data); + void HandleGroupChangeSubGroupOpcode(WorldPacket& recv_data); + void HandleGroupAssistantLeaderOpcode(WorldPacket& recv_data); + void HandlePartyAssignmentOpcode(WorldPacket& recv_data); void HandlePetitionBuyOpcode(WorldPacket& recv_data); void HandlePetitionShowSignOpcode(WorldPacket& recv_data); @@ -613,25 +611,25 @@ class WorldSession void HandleUnacceptTradeOpcode(WorldPacket& recvPacket); void HandleAuctionHelloOpcode(WorldPacket& recvPacket); - void HandleAuctionListItems(WorldPacket & recv_data); - void HandleAuctionListBidderItems(WorldPacket & recv_data); - void HandleAuctionSellItem(WorldPacket & recv_data); - void HandleAuctionRemoveItem(WorldPacket & recv_data); - void HandleAuctionListOwnerItems(WorldPacket & recv_data); - void HandleAuctionPlaceBid(WorldPacket & recv_data); - void HandleAuctionListPendingSales(WorldPacket & recv_data); - - void HandleGetMailList(WorldPacket & recv_data); - void HandleSendMail(WorldPacket & recv_data); - void HandleMailTakeMoney(WorldPacket & recv_data); - void HandleMailTakeItem(WorldPacket & recv_data); - void HandleMailMarkAsRead(WorldPacket & recv_data); - void HandleMailReturnToSender(WorldPacket & recv_data); - void HandleMailDelete(WorldPacket & recv_data); - void HandleItemTextQuery(WorldPacket & recv_data); - void HandleMailCreateTextItem(WorldPacket & recv_data); - void HandleQueryNextMailTime(WorldPacket & recv_data); - void HandleCancelChanneling(WorldPacket & recv_data); + void HandleAuctionListItems(WorldPacket& recv_data); + void HandleAuctionListBidderItems(WorldPacket& recv_data); + void HandleAuctionSellItem(WorldPacket& recv_data); + void HandleAuctionRemoveItem(WorldPacket& recv_data); + void HandleAuctionListOwnerItems(WorldPacket& recv_data); + void HandleAuctionPlaceBid(WorldPacket& recv_data); + void HandleAuctionListPendingSales(WorldPacket& recv_data); + + void HandleGetMailList(WorldPacket& recv_data); + void HandleSendMail(WorldPacket& recv_data); + void HandleMailTakeMoney(WorldPacket& recv_data); + void HandleMailTakeItem(WorldPacket& recv_data); + void HandleMailMarkAsRead(WorldPacket& recv_data); + void HandleMailReturnToSender(WorldPacket& recv_data); + void HandleMailDelete(WorldPacket& recv_data); + void HandleItemTextQuery(WorldPacket& recv_data); + void HandleMailCreateTextItem(WorldPacket& recv_data); + void HandleQueryNextMailTime(WorldPacket& recv_data); + void HandleCancelChanneling(WorldPacket& recv_data); void SendItemPageInfo(ItemTemplate* itemProto); void HandleSplitItemOpcode(WorldPacket& recvPacket); @@ -645,9 +643,9 @@ class WorldSession void HandleListInventoryOpcode(WorldPacket& recvPacket); void HandleAutoStoreBagItemOpcode(WorldPacket& recvPacket); void HandleReadItem(WorldPacket& recvPacket); - void HandleAutoEquipItemSlotOpcode(WorldPacket & recvPacket); - void HandleSwapItem(WorldPacket & recvPacket); - void HandleBuybackItem(WorldPacket & recvPacket); + void HandleAutoEquipItemSlotOpcode(WorldPacket& recvPacket); + void HandleSwapItem(WorldPacket& recvPacket); + void HandleBuybackItem(WorldPacket& recvPacket); void HandleAutoBankItemOpcode(WorldPacket& recvPacket); void HandleAutoStoreBankItemOpcode(WorldPacket& recvPacket); void HandleWrapItemOpcode(WorldPacket& recvPacket); @@ -728,18 +726,18 @@ class WorldSession void HandlePageQuerySkippedOpcode(WorldPacket& recvPacket); void HandlePageTextQueryOpcode(WorldPacket& recvPacket); - void HandleTutorialFlag (WorldPacket & recv_data); - void HandleTutorialClear(WorldPacket & recv_data); - void HandleTutorialReset(WorldPacket & recv_data); + void HandleTutorialFlag (WorldPacket& recv_data); + void HandleTutorialClear(WorldPacket& recv_data); + void HandleTutorialReset(WorldPacket& recv_data); //Pet - void HandlePetAction(WorldPacket & recv_data); + void HandlePetAction(WorldPacket& recv_data); void HandlePetStopAttack(WorldPacket& recv_data); void HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid, uint16 flag, uint64 guid2); - void HandlePetNameQuery(WorldPacket & recv_data); - void HandlePetSetAction(WorldPacket & recv_data); - void HandlePetAbandon(WorldPacket & recv_data); - void HandlePetRename(WorldPacket & recv_data); + void HandlePetNameQuery(WorldPacket& recv_data); + void HandlePetSetAction(WorldPacket& recv_data); + void HandlePetAbandon(WorldPacket& recv_data); + void HandlePetRename(WorldPacket& recv_data); void HandlePetCancelAuraOpcode(WorldPacket& recvPacket); void HandlePetSpellAutocastOpcode(WorldPacket& recvPacket); void HandlePetCastSpellOpcode(WorldPacket& recvPacket); @@ -756,15 +754,15 @@ class WorldSession void HandleDismissCritter(WorldPacket& recv_data); //Battleground - void HandleBattlemasterHelloOpcode(WorldPacket &recv_data); - void HandleBattlemasterJoinOpcode(WorldPacket &recv_data); + void HandleBattlemasterHelloOpcode(WorldPacket& recv_data); + void HandleBattlemasterJoinOpcode(WorldPacket& recv_data); void HandleBattlegroundPlayerPositionsOpcode(WorldPacket& recv_data); - void HandlePVPLogDataOpcode(WorldPacket &recv_data); - void HandleBattleFieldPortOpcode(WorldPacket &recv_data); - void HandleBattlefieldListOpcode(WorldPacket &recv_data); - void HandleLeaveBattlefieldOpcode(WorldPacket &recv_data); - void HandleBattlemasterJoinArena(WorldPacket &recv_data); - void HandleReportPvPAFK(WorldPacket &recv_data); + void HandlePVPLogDataOpcode(WorldPacket& recv_data); + void HandleBattleFieldPortOpcode(WorldPacket& recv_data); + void HandleBattlefieldListOpcode(WorldPacket& recv_data); + void HandleLeaveBattlefieldOpcode(WorldPacket& recv_data); + void HandleBattlemasterJoinArena(WorldPacket& recv_data); + void HandleReportPvPAFK(WorldPacket& recv_data); void HandleWardenDataOpcode(WorldPacket& recv_data); void HandleWorldTeleportOpcode(WorldPacket& recv_data); @@ -783,17 +781,17 @@ class WorldSession void HandleInstanceLockResponse(WorldPacket& recvPacket); // Looking for Dungeon/Raid - void HandleLfgSetCommentOpcode(WorldPacket & recv_data); + void HandleLfgSetCommentOpcode(WorldPacket& recv_data); void HandleLfgPlayerLockInfoRequestOpcode(WorldPacket& recv_data); void HandleLfgPartyLockInfoRequestOpcode(WorldPacket& recv_data); - void HandleLfgJoinOpcode(WorldPacket &recv_data); - void HandleLfgLeaveOpcode(WorldPacket & /*recv_data*/); - void HandleLfgSetRolesOpcode(WorldPacket &recv_data); - void HandleLfgProposalResultOpcode(WorldPacket &recv_data); - void HandleLfgSetBootVoteOpcode(WorldPacket &recv_data); - void HandleLfgTeleportOpcode(WorldPacket &recv_data); - void HandleLfrSearchOpcode(WorldPacket &recv_data); - void HandleLfrLeaveOpcode(WorldPacket &recv_data); + void HandleLfgJoinOpcode(WorldPacket& recv_data); + void HandleLfgLeaveOpcode(WorldPacket& recv_data); + void HandleLfgSetRolesOpcode(WorldPacket& recv_data); + void HandleLfgProposalResultOpcode(WorldPacket& recv_data); + void HandleLfgSetBootVoteOpcode(WorldPacket& recv_data); + void HandleLfgTeleportOpcode(WorldPacket& recv_data); + void HandleLfrSearchOpcode(WorldPacket& recv_data); + void HandleLfrLeaveOpcode(WorldPacket& recv_data); void SendLfgUpdatePlayer(const LfgUpdateData& updateData); void SendLfgUpdateParty(const LfgUpdateData& updateData); @@ -836,7 +834,7 @@ class WorldSession void HandleItemRefundInfoRequest(WorldPacket& recv_data); void HandleItemRefund(WorldPacket& recv_data); - void HandleChannelVoiceOnOpcode(WorldPacket & recv_data); + void HandleChannelVoiceOnOpcode(WorldPacket& recv_data); void HandleVoiceSessionEnableOpcode(WorldPacket& recv_data); void HandleSetActiveVoiceChannel(WorldPacket& recv_data); void HandleSetTaxiBenchmarkOpcode(WorldPacket& recv_data); @@ -878,7 +876,7 @@ class WorldSession void HandleCalendarGetNumPending(WorldPacket& recv_data); void HandleSpellClick(WorldPacket& recv_data); - void HandleMirrorImageDataRequest(WorldPacket & recv_data); + void HandleMirrorImageDataRequest(WorldPacket& recv_data); void HandleAlterAppearance(WorldPacket& recv_data); void HandleRemoveGlyph(WorldPacket& recv_data); void HandleCharCustomize(WorldPacket& recv_data); @@ -890,8 +888,8 @@ class WorldSession void HandleReadyForAccountDataTimes(WorldPacket& recv_data); void HandleQueryQuestsCompleted(WorldPacket& recv_data); void HandleQuestPOIQuery(WorldPacket& recv_data); - void HandleEjectPassenger(WorldPacket &data); - void HandleEnterPlayerVehicle(WorldPacket &data); + void HandleEjectPassenger(WorldPacket& data); + void HandleEnterPlayerVehicle(WorldPacket& data); void HandleUpdateProjectilePosition(WorldPacket& recvPacket); private: diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 3875156289e..0ddc03e3d5c 100755 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -802,7 +802,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) recvPacket >> clientSeed; recvPacket >> unk5 >> unk6 >> unk7; recvPacket >> unk4; - recvPacket.read (digest, 20); + recvPacket.read(digest, 20); sLog->outStaticDebug ("WorldSocket::HandleAuthSession: client %u, unk2 %u, account %s, unk3 %u, clientseed %u", BuiltNumberClient, diff --git a/src/server/game/Server/WorldSocketMgr.cpp b/src/server/game/Server/WorldSocketMgr.cpp index ec29273d6b0..b7d48f3ece5 100755 --- a/src/server/game/Server/WorldSocketMgr.cpp +++ b/src/server/game/Server/WorldSocketMgr.cpp @@ -192,7 +192,7 @@ class ReactorRunnable : protected ACE_Task_Base } } - sLog->outStaticDebug ("Network Thread Exitting"); + sLog->outStaticDebug ("Network Thread exits"); return 0; } diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 98b0303a30b..ed585739399 100755 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -5711,9 +5711,8 @@ void AuraEffect::HandlePeriodicDummyAuraTick(Unit* target, Unit* caster) const // eff_radius == 0 float radius = GetSpellInfo()->GetMaxRange(false); - CellPair p(Trinity::ComputeCellPair(target->GetPositionX(), target->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(target->GetPositionX(), target->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; Trinity::AnyUnfriendlyAttackableVisibleUnitInObjectRangeCheck u_check(target, radius); Trinity::UnitListSearcher<Trinity::AnyUnfriendlyAttackableVisibleUnitInObjectRangeCheck> checker(target, targets, u_check); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 16243396ebb..4d7534509e4 100755 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -598,9 +598,8 @@ WorldObject* Spell::FindCorpseUsing() // non-standard target selection float max_range = m_spellInfo->GetMaxRange(false); - CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(m_caster->GetPositionX(), m_caster->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); WorldObject* result = NULL; @@ -1202,7 +1201,6 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) m_spellAura = NULL; // Set aura to null for every target-make sure that pointer is not used for unit without aura applied //Spells with this flag cannot trigger if effect is casted on self - // Slice and Dice, relentless strikes, eviscerate bool canEffectTrigger = !(m_spellInfo->AttributesEx3 & SPELL_ATTR3_CANT_TRIGGER_PROC) && unitTarget->CanProc() && CanExecuteTriggersOnHit(mask); Unit* spellHitTarget = NULL; @@ -1598,12 +1596,12 @@ void Spell::DoTriggersOnSpellHit(Unit* unit, uint8 effMask) // this is executed after spell proc spells on target hit // spells are triggered for each hit spell target // info confirmed with retail sniffs of permafrost and shadow weaving - if (!m_hitTriggerSpells.empty() && CanExecuteTriggersOnHit(effMask)) + if (!m_hitTriggerSpells.empty()) { int _duration = 0; for (HitTriggerSpells::const_iterator i = m_hitTriggerSpells.begin(); i != m_hitTriggerSpells.end(); ++i) { - if (roll_chance_i(i->second)) + if (CanExecuteTriggersOnHit(effMask, i->first) && roll_chance_i(i->second)) { m_caster->CastSpell(unit, i->first, true); sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell %d triggered spell %d by SPELL_AURA_ADD_TARGET_TRIGGER aura", m_spellInfo->Id, i->first->Id); @@ -5639,7 +5637,16 @@ SpellCastResult Spell::CheckRange(bool strict) if (!strict && m_casttime == 0) return SPELL_CAST_OK; - uint32 range_type = m_spellInfo->RangeEntry ? m_spellInfo->RangeEntry->type : 0; + uint32 range_type = 0; + + if (m_spellInfo->RangeEntry) + { + // self cast is used for triggered spells, no range checking needed + if (m_spellInfo->RangeEntry->ID == 1) + return SPELL_CAST_OK; + + range_type = m_spellInfo->RangeEntry->type; + } Unit* target = m_targets.GetUnitTarget(); float max_range = m_caster->GetSpellMaxRangeForTarget(target, m_spellInfo); @@ -5820,9 +5827,8 @@ SpellCastResult Spell::CheckItems() // check spell focus object if (m_spellInfo->RequiresSpellFocus) { - CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(m_caster->GetPositionX(), m_caster->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; GameObject* ok = NULL; Trinity::GameObjectFocusCheck go_check(m_caster, m_spellInfo->RequiresSpellFocus); @@ -7085,17 +7091,17 @@ void Spell::CallScriptAfterUnitTargetSelectHandlers(std::list<Unit*>& unitTarget } } -bool Spell::CanExecuteTriggersOnHit(uint8 effMask) const +bool Spell::CanExecuteTriggersOnHit(uint8 effMask, SpellInfo const* spellInfo) const { - // check which effects can trigger proc - // don't allow to proc for dummy-only spell target hits - // prevents triggering/procing effects twice from spells like Eviscerate - for (uint8 i = 0;effMask && i < MAX_SPELL_EFFECTS; ++i) + bool only_on_dummy = (spellInfo && (spellInfo->AttributesEx4 & SPELL_ATTR4_PROC_ONLY_ON_DUMMY)); + // If triggered spell has SPELL_ATTR4_PROC_ONLY_ON_DUMMY then it can only proc on a casted spell with SPELL_EFFECT_DUMMY + // If triggered spell doesn't have SPELL_ATTR4_PROC_ONLY_ON_DUMMY then it can NOT proc on SPELL_EFFECT_DUMMY (needs confirmation) + for (uint8 i = 0;i < MAX_SPELL_EFFECTS; ++i) { - if (m_spellInfo->Effects[i].Effect == SPELL_EFFECT_DUMMY) - effMask &= ~(1<<i); + if ((effMask & (1 << i)) && (only_on_dummy == (m_spellInfo->Effects[i].Effect == SPELL_EFFECT_DUMMY))) + return true; } - return effMask; + return false; } void Spell::PrepareTriggersExecutedOnHit() diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 27b0844f32e..65ed47af322 100755 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -633,7 +633,7 @@ class Spell void CallScriptAfterUnitTargetSelectHandlers(std::list<Unit*>& unitTargets, SpellEffIndex effIndex); std::list<SpellScript*> m_loadedScripts; - bool CanExecuteTriggersOnHit(uint8 effMask) const; + bool CanExecuteTriggersOnHit(uint8 effMask, SpellInfo const* spellInfo = NULL) const; void PrepareTriggersExecutedOnHit(); typedef std::list< std::pair<SpellInfo const*, int32> > HitTriggerSpells; HitTriggerSpells m_hitTriggerSpells; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 19f84854ae4..83cecf7d884 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -456,7 +456,11 @@ void Spell::EffectSchoolDMG(SpellEffIndex effIndex) ApplyPctF(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); // Shield Slam else if (m_spellInfo->SpellFamilyFlags[1] & 0x200 && m_spellInfo->Category == 1209) - damage += int32(m_caster->ApplyEffectModifiers(m_spellInfo, effIndex, float(m_caster->GetShieldBlockValue()))); + { + uint8 level = m_caster->getLevel(); + uint32 block_value = m_caster->GetShieldBlockValue(uint32(float(level) * 24.5f), uint32(float(level) * 34.5f)); + damage += int32(m_caster->ApplyEffectModifiers(m_spellInfo, effIndex, float(block_value))); + } // Victory Rush else if (m_spellInfo->SpellFamilyFlags[1] & 0x100) ApplyPctF(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); @@ -716,7 +720,9 @@ void Spell::EffectSchoolDMG(SpellEffIndex effIndex) // Shield of Righteousness if (m_spellInfo->SpellFamilyFlags[EFFECT_1] & 0x100000) { - damage += CalculatePctN(m_caster->GetShieldBlockValue(), m_spellInfo->Effects[EFFECT_1].CalcValue()); + uint8 level = m_caster->getLevel(); + uint32 block_value = m_caster->GetShieldBlockValue(uint32(float(level) * 29.5f), uint32(float(level) * 39.5f)); + damage += CalculatePctN(block_value, m_spellInfo->Effects[EFFECT_1].CalcValue()); break; } break; @@ -1663,13 +1669,6 @@ void Spell::EffectTriggerSpell(SpellEffIndex effIndex) } return; } - // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet - case 41967: - { - if (Unit* pet = unitTarget->GetGuardianPet()) - pet->CastSpell(pet, 28305, true); - return; - } } } @@ -3575,7 +3574,7 @@ void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex) // add new enchanting if equipped item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, true); - itemTarget->SetSoulboundTradeable(NULL, item_owner, false); + itemTarget->ClearSoulboundTradeable(item_owner); } } @@ -3639,7 +3638,7 @@ void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex) // add new enchanting if equipped item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, true); - itemTarget->SetSoulboundTradeable(NULL, item_owner, false); + itemTarget->ClearSoulboundTradeable(item_owner); } void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex) diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 4fc9564baa3..35e380736c5 100755 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -694,6 +694,38 @@ void SpellMgr::GetSetOfSpellsInSpellGroup(SpellGroup group_id, std::set<uint32>& } } +bool SpellMgr::AddSameEffectStackRuleSpellGroups(SpellInfo const* spellInfo, int32 amount, std::map<SpellGroup, int32>& groups) const +{ + uint32 spellId = spellInfo->GetFirstRankSpell()->Id; + SpellSpellGroupMapBounds spellGroup = GetSpellSpellGroupMapBounds(spellId); + // Find group with SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT if it belongs to one + for (SpellSpellGroupMap::const_iterator itr = spellGroup.first; itr != spellGroup.second ; ++itr) + { + SpellGroup group = itr->second; + SpellGroupStackMap::const_iterator found = mSpellGroupStack.find(group); + if (found != mSpellGroupStack.end()) + { + if (found->second == SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT) + { + // Put the highest amount in the map + if (groups.find(group) == groups.end()) + groups[group] = amount; + else + { + int32 curr_amount = groups[group]; + // Take absolute value because this also counts for the highest negative aura + if (abs(curr_amount) < abs(amount)) + groups[group] = amount; + } + // return because a spell should be in only one SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT group + return true; + } + } + } + // Not in a SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT group, so return false + return false; +} + SpellGroupStackRule SpellMgr::CheckSpellGroupStackRules(SpellInfo const* spellInfo1, SpellInfo const* spellInfo2) const { uint32 spellid_1 = spellInfo1->GetFirstRankSpell()->Id; @@ -3116,6 +3148,7 @@ void SpellMgr::LoadDbcDataCorrections() case 51726: spellInfo->AttributesEx3 |= SPELL_ATTR3_STACK_FOR_DIFF_CASTERS; spellInfo->SpellFamilyFlags[2] = 0x10; + spellInfo->EffectApplyAuraName[1] = SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN; break; case 41913: // Parasitic Shadowfiend Passive spellInfo->EffectApplyAuraName[0] = 4; // proc debuff, and summon infinite fiends @@ -3146,6 +3179,24 @@ void SpellMgr::LoadDbcDataCorrections() case 6474: // Earthbind Totem (instant pulse) spellInfo->AttributesEx5 |= SPELL_ATTR5_START_PERIODIC_AT_APPLY; break; + case 2895: // Wrath of Air Totem rank 1 (Aura) + case 68933: // Wrath of Air Totem rank 2 (Aura) + spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; + spellInfo->EffectImplicitTargetB[0] = 0; + break; + case 52109: // Flametongue Totem rank 1 (Aura) + case 52110: // Flametongue Totem rank 2 (Aura) + case 52111: // Flametongue Totem rank 3 (Aura) + case 52112: // Flametongue Totem rank 4 (Aura) + case 52113: // Flametongue Totem rank 5 (Aura) + case 58651: // Flametongue Totem rank 6 (Aura) + case 58654: // Flametongue Totem rank 7 (Aura) + case 58655: // Flametongue Totem rank 8 (Aura) + spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; + spellInfo->EffectImplicitTargetA[1] = TARGET_UNIT_CASTER; + spellInfo->EffectImplicitTargetB[0] = 0; + spellInfo->EffectImplicitTargetB[1] = 0; + break; case 53241: // Marked for Death (Rank 1) case 53243: // Marked for Death (Rank 2) case 53244: // Marked for Death (Rank 3) diff --git a/src/server/game/Spells/SpellMgr.h b/src/server/game/Spells/SpellMgr.h index d701ab2882c..a3c4779e9f3 100755 --- a/src/server/game/Spells/SpellMgr.h +++ b/src/server/game/Spells/SpellMgr.h @@ -322,6 +322,7 @@ typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap; enum SpellGroup { + SPELL_GROUP_NONE = 0, SPELL_GROUP_ELIXIR_BATTLE = 1, SPELL_GROUP_ELIXIR_GUARDIAN = 2, SPELL_GROUP_ELIXIR_UNSTABLE = 3, @@ -344,8 +345,9 @@ enum SpellGroupStackRule SPELL_GROUP_STACK_RULE_DEFAULT = 0, SPELL_GROUP_STACK_RULE_EXCLUSIVE = 1, SPELL_GROUP_STACK_RULE_EXCLUSIVE_FROM_SAME_CASTER = 2, + SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT = 3, }; -#define SPELL_GROUP_STACK_RULE_MAX 3 +#define SPELL_GROUP_STACK_RULE_MAX 4 typedef std::map<SpellGroup, SpellGroupStackRule> SpellGroupStackMap; @@ -596,6 +598,7 @@ class SpellMgr void GetSetOfSpellsInSpellGroup(SpellGroup group_id, std::set<uint32>& foundSpells, std::set<SpellGroup>& usedGroups) const; // Spell Group Stack Rules table + bool AddSameEffectStackRuleSpellGroups(SpellInfo const* spellInfo, int32 amount, std::map<SpellGroup, int32>& groups) const; SpellGroupStackRule CheckSpellGroupStackRules(SpellInfo const* spellInfo1, SpellInfo const* spellInfo2) const; // Spell proc event table diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp index 2a352e92d01..68ccf96bb87 100644 --- a/src/server/scripts/Commands/cs_gm.cpp +++ b/src/server/scripts/Commands/cs_gm.cpp @@ -117,8 +117,8 @@ public: bool first = true; bool footer = false; - ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true); - HashMapHolder<Player>::MapType& m = sObjectAccessor->GetPlayers(); + ACE_READ_GUARD_RETURN(HashMapHolder<Player>::LockType, guard, *HashMapHolder<Player>::GetLock(), true); + HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { AccountTypes itrSec = itr->second->GetSession()->GetSecurity(); diff --git a/src/server/scripts/Commands/cs_gps.cpp b/src/server/scripts/Commands/cs_gps.cpp index 2a270527fb8..eb791b35e58 100644 --- a/src/server/scripts/Commands/cs_gps.cpp +++ b/src/server/scripts/Commands/cs_gps.cpp @@ -70,7 +70,7 @@ public: return false; } } - CellPair cell_val = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); + CellCoord cell_val = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); Cell cell(cell_val); uint32 zone_id, area_id; @@ -89,7 +89,7 @@ public: float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT); float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ()); - GridPair p = Trinity::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY()); + GridCoord p = Trinity::ComputeGridCoord(obj->GetPositionX(), obj->GetPositionY()); // 63? WHY? int gx = 63 - p.x_coord; diff --git a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_felmyst.cpp b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_felmyst.cpp index 4de719d684e..4e3f3899b35 100644 --- a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_felmyst.cpp +++ b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_felmyst.cpp @@ -484,15 +484,14 @@ public: float x, y, z; me->GetPosition(x, y, z); - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AllCreaturesOfEntryInRange check(me, entry, 100); Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(me, templist, check); TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> cSearcher(searcher); - cell.Visit(pair, cSearcher, *(me->GetMap())); + cell.Visit(pair, cSearcher, *(me->GetMap()), *me, me->GetGridActivationRange()); for (std::list<Creature*>::const_iterator i = templist.begin(); i != templist.end(); ++i) { diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_akilzon.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_akilzon.cpp index ba2d638d45f..413897c94e8 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_akilzon.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_akilzon.cpp @@ -189,22 +189,21 @@ class boss_akilzon : public CreatureScript for (uint8 i = 2; i < StormCount; ++i) bp0 *= 2; - CellPair p(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord p(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); std::list<Unit*> tempUnitMap; { - Trinity::AnyAoETargetUnitInObjectRangeCheck u_check(me, me, 999); + Trinity::AnyAoETargetUnitInObjectRangeCheck u_check(me, me, SIZE_OF_GRIDS); Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck> searcher(me, tempUnitMap, u_check); TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher); - cell.Visit(p, world_unit_searcher, *(me->GetMap())); - cell.Visit(p, grid_unit_searcher, *(me->GetMap())); + cell.Visit(p, world_unit_searcher, *me->GetMap(), *me, SIZE_OF_GRIDS); + cell.Visit(p, grid_unit_searcher, *me->GetMap(), *me, SIZE_OF_GRIDS); } //dealdamege for (std::list<Unit*>::const_iterator i = tempUnitMap.begin(); i != tempUnitMap.end(); ++i) diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_janalai.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_janalai.cpp index d2ad81b4910..aea9e322583 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_janalai.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_janalai.cpp @@ -233,9 +233,8 @@ class boss_janalai : public CreatureScript me->GetPosition(x, y, z); { - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AllCreaturesOfEntryInRange check(me, MOB_EGG, 100); @@ -243,7 +242,7 @@ class boss_janalai : public CreatureScript TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> cSearcher(searcher); - cell.Visit(pair, cSearcher, *(me->GetMap())); + cell.Visit(pair, cSearcher, *me->GetMap(), *me, me->GetGridActivationRange()); } //sLog->outError("Eggs %d at middle", templist.size()); @@ -267,9 +266,8 @@ class boss_janalai : public CreatureScript me->GetPosition(x, y, z); { - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AllCreaturesOfEntryInRange check(me, MOB_FIRE_BOMB, 100); @@ -277,7 +275,7 @@ class boss_janalai : public CreatureScript TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> cSearcher(searcher); - cell.Visit(pair, cSearcher, *(me->GetMap())); + cell.Visit(pair, cSearcher, *me->GetMap(), *me, me->GetGridActivationRange()); } for (std::list<Creature*>::const_iterator i = templist.begin(); i != templist.end(); ++i) { @@ -519,9 +517,8 @@ class mob_janalai_hatcher : public CreatureScript me->GetPosition(x, y, z); { - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AllCreaturesOfEntryInRange check(me, 23817, 50); @@ -529,7 +526,7 @@ class mob_janalai_hatcher : public CreatureScript TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange>, GridTypeMapContainer> cSearcher(searcher); - cell.Visit(pair, cSearcher, *(me->GetMap())); + cell.Visit(pair, cSearcher, *(me->GetMap()), *me, me->GetGridActivationRange()); } //sLog->outError("Eggs %d at %d", templist.size(), side); diff --git a/src/server/scripts/EasternKingdoms/ZulAman/boss_nalorakk.cpp b/src/server/scripts/EasternKingdoms/ZulAman/boss_nalorakk.cpp index 17968766a5f..3ff465a3c1d 100644 --- a/src/server/scripts/EasternKingdoms/ZulAman/boss_nalorakk.cpp +++ b/src/server/scripts/EasternKingdoms/ZulAman/boss_nalorakk.cpp @@ -162,9 +162,8 @@ class boss_nalorakk : public CreatureScript me->GetPosition(x, y, z); { - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::AllFriendlyCreaturesInGrid check(me); @@ -172,7 +171,7 @@ class boss_nalorakk : public CreatureScript TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> cSearcher(searcher); - cell.Visit(pair, cSearcher, *(me->GetMap())); + cell.Visit(pair, cSearcher, *(me->GetMap()), *me, me->GetGridActivationRange()); } if (templist.empty()) diff --git a/src/server/scripts/EasternKingdoms/eversong_woods.cpp b/src/server/scripts/EasternKingdoms/eversong_woods.cpp index 10b7066068b..d02cce3f17c 100644 --- a/src/server/scripts/EasternKingdoms/eversong_woods.cpp +++ b/src/server/scripts/EasternKingdoms/eversong_woods.cpp @@ -35,91 +35,6 @@ EndContentData */ #include "ScriptedEscortAI.h" /*###### -## npc_prospector_anvilward -######*/ - -#define GOSSIP_HELLO "I need a moment of your time, sir." -#define GOSSIP_SELECT "Why... yes, of course. I've something to show you right inside this building, Mr. Anvilward." - -enum eProspectorAnvilward -{ - SAY_ANVIL1 = -1000209, - SAY_ANVIL2 = -1000210, - QUEST_THE_DWARVEN_SPY = 8483, -}; - -class npc_prospector_anvilward : public CreatureScript -{ -public: - npc_prospector_anvilward() : CreatureScript("npc_prospector_anvilward") { } - - bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) - { - player->PlayerTalkClass->ClearMenus(); - switch (uiAction) - { - case GOSSIP_ACTION_INFO_DEF+1: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SELECT, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2); - player->SEND_GOSSIP_MENU(8240, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+2: - player->CLOSE_GOSSIP_MENU(); - if (npc_escortAI* pEscortAI = CAST_AI(npc_prospector_anvilward::npc_prospector_anvilwardAI, creature->AI())) - pEscortAI->Start(true, false, player->GetGUID()); - break; - } - return true; - } - - bool OnGossipHello(Player* player, Creature* creature) - { - if (player->GetQuestStatus(QUEST_THE_DWARVEN_SPY) == QUEST_STATUS_INCOMPLETE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HELLO, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1); - - player->SEND_GOSSIP_MENU(8239, creature->GetGUID()); - return true; - } - - CreatureAI* GetAI(Creature* creature) const - { - return new npc_prospector_anvilwardAI(creature); - } - - struct npc_prospector_anvilwardAI : public npc_escortAI - { - // CreatureAI functions - npc_prospector_anvilwardAI(Creature* c) : npc_escortAI(c) {} - - // Pure Virtual Functions - void WaypointReached(uint32 i) - { - Player* player = GetPlayerForEscort(); - - if (!player) - return; - - switch (i) - { - case 0: DoScriptText(SAY_ANVIL1, me, player); break; - case 5: DoScriptText(SAY_ANVIL2, me, player); break; - case 6: me->setFaction(24); break; - } - } - - void Reset() - { - me->RestoreFaction(); - } - - void JustDied(Unit* /*killer*/) - { - me->RestoreFaction(); - } - }; - -}; - -/*###### ## Quest 9686 Second Trial ######*/ @@ -711,7 +626,6 @@ public: void AddSC_eversong_woods() { - new npc_prospector_anvilward(); new npc_second_trial_controller(); new npc_second_trial_paladin(); new go_second_trial(); diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp index 6186369a3a0..187ff9b9dd7 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/BattleForMountHyjal/hyjalAI.cpp @@ -459,7 +459,9 @@ void hyjalAI::SummonCreature(uint32 entry, float Base[4][3]) creature = me->SummonCreature(entry, SpawnPointSpecial[SPAWN_NEAR_TOWER][0]+irand(-20, 20), SpawnPointSpecial[SPAWN_NEAR_TOWER][1]+irand(-20, 20), SpawnPointSpecial[SPAWN_NEAR_TOWER][2]+irand(-10, 10), 0, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 120000); if (creature) CAST_AI(hyjal_trashAI, creature->AI())->useFlyPath = true; - }else{//summon at gate + } + else + {//summon at gate creature = me->SummonCreature(entry, SpawnPointSpecial[SPAWN_GARG_GATE][0]+irand(-10, 10), SpawnPointSpecial[SPAWN_GARG_GATE][1]+irand(-10, 10), SpawnPointSpecial[SPAWN_GARG_GATE][2]+irand(-10, 10), 0, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 120000); } break; @@ -910,6 +912,7 @@ void hyjalAI::UpdateAI(const uint32 diff) DoMeleeAttackIfReady(); } + void hyjalAI::JustDied(Unit* /*killer*/) { if (IsDummy)return; @@ -932,23 +935,20 @@ void hyjalAI::JustDied(Unit* /*killer*/) instance->SetData(DATA_RESET_RAIDDAMAGE, 0);//reset damage on die } } + void hyjalAI::HideNearPos(float x, float y) { - CellPair pair(Trinity::ComputeCellPair(x, y)); + CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); // First get all creatures. std::list<Creature*> creatures; Trinity::AllFriendlyCreaturesInGrid creature_check(me); Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid> creature_searcher(me, creatures, creature_check); - TypeContainerVisitor - <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, - GridTypeMapContainer> creature_visitor(creature_searcher); - // Get Creatures - cell.Visit(pair, creature_visitor, *(me->GetMap())); + TypeContainerVisitor <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); + cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { @@ -959,18 +959,19 @@ void hyjalAI::HideNearPos(float x, float y) } } } + void hyjalAI::RespawnNearPos(float x, float y) { - CellPair p(Trinity::ComputeCellPair(x, y)); + CellCoord p(Trinity::ComputeCellCoord(x, y)); Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Trinity::RespawnDo u_do; Trinity::WorldObjectWorker<Trinity::RespawnDo> worker(me, u_do); TypeContainerVisitor<Trinity::WorldObjectWorker<Trinity::RespawnDo>, GridTypeMapContainer > obj_worker(worker); - cell.Visit(p, obj_worker, *me->GetMap()); + cell.Visit(p, obj_worker, *me->GetMap(), *me, me->GetGridActivationRange()); } + void hyjalAI::WaypointReached(uint32 i) { if (i == 1 || (i == 0 && me->GetEntry() == THRALL)) @@ -992,9 +993,8 @@ void hyjalAI::WaypointReached(uint32 i) } //do some talking //all alive guards walk near here - CellPair pair(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord pair(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); // First get all creatures. @@ -1005,7 +1005,7 @@ void hyjalAI::WaypointReached(uint32 i) <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); - cell.Visit(pair, creature_visitor, *(me->GetMap())); + cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { @@ -1034,9 +1034,8 @@ void hyjalAI::DoOverrun(uint32 faction, const uint32 diff) { if (TeleportTimer <= diff) { - CellPair pair(Trinity::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); + CellCoord pair(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); std::list<Creature*> creatures; @@ -1046,7 +1045,7 @@ void hyjalAI::DoOverrun(uint32 faction, const uint32 diff) <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); - cell.Visit(pair, creature_visitor, *(me->GetMap())); + cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { diff --git a/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_hadronox.cpp b/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_hadronox.cpp index dea3d6eaede..605f3a11c8a 100644 --- a/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_hadronox.cpp +++ b/src/server/scripts/Northrend/AzjolNerub/AzjolNerub/boss_hadronox.cpp @@ -118,7 +118,7 @@ public: return; float x=0.0f, y=0.0f, z=0.0f; - me->GetRespawnCoord(x, y, z); + me->GetRespawnPosition(x, y, z); if (uiCheckDistanceTimer <= uiDiff) uiCheckDistanceTimer = 5*IN_MILLISECONDS; diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp index e4749fd2ffe..be83c4d326a 100755 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp @@ -284,7 +284,7 @@ public: if (m_uiPenetratingColdTimer <= uiDiff) { - me->CastCustomSpell(SPELL_PENETRATING_COLD, SPELLVALUE_MAX_TARGETS, RAID_MODE(2, 5)); + me->CastCustomSpell(SPELL_PENETRATING_COLD, SPELLVALUE_MAX_TARGETS, RAID_MODE(2, 5, 2, 5)); m_uiPenetratingColdTimer = 20*IN_MILLISECONDS; } else m_uiPenetratingColdTimer -= uiDiff; diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp index 1688624be91..38f334058b8 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp @@ -1227,7 +1227,7 @@ class npc_tirion_fordring_tft : public CreatureScript SetEquipmentSlots(true); // remove glow on ashbringer } - void sGossipSelect(Player* player, uint32 sender, uint32 action) + void sGossipSelect(Player* /*player*/, uint32 sender, uint32 action) { if (me->GetCreatureInfo()->GossipMenuId == sender && !action) { @@ -1407,14 +1407,14 @@ class npc_raging_spirit : public CreatureScript DoCast(me, SPELL_BOSS_HITTIN_YA, true); } - void IsSummonedBy(Unit* summoner) + void IsSummonedBy(Unit* /*summoner*/) { // player is the spellcaster so register summon manually if (Creature* lichKing = ObjectAccessor::GetCreature(*me, _instance->GetData64(DATA_THE_LICH_KING))) lichKing->AI()->JustSummoned(me); } - void JustDied(Unit* killer) + void JustDied(Unit* /*killer*/) { if (Creature* lichKing = ObjectAccessor::GetCreature(*me, _instance->GetData64(DATA_THE_LICH_KING))) lichKing->AI()->SummonedCreatureDespawn(me); @@ -1931,7 +1931,7 @@ class npc_spirit_bomb : public CreatureScript { } - void IsSummonedBy(Unit* summoner) + void IsSummonedBy(Unit* /*summoner*/) { float destX, destY, destZ; me->GetPosition(destX, destY); @@ -1954,7 +1954,7 @@ class npc_spirit_bomb : public CreatureScript { } - void UpdateAI(uint32 const diff) + void UpdateAI(uint32 const /*diff*/) { UpdateVictim(); // no melee attacks @@ -1983,7 +1983,7 @@ class npc_broken_frostmourne : public CreatureScript _events.Reset(); } - void IsSummonedBy(Unit* summoner) + void IsSummonedBy(Unit* /*summoner*/) { _events.SetPhase(PHASE_OUTRO); _events.ScheduleEvent(EVENT_OUTRO_KNOCK_BACK, 3000, 0, PHASE_OUTRO); @@ -2087,7 +2087,6 @@ class spell_the_lich_king_necrotic_plague : public SpellScriptLoader void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) { - Unit* newCaster = GetTarget(); switch (GetTargetApplication()->GetRemoveMode()) { case AURA_REMOVE_BY_ENEMY_SPELL: @@ -2250,7 +2249,7 @@ class spell_the_lich_king_shadow_trap_visual : public SpellScriptLoader { PrepareAuraScript(spell_the_lich_king_shadow_trap_visual_AuraScript); - void OnRemove(AuraEffect const* aurEff, AuraEffectHandleModes mode) + void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) { if (GetTargetApplication()->GetRemoveMode() == AURA_REMOVE_BY_EXPIRE) GetTarget()->CastSpell(GetTarget(), SPELL_SHADOW_TRAP_AURA, TRIGGERED_NONE); @@ -2633,7 +2632,7 @@ class spell_the_lich_king_cast_back_to_caster : public SpellScriptLoader { PrepareSpellScript(spell_the_lich_king_cast_back_to_caster_SpellScript); - void HandleScript(SpellEffIndex effIndex) + void HandleScript(SpellEffIndex /*effIndex*/) { GetHitUnit()->CastSpell(GetCaster(), uint32(GetEffectValue()), true); } diff --git a/src/server/scripts/Northrend/dalaran.cpp b/src/server/scripts/Northrend/dalaran.cpp index be9e9308f4f..8ff5a314dcc 100644 --- a/src/server/scripts/Northrend/dalaran.cpp +++ b/src/server/scripts/Northrend/dalaran.cpp @@ -70,8 +70,9 @@ public: return; Player* player = who->GetCharmerOrOwnerPlayerOrPlayerItself(); - - if (!player || player->isGameMaster() || player->IsBeingTeleported()) + + // If player has Disguise aura for quest A Meeting With The Magister or An Audience With The Arcanist, do not teleport it away but let it pass + if (!player || player->isGameMaster() || player->IsBeingTeleported() || player->HasAura(70973) || player->HasAura(70971)) return; switch (me->GetEntry()) diff --git a/src/server/scripts/OutdoorPvP/OutdoorPvPNA.cpp b/src/server/scripts/OutdoorPvP/OutdoorPvPNA.cpp index c081f0970f2..9b0a4a469ae 100755 --- a/src/server/scripts/OutdoorPvP/OutdoorPvPNA.cpp +++ b/src/server/scripts/OutdoorPvP/OutdoorPvPNA.cpp @@ -384,7 +384,7 @@ bool OPvPCapturePointNA::HandleCustomSpell(Player* player, uint32 spellId, GameO int32 count = 10; uint32 itemid = 24538; // bomb id count - uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemid, count, &noSpaceForCount); + InventoryResult msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemid, count, &noSpaceForCount); if (msg != EQUIP_ERR_OK) // convert to possible store amount count -= noSpaceForCount; diff --git a/src/server/scripts/Outland/nagrand.cpp b/src/server/scripts/Outland/nagrand.cpp index b639050320c..726edb5efb2 100644 --- a/src/server/scripts/Outland/nagrand.cpp +++ b/src/server/scripts/Outland/nagrand.cpp @@ -19,330 +19,20 @@ /* ScriptData SDName: Nagrand SD%Complete: 90 -SDComment: Quest support: 9849, 9868, 9918, 9874, 9991, 10107, 10108, 10044, 10172, 10646, 10085, 10987. TextId's unknown for altruis_the_sufferer and greatmother_geyah (npc_text) +SDComment: Quest support: 9868, 9874, 10044, 10172, 10085. TextId's unknown for altruis_the_sufferer and greatmother_geyah (npc_text) SDCategory: Nagrand EndScriptData */ /* ContentData -mob_shattered_rumbler -mob_lump -npc_altruis_the_sufferer npc_greatmother_geyah -npc_lantresor_of_the_blade npc_maghar_captive npc_creditmarker_visit_with_ancestors -mob_sparrowhawk EndContentData */ #include "ScriptPCH.h" #include "ScriptedEscortAI.h" /*###### -## mob_shattered_rumbler - this should be done with ACID -######*/ - -class mob_shattered_rumbler : public CreatureScript -{ -public: - mob_shattered_rumbler() : CreatureScript("mob_shattered_rumbler") { } - - CreatureAI* GetAI(Creature* creature) const - { - return new mob_shattered_rumblerAI (creature); - } - - struct mob_shattered_rumblerAI : public ScriptedAI - { - bool Spawn; - - mob_shattered_rumblerAI(Creature* c) : ScriptedAI(c) {} - - void Reset() - { - Spawn = false; - } - - void EnterCombat(Unit* /*who*/) {} - - void SpellHit(Unit* Hitter, const SpellInfo* Spellkind) - { - if (Spellkind->Id == 32001 && !Spawn) - { - float x = me->GetPositionX(); - float y = me->GetPositionY(); - float z = me->GetPositionZ(); - - Hitter->SummonCreature(18181, x+(0.7f * (rand()%30)), y+(rand()%5), z, 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 60000); - Hitter->SummonCreature(18181, x+(rand()%5), y-(rand()%5), z, 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 60000); - Hitter->SummonCreature(18181, x-(rand()%5), y+(0.5f *(rand()%60)), z, 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 60000); - me->setDeathState(CORPSE); - Spawn = true; - } - return; - } - }; - -}; - -/*###### -## mob_lump -######*/ - -#define SPELL_VISUAL_SLEEP 16093 -#define SPELL_SPEAR_THROW 32248 - -#define LUMP_SAY0 -1000190 -#define LUMP_SAY1 -1000191 - -#define LUMP_DEFEAT -1000192 - -#define GOSSIP_HL "I need answers, ogre!" -#define GOSSIP_SL1 "Why are Boulderfist out this far? You know that this is Kurenai territory." -#define GOSSIP_SL2 "And you think you can just eat anything you want? You're obviously trying to eat the Broken of Telaar." -#define GOSSIP_SL3 "This means war, Lump! War I say!" - -class mob_lump : public CreatureScript -{ -public: - mob_lump() : CreatureScript("mob_lump") { } - - bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) - { - player->PlayerTalkClass->ClearMenus(); - switch (uiAction) - { - case GOSSIP_ACTION_INFO_DEF: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SL1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1); - player->SEND_GOSSIP_MENU(9353, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+1: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SL2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2); - player->SEND_GOSSIP_MENU(9354, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+2: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SL3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3); - player->SEND_GOSSIP_MENU(9355, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+3: - player->SEND_GOSSIP_MENU(9356, creature->GetGUID()); - player->TalkedToCreature(18354, creature->GetGUID()); - break; - } - return true; - } - - bool OnGossipHello(Player* player, Creature* creature) - { - if (player->GetQuestStatus(9918) == QUEST_STATUS_INCOMPLETE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HL, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF); - - player->SEND_GOSSIP_MENU(9352, creature->GetGUID()); - - return true; - } - - CreatureAI* GetAI(Creature* creature) const - { - return new mob_lumpAI(creature); - } - - struct mob_lumpAI : public ScriptedAI - { - mob_lumpAI(Creature* c) : ScriptedAI(c) - { - bReset = false; - } - - uint32 Reset_Timer; - uint32 Spear_Throw_Timer; - bool bReset; - - void Reset() - { - Reset_Timer = 60000; - Spear_Throw_Timer = 2000; - - me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); - } - - void AttackedBy(Unit* pAttacker) - { - if (me->getVictim()) - return; - - if (me->IsFriendlyTo(pAttacker)) - return; - - AttackStart(pAttacker); - } - - void DamageTaken(Unit* done_by, uint32 & damage) - { - if (done_by->GetTypeId() == TYPEID_PLAYER && me->HealthBelowPctDamaged(30, damage)) - { - if (!bReset && CAST_PLR(done_by)->GetQuestStatus(9918) == QUEST_STATUS_INCOMPLETE) - { - //Take 0 damage - damage = 0; - - CAST_PLR(done_by)->AttackStop(); - me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); - me->RemoveAllAuras(); - me->DeleteThreatList(); - me->CombatStop(true); - me->setFaction(1080); //friendly - me->SetStandState(UNIT_STAND_STATE_SIT); - DoScriptText(LUMP_DEFEAT, me); - - bReset = true; - } - } - } - - void EnterCombat(Unit* /*who*/) - { - if (me->HasAura(SPELL_VISUAL_SLEEP)) - me->RemoveAura(SPELL_VISUAL_SLEEP); - - if (!me->IsStandState()) - me->SetStandState(UNIT_STAND_STATE_STAND); - - DoScriptText(RAND(LUMP_SAY0, LUMP_SAY1), me); - } - - void UpdateAI(const uint32 diff) - { - //check if we waiting for a reset - if (bReset) - { - if (Reset_Timer <= diff) - { - EnterEvadeMode(); - bReset = false; - me->setFaction(1711); //hostile - return; - } - else Reset_Timer -= diff; - } - - //Return since we have no target - if (!UpdateVictim()) - return; - - //Spear_Throw_Timer - if (Spear_Throw_Timer <= diff) - { - DoCast(me->getVictim(), SPELL_SPEAR_THROW); - Spear_Throw_Timer = 20000; - } else Spear_Throw_Timer -= diff; - - DoMeleeAttackIfReady(); - } - }; - -}; - -/*###### -## npc_altruis_the_sufferer -######*/ - -#define GOSSIP_HATS1 "I see twisted steel and smell sundered earth." -#define GOSSIP_HATS2 "Well...?" -#define GOSSIP_HATS3 "[PH] Story about Illidan's Pupil" - -#define GOSSIP_SATS1 "Legion?" -#define GOSSIP_SATS2 "And now?" -#define GOSSIP_SATS3 "How do you see them now?" -#define GOSSIP_SATS4 "Forge camps?" -#define GOSSIP_SATS5 "Ok." -#define GOSSIP_SATS6 "[PH] Story done" - -class npc_altruis_the_sufferer : public CreatureScript -{ -public: - npc_altruis_the_sufferer() : CreatureScript("npc_altruis_the_sufferer") { } - - bool OnQuestAccept(Player* player, Creature* /*creature*/, Quest const* /*quest*/) - { - if (!player->GetQuestRewardStatus(9991)) //Survey the Land, q-id 9991 - { - player->CLOSE_GOSSIP_MENU(); - player->ActivateTaxiPathTo(532); //TaxiPath 532 - } - return true; - } - - bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) - { - player->PlayerTalkClass->ClearMenus(); - switch (uiAction) - { - case GOSSIP_ACTION_INFO_DEF+10: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 11); - player->SEND_GOSSIP_MENU(9420, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+11: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 12); - player->SEND_GOSSIP_MENU(9421, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+12: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 13); - player->SEND_GOSSIP_MENU(9422, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+13: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS4, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 14); - player->SEND_GOSSIP_MENU(9423, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+14: - player->SEND_GOSSIP_MENU(9424, creature->GetGUID()); - break; - - case GOSSIP_ACTION_INFO_DEF+20: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS5, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 21); - player->SEND_GOSSIP_MENU(9427, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+21: - player->CLOSE_GOSSIP_MENU(); - player->AreaExploredOrEventHappens(9991); - break; - - case GOSSIP_ACTION_INFO_DEF+30: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SATS6, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 31); - player->SEND_GOSSIP_MENU(384, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+31: - player->CLOSE_GOSSIP_MENU(); - player->AreaExploredOrEventHappens(10646); - break; - } - return true; - } - - bool OnGossipHello(Player* player, Creature* creature) - { - if (creature->isQuestGiver()) - player->PrepareQuestMenu(creature->GetGUID()); - - //gossip before obtaining Survey the Land - if (player->GetQuestStatus(9991) == QUEST_STATUS_NONE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HATS1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+10); - - //gossip when Survey the Land is incomplete (technically, after the flight) - if (player->GetQuestStatus(9991) == QUEST_STATUS_INCOMPLETE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HATS2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+20); - - //wowwiki.com/Varedis - if (player->GetQuestStatus(10646) == QUEST_STATUS_INCOMPLETE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HATS3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+30); - - player->SEND_GOSSIP_MENU(9419, creature->GetGUID()); - - return true; - } - -}; - -/*###### ## npc_greatmother_geyah ######*/ @@ -453,83 +143,6 @@ public: }; -/*###### -## npc_lantresor_of_the_blade -######*/ - -#define GOSSIP_HLB "I have killed many of your ogres, Lantresor. I have no fear." -#define GOSSIP_SLB1 "Should I know? You look like an orc to me." -#define GOSSIP_SLB2 "And the other half?" -#define GOSSIP_SLB3 "I have heard of your kind, but I never thought to see the day when I would meet a half-breed." -#define GOSSIP_SLB4 "My apologies. I did not mean to offend. I am here on behalf of my people." -#define GOSSIP_SLB5 "My people ask that you pull back your Boulderfist ogres and cease all attacks on our territories. In return, we will also pull back our forces." -#define GOSSIP_SLB6 "We will fight you until the end, then, Lantresor. We will not stand idly by as you pillage our towns and kill our people." -#define GOSSIP_SLB7 "What do I need to do?" - -class npc_lantresor_of_the_blade : public CreatureScript -{ -public: - npc_lantresor_of_the_blade() : CreatureScript("npc_lantresor_of_the_blade") { } - - bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) - { - player->PlayerTalkClass->ClearMenus(); - switch (uiAction) - { - case GOSSIP_ACTION_INFO_DEF: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1); - player->SEND_GOSSIP_MENU(9362, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+1: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2); - player->SEND_GOSSIP_MENU(9363, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+2: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3); - player->SEND_GOSSIP_MENU(9364, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+3: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB4, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4); - player->SEND_GOSSIP_MENU(9365, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+4: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB5, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5); - player->SEND_GOSSIP_MENU(9366, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+5: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB6, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6); - player->SEND_GOSSIP_MENU(9367, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+6: - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_SLB7, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7); - player->SEND_GOSSIP_MENU(9368, creature->GetGUID()); - break; - case GOSSIP_ACTION_INFO_DEF+7: - player->SEND_GOSSIP_MENU(9369, creature->GetGUID()); - if (player->GetQuestStatus(10107) == QUEST_STATUS_INCOMPLETE) - player->AreaExploredOrEventHappens(10107); - if (player->GetQuestStatus(10108) == QUEST_STATUS_INCOMPLETE) - player->AreaExploredOrEventHappens(10108); - break; - } - return true; - } - - bool OnGossipHello(Player* player, Creature* creature) - { - if (creature->isQuestGiver()) - player->PrepareQuestMenu(creature->GetGUID()); - - if (player->GetQuestStatus(10107) == QUEST_STATUS_INCOMPLETE || player->GetQuestStatus(10108) == QUEST_STATUS_INCOMPLETE) - player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_HLB, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF); - - player->SEND_GOSSIP_MENU(9361, creature->GetGUID()); - - return true; - } - -}; - /*##### ## npc_maghar_captive #####*/ @@ -747,113 +360,9 @@ public: }; /*###### -## mob_sparrowhawk +## go_corkis_prison and npc_corki ######*/ -#define SPELL_SPARROWHAWK_NET 39810 -#define SPELL_ITEM_CAPTIVE_SPARROWHAWK 39812 - -class mob_sparrowhawk : public CreatureScript -{ -public: - mob_sparrowhawk() : CreatureScript("mob_sparrowhawk") { } - - CreatureAI* GetAI(Creature* creature) const - { - return new mob_sparrowhawkAI (creature); - } - - struct mob_sparrowhawkAI : public ScriptedAI - { - - mob_sparrowhawkAI(Creature* c) : ScriptedAI(c) {} - - uint32 Check_Timer; - uint64 PlayerGUID; - bool fleeing; - - void Reset() - { - me->RemoveAurasDueToSpell(SPELL_SPARROWHAWK_NET); - Check_Timer = 1000; - PlayerGUID = 0; - fleeing = false; - } - void AttackStart(Unit* who) - { - if (PlayerGUID) - return; - - ScriptedAI::AttackStart(who); - } - - void EnterCombat(Unit* /*who*/) {} - - void MoveInLineOfSight(Unit* who) - { - if (!who || PlayerGUID) - return; - - if (!PlayerGUID && who->GetTypeId() == TYPEID_PLAYER && me->IsWithinDistInMap(who, 30) && CAST_PLR(who)->GetQuestStatus(10987) == QUEST_STATUS_INCOMPLETE) - { - PlayerGUID = who->GetGUID(); - return; - } - - ScriptedAI::MoveInLineOfSight(who); - } - - void UpdateAI(const uint32 diff) - { - if (Check_Timer <= diff) - { - if (PlayerGUID) - { - if (fleeing && me->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLEEING_MOTION_TYPE) - fleeing = false; - - Player* player = Unit::GetPlayer(*me, PlayerGUID); - if (player && me->IsWithinDistInMap(player, 30)) - { - if (!fleeing) - { - me->DeleteThreatList(); - me->GetMotionMaster()->MoveFleeing(player); - fleeing = true; - } - } - else if (fleeing) - { - me->GetMotionMaster()->MovementExpired(false); - PlayerGUID = 0; - fleeing = false; - } - } - Check_Timer = 1000; - } else Check_Timer -= diff; - - if (PlayerGUID) - return; - - ScriptedAI::UpdateAI(diff); - } - - void SpellHit(Unit* caster, const SpellInfo* spell) - { - if (caster->GetTypeId() == TYPEID_PLAYER) - { - if (spell->Id == SPELL_SPARROWHAWK_NET && CAST_PLR(caster)->GetQuestStatus(10987) == QUEST_STATUS_INCOMPLETE) - { - DoCast(caster, SPELL_ITEM_CAPTIVE_SPARROWHAWK, true); - me->DealDamage(me, me->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); - me->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); - } - } - return; - } - }; -}; - enum CorkiData { // first quest @@ -916,10 +425,6 @@ public: } }; -/*###### -## npc_corki -######*/ - class npc_corki : public CreatureScript { public: @@ -970,16 +475,241 @@ public: }; }; +/*##### +## npc_kurenai_captive +#####*/ + +enum KurenaiCaptive +{ + SAY_KUR_START = 0, + SAY_KUR_NO_ESCAPE = 1, + SAY_KUR_MORE = 2, + SAY_KUR_MORE_TWO = 3, + SAY_KUR_LIGHTNING = 4, + SAY_KUR_SHOCK = 5, + SAY_KUR_COMPLETE = 6, + + SPELL_KUR_CHAIN_LIGHTNING = 16006, + SPELL_KUR_EARTHBIND_TOTEM = 15786, + SPELL_KUR_FROST_SHOCK = 12548, + SPELL_KUR_HEALING_WAVE = 12491, + + QUEST_TOTEM_KARDASH_A = 9879, + + NPC_KUR_MURK_RAIDER = 18203, + NPC_KUR_MURK_BRUTE = 18211, + NPC_KUR_MURK_SCAVENGER = 18207, + NPC_KUR_MURK_PUTRIFIER = 18202, +}; + +static float kurenaiAmbushA[]= {-1568.805786f, 8533.873047f, 1.958f}; +static float kurenaiAmbushB[]= {-1491.554321f, 8506.483398f, 1.248f}; + +class npc_kurenai_captive : public CreatureScript +{ +public: + npc_kurenai_captive() : CreatureScript("npc_kurenai_captive") { } + + bool OnQuestAccept(Player* player, Creature* creature, const Quest* quest) + { + if (quest->GetQuestId() == QUEST_TOTEM_KARDASH_A) + { + if (npc_kurenai_captiveAI* EscortAI = dynamic_cast<npc_kurenai_captiveAI*>(creature->AI())) + { + creature->SetStandState(UNIT_STAND_STATE_STAND); + EscortAI->Start(true, false, player->GetGUID(), quest); + DoScriptText(SAY_KUR_START, creature); + + creature->SummonCreature(NPC_KUR_MURK_RAIDER, kurenaiAmbushA[0]+2.5f, kurenaiAmbushA[1]-2.5f, kurenaiAmbushA[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + creature->SummonCreature(NPC_KUR_MURK_BRUTE, kurenaiAmbushA[0]-2.5f, kurenaiAmbushA[1]+2.5f, kurenaiAmbushA[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + creature->SummonCreature(NPC_KUR_MURK_SCAVENGER, kurenaiAmbushA[0], kurenaiAmbushA[1], kurenaiAmbushA[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + } + } + return true; + } + + CreatureAI* GetAI(Creature* creature) const + { + return new npc_kurenai_captiveAI(creature); + } + + struct npc_kurenai_captiveAI : public npc_escortAI + { + npc_kurenai_captiveAI(Creature* creature) : npc_escortAI(creature) { } + + uint32 ChainLightningTimer; + uint32 HealTimer; + uint32 FrostShockTimer; + + void Reset() + { + ChainLightningTimer = 1000; + HealTimer = 0; + FrostShockTimer = 6000; + } + + void EnterCombat(Unit* /*who*/) + { + DoCast(me, SPELL_KUR_EARTHBIND_TOTEM, false); + } + + void JustDied(Unit* /*killer*/) + { + if (!HasEscortState(STATE_ESCORT_ESCORTING)) + return; + + if (Player* player = GetPlayerForEscort()) + { + if (player->GetQuestStatus(QUEST_TOTEM_KARDASH_A) != QUEST_STATUS_COMPLETE) + player->FailQuest(QUEST_TOTEM_KARDASH_A); + } + } + + void WaypointReached(uint32 PointId) + { + switch(PointId) + { + case 3: + { + Talk(SAY_KUR_MORE); + + if (Creature* temp = me->SummonCreature(NPC_KUR_MURK_PUTRIFIER, kurenaiAmbushB[0], kurenaiAmbushB[1], kurenaiAmbushB[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000)) + Talk(SAY_KUR_MORE_TWO); + + me->SummonCreature(NPC_KUR_MURK_PUTRIFIER, kurenaiAmbushB[0]-2.5f, kurenaiAmbushB[1]-2.5f, kurenaiAmbushB[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + me->SummonCreature(NPC_KUR_MURK_SCAVENGER, kurenaiAmbushB[0]+2.5f, kurenaiAmbushB[1]+2.5f, kurenaiAmbushB[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + me->SummonCreature(NPC_KUR_MURK_SCAVENGER, kurenaiAmbushB[0]+2.5f, kurenaiAmbushB[1]-2.5f, kurenaiAmbushB[2], 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + break; + } + case 7: + { + Talk(SAY_KUR_COMPLETE); + + if (Player* player = GetPlayerForEscort()) + player->GroupEventHappens(QUEST_TOTEM_KARDASH_A, me); + + SetRun(); + break; + } + } + } + + void JustSummoned(Creature* summoned) + { + if (summoned->GetEntry() == NPC_KUR_MURK_BRUTE) + Talk(SAY_KUR_NO_ESCAPE); + + // This function is for when we summoned enemies to fight - so that does NOT mean we should make our totem count in this! + if (summoned->isTotem()) + return; + + summoned->RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING); + summoned->GetMotionMaster()->MovePoint(0, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()); + summoned->AI()->AttackStart(me); + } + + void SpellHitTarget(Unit* /*target*/, const SpellInfo* spell) + { + if (spell->Id == SPELL_KUR_CHAIN_LIGHTNING) + { + if (rand()%30) + return; + + Talk(SAY_KUR_LIGHTNING); + } + + if (spell->Id == SPELL_KUR_FROST_SHOCK) + { + if (rand()%30) + return; + + Talk(SAY_KUR_SHOCK); + } + } + + void UpdateAI(const uint32 diff) + { + if (!UpdateVictim()) + return; + + if (me->HasUnitState(UNIT_STAT_CASTING)) + return; + + if (ChainLightningTimer <= diff) + { + DoCast(me->getVictim(), SPELL_KUR_CHAIN_LIGHTNING); + ChainLightningTimer = urand(7000,14000); + } else ChainLightningTimer -= diff; + + if (HealthBelowPct(30)) + { + if (HealTimer <= diff) + { + DoCast(me, SPELL_KUR_HEALING_WAVE); + HealTimer = 5000; + } else HealTimer -= diff; + } + + if (FrostShockTimer <= diff) + { + DoCast(me->getVictim(), SPELL_KUR_FROST_SHOCK); + FrostShockTimer = urand(7500,15000); + } else FrostShockTimer -= diff; + + DoMeleeAttackIfReady(); + } + }; +}; + +/*###### +## go_warmaul_prison +######*/ + +enum FindingTheSurvivorsData +{ + QUEST_FINDING_THE_SURVIVORS = 9948, + NPC_MAGHAR_PRISONER = 18428, + + SAY_FREE_0 = 0, + SAY_FREE_1 = 1, + SAY_FREE_2 = 2, + SAY_FREE_3 = 3, + SAY_FREE_4 = 4, +}; + +class go_warmaul_prison : public GameObjectScript +{ +public: + go_warmaul_prison() : GameObjectScript("go_warmaul_prison") { } + + bool OnGossipHello(Player* player, GameObject* go) + { + if (player->GetQuestStatus(QUEST_FINDING_THE_SURVIVORS) != QUEST_STATUS_INCOMPLETE) + return false; + + if (Creature* prisoner = go->FindNearestCreature(NPC_MAGHAR_PRISONER, 1.0f)) + { + if (prisoner) + { + go->UseDoorOrButton(); + if (player) + player->KilledMonsterCredit(NPC_MAGHAR_PRISONER, 0); + + prisoner->AI()->Talk(RAND(SAY_FREE_0, SAY_FREE_1, SAY_FREE_2, SAY_FREE_3, SAY_FREE_4), player->GetGUID()); + prisoner->ForcedDespawn(6000); + } + } + return true; + } +}; + void AddSC_nagrand() { - new mob_shattered_rumbler(); - new mob_lump(); - new npc_altruis_the_sufferer(); new npc_greatmother_geyah(); - new npc_lantresor_of_the_blade(); new npc_maghar_captive(); new npc_creditmarker_visit_with_ancestors(); - new mob_sparrowhawk(); new npc_corki(); new go_corkis_prison(); + new npc_kurenai_captive(); + new go_warmaul_prison(); } diff --git a/src/server/scripts/Spells/spell_quest.cpp b/src/server/scripts/Spells/spell_quest.cpp index 6ae9577070e..3b2cc5f5e00 100644 --- a/src/server/scripts/Spells/spell_quest.cpp +++ b/src/server/scripts/Spells/spell_quest.cpp @@ -899,7 +899,6 @@ class spell_q9874_liquid_fire : public SpellScriptLoader }; }; - enum SalvagingLifesStength { NPC_SHARD_KILL_CREDIT = 29303, @@ -950,6 +949,7 @@ enum eBattleStandard { NPC_KING_OF_THE_MOUNTAINT_KC = 31766, }; + class spell_q13280_13283_plant_battle_standard: public SpellScriptLoader { public: @@ -978,6 +978,54 @@ public: } }; +enum ChumTheWaterSummons +{ + SUMMON_ANGRY_KVALDIR = 66737, + SUMMON_NORTH_SEA_MAKO = 66738, + SUMMON_NORTH_SEA_THRESHER = 66739, + SUMMON_NORTH_SEA_BLUE_SHARK = 66740 +}; + +class spell_q14112_14145_chum_the_water: public SpellScriptLoader +{ +public: + spell_q14112_14145_chum_the_water() : SpellScriptLoader("spell_q14112_14145_chum_the_water") { } + + class spell_q14112_14145_chum_the_water_SpellScript : public SpellScript + { + PrepareSpellScript(spell_q14112_14145_chum_the_water_SpellScript); + + bool Validate(SpellInfo const* /*spellEntry*/) + { + if (!sSpellMgr->GetSpellInfo(SUMMON_ANGRY_KVALDIR)) + return false; + if (!sSpellMgr->GetSpellInfo(SUMMON_NORTH_SEA_MAKO)) + return false; + if (!sSpellMgr->GetSpellInfo(SUMMON_NORTH_SEA_THRESHER)) + return false; + if (!sSpellMgr->GetSpellInfo(SUMMON_NORTH_SEA_BLUE_SHARK)) + return false; + return true; + } + + void HandleScriptEffect(SpellEffIndex /*effIndex*/) + { + Unit* caster = GetCaster(); + caster->CastSpell(caster, RAND(SUMMON_ANGRY_KVALDIR, SUMMON_NORTH_SEA_MAKO, SUMMON_NORTH_SEA_THRESHER, SUMMON_NORTH_SEA_BLUE_SHARK)); + } + + void Register() + { + OnEffectHitTarget += SpellEffectFn(spell_q14112_14145_chum_the_water_SpellScript::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT); + } + }; + + SpellScript* GetSpellScript() const + { + return new spell_q14112_14145_chum_the_water_SpellScript(); + } +}; + void AddSC_quest_spell_scripts() { new spell_q55_sacred_cleansing(); @@ -1001,4 +1049,5 @@ void AddSC_quest_spell_scripts() new spell_q9874_liquid_fire(); new spell_q12805_lifeblood_dummy(); new spell_q13280_13283_plant_battle_standard(); + new spell_q14112_14145_chum_the_water(); } diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h index ffecf020d24..01aff4bb10f 100755 --- a/src/server/shared/Common.h +++ b/src/server/shared/Common.h @@ -146,12 +146,12 @@ inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; } enum TimeConstants { - MINUTE = 60, - HOUR = MINUTE*60, - DAY = HOUR*24, - WEEK = DAY*7, - MONTH = DAY*30, - YEAR = MONTH*12, + MINUTE = 60, + HOUR = MINUTE*60, + DAY = HOUR*24, + WEEK = DAY*7, + MONTH = DAY*30, + YEAR = MONTH*12, IN_MILLISECONDS = 1000 }; diff --git a/src/server/shared/Cryptography/ARC4.h b/src/server/shared/Cryptography/ARC4.h index 777dbb8cb99..abf753be02f 100755 --- a/src/server/shared/Cryptography/ARC4.h +++ b/src/server/shared/Cryptography/ARC4.h @@ -19,7 +19,7 @@ #ifndef _AUTH_SARC4_H #define _AUTH_SARC4_H -#include "Common.h" +#include "Define.h" #include <openssl/evp.h> class ARC4 diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp index 146f4e992b7..a2db02dfbe3 100755 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp @@ -18,12 +18,11 @@ #include "AuthCrypt.h" #include "Cryptography/HMACSHA1.h" -#include "Logging/Log.h" #include "Cryptography/BigNumber.h" AuthCrypt::AuthCrypt() : _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH) + , _initialized(false) { - _initialized = false; } AuthCrypt::~AuthCrypt() diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.h b/src/server/shared/Cryptography/Authentication/AuthCrypt.h index 0304ef6b69e..e7463b0d962 100755 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.h +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.h @@ -19,7 +19,6 @@ #ifndef _AUTHCRYPT_H #define _AUTHCRYPT_H -#include <Common.h> #include "Cryptography/ARC4.h" class BigNumber; diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp index 6149a680594..76cb74d5e13 100755 --- a/src/server/shared/Cryptography/BigNumber.cpp +++ b/src/server/shared/Cryptography/BigNumber.cpp @@ -18,31 +18,30 @@ #include "Cryptography/BigNumber.h" #include <openssl/bn.h> +#include <openssl/crypto.h> #include <algorithm> BigNumber::BigNumber() -{ - _bn = BN_new(); - _array = NULL; -} + : _bn(BN_new()) + , _array(NULL) +{ } BigNumber::BigNumber(const BigNumber &bn) -{ - _bn = BN_dup(bn._bn); - _array = NULL; -} + : _bn(BN_dup(bn._bn)) + , _array(NULL) +{ } BigNumber::BigNumber(uint32 val) + : _bn(BN_new()) + , _array(NULL) { - _bn = BN_new(); BN_set_word(_bn, val); - _array = NULL; } BigNumber::~BigNumber() { BN_free(_bn); - if (_array) delete[] _array; + delete[] _array; } void BigNumber::SetDword(uint32 val) @@ -76,6 +75,8 @@ void BigNumber::SetRand(int numbits) BigNumber BigNumber::operator=(const BigNumber &bn) { + if (this == &bn) + return *this; BN_copy(_bn, bn._bn); return *this; } diff --git a/src/server/shared/Cryptography/BigNumber.h b/src/server/shared/Cryptography/BigNumber.h index 485d4ced470..eb450c27777 100755 --- a/src/server/shared/Cryptography/BigNumber.h +++ b/src/server/shared/Cryptography/BigNumber.h @@ -19,7 +19,7 @@ #ifndef _AUTH_BIGNUMBER_H #define _AUTH_BIGNUMBER_H -#include "Common.h" +#include "Define.h" struct bignum_st; diff --git a/src/server/shared/Cryptography/HMACSHA1.h b/src/server/shared/Cryptography/HMACSHA1.h index 180ac6f4262..2d6e0c276a8 100755 --- a/src/server/shared/Cryptography/HMACSHA1.h +++ b/src/server/shared/Cryptography/HMACSHA1.h @@ -19,7 +19,8 @@ #ifndef _AUTH_HMAC_H #define _AUTH_HMAC_H -#include "Common.h" +#include "Define.h" +#include <string> #include <openssl/hmac.h> #include <openssl/sha.h> diff --git a/src/server/shared/Cryptography/SHA1.h b/src/server/shared/Cryptography/SHA1.h index 27e2d3290d0..9cb9b7b90f9 100755 --- a/src/server/shared/Cryptography/SHA1.h +++ b/src/server/shared/Cryptography/SHA1.h @@ -19,9 +19,9 @@ #ifndef _AUTH_SHA1_H #define _AUTH_SHA1_H -#include "Common.h" +#include "Define.h" +#include <string> #include <openssl/sha.h> -#include <openssl/crypto.h> class BigNumber; diff --git a/src/server/shared/Dynamic/UnorderedMap.h b/src/server/shared/Dynamic/UnorderedMap.h index c698cc0a823..92a7dddf8a8 100755 --- a/src/server/shared/Dynamic/UnorderedMap.h +++ b/src/server/shared/Dynamic/UnorderedMap.h @@ -71,4 +71,3 @@ namespace __gnu_cxx using std::hash_map; #endif #endif - diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 56c02a8e77b..15008f13c10 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -139,7 +139,7 @@ void Log::Initialize() { bool m_gmlog_timestamp = ConfigMgr::GetBoolDefault("GmLogTimestamp", false); - size_t dot_pos = m_gmlog_filename_format.find_last_of("."); + size_t dot_pos = m_gmlog_filename_format.find_last_of('.'); if (dot_pos!=m_gmlog_filename_format.npos) { if (m_gmlog_timestamp) diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 5c23616ac5c..5b2eb6aafb6 100755 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -102,8 +102,10 @@ const int Colors = int(WHITE)+1; class Log { friend class ACE_Singleton<Log, ACE_Thread_Mutex>; - Log(); - ~Log(); + + private: + Log(); + ~Log(); public: void Initialize(); diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 187258e41b3..5919529c6bf 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -17,7 +17,6 @@ */ #include "Util.h" - #include "utf8.h" #ifdef USE_SFMT_FOR_RNG #include "SFMT.h" @@ -162,13 +161,13 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly) std::ostringstream ss; if (days) - ss << days << (shortText ? "d " : " Day(s) "); + ss << days << (shortText ? "d" : " Day(s) "); if (hours || hoursOnly) - ss << hours << (shortText ? "h " : " Hour(s) "); + ss << hours << (shortText ? "h" : " Hour(s) "); if (!hoursOnly) { if (minutes) - ss << minutes << (shortText ? "m " : " Minute(s) "); + ss << minutes << (shortText ? "m" : " Minute(s) "); if (secs || (!days && !hours && !minutes) ) ss << secs << (shortText ? "s" : " Second(s)."); } diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index cf5ad79f878..564f6028eca 100755 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -115,6 +115,7 @@ void commandFinished(void*, bool /*success*/) printf("TC> "); fflush(stdout); } + /** * Collects all GUIDs (and related info) from deleted characters which are still in the database. * @@ -562,10 +563,11 @@ void CliRunnable::run() { ///- Display the list of available CLI functions then beep //sLog->outString(""); - #if PLATFORM != PLATFORM_WINDOWS +#if PLATFORM != PLATFORM_WINDOWS rl_attempted_completion_function = cli_completion; rl_event_hook = cli_hook_func; - #endif +#endif + if (ConfigMgr::GetBoolDefault("BeepAtStart", true)) printf("\a"); // \a = Alert @@ -580,49 +582,49 @@ void CliRunnable::run() char *command_str ; // = fgets(commandbuf, sizeof(commandbuf), stdin); - #if PLATFORM == PLATFORM_WINDOWS +#if PLATFORM == PLATFORM_WINDOWS char commandbuf[256]; command_str = fgets(commandbuf, sizeof(commandbuf), stdin); - #else +#else command_str = readline("TC>"); rl_bind_key('\t', rl_complete); - #endif +#endif + if (command_str != NULL) { - for (int x=0; command_str[x]; x++) - if (command_str[x]=='\r'||command_str[x]=='\n') + for (int x=0; command_str[x]; ++x) + if (command_str[x] == '\r' || command_str[x] == '\n') { - command_str[x]=0; + command_str[x] = 0; break; } if (!*command_str) { - #if PLATFORM == PLATFORM_WINDOWS +#if PLATFORM == PLATFORM_WINDOWS printf("TC>"); - #endif +#endif continue; } std::string command; if (!consoleToUtf8(command_str, command)) // convert from console encoding to utf8 { - #if PLATFORM == PLATFORM_WINDOWS +#if PLATFORM == PLATFORM_WINDOWS printf("TC>"); - #endif +#endif continue; } + fflush(stdout); sWorld->QueueCliCommand(new CliCommandHolder(NULL, command.c_str(), &utf8print, &commandFinished)); - #if PLATFORM != PLATFORM_WINDOWS +#if PLATFORM != PLATFORM_WINDOWS add_history(command.c_str()); - #endif - +#endif } else if (feof(stdin)) { World::StopNow(SHUTDOWN_EXIT_CODE); } - } } diff --git a/src/server/worldserver/RemoteAccess/RARunnable.cpp b/src/server/worldserver/RemoteAccess/RARunnable.cpp index d7cee88b994..60145cf99aa 100644 --- a/src/server/worldserver/RemoteAccess/RARunnable.cpp +++ b/src/server/worldserver/RemoteAccess/RARunnable.cpp @@ -33,22 +33,17 @@ #include "RASocket.h" -RARunnable::RARunnable() : m_Reactor(NULL) +RARunnable::RARunnable() { - ACE_Reactor_Impl* imp = 0; + ACE_Reactor_Impl* imp = NULL; #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL) - imp = new ACE_Dev_Poll_Reactor(); - imp->max_notify_iterations (128); imp->restart (1); - #else - imp = new ACE_TP_Reactor(); imp->max_notify_iterations (128); - #endif m_Reactor = new ACE_Reactor (imp, 1); @@ -68,7 +63,6 @@ void RARunnable::run() uint16 raport = ConfigMgr::GetIntDefault("Ra.Port", 3443); std::string stringip = ConfigMgr::GetStringDefault("Ra.IP", "0.0.0.0"); - ACE_INET_Addr listen_addr(raport, stringip.c_str()); if (acceptor.open(listen_addr, m_Reactor) == -1) @@ -84,7 +78,6 @@ void RARunnable::run() // don't be too smart to move this outside the loop // the run_reactor_event_loop will modify interval ACE_Time_Value interval(0, 100000); - if (m_Reactor->run_reactor_event_loop(interval) == -1) break; } |
