ModernUO/Projects/Server/Regions/RegionJsonDto.cs
Kamron Batman 1f778cfacf
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.
2022-11-21 16:47:40 -08:00

67 lines
2.6 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: RegionJsonDto.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Text.Json.Serialization;
using Server.Utilities;
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);
public Map Map { get; set; }
public string? Parent { get; set; }
public string Name { get; set; }
public int? Priority { get; set; }
public Rectangle3D[] Area { get; set; }
public Point3D GoLocation { get; set; }
public MusicName? Music { get; set; }
public virtual void FromRegion(Region region)
{
Map = region.Map;
Parent = region.Parent?.Name;
Name = region.Name;
Priority = region.Priority;
Area = region.Area;
GoLocation = region.GoLocation;
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()
{
var region = Priority != null
? RegionType.CreateInstance<Region>(Name, Map, Region.Find(Parent, Map), Priority, Area)
: RegionType.CreateInstance<Region>(Name, Map, Region.Find(Parent, Map), Area);
HydrateRegion(region);
return region;
}
protected virtual void HydrateRegion(Region region)
{
region.GoLocation = GoLocation;
region.Music = Music ?? region.DefaultMusic;
}
}