fix: Fixes region priority and resolution. (#1254)
- [X] Fixes world location JSON deserializer. - [X] Fixes region resolver and priorities. - [X] Removes DynamicJson from regions. - [X] Adds missing region music.
This commit is contained in:
parent
139be1bc23
commit
18c4459e6b
31 changed files with 3809 additions and 3677 deletions
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Logging;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
|
|
@ -78,6 +76,42 @@ public enum MusicName
|
|||
SelimsBar,
|
||||
SerpentIsleCombat_U7,
|
||||
ValoriaShips,
|
||||
TheWanderer,
|
||||
Castle,
|
||||
Festival,
|
||||
Honor,
|
||||
Medieval,
|
||||
BattleOnStones,
|
||||
Docktown,
|
||||
GargoyleQueen,
|
||||
GenericCombat,
|
||||
Holycity,
|
||||
HumanLevel,
|
||||
LoginLoop,
|
||||
NorthernForestBattleonStones,
|
||||
PrimevalLich,
|
||||
QueenPalace,
|
||||
RoyalCity,
|
||||
SlasherVeil,
|
||||
StygianAbyss,
|
||||
StygianDragon,
|
||||
Void,
|
||||
CodexShrine,
|
||||
AnvilStrikeInMinoc,
|
||||
ASkaranLullaby,
|
||||
BlackthornsMarch,
|
||||
DupresNightInTrinsic,
|
||||
FayaxionAndTheSix,
|
||||
FlightOfTheNexus,
|
||||
GalehavenJaunt,
|
||||
JhelomToArms,
|
||||
MidnightInYew,
|
||||
MoonglowSonata,
|
||||
NewMaginciaMarch,
|
||||
NujelmWaltz,
|
||||
SherrysSong,
|
||||
StarlightInBritain,
|
||||
TheVesperMist,
|
||||
NoMusic = 0x1FFF
|
||||
}
|
||||
|
||||
|
|
@ -98,9 +132,16 @@ public class Region : IComparable<Region>
|
|||
{
|
||||
}
|
||||
|
||||
public Region(string name, Map map, params Rectangle3D[] area) : this(name, map, null, area)
|
||||
{
|
||||
}
|
||||
|
||||
public Region(string name, Map map, int priority, params Rectangle3D[] area) : this(name, map, null, area) =>
|
||||
Priority = priority;
|
||||
|
||||
public Region(string name, Map map, Region parent, int priority, params Rectangle3D[] area) : this(name, map, parent, area) =>
|
||||
Priority = priority;
|
||||
|
||||
public Region(string name, Map map, Region parent, params Rectangle2D[] area) : this(
|
||||
name,
|
||||
map,
|
||||
|
|
@ -131,54 +172,6 @@ public class Region : IComparable<Region>
|
|||
}
|
||||
}
|
||||
|
||||
public Region(DynamicJson json, JsonSerializerOptions options)
|
||||
{
|
||||
Map = json.GetProperty("map", options, out Map map) ? map : null;
|
||||
Parent = json.GetProperty("parent", options, out string parent) ? Find(parent, Map) : null;
|
||||
Name = json.GetProperty("name", options, out string name) ? name : null;
|
||||
|
||||
Dynamic = false;
|
||||
|
||||
if (Parent == null)
|
||||
{
|
||||
ChildLevel = 0;
|
||||
Priority = DefaultPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChildLevel = Parent.ChildLevel + 1;
|
||||
Priority = Parent.Priority;
|
||||
}
|
||||
|
||||
Priority = json.GetProperty("priority", options, out int priority) ? priority : Priority;
|
||||
|
||||
Area = json.GetProperty("rects", options, out List<Rectangle3D> rects)
|
||||
? rects.ToArray()
|
||||
: Array.Empty<Rectangle3D>();
|
||||
|
||||
if (Area.Length == 0)
|
||||
{
|
||||
logger.Debug("Empty area for region '{Region}'", this);
|
||||
}
|
||||
|
||||
if (json.GetProperty("go", options, out Point3D go))
|
||||
{
|
||||
GoLocation = go;
|
||||
}
|
||||
else if (Area.Length > 0)
|
||||
{
|
||||
var start = Area[0].Start;
|
||||
var end = Area[0].End;
|
||||
|
||||
var x = start.X + (end.X - start.X) / 2;
|
||||
var y = start.Y + (end.Y - start.Y) / 2;
|
||||
|
||||
GoLocation = new Point3D(x, y, Map?.GetAverageZ(x, y) ?? start.Z + (end.Z - start.Z) / 2);
|
||||
}
|
||||
|
||||
Music = json.GetEnumProperty("music", options, out MusicName music) ? music : DefaultMusic;
|
||||
}
|
||||
|
||||
public static List<Region> Regions { get; } = new();
|
||||
|
||||
public static TimeSpan StaffLogoutDelay { get; set; } = TimeSpan.Zero;
|
||||
|
|
@ -239,6 +232,11 @@ public class Region : IComparable<Region>
|
|||
// This is not optimized. Use sparingly
|
||||
public static Region Find(string name, Map map, bool insensitive = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (insensitive)
|
||||
{
|
||||
name = name.ToLower();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue