Core/Phases: Fixes errors in phases.
This commit is contained in:
@@ -21,7 +21,6 @@ using Game.DataStorage;
|
||||
using Game.Loots;
|
||||
using Game.Maps;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
@@ -66,7 +65,7 @@ namespace Game.Entities
|
||||
|
||||
public bool Create(ulong guidlow, Player owner)
|
||||
{
|
||||
Contract.Assert(owner != null);
|
||||
Cypher.Assert(owner != null);
|
||||
|
||||
Relocate(owner.GetPositionX(), owner.GetPositionY(), owner.GetPositionZ(), owner.GetOrientation());
|
||||
|
||||
@@ -114,12 +113,12 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, GetInstanceId()); // instanceId
|
||||
trans.Append(stmt);
|
||||
|
||||
foreach (PhaseRef phase in GetPhaseShift().GetPhases())
|
||||
foreach (var phaseId in GetPhaseShift().GetPhases().Keys)
|
||||
{
|
||||
index = 0;
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CORPSE_PHASES);
|
||||
stmt.AddValue(index++, GetOwnerGUID().GetCounter()); // OwnerGuid
|
||||
stmt.AddValue(index++, phase.Id); // PhaseId
|
||||
stmt.AddValue(index++, phaseId); // PhaseId
|
||||
trans.Append(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ using Game.Scenarios;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -63,9 +62,8 @@ namespace Game.Entities
|
||||
{
|
||||
if (IsTypeId(TypeId.Corpse))
|
||||
{
|
||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() Corpse Type: {0} ({1}) deleted but still in map!!",
|
||||
ToCorpse().GetCorpseType(), GetGUID().ToString());
|
||||
Contract.Assert(false);
|
||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() Corpse Type: {0} ({1}) deleted but still in map!!", ToCorpse().GetCorpseType(), GetGUID().ToString());
|
||||
Cypher.Assert(false);
|
||||
}
|
||||
ResetMap();
|
||||
}
|
||||
@@ -75,13 +73,13 @@ namespace Game.Entities
|
||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() {0} deleted but still in world!!", GetGUID().ToString());
|
||||
if (isTypeMask(TypeMask.Item))
|
||||
Log.outFatal(LogFilter.Misc, "Item slot {0}", ((Item)this).GetSlot());
|
||||
Contract.Assert(false);
|
||||
Cypher.Assert(false);
|
||||
}
|
||||
|
||||
if (m_objectUpdated)
|
||||
{
|
||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() {0} deleted but still in update list!!", GetGUID().ToString());
|
||||
Contract.Assert(false);
|
||||
Cypher.Assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,45 +263,45 @@ namespace Game.Entities
|
||||
|
||||
public int GetInt32Value(object index)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
return updateValues[(int)index].SignedValue;
|
||||
}
|
||||
|
||||
public uint GetUInt32Value(object index)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
return updateValues[(int)index].UnsignedValue;
|
||||
}
|
||||
|
||||
public ulong GetUInt64Value(object index)
|
||||
{
|
||||
Contract.Assert((int)index + 1 < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index + 1 < valuesCount || PrintIndexError(index, false));
|
||||
return ((ulong)updateValues[(int)index + 1].UnsignedValue << 32 | updateValues[(int)index].UnsignedValue);
|
||||
}
|
||||
|
||||
public float GetFloatValue(object index)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
return updateValues[(int)index].FloatValue;
|
||||
}
|
||||
|
||||
public byte GetByteValue(object index, byte offset)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Contract.Assert(offset < 4);
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert(offset < 4);
|
||||
return (byte)((updateValues[(int)index].UnsignedValue >> (offset * 8)) & 0xFF);
|
||||
}
|
||||
|
||||
public ushort GetUInt16Value(object index, byte offset)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Contract.Assert(offset < 2);
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert(offset < 2);
|
||||
return (ushort)((updateValues[(int)index].UnsignedValue >> (offset * 16)) & 0xFFFF);
|
||||
}
|
||||
|
||||
public ObjectGuid GetGuidValue(object index)
|
||||
{
|
||||
Contract.Assert((int)index + 3 < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index + 3 < valuesCount || PrintIndexError(index, false));
|
||||
return new ObjectGuid(GetUInt64Value((int)index + 2), GetUInt64Value(index));
|
||||
}
|
||||
|
||||
@@ -976,7 +974,7 @@ namespace Game.Entities
|
||||
flags = UpdateFieldFlags.ConversationUpdateFieldFlags;
|
||||
break;
|
||||
case TypeId.Object:
|
||||
Contract.Assert(false);
|
||||
Cypher.Assert(false);
|
||||
break;
|
||||
}
|
||||
return visibleFlag;
|
||||
@@ -1051,7 +1049,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetInt32Value(object index, int value)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (updateValues[(int)index].SignedValue != value)
|
||||
{
|
||||
@@ -1065,7 +1063,7 @@ namespace Game.Entities
|
||||
public void SetUInt32Value(object index, uint value)
|
||||
{
|
||||
int _index = Convert.ToInt32(index);
|
||||
Contract.Assert(_index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert(_index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (updateValues[_index].UnsignedValue != value)
|
||||
{
|
||||
@@ -1078,7 +1076,7 @@ namespace Game.Entities
|
||||
|
||||
public void UpdateUInt32Value(object index, uint value)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
updateValues[(int)index].UnsignedValue = value;
|
||||
_changesMask.Set((int)index, true);
|
||||
@@ -1086,7 +1084,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetUInt64Value(object index, ulong value)
|
||||
{
|
||||
Contract.Assert((int)index + 1 < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index + 1 < valuesCount || PrintIndexError(index, true));
|
||||
if (GetUInt64Value(index) != value)
|
||||
{
|
||||
updateValues[(int)index].UnsignedValue = MathFunctions.Pair64_LoPart(value);
|
||||
@@ -1100,7 +1098,7 @@ namespace Game.Entities
|
||||
|
||||
public bool AddGuidValue(object index, ObjectGuid value)
|
||||
{
|
||||
Contract.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
if (!value.IsEmpty() && GetGuidValue(index).IsEmpty())
|
||||
{
|
||||
SetGuidValue(index, value);
|
||||
@@ -1112,7 +1110,7 @@ namespace Game.Entities
|
||||
|
||||
public bool RemoveGuidValue(object index, ObjectGuid value)
|
||||
{
|
||||
Contract.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
if (!value.IsEmpty() && GetGuidValue(index) == value)
|
||||
{
|
||||
SetGuidValue(index, ObjectGuid.Empty);
|
||||
@@ -1124,7 +1122,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetFloatValue(object index, float value)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (updateValues[(int)index].FloatValue != value)
|
||||
{
|
||||
@@ -1137,7 +1135,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetByteValue(object index, byte offset, byte value)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (offset > 3)
|
||||
{
|
||||
@@ -1157,7 +1155,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetUInt16Value(object index, byte offset, ushort value)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (offset > 2)
|
||||
{
|
||||
@@ -1177,7 +1175,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetGuidValue(object index, ObjectGuid value)
|
||||
{
|
||||
Contract.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index + 3 < valuesCount || PrintIndexError(index, true));
|
||||
if (GetGuidValue(index) != value)
|
||||
{
|
||||
SetUInt64Value(index, value.GetLowValue());
|
||||
@@ -1246,7 +1244,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetFlag(object index, object newflag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
uint oldval = updateValues[(int)index].UnsignedValue;
|
||||
uint newval = oldval | Convert.ToUInt32(newflag);
|
||||
|
||||
@@ -1261,8 +1259,8 @@ namespace Game.Entities
|
||||
|
||||
public void RemoveFlag(object index, object oldFlag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Contract.Assert(updateValues != null);
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert(updateValues != null);
|
||||
|
||||
uint oldval = updateValues[(int)index].UnsignedValue;
|
||||
uint newval = (oldval & ~Convert.ToUInt32(oldFlag));
|
||||
@@ -1301,7 +1299,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetByteFlag(object index, byte offset, object newFlag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (offset > 4)
|
||||
{
|
||||
@@ -1320,7 +1318,7 @@ namespace Game.Entities
|
||||
|
||||
public void RemoveByteFlag(object index, byte offset, object oldFlag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, true));
|
||||
|
||||
if (offset > 4)
|
||||
{
|
||||
@@ -1347,8 +1345,8 @@ namespace Game.Entities
|
||||
|
||||
public bool HasByteFlag(object index, byte offset, object flag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Contract.Assert(offset < 4);
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert(offset < 4);
|
||||
return Convert.ToBoolean(updateValues[(int)index].UnsignedValue >> (offset * 8) & Convert.ToUInt32(flag));
|
||||
}
|
||||
|
||||
@@ -1376,7 +1374,7 @@ namespace Game.Entities
|
||||
|
||||
public bool HasFlag64(object index, object flag)
|
||||
{
|
||||
Contract.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < valuesCount || PrintIndexError(index, false));
|
||||
return (GetUInt64Value(index) & Convert.ToUInt64(flag)) != 0;
|
||||
}
|
||||
|
||||
@@ -1390,13 +1388,13 @@ namespace Game.Entities
|
||||
|
||||
public uint[] GetDynamicValues(object index)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
return _dynamicValues[(int)index];
|
||||
}
|
||||
|
||||
public uint GetDynamicValue(object index, ushort offset)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
if (offset >= _dynamicValues[(int)index].Length)
|
||||
return 0;
|
||||
|
||||
@@ -1405,14 +1403,14 @@ namespace Game.Entities
|
||||
|
||||
public void AddDynamicValue(object index, uint value)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, true));
|
||||
|
||||
SetDynamicValue(index, (byte)_dynamicValues[(int)index].Length, value);
|
||||
}
|
||||
|
||||
public void RemoveDynamicValue(object index, uint value)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
|
||||
// TODO: Research if this is blizzlike to just set value to 0
|
||||
for (var i = 0; i < _dynamicValues[(int)index].Length; ++i)
|
||||
@@ -1430,7 +1428,7 @@ namespace Game.Entities
|
||||
|
||||
public void ClearDynamicValue(object index)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, false));
|
||||
|
||||
if (!_dynamicValues[(int)index].Empty())
|
||||
{
|
||||
@@ -1444,7 +1442,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetDynamicValue(object index, ushort offset, uint value)
|
||||
{
|
||||
Contract.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, true));
|
||||
Cypher.Assert((int)index < _dynamicValuesCount || PrintIndexError(index, true));
|
||||
|
||||
DynamicFieldChangeType changeType = DynamicFieldChangeType.ValueChanged;
|
||||
if (_dynamicValues[(int)index].Length <= offset)
|
||||
@@ -1892,8 +1890,8 @@ namespace Game.Entities
|
||||
|
||||
public virtual void SetMap(Map map)
|
||||
{
|
||||
Contract.Assert(map != null);
|
||||
Contract.Assert(!IsInWorld);
|
||||
Cypher.Assert(map != null);
|
||||
Cypher.Assert(!IsInWorld);
|
||||
|
||||
if (_currMap == map)
|
||||
return;
|
||||
@@ -1907,8 +1905,8 @@ namespace Game.Entities
|
||||
|
||||
public virtual void ResetMap()
|
||||
{
|
||||
Contract.Assert(_currMap != null);
|
||||
Contract.Assert(!IsInWorld);
|
||||
Cypher.Assert(_currMap != null);
|
||||
Cypher.Assert(!IsInWorld);
|
||||
if (IsWorldObject())
|
||||
_currMap.RemoveWorldObject(this);
|
||||
_currMap = null;
|
||||
@@ -2047,7 +2045,7 @@ namespace Game.Entities
|
||||
|
||||
public void SummonCreatureGroup(byte group, out List<TempSummon> list)
|
||||
{
|
||||
Contract.Assert((IsTypeId(TypeId.GameObject) || IsTypeId(TypeId.Unit)), "Only GOs and creatures can summon npc groups!");
|
||||
Cypher.Assert((IsTypeId(TypeId.GameObject) || IsTypeId(TypeId.Unit)), "Only GOs and creatures can summon npc groups!");
|
||||
list = new List<TempSummon>();
|
||||
var data = Global.ObjectMgr.GetSummonGroup(GetEntry(), IsTypeId(TypeId.GameObject) ? SummonerType.GameObject : SummonerType.Creature, group);
|
||||
if (data.Empty())
|
||||
@@ -2128,9 +2126,9 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
public PhaseShift GetPhaseShift() { return _phaseShift; }
|
||||
public void SetPhaseShift(PhaseShift phaseShift) { _phaseShift = phaseShift; }
|
||||
public void SetPhaseShift(PhaseShift phaseShift) { _phaseShift = new PhaseShift(phaseShift); }
|
||||
public PhaseShift GetSuppressedPhaseShift() { return _suppressedPhaseShift; }
|
||||
public void SetSuppressedPhaseShift(PhaseShift phaseShift) { _suppressedPhaseShift = phaseShift; }
|
||||
public void SetSuppressedPhaseShift(PhaseShift phaseShift) { _suppressedPhaseShift = new PhaseShift(phaseShift); }
|
||||
public int GetDBPhase() { return _dbPhase; }
|
||||
|
||||
// if negative it is used as PhaseGroupId
|
||||
|
||||
@@ -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