Core/Phasing: Implemented setting personal guid on PhaseShift

This commit is contained in:
Shauren
2021-02-27 01:44:44 +01:00
parent c9344c145a
commit ec9f5be6a6
5 changed files with 66 additions and 26 deletions

View File

@@ -2109,7 +2109,7 @@ void Player::SetGameMaster(bool on)
}
else
{
PhasingHandler::SetAlwaysVisible(this, !HasAuraType(SPELL_AURA_PHASE_ALWAYS_VISIBLE), false);
PhasingHandler::SetAlwaysVisible(this, HasAuraType(SPELL_AURA_PHASE_ALWAYS_VISIBLE), false);
m_ExtraFlags &= ~ PLAYER_EXTRA_GM_ON;
setFactionForRace(getRace());

View File

@@ -82,7 +82,6 @@ PhaseShift::EraseResult<PhaseShift::UiMapPhaseIdContainer> PhaseShift::RemoveUiM
void PhaseShift::Clear()
{
ClearPhases();
PersonalGuid.Clear();
VisibleMapIds.clear();
UiMapPhaseIds.clear();
}
@@ -90,9 +89,11 @@ void PhaseShift::Clear()
void PhaseShift::ClearPhases()
{
Flags &= PhaseShiftFlags::AlwaysVisible | PhaseShiftFlags::Inverse;
PersonalGuid.Clear();
Phases.clear();
NonCosmeticReferences = 0;
CosmeticReferences = 0;
PersonalReferences = 0;
DefaultReferences = 0;
UpdateUnphasedFlag();
}
@@ -126,12 +127,12 @@ bool PhaseShift::CanSee(PhaseShift const& other) const
if (phaseShift.Flags.HasFlag(PhaseShiftFlags::Unphased) && !excludedPhaseShift.Flags.HasFlag(PhaseShiftFlags::InverseUnphased))
return true;
for (auto itr = phaseShift.Phases.begin(); itr != phaseShift.Phases.end(); ++itr)
for (PhaseRef const& phase : phaseShift.Phases)
{
if (itr->Flags.HasFlag(excludePhasesWithFlag))
if (phase.Flags.HasFlag(excludePhasesWithFlag))
continue;
auto itr2 = std::find(excludedPhaseShift.Phases.begin(), excludedPhaseShift.Phases.end(), *itr);
auto itr2 = std::find(excludedPhaseShift.Phases.begin(), excludedPhaseShift.Phases.end(), phase);
if (itr2 == excludedPhaseShift.Phases.end() || itr2->Flags.HasFlag(excludePhasesWithFlag))
return true;
}
@@ -158,12 +159,16 @@ void PhaseShift::ModifyPhasesReferences(PhaseContainer::iterator itr, int32 refe
else
DefaultReferences += references;
if (itr->Flags.HasFlag(PhaseFlags::Personal))
PersonalReferences += references;
if (CosmeticReferences)
Flags |= PhaseShiftFlags::NoCosmetic;
else
Flags &= ~PhaseShiftFlags::NoCosmetic;
UpdateUnphasedFlag();
UpdatePersonalGuid();
}
}
@@ -176,3 +181,9 @@ void PhaseShift::UpdateUnphasedFlag()
else
Flags |= unphasedFlag;
}
void PhaseShift::UpdatePersonalGuid()
{
if (!PersonalReferences)
PersonalGuid.Clear();
}

View File

@@ -81,11 +81,9 @@ public:
typename Container::iterator Iterator;
bool Erased;
};
typedef boost::container::flat_set<PhaseRef> PhaseContainer;
typedef std::map<uint32, VisibleMapIdRef> VisibleMapIdContainer;
typedef std::map<uint32, UiMapPhaseIdRef> UiMapPhaseIdContainer;
PhaseShift() : Flags(PhaseShiftFlags::Unphased), NonCosmeticReferences(0), CosmeticReferences(0), DefaultReferences(0), IsDbPhaseShift(false) { }
using PhaseContainer = boost::container::flat_set<PhaseRef>;
using VisibleMapIdContainer = std::map<uint32, VisibleMapIdRef>;
using UiMapPhaseIdContainer = std::map<uint32, UiMapPhaseIdRef>;
bool AddPhase(uint32 phaseId, PhaseFlags flags, std::vector<Condition*> const* areaConditions, int32 references = 1);
EraseResult<PhaseContainer> RemovePhase(uint32 phaseId);
@@ -100,7 +98,7 @@ public:
bool AddUiMapPhaseId(uint32 uiMapPhaseId, int32 references = 1);
EraseResult<UiMapPhaseIdContainer> RemoveUiMapPhaseId(uint32 uiMapPhaseId);
bool HasUiMapPhaseId(uint32 uiMapPhaseId) const { return UiMapPhaseIds.find(uiMapPhaseId) != UiMapPhaseIds.end(); }
UiMapPhaseIdContainer const& GetUiWorldMapAreaIdSwaps() const { return UiMapPhaseIds; }
UiMapPhaseIdContainer const& GetUiMapPhaseIds() const { return UiMapPhaseIds; }
void Clear();
void ClearPhases();
@@ -110,7 +108,7 @@ public:
protected:
friend class PhasingHandler;
EnumFlag<PhaseShiftFlags> Flags;
EnumFlag<PhaseShiftFlags> Flags = PhaseShiftFlags::Unphased;
ObjectGuid PersonalGuid;
PhaseContainer Phases;
VisibleMapIdContainer VisibleMapIds;
@@ -118,10 +116,12 @@ protected:
void ModifyPhasesReferences(PhaseContainer::iterator itr, int32 references);
void UpdateUnphasedFlag();
int32 NonCosmeticReferences;
int32 CosmeticReferences;
int32 DefaultReferences;
bool IsDbPhaseShift;
void UpdatePersonalGuid();
int32 NonCosmeticReferences = 0;
int32 CosmeticReferences = 0;
int32 PersonalReferences = 0;
int32 DefaultReferences = 0;
bool IsDbPhaseShift = false;
};
#endif // PhaseShift_h__

