Jump to content

[fix][8858] Threat


Auntie Mangos

Recommended Posts

What bug does the patch fix? What features does the patch add?

According to Kapatejib (at mangos.ru) this patch should fix the issues with the threatvalues that are send to the client. As you probably know, addons like omen aren't working at the moment because of this bug. This fix WONT (I repeat WONT!!!) fix any threatbugs from certain spells!

For which repository revision was the patch created?

8478

Is there a thread in the bug report section or at lighthouse? If yes, please add a link to the thread.

Not sure, couldn't find any. Only topic I found was a hacky fix.

Who has been writing this patch? Please include either forum user names or email addresses.

Kapatejib (topic at mangos.ru can be found here)

I'm not the creator of the patch, I just want to share this with the English speaking people :)

diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp
index a058a8f..805dbaf 100644
--- a/src/game/ThreatManager.cpp
+++ b/src/game/ThreatManager.cpp
@@ -212,6 +212,9 @@ void ThreatContainer::clearReferences()
HostilReference* ThreatContainer::getReferenceByTarget(Unit* pVictim)
{
    HostilReference* result = NULL;
+    if(!pVictim)
+        return NULL;
+
    uint64 guid = pVictim->GetGUID();
    for(std::list<HostilReference*>::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
    {
@@ -342,7 +345,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)
{
}

@@ -353,6 +356,7 @@ void ThreatManager::clearReferences()
    iThreatContainer.clearReferences();
    iThreatOfflineContainer.clearReferences();
    iCurrentVictim = NULL;
+    iUpdateTimer = THREAT_UPDATE_INTERVAL;
}

//============================================================
@@ -452,6 +456,10 @@ void ThreatManager::tauntFadeOut(Unit *pTaunter)

void ThreatManager::setCurrentVictim(HostilReference* pHostilReference)
{
+    if (pHostilReference && pHostilReference != iCurrentVictim)
+    {
+        iOwner->SendChangeCurrentVictimOpcode(pHostilReference);
+    }
    iCurrentVictim = pHostilReference;
}

@@ -497,6 +505,7 @@ void ThreatManager::ProcessThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
                setCurrentVictim(NULL);
                setDirty(true);
            }
+            iOwner->SendRemoveFromThreatListOpcode(hostilReference);
            if(hostilReference->isOnline())
                iThreatContainer.remove(hostilReference);
            else
@@ -504,3 +513,16 @@ void ThreatManager::ProcessThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
            break;
    }
}
+
+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 d569480..efc753b 100644
--- a/src/game/ThreatManager.h
+++ b/src/game/ThreatManager.h
@@ -33,6 +33,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

@@ -185,6 +187,8 @@ class MANGOS_DLL_SPEC ThreatManager

        void processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent);

+        bool isNeedUpdateToClient(uint32 time);
+
        HostilReference* getCurrentVictim() { return iCurrentVictim; }

        Unit*  getOwner() { return iOwner; }
@@ -207,6 +211,7 @@ class MANGOS_DLL_SPEC ThreatManager
    private:
        HostilReference* iCurrentVictim;
        Unit* iOwner;
+        uint32 iUpdateTimer;
        ThreatContainer iThreatContainer;
        ThreatContainer iThreatOfflineContainer;
};
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 2725018..0e5f1e2 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -205,6 +205,9 @@ void Unit::Update( uint32 p_time )
        delete *itr;
    m_deletedAuras.clear();

+    if (CanHaveThreatList() && getThreatManager().isNeedUpdateToClient(p_time))
+        SendThreatListUpdate();
+
    // update combat timer only for players and pets
    if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed()))
    {
@@ -9905,6 +9908,8 @@ void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, Sp

void Unit::DeleteThreatList()
{
+    if(CanHaveThreatList() && !m_ThreatManager.isThreatListEmpty())
+        SendClearThreatListOpcode();
    m_ThreatManager.clearReferences();
}

@@ -12147,3 +12152,57 @@ void Unit::KnockBackFrom(Unit* target, float horizintalSpeed, float verticalSpee
        NearTeleportTo(fx, fy, fz, GetOrientation(), this == target);
    }
}
+
+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);
+}
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 20c1754..33547b6 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1142,6 +1142,11 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
        void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, MonsterMovementFlags flags, uint32 Time, Player* player = NULL);
        void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, MonsterMovementFlags flags);

+        void SendChangeCurrentVictimOpcode(HostilReference* pHostilReference);
+        void SendClearThreatListOpcode();
+        void SendRemoveFromThreatListOpcode(HostilReference* pHostilReference);
+        void SendThreatListUpdate();
+
        void BuildHeartBeatMsg( WorldPacket *data ) const;

        virtual void MoveOutOfRange(Player &) {  };

Link to comment
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

  • 39 years later...

