Core/Threat: Re-add fixtate system. I am being told Netherspite needs it.

This commit is contained in:
Treeston
2018-05-04 14:49:08 +02:00
parent 7fe59c95d8
commit fd33b1cd02
3 changed files with 51 additions and 12 deletions

View File

@@ -451,10 +451,36 @@ void ThreatManager::ClearAllThreat()
while (!_myThreatListEntries.empty()); while (!_myThreatListEntries.empty());
} }
void ThreatManager::FixtateTarget(Unit* target)
{
if (target)
{
auto it = _myThreatListEntries.find(target->GetGUID());
if (it != _myThreatListEntries.end())
{
_fixtateRef = it->second;
return;
}
}
_fixtateRef = nullptr;
}
Unit* ThreatManager::GetFixtateTarget() const
{
if (_fixtateRef)
return _fixtateRef->GetVictim();
else
return nullptr;
}
ThreatReference const* ThreatManager::ReselectVictim() ThreatReference const* ThreatManager::ReselectVictim()
{ {
// fixtated target is always preferred
if (_fixtateRef && _fixtateRef->IsAvailable())
return _fixtateRef;
ThreatReference const* oldVictimRef = _currentVictimRef; ThreatReference const* oldVictimRef = _currentVictimRef;
if (oldVictimRef && !oldVictimRef->IsAvailable()) if (oldVictimRef && oldVictimRef->IsOffline())
oldVictimRef = nullptr; oldVictimRef = nullptr;
// in 99% of cases - we won't need to actually look at anything beyond the first element // in 99% of cases - we won't need to actually look at anything beyond the first element
ThreatReference const* highest = _sortedThreatList.top(); ThreatReference const* highest = _sortedThreatList.top();
@@ -699,6 +725,8 @@ void ThreatManager::PurgeThreatListRef(ObjectGuid const& guid, bool sendRemove)
if (_currentVictimRef == ref) if (_currentVictimRef == ref)
_currentVictimRef = nullptr; _currentVictimRef = nullptr;
if (_fixtateRef == ref)
_fixtateRef = nullptr;
_sortedThreatList.erase(ref->_handle); _sortedThreatList.erase(ref->_handle);
if (sendRemove && ref->IsAvailable()) if (sendRemove && ref->IsAvailable())

View File

@@ -160,6 +160,12 @@ class TC_GAME_API ThreatManager
// Removes all targets from the threat list (will cause evade in UpdateVictim if called) // Removes all targets from the threat list (will cause evade in UpdateVictim if called)
void ClearAllThreat(); void ClearAllThreat();
// Fixtate on the passed target; this target will always be selected until the fixtate is cleared
// (if the target is not in the threat list, does nothing)
void FixtateTarget(Unit* target);
void ClearFixtate() { FixtateTarget(nullptr); }
Unit* GetFixtateTarget() const;
// sends SMSG_THREAT_UPDATE to all nearby clients (used by client to forward threat list info to addons) // sends SMSG_THREAT_UPDATE to all nearby clients (used by client to forward threat list info to addons)
void SendThreatListToClients() const; void SendThreatListToClients() const;
@@ -204,6 +210,7 @@ class TC_GAME_API ThreatManager
std::unordered_map<ObjectGuid, ThreatReference*> _myThreatListEntries; std::unordered_map<ObjectGuid, ThreatReference*> _myThreatListEntries;
ThreatReference const* _currentVictimRef; ThreatReference const* _currentVictimRef;
ThreatReference const* ReselectVictim(); ThreatReference const* ReselectVictim();
ThreatReference const* _fixtateRef;
///== OTHERS' THREAT LISTS == ///== OTHERS' THREAT LISTS ==
void PutThreatenedByMeRef(ObjectGuid const& guid, ThreatReference* ref); void PutThreatenedByMeRef(ObjectGuid const& guid, ThreatReference* ref);

View File

@@ -885,6 +885,7 @@ public:
handler->PSendSysMessage("%s (GUID %u, SpawnID %u) is not engaged, but still has a threat list? Well, here it is:", target->GetName().c_str(), target->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_UNIT ? target->ToCreature()->GetSpawnId() : 0); handler->PSendSysMessage("%s (GUID %u, SpawnID %u) is not engaged, but still has a threat list? Well, here it is:", target->GetName().c_str(), target->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_UNIT ? target->ToCreature()->GetSpawnId() : 0);
count = 0; count = 0;
Unit* fixtateVictim = mgr.GetFixtateTarget();
for (ThreatReference const* ref : mgr.GetSortedThreatList()) for (ThreatReference const* ref : mgr.GetSortedThreatList())
{ {
Unit* unit = ref->GetVictim(); Unit* unit = ref->GetVictim();
@@ -901,17 +902,20 @@ public:
onlineStr = ""; onlineStr = "";
} }
char const* tauntStr; char const* tauntStr;
switch (ref->GetTauntState()) if (unit == fixtateVictim)
{ tauntStr = " [FIXTATE]";
case ThreatReference::TAUNT_STATE_TAUNT: else
tauntStr = " [TAUNT]"; switch (ref->GetTauntState())
break; {
case ThreatReference::TAUNT_STATE_DETAUNT: case ThreatReference::TAUNT_STATE_TAUNT:
tauntStr = " [DETAUNT]"; tauntStr = " [TAUNT]";
break; break;
default: case ThreatReference::TAUNT_STATE_DETAUNT:
tauntStr = ""; tauntStr = " [DETAUNT]";
} break;
default:
tauntStr = "";
}
handler->PSendSysMessage(" %u. %s (GUID %u) - threat %f%s%s", ++count, unit->GetName().c_str(), unit->GetGUID().GetCounter(), ref->GetThreat(), tauntStr, onlineStr); handler->PSendSysMessage(" %u. %s (GUID %u) - threat %f%s%s", ++count, unit->GetName().c_str(), unit->GetGUID().GetCounter(), ref->GetThreat(), tauntStr, onlineStr);
} }
handler->SendSysMessage("End of threat list."); handler->SendSysMessage("End of threat list.");