fix: Fixes spawners, adds convertpremiumspawners, exportspawners, and replaces with neruns distro (#751)

### Additions
* Adds `[exportspawners <relative json file path to distro>`
  * If no path is provided, it will be saved to the `Data\Spawns` folder with the current timestamp as the file name.
  * Supports global, facet, region, multi, and area
* Fixes client disconnect for bad spawner generation command.
* Moves spawner commands to their own folder.
* Adds GUIDs for spawners. This allows for easy replacement during import to reduce duplication.
* Allows exporting the name of the spawner.
* Fixes globbing when using [generatespawners
* Adds [convertpremiumspawners to convert Premium Spawners (from Neruns distro)

Possibly in .NET 6 serializing JSON will be more performant using JSON nodes.


### Screenshots
![Screen_Shot_2021-08-31_at_10 20 06_PM](https://user-images.githubusercontent.com/3953314/131618495-cf7e3ae5-58e5-4f86-9d3c-3cc49906d9fc.png)
![Screen_Shot_2021-08-31_at_10 21 08_PM](https://user-images.githubusercontent.com/3953314/131618502-c39cc368-2266-47a5-9b87-e5ffa108b875.png)
![Screen_Shot_2021-08-31_at_10 13 29_PM](https://user-images.githubusercontent.com/3953314/131618512-f9807f1b-76e4-4503-989d-42324798fbf5.png)
This commit is contained in:
Kamron Batman 2021-09-03 21:52:44 -07:00 • committed by GitHub
parent dbd4d6f13f
commit 0d1fffd9fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
211 changed files with 200435 additions and 91312 deletions

View file

@ -17,6 +17,8 @@ namespace Server.Engines.Spawners
public abstract class BaseSpawner : Item, ISpawner
{
private static WarnTimer m_WarnTimer;
private Guid _guid;
private int m_Count;
private bool m_Group;
private int m_HomeRange;
@ -62,6 +64,7 @@ namespace Server.Engines.Spawners
params string[] spawnedNames
) : base(0x1f13)
{
_guid = Guid.NewGuid();
InitSpawn(amount, minDelay, maxDelay, team, homeRange);
for (var i = 0; i < spawnedNames.Length; i++)
{
@ -71,6 +74,16 @@ namespace Server.Engines.Spawners
public BaseSpawner(DynamicJson json, JsonSerializerOptions options) : base(0x1f13)
{
if (!json.GetProperty("guid", options, out _guid))
{
_guid = Guid.NewGuid();
}
if (json.GetProperty("name", options, out string name))
{
Name = name;
}
json.GetProperty("count", options, out int amount);
json.GetProperty("minDelay", options, out TimeSpan minDelay);
json.GetProperty("maxDelay", options, out TimeSpan maxDelay);
@ -102,6 +115,13 @@ namespace Server.Engines.Spawners
public Dictionary<ISpawnable, SpawnerEntry> Spawned { get; private set; }
[CommandProperty(AccessLevel.Developer)]
public Guid Guid
{
get => _guid;
set => _guid = value;
}
[CommandProperty(AccessLevel.Developer)]
public int Count
{
@ -261,6 +281,22 @@ namespace Server.Engines.Spawners
DoTimer(); // Turn off the timer!
}
public virtual void ToJson(DynamicJson json, JsonSerializerOptions options)
{
json.Type = GetType().Name;
json.SetProperty("name", options, Name);
json.SetProperty("guid", options, _guid);
json.SetProperty("location", options, Location);
json.SetProperty("map", options, Map);
json.SetProperty("count", options, Count);
json.SetProperty("minDelay", options, MinDelay);
json.SetProperty("maxDelay", options, MaxDelay);
json.SetProperty("team", options, Team);
json.SetProperty("homeRange", options, HomeRange);
json.SetProperty("walkingRange", options, WalkingRange);
json.SetProperty("entries", options, Entries);
}
public abstract Point3D GetSpawnPosition(ISpawnable spawned, Map map);
public override void OnAfterDuped(Item newItem)
@ -872,7 +908,9 @@ namespace Server.Engines.Spawners
{
base.Serialize(writer);
writer.Write(8); // version
writer.Write(9); // version
writer.Write(_guid);
writer.Write(ReturnOnDeactivate);
@ -917,6 +955,11 @@ namespace Server.Engines.Spawners
switch (version)
{
case 9:
{
_guid = reader.ReadGuid();
goto case 8;
}
case 8:
{
ReturnOnDeactivate = reader.ReadBool();