Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,621 @@
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 readonly List<Rectangle3D> m_RectBuffer1 = new List<Rectangle3D>();
private static readonly List<Rectangle3D> m_RectBuffer2 = new List<Rectangle3D>();
private static readonly List<Int32> m_SpawnBuffer1 = new List<Int32>();
private static readonly List<Item> m_SpawnBuffer2 = new List<Item>();
private string m_RuneName;
private bool m_NoLogoutDelay;
private SpawnEntry[] m_Spawns;
private SpawnZLevel m_SpawnZLevel;
private bool m_ExcludeFromParentSpawns;
private Rectangle3D[] m_Rectangles;
private int[] m_RectangleWeights;
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 this.m_RuneName, false);
bool logoutDelayActive = true;
ReadBoolean(xml["logoutDelay"], "active", ref logoutDelayActive, false);
this.m_NoLogoutDelay = !logoutDelayActive;
XmlElement spawning = xml["spawning"];
if (spawning != null)
{
ReadBoolean(spawning, "excludeFromParent", ref this.m_ExcludeFromParentSpawns, false);
SpawnZLevel zLevel = SpawnZLevel.Lowest;
ReadEnum(spawning, "zLevel", ref zLevel, false);
this.m_SpawnZLevel = zLevel;
List<SpawnEntry> list = new List<SpawnEntry>();
foreach (XmlNode node in spawning.ChildNodes)
{
XmlElement el = node as XmlElement;
if (el != null)
{
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)
{
this.m_Spawns = list.ToArray();
}
}
}
[CommandProperty(AccessLevel.GameMaster)]
public virtual bool YoungProtected
{
get
{
return true;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public string RuneName
{
get
{
return this.m_RuneName;
}
set
{
this.m_RuneName = value;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public bool NoLogoutDelay
{
get
{
return this.m_NoLogoutDelay;
}
set
{
this.m_NoLogoutDelay = value;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public SpawnEntry[] Spawns
{
get
{
return this.m_Spawns;
}
set
{
if (this.m_Spawns != null)
{
for (int i = 0; i < this.m_Spawns.Length; i++)
this.m_Spawns[i].Delete();
}
this.m_Spawns = value;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public SpawnZLevel SpawnZLevel
{
get
{
return this.m_SpawnZLevel;
}
set
{
this.m_SpawnZLevel = value;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public bool ExcludeFromParentSpawns
{
get
{
return this.m_ExcludeFromParentSpawns;
}
set
{
this.m_ExcludeFromParentSpawns = value;
}
}
public static void Configure()
{
Region.DefaultRegionType = typeof(BaseRegion);
}
public static string GetRuneNameFor(Region region)
{
while (region != null)
{
BaseRegion br = region as BaseRegion;
if (br != null && br.m_RuneName != null)
return br.m_RuneName;
region = region.Parent;
}
return null;
}
public static bool CanSpawn(Region region, params Type[] types)
{
while (region != null)
{
if (!region.AllowSpawn())
return false;
BaseRegion br = region as BaseRegion;
if (br != null)
{
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 OnUnregister()
{
base.OnUnregister();
this.Spawns = null;
}
public override TimeSpan GetLogoutDelay(Mobile m)
{
if (this.m_NoLogoutDelay)
{
if (m.Aggressors.Count == 0 && m.Aggressed.Count == 0 && !m.Criminal)
return TimeSpan.Zero;
}
return base.GetLogoutDelay(m);
}
public override void OnEnter(Mobile m)
{
if (m is PlayerMobile && ((PlayerMobile)m).Young)
{
if (!this.YoungProtected)
{
m.SendGump(new YoungDungeonWarning());
}
}
}
public override bool AcceptsSpawnsFrom(Region region)
{
if (region == this || !this.m_ExcludeFromParentSpawns)
return base.AcceptsSpawnsFrom(region);
return false;
}
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water, Point3D home, int range)
{
Map map = this.Map;
if (map == Map.Internal)
return Point3D.Zero;
this.InitRectangles();
if (this.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(this.m_TotalWeight);
x = int.MinValue;
y = int.MinValue;
minZ = int.MaxValue;
maxZ = int.MinValue;
for (int j = 0; j < this.m_RectangleWeights.Length; j++)
{
int curWeight = this.m_RectangleWeights[j];
if (rand < curWeight)
{
Rectangle3D rect = this.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 < this.Area.Length; j++)
{
Rectangle3D rect = this.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 ( this.m_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 (!Region.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.IsPlayer() || !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 (this.Name != null)
return this.Name;
else if (this.RuneName != null)
return this.RuneName;
else
return this.GetType().Name;
}
private void InitRectangles()
{
if (this.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 < this.Area.Length; i++)
{
m_RectBuffer2.Add(this.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();
}
this.m_Rectangles = m_RectBuffer1.ToArray();
m_RectBuffer1.Clear();
this.m_RectangleWeights = new int[this.m_Rectangles.Length];
for (int i = 0; i < this.m_Rectangles.Length; i++)
{
Rectangle3D rect = this.m_Rectangles[i];
int weight = rect.Width * rect.Height;
this.m_RectangleWeights[i] = weight;
this.m_TotalWeight += weight;
}
}
public virtual bool CheckTravel(Mobile traveller, Point3D p, Server.Spells.TravelCheckType type)
{
return true;
}
public virtual bool CanSee(Mobile m, IEntity e)
{
return true;
}
}
}

View File

@@ -0,0 +1,346 @@
#region References
using System;
using System.Collections.Generic;
using System.Xml;
using Server.Engines.Quests;
using Server.Items;
using Server.Mobiles;
using Server.Network;
#endregion
namespace Server.Regions
{
public class DamagingRegion : MondainRegion
{
private Dictionary<Mobile, Timer> m_Table;
public Dictionary<Mobile, Timer> Table { get { return m_Table; } }
public virtual int EnterMessage { get { return 0; } }
public virtual int EnterSound { get { return 0; } }
public virtual TimeSpan DamageInterval { get { return TimeSpan.FromSeconds(1); } }
public DamagingRegion(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
public override void OnEnter(Mobile m)
{
base.OnEnter(m);
if (!CanDamage(m))
{
return;
}
if (EnterSound > 0)
{
m.PlaySound(EnterSound);
}
if (EnterMessage > 0)
{
m.SendLocalizedMessage(EnterMessage);
}
StartTimer(m);
}
public override void OnExit(Mobile m)
{
base.OnExit(m);
StopTimer(m);
}
public override void OnLocationChanged(Mobile m, Point3D oldLocation)
{
base.OnLocationChanged(m, oldLocation);
if (!Contains(m.Location))
{
StopTimer(m);
}
else if (!Contains(oldLocation))
{
StartTimer(m);
}
}
protected void StartTimer(Mobile m)
{
if (m_Table == null)
{
m_Table = new Dictionary<Mobile, Timer>();
}
Timer t;
if (m_Table.TryGetValue(m, out t) && t != null)
{
t.Start();
}
else
{
m_Table[m] = Timer.DelayCall(DamageInterval, DamageInterval, Damage, m);
}
}
protected void StopTimer(Mobile m)
{
if (m_Table == null)
{
m_Table = new Dictionary<Mobile, Timer>();
}
Timer t;
if (m_Table.TryGetValue(m, out t))
{
if (t != null)
{
t.Stop();
}
m_Table.Remove(m);
}
}
public void Damage(Mobile m)
{
if (CanDamage(m))
{
OnDamage(m);
}
else
{
StopTimer(m);
}
}
protected virtual void OnDamage(Mobile m)
{
m.RevealingAction();
}
public virtual bool CanDamage(Mobile m)
{
if (m.IsDeadBondedPet || !m.Alive || m.Blessed || m.Map != Map || !Contains(m.Location))
{
return false;
}
if (!m.Player && (!(m is BaseCreature) || !(((BaseCreature)m).GetMaster() is PlayerMobile)))
{
return false;
}
if (m.IsStaff())
{
return false;
}
return true;
}
}
public class CrystalField : DamagingRegion
{
// An electric wind chills your blood, making it difficult to traverse the cave unharmed.
public override int EnterMessage { get { return 1072396; } }
public override int EnterSound { get { return 0x22F; } }
public CrystalField(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
AOS.Damage(m, Utility.Random(2, 6), 0, 0, 100, 0, 0);
}
}
public class IcyRiver : DamagingRegion
{
public IcyRiver(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
var dmg = Utility.Random(2, 3);
if (m is PlayerMobile)
{
dmg = (int)BalmOfProtection.HandleDamage((PlayerMobile)m, dmg);
}
AOS.Damage(m, dmg, 0, 0, 100, 0, 0);
}
}
public class PoisonedSemetery : DamagingRegion
{
public override TimeSpan DamageInterval { get { return TimeSpan.FromSeconds(5); } }
public PoisonedSemetery(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
m.FixedParticles(0x36B0, 1, 14, 0x26BB, 0x3F, 0x7, EffectLayer.Waist);
m.PlaySound(0x229);
AOS.Damage(m, Utility.Random(2, 3), 0, 0, 0, 100, 0);
}
}
public class PoisonedTree : DamagingRegion
{
public override TimeSpan DamageInterval { get { return TimeSpan.FromSeconds(1); } }
public PoisonedTree(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
m.FixedEffect(0x374A, 1, 17);
m.PlaySound(0x1E1);
m.LocalOverheadMessage(MessageType.Regular, 0x21, 1074165); // You feel dizzy from a lack of clear air
var mod = (int)(m.Str * 0.1);
if (mod > 10)
{
mod = 10;
}
m.AddStatMod(new StatMod(StatType.Str, "Poisoned Tree Str", mod * -1, TimeSpan.FromSeconds(1)));
mod = (int)(m.Int * 0.1);
if (mod > 10)
{
mod = 10;
}
m.AddStatMod(new StatMod(StatType.Int, "Poisoned Tree Int", mod * -1, TimeSpan.FromSeconds(1)));
}
}
public class ParoxysmusBossEntry : DamagingRegion
{
public override TimeSpan DamageInterval { get { return TimeSpan.FromSeconds(2); } }
public ParoxysmusBossEntry(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
public override void OnEnter(Mobile m)
{
if (ParoxysmusAltar.IsUnderEffects(m))
{
m.SendLocalizedMessage(1074604); // The slimy ointment continues to protect you from the corrosive river.
}
else
{
m.MoveToWorld(new Point3D(6537, 506, -50), m.Map);
m.Kill();
}
}
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
if (!ParoxysmusAltar.IsUnderEffects(m))
{
m.MoveToWorld(new Point3D(6537, 506, -50), m.Map);
m.Kill();
}
}
}
public class AcidRiver : DamagingRegion
{
public override TimeSpan DamageInterval { get { return TimeSpan.FromSeconds(2); } }
public AcidRiver(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
if (m.Location.X > 6484 && m.Location.Y > 500)
{
m.Kill();
}
else
{
m.FixedParticles(0x36B0, 1, 14, 0x26BB, 0x3F, 0x7, EffectLayer.Waist);
m.PlaySound(0x229);
var damage = 0;
damage += (int)Math.Pow(m.Location.X - 6200, 0.5);
damage += (int)Math.Pow(m.Location.Y - 330, 0.5);
if (damage > 20)
{
// The acid river is much stronger here. You realize that allowing the acid to touch your flesh will surely kill you.
m.SendLocalizedMessage(1074567);
}
else if (damage > 10)
{
// The acid river has gotten deeper. The concentration of acid is significantly stronger.
m.SendLocalizedMessage(1074566);
}
else
{
// The acid river burns your skin.
m.SendLocalizedMessage(1074565);
}
AOS.Damage(m, damage, 0, 0, 0, 100, 0);
}
}
}
public class TheLostCityEntry : DamagingRegion
{
public override TimeSpan DamageInterval { get { return TimeSpan.FromMilliseconds(500); } }
public TheLostCityEntry(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{ }
protected override void OnDamage(Mobile m)
{
base.OnDamage(m);
if (m is Kodar)
return;
m.FixedParticles(0x36B0, 1, 14, 0x26BB, 0x3F, 0x7, EffectLayer.Waist);
m.PlaySound(0x229);
var damage = Utility.RandomMinMax(10, 20);
AOS.Damage(m, damage, 0, 0, 0, 100, 0);
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Xml;
namespace Server.Regions
{
public class DungeonRegion : BaseRegion
{
private Point3D m_EntranceLocation;
private Map m_EntranceMap;
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 this.m_EntranceLocation, false))
this.m_EntranceMap = entrMap;
}
[CommandProperty(AccessLevel.GameMaster)]
public override bool YoungProtected
{
get
{
return false;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Point3D EntranceLocation
{
get
{
return this.m_EntranceLocation;
}
set
{
this.m_EntranceLocation = value;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Map EntranceMap
{
get
{
return this.m_EntranceMap;
}
set
{
this.m_EntranceMap = value;
}
}
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;
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
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.IsPlayer())
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.IsPlayer())
{
m.SendMessage("You cannot cast that spell here.");
return false;
}
return base.OnBeginSpellCast(m, s);
}
}
}

View File

@@ -0,0 +1,470 @@
#region References
using System;
using System.Collections.Generic;
using System.Xml;
using Server.Commands;
using Server.Mobiles;
#endregion
namespace Server.Regions
{
public class GuardedRegion : BaseRegion
{
private static readonly object[] m_GuardParams = new object[1];
private readonly Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
private readonly Type m_GuardType;
private bool m_Disabled;
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;
}
}
[CommandProperty(AccessLevel.GameMaster)]
public bool Disabled { get { return m_Disabled; } set { m_Disabled = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public virtual bool AllowReds { get { return Core.AOS; } }
public virtual Type DefaultGuardType
{
get
{
if (Map == Map.Ilshenar || Map == Map.Malas)
{
return typeof(ArcherGuard);
}
else
{
return typeof(WarriorGuard);
}
}
}
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);
}
public static GuardedRegion Disable(GuardedRegion reg)
{
reg.Disabled = true;
return reg;
}
public virtual bool IsDisabled()
{
return m_Disabled;
}
public virtual bool CheckVendorAccess(BaseVendor vendor, Mobile from)
{
if (from.AccessLevel >= AccessLevel.GameMaster || IsDisabled())
{
return true;
}
return !from.Murderer;
}
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)
{
BaseGuard useGuard = null;
IPooledEnumerable eable = focus.GetMobilesInRange(8);
foreach (Mobile m in eable)
{
if (m is BaseGuard)
{
BaseGuard g = (BaseGuard)m;
if (g.Focus == null) // idling
{
useGuard = g;
break;
}
}
}
eable.Free();
if (useGuard == null)
{
m_GuardParams[0] = focus;
try
{
Activator.CreateInstance(m_GuardType, m_GuardParams);
}
catch
{ }
}
else
{
useGuard.Focus = focus;
}
}
public override void OnEnter(Mobile m)
{
if (IsDisabled())
{
return;
}
if (!AllowReds && m.Murderer)
{
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 && Utility.InRange(aggressor.Location, aggressed.Location, 12))
{
CheckGuardCandidate(aggressor, aggressor is BaseCreature && ((BaseCreature)aggressor).IsAggressiveMonster);
}
}
public override void OnGotBeneficialAction(Mobile helper, Mobile helped)
{
base.OnGotBeneficialAction(helper, helped);
if (IsDisabled() || Siege.SiegeShard)
{
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)
{
CheckGuardCandidate(m, false);
}
public void CheckGuardCandidate(Mobile m, bool autoCallGuards)
{
if (IsDisabled())
{
return;
}
if (IsGuardCandidate(m))
{
GuardTimer timer = null;
m_GuardCandidates.TryGetValue(m, out timer);
if (autoCallGuards)
{
MakeGuard(m);
if (timer != null)
{
timer.Stop();
m_GuardCandidates.Remove(m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
}
}
else if (timer == null)
{
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)
{
Mobile fakeCall = null;
double prio = 0.0;
IPooledEnumerable eable = m.GetMobilesInRange(8);
foreach (Mobile v in eable)
{
if (!v.Player && v != m && !IsGuardCandidate(v) &&
((v is BaseCreature) ? ((BaseCreature)v).IsHumanInTown() : (v.Body.IsHuman && v.Region.IsPartOf(this))))
{
double dist = m.GetDistanceToSqrt(v);
if (fakeCall == null || dist < prio)
{
fakeCall = v;
prio = dist;
}
}
}
eable.Free();
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 eable = Map.GetMobilesInRange(p, 14);
foreach (Mobile m in eable)
{
if (IsGuardCandidate(m))
{
if (m_GuardCandidates.ContainsKey(m) || (!AllowReds && m.Murderer && m.Region.IsPartOf(this)))
{
GuardTimer timer = null;
m_GuardCandidates.TryGetValue(m, out timer);
if (timer != null)
{
timer.Stop();
m_GuardCandidates.Remove(m);
}
MakeGuard(m);
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
}
else if (m is BaseCreature && ((BaseCreature)m).IsAggressiveMonster && m.Region.IsPartOf(this))
{
MakeGuard(m);
}
break;
}
}
eable.Free();
}
public bool IsGuardCandidate(Mobile m)
{
if (m is BaseGuard || m.GuardImmune || !m.Alive || m.IsStaff() || m.Blessed || (m is BaseCreature && ((BaseCreature)m).IsInvulnerable) ||
IsDisabled())
{
return false;
}
return (!AllowReds && m.Murderer) || m.Criminal || (m is BaseCreature && ((BaseCreature)m).IsAggressiveMonster);
}
[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 = (GuardedRegion)from.Region.GetRegion(typeof(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 = (GuardedRegion)from.Region.GetRegion(typeof(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 = (GuardedRegion)from.Region.GetRegion(typeof(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.");
}
}
}
private class GuardTimer : Timer
{
private readonly Mobile m_Mobile;
private readonly 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.
}
}
}
}
}

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using Server.Items;
using Server.Spells.Sixth;
using Server.Targeting;
namespace Server.Regions
{
public class HouseRaffleRegion : BaseRegion
{
private readonly HouseRaffleStone m_Stone;
[CommandProperty(AccessLevel.GameMaster)]
public HouseRaffleStone Stone { get { return m_Stone; } }
public HouseRaffleRegion(HouseRaffleStone stone)
: base(null, stone.PlotFacet, Region.DefaultPriority, stone.PlotBounds)
{
m_Stone = stone;
}
public override bool AllowHousing(Mobile from, Point3D p)
{
if (Stone == null)
return false;
if (Stone.IsExpired)
return true;
if (Stone.Deed == null)
return false;
Container pack = from.Backpack;
if (pack != null && this.ContainsDeed(pack))
return true;
BankBox bank = from.FindBankNoCreate();
if (bank != null && this.ContainsDeed(bank))
return true;
return false;
}
public override bool OnTarget(Mobile m, Target t, object o)
{
if (m.Spell != null && m.Spell is MarkSpell && m.IsPlayer())
{
m.SendLocalizedMessage(501800); // You cannot mark an object at that location.
return false;
}
return base.OnTarget(m, t, o);
}
private bool ContainsDeed(Container cont)
{
List<HouseRaffleDeed> deeds = cont.FindItemsByType<HouseRaffleDeed>();
for (int i = 0; i < deeds.Count; ++i)
{
if (deeds[i] == Stone.Deed)
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,497 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Multis;
using Server.ContextMenus;
using Server.Network;
namespace Server.Regions
{
public class HouseRegion : BaseRegion
{
public static readonly int HousePriority = Region.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);
}
[CommandProperty(AccessLevel.GameMaster)]
public BaseHouse House { get; }
public static void Initialize()
{
EventSink.Login += new LoginEventHandler(OnLogin);
}
public static void OnLogin(LoginEventArgs e)
{
BaseHouse house = BaseHouse.FindHouseAt(e.Mobile);
if (house != null && !house.Public && !house.IsFriend(e.Mobile))
e.Mobile.Location = house.BanLocation;
}
public override bool AllowHousing(Mobile from, Point3D p)
{
return false;
}
public override void OnEnter(Mobile m)
{
if (m.AccessLevel == AccessLevel.Player && House != null && House.IsFriend(m))
{
if (Core.AOS && House is HouseFoundation)
{
House.RefreshDecay();
}
}
m.SendEverything();
}
public override bool CanSee(Mobile m, IEntity e)
{
Item item = e as Item;
if ((m.PublicHouseContent && House.Public) ||
House.IsInside(m) ||
ExcludeItem(item) ||
(item.RootParent != null && m.CanSee(item.RootParent)))
{
return true;
}
return false;
}
private bool ExcludeItem(Item item)
{
return IsStairArea(item) || m_ItemTypes.Any(t => t == item.GetType() || item.GetType().IsSubclassOf(t));
}
private static Type[] m_ItemTypes = new Type[]
{
typeof(BaseHouse), typeof(HouseTeleporter),
typeof(BaseDoor), typeof(Static),
typeof(HouseSign)
};
public bool IsStairArea(Item item)
{
return item.Y >= House.Sign.Y;
}
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
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;
if (m is BaseCreature && ((BaseCreature)m).NoHouseRestrictions)
{
}
else if (m is BaseCreature && ((BaseCreature)m).IsHouseSummonable && !(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
}
else if (House is HouseFoundation)
{
HouseFoundation foundation = (HouseFoundation)House;
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(typeof(NoticeGump)))
{
/* This house has been customized recently, and vendors that work out of this
* house have been temporarily relocated. You must now put your vendors back to work.
* To do this, walk to a location inside the house where you wish to station
* your vendor, then activate the context-sensitive menu on your avatar and
* select "Get Vendor".
*/
m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null));
}
m_Recursion = false;
}
public override bool OnMoveInto(Mobile from, Direction d, Point3D newLocation, Point3D oldLocation)
{
if (!base.OnMoveInto(from, d, newLocation, oldLocation))
return false;
if (from is BaseCreature && ((BaseCreature)from).NoHouseRestrictions)
{
}
else if (from is BaseCreature && !((BaseCreature)from).Controlled) // Untamed creatures cannot enter public houses
{
return false;
}
else if (from is BaseCreature && ((BaseCreature)from).IsHouseSummonable && !(BaseCreature.Summoning || House.IsInside(oldLocation, 16)))
{
return false;
}
else if (from is BaseCreature && !((BaseCreature)from).Controlled && 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
return false;
}
else if (House is HouseFoundation)
{
HouseFoundation foundation = (HouseFoundation)House;
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(typeof(NoticeGump)))
{
/* This house has been customized recently, and vendors that work out of this
* house have been temporarily relocated. You must now put your vendors back to work.
* To do this, walk to a location inside the house where you wish to station
* your vendor, then activate the context-sensitive menu on your avatar and
* select "Get Vendor".
*/
from.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null));
}
if(Core.AOS)
House.AddVisit(from);
return true;
}
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item)
{
if (House.IsOwner(from) && item.Parent == null &&
(House.IsLockedDown(item) || House.IsSecure(item)) &&
!House.Addons.ContainsKey(item))
{
list.Add(new ReleaseEntry(from, item, House));
}
if (item is BaseContainer && House.IsSecure(item) &&
!House.IsLockedDown(item) && item.Parent == null && House.IsOwner(from) &&
!House.Addons.ContainsKey(item))
{
list.Add(new ReLocateEntry(from, item, House));
}
base.GetContextMenuEntries(from, list, item);
}
public override bool OnDecay(Item item)
{
if ((House.IsLockedDown(item) || House.IsSecure(item)) && House.IsInside(item))
return false;
else
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(typeof(ConfirmHouseResize));
from.CloseGump(typeof(HouseGumpAOS));
from.SendGump(new ConfirmHouseResize(from, House));
}
else
{
from.SendLocalizedMessage(501320); // Only the house owner may do
}
}
if (!House.IsInside(from) || !House.IsActive)
return;
else if (e.HasKeyword(0x33)) // remove thyself
{
if (isFriend)
{
from.SendLocalizedMessage(501326); // Target the individual to eject from this house.
from.Target = new HouseKickTarget(House);
}
else
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
}
else if (e.HasKeyword(0x34)) // I ban thee
{
if (!isFriend)
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
else 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 (isFriend)
{
from.SendLocalizedMessage(502097); // Lock what down?
from.Target = new LockdownTarget(false, House);
}
else
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
}
else if (e.HasKeyword(0x24)) // I wish to release this
{
if (isFriend)
{
from.SendLocalizedMessage(502100); // Choose the item you wish to release
from.Target = new LockdownTarget(true, House);
}
else
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
}
else if (e.HasKeyword(0x25)) // I wish to secure this
{
if (isCoOwner)
{
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 if (isFriend)
{
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
}
else
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
}
else if (e.HasKeyword(0x28)) // trash barrel
{
if (isCoOwner)
{
House.AddTrashBarrel(from);
}
else if (isFriend)
{
from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
}
else
{
from.SendLocalizedMessage(502094); // You must be in your house to do this.
}
}
}
public override bool OnDoubleClick(Mobile from, object o)
{
if (o is Container)
{
Container c = (Container)o;
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 item = (Item)o;
if (House.IsLockedDown(item))
item.LabelTo(from, 501643); // [locked down]
else if (House.IsSecure(item))
item.LabelTo(from, 501644); // [locked down & secure]
}
return base.OnSingleClick(from, o);
}
public override void OnDelete(Item item)
{
if (House.IsLockedDown(item) || House.IsSecure(item))
{
House.SetLockdown(null, item, 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] = Region.ConvertTo3D(new Rectangle2D(x + rect.Start.X, y + rect.Start.Y, rect.Width, rect.Height));
}
return area;
}
}
}

68
Scripts/Regions/Jail.cs Normal file
View File

@@ -0,0 +1,68 @@
using System;
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 AllowAutoClaim( Mobile from )
{
return false;
}
public override bool AllowBeneficial(Mobile from, Mobile target)
{
if (from.IsPlayer())
from.SendLocalizedMessage(1115999); // You may not do that in this area.
return (from.IsStaff());
}
public override bool AllowHarmful(Mobile from, IDamageable target)
{
if (from.Player)
from.SendLocalizedMessage(1115999); // You may not do that in this area.
return (from.IsStaff());
}
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.IsPlayer())
{
from.SendLocalizedMessage(502629); // You cannot cast spells here.
return false;
}
return base.OnBeginSpellCast(from, s);
}
public override bool OnSkillUse(Mobile from, int Skill)
{
if (from.IsPlayer())
from.SendLocalizedMessage(1116000); // You may not use that skill in this area.
return (from.IsStaff());
}
public override bool OnCombatantChange(Mobile from, IDamageable Old, IDamageable New)
{
return (from.IsStaff());
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Xml;
using Server.Spells.Chivalry;
using Server.Spells.Fourth;
using Server.Spells.Seventh;
using Server.Spells.Sixth;
namespace Server.Regions
{
public class MondainRegion : DungeonRegion
{
public MondainRegion(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{
}
public override bool OnBeginSpellCast(Mobile m, ISpell s)
{
if (m.IsPlayer())
{
if (s is MarkSpell)
{
m.SendLocalizedMessage(501802); // Thy spell doth not appear to work...
return false;
}
else if (s is GateTravelSpell || s is RecallSpell || s is SacredJourneySpell)
{
m.SendLocalizedMessage(501035); // You cannot teleport from here to the destination.
return false;
}
}
return base.OnBeginSpellCast(m, s);
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
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 readonly bool m_SmartChecking;
public NoHousingRegion(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{
ReadBoolean(xml["smartNoHousing"], "active", ref this.m_SmartChecking, false);
}
[CommandProperty(AccessLevel.GameMaster)]
public bool SmartChecking
{
get
{
return this.m_SmartChecking;
}
}
public override bool AllowHousing(Mobile from, Point3D p)
{
return this.m_SmartChecking;
}
}
}

View File

@@ -0,0 +1,482 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Server.Items;
using Server.Mobiles;
namespace Server.Regions
{
public abstract class SpawnDefinition
{
protected SpawnDefinition()
{
}
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);
}
else if (typeof(Item).IsAssignableFrom(type))
{
return SpawnItem.Get(type);
}
else
{
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;
SpawnDefinition def = (SpawnDefinition)SpawnGroup.Table[group];
if (def == null)
{
Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group);
return null;
}
else
{
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 ISpawnable Spawn(SpawnEntry entry);
public abstract bool CanSpawn(params Type[] types);
}
public abstract class SpawnType : SpawnDefinition
{
private readonly Type m_Type;
private bool m_Init;
protected SpawnType(Type type)
{
this.m_Type = type;
this.m_Init = false;
}
public Type Type
{
get
{
return this.m_Type;
}
}
public abstract int Height { get; }
public abstract bool Land { get; }
public abstract bool Water { get; }
public override ISpawnable Spawn(SpawnEntry entry)
{
BaseRegion region = entry.Region;
Map map = region.Map;
Point3D loc = entry.RandomSpawnLocation(this.Height, this.Land, this.Water);
if (loc == Point3D.Zero)
return null;
return this.Construct(entry, loc, map);
}
public override bool CanSpawn(params Type[] types)
{
for (int i = 0; i < types.Length; i++)
{
if (types[i] == this.m_Type)
return true;
}
return false;
}
protected void EnsureInit()
{
if (this.m_Init)
return;
this.Init();
this.m_Init = true;
}
protected virtual void Init()
{
}
protected abstract ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map);
}
public class SpawnMobile : SpawnType
{
protected bool m_Land;
protected bool m_Water;
private static readonly Hashtable m_Table = new Hashtable();
protected SpawnMobile(Type type)
: base(type)
{
}
public override int Height
{
get
{
return 16;
}
}
public override bool Land
{
get
{
this.EnsureInit();
return this.m_Land;
}
}
public override bool Water
{
get
{
this.EnsureInit();
return this.m_Water;
}
}
public static SpawnMobile Get(Type type)
{
SpawnMobile sm = (SpawnMobile)m_Table[type];
if (sm == null)
{
sm = new SpawnMobile(type);
m_Table[type] = sm;
}
return sm;
}
protected override void Init()
{
Mobile mob = (Mobile)Activator.CreateInstance(this.Type);
this.m_Land = !mob.CantWalk;
this.m_Water = mob.CanSwim;
mob.Delete();
}
protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
{
Mobile mobile = this.CreateMobile();
BaseCreature creature = mobile as BaseCreature;
if (creature != null)
{
creature.Home = entry.HomeLocation;
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(this.Type);
}
}
public class SpawnItem : SpawnType
{
protected int m_Height;
private static readonly Hashtable m_Table = new Hashtable();
protected SpawnItem(Type type)
: base(type)
{
}
public override int Height
{
get
{
this.EnsureInit();
return this.m_Height;
}
}
public override bool Land
{
get
{
return true;
}
}
public override bool Water
{
get
{
return false;
}
}
public static SpawnItem Get(Type type)
{
SpawnItem si = (SpawnItem)m_Table[type];
if (si == null)
{
si = new SpawnItem(type);
m_Table[type] = si;
}
return si;
}
protected override void Init()
{
Item item = (Item)Activator.CreateInstance(this.Type);
this.m_Height = item.ItemData.Height;
item.Delete();
}
protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
{
Item item = this.CreateItem();
item.OnBeforeSpawn(loc, map);
item.MoveToWorld(loc, map);
item.OnAfterSpawn();
return item;
}
protected virtual Item CreateItem()
{
return (Item)Activator.CreateInstance(this.Type);
}
}
public class SpawnTreasureChest : SpawnItem
{
private readonly int m_ItemID;
private readonly BaseTreasureChest.TreasureLevel m_Level;
public SpawnTreasureChest(int itemID, BaseTreasureChest.TreasureLevel level)
: base(typeof(BaseTreasureChest))
{
this.m_ItemID = itemID;
this.m_Level = level;
}
public int ItemID
{
get
{
return this.m_ItemID;
}
}
public BaseTreasureChest.TreasureLevel Level
{
get
{
return this.m_Level;
}
}
protected override void Init()
{
this.m_Height = TileData.ItemTable[this.m_ItemID & TileData.MaxItemValue].Height;
}
protected override Item CreateItem()
{
return new BaseTreasureChest(this.m_ItemID, this.m_Level);
}
}
public class SpawnGroupElement
{
private readonly SpawnDefinition m_SpawnDefinition;
private readonly int m_Weight;
public SpawnGroupElement(SpawnDefinition spawnDefinition, int weight)
{
this.m_SpawnDefinition = spawnDefinition;
this.m_Weight = weight;
}
public SpawnDefinition SpawnDefinition
{
get
{
return this.m_SpawnDefinition;
}
}
public int Weight
{
get
{
return this.m_Weight;
}
}
}
public class SpawnGroup : SpawnDefinition
{
private static readonly Hashtable m_Table = new Hashtable();
private readonly string m_Name;
private readonly SpawnGroupElement[] m_Elements;
private readonly int m_TotalWeight;
public SpawnGroup(string name, SpawnGroupElement[] elements)
{
this.m_Name = name;
this.m_Elements = elements;
this.m_TotalWeight = 0;
for (int i = 0; i < elements.Length; i++)
this.m_TotalWeight += elements[i].Weight;
}
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)
{
XmlElement el = node as XmlElement;
if (el != null)
{
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 static Hashtable Table
{
get
{
return m_Table;
}
}
public string Name
{
get
{
return this.m_Name;
}
}
public SpawnGroupElement[] Elements
{
get
{
return this.m_Elements;
}
}
public static void Register(SpawnGroup group)
{
if (m_Table.Contains(group.Name))
Console.WriteLine("Warning: Double SpawnGroup name '{0}'", group.Name);
else
m_Table[group.Name] = group;
}
public override ISpawnable Spawn(SpawnEntry entry)
{
int index = Utility.Random(this.m_TotalWeight);
for (int i = 0; i < this.m_Elements.Length; i++)
{
SpawnGroupElement element = this.m_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 < this.m_Elements.Length; i++)
{
if (this.m_Elements[i].SpawnDefinition.CanSpawn(types))
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,560 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Commands;
using Server.ContextMenus;
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 readonly Hashtable m_Table = new Hashtable();
private static List<IEntity> m_RemoveList;
private readonly int m_ID;
private readonly BaseRegion m_Region;
private readonly Point3D m_Home;
private readonly int m_Range;
private readonly Direction m_Direction;
private readonly SpawnDefinition m_Definition;
private readonly List<ISpawnable> m_SpawnedObjects;
private readonly TimeSpan m_MinSpawnTime;
private readonly TimeSpan m_MaxSpawnTime;
private int m_Max;
private bool m_Running;
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)
{
this.m_ID = id;
this.m_Region = region;
this.m_Home = home;
this.m_Range = range;
this.m_Direction = direction;
this.m_Definition = definition;
this.m_SpawnedObjects = new List<ISpawnable>();
this.m_Max = max;
this.m_MinSpawnTime = minSpawnTime;
this.m_MaxSpawnTime = maxSpawnTime;
this.m_Running = false;
if (m_Table.Contains(id))
Console.WriteLine("Warning: double SpawnEntry ID '{0}'", id);
else
m_Table[id] = this;
}
public static Hashtable Table
{
get
{
return m_Table;
}
}
// When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home?
public bool ReturnOnDeactivate
{
get
{
return true;
}
}
// Are creatures unlinked on taming (true) or should they also go out of the region (false)?
public bool UnlinkOnTaming
{
get
{
return false;
}
}
// Are unlinked and untamed creatures removed after 20 hours?
public bool RemoveIfUntamed
{
get
{
return true;
}
}
public int ID
{
get
{
return this.m_ID;
}
}
public BaseRegion Region
{
get
{
return this.m_Region;
}
}
public Point3D HomeLocation
{
get
{
return this.m_Home;
}
}
public int HomeRange
{
get
{
return this.m_Range;
}
}
public Direction Direction
{
get
{
return this.m_Direction;
}
}
public SpawnDefinition Definition
{
get
{
return this.m_Definition;
}
}
public List<ISpawnable> SpawnedObjects
{
get
{
return this.m_SpawnedObjects;
}
}
public int Max
{
get
{
return this.m_Max;
}
}
public TimeSpan MinSpawnTime
{
get
{
return this.m_MinSpawnTime;
}
}
public TimeSpan MaxSpawnTime
{
get
{
return this.m_MaxSpawnTime;
}
}
public bool Running
{
get
{
return this.m_Running;
}
}
public bool Complete
{
get
{
return this.m_SpawnedObjects.Count >= this.m_Max;
}
}
public bool Spawning
{
get
{
return this.m_Running && !this.Complete;
}
}
public virtual void GetSpawnProperties(ISpawnable spawn, ObjectPropertyList list)
{ }
public virtual void GetSpawnContextEntries(ISpawnable spawn, Mobile m, List<ContextMenuEntry> list)
{ }
public static void Remove(GenericReader reader, int version)
{
int count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
int serial = reader.ReadInt();
IEntity entity = World.FindEntity(serial);
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, new CommandEventHandler(RespawnAllRegions_OnCommand));
CommandSystem.Register("RespawnRegion", AccessLevel.GameMaster, new CommandEventHandler(RespawnRegion_OnCommand));
CommandSystem.Register("DelAllRegionSpawns", AccessLevel.Administrator, new CommandEventHandler(DelAllRegionSpawns_OnCommand));
CommandSystem.Register("DelRegionSpawns", AccessLevel.GameMaster, new CommandEventHandler(DelRegionSpawns_OnCommand));
CommandSystem.Register("StartAllRegionSpawns", AccessLevel.Administrator, new CommandEventHandler(StartAllRegionSpawns_OnCommand));
CommandSystem.Register("StartRegionSpawns", AccessLevel.GameMaster, new CommandEventHandler(StartRegionSpawns_OnCommand));
CommandSystem.Register("StopAllRegionSpawns", AccessLevel.Administrator, new CommandEventHandler(StopAllRegionSpawns_OnCommand));
CommandSystem.Register("StopRegionSpawns", AccessLevel.GameMaster, new CommandEventHandler(StopRegionSpawns_OnCommand));
}
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water)
{
return this.m_Region.RandomSpawnLocation(spawnHeight, land, water, this.m_Home, this.m_Range);
}
public void Start()
{
if (this.m_Running)
return;
this.m_Running = true;
this.CheckTimer();
}
public void Stop()
{
if (!this.m_Running)
return;
this.m_Running = false;
this.CheckTimer();
}
public void DeleteSpawnedObjects()
{
this.InternalDeleteSpawnedObjects();
this.m_Running = false;
this.CheckTimer();
}
public void Respawn()
{
this.InternalDeleteSpawnedObjects();
for (int i = 0; !this.Complete && i < this.m_Max; i++)
this.Spawn();
this.m_Running = true;
this.CheckTimer();
}
public void Delete()
{
this.m_Max = 0;
this.InternalDeleteSpawnedObjects();
if (this.m_SpawnTimer != null)
{
this.m_SpawnTimer.Stop();
this.m_SpawnTimer = null;
}
if (m_Table[this.m_ID] == this)
m_Table.Remove(this.m_ID);
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)this.m_SpawnedObjects.Count);
for (int i = 0; i < this.m_SpawnedObjects.Count; i++)
{
ISpawnable spawn = this.m_SpawnedObjects[i];
int serial = spawn.Serial;
writer.Write((int)serial);
}
writer.Write((bool)this.m_Running);
if (this.m_SpawnTimer != null)
{
writer.Write(true);
writer.WriteDeltaTime((DateTime)this.m_NextSpawn);
}
else
{
writer.Write(false);
}
}
public void Deserialize(GenericReader reader, int version)
{
int count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
int serial = reader.ReadInt();
ISpawnable spawnableEntity = World.FindEntity(serial) as ISpawnable;
if (spawnableEntity != null)
this.Add(spawnableEntity);
}
this.m_Running = reader.ReadBool();
if (reader.ReadBool())
{
this.m_NextSpawn = reader.ReadDeltaTime();
if (this.Spawning)
{
if (this.m_SpawnTimer != null)
this.m_SpawnTimer.Stop();
TimeSpan delay = this.m_NextSpawn - DateTime.UtcNow;
this.m_SpawnTimer = Timer.DelayCall(delay > TimeSpan.Zero ? delay : TimeSpan.Zero, new TimerCallback(TimerCallback));
}
}
this.CheckTimer();
}
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);
//reg = (Region) from.Map.Regions[name];
if (!from.Map.Regions.TryGetValue(name, out reg))
{
from.SendMessage("Could not find region '{0}'.", name);
return null;
}
}
BaseRegion br = reg as BaseRegion;
if (br == null || br.Spawns == null)
{
from.SendMessage("There are no spawners in region '{0}'.", reg);
return null;
}
return br;
}
[Usage("RespawnAllRegions")]
[Description("Respawns all regions and sets the spawners as running.")]
private static void RespawnAllRegions_OnCommand(CommandEventArgs args)
{
foreach (SpawnEntry entry in m_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 m_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 m_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 m_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);
}
private void Spawn()
{
ISpawnable spawn = this.m_Definition.Spawn(this);
if (spawn != null)
this.Add(spawn);
}
private void Add(ISpawnable spawn)
{
this.m_SpawnedObjects.Add(spawn);
spawn.Spawner = this;
if (spawn is BaseCreature)
((BaseCreature)spawn).RemoveIfUntamed = this.RemoveIfUntamed;
}
void ISpawner.Remove(ISpawnable spawn)
{
this.m_SpawnedObjects.Remove(spawn);
this.CheckTimer();
}
private TimeSpan RandomTime()
{
int min = (int)this.m_MinSpawnTime.TotalSeconds;
int max = (int)this.m_MaxSpawnTime.TotalSeconds;
int rand = Utility.RandomMinMax(min, max);
return TimeSpan.FromSeconds(rand);
}
private void CheckTimer()
{
if (this.Spawning)
{
if (this.m_SpawnTimer == null)
{
TimeSpan time = this.RandomTime();
this.m_SpawnTimer = Timer.DelayCall(time, new TimerCallback(TimerCallback));
this.m_NextSpawn = DateTime.UtcNow + time;
}
}
else if (this.m_SpawnTimer != null)
{
this.m_SpawnTimer.Stop();
this.m_SpawnTimer = null;
}
}
private void TimerCallback()
{
int amount = Math.Max((this.m_Max - this.m_SpawnedObjects.Count) / 3, 1);
for (int i = 0; i < amount; i++)
this.Spawn();
this.m_SpawnTimer = null;
this.CheckTimer();
}
private void InternalDeleteSpawnedObjects()
{
foreach (ISpawnable spawnable in this.m_SpawnedObjects)
{
spawnable.Spawner = null;
bool uncontrolled = !(spawnable is BaseCreature) || !((BaseCreature)spawnable).Controlled;
if (uncontrolled)
spawnable.Delete();
}
this.m_SpawnedObjects.Clear();
}
}
}

View File

@@ -0,0 +1,75 @@
using System;
namespace Server.Regions
{
public class SpawnPersistence : Item
{
private static SpawnPersistence m_Instance;
public SpawnPersistence(Serial serial)
: base(serial)
{
m_Instance = this;
}
private SpawnPersistence()
: base(1)
{
this.Movable = false;
}
public SpawnPersistence Instance
{
get
{
return m_Instance;
}
}
public override string DefaultName
{
get
{
return "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((int)SpawnEntry.Table.Values.Count);
foreach (SpawnEntry entry in SpawnEntry.Table.Values)
{
writer.Write((int)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)SpawnEntry.Table[id];
if (entry != null)
entry.Deserialize(reader, version);
else
SpawnEntry.Remove(reader, version);
}
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Xml;
using System.Linq;
using Server.Engines.VvV;
using Server.Mobiles;
namespace Server.Regions
{
public class TownRegion : GuardedRegion
{
public TownRegion(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{
}
public override void OnEnter(Mobile m)
{
base.OnEnter(m);
if (ViceVsVirtueSystem.EnhancedRules &&
IsVvVBattleRegion() &&
ViceVsVirtueSystem.IsVvVCombatant(m) &&
ViceVsVirtueSystem.Instance != null &&
ViceVsVirtueSystem.Instance.Battle != null &&
ViceVsVirtueSystem.Instance.Battle.OnGoing &&
ViceVsVirtueSystem.Instance.Battle.Region == this)
{
ViceVsVirtueSystem.Instance.Battle.AddAggression(m);
}
}
public override void OnExit(Mobile m)
{
base.OnExit(m);
if (IsVvVBattleRegion() && m is PlayerMobile && m.HasGump(typeof(BattleWarningGump)))
{
m.CloseGump(typeof(BattleWarningGump));
}
}
private bool IsVvVBattleRegion()
{
return CityInfo.Infos.Any(kvp => IsPartOf(kvp.Value.Name) && Map == Map.Felucca);
}
}
}

View File

@@ -0,0 +1,44 @@
using System.Xml;
using Server.Network;
using Server.Spells;
using Server.Spells.Ninjitsu;
namespace Server.Regions
{
public class TwistedWealdDesert : MondainRegion
{
public TwistedWealdDesert(XmlElement xml, Map map, Region parent)
: base(xml, map, parent)
{
}
public static void Initialize()
{
EventSink.Login += new LoginEventHandler(Desert_OnLogin);
}
public override void OnEnter(Mobile m)
{
if (m.NetState != null &&
!TransformationSpellHelper.UnderTransformation(m, typeof(AnimalForm)) &&
m.AccessLevel < AccessLevel.GameMaster)
m.SendSpeedControl(SpeedControlType.WalkSpeed);
}
public override void OnExit(Mobile m)
{
if (m.NetState != null &&
!TransformationSpellHelper.UnderTransformation(m, typeof(AnimalForm)) &&
(Core.SA || !TransformationSpellHelper.UnderTransformation(m, typeof(Server.Spells.Spellweaving.ReaperFormSpell))))
m.SendSpeedControl(SpeedControlType.Disable);
}
private static void Desert_OnLogin(LoginEventArgs e)
{
Mobile m = e.Mobile;
if (m.Region.IsPartOf<TwistedWealdDesert>() && m.AccessLevel < AccessLevel.GameMaster)
m.SendSpeedControl(SpeedControlType.WalkSpeed);
}
}
}