From 69f36d7af4724b68c7a3a104b2913d1e2743971b Mon Sep 17 00:00:00 2001 From: QAston Date: Thu, 2 Jul 2009 00:03:57 +0200 Subject: *Send threat messages to client - thanks to megamage for research. --HG-- branch : trunk --- src/game/Creature.h | 1 + src/game/ThreatManager.cpp | 21 +++++++++++++++- src/game/ThreatManager.h | 5 ++++ src/game/Unit.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/game/Unit.h | 5 ++++ 5 files changed, 91 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game/Creature.h b/src/game/Creature.h index 4f749eec78c..dba1997d19d 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -740,6 +740,7 @@ class TRINITY_DLL_SPEC Creature : public Unit void SetOriginalEntry(uint32 entry) { m_originalEntry = entry; } static float _GetDamageMod(int32 Rank); + protected: bool CreateFromProto(uint32 guidlow,uint32 Entry,uint32 team, const CreatureData *data = NULL); bool InitEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL); diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp index a0459aa81dc..e982cbbfe22 100644 --- a/src/game/ThreatManager.cpp +++ b/src/game/ThreatManager.cpp @@ -346,7 +346,7 @@ HostilReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostilRe //=================== ThreatManager ========================== //============================================================ -ThreatManager::ThreatManager(Unit* owner) : iCurrentVictim(NULL), iOwner(owner) +ThreatManager::ThreatManager(Unit* owner) : iCurrentVictim(NULL), iOwner(owner), iUpdateTimer(THREAT_UPDATE_INTERVAL) { } @@ -357,6 +357,7 @@ void ThreatManager::clearReferences() iThreatContainer.clearReferences(); iThreatOfflineContainer.clearReferences(); iCurrentVictim = NULL; + iUpdateTimer = THREAT_UPDATE_INTERVAL; } //============================================================ @@ -470,6 +471,10 @@ void ThreatManager::tauntFadeOut(Unit *pTaunter) void ThreatManager::setCurrentVictim(HostilReference* pHostilReference) { + if (pHostilReference && pHostilReference != iCurrentVictim) + { + iOwner->SendChangeCurrentVictimOpcode(pHostilReference); + } iCurrentVictim = pHostilReference; } @@ -515,6 +520,7 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat setCurrentVictim(NULL); setDirty(true); } + iOwner->SendRemoveFromThreatListOpcode(hostilReference); if(hostilReference->isOnline()) iThreatContainer.remove(hostilReference); else @@ -523,3 +529,16 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat } } +bool ThreatManager::isNeedUpdateToClient(uint32 time) +{ + if (isThreatListEmpty()) + return false; + if (time >= iUpdateTimer) + { + iUpdateTimer = THREAT_UPDATE_INTERVAL; + return true; + } + iUpdateTimer -= time; + return false; +} + diff --git a/src/game/ThreatManager.h b/src/game/ThreatManager.h index aa84cb7d52c..1dba6277cfc 100644 --- a/src/game/ThreatManager.h +++ b/src/game/ThreatManager.h @@ -35,6 +35,8 @@ class Creature; class ThreatManager; struct SpellEntry; +#define THREAT_UPDATE_INTERVAL 1 * IN_MILISECONDS // Server should send threat update to client periodically each second + //============================================================== // Class to calculate the real threat based @@ -187,6 +189,8 @@ class TRINITY_DLL_SPEC ThreatManager void processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent); + bool isNeedUpdateToClient(uint32 time); + HostilReference* getCurrentVictim() { return iCurrentVictim; } Unit* getOwner() { return iOwner; } @@ -211,6 +215,7 @@ class TRINITY_DLL_SPEC ThreatManager HostilReference* iCurrentVictim; Unit* iOwner; + uint32 iUpdateTimer; ThreatContainer iThreatContainer; ThreatContainer iThreatOfflineContainer; }; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 6da5ae063d4..80eb7c665bb 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -211,6 +211,9 @@ void Unit::Update( uint32 p_time ) m_Events.Update( p_time ); _UpdateSpells( p_time ); + if (CanHaveThreatList() && getThreatManager().isNeedUpdateToClient(p_time)) + SendThreatListUpdate(); + // update combat timer only for players and pets if (isInCombat() && IsControlledByPlayer()) { @@ -11186,6 +11189,8 @@ void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, Sp void Unit::DeleteThreatList() { + if(CanHaveThreatList() && !m_ThreatManager.isThreatListEmpty()) + SendClearThreatListOpcode(); m_ThreatManager.clearReferences(); } @@ -14861,3 +14866,58 @@ void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool ca //SendMessageToSet(&data, false); } } + +void Unit::SendThreatListUpdate() +{ + if (uint32 count = getThreatManager().getThreatList().size()) + { + sLog.outDebug( "WORLD: Send SMSG_THREAT_UPDATE Message" ); + WorldPacket data(SMSG_THREAT_UPDATE, 8 + count * 8); + data.append(GetPackGUID()); + data << uint32(count); + std::list& tlist = getThreatManager().getThreatList(); + for (std::list::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr) + { + data.appendPackGUID((*itr)->getUnitGuid()); + data << uint32((*itr)->getThreat()); + } + SendMessageToSet(&data, false); + } +} + + +void Unit::SendChangeCurrentVictimOpcode(HostilReference* pHostilReference) +{ + if (uint32 count = getThreatManager().getThreatList().size()) + { + sLog.outDebug( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" ); + WorldPacket data(SMSG_HIGHEST_THREAT_UPDATE, 8 + 8 + count * 8); + data.append(GetPackGUID()); + data.appendPackGUID(pHostilReference->getUnitGuid()); + data << uint32(count); + std::list& tlist = getThreatManager().getThreatList(); + for (std::list::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr) + { + data.appendPackGUID((*itr)->getUnitGuid()); + data << uint32((*itr)->getThreat()); + } + SendMessageToSet(&data, false); + } +} + +void Unit::SendClearThreatListOpcode() +{ + sLog.outDebug( "WORLD: Send SMSG_THREAT_CLEAR Message" ); + WorldPacket data(SMSG_THREAT_CLEAR, 8); + data.append(GetPackGUID()); + SendMessageToSet(&data, false); +} + +void Unit::SendRemoveFromThreatListOpcode(HostilReference* pHostilReference) +{ + sLog.outDebug( "WORLD: Send SMSG_THREAT_REMOVE Message" ); + WorldPacket data(SMSG_THREAT_REMOVE, 8 + 8); + data.append(GetPackGUID()); + data.appendPackGUID(pHostilReference->getUnitGuid()); + SendMessageToSet(&data, false); +} diff --git a/src/game/Unit.h b/src/game/Unit.h index 5ce52110aae..cf062171370 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1326,6 +1326,11 @@ class TRINITY_DLL_SPEC Unit : public WorldObject void SendMonsterMoveWithSpeedToCurrentDestination(Player* player = NULL); void SendMovementFlagUpdate(); + void SendChangeCurrentVictimOpcode(HostilReference* pHostilReference); + void SendClearThreatListOpcode(); + void SendRemoveFromThreatListOpcode(HostilReference* pHostilReference); + void SendThreatListUpdate(); + void BuildHeartBeatMsg(WorldPacket *data) const; void OutMovementInfo() const; -- cgit v1.2.3