diff --git a/Application/RSBot/Views/SplashScreen.cs b/Application/RSBot/Views/SplashScreen.cs index f33de950..f952584a 100644 --- a/Application/RSBot/Views/SplashScreen.cs +++ b/Application/RSBot/Views/SplashScreen.cs @@ -186,28 +186,6 @@ private void InitializeBot() MessageBoxButtons.OK, MessageBoxIcon.Error); CommandManager.Initialize(); - - InitializeMap(); - } - - /// - /// Initializes the map. - /// - private void InitializeMap() - { - //---- Load Map ---- - var mapFile = Path.Combine(Kernel.BasePath, "Data", "Game", "map.rsc"); - - if (!CollisionManager.Enabled) Log.Warn("[Collision] Collision detection has been deactivated by the user!"); - - if (!File.Exists(mapFile)) - { - Log.Error($"[Collisions] Directory {mapFile} not found!"); - - return; - } - - CollisionManager.Initialize(); } /// diff --git a/Botbases/RSBot.Default/Bot/Botbase.cs b/Botbases/RSBot.Default/Bot/Botbase.cs index e8a2923d..fd79d2a6 100644 --- a/Botbases/RSBot.Default/Bot/Botbase.cs +++ b/Botbases/RSBot.Default/Bot/Botbase.cs @@ -47,6 +47,9 @@ public void Reload() /// public void Tick() { + if (!Kernel.Bot.Running) + return; + if (Game.Player.HasActiveVehicle) { Game.Player.Vehicle.Dismount(); diff --git a/Botbases/RSBot.Default/Bundle/Target/TargetBundle.cs b/Botbases/RSBot.Default/Bundle/Target/TargetBundle.cs index 5cd71788..40de4675 100644 --- a/Botbases/RSBot.Default/Bundle/Target/TargetBundle.cs +++ b/Botbases/RSBot.Default/Bundle/Target/TargetBundle.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.SymbolStore; using System.Linq; using RSBot.Core; using RSBot.Core.Components; @@ -144,14 +145,14 @@ private SpawnedMonster GetNearestEnemy() var ignorePillar = PlayerConfig.Get("RSBot.Training.checkBoxDimensionPillar"); if (!SpawnManager.TryGetEntities(m => - m.State.LifeState == LifeState.Alive && - !(warlockModeEnabled && m.State.HasTwoDots()) && - m.IsBehindObstacle == false && - _blacklist?.ContainsKey(m.UniqueId) == false && - Container.Bot.Area.IsInSight(m) && - !m.Record.IsPandora && - //m.DistanceToPlayer <= 40 && - !(m.Record.IsDimensionPillar && ignorePillar) && + m.State.LifeState == LifeState.Alive && //Only alive + !(warlockModeEnabled && m.State.HasTwoDots()) && //Has two Dots? + m.IsBehindObstacle == false && //Is not behind obstacle + (_blacklist == null || !_blacklist.ContainsKey(m.UniqueId)) && //Is not blacklisted + (m.AttackingPlayer || !Bundles.Avoidance.AvoidMonster(m.Rarity)) && //Is attacking player or shouldn't be avoided + Container.Bot.Area.IsInSight(m) && //Is in training area + !m.Record.IsPandora && //Isn't pandora box + !(m.Record.IsDimensionPillar && ignorePillar) && //Isn't dimension pillar !m.Record.IsSummonFlower, out var entities)) return default; diff --git a/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionLine.cs b/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionLine.cs deleted file mode 100644 index 195bd750..00000000 --- a/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionLine.cs +++ /dev/null @@ -1,15 +0,0 @@ -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision.Calculated; - -public struct CalculatedCollisionLine -{ - public Position Source; - public Position Destination; - - public CalculatedCollisionLine(Position source, Position destination) - { - Source = source; - Destination = destination; - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionMesh.cs b/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionMesh.cs deleted file mode 100644 index 72e26e97..00000000 --- a/Library/RSBot.Core/Components/Collision/Calculated/CalculatedCollisionMesh.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision.Calculated; - -/// -/// Represents the calculated version of the collision mesh. -/// Calculated means, that it positions are mapped to the in game world. -/// -public class CalculatedCollisionMesh -{ - public CalculatedCollisionLine[] Collisions; - public Region Region; - - internal CalculatedCollisionMesh(RSCollisionMesh original) - { - Region = original.Region; - - var collisions = original.Collisions; - Collisions = new CalculatedCollisionLine[collisions.Length]; - - Calculate(collisions); - } - - private void Calculate(IReadOnlyList collisions) - { - for (var iLine = 0; iLine < collisions.Count; iLine++) - { - var line = collisions[iLine]; - - var posSource = new Position(Region, line.Source.X, line.Source.Y, 0); - var posDestination = new Position(Region, line.Destination.X, line.Destination.Y, 0); - - Collisions[iLine] = new CalculatedCollisionLine(posSource, posDestination); - } - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/CollisionCalculator.cs b/Library/RSBot.Core/Components/Collision/CollisionCalculator.cs deleted file mode 100644 index 2584cdd4..00000000 --- a/Library/RSBot.Core/Components/Collision/CollisionCalculator.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using RSBot.Core.Components.Collision.Calculated; -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision; - -internal class CollisionCalculator -{ - /// - /// Gets the calculated collision between the two positions. - /// - /// The source. - /// The destination. - /// The meshes. - /// - public static CollisionResult? GetCalculatedCollisionBetween(Position source, - Position destination, List meshes) - { - var sourceLine = new CalculatedCollisionLine(source, destination); - - foreach (var mesh in meshes) - foreach (var line in mesh.Collisions - .Where(x => x.Source.DistanceToPlayer() <= destination.DistanceToPlayer() || - x.Destination.DistanceToPlayer() <= destination.DistanceToPlayer()) - .OrderBy(x => x.Source.DistanceToPlayer())) - { - var collision = Intersection.FindIntersection(sourceLine, line, 0.05); - - if (collision.HasValue) - return new CollisionResult - { - CollidedAt = collision.Value.collidedAt, - CollidedWith = collision.Value.collidedWith, - Source = source, - Destination = destination - }; - } - - return null; - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/CollisionResult.cs b/Library/RSBot.Core/Components/Collision/CollisionResult.cs deleted file mode 100644 index 00d38dac..00000000 --- a/Library/RSBot.Core/Components/Collision/CollisionResult.cs +++ /dev/null @@ -1,30 +0,0 @@ -using RSBot.Core.Components.Collision.Calculated; -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision; - -/// -/// The result of a collision request -/// -public struct CollisionResult -{ - /// - /// Gets the line the ray collided with - /// - public CalculatedCollisionLine CollidedWith; - - /// - /// The collided at position - /// - public Position CollidedAt; - - /// - /// The source position from where the check started - /// - public Position Source; - - /// - /// The destination of the check - /// - public Position Destination; -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/Intersection.cs b/Library/RSBot.Core/Components/Collision/Intersection.cs deleted file mode 100644 index 9607a8af..00000000 --- a/Library/RSBot.Core/Components/Collision/Intersection.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using RSBot.Core.Components.Collision.Calculated; -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision; - -/// -/// Taken from -/// https://github.com/justcoding121/Advanced-Algorithms/blob/master/Advanced.Algorithms/Geometry/Intersection.cs -/// Slightly modified to match RSBot purposes! -/// -internal class Intersection -{ - public static (Position collidedAt, CalculatedCollisionLine collidedWith)? FindIntersection( - CalculatedCollisionLine lineA, CalculatedCollisionLine lineB, double tolerance = 1) - { - float x1 = lineA.Source.X, y1 = lineA.Source.Y; - float x2 = lineA.Destination.X, y2 = lineA.Destination.Y; - - float x3 = lineB.Source.X, y3 = lineB.Source.Y; - float x4 = lineB.Destination.X, y4 = lineB.Destination.Y; - - float x, y; - - //lineA is vertical x1 = x2 - //slope will be infinity - //so lets derive another solution - if (MathF.Abs(x1 - x2) < tolerance) - { - //compute slope of line 2 (m2) and c2 - var m2 = (y4 - y3) / (x4 - x3); - var c2 = -m2 * x3 + y3; - - //equation of vertical line is x = c - //if line 1 and 2 intersect then x1=c1=x - //subsitute x=x1 in (4) => -m2x1 + y = c2 - // => y = c2 + m2x1 - x = x1; - y = c2 + m2 * x1; - } - //lineB is vertical x3 = x4 - //slope will be infinity - //so lets derive another solution - else if (MathF.Abs(x3 - x4) < tolerance) - { - //compute slope of line 1 (m1) and c2 - var m1 = (y2 - y1) / (x2 - x1); - var c1 = -m1 * x1 + y1; - - //equation of vertical line is x = c - //if line 1 and 2 intersect then x3=c3=x - //subsitute x=x3 in (3) => -m1x3 + y = c1 - // => y = c1 + m1x3 - x = x3; - y = c1 + m1 * x3; - } - //lineA & lineB are not vertical - //(could be horizontal we can handle it with slope = 0) - else - { - //compute slope of line 1 (m1) and c2 - var m1 = (y2 - y1) / (x2 - x1); - var c1 = -m1 * x1 + y1; - - //compute slope of line 2 (m2) and c2 - var m2 = (y4 - y3) / (x4 - x3); - var c2 = -m2 * x3 + y3; - - //solving equations (3) & (4) => x = (c1-c2)/(m2-m1) - //plugging x value in equation (4) => y = c2 + m2 * x - x = (c1 - c2) / (m2 - m1); - y = c2 + m2 * x; - - //verify by plugging intersection point (x, y) - //in orginal equations (1) & (2) to see if they intersect - //otherwise x,y values will not be finite and will fail this check - if (!(Math.Abs(-m1 * x + y - c1) < tolerance - && Math.Abs(-m2 * x + y - c2) < tolerance)) - return null; - } - - //x,y can intersect outside the line segment since line is infinitely long - //so finally check if x, y is within both the line segments - if (IsInsideLine(lineA, x, y) && - IsInsideLine(lineB, x, y)) - return new ValueTuple(new Position(x, y), lineB); - //return default null (no intersection) - return null; - } - - /// - /// Returns true if given point(x,y) is inside the given line segment - /// - /// - /// - /// - /// - private static bool IsInsideLine(CalculatedCollisionLine line, float x, float y) - { - var isInX = (x >= line.Source.X && x <= line.Destination.X) - || (x >= line.Destination.X && x <= line.Source.X); - - var isInY = (y >= line.Source.Y && y <= line.Destination.Y) - || (y >= line.Destination.Y && y <= line.Source.Y); - - return isInX && isInY; - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/RSCollisionLine.cs b/Library/RSBot.Core/Components/Collision/RSCollisionLine.cs deleted file mode 100644 index 59e2e81d..00000000 --- a/Library/RSBot.Core/Components/Collision/RSCollisionLine.cs +++ /dev/null @@ -1,28 +0,0 @@ -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision; - -internal struct RSCollisionLine -{ - /// - /// The source point. - /// - public RSCollisionPoint Source; - - /// - /// The destination point. - /// - public RSCollisionPoint Destination; - - /// - /// The region identifier of this collision line - /// - public Region Region; - - public RSCollisionLine(RSCollisionPoint source, RSCollisionPoint destination, Region region) - { - Source = source; - Destination = destination; - Region = region; - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/RSCollisionMesh.cs b/Library/RSBot.Core/Components/Collision/RSCollisionMesh.cs deleted file mode 100644 index e66ca6fe..00000000 --- a/Library/RSBot.Core/Components/Collision/RSCollisionMesh.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.IO; -using RSBot.Core.Objects; - -namespace RSBot.Core.Components.Collision; - -/// -/// Represents the structure of a RSBot collision mesh. -/// -internal struct RSCollisionMesh -{ - /// - /// The region identifier this navmesh is used for - /// - public Region Region; - - /// - /// Gets the collision lines - /// - public RSCollisionLine[] Collisions; - - /// - /// Initializes a new instance of the struct. - /// Takes the binary reader and parses a new instance. - /// - /// The reader. - public RSCollisionMesh(BinaryReader reader) - { - Region = reader.ReadUInt16(); - var collisionLineCount = reader.ReadInt32(); - - Collisions = new RSCollisionLine[collisionLineCount]; - - for (var i = 0; i < collisionLineCount; i++) - { - var source = new RSCollisionPoint - { - X = reader.ReadInt16(), - Y = reader.ReadInt16() - }; - var destination = new RSCollisionPoint - { - X = reader.ReadInt16(), - Y = reader.ReadInt16() - }; - - Collisions[i] = new RSCollisionLine(source, destination, Region); - } - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/Collision/RSCollisionPoint.cs b/Library/RSBot.Core/Components/Collision/RSCollisionPoint.cs deleted file mode 100644 index 84f4f58b..00000000 --- a/Library/RSBot.Core/Components/Collision/RSCollisionPoint.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace RSBot.Core.Components.Collision; - -/// -/// Represents a point within an RSCollisionMesh -/// -internal struct RSCollisionPoint -{ - public short X; - public short Y; - - public RSCollisionPoint() - { - X = 0; - Y = 0; - } -} \ No newline at end of file diff --git a/Library/RSBot.Core/Components/CollisionManager.cs b/Library/RSBot.Core/Components/CollisionManager.cs index 6d695521..5983e3e8 100644 --- a/Library/RSBot.Core/Components/CollisionManager.cs +++ b/Library/RSBot.Core/Components/CollisionManager.cs @@ -1,32 +1,14 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; +using System.Diagnostics; using System.Linq; -using RSBot.Core.Components.Collision; -using RSBot.Core.Components.Collision.Calculated; +using System.Numerics; using RSBot.Core.Event; using RSBot.Core.Objects; +using RSBot.NavMeshApi; namespace RSBot.Core.Components; public static class CollisionManager { - private record LookupEntry(Region Region, long DataPosition); - private record CollisionEntry(Region Region, RSCollisionMesh CollisionMesh); - - private const string SupportedHeader = "RSNVM"; - private const int SupportedVersion = 1200; - - private static LookupEntry[] _lookupTable; - private static CollisionEntry[] _loadedCollisions; - - /// - /// Gets a value indicating whether this instance is initialized. - /// - /// - /// true if this instance is initialized; otherwise, false. - /// - public static bool IsInitialized { get; private set; } /// /// Gets a value indicating whether this instance is updating. @@ -44,28 +26,6 @@ private record CollisionEntry(Region Region, RSCollisionMesh CollisionMesh); /// public static Region CenterRegion { get; private set; } - /// - /// Gets a value indicating whether this instance has active collision meshes. - /// - /// - /// true if this instance has active meshes; otherwise, false. - /// - public static bool HasActiveMeshes - { - get - { - if (!IsInitialized || !Enabled) - return false; - - if (ActiveCollisionMeshes == null) - return false; - - if (IsUpdating) - return false; - - return ActiveCollisionMeshes.Count > 0; - } - } /// /// Gets or sets a value indicating whether this is enabled. @@ -79,102 +39,7 @@ public static bool Enabled set => GlobalConfig.Set("RSBot.EnableCollisionDetection", value); } - /// - /// Gets the active collision meshes. - /// - /// - /// The active collision meshes. - /// - public static List ActiveCollisionMeshes { get; private set; } - - /// - /// Initializes the specified map data directory. - /// - public static void Initialize() - { - LoadLookupTable(); - - IsInitialized = true; - } - - /// - /// Loads the collisions from the specified file path. - /// - /// The path. - public static void LoadLookupTable() - { - var sw = Stopwatch.StartNew(); - - using var fileStream = - new BinaryReader(File.OpenRead(Path.Combine(Kernel.BasePath, "Data", "Game", "map.rsc"))); - - var header = fileStream.ReadString(); - var version = fileStream.ReadInt32(); - - if (header != SupportedHeader || version != SupportedVersion) - { - Log.Error("[Collision] Outdated or invalid collision file!"); - - return; - } - - var lookupTableOffset = fileStream.ReadInt64(); - fileStream.BaseStream.Seek(lookupTableOffset, SeekOrigin.Begin); - - var entryCount = fileStream.ReadUInt16(); - _lookupTable = new LookupEntry[entryCount]; - - for (var entryIndex = 0; entryIndex < entryCount; entryIndex++) - { - var regionId = fileStream.ReadUInt16(); - var fileOffset = fileStream.ReadInt64(); - - _lookupTable[entryIndex] = new LookupEntry(regionId, fileOffset); - } - - sw.Stop(); - - Log.Notify( - $"[Collision] Loaded lookup table for {_lookupTable.Length} collision regions in {sw.ElapsedMilliseconds}ms"); - - EventManager.FireEvent("OnLoadCollisionLookupTable"); - } - - /// - /// Loads the specified regions collision information. - /// - /// - private static void LoadRegions(Region[] regions) - { - var sw = Stopwatch.StartNew(); - - using var fileStream = - new BinaryReader(File.OpenRead(Path.Combine(Kernel.BasePath, "Data", "Game", "map.rsc"))); - - _loadedCollisions ??= new CollisionEntry[regions.Length]; - - for (var regionIndex = 0; regionIndex < regions.Length; regionIndex++) - { - var region = regions[regionIndex]; - var entry = _lookupTable.FirstOrDefault(e => e.Region == region); - - if (entry == null) - { - Log.Debug($"[Collision] Could not find entry in lookup table for region with id [{region}]"); - - continue; - } - - fileStream.BaseStream.Seek(entry.DataPosition, SeekOrigin.Begin); - var collisionMesh = new RSCollisionMesh(fileStream); - _loadedCollisions[regionIndex] = new CollisionEntry(region, collisionMesh); - } - - sw.Stop(); - Log.Debug($"[Collision] Loaded {_loadedCollisions.Length} collision regions in {sw.ElapsedMilliseconds}ms"); - - EventManager.FireEvent("OnLoadCollisionRegions"); - } + private static NavMesh[] _loadedNavMeshes = new NavMesh[9]; /// /// Updates the collision that are currently stored as active. @@ -183,40 +48,30 @@ private static void LoadRegions(Region[] regions) /// The center region identifier. public static void Update(Region region) { - if (region.IsDungeon) - return; - - if ((region == CenterRegion && HasActiveMeshes) || region == 0) - return; - - CenterRegion = region; - if (!Enabled) - { - ActiveCollisionMeshes = null; - return; - } - if (!IsInitialized) - Initialize(); + if (region == CenterRegion) + return; IsUpdating = true; - ActiveCollisionMeshes = new List(9); - - var surroundedBy = CenterRegion.GetSurroundingRegions(); - - LoadRegions(surroundedBy); + + CenterRegion = region; - foreach (var surroundingRegion in surroundedBy) + var surrounding = CenterRegion.GetSurroundingRegions(); + for (var iRegion = 0; iRegion < 9; iRegion++) { - var mesh = _loadedCollisions.FirstOrDefault(c => c.Region == surroundingRegion); - if (mesh == null) - continue; + var navSw = Stopwatch.StartNew(); + var actualRegion = surrounding[iRegion]; - var calculatedMesh = new CalculatedCollisionMesh(mesh.CollisionMesh); + if (!NavMeshManager.TryGetNavMesh(actualRegion.Id, out _loadedNavMeshes[iRegion])) + { + Log.Warn($"Could not load NavMesh for region 0x{actualRegion.Id:x4}"); + return; + } - ActiveCollisionMeshes.Add(calculatedMesh); + navSw.Stop(); + Log.Debug($"Loaded navmesh in {navSw.ElapsedMilliseconds}ms (Ticks: {navSw.ElapsedTicks})"); } IsUpdating = false; @@ -234,23 +89,32 @@ public static void Update(Region region) /// public static bool HasCollisionBetween(Position source, Position destination) { - if (!HasActiveMeshes) + if (source.DistanceTo(destination) > 150) return false; - return CollisionCalculator.GetCalculatedCollisionBetween(source, destination, ActiveCollisionMeshes) != null; - } + var navMeshSrc = _loadedNavMeshes.FirstOrDefault(nm => nm != null && nm.Region == source.Region.Id); + if (navMeshSrc == null) + return false; - /// - /// Gets the collision between the source and destination. - /// - /// The source. - /// The destination. - /// null if no collision was found - public static CollisionResult? GetCollisionBetween(Position source, Position destination) - { - if (!HasActiveMeshes) - return null; + var navMeshDest = _loadedNavMeshes.FirstOrDefault(nm => nm != null && nm.Region == destination.Region.Id); + if (navMeshDest == null) + return false; + + var srcOffset = new Vector3(source.XOffset, source.ZOffset, source.YOffset); + var destOffset = new Vector3(destination.XOffset, destination.ZOffset, destination.YOffset); - return CollisionCalculator.GetCalculatedCollisionBetween(source, destination, ActiveCollisionMeshes); + var navMeshTransformerSrc = new NavMeshTransform(source.Region.Id, srcOffset); + if (!NavMeshManager.ResolveCellAndHeight(navMeshTransformerSrc)) + return false; + + var navMeshTransformerDest = new NavMeshTransform(destination.Region.Id, destOffset); + if (!NavMeshManager.ResolveCellAndHeight(navMeshTransformerDest)) + return false; + + var hasCollision = !NavMeshManager.Raycast(navMeshTransformerSrc, navMeshTransformerDest, NavMeshRaycastType.Attack); + + return hasCollision; } + + public static NavMesh[] GetActiveMeshes() => _loadedNavMeshes; } \ No newline at end of file diff --git a/Library/RSBot.Core/Game.cs b/Library/RSBot.Core/Game.cs index ebd3c059..2f02fb3b 100644 --- a/Library/RSBot.Core/Game.cs +++ b/Library/RSBot.Core/Game.cs @@ -8,6 +8,7 @@ using RSBot.Core.Objects.Party; using RSBot.Core.Objects.Spawn; using RSBot.FileSystem; +using RSBot.NavMeshApi; namespace RSBot.Core; @@ -34,6 +35,23 @@ public class Game /// public static IFileSystem MediaPk2 { get; set; } + /// + /// Gets or sets the Data.pk2 reader. + /// + /// + /// The PK2 reader. + /// + public static IFileSystem DataPk2 { get; set; } + + + /// + /// Gets or sets the Map.pk2 reader. + /// + /// + /// The PK2 reader. + /// + public static IFileSystem MapPk2 { get; set; } + /// /// Gets or sets the reference manager /// @@ -145,7 +163,11 @@ public static bool InitializeArchiveFiles() try { MediaPk2 = new PackFileSystem(Path.Combine(directory, "media.pk2"), pk2Key); + DataPk2 = new PackFileSystem(Path.Combine(directory, "data.pk2"), pk2Key); + MapPk2 = new PackFileSystem(Path.Combine(directory, "map.pk2"), pk2Key); + + NavMeshManager.Initialize(DataPk2, MapPk2); return true; } catch (Exception ex) diff --git a/Library/RSBot.Core/Objects/Position.cs b/Library/RSBot.Core/Objects/Position.cs index 00d86160..5004e73b 100644 --- a/Library/RSBot.Core/Objects/Position.cs +++ b/Library/RSBot.Core/Objects/Position.cs @@ -26,17 +26,17 @@ public float XOffset if (Region.IsDungeon) return; - while (_XOffset < 0) - { - _XOffset += 1920; - Region.X -= 1; - } - - while (_XOffset > 1920) - { - _XOffset -= 1920; - Region.X += 1; - } + //while (_XOffset < 0) + //{ + // _XOffset += 1920; + // Region.X -= 1; + //} + + //while (_XOffset > 1920) + //{ + // _XOffset -= 1920; + // Region.X += 1; + //} } } @@ -50,20 +50,20 @@ public float YOffset { _YOffset = value; - if (Region.IsDungeon) - return; + //if (Region.IsDungeon) + // return; + + //while (_YOffset < 0) + //{ + // _YOffset += 1920; + // Region.Y -= 1; + //} - while (_YOffset < 0) - { - _YOffset += 1920; - Region.Y -= 1; - } - - while (_YOffset > 1920) - { - _YOffset -= 1920; - Region.Y += 1; - } + //while (_YOffset > 1920) + //{ + // _YOffset -= 1920; + // Region.Y += 1; + //} } } diff --git a/Library/RSBot.Core/Objects/State.cs b/Library/RSBot.Core/Objects/State.cs index 8617ca4d..cddb7e33 100644 --- a/Library/RSBot.Core/Objects/State.cs +++ b/Library/RSBot.Core/Objects/State.cs @@ -191,8 +191,6 @@ public bool TryRemoveActiveBuff(uint token, out SkillInfo removedBuff) /// Checks two active DoTs. /// /// - public bool HasTwoDots() - { - return ActiveBuffs.Where(b => b.IsDot).Count() >= 2; - } + public bool HasTwoDots() => ActiveBuffs.Count(b => b.IsDot) >= 2; + } \ No newline at end of file diff --git a/Library/RSBot.Core/RSBot.Core.csproj b/Library/RSBot.Core/RSBot.Core.csproj index 3ce065fc..9647c08f 100644 --- a/Library/RSBot.Core/RSBot.Core.csproj +++ b/Library/RSBot.Core/RSBot.Core.csproj @@ -16,6 +16,7 @@ + diff --git a/RSBot.NavMeshApi/CardinalDirection.cs b/Library/RSBot.NavMeshApi/CardinalDirection.cs similarity index 81% rename from RSBot.NavMeshApi/CardinalDirection.cs rename to Library/RSBot.NavMeshApi/CardinalDirection.cs index af885a2f..d5a425ec 100644 --- a/RSBot.NavMeshApi/CardinalDirection.cs +++ b/Library/RSBot.NavMeshApi/CardinalDirection.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; [Flags] public enum CardinalDirection diff --git a/RSBot.NavMeshApi/Cells/NavMeshCell.cs b/Library/RSBot.NavMeshApi/Cells/NavMeshCell.cs similarity index 86% rename from RSBot.NavMeshApi/Cells/NavMeshCell.cs rename to Library/RSBot.NavMeshApi/Cells/NavMeshCell.cs index 2ee83f7c..298c1690 100644 --- a/RSBot.NavMeshApi/Cells/NavMeshCell.cs +++ b/Library/RSBot.NavMeshApi/Cells/NavMeshCell.cs @@ -1,9 +1,8 @@ -using NavMeshApi.Edges; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Edges; -namespace NavMeshApi.Cells; +namespace RSBot.NavMeshApi.Cells; [DebuggerDisplay("NavMeshCell: {Index}")] public abstract class NavMeshCell diff --git a/RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs b/Library/RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs similarity index 87% rename from RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs rename to Library/RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs index 6fc3272b..d56bd2a1 100644 --- a/RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs +++ b/Library/RSBot.NavMeshApi/Cells/NavMeshCellQuad.cs @@ -1,11 +1,10 @@ -using NavMeshApi.Edges; -using NavMeshApi.Mathematics; -using NavMeshApi.Terrain; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Terrain; -namespace NavMeshApi.Cells; +namespace RSBot.NavMeshApi.Cells; [DebuggerDisplay("NavMeshCellQuad: {Index}")] public class NavMeshCellQuad : NavMeshCell diff --git a/RSBot.NavMeshApi/Cells/NavMeshCellTri.cs b/Library/RSBot.NavMeshApi/Cells/NavMeshCellTri.cs similarity index 85% rename from RSBot.NavMeshApi/Cells/NavMeshCellTri.cs rename to Library/RSBot.NavMeshApi/Cells/NavMeshCellTri.cs index a7495786..0be786d0 100644 --- a/RSBot.NavMeshApi/Cells/NavMeshCellTri.cs +++ b/Library/RSBot.NavMeshApi/Cells/NavMeshCellTri.cs @@ -1,12 +1,11 @@ -using NavMeshApi.Edges; -using NavMeshApi.Extensions; -using NavMeshApi.Mathematics; -using NavMeshApi.Object; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Extensions; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Object; -namespace NavMeshApi.Cells; +namespace RSBot.NavMeshApi.Cells; [DebuggerDisplay("NavMeshCellTri: {Index}")] public class NavMeshCellTri : NavMeshCell diff --git a/RSBot.NavMeshApi/Dungeon/DungeonColObj.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonColObj.cs similarity index 59% rename from RSBot.NavMeshApi/Dungeon/DungeonColObj.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonColObj.cs index 06af18c3..ca30bf8e 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonColObj.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonColObj.cs @@ -1,6 +1,6 @@ -using NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class DungeonColObj { diff --git a/RSBot.NavMeshApi/Dungeon/DungeonID.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonID.cs similarity index 95% rename from RSBot.NavMeshApi/Dungeon/DungeonID.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonID.cs index 148b2e48..5ea28ba4 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonID.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonID.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; [Serializable] public enum DungeonID : byte diff --git a/RSBot.NavMeshApi/Dungeon/DungeonInfo.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonInfo.cs similarity index 93% rename from RSBot.NavMeshApi/Dungeon/DungeonInfo.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonInfo.cs index 78f754ed..59a4442c 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonInfo.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonInfo.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Mathematics; +using System.Text.RegularExpressions; +using RSBot.NavMeshApi.Mathematics; -using System.Text.RegularExpressions; - -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class DungeonInfo { diff --git a/RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs similarity index 88% rename from RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs index 27615aec..9c0f6b33 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxel.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Mathematics; +using System.Numerics; +using RSBot.NavMeshApi.Mathematics; -using System.Numerics; - -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class DungeonVoxel { diff --git a/RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs similarity index 96% rename from RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs index 682005e9..aeb05458 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelGrid.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class DungeonVoxelGrid { diff --git a/RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs similarity index 98% rename from RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs rename to Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs index ca2db41f..f2404759 100644 --- a/RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/DungeonVoxelID.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public struct DungeonVoxelID : IEquatable { diff --git a/RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs b/Library/RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs similarity index 98% rename from RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs rename to Library/RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs index b1d425a2..79e565cb 100644 --- a/RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/NavMeshDungeon.cs @@ -1,13 +1,11 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Extensions; - -using NavMeshApi.Mathematics; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Extensions; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class NavMeshDungeon : NavMesh { diff --git a/RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs b/Library/RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs similarity index 88% rename from RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs rename to Library/RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs index ec7a9a18..3159f6af 100644 --- a/RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs +++ b/Library/RSBot.NavMeshApi/Dungeon/NavMeshInstBlock.cs @@ -1,6 +1,6 @@ -using NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi.Dungeon; +namespace RSBot.NavMeshApi.Dungeon; public class NavMeshInstBlock : NavMeshInst { diff --git a/RSBot.NavMeshApi/Edges/NavMeshEdge.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshEdge.cs similarity index 95% rename from RSBot.NavMeshApi/Edges/NavMeshEdge.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshEdge.cs index 94bd7708..aa170942 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshEdge.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshEdge.cs @@ -1,10 +1,9 @@ -using NavMeshApi.Cells; -using NavMeshApi.Mathematics; -using NavMeshApi.Object; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Object; -using System.Numerics; - -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; [System.Diagnostics.DebuggerDisplay("{Index} = {Flag} ({SrcCellIndex} [{SrcDirection}] -> {DstCellIndex} [{DstDirection}])")] public abstract class NavMeshEdge diff --git a/RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs similarity index 75% rename from RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs index 3a3b6c20..3a0ac845 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeDirection.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; public enum NavMeshCellSide : sbyte { diff --git a/RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs similarity index 95% rename from RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs index c2cd695b..266cfff5 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeFlag.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; [Flags] public enum NavMeshEdgeFlag diff --git a/RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs similarity index 93% rename from RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs index b7a8a034..2d2e9fef 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeGlobal.cs @@ -1,6 +1,6 @@ -using NavMeshApi.Terrain; +using RSBot.NavMeshApi.Terrain; -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; public class NavMeshEdgeGlobal : NavMeshEdge { diff --git a/RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs similarity index 96% rename from RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs index 503868be..6db9057c 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshEdgeInternal.cs @@ -1,7 +1,7 @@  using System.Diagnostics; -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; public class NavMeshEdgeInternal : NavMeshEdge { diff --git a/RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs b/Library/RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs similarity index 87% rename from RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs rename to Library/RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs index bb4e4e15..f0ae9053 100644 --- a/RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs +++ b/Library/RSBot.NavMeshApi/Edges/NavMeshLinkEdge.cs @@ -1,6 +1,6 @@ -using NavMeshApi.Cells; +using RSBot.NavMeshApi.Cells; -namespace NavMeshApi.Edges; +namespace RSBot.NavMeshApi.Edges; public class NavMeshLinkEdge { diff --git a/RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs b/Library/RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs similarity index 89% rename from RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs rename to Library/RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs index 03d083cd..607e83c0 100644 --- a/RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs +++ b/Library/RSBot.NavMeshApi/Extensions/Matrix4x4Extensions.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Mathematics; +using System.Numerics; +using RSBot.NavMeshApi.Mathematics; -using System.Numerics; - -namespace NavMeshApi.Extensions; +namespace RSBot.NavMeshApi.Extensions; public static class Matrix4x4Extensions { diff --git a/RSBot.NavMeshApi/Extensions/Vector2Extensions.cs b/Library/RSBot.NavMeshApi/Extensions/Vector2Extensions.cs similarity index 91% rename from RSBot.NavMeshApi/Extensions/Vector2Extensions.cs rename to Library/RSBot.NavMeshApi/Extensions/Vector2Extensions.cs index f650d565..5a807cb2 100644 --- a/RSBot.NavMeshApi/Extensions/Vector2Extensions.cs +++ b/Library/RSBot.NavMeshApi/Extensions/Vector2Extensions.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace NavMeshApi.Extensions; +namespace RSBot.NavMeshApi.Extensions; public static class VectorExtensions { diff --git a/RSBot.NavMeshApi/Helper/MathHelper.cs b/Library/RSBot.NavMeshApi/Helper/MathHelper.cs similarity index 89% rename from RSBot.NavMeshApi/Helper/MathHelper.cs rename to Library/RSBot.NavMeshApi/Helper/MathHelper.cs index 0170087d..40ae7462 100644 --- a/RSBot.NavMeshApi/Helper/MathHelper.cs +++ b/Library/RSBot.NavMeshApi/Helper/MathHelper.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; -namespace NavMeshApi.Helper; +namespace RSBot.NavMeshApi.Helper; internal static class MathHelper { @@ -18,7 +18,7 @@ internal static class MathHelper [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Clamp(this float value, float min, float max) { - Debug.Assert(max > min, $"min({min:0.000}) exceeded max({max:0.000}) value"); + //Debug.Assert(max > min, $"min({min:0.000}) exceeded max({max:0.000}) value"); return value < min ? min : value > max ? max : value; } diff --git a/RSBot.NavMeshApi/Helper/NavMeshHelper.cs b/Library/RSBot.NavMeshApi/Helper/NavMeshHelper.cs similarity index 97% rename from RSBot.NavMeshApi/Helper/NavMeshHelper.cs rename to Library/RSBot.NavMeshApi/Helper/NavMeshHelper.cs index 19fdf4f5..39bfb6cb 100644 --- a/RSBot.NavMeshApi/Helper/NavMeshHelper.cs +++ b/Library/RSBot.NavMeshApi/Helper/NavMeshHelper.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace NavMeshApi.Helper; +namespace RSBot.NavMeshApi.Helper; public static class NavMeshHelper { diff --git a/RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs b/Library/RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs similarity index 95% rename from RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs rename to Library/RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs index 0beefb4f..bfd19ebd 100644 --- a/RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/BoundingBoxF.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public readonly struct BoundingBoxF { diff --git a/RSBot.NavMeshApi/Mathematics/CircleF.cs b/Library/RSBot.NavMeshApi/Mathematics/CircleF.cs similarity index 96% rename from RSBot.NavMeshApi/Mathematics/CircleF.cs rename to Library/RSBot.NavMeshApi/Mathematics/CircleF.cs index 72c72668..d977f51c 100644 --- a/RSBot.NavMeshApi/Mathematics/CircleF.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/CircleF.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Extensions; +using System.Numerics; +using RSBot.NavMeshApi.Extensions; -using System.Numerics; - -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public struct CircleF { diff --git a/RSBot.NavMeshApi/Mathematics/LineF.cs b/Library/RSBot.NavMeshApi/Mathematics/LineF.cs similarity index 98% rename from RSBot.NavMeshApi/Mathematics/LineF.cs rename to Library/RSBot.NavMeshApi/Mathematics/LineF.cs index ec94de08..1b9fda02 100644 --- a/RSBot.NavMeshApi/Mathematics/LineF.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/LineF.cs @@ -1,9 +1,8 @@ -using NavMeshApi.Extensions; -using NavMeshApi.Helper; +using System.Numerics; +using RSBot.NavMeshApi.Extensions; +using RSBot.NavMeshApi.Helper; -using System.Numerics; - -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public readonly struct LineF { diff --git a/RSBot.NavMeshApi/Mathematics/RectangleF.cs b/Library/RSBot.NavMeshApi/Mathematics/RectangleF.cs similarity index 97% rename from RSBot.NavMeshApi/Mathematics/RectangleF.cs rename to Library/RSBot.NavMeshApi/Mathematics/RectangleF.cs index c5505d65..463c83d5 100644 --- a/RSBot.NavMeshApi/Mathematics/RectangleF.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/RectangleF.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Extensions; +using System.Numerics; +using RSBot.NavMeshApi.Extensions; -using System.Numerics; - -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public struct RectangleF { diff --git a/RSBot.NavMeshApi/Mathematics/Region.cs b/Library/RSBot.NavMeshApi/Mathematics/Region.cs similarity index 98% rename from RSBot.NavMeshApi/Mathematics/Region.cs rename to Library/RSBot.NavMeshApi/Mathematics/Region.cs index ea2f76df..82a2e4b1 100644 --- a/RSBot.NavMeshApi/Mathematics/Region.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/Region.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.Numerics; -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; [DebuggerDisplay("{_value} [{this.X}x{this.Z}]")] public struct Region : IEquatable diff --git a/RSBot.NavMeshApi/Mathematics/RegionPosition.cs b/Library/RSBot.NavMeshApi/Mathematics/RegionPosition.cs similarity index 95% rename from RSBot.NavMeshApi/Mathematics/RegionPosition.cs rename to Library/RSBot.NavMeshApi/Mathematics/RegionPosition.cs index 45c4423e..9d69704d 100644 --- a/RSBot.NavMeshApi/Mathematics/RegionPosition.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/RegionPosition.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Helper; +using System.Numerics; +using RSBot.NavMeshApi.Helper; -using System.Numerics; - -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public struct RegionPosition { diff --git a/RSBot.NavMeshApi/Mathematics/TriangleF.cs b/Library/RSBot.NavMeshApi/Mathematics/TriangleF.cs similarity index 97% rename from RSBot.NavMeshApi/Mathematics/TriangleF.cs rename to Library/RSBot.NavMeshApi/Mathematics/TriangleF.cs index 3f1e3204..a981588b 100644 --- a/RSBot.NavMeshApi/Mathematics/TriangleF.cs +++ b/Library/RSBot.NavMeshApi/Mathematics/TriangleF.cs @@ -1,8 +1,7 @@ -using NavMeshApi.Extensions; +using System.Numerics; +using RSBot.NavMeshApi.Extensions; -using System.Numerics; - -namespace NavMeshApi.Mathematics; +namespace RSBot.NavMeshApi.Mathematics; public struct TriangleF { diff --git a/RSBot.NavMeshApi/NavMesh.cs b/Library/RSBot.NavMeshApi/NavMesh.cs similarity index 85% rename from RSBot.NavMeshApi/NavMesh.cs rename to Library/RSBot.NavMeshApi/NavMesh.cs index 7ab29062..ec98444a 100644 --- a/RSBot.NavMeshApi/NavMesh.cs +++ b/Library/RSBot.NavMeshApi/NavMesh.cs @@ -1,9 +1,8 @@ -using NavMeshApi.Cells; -using NavMeshApi.Mathematics; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Mathematics; -using System.Numerics; - -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public abstract class NavMesh { diff --git a/RSBot.NavMeshApi/NavMeshHitResult.cs b/Library/RSBot.NavMeshApi/NavMeshHitResult.cs similarity index 78% rename from RSBot.NavMeshApi/NavMeshHitResult.cs rename to Library/RSBot.NavMeshApi/NavMeshHitResult.cs index ba6f8de1..b127ca0a 100644 --- a/RSBot.NavMeshApi/NavMeshHitResult.cs +++ b/Library/RSBot.NavMeshApi/NavMeshHitResult.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; [Flags] public enum NavMeshHitResult diff --git a/RSBot.NavMeshApi/NavMeshInst.cs b/Library/RSBot.NavMeshApi/NavMeshInst.cs similarity index 88% rename from RSBot.NavMeshApi/NavMeshInst.cs rename to Library/RSBot.NavMeshApi/NavMeshInst.cs index e4d9dedb..4c1ce53c 100644 --- a/RSBot.NavMeshApi/NavMeshInst.cs +++ b/Library/RSBot.NavMeshApi/NavMeshInst.cs @@ -1,11 +1,10 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Mathematics; -using NavMeshApi.Object; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Object; -using System.Numerics; - -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public abstract class NavMeshInst { diff --git a/RSBot.NavMeshApi/NavMeshManager.cs b/Library/RSBot.NavMeshApi/NavMeshManager.cs similarity index 83% rename from RSBot.NavMeshApi/NavMeshManager.cs rename to Library/RSBot.NavMeshApi/NavMeshManager.cs index a6d55c2f..a9e03a77 100644 --- a/RSBot.NavMeshApi/NavMeshManager.cs +++ b/Library/RSBot.NavMeshApi/NavMeshManager.cs @@ -1,18 +1,19 @@ -using NavMeshApi.Dungeon; -using NavMeshApi.Mathematics; -using NavMeshApi.Object; -using NavMeshApi.Terrain; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.FileSystem; +using RSBot.NavMeshApi.Dungeon; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Object; +using RSBot.NavMeshApi.Terrain; -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public static class NavMeshManager { private const int NORMAL_CACHE_SIZE = 256; - private static string _path; + private static IFileSystem _dataFileSystem; + private static IFileSystem _mapFileSystem; public static ObjectIndex ObjectIndex { get; } = new ObjectIndex(); public static RegionManager RegionManager { get; } = new RegionManager(); @@ -25,15 +26,14 @@ public static class NavMeshManager private static readonly Dictionary _objectCache = new Dictionary(); private static readonly Dictionary _dungeonCache = new Dictionary(); - public static void Initialize(string path) + public static void Initialize(IFileSystem _dataFileSystem, IFileSystem _mapFileSystem) { - _path = path; + NavMeshManager._dataFileSystem = _dataFileSystem; + NavMeshManager._mapFileSystem = _mapFileSystem; - LoadMapInfo("NavMesh/MapInfo.mfo"); - LoadObjectIndex("NavMesh/Object.ifo"); - LoadObjectExtensions("NavMesh/ObjExt.ifo"); // DunBlock extensions - //LoadTextureIndex("NavMesh/Tile2D.ifo"); - LoadDungeonInfo("Dungeon/DungeonInfo.txt"); + LoadMapInfo("mapinfo.mfo"); + LoadObjectIndex("object.ifo"); + LoadDungeonInfo("dungeon\\dungeoninfo.txt"); //LoadObjectString("NavMesh/ObjectString.ifo"); // EventZone data //_terrainCache.EnsureCapacity(RegionManager.ActiveRegions); @@ -45,6 +45,10 @@ public static void Initialize(string path) NormalCache[i].Y = -MathF.Sin(i * TwoPiOverANGLE_CACHE_SIZE); NormalCache[i].X = MathF.Cos(i * TwoPiOverANGLE_CACHE_SIZE); } + + Debug.WriteLine("Initialized NavMeshManager!"); + Debug.WriteLine($"Mapinfo.mfo: {RegionManager.ActiveRegions} active regions"); + Debug.WriteLine($"Object.ifo: {ObjectIndex.Count()} objects"); } public static bool Raycast(NavMeshTransform src, NavMeshTransform dst, NavMeshRaycastType type) @@ -124,20 +128,20 @@ public static bool ResolveCellAndHeight(NavMeshTransform transform) private static void LoadMapInfo(string fileName) { - using (var stream = File.OpenRead(Path.Combine(_path, fileName))) - RegionManager.Load(stream); + using var stream = _mapFileSystem.OpenRead(fileName).GetStream(); + RegionManager.Load(stream); } private static void LoadDungeonInfo(string fileName) { - using (var stream = File.OpenRead(Path.Combine(_path, fileName))) - DungeonInfo.Load(stream); + using var stream = _dataFileSystem.OpenRead(fileName).GetStream(); + DungeonInfo.Load(stream); } private static void LoadObjectIndex(string fileName) { - using (var stream = File.OpenRead(Path.Combine(_path, fileName))) - ObjectIndex.Load(stream); + using var stream = _mapFileSystem.OpenRead(fileName).GetStream(); + ObjectIndex.Load(stream); //foreach (var obj in ObjectIndex) //{ @@ -154,10 +158,6 @@ private static void LoadObjectIndex(string fileName) //} } - private static void LoadObjectExtensions(string fileName) - { - } - public static NavMeshObj LoadNavMeshObj(string fileName) { switch (fileName[fileName.Length - 1]) @@ -172,12 +172,11 @@ public static NavMeshObj LoadNavMeshObj(string fileName) public static NavMeshTerrain LoadNavMeshTerrain(string fileName, Region region) { var terrain = new NavMeshTerrain(region); - var path = Path.Combine(_path, fileName); - if (!File.Exists(path)) + if (!_dataFileSystem.TryGetFile(fileName, out var file)) return null; - using (var stream = File.OpenRead(path)) - terrain.Load(stream); + using var stream = file.OpenRead().GetStream(); + terrain.Load(stream); return terrain; } @@ -185,12 +184,12 @@ public static NavMeshTerrain LoadNavMeshTerrain(string fileName, Region region) public static NavMeshDungeon LoadNavMeshDungeon(string fileName, Region region) { var dungeon = new NavMeshDungeon(region); - var path = Path.Combine(_path, fileName); - if (!File.Exists(path)) + + if (!_dataFileSystem.TryGetFile(fileName, out var file)) return null; - using (var stream = File.OpenRead(path)) - dungeon.Load(stream); + using var stream = file.OpenRead().GetStream(); + dungeon.Load(stream); return dungeon; } @@ -198,12 +197,12 @@ public static NavMeshDungeon LoadNavMeshDungeon(string fileName, Region region) public static NavMeshObj LoadNavMeshObjFromPrimMesh(string fileName) { var obj = new NavMeshObj(); - var path = Path.Combine(_path, fileName); - if (!File.Exists(path)) + if (!_dataFileSystem.TryGetFile(fileName, out var file)) return null; - using (var stream = File.OpenRead(path)) - obj.Load(stream); + using var stream = file.OpenRead().GetStream(); + + obj.Load(stream); //foreach (var edge in obj.GlobalEdges) // edge.Link(); @@ -216,11 +215,11 @@ public static NavMeshObj LoadNavMeshObjFromPrimMesh(string fileName) public static NavMeshObj LoadNavMeshObjFromResource(string fileName) { - var path = Path.Combine(_path, fileName); - if (!File.Exists(path)) + if (!_dataFileSystem.TryGetFile(fileName, out var file)) return null; - using (var stream = File.OpenRead(path)) + using var stream = file.OpenRead().GetStream(); + using (var reader = new NavMeshReader(stream)) { var signature = reader.ReadString(12); @@ -259,11 +258,10 @@ public static NavMeshObj LoadNavMeshObjFromResource(string fileName) public static NavMeshObj LoadNavMeshObjFromCompound(string fileName) { - string path = Path.Combine(_path, fileName); - if (!File.Exists(path)) + if (!_dataFileSystem.TryGetFile(fileName, out var file)) return null; - using (var stream = File.OpenRead(path)) + using var stream = file.OpenRead().GetStream(); using (var reader = new NavMeshReader(stream)) { var signature = reader.ReadString(12); @@ -334,7 +332,7 @@ public static bool TryGetNavMeshTerrain(Region region, out NavMeshTerrain terrai if (!_terrainCache.TryGetValue(region, out terrain)) { - terrain = LoadNavMeshTerrain($"NavMesh/nv_{(ushort)region:X4}.nvm", region); + terrain = LoadNavMeshTerrain($"navmesh\\nv_{(ushort)region:X4}.nvm", region); _regionCache[region] = terrain; _terrainCache[region] = terrain; } diff --git a/RSBot.NavMeshApi/NavMeshRay.cs b/Library/RSBot.NavMeshApi/NavMeshRay.cs similarity index 85% rename from RSBot.NavMeshApi/NavMeshRay.cs rename to Library/RSBot.NavMeshApi/NavMeshRay.cs index 328e0023..0f8b39b6 100644 --- a/RSBot.NavMeshApi/NavMeshRay.cs +++ b/Library/RSBot.NavMeshApi/NavMeshRay.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public struct NavMeshRay { diff --git a/RSBot.NavMeshApi/NavMeshRaycastHit.cs b/Library/RSBot.NavMeshApi/NavMeshRaycastHit.cs similarity index 75% rename from RSBot.NavMeshApi/NavMeshRaycastHit.cs rename to Library/RSBot.NavMeshApi/NavMeshRaycastHit.cs index f895ba5c..5b02adcc 100644 --- a/RSBot.NavMeshApi/NavMeshRaycastHit.cs +++ b/Library/RSBot.NavMeshApi/NavMeshRaycastHit.cs @@ -1,10 +1,9 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Mathematics; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Mathematics; -using System.Numerics; - -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class NavMeshRaycastHit { diff --git a/RSBot.NavMeshApi/NavMeshRaycastResult.cs b/Library/RSBot.NavMeshApi/NavMeshRaycastResult.cs similarity index 72% rename from RSBot.NavMeshApi/NavMeshRaycastResult.cs rename to Library/RSBot.NavMeshApi/NavMeshRaycastResult.cs index 13670610..d580e8c8 100644 --- a/RSBot.NavMeshApi/NavMeshRaycastResult.cs +++ b/Library/RSBot.NavMeshApi/NavMeshRaycastResult.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public enum NavMeshRaycastResult { diff --git a/RSBot.NavMeshApi/NavMeshRaycastType.cs b/Library/RSBot.NavMeshApi/NavMeshRaycastType.cs similarity index 85% rename from RSBot.NavMeshApi/NavMeshRaycastType.cs rename to Library/RSBot.NavMeshApi/NavMeshRaycastType.cs index 5470b80c..23af5da2 100644 --- a/RSBot.NavMeshApi/NavMeshRaycastType.cs +++ b/Library/RSBot.NavMeshApi/NavMeshRaycastType.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public enum NavMeshRaycastType { diff --git a/RSBot.NavMeshApi/NavMeshReader.cs b/Library/RSBot.NavMeshApi/NavMeshReader.cs similarity index 95% rename from RSBot.NavMeshApi/NavMeshReader.cs rename to Library/RSBot.NavMeshApi/NavMeshReader.cs index f95efcd3..e4f2a81f 100644 --- a/RSBot.NavMeshApi/NavMeshReader.cs +++ b/Library/RSBot.NavMeshApi/NavMeshReader.cs @@ -1,10 +1,9 @@ -using NavMeshApi.Mathematics; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; using System.Text; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class NavMeshReader : BinaryReader { diff --git a/RSBot.NavMeshApi/NavMeshTransform.cs b/Library/RSBot.NavMeshApi/NavMeshTransform.cs similarity index 95% rename from RSBot.NavMeshApi/NavMeshTransform.cs rename to Library/RSBot.NavMeshApi/NavMeshTransform.cs index ebdc56dc..e632d339 100644 --- a/RSBot.NavMeshApi/NavMeshTransform.cs +++ b/Library/RSBot.NavMeshApi/NavMeshTransform.cs @@ -1,11 +1,9 @@ -using NavMeshApi.Cells; -using NavMeshApi.Helper; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Helper; +using RSBot.NavMeshApi.Mathematics; -using NavMeshApi.Mathematics; - -using System.Numerics; - -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class NavMeshTransform { diff --git a/RSBot.NavMeshApi/NavMeshType.cs b/Library/RSBot.NavMeshApi/NavMeshType.cs similarity index 76% rename from RSBot.NavMeshApi/NavMeshType.cs rename to Library/RSBot.NavMeshApi/NavMeshType.cs index 9888bd15..b7d71ac3 100644 --- a/RSBot.NavMeshApi/NavMeshType.cs +++ b/Library/RSBot.NavMeshApi/NavMeshType.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public enum NavMeshType : byte { diff --git a/RSBot.NavMeshApi/NavMeshVertex.cs b/Library/RSBot.NavMeshApi/NavMeshVertex.cs similarity index 86% rename from RSBot.NavMeshApi/NavMeshVertex.cs rename to Library/RSBot.NavMeshApi/NavMeshVertex.cs index 7ce4c109..d28e3947 100644 --- a/RSBot.NavMeshApi/NavMeshVertex.cs +++ b/Library/RSBot.NavMeshApi/NavMeshVertex.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class NavMeshVertex { diff --git a/RSBot.NavMeshApi/Object/NavMeshEventZone.cs b/Library/RSBot.NavMeshApi/Object/NavMeshEventZone.cs similarity index 98% rename from RSBot.NavMeshApi/Object/NavMeshEventZone.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshEventZone.cs index 9a15f7cd..9e75bb51 100644 --- a/RSBot.NavMeshApi/Object/NavMeshEventZone.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshEventZone.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; public struct NavMeshEventZone : IEquatable { diff --git a/RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs b/Library/RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs similarity index 76% rename from RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs index 7dd37803..19e6f90d 100644 --- a/RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshEventZoneFlag.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; [Flags] public enum NavMeshEventZoneFlag diff --git a/RSBot.NavMeshApi/Object/NavMeshObj.cs b/Library/RSBot.NavMeshApi/Object/NavMeshObj.cs similarity index 98% rename from RSBot.NavMeshApi/Object/NavMeshObj.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshObj.cs index fbf31dda..dc1124c2 100644 --- a/RSBot.NavMeshApi/Object/NavMeshObj.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshObj.cs @@ -1,13 +1,12 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Extensions; -using NavMeshApi.Mathematics; -using NavMeshApi.Terrain; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Extensions; +using RSBot.NavMeshApi.Mathematics; +using RSBot.NavMeshApi.Terrain; -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; public class NavMeshObj : NavMesh { diff --git a/RSBot.NavMeshApi/Object/NavMeshObjGrid.cs b/Library/RSBot.NavMeshApi/Object/NavMeshObjGrid.cs similarity index 94% rename from RSBot.NavMeshApi/Object/NavMeshObjGrid.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshObjGrid.cs index 49e0ada8..09b69f15 100644 --- a/RSBot.NavMeshApi/Object/NavMeshObjGrid.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshObjGrid.cs @@ -1,11 +1,9 @@ -using NavMeshApi.Helper; - -using NavMeshApi.Mathematics; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Helper; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; public class NavMeshObjGrid { diff --git a/RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs b/Library/RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs similarity index 90% rename from RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs index 28591e79..864717cf 100644 --- a/RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshObjGridTile.cs @@ -1,10 +1,9 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Mathematics; +using System.Numerics; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Mathematics; -using System.Numerics; - -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; public class NavMeshObjGridTile { diff --git a/RSBot.NavMeshApi/Object/NavMeshStructOption.cs b/Library/RSBot.NavMeshApi/Object/NavMeshStructOption.cs similarity index 73% rename from RSBot.NavMeshApi/Object/NavMeshStructOption.cs rename to Library/RSBot.NavMeshApi/Object/NavMeshStructOption.cs index 540fd234..7408ad48 100644 --- a/RSBot.NavMeshApi/Object/NavMeshStructOption.cs +++ b/Library/RSBot.NavMeshApi/Object/NavMeshStructOption.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Object; +namespace RSBot.NavMeshApi.Object; [Flags] public enum NavMeshStructOption : int diff --git a/RSBot.NavMeshApi/ObjectIndex.cs b/Library/RSBot.NavMeshApi/ObjectIndex.cs similarity index 98% rename from RSBot.NavMeshApi/ObjectIndex.cs rename to Library/RSBot.NavMeshApi/ObjectIndex.cs index 7b2f5c87..80e5f4e0 100644 --- a/RSBot.NavMeshApi/ObjectIndex.cs +++ b/Library/RSBot.NavMeshApi/ObjectIndex.cs @@ -2,7 +2,7 @@ using System.Globalization; using System.Text.RegularExpressions; -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class ObjectIndex : IEnumerable { diff --git a/RSBot.NavMeshApi/ObjectIndexEntry.cs b/Library/RSBot.NavMeshApi/ObjectIndexEntry.cs similarity index 87% rename from RSBot.NavMeshApi/ObjectIndexEntry.cs rename to Library/RSBot.NavMeshApi/ObjectIndexEntry.cs index 97bb982f..ca21179f 100644 --- a/RSBot.NavMeshApi/ObjectIndexEntry.cs +++ b/Library/RSBot.NavMeshApi/ObjectIndexEntry.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class ObjectIndexEntry { diff --git a/Library/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj b/Library/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj new file mode 100644 index 00000000..2b8d1a96 --- /dev/null +++ b/Library/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/RSBot.NavMeshApi/RegionManager.cs b/Library/RSBot.NavMeshApi/RegionManager.cs similarity index 90% rename from RSBot.NavMeshApi/RegionManager.cs rename to Library/RSBot.NavMeshApi/RegionManager.cs index 52b10841..b9645a88 100644 --- a/RSBot.NavMeshApi/RegionManager.cs +++ b/Library/RSBot.NavMeshApi/RegionManager.cs @@ -1,6 +1,7 @@ -using NavMeshApi.Mathematics; +using System.Diagnostics; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi; +namespace RSBot.NavMeshApi; public class RegionManager { @@ -28,7 +29,7 @@ public void Load(Stream stream) this.MapWidth = reader.ReadInt16(); this.MapLength = reader.ReadInt16(); - Console.WriteLine($"RegionManager: Map project resolution {this.MapWidth}x{this.MapLength}"); + Debug.WriteLine($"RegionManager: Map project resolution {this.MapWidth}x{this.MapLength}"); this.Short2 = reader.ReadInt16(); this.Short3 = reader.ReadInt16(); diff --git a/RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs similarity index 93% rename from RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs index 9e711c1b..2aeab33d 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshInstObj.cs @@ -1,10 +1,9 @@ -using NavMeshApi.Edges; -using NavMeshApi.Object; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Object; -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; public class NavMeshInstObj : NavMeshInst { diff --git a/RSBot.NavMeshApi/Terrain/NavMeshPlane.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshPlane.cs similarity index 85% rename from RSBot.NavMeshApi/Terrain/NavMeshPlane.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshPlane.cs index 3b2f2d06..eea22210 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshPlane.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshPlane.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; public struct NavMeshPlane { diff --git a/RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs similarity index 70% rename from RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs index bb3d7251..c2a0d409 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshPlaneType.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; [Flags] public enum NavMeshPlaneType : byte diff --git a/RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs similarity index 98% rename from RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs index 0817309c..a22638d3 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshTerrain.cs @@ -1,14 +1,12 @@ -using NavMeshApi.Cells; -using NavMeshApi.Edges; -using NavMeshApi.Extensions; - -using NavMeshApi.Mathematics; - -using System.Diagnostics; +using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; +using RSBot.NavMeshApi.Cells; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Extensions; +using RSBot.NavMeshApi.Mathematics; -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; public class NavMeshTerrain : NavMesh { diff --git a/RSBot.NavMeshApi/Terrain/NavMeshTile.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshTile.cs similarity index 87% rename from RSBot.NavMeshApi/Terrain/NavMeshTile.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshTile.cs index e8137475..043c310f 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshTile.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshTile.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; public struct NavMeshTile { diff --git a/RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs b/Library/RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs similarity index 89% rename from RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs rename to Library/RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs index 6dbaf695..d9d2a703 100644 --- a/RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs +++ b/Library/RSBot.NavMeshApi/Terrain/NavMeshTileFlag.cs @@ -1,4 +1,4 @@ -namespace NavMeshApi.Terrain; +namespace RSBot.NavMeshApi.Terrain; [Flags] diff --git a/Plugins/RSBot.Map/Renderer/NavMeshRenderer.cs b/Plugins/RSBot.Map/Renderer/NavMeshRenderer.cs new file mode 100644 index 00000000..6e7cf99a --- /dev/null +++ b/Plugins/RSBot.Map/Renderer/NavMeshRenderer.cs @@ -0,0 +1,162 @@ +using System.Drawing; +using System.Numerics; +using RSBot.Core; +using RSBot.Core.Objects; +using RSBot.NavMeshApi; +using RSBot.NavMeshApi.Edges; +using RSBot.NavMeshApi.Terrain; + +namespace RSBot.Map.Renderer; + +internal class NavMeshRenderer +{ + private record NavMeshObjRenderConfig(bool DrawInternalEdges, bool DrawGlobalEdges, Pen Color); + private record NavMeshTerrainRenderConfig(bool DrawInternalEdges, bool DrawGlobalEdges, Pen Color); + + private const float Scale = 256 / 192.0f; + + private readonly Graphics _graphics; + private readonly int _canvasWidth; + private readonly int _canvasHeight; + + public NavMeshRenderer(Graphics graphics, int canvasWidth, int canvasHeight) + { + _graphics = graphics; + _canvasWidth = canvasWidth; + _canvasHeight = canvasHeight; + } + + public void Render(NavMesh navMesh) + { + var terrainConfig = new NavMeshTerrainRenderConfig(true, true, Pens.DarkRed); + var objConfig = new NavMeshObjRenderConfig(true, true, Pens.Red); + + if (navMesh is not NavMeshTerrain terrain) + return; + + DrawNavMeshTerrain(terrain, terrainConfig); + foreach (var navMeshObjInst in terrain.Instances) + DrawNavMeshInstObj(terrain.Region, navMeshObjInst, objConfig); + } + + private void DrawNavMeshInstObj(NavMeshApi.Mathematics.Region region, NavMeshInst instObj, NavMeshObjRenderConfig config) + { + var transformedPositions = new Vector3[instObj.NavMeshObj.Vertices.Length]; + for (var iVertex = 0; iVertex < instObj.NavMeshObj.Vertices.Length; iVertex++) + { + var transformed = Vector3.Transform(instObj.NavMeshObj.Vertices[iVertex].Position, instObj.LocalToWorld); + + transformedPositions[iVertex] = transformed; + } + + if (config.DrawGlobalEdges) + { + foreach (var globalEdge in instObj.NavMeshObj.GlobalEdges) + { + if (!globalEdge.IsBlocked) + continue; + + var posA = transformedPositions[globalEdge.Vertex0.Index]; + var posB = transformedPositions[globalEdge.Vertex1.Index]; + + var positionA = GetWorldPosition(region, posA); + var positionB = GetWorldPosition(region, posB); + + DrawLine(positionA, positionB, config.Color); + } + } + + if (config.DrawInternalEdges) + { + foreach (var internalEdge in instObj.NavMeshObj.InternalEdges) + { + if (!internalEdge.IsBlocked) + continue; + + var posA = transformedPositions[internalEdge.Vertex0.Index]; + var posB = transformedPositions[internalEdge.Vertex1.Index]; + + var positionA = GetWorldPosition(region, posA); + var positionB = GetWorldPosition(region, posB); + + DrawLine(positionA, positionB, config.Color); + } + } + } + + private void DrawNavMeshTerrain(NavMeshTerrain terrain, NavMeshTerrainRenderConfig config) + { + + if (config.DrawInternalEdges) + { + foreach (var internalEdge in terrain.InternalEdges) + { + if (internalEdge.IsBlocked) + DrawEdge(terrain.Region, internalEdge, config.Color); + + } + } + + if (config.DrawGlobalEdges) + { + foreach (var globalEdge in terrain.GlobalEdges) + { + if (globalEdge.IsBlocked) + DrawEdge(terrain.Region, globalEdge, config.Color); + } + } + } + + private void DrawEdge(NavMeshApi.Mathematics.Region region, NavMeshEdge edge, Pen color) + { + var posA = GetWorldPosition(region, edge.Line.Min); + var posB = GetWorldPosition(region, edge.Line.Max); + + DrawLine(posA, posB, color); + } + + private void DrawLine(Position source, Position destination, Pen color) + { + //Skip too far away? + var distanceToPositionA = source.DistanceToPlayer(); + var distanceToPositionB = destination.DistanceToPlayer(); + if (distanceToPositionA > 150 || distanceToPositionB > 150) + return; + + if (source.DistanceTo(destination) > 150) + return; + + var srcX = GetMapX(source); + var srcY = GetMapY(source); + var destinationX = GetMapX(destination); + var destinationY = GetMapY(destination); + + if (srcX == 0 && srcY == 0 && destinationY == 0 && destinationX == 0) + return; + + if (srcX < 0 || srcX > _canvasWidth || srcY > _canvasHeight || srcY < 0) + return; + + if (destinationX < 0 || destinationX > _canvasWidth || destinationY > _canvasHeight || destinationY < 0) + return; + + _graphics.DrawLine(color, srcX, srcY, destinationX, destinationY); + } + + private Position GetWorldPosition(NavMeshApi.Mathematics.Region region, Vector3 localPosition) + { + return new Position(region.X, region.Z, localPosition.X, localPosition.Z, localPosition.Y); + } + + private float GetMapX(Position gamePosition) + { + //Player is center + return _canvasWidth / 2f + (gamePosition.X - Game.Player.Movement.Source.X) * Scale; + } + + private float GetMapY(Position gamePosition) + { + //Player is center + return _canvasHeight / 2f + (gamePosition.Y - Game.Player.Movement.Source.Y) * Scale * -1.0f; + } +} \ No newline at end of file diff --git a/Plugins/RSBot.Map/Views/Main.Designer.cs b/Plugins/RSBot.Map/Views/Main.Designer.cs index 0f793280..3d4d61e4 100644 --- a/Plugins/RSBot.Map/Views/Main.Designer.cs +++ b/Plugins/RSBot.Map/Views/Main.Designer.cs @@ -60,7 +60,7 @@ private void InitializeComponent() label1.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); label1.Gradient = new System.Drawing.Color[] { System.Drawing.Color.Gray, System.Drawing.Color.Black }; label1.GradientAnimation = false; - label1.Location = new System.Drawing.Point(18, 339); + label1.Location = new System.Drawing.Point(18, 350); label1.Name = "label1"; label1.Size = new System.Drawing.Size(17, 13); label1.TabIndex = 1; @@ -74,7 +74,7 @@ private void InitializeComponent() label2.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); label2.Gradient = new System.Drawing.Color[] { System.Drawing.Color.Gray, System.Drawing.Color.Black }; label2.GradientAnimation = false; - label2.Location = new System.Drawing.Point(120, 339); + label2.Location = new System.Drawing.Point(120, 350); label2.Name = "label2"; label2.Size = new System.Drawing.Size(17, 13); label2.TabIndex = 2; @@ -88,7 +88,7 @@ private void InitializeComponent() lblX.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); lblX.Gradient = new System.Drawing.Color[] { System.Drawing.Color.Gray, System.Drawing.Color.Black }; lblX.GradientAnimation = false; - lblX.Location = new System.Drawing.Point(41, 339); + lblX.Location = new System.Drawing.Point(41, 350); lblX.Name = "lblX"; lblX.Size = new System.Drawing.Size(13, 13); lblX.TabIndex = 4; @@ -102,7 +102,7 @@ private void InitializeComponent() lblY.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); lblY.Gradient = new System.Drawing.Color[] { System.Drawing.Color.Gray, System.Drawing.Color.Black }; lblY.GradientAnimation = false; - lblY.Location = new System.Drawing.Point(143, 339); + lblY.Location = new System.Drawing.Point(143, 350); lblY.Name = "lblY"; lblY.Size = new System.Drawing.Size(13, 13); lblY.TabIndex = 5; @@ -127,7 +127,7 @@ private void InitializeComponent() mapCanvas.BackColor = System.Drawing.Color.FromArgb(64, 64, 64); mapCanvas.Location = new System.Drawing.Point(18, 46); mapCanvas.Name = "mapCanvas"; - mapCanvas.Size = new System.Drawing.Size(300, 290); + mapCanvas.Size = new System.Drawing.Size(300, 300); mapCanvas.TabIndex = 0; mapCanvas.MouseClick += mapCanvas_MouseClick; // diff --git a/Plugins/RSBot.Map/Views/Main.cs b/Plugins/RSBot.Map/Views/Main.cs index feebfe3f..6757b2d8 100644 --- a/Plugins/RSBot.Map/Views/Main.cs +++ b/Plugins/RSBot.Map/Views/Main.cs @@ -13,6 +13,7 @@ using RSBot.Core.Extensions; using RSBot.Core.Objects; using RSBot.Core.Objects.Spawn; +using RSBot.Map.Renderer; namespace RSBot.Map.Views; @@ -286,9 +287,10 @@ private void PopulateMapAndGrid(Graphics graphics) DrawCircleAt(graphics, entry.Position, Color.Wheat.Alpha(100), 6); //Other style for mobs behind obstacles - if (entry.IsBehindObstacle) + if (entry.IsBehindObstacle) { DrawCircleAt(graphics, entry.Position, Color.DarkRed.Alpha(100), 6); - + DrawLineAt(graphics, Game.Player.Movement.Source, entry.Position, Pens.DarkRed); + } if (entry.Rarity == MonsterRarity.Unique || entry.Rarity == MonsterRarity.Unique2) DrawPointAt(graphics, entry.Position, 5); else @@ -358,32 +360,13 @@ private void PopulateMapAndGrid(Graphics graphics) private void DrawCollisions(Graphics gfx) { - if (CollisionManager.HasActiveMeshes && CollisionManager.Enabled) - { - foreach (var collisionNavmesh in CollisionManager.ActiveCollisionMeshes) - { - var colliders = collisionNavmesh.Collisions - .Where(c => c.Source.DistanceToPlayer() < 100 || c.Destination.DistanceToPlayer() < 100); - - foreach (var collider in colliders) - DrawLineAt(gfx, collider.Source, collider.Destination, Pens.Red); - } - - if (!SpawnManager.TryGetEntities(out var entities)) - return; - - foreach (var entity in entities.Where(e => e.IsBehindObstacle)) - { - var collision = - CollisionManager.GetCollisionBetween(Game.Player.Position, entity.Position); - - if (!collision.HasValue) - continue; + if (!checkEnableCollisions.Checked || !_debug) + return; - DrawLineAt(gfx, Game.Player.Position, collision.Value.CollidedAt, Pens.GreenYellow); - DrawLineAt(gfx, collision.Value.CollidedWith.Source, collision.Value.CollidedWith.Destination, - Pens.Yellow); - } + foreach (var navMesh in CollisionManager.GetActiveMeshes().Where(x => x != null)) + { + var renderer = new NavMeshRenderer(gfx, mapCanvas.Width, mapCanvas.Height); + renderer.Render(navMesh); } } @@ -460,8 +443,8 @@ private string GetLayerPath(Position p) // Bahgdad Room case 32793: return "minimap_d\\Arabia\\RN_ARABIA_FIELD_02_BOSS_{0}x{1}.ddj"; - // 32791 - GM's Room - // 32792 - Fortress Prison + // 32791 - GM's Room + // 32792 - Fortress Prison } // Default as world map @@ -500,22 +483,22 @@ private void RedrawMap() { gfx.InterpolationMode = InterpolationMode.Bicubic; for (var x = 0; x < GridSize; x++) - for (var z = 0; z < GridSize; z++) - { - var sectorImgName = string.Format(layerPath, _currentXSec + x - 1, _currentYSec + z - 1); + for (var z = 0; z < GridSize; z++) + { + var sectorImgName = string.Format(layerPath, _currentXSec + x - 1, _currentYSec + z - 1); - using var bitmap = LoadSectorImage(sectorImgName); - var pos = new Point(bitmap.Width * x, bitmap.Height * (GridSize - 1 - z)); + using var bitmap = LoadSectorImage(sectorImgName); + var pos = new Point(bitmap.Width * x, bitmap.Height * (GridSize - 1 - z)); - gfx.DrawImage(bitmap, pos); + gfx.DrawImage(bitmap, pos); - if (_debug) - { - using var pen = new Pen(Color.Black); - pen.DashStyle = DashStyle.Dot; - gfx.DrawRectangle(pen, new Rectangle(pos, new Size(SectorSize, SectorSize))); + if (_debug) + { + using var pen = new Pen(Color.Black); + pen.DashStyle = DashStyle.Dot; + gfx.DrawRectangle(pen, new Rectangle(pos, new Size(SectorSize, SectorSize))); + } } - } } } @@ -561,9 +544,7 @@ private void DrawObjects(Graphics graphics) PopulateMapAndGrid(graphics); DrawPointAt(graphics, Game.Player.Movement.Source, 0); - - if (_debug) - DrawCollisions(graphics); + DrawCollisions(graphics); } } diff --git a/Plugins/RSBot.Map/Views/Main.resx b/Plugins/RSBot.Map/Views/Main.resx index 68986d8c..64373562 100644 --- a/Plugins/RSBot.Map/Views/Main.resx +++ b/Plugins/RSBot.Map/Views/Main.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj b/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj deleted file mode 100644 index cfadb03d..00000000 --- a/RSBot.NavMeshApi/RSBot.NavMeshApi.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net7.0 - enable - enable - - - diff --git a/RSBot.sln b/RSBot.sln index 68381324..72697f4f 100644 --- a/RSBot.sln +++ b/RSBot.sln @@ -37,7 +37,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSBot.Default", "Botbases\R EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSBot", "Application\RSBot\RSBot.csproj", "{259A396E-2479-493E-A360-6CAD48E3CB5E}" ProjectSection(ProjectDependencies) = postProject - {2512902C-3EF4-4395-9925-258F49A5813B} = {2512902C-3EF4-4395-9925-258F49A5813B} + {977F3DA7-3963-414B-B474-63BA941CF726} = {977F3DA7-3963-414B-B474-63BA941CF726} EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSBot.Replacer", "Application\RSBot.Replacer\RSBot.Replacer.csproj", "{EBA7F066-8BD6-488D-A65A-B9FFFF2667C4}" @@ -60,7 +60,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSBot.Quest", "Plugins\RSBo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSBot.FileSystem", "Library\RSBot.FileSystem\RSBot.FileSystem.csproj", "{43159571-287D-42E1-B262-A39DE07D6763}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSBot.NavMeshApi", "RSBot.NavMeshApi\RSBot.NavMeshApi.csproj", "{9DED38E3-6DF5-4D37-AEE3-A7B0F759B34E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSBot.NavMeshApi", "Library\RSBot.NavMeshApi\RSBot.NavMeshApi.csproj", "{9DED38E3-6DF5-4D37-AEE3-A7B0F759B34E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution