Updates teleporter generator (#105)
This commit is contained in:
parent
141ec11330
commit
be0c33bc8a
5 changed files with 15228 additions and 1440 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -5,59 +5,35 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using Server.Json;
|
||||||
|
|
||||||
namespace Server.Commands
|
namespace Server.Commands
|
||||||
{
|
{
|
||||||
public class MapConverter : JsonConverter<Map>
|
|
||||||
{
|
|
||||||
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
||||||
=> Map.Parse(reader.GetString());
|
|
||||||
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options)
|
|
||||||
=> writer.WriteStringValue(value.Name);
|
|
||||||
}
|
|
||||||
public class Point3DConverter : JsonConverter<Point3D>
|
|
||||||
{
|
|
||||||
public override Point3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
if (reader.TokenType != JsonTokenType.StartArray)
|
|
||||||
throw new JsonException($"Point3D requires an array of exactly 3 integers. Invalid Starting TokenType: ${reader.TokenType}");
|
|
||||||
reader.Read();
|
|
||||||
var data = new List<int>();
|
|
||||||
for (; reader.TokenType != JsonTokenType.EndArray; reader.Read())
|
|
||||||
data.Add(reader.GetInt32());
|
|
||||||
if (data.Count < 2 || data.Count > 3)
|
|
||||||
throw new JsonException($"Invalid number of parameters for Point3D, {data.Count} were provided when either 2 or 3 expected.");
|
|
||||||
return new Point3D(data[0], data[1], data.Count == 3 ? data[2] : 0);
|
|
||||||
}
|
|
||||||
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
writer.WriteStartArray();
|
|
||||||
writer.WriteNumberValue(value.X);
|
|
||||||
writer.WriteNumberValue(value.Y);
|
|
||||||
writer.WriteNumberValue(value.Z);
|
|
||||||
writer.WriteEndArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Location
|
public struct Location
|
||||||
{
|
{
|
||||||
[JsonPropertyName("p"), JsonConverter(typeof(Point3DConverter))] public Point3D Pos { get; set; }
|
[JsonPropertyName("point"), JsonConverter(typeof(Point3dConverter))]
|
||||||
[JsonPropertyName("m"), JsonConverter(typeof(MapConverter))] public Map Map { get; set; }
|
public Point3D Pos { get; set; }
|
||||||
|
[JsonPropertyName("map"), JsonConverter(typeof(MapConverter))]
|
||||||
|
public Map Map { get; set; }
|
||||||
public override string ToString() => $"({Map.Name}:{Pos.X},{Pos.Y},{Pos.Z})";
|
public override string ToString() => $"({Map.Name}:{Pos.X},{Pos.Y},{Pos.Z})";
|
||||||
public override int GetHashCode() => ToString().GetHashCode();
|
public override int GetHashCode() => ToString().GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct TeleporterDefinition
|
public struct TeleporterDefinition
|
||||||
{
|
{
|
||||||
[JsonPropertyName("s")] public Location Source { get; set; }
|
[JsonPropertyName("source")]
|
||||||
[JsonPropertyName("d")] public Location Destination { get; set; }
|
public Location Source { get; set; }
|
||||||
[JsonPropertyName("b")] public bool Back { get; set; }
|
[JsonPropertyName("destination")]
|
||||||
|
public Location Destination { get; set; }
|
||||||
|
[JsonPropertyName("back")]
|
||||||
|
public bool Back { get; set; }
|
||||||
public override string ToString() => $"{{{Source},{Destination},{Back}}}";
|
public override string ToString() => $"{{{Source},{Destination},{Back}}}";
|
||||||
public override int GetHashCode() => ToString().GetHashCode();
|
public override int GetHashCode() => ToString().GetHashCode();
|
||||||
}
|
}
|
||||||
public class GenTeleporter
|
|
||||||
|
public static class GenTeleporter
|
||||||
{
|
{
|
||||||
private const int SuccessHue = 72, WarningHue = 53, ErrorHue = 33;
|
private const int SuccessHue = 72, WarningHue = 53, ErrorHue = 33;
|
||||||
private static readonly string TeleporterDataPath = Path.Combine("Data", "teleporters.csv");
|
|
||||||
private static readonly string TeleporterJsonDataPath = Path.Combine("Data", "teleporters.json");
|
private static readonly string TeleporterJsonDataPath = Path.Combine("Data", "teleporters.json");
|
||||||
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
|
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
|
|
@ -68,49 +44,59 @@ namespace Server.Commands
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
CommandSystem.Register("TelGen", AccessLevel.Administrator, new CommandEventHandler(GenTeleporter_OnCommand));
|
CommandSystem.Register("TelGen", AccessLevel.Administrator, GenTeleporter_OnCommand);
|
||||||
CommandSystem.Register("TelGenDelete", AccessLevel.Administrator, new CommandEventHandler(TelGenDelete_OnCommand));
|
CommandSystem.Register("TelGenDelete", AccessLevel.Administrator, TelGenDelete_OnCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Usage("TelGenDelete")]
|
[Usage("TelGenDelete")]
|
||||||
[Description("Destroys world/dungeon teleporters for all facets.")]
|
[Description("Destroys world/dungeon teleporters for all facets.")]
|
||||||
public static void TelGenDelete_OnCommand(CommandEventArgs e)
|
public static void TelGenDelete_OnCommand(CommandEventArgs e)
|
||||||
{
|
{
|
||||||
e.Mobile.SendMessage("Removing teleporters, please wait.");
|
Mobile from = e.Mobile;
|
||||||
|
|
||||||
|
from.SendMessage("Removing teleporters, please wait.");
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (ProcessTeleporterData(e, x =>
|
|
||||||
{
|
void ProcessDeletion(TeleporterDefinition x)
|
||||||
count += TeleportersCreator.DeleteTeleporters(x.Source);
|
{
|
||||||
if (x.Back) count += TeleportersCreator.DeleteTeleporters(x.Destination);
|
count += TeleportersCreator.DeleteTeleporters(x.Source);
|
||||||
}))
|
if (x.Back) count += TeleportersCreator.DeleteTeleporters(x.Destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ProcessTeleporterData(from, ProcessDeletion))
|
||||||
{
|
{
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
e.Mobile.SendMessage(WarningHue, $"Partial Completion, {count} Teleporters Removed.");
|
from.SendMessage(WarningHue, $"Partial Completion, {count} Teleporters Removed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.Mobile.SendMessage(WarningHue, $"{count} Teleporters Removed.");
|
|
||||||
|
from.SendMessage(WarningHue, $"{count} Teleporters Removed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Usage("TelGen")]
|
[Usage("TelGen")]
|
||||||
[Description("Generates world/dungeon teleporters for all facets.")]
|
[Description("Generates world/dungeon teleporters for all facets.")]
|
||||||
public static void GenTeleporter_OnCommand(CommandEventArgs e)
|
public static void GenTeleporter_OnCommand(CommandEventArgs e)
|
||||||
{
|
{
|
||||||
e.Mobile.SendMessage("Generating teleporters, please wait.");
|
Mobile from = e.Mobile;
|
||||||
|
|
||||||
|
from.SendMessage("Generating teleporters, please wait.");
|
||||||
TeleportersCreator c = new TeleportersCreator();
|
TeleportersCreator c = new TeleportersCreator();
|
||||||
if (ProcessTeleporterData(e, c.CreateTeleporter))
|
|
||||||
|
if (!ProcessTeleporterData(from, c.CreateTeleporter))
|
||||||
{
|
{
|
||||||
if (c.DelCount > 0)
|
if (c.DelCount > 0)
|
||||||
e.Mobile.SendMessage(WarningHue, $"Partial Completion: {c.DelCount} Teleporters Removed.");
|
from.SendMessage(WarningHue, $"Partial Completion: {c.DelCount} Teleporters Removed.");
|
||||||
if (c.Count > 0)
|
if (c.Count > 0)
|
||||||
e.Mobile.SendMessage(WarningHue, $"Partial Completion: {c.Count} Teleporters Added.");
|
from.SendMessage(WarningHue, $"Partial Completion: {c.Count} Teleporters Added.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.Mobile.SendMessage(SuccessHue, $"Teleporter generating complete.");
|
|
||||||
e.Mobile.SendMessage(WarningHue, $"{c.DelCount} Teleporters Removed.");
|
from.SendMessage(SuccessHue, "Teleporter generating complete.");
|
||||||
e.Mobile.SendMessage(SuccessHue, $"{c.Count} Teleporters Added.");
|
from.SendMessage(WarningHue, $"{c.DelCount} Teleporters Removed.");
|
||||||
|
from.SendMessage(SuccessHue, $"{c.Count} Teleporters Added.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ProcessTeleporterData(CommandEventArgs e, Action<TeleporterDefinition> processor)
|
private static bool ProcessTeleporterData(Mobile m, Action<TeleporterDefinition> processor)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -124,29 +110,32 @@ namespace Server.Commands
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
Console.WriteLine(ex.ToString());
|
||||||
e.Mobile.SendMessage(ErrorHue, $"Failed to load/process data file '{TeleporterJsonDataPath}'");
|
m.SendMessage(ErrorHue, $"Failed to load/process data file '{TeleporterJsonDataPath}'");
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TeleportersCreator
|
private class TeleportersCreator
|
||||||
{
|
{
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
public int DelCount { get; private set; }
|
public int DelCount { get; private set; }
|
||||||
|
|
||||||
|
private static bool IsWithinZ(int delta) => -12 <= delta && delta <= 12;
|
||||||
|
|
||||||
public static int DeleteTeleporters(Location location)
|
public static int DeleteTeleporters(Location location)
|
||||||
{
|
{
|
||||||
bool IsWithinZ(int delta) => -12 <= delta && delta <= 12;
|
|
||||||
IPooledEnumerable<Teleporter> eable = location.Map.GetItemsInRange<Teleporter>(location.Pos, 0);
|
IPooledEnumerable<Teleporter> eable = location.Map.GetItemsInRange<Teleporter>(location.Pos, 0);
|
||||||
var items = eable.Where(x => !(x is KeywordTeleporter || x is SkillTeleporter) && IsWithinZ(x.Z - location.Pos.Z)).ToList();
|
var items = eable
|
||||||
eable.Free();
|
.Where(x => !(x is KeywordTeleporter || x is SkillTeleporter) && IsWithinZ(x.Z - location.Pos.Z));
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
item.Delete();
|
item.Delete();
|
||||||
}
|
}
|
||||||
|
eable.Free();
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
Projects/Server/JsonConverters/MapConverter.cs
Normal file
15
Projects/Server/JsonConverters/MapConverter.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Server.Json
|
||||||
|
{
|
||||||
|
public class MapConverter : JsonConverter<Map>
|
||||||
|
{
|
||||||
|
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
=> Map.Parse(reader.GetString());
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options)
|
||||||
|
=> writer.WriteStringValue(value.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Projects/Server/JsonConverters/Point3dConverter.cs
Normal file
47
Projects/Server/JsonConverters/Point3dConverter.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Server.Json
|
||||||
|
{
|
||||||
|
public class Point3dConverter : JsonConverter<Point3D>
|
||||||
|
{
|
||||||
|
public override Point3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (reader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException("Point3d must be an array of x, y, z");
|
||||||
|
|
||||||
|
var data = new int[3];
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
reader.Read();
|
||||||
|
if (reader.TokenType == JsonTokenType.EndArray)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (reader.TokenType == JsonTokenType.Number)
|
||||||
|
{
|
||||||
|
if (count < 3)
|
||||||
|
data[count] = reader.GetInt32();
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count < 2 || count > 3)
|
||||||
|
throw new JsonException("Point3d must be an array of x, y, z");
|
||||||
|
|
||||||
|
return new Point3D(data[0], data[1], data[2]);
|
||||||
|
}
|
||||||
|
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStartArray();
|
||||||
|
writer.WriteNumberValue(value.X);
|
||||||
|
writer.WriteNumberValue(value.Y);
|
||||||
|
writer.WriteNumberValue(value.Z);
|
||||||
|
writer.WriteEndArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -294,8 +294,6 @@ namespace Server.Network
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Processing Packet... {0:X}", packetId);
|
|
||||||
|
|
||||||
if (!ns.Seeded)
|
if (!ns.Seeded)
|
||||||
{
|
{
|
||||||
if (packetId == 0xEF)
|
if (packetId == 0xEF)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue