Core/Phases: Fixes errors in phases.
This commit is contained in:
@@ -27,38 +27,65 @@ namespace Game
|
||||
{
|
||||
public class PhaseShift
|
||||
{
|
||||
public PhaseShift()
|
||||
{
|
||||
Flags = PhaseShiftFlags.Unphased;
|
||||
}
|
||||
public PhaseShift(PhaseShift copy)
|
||||
{
|
||||
Flags = copy.Flags;
|
||||
PersonalGuid = copy.PersonalGuid;
|
||||
Phases = new Dictionary<uint, PhaseRef>(copy.Phases);
|
||||
VisibleMapIds = new Dictionary<uint, VisibleMapIdRef>(copy.VisibleMapIds);
|
||||
UiWorldMapAreaIdSwaps = new Dictionary<uint, UiWorldMapAreaIdSwapRef>(copy.UiWorldMapAreaIdSwaps);
|
||||
|
||||
NonCosmeticReferences = copy.NonCosmeticReferences;
|
||||
CosmeticReferences = copy.CosmeticReferences;
|
||||
DefaultReferences = copy.DefaultReferences;
|
||||
IsDbPhaseShift = copy.IsDbPhaseShift;
|
||||
}
|
||||
|
||||
public bool AddPhase(uint phaseId, PhaseFlags flags, List<Condition> areaConditions, int references = 1)
|
||||
{
|
||||
var phase = new PhaseRef(phaseId, flags, null);
|
||||
ModifyPhasesReferences(phase, references);
|
||||
bool newPhase = false;
|
||||
|
||||
if (!Phases.ContainsKey(phaseId))
|
||||
{
|
||||
newPhase = true;
|
||||
Phases.Add(phaseId, new PhaseRef(flags, null));
|
||||
}
|
||||
|
||||
var phase = Phases.LookupByKey(phaseId);
|
||||
ModifyPhasesReferences(phaseId, phase, references);
|
||||
if (areaConditions != null)
|
||||
phase.AreaConditions = areaConditions;
|
||||
|
||||
Phases.Add(phase);
|
||||
return true;
|
||||
return newPhase;
|
||||
}
|
||||
|
||||
public bool RemovePhase(uint phaseId)
|
||||
{
|
||||
var phaseRef = new PhaseRef(phaseId, PhaseFlags.None, null);
|
||||
if (Phases.Contains(phaseRef))
|
||||
var phaseRef = Phases.LookupByKey(phaseId);
|
||||
if (phaseRef != null)
|
||||
{
|
||||
ModifyPhasesReferences(phaseRef, -1);
|
||||
ModifyPhasesReferences(phaseId, phaseRef, -1);
|
||||
if (phaseRef.References == 0)
|
||||
{
|
||||
Phases.Remove(phaseRef);
|
||||
Phases.Remove(phaseId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AddVisibleMapId(uint visibleMapId, TerrainSwapInfo visibleMapInfo, int references = 1)
|
||||
{
|
||||
if (VisibleMapIds.ContainsKey(visibleMapId))
|
||||
return false;
|
||||
|
||||
VisibleMapIds.Add(visibleMapId, new VisibleMapIdRef(references, visibleMapInfo));
|
||||
return true; //Tryadd? maybe Concurrent
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveVisibleMapId(uint visibleMapId)
|
||||
@@ -71,8 +98,6 @@ namespace Game
|
||||
VisibleMapIds.Remove(visibleMapId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -80,12 +105,15 @@ namespace Game
|
||||
|
||||
public bool AddUiWorldMapAreaIdSwap(uint uiWorldMapAreaId, int references = 1)
|
||||
{
|
||||
if (UiWorldMapAreaIdSwaps.ContainsKey(uiWorldMapAreaId))
|
||||
return false;
|
||||
|
||||
UiWorldMapAreaIdSwaps.Add(uiWorldMapAreaId, new UiWorldMapAreaIdSwapRef(references));
|
||||
return true; //Tryadd? maybe Concurrent
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveUiWorldMapAreaIdSwap(uint uiWorldMapAreaId)
|
||||
{
|
||||
{
|
||||
if (UiWorldMapAreaIdSwaps.ContainsKey(uiWorldMapAreaId))
|
||||
{
|
||||
var value = UiWorldMapAreaIdSwaps[uiWorldMapAreaId];
|
||||
@@ -94,8 +122,6 @@ namespace Game
|
||||
UiWorldMapAreaIdSwaps.Remove(uiWorldMapAreaId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -136,7 +162,7 @@ namespace Game
|
||||
{
|
||||
ObjectGuid ownerGuid = PersonalGuid;
|
||||
ObjectGuid otherPersonalGuid = other.PersonalGuid;
|
||||
return Phases.Intersect(other.Phases, (myPhase, otherPhase) => !myPhase.Flags.HasAnyFlag(excludePhasesWithFlag) && (!myPhase.Flags.HasFlag(PhaseFlags.Personal) || ownerGuid == otherPersonalGuid)).Any();
|
||||
return Phases.Intersect(other.Phases, (myPhase, otherPhase) => !myPhase.Value.Flags.HasAnyFlag(excludePhasesWithFlag) && (!myPhase.Value.Flags.HasFlag(PhaseFlags.Personal) || ownerGuid == otherPersonalGuid)).Any();
|
||||
}
|
||||
|
||||
var checkInversePhaseShift = new Func<PhaseShift, PhaseShift, bool>((phaseShift, excludedPhaseShift) =>
|
||||
@@ -144,13 +170,14 @@ namespace Game
|
||||
if (phaseShift.Flags.HasFlag(PhaseShiftFlags.Unphased) && !excludedPhaseShift.Flags.HasFlag(PhaseShiftFlags.InverseUnphased))
|
||||
return true;
|
||||
|
||||
foreach (var itr in phaseShift.Phases)
|
||||
var list = excludedPhaseShift.Phases.ToList();
|
||||
foreach (var pair in phaseShift.Phases)
|
||||
{
|
||||
if (itr.Flags.HasAnyFlag(excludePhasesWithFlag))
|
||||
if (pair.Value.Flags.HasAnyFlag(excludePhasesWithFlag))
|
||||
continue;
|
||||
|
||||
var index = excludedPhaseShift.Phases.IndexOf(itr);
|
||||
if (index == -1 || excludedPhaseShift.Phases[index].Flags.HasAnyFlag(excludePhasesWithFlag))
|
||||
var ExcludedPhaseRef = excludedPhaseShift.Phases.LookupByKey(pair.Key);
|
||||
if (ExcludedPhaseRef == null || ExcludedPhaseRef.Flags.HasAnyFlag(excludePhasesWithFlag))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,7 +190,7 @@ namespace Game
|
||||
return checkInversePhaseShift(other, this);
|
||||
}
|
||||
|
||||
public void ModifyPhasesReferences(PhaseRef phaseRef, int references)
|
||||
public void ModifyPhasesReferences(uint phaseId, PhaseRef phaseRef, int references)
|
||||
{
|
||||
phaseRef.References += references;
|
||||
|
||||
@@ -171,7 +198,7 @@ namespace Game
|
||||
{
|
||||
if (phaseRef.Flags.HasAnyFlag(PhaseFlags.Cosmetic))
|
||||
CosmeticReferences += references;
|
||||
else if (phaseRef.Id != 169)
|
||||
else if (phaseId != 169)
|
||||
NonCosmeticReferences += references;
|
||||
else
|
||||
DefaultReferences += references;
|
||||
@@ -195,8 +222,8 @@ namespace Game
|
||||
Flags |= unphasedFlag;
|
||||
}
|
||||
|
||||
public bool HasPhase(uint phaseId) { return Phases.Contains(new PhaseRef(phaseId, PhaseFlags.None, null)); }
|
||||
public List<PhaseRef> GetPhases() { return Phases; }
|
||||
public bool HasPhase(uint phaseId) { return Phases.ContainsKey(phaseId); }
|
||||
public Dictionary<uint, PhaseRef> GetPhases() { return Phases; }
|
||||
|
||||
public bool HasVisibleMapId(uint visibleMapId) { return VisibleMapIds.ContainsKey(visibleMapId); }
|
||||
public Dictionary<uint, VisibleMapIdRef> GetVisibleMapIds() { return VisibleMapIds; }
|
||||
@@ -204,9 +231,9 @@ namespace Game
|
||||
public bool HasUiWorldMapAreaIdSwap(uint uiWorldMapAreaId) { return UiWorldMapAreaIdSwaps.ContainsKey(uiWorldMapAreaId); }
|
||||
public Dictionary<uint, UiWorldMapAreaIdSwapRef> GetUiWorldMapAreaIdSwaps() { return UiWorldMapAreaIdSwaps; }
|
||||
|
||||
public PhaseShiftFlags Flags = PhaseShiftFlags.Unphased;
|
||||
public PhaseShiftFlags Flags;
|
||||
public ObjectGuid PersonalGuid;
|
||||
public List<PhaseRef> Phases = new List<PhaseRef>();
|
||||
public Dictionary<uint, PhaseRef> Phases = new Dictionary<uint, PhaseRef>();
|
||||
public Dictionary<uint, VisibleMapIdRef> VisibleMapIds = new Dictionary<uint, VisibleMapIdRef>();
|
||||
public Dictionary<uint, UiWorldMapAreaIdSwapRef> UiWorldMapAreaIdSwaps = new Dictionary<uint, UiWorldMapAreaIdSwapRef>();
|
||||
|
||||
@@ -216,46 +243,18 @@ namespace Game
|
||||
public bool IsDbPhaseShift;
|
||||
}
|
||||
|
||||
public struct PhaseRef
|
||||
public class PhaseRef
|
||||
{
|
||||
public PhaseRef(uint id, PhaseFlags flags, List<Condition> conditions)
|
||||
public PhaseRef(PhaseFlags flags, List<Condition> conditions)
|
||||
{
|
||||
Id = id;
|
||||
Flags = flags;
|
||||
References = 0;
|
||||
AreaConditions = conditions;
|
||||
}
|
||||
|
||||
public uint Id;
|
||||
public PhaseFlags Flags;
|
||||
public int References;
|
||||
public List<Condition> AreaConditions;
|
||||
|
||||
public static bool operator <(PhaseRef left, PhaseRef right)
|
||||
{
|
||||
return left.Id < right.Id;
|
||||
}
|
||||
|
||||
public static bool operator >(PhaseRef left, PhaseRef right)
|
||||
{
|
||||
return left.Id > right.Id;
|
||||
}
|
||||
|
||||
public static bool operator ==(PhaseRef left, PhaseRef right) { return left.Id == right.Id; }
|
||||
public static bool operator !=(PhaseRef left, PhaseRef right) { return !(left == right); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is PhaseRef)
|
||||
return (PhaseRef)obj == this;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode() ^ Flags.GetHashCode() ^ References.GetHashCode() ^ AreaConditions.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public struct VisibleMapIdRef
|
||||
|
||||
@@ -34,9 +34,12 @@ namespace Game
|
||||
|
||||
public static void ForAllControlled(Unit unit, Action<Unit> func)
|
||||
{
|
||||
foreach (Unit controlled in unit.m_Controlled)
|
||||
for (var i = 0; i < unit.m_Controlled.Count; ++i)
|
||||
{
|
||||
Unit controlled = unit.m_Controlled[i];
|
||||
if (controlled.GetTypeId() != TypeId.Player)
|
||||
func(controlled);
|
||||
}
|
||||
|
||||
for (byte i = 0; i < SharedConst.MaxSummonSlot; ++i)
|
||||
{
|
||||
@@ -287,23 +290,23 @@ namespace Game
|
||||
ConditionSourceInfo srcInfo = new ConditionSourceInfo(obj);
|
||||
bool changed = false;
|
||||
|
||||
foreach (var phaseRef in phaseShift.Phases.ToArray())
|
||||
foreach (var pair in phaseShift.Phases.ToList())
|
||||
{
|
||||
if (!phaseRef.AreaConditions.Empty() && !Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseRef.AreaConditions))
|
||||
if (pair.Value.AreaConditions != null && !Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, pair.Value.AreaConditions))
|
||||
{
|
||||
newSuppressions.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References);
|
||||
phaseShift.ModifyPhasesReferences(phaseRef, -phaseRef.References);
|
||||
phaseShift.Phases.Remove(phaseRef);
|
||||
newSuppressions.AddPhase(pair.Key, pair.Value.Flags, pair.Value.AreaConditions, pair.Value.References);
|
||||
phaseShift.ModifyPhasesReferences(pair.Key, pair.Value, -pair.Value.References);
|
||||
phaseShift.Phases.Remove(pair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var phaseRef in suppressedPhaseShift.Phases.ToArray())
|
||||
foreach (var pair in suppressedPhaseShift.Phases.ToList())
|
||||
{
|
||||
if (Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseRef.AreaConditions))
|
||||
if (Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, pair.Value.AreaConditions))
|
||||
{
|
||||
changed = phaseShift.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References) || changed;
|
||||
suppressedPhaseShift.ModifyPhasesReferences(phaseRef, -phaseRef.References);
|
||||
suppressedPhaseShift.Phases.Remove(phaseRef);
|
||||
changed = phaseShift.AddPhase(pair.Key, pair.Value.Flags, pair.Value.AreaConditions, pair.Value.References) || changed;
|
||||
suppressedPhaseShift.ModifyPhasesReferences(pair.Key, pair.Value, -pair.Value.References);
|
||||
suppressedPhaseShift.Phases.Remove(pair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,8 +362,8 @@ namespace Game
|
||||
}
|
||||
|
||||
changed = changed || !newSuppressions.Phases.Empty() || !newSuppressions.VisibleMapIds.Empty();
|
||||
foreach (var phaseRef in newSuppressions.Phases)
|
||||
suppressedPhaseShift.AddPhase(phaseRef.Id, phaseRef.Flags, phaseRef.AreaConditions, phaseRef.References);
|
||||
foreach (var pair in newSuppressions.Phases)
|
||||
suppressedPhaseShift.AddPhase(pair.Key, pair.Value.Flags, pair.Value.AreaConditions, pair.Value.References);
|
||||
|
||||
foreach (var pair in newSuppressions.VisibleMapIds)
|
||||
suppressedPhaseShift.AddVisibleMapId(pair.Key, pair.Value.VisibleMapInfo, pair.Value.References);
|
||||
@@ -389,8 +392,8 @@ namespace Game
|
||||
phaseShiftChange.Phaseshift.PhaseShiftFlags = (uint)phaseShift.Flags;
|
||||
phaseShiftChange.Phaseshift.PersonalGUID = phaseShift.PersonalGuid;
|
||||
|
||||
foreach (var phaseRef in phaseShift.Phases)
|
||||
phaseShiftChange.Phaseshift.Phases.Add(new PhaseShiftDataPhase((uint)phaseRef.Flags, phaseRef.Id));
|
||||
foreach (var pair in phaseShift.Phases)
|
||||
phaseShiftChange.Phaseshift.Phases.Add(new PhaseShiftDataPhase((uint)pair.Value.Flags, pair.Key));
|
||||
|
||||
foreach (var visibleMapId in phaseShift.VisibleMapIds)
|
||||
phaseShiftChange.VisibleMapIDs.Add((ushort)visibleMapId.Key);
|
||||
@@ -411,8 +414,8 @@ namespace Game
|
||||
partyMemberPhases.PhaseShiftFlags = (int)phaseShift.Flags;
|
||||
partyMemberPhases.PersonalGUID = phaseShift.PersonalGuid;
|
||||
|
||||
foreach (var phase in phaseShift.Phases)
|
||||
partyMemberPhases.List.Add(new PartyMemberPhase((uint)phase.Flags, phase.Id));
|
||||
foreach (var pair in phaseShift.Phases)
|
||||
partyMemberPhases.List.Add(new PartyMemberPhase((uint)pair.Value.Flags, pair.Key));
|
||||
}
|
||||
|
||||
public static void InitDbPhaseShift(PhaseShift phaseShift, PhaseUseFlagsValues phaseUseFlags, uint phaseId, uint phaseGroupId)
|
||||
@@ -512,12 +515,12 @@ namespace Game
|
||||
StringBuilder phases = new StringBuilder();
|
||||
string cosmetic = Global.ObjectMgr.GetCypherString(CypherStrings.PhaseFlagCosmetic, chat.GetSessionDbcLocale());
|
||||
string personal = Global.ObjectMgr.GetCypherString(CypherStrings.PhaseFlagPersonal, chat.GetSessionDbcLocale());
|
||||
foreach (PhaseRef phase in phaseShift.Phases)
|
||||
foreach (var pair in phaseShift.Phases)
|
||||
{
|
||||
phases.Append(phase.Id);
|
||||
if (phase.Flags.HasFlag(PhaseFlags.Cosmetic))
|
||||
phases.Append(pair.Key);
|
||||
if (pair.Value.Flags.HasFlag(PhaseFlags.Cosmetic))
|
||||
phases.Append(' ' + '(' + cosmetic + ')');
|
||||
if (phase.Flags.HasFlag(PhaseFlags.Personal))
|
||||
if (pair.Value.Flags.HasFlag(PhaseFlags.Personal))
|
||||
phases.Append(' ' + '(' + personal + ')');
|
||||
phases.Append(", ");
|
||||
}
|
||||
@@ -547,8 +550,8 @@ namespace Game
|
||||
public static string FormatPhases(PhaseShift phaseShift)
|
||||
{
|
||||
StringBuilder phases = new StringBuilder();
|
||||
foreach (var phase in phaseShift.Phases)
|
||||
phases.Append(phase.Id + ',');
|
||||
foreach (var phaseId in phaseShift.Phases.Keys)
|
||||
phases.Append(phaseId + ',');
|
||||
|
||||
return phases.ToString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user