Skip to content

Commit

Permalink
feat: update spawn point direction as enum
Browse files Browse the repository at this point in the history
Signed-off-by: Utku Korkmaz <uutkukorkmaz@gmail.com>
  • Loading branch information
uutkukorkmaz committed Oct 6, 2024
1 parent 36e635c commit 09e5236
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/Executables/Game/Services/ParserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -492,7 +492,22 @@ private static void ParseCommonDropAndAdd(ReadOnlySpan<char> line, ICollection<C
return new CommonDropEntry(minLevel, maxLevel, itemId, percentage);
}


private static ESpawnPointDirection ParseCompassDirection(string value)
{
return int.Parse(value) switch
{
0 => 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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Executables/Game/World/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 17 additions & 1 deletion src/Executables/Game/World/SpawnPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ public enum ESpawnPointType
Special
}

/// <summary>
/// Spawn point directions follows the compass rose with counter-clockwise increments.
/// </summary>
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; }
Expand All @@ -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<int> Groups { get; } = new List<int>();
public uint Monster { get; set; }
Expand Down

0 comments on commit 09e5236

Please sign in to comment.