Reorganizes Project (#41)
This commit is contained in:
parent
08bf44af9a
commit
3614a66aee
3499 changed files with 79 additions and 55 deletions
553
Projects/Scripts/Regions/BaseRegion.cs
Normal file
553
Projects/Scripts/Regions/BaseRegion.cs
Normal file
|
|
@ -0,0 +1,553 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public enum SpawnZLevel
|
||||
{
|
||||
Lowest,
|
||||
Highest,
|
||||
Random
|
||||
}
|
||||
|
||||
public class BaseRegion : Region
|
||||
{
|
||||
private static List<Rectangle3D> m_RectBuffer1 = new List<Rectangle3D>();
|
||||
private static List<Rectangle3D> m_RectBuffer2 = new List<Rectangle3D>();
|
||||
|
||||
private static List<int> m_SpawnBuffer1 = new List<int>();
|
||||
private static List<Item> m_SpawnBuffer2 = new List<Item>();
|
||||
private bool m_ExcludeFromParentSpawns;
|
||||
|
||||
private Rectangle3D[] m_Rectangles;
|
||||
private int[] m_RectangleWeights;
|
||||
|
||||
private string m_RuneName;
|
||||
|
||||
private SpawnEntry[] m_Spawns;
|
||||
private int m_TotalWeight;
|
||||
|
||||
public BaseRegion(string name, Map map, int priority, params Rectangle2D[] area) : base(name, map, priority, area)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseRegion(string name, Map map, int priority, params Rectangle3D[] area) : base(name, map, priority, area)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseRegion(string name, Map map, Region parent, params Rectangle2D[] area) : base(name, map, parent, area)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseRegion(string name, Map map, Region parent, params Rectangle3D[] area) : base(name, map, parent, area)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
ReadString(xml["rune"], "name", ref m_RuneName, false);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool YoungProtected => true;
|
||||
public virtual bool YoungMayEnter => true;
|
||||
public virtual bool MountsAllowed => true;
|
||||
public virtual bool DeadMayEnter => true;
|
||||
public virtual bool ResurrectionAllowed => true;
|
||||
public virtual bool LogoutAllowed => true;
|
||||
|
||||
public string RuneName
|
||||
{
|
||||
get => m_RuneName;
|
||||
set => m_RuneName = value;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
BaseRegion br = region as BaseRegion;
|
||||
|
||||
if (br?.m_RuneName != null)
|
||||
return br.m_RuneName;
|
||||
|
||||
region = region.Parent;
|
||||
}
|
||||
|
||||
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 void OnEnter(Mobile m)
|
||||
{
|
||||
if (m is PlayerMobile mobile && mobile.Young)
|
||||
if (!YoungProtected)
|
||||
mobile.SendGump(new YoungDungeonWarning());
|
||||
}
|
||||
|
||||
public override bool AcceptsSpawnsFrom(Region region)
|
||||
{
|
||||
if (region == this || !m_ExcludeFromParentSpawns)
|
||||
return base.AcceptsSpawnsFrom(region);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void InitRectangles()
|
||||
{
|
||||
if (m_Rectangles != null)
|
||||
return;
|
||||
|
||||
// Test if area rectangles are overlapping, and in that case break them into smaller non overlapping rectangles
|
||||
for (int i = 0; i < Area.Length; i++)
|
||||
{
|
||||
m_RectBuffer2.Add(Area[i]);
|
||||
|
||||
for (int j = 0; j < m_RectBuffer1.Count && m_RectBuffer2.Count > 0; j++)
|
||||
{
|
||||
Rectangle3D comp = m_RectBuffer1[j];
|
||||
|
||||
for (int k = m_RectBuffer2.Count - 1; k >= 0; k--)
|
||||
{
|
||||
Rectangle3D rect = m_RectBuffer2[k];
|
||||
|
||||
int l1 = rect.Start.X, r1 = rect.End.X, t1 = rect.Start.Y, b1 = rect.End.Y;
|
||||
int l2 = comp.Start.X, r2 = comp.End.X, t2 = comp.Start.Y, b2 = comp.End.Y;
|
||||
|
||||
if (l1 < r2 && r1 > l2 && t1 < b2 && b1 > t2)
|
||||
{
|
||||
m_RectBuffer2.RemoveAt(k);
|
||||
|
||||
int sz = rect.Start.Z;
|
||||
int ez = rect.End.X;
|
||||
|
||||
if (l1 < l2)
|
||||
m_RectBuffer2.Add(new Rectangle3D(new Point3D(l1, t1, sz), new Point3D(l2, b1, ez)));
|
||||
|
||||
if (r1 > r2)
|
||||
m_RectBuffer2.Add(new Rectangle3D(new Point3D(r2, t1, sz), new Point3D(r1, b1, ez)));
|
||||
|
||||
if (t1 < t2)
|
||||
m_RectBuffer2.Add(new Rectangle3D(new Point3D(Math.Max(l1, l2), t1, sz),
|
||||
new Point3D(Math.Min(r1, r2), t2, ez)));
|
||||
|
||||
if (b1 > b2)
|
||||
m_RectBuffer2.Add(new Rectangle3D(new Point3D(Math.Max(l1, l2), b2, sz),
|
||||
new Point3D(Math.Min(r1, r2), b1, ez)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_RectBuffer1.AddRange(m_RectBuffer2);
|
||||
m_RectBuffer2.Clear();
|
||||
}
|
||||
|
||||
m_Rectangles = m_RectBuffer1.ToArray();
|
||||
m_RectBuffer1.Clear();
|
||||
|
||||
m_RectangleWeights = new int[m_Rectangles.Length];
|
||||
for (int i = 0; i < m_Rectangles.Length; i++)
|
||||
{
|
||||
Rectangle3D rect = m_Rectangles[i];
|
||||
int weight = rect.Width * rect.Height;
|
||||
|
||||
m_RectangleWeights[i] = weight;
|
||||
m_TotalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water, Point3D home, int range)
|
||||
{
|
||||
Map map = Map;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
48
Projects/Scripts/Regions/DungeonRegion.cs
Normal file
48
Projects/Scripts/Regions/DungeonRegion.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System.Xml;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class DungeonRegion : BaseRegion
|
||||
{
|
||||
private Point3D m_EntranceLocation;
|
||||
|
||||
public DungeonRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
XmlElement entrEl = xml["entrance"];
|
||||
|
||||
Map entrMap = map;
|
||||
ReadMap(entrEl, "map", ref entrMap, false);
|
||||
|
||||
if (ReadPoint3D(entrEl, entrMap, ref m_EntranceLocation, false))
|
||||
EntranceMap = entrMap;
|
||||
}
|
||||
|
||||
public override bool YoungProtected => false;
|
||||
|
||||
public Point3D EntranceLocation
|
||||
{
|
||||
get => m_EntranceLocation;
|
||||
set => m_EntranceLocation = value;
|
||||
}
|
||||
|
||||
public Map EntranceMap{ get; set; }
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void AlterLightLevel(Mobile m, ref int global, ref int personal)
|
||||
{
|
||||
global = LightCycle.DungeonLevel;
|
||||
}
|
||||
|
||||
public override bool CanUseStuckMenu(Mobile m)
|
||||
{
|
||||
if (Map == Map.Felucca)
|
||||
return false;
|
||||
|
||||
return base.CanUseStuckMenu(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Projects/Scripts/Regions/GreenAcres.cs
Normal file
34
Projects/Scripts/Regions/GreenAcres.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
362
Projects/Scripts/Regions/GuardedRegion.cs
Normal file
362
Projects/Scripts/Regions/GuardedRegion.cs
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Server.Commands;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class GuardedRegion : BaseRegion
|
||||
{
|
||||
private static object[] m_GuardParams = new object[1];
|
||||
|
||||
private Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
|
||||
private 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)
|
||||
{
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
public GuardedRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
XmlElement el = xml["guards"];
|
||||
|
||||
if (ReadType(el, "type", ref m_GuardType, false))
|
||||
{
|
||||
if (!typeof(Mobile).IsAssignableFrom(m_GuardType))
|
||||
{
|
||||
Console.WriteLine("Invalid guard type for region '{0}'", this);
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
bool disabled = false;
|
||||
if (ReadBoolean(el, "disabled", ref disabled, false))
|
||||
Disabled = disabled;
|
||||
}
|
||||
|
||||
public bool Disabled{ get; set; }
|
||||
|
||||
public virtual bool AllowReds => Core.AOS;
|
||||
|
||||
public virtual Type DefaultGuardType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Map == Map.Ilshenar || Map == Map.Malas)
|
||||
return typeof(ArcherGuard);
|
||||
return typeof(WarriorGuard);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsDisabled()
|
||||
{
|
||||
return Disabled;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("CheckGuarded", AccessLevel.GameMaster, CheckGuarded_OnCommand);
|
||||
CommandSystem.Register("SetGuarded", AccessLevel.Administrator, SetGuarded_OnCommand);
|
||||
CommandSystem.Register("ToggleGuarded", AccessLevel.Administrator, ToggleGuarded_OnCommand);
|
||||
}
|
||||
|
||||
[Usage("CheckGuarded")]
|
||||
[Description("Returns a value indicating if the current region is guarded or not.")]
|
||||
private static void CheckGuarded_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
||||
|
||||
if (reg == null)
|
||||
from.SendMessage("You are not in a guardable region.");
|
||||
else if (reg.Disabled)
|
||||
from.SendMessage("The guards in this region have been disabled.");
|
||||
else
|
||||
from.SendMessage("This region is actively guarded.");
|
||||
}
|
||||
|
||||
[Usage("SetGuarded <true|false>")]
|
||||
[Description("Enables or disables guards for the current region.")]
|
||||
private static void SetGuarded_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
|
||||
if (e.Length == 1)
|
||||
{
|
||||
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
||||
|
||||
if (reg == null)
|
||||
{
|
||||
from.SendMessage("You are not in a guardable region.");
|
||||
}
|
||||
else
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendMessage("Format: SetGuarded <true|false>");
|
||||
}
|
||||
}
|
||||
|
||||
[Usage("ToggleGuarded")]
|
||||
[Description("Toggles the state of guards for the current region.")]
|
||||
private static void ToggleGuarded_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
||||
|
||||
if (reg == null)
|
||||
{
|
||||
from.SendMessage("You are not in a guardable region.");
|
||||
}
|
||||
else
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
public static GuardedRegion Disable(GuardedRegion reg)
|
||||
{
|
||||
reg.Disabled = true;
|
||||
return reg;
|
||||
}
|
||||
|
||||
public virtual bool CheckVendorAccess(BaseVendor vendor, Mobile from)
|
||||
{
|
||||
if (from.AccessLevel >= AccessLevel.GameMaster || IsDisabled())
|
||||
return true;
|
||||
|
||||
return from.Kills < 5;
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if (!IsDisabled() && !s.OnCastInTown(this))
|
||||
{
|
||||
m.SendLocalizedMessage(500946); // You cannot cast this in town!
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void MakeGuard(Mobile focus)
|
||||
{
|
||||
IPooledEnumerable<BaseGuard> eable = focus.GetMobilesInRange<BaseGuard>(8);
|
||||
BaseGuard useGuard = eable.FirstOrDefault(m => m.Focus == null);
|
||||
|
||||
eable.Free();
|
||||
|
||||
if (useGuard == null)
|
||||
{
|
||||
m_GuardParams[0] = focus;
|
||||
|
||||
try
|
||||
{
|
||||
Activator.CreateInstance(m_GuardType, m_GuardParams);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
useGuard.Focus = focus;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEnter(Mobile m)
|
||||
{
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
if (!AllowReds && m.Kills >= 5)
|
||||
CheckGuardCandidate(m);
|
||||
}
|
||||
|
||||
public override void OnExit(Mobile m)
|
||||
{
|
||||
// if (IsDisabled())
|
||||
return;
|
||||
}
|
||||
|
||||
public override void OnSpeech(SpeechEventArgs args)
|
||||
{
|
||||
base.OnSpeech(args);
|
||||
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
if (args.Mobile.Alive && args.HasKeyword(0x0007)) // *guards*
|
||||
CallGuards(args.Mobile.Location);
|
||||
}
|
||||
|
||||
public override void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
|
||||
{
|
||||
base.OnAggressed(aggressor, aggressed, criminal);
|
||||
|
||||
if (!IsDisabled() && aggressor != aggressed && criminal)
|
||||
CheckGuardCandidate(aggressor);
|
||||
}
|
||||
|
||||
public override void OnGotBeneficialAction(Mobile helper, Mobile helped)
|
||||
{
|
||||
base.OnGotBeneficialAction(helper, helped);
|
||||
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
int noto = Notoriety.Compute(helper, helped);
|
||||
|
||||
if (helper != helped && (noto == Notoriety.Criminal || noto == Notoriety.Murderer))
|
||||
CheckGuardCandidate(helper);
|
||||
}
|
||||
|
||||
public override void OnCriminalAction(Mobile m, bool message)
|
||||
{
|
||||
base.OnCriminalAction(m, message);
|
||||
|
||||
if (!IsDisabled())
|
||||
CheckGuardCandidate(m);
|
||||
}
|
||||
|
||||
public void CheckGuardCandidate(Mobile m)
|
||||
{
|
||||
if (IsDisabled() || !IsGuardCandidate(m))
|
||||
return;
|
||||
|
||||
if (!m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
||||
{
|
||||
timer = new GuardTimer(m, m_GuardCandidates);
|
||||
timer.Start();
|
||||
|
||||
m_GuardCandidates[m] = timer;
|
||||
m.SendLocalizedMessage(502275); // Guards can now be called on you!
|
||||
|
||||
Map map = m.Map;
|
||||
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
Mobile fakeCall = null;
|
||||
double prio = 0.0;
|
||||
|
||||
foreach (Mobile v in m.GetMobilesInRange(8))
|
||||
if (!v.Player && v != m && !IsGuardCandidate(v) &&
|
||||
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
|
||||
{
|
||||
double dist = m.GetDistanceToSqrt(v);
|
||||
|
||||
if (fakeCall == null || dist < prio)
|
||||
{
|
||||
fakeCall = v;
|
||||
prio = dist;
|
||||
}
|
||||
}
|
||||
|
||||
if (fakeCall != null)
|
||||
{
|
||||
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
|
||||
1013043, 1013052));
|
||||
MakeGuard(m);
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void CallGuards(Point3D p)
|
||||
{
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
IPooledEnumerable<Mobile> eable = Map.GetMobilesInRange(p, 14);
|
||||
|
||||
foreach (Mobile m in eable)
|
||||
if (IsGuardCandidate(m) &&
|
||||
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
|
||||
{
|
||||
if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
||||
{
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
}
|
||||
|
||||
MakeGuard(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private class GuardTimer : Timer
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private Dictionary<Mobile, GuardTimer> m_Table;
|
||||
|
||||
public GuardTimer(Mobile m, Dictionary<Mobile, GuardTimer> table) : base(TimeSpan.FromSeconds(15.0))
|
||||
{
|
||||
Priority = TimerPriority.TwoFiftyMS;
|
||||
|
||||
m_Mobile = m;
|
||||
m_Table = table;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (m_Table.ContainsKey(m_Mobile))
|
||||
{
|
||||
m_Table.Remove(m_Mobile);
|
||||
m_Mobile.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
375
Projects/Scripts/Regions/HouseRegion.cs
Normal file
375
Projects/Scripts/Regions/HouseRegion.cs
Normal file
|
|
@ -0,0 +1,375 @@
|
|||
using System;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Multis;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class HouseRegion : BaseRegion
|
||||
{
|
||||
public static readonly int HousePriority = DefaultPriority + 1;
|
||||
|
||||
public static TimeSpan CombatHeatDelay = TimeSpan.FromSeconds(30.0);
|
||||
|
||||
private bool m_Recursion;
|
||||
|
||||
public HouseRegion(BaseHouse house) : base(null, house.Map, HousePriority, GetArea(house))
|
||||
{
|
||||
House = house;
|
||||
|
||||
Point3D ban = house.RelativeBanLocation;
|
||||
|
||||
GoLocation = new Point3D(house.X + ban.X, house.Y + ban.Y, house.Z + ban.Z);
|
||||
}
|
||||
|
||||
public BaseHouse House{ get; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.Login += OnLogin;
|
||||
}
|
||||
|
||||
public static void OnLogin(LoginEventArgs e)
|
||||
{
|
||||
BaseHouse house = BaseHouse.FindHouseAt(e.Mobile);
|
||||
|
||||
if (house?.Public == false && !house.IsFriend(e.Mobile))
|
||||
e.Mobile.Location = house.BanLocation;
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Rectangle3D[] GetArea(BaseHouse house)
|
||||
{
|
||||
int x = house.X;
|
||||
int y = house.Y;
|
||||
// int z = house.Z;
|
||||
|
||||
Rectangle2D[] houseArea = house.Area;
|
||||
Rectangle3D[] area = new Rectangle3D[houseArea.Length];
|
||||
|
||||
for (int i = 0; i < area.Length; i++)
|
||||
{
|
||||
Rectangle2D rect = houseArea[i];
|
||||
area[i] = ConvertTo3D(new Rectangle2D(x + rect.Start.X, y + rect.Start.Y, rect.Width, rect.Height));
|
||||
}
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
public override bool SendInaccessibleMessage(Item item, Mobile from)
|
||||
{
|
||||
if (item is Container)
|
||||
item.SendLocalizedMessageTo(from, 501647); // That is secure.
|
||||
else
|
||||
item.SendLocalizedMessageTo(from, 1061637); // You are not allowed to access this.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CheckAccessibility(Item item, Mobile from)
|
||||
{
|
||||
return House.CheckAccessibility(item, from);
|
||||
}
|
||||
|
||||
// Use OnLocationChanged instead of OnEnter because it can be that we enter a house region even though we're not actually inside the house
|
||||
public override void OnLocationChanged(Mobile m, Point3D oldLocation)
|
||||
{
|
||||
if (m_Recursion)
|
||||
return;
|
||||
|
||||
base.OnLocationChanged(m, oldLocation);
|
||||
|
||||
m_Recursion = true;
|
||||
|
||||
BaseCreature bc = m as BaseCreature;
|
||||
|
||||
if (bc?.NoHouseRestrictions == true)
|
||||
{
|
||||
}
|
||||
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))
|
||||
m.Location = House.BanLocation;
|
||||
}
|
||||
|
||||
if (House.InternalizedVendors.Count > 0 && House.IsInside(m) && !House.IsInside(oldLocation, 16) &&
|
||||
House.IsOwner(m) && m.Alive &&
|
||||
!m.HasGump<NoticeGump>())
|
||||
m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180));
|
||||
|
||||
m_Recursion = false;
|
||||
}
|
||||
|
||||
public override bool OnMoveInto(Mobile from, Direction d, Point3D newLocation, Point3D oldLocation)
|
||||
{
|
||||
if (!base.OnMoveInto(from, d, newLocation, oldLocation))
|
||||
return false;
|
||||
|
||||
BaseCreature bc = from as BaseCreature;
|
||||
|
||||
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 (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
|
||||
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.
|
||||
|
||||
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;
|
||||
|
||||
if (foundation?.Customizer != null && foundation.Customizer != from && House.IsInside(newLocation, 16))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (House.InternalizedVendors.Count > 0 && House.IsInside(from) && !House.IsInside(oldLocation, 16) &&
|
||||
House.IsOwner(from) && from.Alive &&
|
||||
!from.HasGump<NoticeGump>())
|
||||
from.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180));
|
||||
|
||||
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 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 void OnSpeech(SpeechEventArgs e)
|
||||
{
|
||||
base.OnSpeech(e);
|
||||
|
||||
Mobile from = e.Mobile;
|
||||
Item sign = House.Sign;
|
||||
|
||||
bool isOwner = House.IsOwner(from);
|
||||
bool isCoOwner = isOwner || House.IsCoOwner(from);
|
||||
bool isFriend = isCoOwner || House.IsFriend(from);
|
||||
|
||||
if (!isFriend)
|
||||
return;
|
||||
|
||||
if (!from.Alive)
|
||||
return;
|
||||
|
||||
if (Core.ML && Insensitive.Equals(e.Speech, "I wish to resize my house"))
|
||||
{
|
||||
if (from.Map != sign.Map || !from.InRange(sign, 0))
|
||||
{
|
||||
from.SendLocalizedMessage(500295); // you are too far away to do that.
|
||||
}
|
||||
else if (DateTime.UtcNow <= House.BuiltOn.AddHours(1))
|
||||
{
|
||||
from.SendLocalizedMessage(1080178); // You must wait one hour between each house demolition.
|
||||
}
|
||||
else if (isOwner)
|
||||
{
|
||||
from.CloseGump<ConfirmHouseResize>();
|
||||
from.CloseGump<HouseGumpAOS>();
|
||||
from.SendGump(new ConfirmHouseResize(from, House));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(501320); // Only the house owner may do this.
|
||||
}
|
||||
}
|
||||
|
||||
if (!House.IsInside(from) || !House.IsActive)
|
||||
return;
|
||||
if (e.HasKeyword(0x33)) // remove thyself
|
||||
{
|
||||
from.SendLocalizedMessage(501326); // Target the individual to eject from this house.
|
||||
from.Target = new HouseKickTarget(House);
|
||||
}
|
||||
else if (e.HasKeyword(0x34)) // I ban thee
|
||||
{
|
||||
if (!House.Public && House.IsAosRules)
|
||||
{
|
||||
from.SendLocalizedMessage(
|
||||
1062521); // You cannot ban someone from a private house. Revoke their access instead.
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(501325); // Target the individual to ban from this house.
|
||||
from.Target = new HouseBanTarget(true, House);
|
||||
}
|
||||
}
|
||||
else if (e.HasKeyword(0x23)) // I wish to lock this down
|
||||
{
|
||||
if (isCoOwner)
|
||||
{
|
||||
from.SendLocalizedMessage(502097); // Lock what down?
|
||||
from.Target = new LockdownTarget(false, House);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
|
||||
}
|
||||
}
|
||||
else if (e.HasKeyword(0x24)) // I wish to release this
|
||||
{
|
||||
if (isCoOwner)
|
||||
{
|
||||
from.SendLocalizedMessage(502100); // Choose the item you wish to release
|
||||
from.Target = new LockdownTarget(true, House);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
|
||||
}
|
||||
}
|
||||
else if (e.HasKeyword(0x25)) // I wish to secure this
|
||||
{
|
||||
if (isOwner)
|
||||
{
|
||||
from.SendLocalizedMessage(502103); // Choose the item you wish to secure
|
||||
from.Target = new SecureTarget(false, House);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(502094); // You must be in your house to do this.
|
||||
}
|
||||
}
|
||||
else if (e.HasKeyword(0x26)) // I wish to unsecure this
|
||||
{
|
||||
if (isOwner)
|
||||
{
|
||||
from.SendLocalizedMessage(502106); // Choose the item you wish to unsecure
|
||||
from.Target = new SecureTarget(true, House);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(502094); // You must be in your house to do this.
|
||||
}
|
||||
}
|
||||
else if (e.HasKeyword(0x27)) // I wish to place a strongbox
|
||||
{
|
||||
if (isOwner)
|
||||
from.SendLocalizedMessage(502109); // Owners do not get a strongbox of their own.
|
||||
else if (isCoOwner)
|
||||
House.AddStrongBox(from);
|
||||
else
|
||||
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
|
||||
}
|
||||
else if (e.HasKeyword(0x28)) // trash barrel
|
||||
{
|
||||
if (isCoOwner)
|
||||
House.AddTrashBarrel(from);
|
||||
else
|
||||
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnDoubleClick(Mobile from, object o)
|
||||
{
|
||||
if (o is Container c)
|
||||
{
|
||||
SecureAccessResult res = House.CheckSecureAccess(from, c);
|
||||
|
||||
switch (res)
|
||||
{
|
||||
case SecureAccessResult.Insecure: break;
|
||||
case SecureAccessResult.Accessible: return true;
|
||||
case SecureAccessResult.Inaccessible:
|
||||
c.SendLocalizedMessageTo(from, 1010563);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return base.OnDoubleClick(from, o);
|
||||
}
|
||||
|
||||
public override bool OnSingleClick(Mobile from, object o)
|
||||
{
|
||||
if (o is Item item)
|
||||
{
|
||||
if (House.HasLockedDownItem(item))
|
||||
item.LabelTo(from, 501643); // [locked down]
|
||||
else if (House.HasSecureItem(item))
|
||||
item.LabelTo(from, 501644); // [locked down & secure]
|
||||
}
|
||||
|
||||
return base.OnSingleClick(from, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Projects/Scripts/Regions/Jail.cs
Normal file
58
Projects/Scripts/Regions/Jail.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using System.Xml;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class Jail : BaseRegion
|
||||
{
|
||||
public Jail(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowBeneficial(Mobile from, Mobile target)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
from.SendMessage("You may not do that in jail.");
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool AllowHarmful(Mobile from, Mobile target)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
from.SendMessage("You may not do that in jail.");
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void AlterLightLevel(Mobile m, ref int global, ref int personal)
|
||||
{
|
||||
global = LightCycle.JailLevel;
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile from, ISpell s)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
from.SendLocalizedMessage(502629); // You cannot cast spells here.
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool OnSkillUse(Mobile from, int Skill)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
from.SendMessage("You may not use skills in jail.");
|
||||
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool OnCombatantChange(Mobile from, Mobile Old, Mobile New)
|
||||
{
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Projects/Scripts/Regions/NoHousingRegion.cs
Normal file
24
Projects/Scripts/Regions/NoHousingRegion.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using System.Xml;
|
||||
|
||||
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
|
||||
*/
|
||||
private bool m_SmartChecking;
|
||||
|
||||
public NoHousingRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
ReadBoolean(xml["smartNoHousing"], "active", ref m_SmartChecking, false);
|
||||
}
|
||||
|
||||
public bool SmartChecking => m_SmartChecking;
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return m_SmartChecking;
|
||||
}
|
||||
}
|
||||
}
|
||||
390
Projects/Scripts/Regions/Spawning/SpawnDefinition.cs
Normal file
390
Projects/Scripts/Regions/Spawning/SpawnDefinition.cs
Normal file
|
|
@ -0,0 +1,390 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
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 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)Activator.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()
|
||||
{
|
||||
return (Mobile)Activator.CreateInstance(Type);
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnItem : SpawnType
|
||||
{
|
||||
private static 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)Activator.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()
|
||||
{
|
||||
return (Item)Activator.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()
|
||||
{
|
||||
return 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
435
Projects/Scripts/Regions/Spawning/SpawnEntry.cs
Normal file
435
Projects/Scripts/Regions/Spawning/SpawnEntry.cs
Normal file
|
|
@ -0,0 +1,435 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
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)
|
||||
{
|
||||
return 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 is BaseCreature) || !((BaseCreature)spawnable).Controlled;
|
||||
|
||||
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(GenericWriter 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(GenericReader 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(GenericReader reader, int version)
|
||||
{
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
IEntity entity = World.FindEntity(reader.ReadUInt());
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (m_RemoveList == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Projects/Scripts/Regions/Spawning/SpawnPersistence.cs
Normal file
63
Projects/Scripts/Regions/Spawning/SpawnPersistence.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
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()
|
||||
{
|
||||
if (m_Instance == null)
|
||||
m_Instance = new SpawnPersistence();
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter 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(GenericReader 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Projects/Scripts/Regions/TownRegion.cs
Normal file
11
Projects/Scripts/Regions/TownRegion.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Xml;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class TownRegion : GuardedRegion
|
||||
{
|
||||
public TownRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue