Core/Phases: Fixes errors in phases.

This commit is contained in:
hondacrx
2018-06-15 12:36:55 -04:00
parent b8b0ff0fba
commit 2fa79e0855
5 changed files with 132 additions and 133 deletions
+57 -58
View File
@@ -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