Convert Regions/Spawns to JSON (#138)
This commit is contained in:
parent
b8316e9202
commit
390f30e706
117 changed files with 97306 additions and 4848 deletions
1005
Projects/UOContent/Engines/Spawners/BaseSpawner.cs
Normal file
1005
Projects/UOContent/Engines/Spawners/BaseSpawner.cs
Normal file
File diff suppressed because it is too large
Load diff
116
Projects/UOContent/Engines/Spawners/GenerateSpawners.cs
Normal file
116
Projects/UOContent/Engines/Spawners/GenerateSpawners.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Utilities;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public static class GenerateSpawners
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("GenerateSpawners", AccessLevel.Developer, GenerateSpawners_OnCommand);
|
||||
}
|
||||
|
||||
private static void GenerateSpawners_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
|
||||
if (e.Arguments.Length == 0)
|
||||
{
|
||||
from.SendMessage("Usage: [GenerateSpawners <path|search pattern>");
|
||||
return;
|
||||
}
|
||||
|
||||
var di = new DirectoryInfo(Core.BaseDirectory);
|
||||
|
||||
var files = di.GetFiles(e.Arguments[0], SearchOption.AllDirectories);
|
||||
|
||||
if (files.Length == 0)
|
||||
{
|
||||
from.SendMessage("GenerateSpawners: No files found matching the pattern");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonSerializerOptions options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new MapConverterFactory());
|
||||
options.Converters.Add(new Point3DConverterFactory());
|
||||
options.Converters.Add(new TimeSpanConverterFactory());
|
||||
options.Converters.Add(new TextDefinitionConverterFactory());
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
var file = files[i];
|
||||
from.SendMessage("GenerateSpawners: Generating spawners for {0}...", file.Name);
|
||||
List<DynamicJson> spawners = JsonConfig.Deserialize<List<DynamicJson>>(file.FullName);
|
||||
ParseSpawnerList(from, spawners, options);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseSpawnerList(Mobile from, List<DynamicJson> spawners, JsonSerializerOptions options)
|
||||
{
|
||||
Stopwatch watch = Stopwatch.StartNew();
|
||||
List<string> failures = new List<string>();
|
||||
int count = 0;
|
||||
|
||||
for (var i = 0; i < spawners.Count; i++)
|
||||
{
|
||||
var json = spawners[i];
|
||||
Type type = AssemblyHandler.FindFirstTypeForName(json.Type);
|
||||
|
||||
if (type == null || !typeof(BaseSpawner).IsAssignableFrom(type))
|
||||
{
|
||||
string failure = $"GenerateSpawners: Invalid spawner type {json.Type ?? "(-null-)"} ({i})";
|
||||
if (!failures.Contains(failure))
|
||||
{
|
||||
failures.Add(failure);
|
||||
from.SendMessage(failure);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
json.GetProperty("location", options, out Point3D location);
|
||||
json.GetProperty("map", options, out Map map);
|
||||
|
||||
var eable = map.GetItemsInRange<BaseSpawner>(location, 0);
|
||||
|
||||
if (eable.Any(sp => sp.GetType() == type))
|
||||
{
|
||||
eable.Free();
|
||||
continue;
|
||||
}
|
||||
|
||||
eable.Free();
|
||||
|
||||
try
|
||||
{
|
||||
var spawner = ActivatorUtil.CreateInstance(type, json, options) as ISpawner;
|
||||
|
||||
spawner!.MoveToWorld(location, map);
|
||||
spawner!.Respawn();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
string failure = $"GenerateSpawners: Spawner {type} failed to construct";
|
||||
if (!failures.Contains(failure))
|
||||
{
|
||||
failures.Add(failure);
|
||||
from.SendMessage(failure);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
from.SendMessage("GenerateSpawners: Generated {0} spawners ({1:F2} seconds, {2} failures)", count, watch.Elapsed.TotalSeconds, failures.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
148
Projects/UOContent/Engines/Spawners/ProximitySpawner.cs
Normal file
148
Projects/UOContent/Engines/Spawners/ProximitySpawner.cs
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class ProximitySpawner : Spawner
|
||||
{
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner()
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner(string spawnName)
|
||||
: base(spawnName)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner(int amount, int minDelay, int maxDelay, int team, int homeRange, string spawnName)
|
||||
: base(amount, minDelay, maxDelay, team, homeRange, spawnName)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner(int amount, int minDelay, int maxDelay, int team, int homeRange, int triggerRange,
|
||||
string spawnMessage, bool instantFlag, string spawnName)
|
||||
: base(amount, minDelay, maxDelay, team, homeRange, spawnName)
|
||||
{
|
||||
TriggerRange = triggerRange;
|
||||
SpawnMessage = TextDefinition.Parse(spawnMessage);
|
||||
InstantFlag = instantFlag;
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
|
||||
params string[] spawnedNames)
|
||||
: base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public ProximitySpawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, int triggerRange,
|
||||
TextDefinition spawnMessage, bool instantFlag, params string[] spawnedNames)
|
||||
: base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
|
||||
{
|
||||
TriggerRange = triggerRange;
|
||||
SpawnMessage = spawnMessage;
|
||||
InstantFlag = instantFlag;
|
||||
}
|
||||
|
||||
public ProximitySpawner(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
json.GetProperty("triggerRange", options, out int triggerRange);
|
||||
json.GetProperty("spawnMessage", options, out TextDefinition spawnMessage);
|
||||
json.GetProperty("instant", options, out bool instant);
|
||||
|
||||
TriggerRange = triggerRange;
|
||||
SpawnMessage = spawnMessage;
|
||||
InstantFlag = instant;
|
||||
}
|
||||
|
||||
public ProximitySpawner(Serial serial)
|
||||
: base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Developer)]
|
||||
public int TriggerRange { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Developer)]
|
||||
public TextDefinition SpawnMessage { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Developer)]
|
||||
public bool InstantFlag { get; set; }
|
||||
|
||||
public override string DefaultName => "Proximity Spawner";
|
||||
|
||||
public override bool HandlesOnMovement => true;
|
||||
|
||||
public override void DoTimer(TimeSpan delay)
|
||||
{
|
||||
if (!Running)
|
||||
return;
|
||||
|
||||
End = DateTime.UtcNow + delay;
|
||||
}
|
||||
|
||||
public override void Respawn()
|
||||
{
|
||||
RemoveSpawns();
|
||||
|
||||
End = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public virtual bool ValidTrigger(Mobile m)
|
||||
{
|
||||
if (m is BaseCreature bc && (bc.IsDeadBondedPet || !(bc.Controlled || bc.Summoned)))
|
||||
return false;
|
||||
|
||||
return m.AccessLevel == AccessLevel.Player && (m.Player || (m.Alive && !m.Hidden && m.CanBeDamaged()));
|
||||
}
|
||||
|
||||
public override void OnMovement(Mobile m, Point3D oldLocation)
|
||||
{
|
||||
if (!Running)
|
||||
return;
|
||||
|
||||
if (IsEmpty && End <= DateTime.UtcNow && m.InRange(GetWorldLocation(), TriggerRange) &&
|
||||
m.Location != oldLocation && ValidTrigger(m))
|
||||
{
|
||||
TextDefinition.SendMessageTo(m, SpawnMessage);
|
||||
|
||||
DoTimer();
|
||||
Spawn();
|
||||
|
||||
if (InstantFlag)
|
||||
foreach (ISpawnable spawned in Spawned.Keys)
|
||||
if (spawned is Mobile mobile)
|
||||
mobile.Combatant = m;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(TriggerRange);
|
||||
TextDefinition.Serialize(writer, SpawnMessage);
|
||||
writer.Write(InstantFlag);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
TriggerRange = reader.ReadInt();
|
||||
SpawnMessage = TextDefinition.Deserialize(reader);
|
||||
InstantFlag = reader.ReadBool();
|
||||
}
|
||||
}
|
||||
}
|
||||
152
Projects/UOContent/Engines/Spawners/RegionSpawner.cs
Normal file
152
Projects/UOContent/Engines/Spawners/RegionSpawner.cs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Regions;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class RegionSpawner : Spawner
|
||||
{
|
||||
private BaseRegion m_SpawnRegion;
|
||||
|
||||
[CommandProperty(AccessLevel.Developer)]
|
||||
public BaseRegion SpawnRegion
|
||||
{
|
||||
get => m_SpawnRegion;
|
||||
set
|
||||
{
|
||||
m_SpawnRegion = value;
|
||||
m_SpawnRegion?.InitRectangles();
|
||||
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public RegionSpawner()
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public RegionSpawner(string spawnedName) : base(spawnedName)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public RegionSpawner(int amount, int minDelay, int maxDelay, int team, int homeRange,
|
||||
params string[] spawnedNames) : this(amount, TimeSpan.FromMinutes(minDelay), TimeSpan.FromMinutes(maxDelay),
|
||||
team, homeRange, spawnedNames)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public RegionSpawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
|
||||
params string[] spawnedNames) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
|
||||
{
|
||||
}
|
||||
|
||||
public RegionSpawner(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
json.GetProperty("map", options, out Map map);
|
||||
json.GetProperty("region", options, out string spawnRegion);
|
||||
|
||||
m_SpawnRegion = Region.Find(spawnRegion, map) as BaseRegion;
|
||||
m_SpawnRegion?.InitRectangles();
|
||||
}
|
||||
|
||||
public RegionSpawner(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetSpawnerProperties(ObjectPropertyList list)
|
||||
{
|
||||
base.GetSpawnerProperties(list);
|
||||
|
||||
if (Running && m_SpawnRegion != null) list.Add(1076228, "region:\t{0}", m_SpawnRegion.Name); // ~1_DUMMY~ ~2_DUMMY~
|
||||
}
|
||||
|
||||
public override Point3D GetSpawnPosition(ISpawnable spawned, Map map)
|
||||
{
|
||||
if (m_SpawnRegion == null || map == null || map == Map.Internal || map != m_SpawnRegion.Map || m_SpawnRegion.TotalWeight <= 0)
|
||||
return Location;
|
||||
|
||||
bool waterMob, waterOnlyMob;
|
||||
|
||||
if (spawned is Mobile mob)
|
||||
{
|
||||
waterMob = mob.CanSwim;
|
||||
waterOnlyMob = mob.CanSwim && mob.CantWalk;
|
||||
}
|
||||
else
|
||||
{
|
||||
waterMob = false;
|
||||
waterOnlyMob = false;
|
||||
}
|
||||
|
||||
// Try 10 times to find a valid location.
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
int rand = Utility.Random(m_SpawnRegion.TotalWeight);
|
||||
|
||||
int x = int.MinValue;
|
||||
int y = int.MinValue;
|
||||
|
||||
for (int j = 0; j < m_SpawnRegion.RectangleWeights.Length; j++)
|
||||
{
|
||||
int curWeight = m_SpawnRegion.RectangleWeights[j];
|
||||
|
||||
if (rand < curWeight)
|
||||
{
|
||||
Rectangle3D rect = m_SpawnRegion.Rectangles[j];
|
||||
|
||||
x = rect.Start.X + rand % rect.Width;
|
||||
y = rect.Start.Y + rand / rect.Width;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
rand -= curWeight;
|
||||
}
|
||||
|
||||
int mapZ = map.GetAverageZ(x, y);
|
||||
|
||||
if (waterMob)
|
||||
{
|
||||
if (IsValidWater(map, x, y, Z))
|
||||
return new Point3D(x, y, Z);
|
||||
if (IsValidWater(map, x, y, mapZ))
|
||||
return new Point3D(x, y, mapZ);
|
||||
}
|
||||
|
||||
if (!waterOnlyMob)
|
||||
{
|
||||
if (map.CanSpawnMobile(x, y, Z))
|
||||
return new Point3D(x, y, Z);
|
||||
if (map.CanSpawnMobile(x, y, mapZ))
|
||||
return new Point3D(x, y, mapZ);
|
||||
}
|
||||
}
|
||||
|
||||
return HomeLocation;
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
m_SpawnRegion = Region.Find(reader.ReadString(), Map) as BaseRegion;
|
||||
m_SpawnRegion?.InitRectangles();
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(m_SpawnRegion?.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
139
Projects/UOContent/Engines/Spawners/Spawner.cs
Normal file
139
Projects/UOContent/Engines/Spawners/Spawner.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class Spawner : BaseSpawner
|
||||
{
|
||||
public static bool IsValidWater(Map map, int x, int y, int z)
|
||||
{
|
||||
if (!Region.Find(new Point3D(x, y, z), map).AllowSpawn() || !map.CanFit(x, y, z, 16, false, true, false))
|
||||
return false;
|
||||
|
||||
LandTile landTile = map.Tiles.GetLandTile(x, y);
|
||||
|
||||
if (landTile.Z == z && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) != 0)
|
||||
return true;
|
||||
|
||||
StaticTile[] staticTiles = map.Tiles.GetStaticTiles(x, y, true);
|
||||
|
||||
for (int i = 0; i < staticTiles.Length; ++i)
|
||||
{
|
||||
StaticTile staticTile = staticTiles[i];
|
||||
|
||||
if (staticTile.Z == z &&
|
||||
(TileData.ItemTable[staticTile.ID & TileData.MaxItemValue].Flags & TileFlag.Wet) != 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public Spawner()
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public Spawner(string spawnedName) : base(spawnedName)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public Spawner(int amount, int minDelay, int maxDelay, int team, int homeRange,
|
||||
params string[] spawnedNames) : this(amount, TimeSpan.FromMinutes(minDelay), TimeSpan.FromMinutes(maxDelay),
|
||||
team, homeRange, spawnedNames)
|
||||
{
|
||||
}
|
||||
|
||||
[Constructible(AccessLevel.Developer)]
|
||||
public Spawner(int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange,
|
||||
params string[] spawnedNames) : base(amount, minDelay, maxDelay, team, homeRange, spawnedNames)
|
||||
{
|
||||
}
|
||||
|
||||
public Spawner(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public Spawner(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
public override bool OnDefragSpawn(ISpawnable spawned, bool remove)
|
||||
{
|
||||
// To despawn a mob that was lured 4x away from its spawner
|
||||
// TODO: Move this to a config
|
||||
if (spawned is BaseCreature c && c.Combatant == null && c.GetDistanceToSqrt( Location ) > c.RangeHome * 4)
|
||||
{
|
||||
c.Delete();
|
||||
remove = true;
|
||||
}
|
||||
|
||||
return base.OnDefragSpawn(entry, spawned, remove);
|
||||
}
|
||||
*/
|
||||
|
||||
public override Point3D GetSpawnPosition(ISpawnable spawned, Map map)
|
||||
{
|
||||
if (map == null || map == Map.Internal)
|
||||
return Location;
|
||||
|
||||
bool waterMob, waterOnlyMob;
|
||||
|
||||
if (spawned is Mobile mob)
|
||||
{
|
||||
waterMob = mob.CanSwim;
|
||||
waterOnlyMob = mob.CanSwim && mob.CantWalk;
|
||||
}
|
||||
else
|
||||
{
|
||||
waterMob = false;
|
||||
waterOnlyMob = false;
|
||||
}
|
||||
|
||||
// Try 10 times to find a valid location.
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
int x = Location.X + (Utility.Random(HomeRange * 2 + 1) - HomeRange);
|
||||
int y = Location.Y + (Utility.Random(HomeRange * 2 + 1) - HomeRange);
|
||||
|
||||
int mapZ = map.GetAverageZ(x, y);
|
||||
|
||||
if (waterMob)
|
||||
{
|
||||
if (IsValidWater(map, x, y, Z))
|
||||
return new Point3D(x, y, Z);
|
||||
if (IsValidWater(map, x, y, mapZ))
|
||||
return new Point3D(x, y, mapZ);
|
||||
}
|
||||
|
||||
if (!waterOnlyMob)
|
||||
{
|
||||
if (map.CanSpawnMobile(x, y, Z))
|
||||
return new Point3D(x, y, Z);
|
||||
if (map.CanSpawnMobile(x, y, mapZ))
|
||||
return new Point3D(x, y, mapZ);
|
||||
}
|
||||
}
|
||||
|
||||
return HomeLocation;
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
}
|
||||
}
|
||||
}
|
||||
113
Projects/UOContent/Engines/Spawners/SpawnerEntry.cs
Normal file
113
Projects/UOContent/Engines/Spawners/SpawnerEntry.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class SpawnerEntry
|
||||
{
|
||||
public SpawnerEntry() => Spawned = new List<ISpawnable>();
|
||||
|
||||
public SpawnerEntry(string name, int probability, int maxcount) : this()
|
||||
{
|
||||
SpawnedName = name;
|
||||
SpawnedProbability = probability;
|
||||
SpawnedMaxCount = maxcount;
|
||||
}
|
||||
|
||||
public SpawnerEntry(BaseSpawner parent, IGenericReader reader)
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
|
||||
SpawnedName = reader.ReadString();
|
||||
SpawnedProbability = reader.ReadInt();
|
||||
SpawnedMaxCount = reader.ReadInt();
|
||||
|
||||
Properties = reader.ReadString();
|
||||
Parameters = reader.ReadString();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
|
||||
Spawned = new List<ISpawnable>(count);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
// IEntity e = World.FindEntity( reader.ReadInt() );
|
||||
|
||||
if (reader.ReadEntity() is ISpawnable e)
|
||||
{
|
||||
e.Spawner = parent;
|
||||
|
||||
if (e is BaseCreature creature)
|
||||
creature.RemoveIfUntamed = true;
|
||||
|
||||
Spawned.Add(e);
|
||||
|
||||
if (!parent.Spawned.ContainsKey(e))
|
||||
parent.Spawned.Add(e, this);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("probability")]
|
||||
public int SpawnedProbability { get; set; }
|
||||
|
||||
[JsonPropertyName("maxCount")]
|
||||
public int SpawnedMaxCount { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string SpawnedName { get; set; }
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public string Properties { get; set; }
|
||||
|
||||
[JsonPropertyName("parameters")]
|
||||
public string Parameters { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public EntryFlags Valid { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<ISpawnable> Spawned { get; }
|
||||
|
||||
public bool IsFull => Spawned.Count >= SpawnedMaxCount;
|
||||
|
||||
public void Serialize(IGenericWriter writer)
|
||||
{
|
||||
writer.Write(0); // version
|
||||
|
||||
writer.Write(SpawnedName);
|
||||
writer.Write(SpawnedProbability);
|
||||
writer.Write(SpawnedMaxCount);
|
||||
|
||||
writer.Write(Properties);
|
||||
writer.Write(Parameters);
|
||||
|
||||
writer.Write(Spawned.Count);
|
||||
|
||||
for (int i = 0; i < Spawned.Count; ++i)
|
||||
{
|
||||
object o = Spawned[i];
|
||||
|
||||
if (o is Item item)
|
||||
writer.Write(item);
|
||||
else if (o is Mobile mobile)
|
||||
writer.Write(mobile);
|
||||
else
|
||||
writer.Write(Serial.MinusOne);
|
||||
}
|
||||
}
|
||||
|
||||
public void Defrag(BaseSpawner parent)
|
||||
{
|
||||
for (int i = 0; i < Spawned.Count; ++i)
|
||||
{
|
||||
ISpawnable spawned = Spawned[i];
|
||||
|
||||
if (parent.OnDefragSpawn(spawned, false))
|
||||
{
|
||||
Spawned.RemoveAt(i--);
|
||||
parent.Spawned.Remove(spawned);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
295
Projects/UOContent/Engines/Spawners/SpawnerGump.cs
Normal file
295
Projects/UOContent/Engines/Spawners/SpawnerGump.cs
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class SpawnerGump : Gump
|
||||
{
|
||||
private SpawnerEntry m_Entry;
|
||||
private int m_Page;
|
||||
private readonly BaseSpawner m_Spawner;
|
||||
|
||||
public SpawnerGump(BaseSpawner spawner, SpawnerEntry focusentry = null, int page = 0) : base(50, 50)
|
||||
{
|
||||
m_Spawner = spawner;
|
||||
m_Entry = focusentry;
|
||||
m_Page = page;
|
||||
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 343, 371 + (m_Entry != null ? 44 : 0), 5054);
|
||||
|
||||
AddHtml(95, 1, 250, 20, "<BASEFONT COLOR=#F4F4F4>Creatures List</BASEFONT>");
|
||||
AddHtml(245, 1, 250, 20, "<BASEFONT COLOR=#F4F4F4>#</BASEFONT>");
|
||||
AddHtml(282, 1, 250, 20, "<BASEFONT COLOR=#F4F4F4>Prb</BASEFONT>");
|
||||
|
||||
// AddLabel( 95, 1, 0, "Creatures List" );
|
||||
|
||||
int offset = 0;
|
||||
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
int textindex = i * 5;
|
||||
int entryindex = m_Page * 13 + i;
|
||||
|
||||
SpawnerEntry entry = null;
|
||||
|
||||
if (entryindex < spawner.Entries.Count)
|
||||
entry = m_Spawner.Entries[entryindex];
|
||||
|
||||
if (entry == null || m_Entry != entry)
|
||||
AddButton(5, 22 * i + 21 + offset, entry != null ? 0xFBA : 0xFA5, entry != null ? 0xFBC : 0xFA7,
|
||||
GetButtonID(2, i * 2)); // Expand
|
||||
else
|
||||
AddButton(5, 22 * i + 21 + offset, 0xFBB, 0xFBC,
|
||||
GetButtonID(2, i * 2)); // Unexpand
|
||||
|
||||
AddButton(38, 22 * i + 21 + offset, 0xFA2, 0xFA4, GetButtonID(2, 1 + i * 2)); // Delete
|
||||
|
||||
AddImageTiled(71, 22 * i + 20 + offset, 161, 23, 0xA40); // creature text box
|
||||
AddImageTiled(72, 22 * i + 21 + offset, 159, 21, 0xBBC); // creature text box
|
||||
|
||||
AddImageTiled(235, 22 * i + 20 + offset, 35, 23, 0xA40); // maxcount text box
|
||||
AddImageTiled(236, 22 * i + 21 + offset, 33, 21, 0xBBC); // maxcount text box
|
||||
|
||||
AddImageTiled(273, 22 * i + 20 + offset, 35, 23, 0xA40); // probability text box
|
||||
AddImageTiled(274, 22 * i + 21 + offset, 33, 21, 0xBBC); // probability text box
|
||||
|
||||
string name = "";
|
||||
string probability = "";
|
||||
string maxcount = "";
|
||||
EntryFlags flags = EntryFlags.None;
|
||||
|
||||
if (entry != null)
|
||||
{
|
||||
name = entry.SpawnedName;
|
||||
probability = entry.SpawnedProbability.ToString();
|
||||
maxcount = entry.SpawnedMaxCount.ToString();
|
||||
flags = entry.Valid;
|
||||
|
||||
AddLabel(315, 22 * i + 20 + offset, 0, spawner.CountSpawns(entry).ToString());
|
||||
}
|
||||
|
||||
AddTextEntry(75, 22 * i + 21 + offset, 156, 21, (flags & EntryFlags.InvalidType) != 0 ? 33 : 0, textindex,
|
||||
name); // creature
|
||||
AddTextEntry(239, 22 * i + 21 + offset, 30, 21, 0, textindex + 1, maxcount); // max count
|
||||
AddTextEntry(277, 22 * i + 21 + offset, 30, 21, 0, textindex + 2, probability); // probability
|
||||
|
||||
if (entry != null && m_Entry == entry)
|
||||
{
|
||||
AddLabel(5, 22 * i + 42, 0x384, "Params");
|
||||
AddImageTiled(55, 22 * i + 42, 253, 23, 0xA40); // Parameters
|
||||
AddImageTiled(56, 22 * i + 43, 251, 21, 0xBBC); // Parameters
|
||||
|
||||
AddLabel(5, 22 * i + 64, 0x384, "Props");
|
||||
AddImageTiled(55, 22 * i + 64, 253, 23, 0xA40); // Properties
|
||||
AddImageTiled(56, 22 * i + 65, 251, 21, 0xBBC); // Properties
|
||||
|
||||
AddTextEntry(59, 22 * i + 42, 248, 21, (flags & EntryFlags.InvalidParams) != 0 ? 33 : 0, textindex + 3,
|
||||
entry.Parameters); // parameters
|
||||
AddTextEntry(59, 22 * i + 62, 248, 21, (flags & EntryFlags.InvalidProps) != 0 ? 33 : 0, textindex + 4,
|
||||
entry.Properties); // properties
|
||||
|
||||
offset += 44;
|
||||
}
|
||||
}
|
||||
|
||||
AddButton(5, 347 + offset, 0xFB1, 0xFB3, 0);
|
||||
AddLabel(38, 347 + offset, 0x384, "Cancel");
|
||||
|
||||
AddButton(5, 325 + offset, 0xFB7, 0xFB9, GetButtonID(1, 2));
|
||||
AddLabel(38, 325 + offset, 0x384, "Okay");
|
||||
|
||||
AddButton(110, 325 + offset, 0xFB4, 0xFB6, GetButtonID(1, 3));
|
||||
AddLabel(143, 325 + offset, 0x384, "Bring to Home");
|
||||
|
||||
AddButton(110, 347 + offset, 0xFA8, 0xFAA, GetButtonID(1, 4));
|
||||
AddLabel(143, 347 + offset, 0x384, "Total Respawn");
|
||||
|
||||
AddButton(253, 325 + offset, 0xFB7, 0xFB9, GetButtonID(1, 5));
|
||||
AddLabel(286, 325 + offset, 0x384, "Apply");
|
||||
|
||||
if (m_Page > 0)
|
||||
AddButton(276, 308 + offset, 0x15E3, 0x15E7, GetButtonID(1, 0));
|
||||
else
|
||||
AddImage(276, 308 + offset, 0x25EA);
|
||||
|
||||
if ((m_Page + 1) * 13 <= m_Spawner.Entries.Count)
|
||||
AddButton(293, 308 + offset, 0x15E1, 0x15E5, GetButtonID(1, 1));
|
||||
else
|
||||
AddImage(293, 308 + offset, 0x25E6);
|
||||
}
|
||||
|
||||
public int GetButtonID(int type, int index) => 1 + index * 10 + type;
|
||||
|
||||
public void CreateArray(RelayInfo info, Mobile from, BaseSpawner spawner)
|
||||
{
|
||||
int ocount = spawner.Entries.Count;
|
||||
|
||||
List<SpawnerEntry> rementries = new List<SpawnerEntry>();
|
||||
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
int index = i * 5;
|
||||
int entryindex = m_Page * 13 + i;
|
||||
|
||||
TextRelay cte = info.GetTextEntry(index);
|
||||
TextRelay mte = info.GetTextEntry(index + 1);
|
||||
TextRelay poste = info.GetTextEntry(index + 2);
|
||||
TextRelay parmte = info.GetTextEntry(index + 3);
|
||||
TextRelay propte = info.GetTextEntry(index + 4);
|
||||
|
||||
if (cte == null)
|
||||
continue;
|
||||
|
||||
string str = cte.Text.Trim().ToLower();
|
||||
|
||||
if (str.Length > 0)
|
||||
{
|
||||
Type type = AssemblyHandler.FindFirstTypeForName(str);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
from.SendMessage("{0} is not a valid type name for entry #{1}.", str, i);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnerEntry entry;
|
||||
|
||||
if (entryindex < ocount)
|
||||
{
|
||||
entry = spawner.Entries[entryindex];
|
||||
entry.SpawnedName = str;
|
||||
|
||||
if (mte != null)
|
||||
entry.SpawnedMaxCount = Utility.ToInt32(mte.Text.Trim());
|
||||
|
||||
if (poste != null)
|
||||
entry.SpawnedProbability = Utility.ToInt32(poste.Text.Trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
int maxcount = 1;
|
||||
int probcount = 100;
|
||||
|
||||
if (mte != null)
|
||||
maxcount = Utility.ToInt32(mte.Text.Trim());
|
||||
|
||||
if (poste != null)
|
||||
probcount = Utility.ToInt32(poste.Text.Trim());
|
||||
|
||||
entry = spawner.AddEntry(str, probcount, maxcount);
|
||||
}
|
||||
|
||||
if (parmte != null)
|
||||
entry.Parameters = parmte.Text.Trim();
|
||||
|
||||
if (propte != null)
|
||||
entry.Properties = propte.Text.Trim();
|
||||
}
|
||||
else if (entryindex < ocount && spawner.Entries[entryindex] != null)
|
||||
{
|
||||
rementries.Add(spawner.Entries[entryindex]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < rementries.Count; i++)
|
||||
spawner.RemoveEntry(rementries[i]);
|
||||
|
||||
if (ocount == 0 && spawner.Entries.Count > 0)
|
||||
spawner.Start();
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState state, RelayInfo info)
|
||||
{
|
||||
if (m_Spawner.Deleted)
|
||||
return;
|
||||
|
||||
int val = info.ButtonID - 1;
|
||||
|
||||
if (val < 0)
|
||||
return;
|
||||
|
||||
int type = val % 10;
|
||||
int index = val / 10;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0: // Cancel
|
||||
return;
|
||||
case 1:
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (m_Spawner.Entries != null && m_Page > 0)
|
||||
{
|
||||
m_Page--;
|
||||
m_Entry = null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if ((m_Page + 1) * 13 <= m_Spawner.Entries?.Count)
|
||||
{
|
||||
m_Page++;
|
||||
m_Entry = null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2: // Okay
|
||||
{
|
||||
CreateArray(info, state.Mobile, m_Spawner);
|
||||
return;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
m_Spawner.BringToHome();
|
||||
break;
|
||||
}
|
||||
case 4: // Complete respawn
|
||||
{
|
||||
m_Spawner.Respawn();
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
CreateArray(info, state.Mobile, m_Spawner);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
int entryindex = index / 2 + m_Page * 13;
|
||||
int buttontype = index % 2;
|
||||
|
||||
if (entryindex >= 0 && entryindex < m_Spawner.Entries.Count)
|
||||
{
|
||||
SpawnerEntry entry = m_Spawner.Entries[entryindex];
|
||||
if (buttontype == 0) // Spawn creature
|
||||
m_Entry = m_Entry != entry ? entry : null;
|
||||
else // Remove creatures
|
||||
m_Spawner.RemoveSpawn(entryindex);
|
||||
}
|
||||
|
||||
CreateArray(info, state.Mobile, m_Spawner);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Entry != null && m_Spawner.Entries?.Contains(m_Entry) == true)
|
||||
state.Mobile.SendGump(new SpawnerGump(m_Spawner, m_Entry, m_Page));
|
||||
else
|
||||
state.Mobile.SendGump(new SpawnerGump(m_Spawner, null, m_Page));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue