*Send threat messages to client - thanks to megamage for research.

--HG--
branch : trunk
This commit is contained in:
QAston
2009-07-02 00:03:57 +02:00
parent fd86e6a369
commit 69f36d7af4
5 changed files with 91 additions and 1 deletions
+1
View File
@@ -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);
+20 -1
View File
@@ -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;
}
+5
View File
@@ -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;
};
+60
View File
@@ -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<HostilReference*>& tlist = getThreatManager().getThreatList();
for (std::list<HostilReference*>::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<HostilReference*>& tlist = getThreatManager().getThreatList();
for (std::list<HostilReference*>::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);
}
+5
View File
@@ -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;