From 09e5236871bb6e823dcd82a28cb2445a4b4b2cb1 Mon Sep 17 00:00:00 2001 From: Utku Korkmaz Date: Sun, 6 Oct 2024 20:41:22 +0300 Subject: [PATCH] feat: update spawn point direction as enum Signed-off-by: Utku Korkmaz --- .../Game/Services/ParserService.cs | 19 +++++++++++++++++-- src/Executables/Game/World/Map.cs | 3 +-- src/Executables/Game/World/SpawnPoint.cs | 18 +++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Executables/Game/Services/ParserService.cs b/src/Executables/Game/Services/ParserService.cs index b4bbb4d4..49d377ac 100644 --- a/src/Executables/Game/Services/ParserService.cs +++ b/src/Executables/Game/Services/ParserService.cs @@ -42,7 +42,7 @@ public ParserService(ILoggerFactory loggerFactory) Y = int.Parse(splitted[2]), RangeX = int.Parse(splitted[3]), RangeY = int.Parse(splitted[4]), - Direction = int.Parse(splitted[6]), + Direction = ParseCompassDirection(splitted[6]), RespawnTime = ParseSecondsFromTimespanString(splitted[7].Trim()), Chance = short.Parse(splitted[8]), MaxAmount = short.Parse(splitted[9]), @@ -492,7 +492,22 @@ private static void ParseCommonDropAndAdd(ReadOnlySpan line, ICollection ESpawnPointDirection.Random, + 1 => ESpawnPointDirection.South, + 2 => ESpawnPointDirection.SouthEast, + 3 => ESpawnPointDirection.East, + 4 => ESpawnPointDirection.NorthEast, + 5 => ESpawnPointDirection.North, + 6 => ESpawnPointDirection.NorthWest, + 7 => ESpawnPointDirection.West, + 8 => ESpawnPointDirection.SouthWest, + _ => ESpawnPointDirection.Random + }; + } private static bool IsEmptyOrContainsNewlineOrTab(string str) { diff --git a/src/Executables/Game/World/Map.cs b/src/Executables/Game/World/Map.cs index a2ad1e98..8759b91e 100644 --- a/src/Executables/Game/World/Map.cs +++ b/src/Executables/Game/World/Map.cs @@ -298,8 +298,7 @@ private MonsterEntity SpawnMonster(uint id, SpawnPoint spawnPoint) { monster.PositionX = (int)(PositionX + baseX * SPAWN_POSITION_MULTIPLIER); monster.PositionY = (int)(PositionY + baseY * SPAWN_POSITION_MULTIPLIER); - // SpawnPoint.Direction follows the compass system with counter-clockwise increments: 1 = South, 2 = South-East, 3 = East, 5 = North, etc. - var compassDirection = spawnPoint.Direction - 1; + var compassDirection = (int)spawnPoint.Direction - 1; var rotation = 45 * (compassDirection < 0 ? 8 : compassDirection); monster.Rotation = rotation; } diff --git a/src/Executables/Game/World/SpawnPoint.cs b/src/Executables/Game/World/SpawnPoint.cs index 7494d2df..ae9987ed 100644 --- a/src/Executables/Game/World/SpawnPoint.cs +++ b/src/Executables/Game/World/SpawnPoint.cs @@ -16,6 +16,22 @@ public enum ESpawnPointType Special } + /// + /// Spawn point directions follows the compass rose with counter-clockwise increments. + /// + public enum ESpawnPointDirection + { + Random = 0, + South = 1, + SouthEast = 2, + East = 3, + NorthEast = 4, + North = 5, + NorthWest = 6, + West = 7, + SouthWest = 8 + } + public class SpawnPoint { public ESpawnPointType Type { get; set; } @@ -24,7 +40,7 @@ public class SpawnPoint public int Y { get; set; } public int RangeX { get; set; } public int RangeY { get; set; } - public int Direction { get; set; } + public ESpawnPointDirection Direction { get; set; } public int RespawnTime { get; set; } public List Groups { get; } = new List(); public uint Monster { get; set; }