View File

@@ -55,23 +55,31 @@ inline void ForAllControlled(Unit* unit, Func&& func)
if (controlled->GetTypeId() != TYPEID_PLAYER)
func(controlled);
for (uint8 i = 0; i < MAX_SUMMON_SLOT; ++i)
if (!unit->m_SummonSlot[i].IsEmpty())
if (Creature* summon = unit->GetMap()->GetCreature(unit->m_SummonSlot[i]))
for (ObjectGuid summonGuid : unit->m_SummonSlot)
if (!summonGuid.IsEmpty())
if (Creature* summon = unit->GetMap()->GetCreature(summonGuid))
func(summon);
}
}
void PhasingHandler::AddPhase(WorldObject* object, uint32 phaseId, bool updateVisibility)
{
AddPhase(object, phaseId, object->GetGUID(), updateVisibility);
}
void PhasingHandler::AddPhase(WorldObject* object, uint32 phaseId, ObjectGuid const& personalGuid, bool updateVisibility)
{
bool changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr);
if (object->GetPhaseShift().PersonalReferences)
object->GetPhaseShift().PersonalGuid = personalGuid;
if (Unit* unit = object->ToUnit())
{
unit->OnPhaseChange();
ForAllControlled(unit, [&](Unit* controlled)
{
AddPhase(controlled, phaseId, updateVisibility);
AddPhase(controlled, phaseId, personalGuid, updateVisibility);
});
unit->RemoveNotOwnSingleTargetAuras(true);
}
@@ -97,6 +105,11 @@ void PhasingHandler::RemovePhase(WorldObject* object, uint32 phaseId, bool updat
}
void PhasingHandler::AddPhaseGroup(WorldObject* object, uint32 phaseGroupId, bool updateVisibility)
{
AddPhaseGroup(object, phaseGroupId, object->GetGUID(), updateVisibility);
}
void PhasingHandler::AddPhaseGroup(WorldObject* object, uint32 phaseGroupId, ObjectGuid const& personalGuid, bool updateVisibility)
{
std::vector<uint32> const* phasesInGroup = sDB2Manager.GetPhasesForGroup(phaseGroupId);
if (!phasesInGroup)
@@ -106,12 +119,15 @@ void PhasingHandler::AddPhaseGroup(WorldObject* object, uint32 phaseGroupId, boo
for (uint32 phaseId : *phasesInGroup)
changed = object->GetPhaseShift().AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr) || changed;
if (object->GetPhaseShift().PersonalReferences)
object->GetPhaseShift().PersonalGuid = personalGuid;
if (Unit* unit = object->ToUnit())
{
unit->OnPhaseChange();
ForAllControlled(unit, [&](Unit* controlled)
{
AddPhaseGroup(controlled, phaseGroupId, updateVisibility);
AddPhaseGroup(controlled, phaseGroupId, personalGuid, updateVisibility);
});
unit->RemoveNotOwnSingleTargetAuras(true);
}
@@ -269,6 +285,9 @@ void PhasingHandler::OnAreaChange(WorldObject* object)
for (uint32 phaseId : *phasesInGroup)
changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), nullptr) || changed;
if (phaseShift.PersonalReferences)
phaseShift.PersonalGuid = unit->GetGUID();
if (changed)
unit->OnPhaseChange();
@@ -280,6 +299,11 @@ void PhasingHandler::OnAreaChange(WorldObject* object)
if (changed)
unit->RemoveNotOwnSingleTargetAuras(true);
}
else
{
if (phaseShift.PersonalReferences)
phaseShift.PersonalGuid = object->GetGUID();
}
UpdateVisibilityIfNeeded(object, true, changed);
}
@@ -371,12 +395,15 @@ void PhasingHandler::OnConditionChange(WorldObject* object)
}
}
changed = changed || !newSuppressions.Phases.empty() || !newSuppressions.VisibleMapIds.empty();
for (auto itr = newSuppressions.Phases.begin(); itr != newSuppressions.Phases.end(); ++itr)
suppressedPhaseShift.AddPhase(itr->Id, itr->Flags, itr->AreaConditions, itr->References);
if (phaseShift.PersonalReferences)
phaseShift.PersonalGuid = object->GetGUID();
for (auto itr = newSuppressions.VisibleMapIds.begin(); itr != newSuppressions.VisibleMapIds.end(); ++itr)
suppressedPhaseShift.AddVisibleMapId(itr->first, itr->second.VisibleMapInfo, itr->second.References);
changed = changed || !newSuppressions.Phases.empty() || !newSuppressions.VisibleMapIds.empty();
for (PhaseShift::PhaseRef const& phaseRef : newSuppressions.Phases)
suppressedPhaseShift.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References);
for (std::pair<uint32 const, PhaseShift::VisibleMapIdRef> const& visibleMap : newSuppressions.VisibleMapIds)
suppressedPhaseShift.AddVisibleMapId(visibleMap.first, visibleMap.second.VisibleMapInfo, visibleMap.second.References);
if (unit)
{

View File

@@ -70,6 +70,8 @@ public:
static std::string FormatPhases(PhaseShift const& phaseShift);
private:
static void AddPhase(WorldObject* object, uint32 phaseId, ObjectGuid const& personalGuid, bool updateVisibility);
static void AddPhaseGroup(WorldObject* object, uint32 phaseGroupId, ObjectGuid const& personalGuid, bool updateVisibility);
static void UpdateVisibilityIfNeeded(WorldObject* object, bool updateVisibility, bool changed);
};