Core/Combat: more cleanups and converted threat packets back to packet class
This commit is contained in:
1 parent
1ab7a9328f
commit
e677461c5d
4 files changed
+52
-33
No files matched your search
@@ -251,11 +251,6 @@ void PetAI::UpdateAI(uint32 diff)
|
||||
for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr)
|
||||
delete itr->second;
|
||||
}
|
||||
|
||||
// Update speed as needed to prevent dropping too far behind and despawning
|
||||
me->UpdateSpeed(MOVE_RUN);
|
||||
me->UpdateSpeed(MOVE_WALK);
|
||||
me->UpdateSpeed(MOVE_FLIGHT);
|
||||
}
|
||||
|
||||
void PetAI::UpdateAllies()
|
||||
|
||||
@@ -64,9 +64,6 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/)
|
||||
if (!creature)
|
||||
creature = me;
|
||||
|
||||
if (!creature->CanHaveThreatList())
|
||||
return;
|
||||
|
||||
Map* map = creature->GetMap();
|
||||
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
|
||||
{
|
||||
@@ -74,22 +71,25 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/)
|
||||
return;
|
||||
}
|
||||
|
||||
Map::PlayerList const& playerList = map->GetPlayers();
|
||||
if (playerList.isEmpty())
|
||||
if (!map->HavePlayers())
|
||||
return;
|
||||
|
||||
for (auto const& ref : playerList)
|
||||
for (MapReference const& ref : map->GetPlayers())
|
||||
{
|
||||
if (Player* player = ref.GetSource())
|
||||
{
|
||||
if (!player->IsAlive() || !CombatManager::CanBeginCombat(creature, player))
|
||||
continue;
|
||||
|
||||
creature->EngageWithTarget(player);
|
||||
|
||||
for (Unit* pet : player->m_Controlled)
|
||||
creature->EngageWithTarget(pet);
|
||||
|
||||
if (Unit* vehicle = player->GetVehicleBase())
|
||||
creature->EngageWithTarget(vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// scripts does not take care about MoveInLineOfSight loops
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "SpellAuraEffects.h"
|
||||
#include "SpellInfo.h"
|
||||
#include "SpellMgr.h"
|
||||
#include "CombatPackets.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "WorldPacket.h"
|
||||
#include <algorithm>
|
||||
@@ -746,38 +747,61 @@ void ThreatManager::UnregisterRedirectThreat(uint32 spellId, ObjectGuid const& v
|
||||
|
||||
void ThreatManager::SendClearAllThreatToClients() const
|
||||
{
|
||||
WorldPacket data(SMSG_THREAT_CLEAR, 8);
|
||||
data << _owner->GetPackGUID();
|
||||
_owner->SendMessageToSet(&data, false);
|
||||
WorldPackets::Combat::ThreatClear packet;
|
||||
packet.UnitGUID = _owner->GetGUID();
|
||||
_owner->SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
|
||||
void ThreatManager::SendRemoveToClients(Unit const* victim) const
|
||||
{
|
||||
WorldPacket data(SMSG_THREAT_REMOVE, 16);
|
||||
data << _owner->GetPackGUID();
|
||||
data << victim->GetPackGUID();
|
||||
_owner->SendMessageToSet(&data, false);
|
||||
WorldPackets::Combat::ThreatRemove packet;
|
||||
packet.UnitGUID = _owner->GetGUID();
|
||||
packet.AboutGUID = victim->GetGUID();
|
||||
_owner->SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
|
||||
void ThreatManager::SendThreatListToClients(bool newHighest) const
|
||||
{
|
||||
WorldPacket data(newHighest ? SMSG_HIGHEST_THREAT_UPDATE : SMSG_THREAT_UPDATE, (_sortedThreatList.size() + 2) * 8); // guess
|
||||
data << _owner->GetPackGUID();
|
||||
if (newHighest)
|
||||
data << _currentVictimRef->GetVictim()->GetPackGUID();
|
||||
size_t countPos = data.wpos();
|
||||
data << uint32(0); // placeholder
|
||||
uint32 count = 0;
|
||||
uint32 availableReferences = 0;
|
||||
for (ThreatReference const* ref : _sortedThreatList)
|
||||
if (ref->IsAvailable())
|
||||
++availableReferences;
|
||||
|
||||
if (newHighest)
|
||||
{
|
||||
if (!ref->IsAvailable())
|
||||
continue;
|
||||
data << ref->GetVictim()->GetPackGUID();
|
||||
data << uint32(ref->GetThreat() * 100);
|
||||
++count;
|
||||
WorldPackets::Combat::HighestThreatUpdate packet;
|
||||
packet.UnitGUID = _owner->GetGUID();
|
||||
packet.HighestThreatGUID = _currentVictimRef->GetVictim()->GetGUID();
|
||||
packet.ThreatList.reserve(availableReferences);
|
||||
for (ThreatReference const* ref : _sortedThreatList)
|
||||
{
|
||||
if (!ref->IsAvailable())
|
||||
continue;
|
||||
|
||||
WorldPackets::Combat::ThreatInfo info;
|
||||
info.UnitGUID = ref->GetVictim()->GetGUID();
|
||||
info.Threat = uint32(ref->GetThreat());
|
||||
packet.ThreatList.push_back(info);
|
||||
}
|
||||
_owner->SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldPackets::Combat::ThreatUpdate packet;
|
||||
packet.UnitGUID = _owner->GetGUID();
|
||||
packet.ThreatList.reserve(availableReferences);
|
||||
for (ThreatReference const* ref : _sortedThreatList)
|
||||
{
|
||||
if (!ref->IsAvailable())
|
||||
continue;
|
||||
|
||||
WorldPackets::Combat::ThreatInfo info;
|
||||
info.UnitGUID = ref->GetVictim()->GetGUID();
|
||||
info.Threat = uint32(ref->GetThreat());
|
||||
packet.ThreatList.push_back(info);
|
||||
}
|
||||
_owner->SendMessageToSet(packet.Write(), false);
|
||||
}
|
||||
data.put<uint32>(countPos, count);
|
||||
_owner->SendMessageToSet(&data, false);
|
||||
}
|
||||
|
||||
void ThreatManager::PutThreatListRef(ObjectGuid const& guid, ThreatReference* ref)
|
||||
|
||||
@@ -5746,7 +5746,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
|
||||
//if (GetTypeId() == TYPEID_UNIT)
|
||||
// ToCreature()->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
|
||||
if (creature && !IsPet())
|
||||
if (creature && !IsControlledByPlayer())
|
||||
{
|
||||
EngageWithTarget(victim); // ensure that anything we're attacking has threat
|
||||
|
||||
|
||||
Reference in new issue
Block a user