fix: Fixes regions having the wrong type (#1260)
## Possible Breaking Change * Reverted regions.json back to RunUO until newer regions are implemented and proper expansion checks are added. ### Other Changes - [X] Adds `Region.IsPartOf<T1, T2>()` to check for multiple types. - [X] Fixes regions.json being wrong - [X] Adds lots of missing regions. **They are not implemented properly yet** - [X] Adds regions.xml -> regions.json (check ModernUO Discord) - [X] Adds expansion specific regions.
This commit is contained in:
parent
f9c72a62df
commit
1f778cfacf
38 changed files with 3424 additions and 2949 deletions
|
|
@ -104,10 +104,13 @@ public class Point3DConverter : JsonConverter<Point3D>
|
|||
|
||||
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("x");
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WritePropertyName("y");
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WritePropertyName("z");
|
||||
writer.WriteNumberValue(value.Z);
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,13 +172,29 @@ public class Rectangle3DConverter : JsonConverter<Rectangle3D>
|
|||
|
||||
public override void Write(Utf8JsonWriter writer, Rectangle3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
var writeZ = value.Start.Z is > sbyte.MinValue and < sbyte.MaxValue || value.End.Z is > sbyte.MinValue and < sbyte.MaxValue;
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("x1");
|
||||
writer.WriteNumberValue(value.Start.X);
|
||||
writer.WritePropertyName("y1");
|
||||
writer.WriteNumberValue(value.Start.Y);
|
||||
writer.WriteNumberValue(value.Start.Z);
|
||||
writer.WriteNumberValue(value.Width);
|
||||
writer.WriteNumberValue(value.Height);
|
||||
writer.WriteNumberValue(value.Depth);
|
||||
writer.WriteEndArray();
|
||||
|
||||
if (writeZ)
|
||||
{
|
||||
writer.WritePropertyName("z1");
|
||||
writer.WriteNumberValue(value.Start.Z);
|
||||
}
|
||||
|
||||
writer.WritePropertyName("x2");
|
||||
writer.WriteNumberValue(value.End.X);
|
||||
writer.WritePropertyName("y2");
|
||||
writer.WriteNumberValue(value.End.Y);
|
||||
if (writeZ)
|
||||
{
|
||||
writer.WritePropertyName("z2");
|
||||
writer.WriteNumberValue(value.End.Z);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,12 @@ public class Region : IComparable<Region>
|
|||
}
|
||||
}
|
||||
|
||||
// Used during deserialization only
|
||||
public Expansion MinExpansion { get; set; }
|
||||
|
||||
// Used during deserialization only
|
||||
public Expansion MaxExpansion { get; set; }
|
||||
|
||||
public static List<Region> Regions { get; } = new();
|
||||
|
||||
public static TimeSpan StaffLogoutDelay { get; set; } = TimeSpan.Zero;
|
||||
|
|
@ -448,6 +454,24 @@ public class Region : IComparable<Region>
|
|||
return null;
|
||||
}
|
||||
|
||||
// TODO: Memoize this
|
||||
public bool IsPartOf<T1, T2>() where T1 : Region where T2 : Region
|
||||
{
|
||||
var r = this;
|
||||
|
||||
do
|
||||
{
|
||||
if (r is T1 or T2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
r = r.Parent;
|
||||
} while (r != null);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Region GetRegion(Type regionType)
|
||||
{
|
||||
if (regionType == null)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ namespace Server;
|
|||
|
||||
public class RegionJsonDto
|
||||
{
|
||||
public Expansion MinExpansion { get; set; } = Expansion.None;
|
||||
|
||||
public Expansion? MaxExpansion { get; set; } = Expansion.EJ;
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual Type RegionType => typeof(Region);
|
||||
|
||||
|
|
@ -40,7 +44,9 @@ public class RegionJsonDto
|
|||
Priority = region.Priority;
|
||||
Area = region.Area;
|
||||
GoLocation = region.GoLocation;
|
||||
Music = region.Music != region.DefaultMusic ? region.Music : null;
|
||||
Music = region.Music != MusicName.Invalid && region.Music != region.DefaultMusic ? region.Music : null;
|
||||
MaxExpansion = region.MaxExpansion == Expansion.EJ ? null : region.MaxExpansion;
|
||||
MinExpansion = region.MinExpansion;
|
||||
}
|
||||
|
||||
public Region ToRegion()
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public static class RegionJsonSerializer
|
|||
}
|
||||
};
|
||||
|
||||
public static void RegisterRegionForSerialization<TDto, TRegion>()
|
||||
public static void Register<TDto, TRegion>()
|
||||
where TDto : RegionJsonDto, new() where TRegion : Region
|
||||
{
|
||||
for (var i = 0; i < _derivedTypes.Length; i++)
|
||||
|
|
@ -91,10 +91,15 @@ public static class RegionJsonSerializer
|
|||
throw new JsonException($"Failed to deserialize {path}.");
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
foreach (var dto in regions)
|
||||
{
|
||||
var region = dto.ToRegion();
|
||||
region.Register();
|
||||
if (Core.Expansion >= dto.MinExpansion && Core.Expansion <= dto.MaxExpansion)
|
||||
{
|
||||
var region = dto.ToRegion();
|
||||
region.Register();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
|
|
@ -102,7 +107,7 @@ public static class RegionJsonSerializer
|
|||
logger.Information(
|
||||
"Loading regions {Status} ({Count} regions) ({Duration:F2} seconds)",
|
||||
"done",
|
||||
regions.Count,
|
||||
count,
|
||||
stopwatch.Elapsed.TotalSeconds
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue