diff --git a/Source/Game/Collision/RegularGrid2D.cs b/Source/Game/Collision/RegularGrid2D.cs index a2e2862dd..bd0c42618 100644 --- a/Source/Game/Collision/RegularGrid2D.cs +++ b/Source/Game/Collision/RegularGrid2D.cs @@ -19,6 +19,7 @@ using Framework.GameMath; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; +using System.Collections.Concurrent; namespace Game.Collision { @@ -39,14 +40,14 @@ namespace Game.Collision Vector3 pos = value.getPosition(); Node node = getGridFor(pos.X, pos.Y); node.insert(value); - memberTable.Add(value, node); + memberTable.TryAdd(value, node); } public virtual void remove(T value) { memberTable[value].remove(value); // Remove the member - memberTable.Remove(value); + memberTable.TryRemove(value, out Node node); } public virtual void balance() @@ -205,7 +206,7 @@ namespace Game.Collision node.intersectRay(ray, intersectCallback, ref max_dist); } - Dictionary memberTable = new Dictionary(); + ConcurrentDictionary memberTable = new ConcurrentDictionary(); Node[][] nodes = new Node[CELL_NUMBER][]; } } diff --git a/Source/Game/Entities/Object/Position.cs b/Source/Game/Entities/Object/Position.cs index 521345d18..515c9ae35 100644 --- a/Source/Game/Entities/Object/Position.cs +++ b/Source/Game/Entities/Object/Position.cs @@ -265,10 +265,14 @@ namespace Game.Entities if (obj == this) return true; + // move arc to range 0.. 2*pi + arc = NormalizeOrientation(arc); + float angle = GetAngle(obj); angle -= GetOrientation(); // move angle to range -pi ... +pi + angle = NormalizeOrientation(angle); if (angle > MathFunctions.PI) angle -= 2.0f * MathFunctions.PI; @@ -276,6 +280,16 @@ namespace Game.Entities float rborder = (arc / border); // in range 0..pi return ((angle >= lborder) && (angle <= rborder)); } + + public bool HasInLine(Position pos, float width) + { + if (!HasInArc(MathFunctions.PI, pos)) + return false; + + float angle = GetRelativeAngle(pos); + return Math.Abs(Math.Sin(angle)) * GetExactDist2d(pos.GetPositionX(), pos.GetPositionY()) < width; + } + public void GetSinCos(float x, float y, out float vsin, out float vcos) { float dx = GetPositionX() - x; diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 26cae1131..2195ec003 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -2568,14 +2568,6 @@ namespace Game.Entities public virtual bool LoadFromDB(ulong guid, Map map) { return true; } //Position - public bool HasInLine(WorldObject target, float width) - { - if (!HasInArc(MathFunctions.PI, target)) - return false; - width += target.GetObjectSize(); - float angle = GetRelativeAngle(target); - return Math.Abs(Math.Sin(angle)) * GetExactDist2d(target.GetPositionX(), target.GetPositionY()) < width; - } public float GetDistanceZ(WorldObject obj) { diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index bcabfd96c..8b4cfec52 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -2262,7 +2262,7 @@ namespace Game modelInfo.BoundingRadius = result.Read(1); modelInfo.CombatReach = result.Read(2); modelInfo.DisplayIdOtherGender = result.Read(3); - modelInfo.gender = (sbyte)creatureDisplay.Gender; + modelInfo.gender = creatureDisplay.Gender; // Checks if (modelInfo.gender == (sbyte)Gender.Unknown) @@ -3587,7 +3587,7 @@ namespace Game return null; // If a model for another gender exists, 50% chance to use it - if (modelInfo.DisplayIdOtherGender != 0 && RandomHelper.NextDouble() == 0) + if (modelInfo.DisplayIdOtherGender != 0 && RandomHelper.URand(0, 1) == 0) { CreatureModelInfo minfotmp = GetCreatureModelInfo(modelInfo.DisplayIdOtherGender); if (minfotmp == null)