From what I could gather (I don't read Cyrillic), the patch is derived from a Trinity Core implementation by QAston, but KAPATEJIb has ported it to MaNGOS and updated it about a week or so ago for rev. 8478+. Please correct me if I'm wrong, however.

This works, so far, without error (r8502, ACID 0.3, SD2 1397, UDB 382, AHBot) and it's made my girlfriend very happy to boot.

Link to comment
Share on other sites

From what I could gather (I don't read Cyrillic), the patch is derived from a Trinity Core implementation by QAston, but KAPATEJIb has ported it to MaNGOS and updated it about a week or so ago for rev. 8478+. Please correct me if I'm wrong, however.
Yes you were absolutely right.

Should work on latest rev (8502).

Link to comment
Share on other sites

Ah thanks for posting it in readable letters xD

I've seen some links to getmangos.ru but not being able to read anything there i just kept hoping it gets commited soon...

Applying and compiling fine here too with rev. 8502.

Only did a quick test with warlock+pet, but omen3 seems to work fine.

Link to comment
Share on other sites

Should work on latest rev (8502).

Confirmed, it does work with Rev. 8502 using Omen3.

No idea about stability or other side effects but I will post my experience with this patch here from time to time.

Odd... yesterday i searched the forum here and could not find anything about this and now this patch is already in the under review section.

Btw. Thanks to matsunoichi for pointing me in the right direction over at the UDB-Forums.

I see that you now have applied this useful patch too, which is good, more testers more proof.

Link to comment
Share on other sites

any progres in this necessary patch? iam tested on 8478 rev and works fine
Currently my server's uptime is 2 days with around 150 testers on it... Sounds crashfree to me to be honest.

I'm happy with the patch, so for me it's easy.. I'll keep on using it. Hopefully more people will :)

Link to comment
Share on other sites

this patch works fine, but there is still one problem...tested with addon called threat, which in chat displays threat for every hit...and values are not correct...IMHO, threat is not working properly...with omen tested too...i had 100% threat, healer had 40% and he aggroed...dps will do this about 50-60%...so i don't have feeling, that threat is calculated regullary...but maybe, i'm wrong, can someone tell me?

Link to comment
Share on other sites

Can you explain a bit more?

If you mean "threat 2.0", it seems to be an outdated threat calculator that works with combat log parsing. That always included a certain amount of guessing, and it may just not know threat values for many current spells...

This patch here does not change the way threat is calculated (AFAIK), it only sends it to the client periodically so new addons like omen 3 are working. There probably are spells that cause incorrect amounts of threat (i remember some SQL fixes posted here...), but omen 3 should still show correct percentage when you pull aggro. If not, the implementation here is also bugged...

Unfortunately i couldn't test in a group yet, only with pets.

Link to comment
Share on other sites

I've noticed rather wild variations in threat amounts before this patch in small groups (tank unable to maintain full aggro, abnormally high threat for healing spells (which caused my girlfriend to abstain from playing priests)), and this behavior hasn't changed after its application, so I'm not sure that this particular patch has been poorly implemented in that regard.

Link to comment
Share on other sites

The wild threat wackyness isn't a problem of this patch. Rather it's more likely the threat coefficients for the spells are wrong; if you know the spell id and the threat coefficient from somewhere try tinkering with the spell_threat table in the mangos database.

Absolutely right. That was what I was getting at; that, by my observations, the issue of odd threat levels was a pre-existing condition and neither affected by, nor inflicted by this patch. But as I'm not great at programming in C++, I didn't want to say with absolute certainty as it just wouldn't be proper for me to do so without fully knowing all sides of the subject.

I was considering going through the database to do some tinkering (and possibly even make a patch), but I don't have accurate data from retail to go by as yet.

Link to comment
Share on other sites

ok...maybe i understand it wrong...but according to tankspot.com, warrior 3.0.3 threat values: heroic strike threat is calculated as: damage+259...in defensive stance, damage is multiplied with 2.073...so one hit about 500dmg will do 1295.5 threat...but it do only 759...missing 500threat, which makes tanking very hard...also battle or berserker stance have 0.8 multiplier, but one hit in battle stance (autoattack) for 200dmg do 200 threat...if i remember right...if i'm wrong, please correct me :)

Link to comment
Share on other sites

ok...maybe i understand it wrong...but according to tankspot.com, warrior 3.0.3 threat values: heroic strike threat is calculated as: damage+259...in defensive stance, damage is multiplied with 2.073...so one hit about 500dmg will do 1295.5 threat...but it do only 759...missing 500threat, which makes tanking very hard...also battle or berserker stance have 0.8 multiplier, but one hit in battle stance (autoattack) for 200dmg do 200 threat...if i remember right...if i'm wrong, please correct me :)

It sounds about right to me (and this list of values on WoWWiki was last updated in July, before 3.2.0), but I think this issue should be the topic of another thread. As previously indicated, this particular patch just modifies the core to send threat information to the client via the API so addons like Omen3 can work.

Threat itself is bugged, though. I haven't yet had a chance to look at the core itself, but in the database only standard integer values are stored, not percentages or formulas; which really wouldn't make sense anyway as it seems better to calculate these things (percentages and formulas) in the core. Although, I don't know if threat from any spells or auras are actually calculated in the core at this time (haven't had a chance to look).

Link to comment
Share on other sites

Modified first post, as people kept discussing threatbugs instead of being on-topic.

Please guys, this seriously a GOOD fix... so please don't fill this topic with nonsense about threatbugs which should be posted at other sections of the forums.

This fix is for sending data to the client!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use