Convert Regions/Spawns to JSON (#138)
This commit is contained in:
parent
b8316e9202
commit
390f30e706
117 changed files with 97306 additions and 4848 deletions
|
|
@ -1,35 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Json;
|
||||
using Server.Mobiles;
|
||||
using Server.Spells;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public enum SpawnZLevel
|
||||
{
|
||||
Lowest,
|
||||
Highest,
|
||||
Random
|
||||
}
|
||||
|
||||
public class BaseRegion : Region
|
||||
{
|
||||
private static readonly List<Rectangle3D> m_RectBuffer1 = new List<Rectangle3D>();
|
||||
private static readonly List<Rectangle3D> m_RectBuffer2 = new List<Rectangle3D>();
|
||||
|
||||
private static readonly List<int> m_SpawnBuffer1 = new List<int>();
|
||||
private static readonly List<Item> m_SpawnBuffer2 = new List<Item>();
|
||||
private bool m_ExcludeFromParentSpawns;
|
||||
public bool ExcludeFromParentSpawns { get; set; }
|
||||
|
||||
private Rectangle3D[] m_Rectangles;
|
||||
private int[] m_RectangleWeights;
|
||||
public Rectangle3D[] Rectangles { get; private set; }
|
||||
public int[] RectangleWeights { get; private set; }
|
||||
|
||||
private string m_RuneName;
|
||||
|
||||
private SpawnEntry[] m_Spawns;
|
||||
private int m_TotalWeight;
|
||||
public int TotalWeight { get; private set; }
|
||||
|
||||
public BaseRegion(string name, Map map, int priority, params Rectangle2D[] area) : base(name, map, priority, area)
|
||||
{
|
||||
|
|
@ -47,63 +37,12 @@ namespace Server.Regions
|
|||
{
|
||||
}
|
||||
|
||||
public BaseRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
public BaseRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
ReadString(xml["rune"], "name", ref m_RuneName, false);
|
||||
if (json.data.TryGetValue("rune", out var runeName))
|
||||
m_RuneName = runeName.GetString();
|
||||
|
||||
bool logoutDelayActive = true;
|
||||
ReadBoolean(xml["logoutDelay"], "active", ref logoutDelayActive, false);
|
||||
NoLogoutDelay = !logoutDelayActive;
|
||||
|
||||
XmlElement spawning = xml["spawning"];
|
||||
if (spawning != null)
|
||||
{
|
||||
ReadBoolean(spawning, "excludeFromParent", ref m_ExcludeFromParentSpawns, false);
|
||||
|
||||
SpawnZLevel zLevel = SpawnZLevel.Lowest;
|
||||
ReadEnum(spawning, "zLevel", ref zLevel, false);
|
||||
SpawnZLevel = zLevel;
|
||||
|
||||
List<SpawnEntry> list = new List<SpawnEntry>();
|
||||
|
||||
foreach (XmlNode node in spawning.ChildNodes)
|
||||
if (node is XmlElement el)
|
||||
{
|
||||
SpawnDefinition def = SpawnDefinition.GetSpawnDefinition(el);
|
||||
if (def == null)
|
||||
continue;
|
||||
|
||||
int id = 0;
|
||||
if (!ReadInt32(el, "id", ref id, true))
|
||||
continue;
|
||||
|
||||
int amount = 0;
|
||||
if (!ReadInt32(el, "amount", ref amount, true))
|
||||
continue;
|
||||
|
||||
TimeSpan minSpawnTime = SpawnEntry.DefaultMinSpawnTime;
|
||||
ReadTimeSpan(el, "minSpawnTime", ref minSpawnTime, false);
|
||||
|
||||
TimeSpan maxSpawnTime = SpawnEntry.DefaultMaxSpawnTime;
|
||||
ReadTimeSpan(el, "maxSpawnTime", ref maxSpawnTime, false);
|
||||
|
||||
Point3D home = Point3D.Zero;
|
||||
int range = 0;
|
||||
|
||||
XmlElement homeEl = el["home"];
|
||||
if (ReadPoint3D(homeEl, map, ref home, false))
|
||||
ReadInt32(homeEl, "range", ref range, false);
|
||||
|
||||
Direction dir = SpawnEntry.InvalidDirection;
|
||||
ReadEnum(el["direction"], "value", ref dir, false);
|
||||
|
||||
SpawnEntry entry = new SpawnEntry(id, this, home, range, dir, def, amount, minSpawnTime,
|
||||
maxSpawnTime);
|
||||
list.Add(entry);
|
||||
}
|
||||
|
||||
if (list.Count > 0) m_Spawns = list.ToArray();
|
||||
}
|
||||
NoLogoutDelay = json.data.TryGetValue("logoutDelay", out var logoutDelay) && !logoutDelay.GetBoolean();
|
||||
}
|
||||
|
||||
public virtual bool YoungProtected => true;
|
||||
|
|
@ -121,39 +60,11 @@ namespace Server.Regions
|
|||
|
||||
public bool NoLogoutDelay { get; set; }
|
||||
|
||||
public SpawnEntry[] Spawns
|
||||
{
|
||||
get => m_Spawns;
|
||||
set
|
||||
{
|
||||
if (m_Spawns != null)
|
||||
for (int i = 0; i < m_Spawns.Length; i++)
|
||||
m_Spawns[i].Delete();
|
||||
|
||||
m_Spawns = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SpawnZLevel SpawnZLevel { get; set; }
|
||||
|
||||
public bool ExcludeFromParentSpawns
|
||||
{
|
||||
get => m_ExcludeFromParentSpawns;
|
||||
set => m_ExcludeFromParentSpawns = value;
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
DefaultRegionType = typeof(BaseRegion);
|
||||
}
|
||||
|
||||
public override void OnUnregister()
|
||||
{
|
||||
base.OnUnregister();
|
||||
|
||||
Spawns = null;
|
||||
}
|
||||
|
||||
public static string GetRuneNameFor(Region region)
|
||||
{
|
||||
while (region != null)
|
||||
|
|
@ -169,61 +80,24 @@ namespace Server.Regions
|
|||
return null;
|
||||
}
|
||||
|
||||
public override TimeSpan GetLogoutDelay(Mobile m)
|
||||
{
|
||||
if (NoLogoutDelay)
|
||||
if (m.Aggressors.Count == 0 && m.Aggressed.Count == 0 && !m.Criminal)
|
||||
return TimeSpan.Zero;
|
||||
|
||||
return base.GetLogoutDelay(m);
|
||||
}
|
||||
|
||||
public static bool CanSpawn(Region region, params Type[] types)
|
||||
{
|
||||
while (region != null)
|
||||
{
|
||||
if (!region.AllowSpawn())
|
||||
return false;
|
||||
|
||||
if (region is BaseRegion br)
|
||||
{
|
||||
if (br.Spawns != null)
|
||||
for (int i = 0; i < br.Spawns.Length; i++)
|
||||
{
|
||||
SpawnEntry entry = br.Spawns[i];
|
||||
|
||||
if (entry.Definition.CanSpawn(types))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (br.ExcludeFromParentSpawns)
|
||||
return false;
|
||||
}
|
||||
|
||||
region = region.Parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public override TimeSpan GetLogoutDelay(Mobile m) =>
|
||||
NoLogoutDelay && m.Aggressors.Count == 0 && m.Aggressed.Count == 0 && !m.Criminal
|
||||
? TimeSpan.Zero
|
||||
: base.GetLogoutDelay(m);
|
||||
|
||||
public override void OnEnter(Mobile m)
|
||||
{
|
||||
if (m is PlayerMobile mobile && mobile.Young)
|
||||
if (!YoungProtected)
|
||||
mobile.SendGump(new YoungDungeonWarning());
|
||||
if (m is PlayerMobile mobile && mobile.Young && !YoungProtected)
|
||||
mobile.SendGump(new YoungDungeonWarning());
|
||||
}
|
||||
|
||||
public override bool AcceptsSpawnsFrom(Region region)
|
||||
{
|
||||
if (region == this || !m_ExcludeFromParentSpawns)
|
||||
return base.AcceptsSpawnsFrom(region);
|
||||
public override bool AcceptsSpawnsFrom(Region region) =>
|
||||
(region == this || !ExcludeFromParentSpawns) && base.AcceptsSpawnsFrom(region);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void InitRectangles()
|
||||
// TODO: Clean this up
|
||||
public void InitRectangles()
|
||||
{
|
||||
if (m_Rectangles != null)
|
||||
if (Rectangles != null)
|
||||
return;
|
||||
|
||||
// Test if area rectangles are overlapping, and in that case break them into smaller non overlapping rectangles
|
||||
|
|
@ -270,277 +144,22 @@ namespace Server.Regions
|
|||
m_RectBuffer2.Clear();
|
||||
}
|
||||
|
||||
m_Rectangles = m_RectBuffer1.ToArray();
|
||||
Rectangles = m_RectBuffer1.ToArray();
|
||||
m_RectBuffer1.Clear();
|
||||
|
||||
m_RectangleWeights = new int[m_Rectangles.Length];
|
||||
for (int i = 0; i < m_Rectangles.Length; i++)
|
||||
RectangleWeights = new int[Rectangles.Length];
|
||||
for (int i = 0; i < Rectangles.Length; i++)
|
||||
{
|
||||
Rectangle3D rect = m_Rectangles[i];
|
||||
Rectangle3D rect = Rectangles[i];
|
||||
int weight = rect.Width * rect.Height;
|
||||
|
||||
m_RectangleWeights[i] = weight;
|
||||
m_TotalWeight += weight;
|
||||
RectangleWeights[i] = weight;
|
||||
TotalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water, Point3D home, int range)
|
||||
{
|
||||
Map map = Map;
|
||||
public override string ToString() => Name ?? RuneName ?? GetType().Name;
|
||||
|
||||
if (map == Map.Internal)
|
||||
return Point3D.Zero;
|
||||
|
||||
InitRectangles();
|
||||
|
||||
if (m_TotalWeight <= 0)
|
||||
return Point3D.Zero;
|
||||
|
||||
for (int i = 0; i < 10; i++) // Try 10 times
|
||||
{
|
||||
int x, y, minZ, maxZ;
|
||||
|
||||
if (home == Point3D.Zero)
|
||||
{
|
||||
int rand = Utility.Random(m_TotalWeight);
|
||||
|
||||
x = int.MinValue;
|
||||
y = int.MinValue;
|
||||
minZ = int.MaxValue;
|
||||
maxZ = int.MinValue;
|
||||
for (int j = 0; j < m_RectangleWeights.Length; j++)
|
||||
{
|
||||
int curWeight = m_RectangleWeights[j];
|
||||
|
||||
if (rand < curWeight)
|
||||
{
|
||||
Rectangle3D rect = m_Rectangles[j];
|
||||
|
||||
x = rect.Start.X + rand % rect.Width;
|
||||
y = rect.Start.Y + rand / rect.Width;
|
||||
|
||||
minZ = rect.Start.Z;
|
||||
maxZ = rect.End.Z;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
rand -= curWeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = Utility.RandomMinMax(home.X - range, home.X + range);
|
||||
y = Utility.RandomMinMax(home.Y - range, home.Y + range);
|
||||
|
||||
minZ = int.MaxValue;
|
||||
maxZ = int.MinValue;
|
||||
for (int j = 0; j < Area.Length; j++)
|
||||
{
|
||||
Rectangle3D rect = Area[j];
|
||||
|
||||
if (x >= rect.Start.X && x < rect.End.X && y >= rect.Start.Y && y < rect.End.Y)
|
||||
{
|
||||
minZ = rect.Start.Z;
|
||||
maxZ = rect.End.Z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (minZ == int.MaxValue)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (x < 0 || y < 0 || x >= map.Width || y >= map.Height)
|
||||
continue;
|
||||
|
||||
LandTile lt = map.Tiles.GetLandTile(x, y);
|
||||
|
||||
int ltLowZ = 0, ltAvgZ = 0, ltTopZ = 0;
|
||||
map.GetAverageZ(x, y, ref ltLowZ, ref ltAvgZ, ref ltTopZ);
|
||||
|
||||
TileFlag ltFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags;
|
||||
bool ltImpassable = (ltFlags & TileFlag.Impassable) != 0;
|
||||
|
||||
if (!lt.Ignored && ltAvgZ >= minZ && ltAvgZ < maxZ)
|
||||
if ((ltFlags & TileFlag.Wet) != 0)
|
||||
{
|
||||
if (water)
|
||||
m_SpawnBuffer1.Add(ltAvgZ);
|
||||
}
|
||||
else if (land && !ltImpassable)
|
||||
{
|
||||
m_SpawnBuffer1.Add(ltAvgZ);
|
||||
}
|
||||
|
||||
StaticTile[] staticTiles = map.Tiles.GetStaticTiles(x, y, true);
|
||||
|
||||
for (int j = 0; j < staticTiles.Length; j++)
|
||||
{
|
||||
StaticTile tile = staticTiles[j];
|
||||
ItemData id = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
|
||||
int tileZ = tile.Z + id.CalcHeight;
|
||||
|
||||
if (tileZ >= minZ && tileZ < maxZ)
|
||||
if ((id.Flags & TileFlag.Wet) != 0)
|
||||
{
|
||||
if (water)
|
||||
m_SpawnBuffer1.Add(tileZ);
|
||||
}
|
||||
else if (land && id.Surface && !id.Impassable)
|
||||
{
|
||||
m_SpawnBuffer1.Add(tileZ);
|
||||
}
|
||||
}
|
||||
|
||||
Sector sector = map.GetSector(x, y);
|
||||
|
||||
for (int j = 0; j < sector.Items.Count; j++)
|
||||
{
|
||||
Item item = sector.Items[j];
|
||||
|
||||
if (!(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue && item.AtWorldPoint(x, y))
|
||||
{
|
||||
m_SpawnBuffer2.Add(item);
|
||||
|
||||
if (!item.Movable)
|
||||
{
|
||||
ItemData id = item.ItemData;
|
||||
int itemZ = item.Z + id.CalcHeight;
|
||||
|
||||
if (itemZ >= minZ && itemZ < maxZ)
|
||||
if ((id.Flags & TileFlag.Wet) != 0)
|
||||
{
|
||||
if (water)
|
||||
m_SpawnBuffer1.Add(itemZ);
|
||||
}
|
||||
else if (land && id.Surface && !id.Impassable)
|
||||
{
|
||||
m_SpawnBuffer1.Add(itemZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_SpawnBuffer1.Count == 0)
|
||||
{
|
||||
m_SpawnBuffer1.Clear();
|
||||
m_SpawnBuffer2.Clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
int z;
|
||||
switch (SpawnZLevel)
|
||||
{
|
||||
case SpawnZLevel.Lowest:
|
||||
{
|
||||
z = int.MaxValue;
|
||||
|
||||
for (int j = 0; j < m_SpawnBuffer1.Count; j++)
|
||||
{
|
||||
int l = m_SpawnBuffer1[j];
|
||||
|
||||
if (l < z)
|
||||
z = l;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SpawnZLevel.Highest:
|
||||
{
|
||||
z = int.MinValue;
|
||||
|
||||
for (int j = 0; j < m_SpawnBuffer1.Count; j++)
|
||||
{
|
||||
int l = m_SpawnBuffer1[j];
|
||||
|
||||
if (l > z)
|
||||
z = l;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: // SpawnZLevel.Random
|
||||
{
|
||||
int index = Utility.Random(m_SpawnBuffer1.Count);
|
||||
z = m_SpawnBuffer1[index];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_SpawnBuffer1.Clear();
|
||||
|
||||
if (!Find(new Point3D(x, y, z), map).AcceptsSpawnsFrom(this))
|
||||
{
|
||||
m_SpawnBuffer2.Clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
int top = z + spawnHeight;
|
||||
|
||||
bool ok = true;
|
||||
for (int j = 0; j < m_SpawnBuffer2.Count; j++)
|
||||
{
|
||||
Item item = m_SpawnBuffer2[j];
|
||||
ItemData id = item.ItemData;
|
||||
|
||||
if ((id.Surface || id.Impassable) && item.Z + id.CalcHeight > z && item.Z < top)
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_SpawnBuffer2.Clear();
|
||||
|
||||
if (!ok)
|
||||
continue;
|
||||
|
||||
if (ltImpassable && ltAvgZ > z && ltLowZ < top)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < staticTiles.Length; j++)
|
||||
{
|
||||
StaticTile tile = staticTiles[j];
|
||||
ItemData id = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
|
||||
|
||||
if ((id.Surface || id.Impassable) && tile.Z + id.CalcHeight > z && tile.Z < top)
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < sector.Mobiles.Count; j++)
|
||||
{
|
||||
Mobile m = sector.Mobiles[j];
|
||||
|
||||
if (m.X == x && m.Y == y && (m.AccessLevel == AccessLevel.Player || !m.Hidden))
|
||||
if (m.Z + 16 > z && m.Z < top)
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok)
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
return Point3D.Zero;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Name != null)
|
||||
return Name;
|
||||
if (RuneName != null)
|
||||
return RuneName;
|
||||
return GetType().Name;
|
||||
}
|
||||
public virtual bool CheckTravel(Mobile m, Point3D newLocation, TravelCheckType travelType) => true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,22 @@
|
|||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class DungeonRegion : BaseRegion
|
||||
{
|
||||
private Point3D m_EntranceLocation;
|
||||
|
||||
public DungeonRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
public DungeonRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
XmlElement entrEl = xml["entrance"];
|
||||
if (json.GetProperty("map", options, out Map map))
|
||||
EntranceMap = map;
|
||||
|
||||
Map entrMap = map;
|
||||
ReadMap(entrEl, "map", ref entrMap, false);
|
||||
|
||||
if (ReadPoint3D(entrEl, entrMap, ref m_EntranceLocation, false))
|
||||
EntranceMap = entrMap;
|
||||
if (json.GetProperty("entrance", options, out Point3D entrance))
|
||||
EntranceLocation = entrance;
|
||||
}
|
||||
|
||||
public override bool YoungProtected => false;
|
||||
|
||||
public Point3D EntranceLocation
|
||||
{
|
||||
get => m_EntranceLocation;
|
||||
set => m_EntranceLocation = value;
|
||||
}
|
||||
public Point3D EntranceLocation { get; set; }
|
||||
|
||||
public Map EntranceMap { get; set; }
|
||||
|
||||
|
|
@ -34,12 +27,6 @@ namespace Server.Regions
|
|||
global = LightCycle.DungeonLevel;
|
||||
}
|
||||
|
||||
public override bool CanUseStuckMenu(Mobile m)
|
||||
{
|
||||
if (Map == Map.Felucca)
|
||||
return false;
|
||||
|
||||
return base.CanUseStuckMenu(m);
|
||||
}
|
||||
public override bool CanUseStuckMenu(Mobile m) => Map != Map.Felucca && base.CanUseStuckMenu(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
using System.Xml;
|
||||
using Server.Spells.Chivalry;
|
||||
using Server.Spells.Fourth;
|
||||
using Server.Spells.Seventh;
|
||||
using Server.Spells.Sixth;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class GreenAcres : BaseRegion
|
||||
{
|
||||
public GreenAcres(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
return false;
|
||||
return base.AllowHousing(from, p);
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if ((s is GateTravelSpell || s is RecallSpell || s is MarkSpell || s is SacredJourneySpell) &&
|
||||
m.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
m.SendMessage("You cannot cast that spell here.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Projects/UOContent/Regions/GreenAcresRegion.cs
Normal file
31
Projects/UOContent/Regions/GreenAcresRegion.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Spells;
|
||||
using Server.Spells.Sixth;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class GreenAcresRegion : BaseRegion
|
||||
{
|
||||
public GreenAcresRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p) =>
|
||||
from.AccessLevel != AccessLevel.Player && base.AllowHousing(from, p);
|
||||
|
||||
public override bool CheckTravel(Mobile m, Point3D newLocation, TravelCheckType travelType) =>
|
||||
m.AccessLevel != AccessLevel.Player;
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if (m.AccessLevel == AccessLevel.Player && s is MarkSpell)
|
||||
{
|
||||
m.SendLocalizedMessage(501802); // Thy spell doth not appear to work...
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Mobiles;
|
||||
using Server.Utilities;
|
||||
|
||||
|
|
@ -14,21 +15,23 @@ namespace Server.Regions
|
|||
private readonly Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
|
||||
private readonly Type m_GuardType;
|
||||
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle3D[] area) : base(name, map, priority, area) => m_GuardType = DefaultGuardType;
|
||||
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area)
|
||||
: base(name, map, priority, area) =>
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle3D[] area) : base(name, map, priority, area) =>
|
||||
m_GuardType = DefaultGuardType;
|
||||
|
||||
public GuardedRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
XmlElement el = xml["guards"];
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area) : base(name, map, priority, area) =>
|
||||
m_GuardType = DefaultGuardType;
|
||||
|
||||
if (ReadType(el, "type", ref m_GuardType, false))
|
||||
public GuardedRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
if (json.GetProperty("guardsType", options, out string guardType))
|
||||
{
|
||||
if (!typeof(Mobile).IsAssignableFrom(m_GuardType))
|
||||
m_GuardType = AssemblyHandler.FindFirstTypeForName(guardType);
|
||||
|
||||
if (!typeof(BaseGuard).IsAssignableFrom(m_GuardType))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Invalid guard type for region '{0}'", this);
|
||||
Console.ResetColor();
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,9 +40,7 @@ namespace Server.Regions
|
|||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
bool disabled = false;
|
||||
if (ReadBoolean(el, "disabled", ref disabled, false))
|
||||
Disabled = disabled;
|
||||
Disabled = json.GetProperty("guardsDisabled", options, out bool disabled) && disabled;
|
||||
}
|
||||
|
||||
public bool Disabled { get; set; }
|
||||
|
|
@ -98,10 +99,9 @@ namespace Server.Regions
|
|||
{
|
||||
reg.Disabled = !e.GetBoolean(0);
|
||||
|
||||
if (reg.Disabled)
|
||||
from.SendMessage("The guards in this region have been disabled.");
|
||||
else
|
||||
from.SendMessage("The guards in this region have been enabled.");
|
||||
from.SendMessage(reg.Disabled
|
||||
? "The guards in this region have been disabled."
|
||||
: "The guards in this region have been enabled.");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -125,10 +125,9 @@ namespace Server.Regions
|
|||
{
|
||||
reg.Disabled = !reg.Disabled;
|
||||
|
||||
if (reg.Disabled)
|
||||
from.SendMessage("The guards in this region have been disabled.");
|
||||
else
|
||||
from.SendMessage("The guards in this region have been enabled.");
|
||||
from.SendMessage(reg.Disabled
|
||||
? "The guards in this region have been disabled."
|
||||
: "The guards in this region have been enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,13 +137,8 @@ namespace Server.Regions
|
|||
return reg;
|
||||
}
|
||||
|
||||
public virtual bool CheckVendorAccess(BaseVendor vendor, Mobile from)
|
||||
{
|
||||
if (from.AccessLevel >= AccessLevel.GameMaster || IsDisabled())
|
||||
return true;
|
||||
|
||||
return from.Kills < 5;
|
||||
}
|
||||
public virtual bool CheckVendorAccess(BaseVendor vendor, Mobile from) =>
|
||||
from.AccessLevel >= AccessLevel.GameMaster || IsDisabled() || from.Kills < 5;
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
|
|
@ -298,7 +292,7 @@ namespace Server.Regions
|
|||
|
||||
foreach (Mobile m in eable)
|
||||
if (IsGuardCandidate(m) &&
|
||||
((!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this)) || m_GuardCandidates.ContainsKey(m)))
|
||||
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
|
||||
{
|
||||
if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
||||
{
|
||||
|
|
@ -314,14 +308,10 @@ namespace Server.Regions
|
|||
eable.Free();
|
||||
}
|
||||
|
||||
public bool IsGuardCandidate(Mobile m)
|
||||
{
|
||||
if (m is BaseGuard || !m.Alive || m.AccessLevel > AccessLevel.Player || m.Blessed ||
|
||||
(m is BaseCreature creature && creature.IsInvulnerable) || IsDisabled())
|
||||
return false;
|
||||
|
||||
return (!AllowReds && m.Kills >= 5) || m.Criminal;
|
||||
}
|
||||
public bool IsGuardCandidate(Mobile m) =>
|
||||
!(m is BaseGuard) && m.Alive && m.AccessLevel <= AccessLevel.Player && !m.Blessed &&
|
||||
(!(m is BaseCreature creature) || !creature.IsInvulnerable) && !IsDisabled() &&
|
||||
(!AllowReds && m.Kills >= 5 || m.Criminal);
|
||||
|
||||
private class GuardTimer : Timer
|
||||
{
|
||||
|
|
@ -338,11 +328,8 @@ namespace Server.Regions
|
|||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (m_Table.ContainsKey(m_Mobile))
|
||||
{
|
||||
m_Table.Remove(m_Mobile);
|
||||
if (m_Table.Remove(m_Mobile))
|
||||
m_Mobile.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
|
@ -82,43 +83,37 @@ namespace Server.Regions
|
|||
|
||||
BaseCreature bc = m as BaseCreature;
|
||||
|
||||
if (bc?.NoHouseRestrictions == true)
|
||||
if (bc?.NoHouseRestrictions != true &&
|
||||
(bc?.IsHouseSummonable != true || BaseCreature.Summoning || House.IsInside(oldLocation, 16)))
|
||||
{
|
||||
}
|
||||
else if (bc?.IsHouseSummonable == true &&
|
||||
!(BaseCreature.Summoning || House.IsInside(oldLocation, 16)))
|
||||
{
|
||||
}
|
||||
else if ((House.Public || !House.IsAosRules) && House.IsBanned(m) && House.IsInside(m))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
|
||||
if (!Core.SE)
|
||||
m.SendLocalizedMessage(501284); // You may not enter.
|
||||
}
|
||||
else if (House.IsAosRules && !House.Public && !House.HasAccess(m) && House.IsInside(m))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
|
||||
if (!Core.SE)
|
||||
m.SendLocalizedMessage(501284); // You may not enter.
|
||||
}
|
||||
else if (House.IsCombatRestricted(m) && House.IsInside(m) && !House.IsInside(oldLocation, 16))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
m.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
|
||||
if (foundation?.Customizer != null && foundation.Customizer != m && House.IsInside(m))
|
||||
if ((House.Public || !House.IsAosRules) && House.IsBanned(m) && House.IsInside(m))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
|
||||
if (!Core.SE)
|
||||
m.SendLocalizedMessage(501284); // You may not enter.
|
||||
}
|
||||
else if (House.IsAosRules && !House.Public && !House.HasAccess(m) && House.IsInside(m))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
|
||||
if (!Core.SE)
|
||||
m.SendLocalizedMessage(501284); // You may not enter.
|
||||
}
|
||||
else if (House.IsCombatRestricted(m) && House.IsInside(m) && !House.IsInside(oldLocation, 16))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
m.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
}
|
||||
else if (House is HouseFoundation foundation && foundation?.Customizer != null && foundation.Customizer != m &&
|
||||
House.IsInside(m))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
}
|
||||
}
|
||||
|
||||
if (House.InternalizedVendors.Count > 0 && House.IsInside(m) && !House.IsInside(oldLocation, 16) &&
|
||||
House.IsOwner(m) && m.Alive &&
|
||||
!m.HasGump<NoticeGump>())
|
||||
House.IsOwner(m) && m.Alive && !m.HasGump<NoticeGump>())
|
||||
m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180));
|
||||
|
||||
m_Recursion = false;
|
||||
|
|
@ -131,48 +126,40 @@ namespace Server.Regions
|
|||
|
||||
BaseCreature bc = from as BaseCreature;
|
||||
|
||||
if (bc?.NoHouseRestrictions == true)
|
||||
if (bc?.NoHouseRestrictions != true)
|
||||
{
|
||||
}
|
||||
else if (bc?.Controlled == false) // Untamed creatures cannot enter public houses
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (bc?.IsHouseSummonable == true &&
|
||||
!(BaseCreature.Summoning || House.IsInside(oldLocation, 16)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (bc?.Controlled == false && House.IsAosRules && !House.Public)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((House.Public || !House.IsAosRules) && House.IsBanned(from) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
from.Location = House.BanLocation;
|
||||
if (bc?.Controlled == false) // Untamed creatures cannot enter public houses
|
||||
return false;
|
||||
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
if (bc?.IsHouseSummonable == true &&
|
||||
!(BaseCreature.Summoning || House.IsInside(oldLocation, 16)))
|
||||
return false;
|
||||
if (bc?.Controlled == false && House.IsAosRules && !House.Public)
|
||||
return false;
|
||||
if ((House.Public || !House.IsAosRules) && House.IsBanned(from) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
from.Location = House.BanLocation;
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (House.IsAosRules && !House.Public && !House.HasAccess(from) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (House.IsCombatRestricted(from) && !House.IsInside(oldLocation, 16) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
from.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
return false;
|
||||
}
|
||||
if (House.IsAosRules && !House.Public && !House.HasAccess(from) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
|
||||
if (foundation?.Customizer != null && foundation.Customizer != from && House.IsInside(newLocation, 16))
|
||||
return false;
|
||||
}
|
||||
if (House.IsCombatRestricted(from) && !House.IsInside(oldLocation, 16) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
from.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (House is HouseFoundation foundation && foundation.Customizer != null && foundation.Customizer != from &&
|
||||
House.IsInside(newLocation, 16))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -184,30 +171,14 @@ namespace Server.Regions
|
|||
return true;
|
||||
}
|
||||
|
||||
public override bool OnDecay(Item item)
|
||||
{
|
||||
if ((House.HasLockedDownItem(item) || House.HasSecureItem(item)) && House.IsInside(item))
|
||||
return false;
|
||||
return base.OnDecay(item);
|
||||
}
|
||||
public override bool OnDecay(Item item) =>
|
||||
(!House.HasLockedDownItem(item) && !House.HasSecureItem(item) || !House.IsInside(item)) && base.OnDecay(item);
|
||||
|
||||
public override TimeSpan GetLogoutDelay(Mobile m)
|
||||
{
|
||||
if (House.IsFriend(m) && House.IsInside(m))
|
||||
{
|
||||
for (int i = 0; i < m.Aggressed.Count; ++i)
|
||||
{
|
||||
AggressorInfo info = m.Aggressed[i];
|
||||
|
||||
if (info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatHeatDelay)
|
||||
return base.GetLogoutDelay(m);
|
||||
}
|
||||
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
return base.GetLogoutDelay(m);
|
||||
}
|
||||
public override TimeSpan GetLogoutDelay(Mobile m) =>
|
||||
House.IsFriend(m) && House.IsInside(m)
|
||||
? m.Aggressed.Any(info => info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatHeatDelay)
|
||||
? base.GetLogoutDelay(m) : TimeSpan.Zero
|
||||
: base.GetLogoutDelay(m);
|
||||
|
||||
public override void OnSpeech(SpeechEventArgs e)
|
||||
{
|
||||
|
|
@ -340,13 +311,13 @@ namespace Server.Regions
|
|||
{
|
||||
SecureAccessResult res = House.CheckSecureAccess(from, c);
|
||||
|
||||
switch (res)
|
||||
if (res == SecureAccessResult.Accessible)
|
||||
return true;
|
||||
|
||||
if (res == SecureAccessResult.Inaccessible)
|
||||
{
|
||||
case SecureAccessResult.Insecure: break;
|
||||
case SecureAccessResult.Accessible: return true;
|
||||
case SecureAccessResult.Inaccessible:
|
||||
c.SendLocalizedMessageTo(from, 1010563);
|
||||
return false;
|
||||
c.SendLocalizedMessageTo(from, 1010563);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +1,35 @@
|
|||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Spells;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class Jail : BaseRegion
|
||||
public class JailRegion : BaseRegion
|
||||
{
|
||||
public Jail(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
public JailRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowBeneficial(Mobile from, Mobile target)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
from.SendMessage("You may not do that in jail.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool AllowHarmful(Mobile from, Mobile target)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
from.SendMessage("You may not do that in jail.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p) => false;
|
||||
|
|
@ -31,22 +39,39 @@ namespace Server.Regions
|
|||
global = LightCycle.JailLevel;
|
||||
}
|
||||
|
||||
public override bool CheckTravel(Mobile m, Point3D newLocation, TravelCheckType travelType)
|
||||
{
|
||||
if (m?.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
m.SendLocalizedMessage(1114345); // You'll need a better jailbreak plan than that!
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CheckTravel(m, newLocation, travelType);
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile from, ISpell s)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
from.SendLocalizedMessage(502629); // You cannot cast spells here.
|
||||
return false;
|
||||
}
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnSkillUse(Mobile from, int Skill)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
from.SendMessage("You may not use skills in jail.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnCombatantChange(Mobile from, Mobile Old, Mobile New) => from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Projects/UOContent/Regions/MondainRegion.cs
Normal file
24
Projects/UOContent/Regions/MondainRegion.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Spells.Sixth;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class MondainRegion : NoTravelSpellsAllowedRegion
|
||||
{
|
||||
public MondainRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if (m.Player && s is MarkSpell)
|
||||
{
|
||||
m.SendLocalizedMessage(501802); // Thy spell doth not appear to work...
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Projects/UOContent/Regions/NewMaginciaRegion.cs
Normal file
13
Projects/UOContent/Regions/NewMaginciaRegion.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Regions;
|
||||
|
||||
namespace Server.Engines.NewMagincia
|
||||
{
|
||||
public class NewMaginciaRegion : TownRegion
|
||||
{
|
||||
public NewMaginciaRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,18 @@
|
|||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class NoHousingRegion : BaseRegion
|
||||
{
|
||||
/* - False: this uses 'stupid OSI' house placement checking: part of the house may be placed here provided that the center is not in the region
|
||||
* - True: this uses 'smart RunUO' house placement checking: no part of the house may be in the region
|
||||
/* False: this uses 'stupid OSI' house placement checking: part of the house may be placed here provided that the center is not in the region
|
||||
* True: this uses 'smart RunUO' house placement checking: no part of the house may be in the region
|
||||
*/
|
||||
private readonly bool m_SmartChecking;
|
||||
public bool SmartChecking { get; }
|
||||
|
||||
public NoHousingRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
ReadBoolean(xml["smartNoHousing"], "active", ref m_SmartChecking, false);
|
||||
}
|
||||
public NoHousingRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options) =>
|
||||
SmartChecking = json.GetProperty("smartNoHousing", options, out bool smartNoHousing) && smartNoHousing;
|
||||
|
||||
public bool SmartChecking => m_SmartChecking;
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p) => m_SmartChecking;
|
||||
public override bool AllowHousing(Mobile from, Point3D p) => SmartChecking;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
Projects/UOContent/Regions/NoTravelSpellsAllowedRegion.cs
Normal file
15
Projects/UOContent/Regions/NoTravelSpellsAllowedRegion.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Text.Json;
|
||||
using Server;
|
||||
using Server.Json;
|
||||
using Server.Regions;
|
||||
using Server.Spells;
|
||||
|
||||
public class NoTravelSpellsAllowedRegion : DungeonRegion
|
||||
{
|
||||
public NoTravelSpellsAllowedRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CheckTravel(Mobile m, Point3D newLocation, TravelCheckType travelType) =>
|
||||
m.AccessLevel == AccessLevel.Player;
|
||||
}
|
||||
|
|
@ -1,380 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Utilities;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public abstract class SpawnDefinition
|
||||
{
|
||||
public abstract ISpawnable Spawn(SpawnEntry entry);
|
||||
|
||||
public abstract bool CanSpawn(params Type[] types);
|
||||
|
||||
public static SpawnDefinition GetSpawnDefinition(XmlElement xml)
|
||||
{
|
||||
switch (xml.Name)
|
||||
{
|
||||
case "object":
|
||||
{
|
||||
Type type = null;
|
||||
if (!Region.ReadType(xml, "type", ref type))
|
||||
return null;
|
||||
|
||||
if (typeof(Mobile).IsAssignableFrom(type)) return SpawnMobile.Get(type);
|
||||
|
||||
if (typeof(Item).IsAssignableFrom(type)) return SpawnItem.Get(type);
|
||||
Console.WriteLine("Invalid type '{0}' in a SpawnDefinition", type.FullName);
|
||||
return null;
|
||||
}
|
||||
case "group":
|
||||
{
|
||||
string group = null;
|
||||
if (!Region.ReadString(xml, "name", ref group))
|
||||
return null;
|
||||
|
||||
if (!SpawnGroup.Table.TryGetValue(group, out SpawnGroup def))
|
||||
{
|
||||
Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group);
|
||||
return null;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
case "treasureChest":
|
||||
{
|
||||
int itemID = 0xE43;
|
||||
Region.ReadInt32(xml, "itemID", ref itemID, false);
|
||||
|
||||
BaseTreasureChest.TreasureLevel level = BaseTreasureChest.TreasureLevel.Level2;
|
||||
|
||||
Region.ReadEnum(xml, "level", ref level, false);
|
||||
|
||||
return new SpawnTreasureChest(itemID, level);
|
||||
}
|
||||
default:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SpawnType : SpawnDefinition
|
||||
{
|
||||
private bool m_Init;
|
||||
|
||||
protected SpawnType(Type type)
|
||||
{
|
||||
Type = type;
|
||||
m_Init = false;
|
||||
}
|
||||
|
||||
public Type Type { get; }
|
||||
|
||||
public abstract int Height { get; }
|
||||
public abstract bool Land { get; }
|
||||
public abstract bool Water { get; }
|
||||
|
||||
protected void EnsureInit()
|
||||
{
|
||||
if (m_Init)
|
||||
return;
|
||||
|
||||
Init();
|
||||
m_Init = true;
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public override ISpawnable Spawn(SpawnEntry entry)
|
||||
{
|
||||
Region region = entry.Region;
|
||||
Map map = region.Map;
|
||||
|
||||
Point3D loc = entry.RandomSpawnLocation(Height, Land, Water);
|
||||
|
||||
if (loc == Point3D.Zero)
|
||||
return null;
|
||||
|
||||
return Construct(entry, loc, map);
|
||||
}
|
||||
|
||||
protected abstract ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map);
|
||||
|
||||
public override bool CanSpawn(params Type[] types)
|
||||
{
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
if (types[i] == Type)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnMobile : SpawnType
|
||||
{
|
||||
private static readonly Dictionary<Type, SpawnMobile> m_Table = new Dictionary<Type, SpawnMobile>();
|
||||
|
||||
private bool m_Land;
|
||||
private bool m_Water;
|
||||
|
||||
public SpawnMobile(Type type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Height => 16;
|
||||
|
||||
public override bool Land
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Land;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Water
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Water;
|
||||
}
|
||||
}
|
||||
|
||||
public static SpawnMobile Get(Type type)
|
||||
{
|
||||
if (!m_Table.TryGetValue(type, out SpawnMobile sm))
|
||||
m_Table[type] = sm = new SpawnMobile(type);
|
||||
|
||||
return sm;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
Mobile mob = (Mobile)ActivatorUtil.CreateInstance(Type);
|
||||
|
||||
m_Land = !mob.CantWalk;
|
||||
m_Water = mob.CanSwim;
|
||||
|
||||
mob.Delete();
|
||||
}
|
||||
|
||||
protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
|
||||
{
|
||||
Mobile mobile = CreateMobile();
|
||||
|
||||
if (mobile is BaseCreature creature)
|
||||
{
|
||||
creature.Home = entry.HomeLocation;
|
||||
creature.HomeMap = map;
|
||||
creature.RangeHome = entry.HomeRange;
|
||||
}
|
||||
|
||||
if (entry.Direction != SpawnEntry.InvalidDirection)
|
||||
mobile.Direction = entry.Direction;
|
||||
|
||||
mobile.OnBeforeSpawn(loc, map);
|
||||
mobile.MoveToWorld(loc, map);
|
||||
mobile.OnAfterSpawn();
|
||||
|
||||
return mobile;
|
||||
}
|
||||
|
||||
protected virtual Mobile CreateMobile() => (Mobile)ActivatorUtil.CreateInstance(Type);
|
||||
}
|
||||
|
||||
public class SpawnItem : SpawnType
|
||||
{
|
||||
private static readonly Dictionary<Type, SpawnItem> m_Table = new Dictionary<Type, SpawnItem>();
|
||||
|
||||
protected int m_Height;
|
||||
|
||||
protected SpawnItem(Type type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Height;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Land => true;
|
||||
public override bool Water => false;
|
||||
|
||||
public static SpawnItem Get(Type type)
|
||||
{
|
||||
if (!m_Table.TryGetValue(type, out SpawnItem si))
|
||||
m_Table[type] = si = new SpawnItem(type);
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
Item item = (Item)ActivatorUtil.CreateInstance(Type);
|
||||
|
||||
m_Height = item.ItemData.Height;
|
||||
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
|
||||
{
|
||||
Item item = CreateItem();
|
||||
|
||||
item.OnBeforeSpawn(loc, map);
|
||||
item.MoveToWorld(loc, map);
|
||||
item.OnAfterSpawn();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual Item CreateItem() => (Item)ActivatorUtil.CreateInstance(Type);
|
||||
}
|
||||
|
||||
public class SpawnTreasureChest : SpawnItem
|
||||
{
|
||||
public SpawnTreasureChest(int itemID, BaseTreasureChest.TreasureLevel level) : base(typeof(BaseTreasureChest))
|
||||
{
|
||||
ItemID = itemID;
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public int ItemID { get; }
|
||||
|
||||
public BaseTreasureChest.TreasureLevel Level { get; }
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
m_Height = TileData.ItemTable[ItemID & TileData.MaxItemValue].Height;
|
||||
}
|
||||
|
||||
protected override Item CreateItem() => new BaseTreasureChest(ItemID, Level);
|
||||
}
|
||||
|
||||
public class SpawnGroupElement
|
||||
{
|
||||
public SpawnGroupElement(SpawnDefinition spawnDefinition, int weight)
|
||||
{
|
||||
SpawnDefinition = spawnDefinition;
|
||||
Weight = weight;
|
||||
}
|
||||
|
||||
public SpawnDefinition SpawnDefinition { get; }
|
||||
|
||||
public int Weight { get; }
|
||||
}
|
||||
|
||||
public class SpawnGroup : SpawnDefinition
|
||||
{
|
||||
private readonly int m_TotalWeight;
|
||||
|
||||
static SpawnGroup()
|
||||
{
|
||||
string path = Path.Combine(Core.BaseDirectory, "Data/SpawnDefinitions.xml");
|
||||
if (!File.Exists(path))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(path);
|
||||
|
||||
XmlElement root = doc["spawnDefinitions"];
|
||||
if (root == null)
|
||||
return;
|
||||
|
||||
foreach (XmlElement xmlDef in root.SelectNodes("spawnGroup"))
|
||||
{
|
||||
string name = null;
|
||||
if (!Region.ReadString(xmlDef, "name", ref name))
|
||||
continue;
|
||||
|
||||
List<SpawnGroupElement> list = new List<SpawnGroupElement>();
|
||||
foreach (XmlNode node in xmlDef.ChildNodes)
|
||||
if (node is XmlElement el)
|
||||
{
|
||||
SpawnDefinition def = GetSpawnDefinition(el);
|
||||
if (def == null)
|
||||
continue;
|
||||
|
||||
int weight = 1;
|
||||
Region.ReadInt32(el, "weight", ref weight, false);
|
||||
|
||||
SpawnGroupElement groupElement = new SpawnGroupElement(def, weight);
|
||||
list.Add(groupElement);
|
||||
}
|
||||
|
||||
SpawnGroupElement[] elements = list.ToArray();
|
||||
SpawnGroup group = new SpawnGroup(name, elements);
|
||||
Register(group);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Could not load SpawnDefinitions.xml: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public SpawnGroup(string name, SpawnGroupElement[] elements)
|
||||
{
|
||||
Name = name;
|
||||
Elements = elements;
|
||||
|
||||
m_TotalWeight = 0;
|
||||
for (int i = 0; i < elements.Length; i++)
|
||||
m_TotalWeight += elements[i].Weight;
|
||||
}
|
||||
|
||||
public static Dictionary<string, SpawnGroup> Table { get; } = new Dictionary<string, SpawnGroup>();
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public SpawnGroupElement[] Elements { get; }
|
||||
|
||||
public static void Register(SpawnGroup group)
|
||||
{
|
||||
if (Table.ContainsKey(group.Name))
|
||||
Console.WriteLine("Warning: Double SpawnGroup name '{0}'", group.Name);
|
||||
else
|
||||
Table[group.Name] = group;
|
||||
}
|
||||
|
||||
public override ISpawnable Spawn(SpawnEntry entry)
|
||||
{
|
||||
int index = Utility.Random(m_TotalWeight);
|
||||
|
||||
for (int i = 0; i < Elements.Length; i++)
|
||||
{
|
||||
SpawnGroupElement element = Elements[i];
|
||||
|
||||
if (index < element.Weight)
|
||||
return element.SpawnDefinition.Spawn(entry);
|
||||
|
||||
index -= element.Weight;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool CanSpawn(params Type[] types)
|
||||
{
|
||||
for (int i = 0; i < Elements.Length; i++)
|
||||
if (Elements[i].SpawnDefinition.CanSpawn(types))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,425 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class SpawnEntry : ISpawner
|
||||
{
|
||||
public static readonly TimeSpan DefaultMinSpawnTime = TimeSpan.FromMinutes(2.0);
|
||||
public static readonly TimeSpan DefaultMaxSpawnTime = TimeSpan.FromMinutes(5.0);
|
||||
|
||||
public static readonly Direction InvalidDirection = Direction.Running;
|
||||
|
||||
private static List<IEntity> m_RemoveList;
|
||||
|
||||
private DateTime m_NextSpawn;
|
||||
private Timer m_SpawnTimer;
|
||||
|
||||
public SpawnEntry(int id, BaseRegion region, Point3D home, int range, Direction direction,
|
||||
SpawnDefinition definition, int max, TimeSpan minSpawnTime, TimeSpan maxSpawnTime)
|
||||
{
|
||||
ID = id;
|
||||
Region = region;
|
||||
HomeLocation = home;
|
||||
HomeRange = range;
|
||||
Direction = direction;
|
||||
Definition = definition;
|
||||
SpawnedObjects = new List<ISpawnable>();
|
||||
Max = max;
|
||||
MinSpawnTime = minSpawnTime;
|
||||
MaxSpawnTime = maxSpawnTime;
|
||||
Running = false;
|
||||
|
||||
if (Table.ContainsKey(id))
|
||||
Console.WriteLine("Warning: double SpawnEntry ID '{0}'", id);
|
||||
else
|
||||
Table[id] = this;
|
||||
}
|
||||
|
||||
public static Dictionary<int, SpawnEntry> Table { get; } = new Dictionary<int, SpawnEntry>();
|
||||
|
||||
// When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home?
|
||||
public bool ReturnOnDeactivate => true;
|
||||
|
||||
// Are unlinked and untamed creatures removed after 20 hours?
|
||||
public bool RemoveIfUntamed => true;
|
||||
|
||||
public int ID { get; }
|
||||
|
||||
public BaseRegion Region { get; }
|
||||
|
||||
public Direction Direction { get; }
|
||||
|
||||
public SpawnDefinition Definition { get; }
|
||||
|
||||
public List<ISpawnable> SpawnedObjects { get; }
|
||||
|
||||
public int Max { get; private set; }
|
||||
|
||||
public TimeSpan MinSpawnTime { get; }
|
||||
|
||||
public TimeSpan MaxSpawnTime { get; }
|
||||
|
||||
public bool Running { get; private set; }
|
||||
|
||||
public bool Complete => SpawnedObjects.Count >= Max;
|
||||
public bool Spawning => Running && !Complete;
|
||||
|
||||
// Are creatures unlinked on taming (true) or should they also go out of the region (false)?
|
||||
public bool UnlinkOnTaming => false;
|
||||
|
||||
Region ISpawner.Region => Region;
|
||||
public Point3D HomeLocation { get; }
|
||||
|
||||
public int HomeRange { get; }
|
||||
|
||||
void ISpawner.Remove(ISpawnable spawn)
|
||||
{
|
||||
SpawnedObjects.Remove(spawn);
|
||||
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water) => Region.RandomSpawnLocation(spawnHeight, land, water, HomeLocation, HomeRange);
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (Running)
|
||||
return;
|
||||
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (!Running)
|
||||
return;
|
||||
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
private void Spawn()
|
||||
{
|
||||
ISpawnable spawn = Definition.Spawn(this);
|
||||
|
||||
if (spawn != null)
|
||||
Add(spawn);
|
||||
}
|
||||
|
||||
private void Add(ISpawnable spawn)
|
||||
{
|
||||
SpawnedObjects.Add(spawn);
|
||||
|
||||
spawn.Spawner = this;
|
||||
|
||||
if (spawn is BaseCreature creature)
|
||||
creature.RemoveIfUntamed = RemoveIfUntamed;
|
||||
}
|
||||
|
||||
private TimeSpan RandomTime()
|
||||
{
|
||||
int min = (int)MinSpawnTime.TotalSeconds;
|
||||
int max = (int)MaxSpawnTime.TotalSeconds;
|
||||
|
||||
int rand = Utility.RandomMinMax(min, max);
|
||||
return TimeSpan.FromSeconds(rand);
|
||||
}
|
||||
|
||||
private void CheckTimer()
|
||||
{
|
||||
if (Spawning)
|
||||
{
|
||||
if (m_SpawnTimer == null)
|
||||
{
|
||||
TimeSpan time = RandomTime();
|
||||
m_SpawnTimer = Timer.DelayCall(time, TimerCallback);
|
||||
m_NextSpawn = DateTime.UtcNow + time;
|
||||
}
|
||||
}
|
||||
else if (m_SpawnTimer != null)
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void TimerCallback()
|
||||
{
|
||||
int amount = Math.Max((Max - SpawnedObjects.Count) / 3, 1);
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
Spawn();
|
||||
|
||||
m_SpawnTimer = null;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void DeleteSpawnedObjects()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
private void InternalDeleteSpawnedObjects()
|
||||
{
|
||||
foreach (ISpawnable spawnable in SpawnedObjects)
|
||||
{
|
||||
spawnable.Spawner = null;
|
||||
|
||||
bool uncontrolled = (spawnable as BaseCreature)?.Controlled != true;
|
||||
|
||||
if (uncontrolled)
|
||||
spawnable.Delete();
|
||||
}
|
||||
|
||||
SpawnedObjects.Clear();
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
for (int i = 0; !Complete && i < Max; i++)
|
||||
Spawn();
|
||||
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Max = 0;
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
if (m_SpawnTimer != null)
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
|
||||
if (Table.TryGetValue(ID, out SpawnEntry entry) && entry == this)
|
||||
Table.Remove(ID);
|
||||
}
|
||||
|
||||
public void Serialize(IGenericWriter writer)
|
||||
{
|
||||
writer.Write(SpawnedObjects.Count);
|
||||
|
||||
for (int i = 0; i < SpawnedObjects.Count; i++)
|
||||
writer.Write(SpawnedObjects[i].Serial);
|
||||
|
||||
writer.Write(Running);
|
||||
|
||||
if (m_SpawnTimer != null)
|
||||
{
|
||||
writer.Write(true);
|
||||
writer.WriteDeltaTime(m_NextSpawn);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
if (World.FindEntity(reader.ReadUInt()) is ISpawnable spawnableEntity)
|
||||
Add(spawnableEntity);
|
||||
|
||||
Running = reader.ReadBool();
|
||||
|
||||
if (reader.ReadBool())
|
||||
{
|
||||
m_NextSpawn = reader.ReadDeltaTime();
|
||||
|
||||
if (Spawning)
|
||||
{
|
||||
m_SpawnTimer?.Stop();
|
||||
|
||||
TimeSpan delay = m_NextSpawn - DateTime.UtcNow;
|
||||
m_SpawnTimer = Timer.DelayCall(delay > TimeSpan.Zero ? delay : TimeSpan.Zero, TimerCallback);
|
||||
}
|
||||
}
|
||||
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public static void Remove(IGenericReader reader, int version)
|
||||
{
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
IEntity entity = World.FindEntity(reader.ReadUInt());
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
m_RemoveList ??= new List<IEntity>();
|
||||
m_RemoveList.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
reader.ReadBool(); // m_Running
|
||||
|
||||
if (reader.ReadBool())
|
||||
reader.ReadDeltaTime(); // m_NextSpawn
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (m_RemoveList != null)
|
||||
{
|
||||
foreach (IEntity ent in m_RemoveList) ent.Delete();
|
||||
|
||||
m_RemoveList = null;
|
||||
}
|
||||
|
||||
SpawnPersistence.EnsureExistence();
|
||||
|
||||
CommandSystem.Register("RespawnAllRegions", AccessLevel.Administrator, RespawnAllRegions_OnCommand);
|
||||
CommandSystem.Register("RespawnRegion", AccessLevel.GameMaster, RespawnRegion_OnCommand);
|
||||
CommandSystem.Register("DelAllRegionSpawns", AccessLevel.Administrator, DelAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("DelRegionSpawns", AccessLevel.GameMaster, DelRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StartAllRegionSpawns", AccessLevel.Administrator, StartAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StartRegionSpawns", AccessLevel.GameMaster, StartRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StopAllRegionSpawns", AccessLevel.Administrator, StopAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StopRegionSpawns", AccessLevel.GameMaster, StopRegionSpawns_OnCommand);
|
||||
}
|
||||
|
||||
private static BaseRegion GetCommandData(CommandEventArgs args)
|
||||
{
|
||||
Mobile from = args.Mobile;
|
||||
|
||||
Region reg;
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
reg = from.Region;
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = args.GetString(0);
|
||||
if (!from.Map.Regions.TryGetValue(name, out reg))
|
||||
{
|
||||
from.SendMessage("Could not find region '{0}'.", name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (reg is BaseRegion br && br.Spawns != null)
|
||||
return br;
|
||||
|
||||
from.SendMessage("There are no spawners in region '{0}'.", reg);
|
||||
return null;
|
||||
}
|
||||
|
||||
[Usage("RespawnAllRegions")]
|
||||
[Description("Respawns all regions and sets the spawners as running.")]
|
||||
private static void RespawnAllRegions_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Respawn();
|
||||
|
||||
args.Mobile.SendMessage("All regions have respawned.");
|
||||
}
|
||||
|
||||
[Usage("RespawnRegion [<region name>]")]
|
||||
[Description("Respawns the region in which you are (or that you provided) and sets the spawners as running.")]
|
||||
private static void RespawnRegion_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Respawn();
|
||||
|
||||
args.Mobile.SendMessage("Region '{0}' has respawned.", region);
|
||||
}
|
||||
|
||||
[Usage("DelAllRegionSpawns")]
|
||||
[Description("Deletes all spawned objects of every regions and sets the spawners as not running.")]
|
||||
private static void DelAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage("All region spawned objects have been deleted.");
|
||||
}
|
||||
|
||||
[Usage("DelRegionSpawns [<region name>]")]
|
||||
[Description(
|
||||
"Deletes all spawned objects of the region in which you are (or that you provided) and sets the spawners as not running.")]
|
||||
private static void DelRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage("Spawned objects of region '{0}' have been deleted.", region);
|
||||
}
|
||||
|
||||
[Usage("StartAllRegionSpawns")]
|
||||
[Description("Sets the region spawners of all regions as running.")]
|
||||
private static void StartAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Start();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have started.");
|
||||
}
|
||||
|
||||
[Usage("StartRegionSpawns [<region name>]")]
|
||||
[Description("Sets the region spawners of the region in which you are (or that you provided) as running.")]
|
||||
private static void StartRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Start();
|
||||
|
||||
args.Mobile.SendMessage("Spawners of region '{0}' have started.", region);
|
||||
}
|
||||
|
||||
[Usage("StopAllRegionSpawns")]
|
||||
[Description("Sets the region spawners of all regions as not running.")]
|
||||
private static void StopAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Stop();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have stopped.");
|
||||
}
|
||||
|
||||
[Usage("StopRegionSpawns [<region name>]")]
|
||||
[Description("Sets the region spawners of the region in which you are (or that you provided) as not running.")]
|
||||
private static void StopRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Stop();
|
||||
|
||||
args.Mobile.SendMessage("Spawners of region '{0}' have stopped.", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
namespace Server.Regions
|
||||
{
|
||||
[TypeAlias("Server.Regions.SpawnPersistance")]
|
||||
public class SpawnPersistence : Item
|
||||
{
|
||||
private static SpawnPersistence m_Instance;
|
||||
|
||||
private SpawnPersistence() : base(1) => Movable = false;
|
||||
|
||||
public SpawnPersistence(Serial serial) : base(serial) => m_Instance = this;
|
||||
|
||||
public SpawnPersistence Instance => m_Instance;
|
||||
|
||||
public override string DefaultName => "Region spawn persistence - Internal";
|
||||
|
||||
public static void EnsureExistence()
|
||||
{
|
||||
m_Instance ??= new SpawnPersistence();
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write(SpawnEntry.Table.Values.Count);
|
||||
foreach (SpawnEntry entry in SpawnEntry.Table.Values)
|
||||
{
|
||||
writer.Write(entry.ID);
|
||||
|
||||
entry.Serialize(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int id = reader.ReadInt();
|
||||
|
||||
SpawnEntry entry = SpawnEntry.Table[id];
|
||||
|
||||
if (entry != null)
|
||||
entry.Deserialize(reader, version);
|
||||
else
|
||||
SpawnEntry.Remove(reader, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
using System.Xml;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class TownRegion : GuardedRegion
|
||||
{
|
||||
public TownRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
public TownRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
Projects/UOContent/Regions/TwistedWealdDesertRegion.cs
Normal file
41
Projects/UOContent/Regions/TwistedWealdDesertRegion.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.Text.Json;
|
||||
using Server.Network;
|
||||
using Server.Spells;
|
||||
using Server.Spells.Ninjitsu;
|
||||
using Server.Json;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class TwistedWealdDesertRegion : MondainRegion
|
||||
{
|
||||
public TwistedWealdDesertRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||
{
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.Login += Desert_OnLogin;
|
||||
}
|
||||
|
||||
public override void OnEnter(Mobile m)
|
||||
{
|
||||
NetState ns = m.NetState;
|
||||
if (ns != null && !TransformationSpellHelper.UnderTransformation(m, typeof(AnimalForm)) &&
|
||||
m.AccessLevel == AccessLevel.Player)
|
||||
ns.Send(SpeedControl.WalkSpeed);
|
||||
}
|
||||
|
||||
public override void OnExit(Mobile m)
|
||||
{
|
||||
NetState ns = m.NetState;
|
||||
if (ns != null && !TransformationSpellHelper.UnderTransformation(m, typeof(AnimalForm)))
|
||||
ns.Send(SpeedControl.Disable);
|
||||
}
|
||||
|
||||
private static void Desert_OnLogin(Mobile m)
|
||||
{
|
||||
if (m.Region.IsPartOf<TwistedWealdDesertRegion>() && m.AccessLevel == AccessLevel.Player)
|
||||
m.NetState.Send(SpeedControl.WalkSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue