#W# Source and Scripts added. Added Scripts/Settings.cs to expose some basic tweak able settings.

This commit is contained in:
WarrentyExpired 2026-08-06 11:06:05 -04:00
parent b51c58f514
commit 3045c83799
3512 changed files with 627673 additions and 0 deletions

View file

@ -0,0 +1,560 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Gumps;
namespace Server.Regions
{
public enum SpawnZLevel
{
Lowest,
Highest,
Random
}
public class BaseRegion : Region
{
public virtual bool YoungProtected { get { return true; } }
public virtual bool YoungMayEnter { get { return true; } }
public virtual bool MountsAllowed { get { return true; } }
public virtual bool DeadMayEnter { get { return true; } }
public virtual bool ResurrectionAllowed { get { return true; } }
public virtual bool LogoutAllowed { get { return true; } }
public static void Configure()
{
Region.DefaultRegionType = typeof( BaseRegion );
}
private string m_RuneName;
private bool m_NoLogoutDelay;
private SpawnEntry[] m_Spawns;
private SpawnZLevel m_SpawnZLevel;
private bool m_ExcludeFromParentSpawns;
public string RuneName{ get{ return m_RuneName; } set{ m_RuneName = value; } }
public bool NoLogoutDelay{ get{ return m_NoLogoutDelay; } set{ m_NoLogoutDelay = value; } }
public SpawnEntry[] Spawns
{
get{ return 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{ return m_SpawnZLevel; } set{ m_SpawnZLevel = value; } }
public bool ExcludeFromParentSpawns{ get{ return m_ExcludeFromParentSpawns; } set{ m_ExcludeFromParentSpawns = value; } }
public override void OnUnregister()
{
base.OnUnregister();
this.Spawns = null;
}
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 override TimeSpan GetLogoutDelay( Mobile m )
{
if ( m_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;
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 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 || !m_ExcludeFromParentSpawns )
return base.AcceptsSpawnsFrom( region );
return false;
}
private Rectangle3D[] m_Rectangles;
private int[] m_RectangleWeights;
private int m_TotalWeight;
private static List<Rectangle3D> m_RectBuffer1 = new List<Rectangle3D>();
private static List<Rectangle3D> m_RectBuffer2 = new List<Rectangle3D>();
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 < 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();
}
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;
}
}
private static List<Int32> m_SpawnBuffer1 = new List<Int32>();
private static List<Item> m_SpawnBuffer2 = new List<Item>();
public Point3D RandomSpawnLocation( int spawnHeight, bool land, bool water, Point3D home, int range )
{
Map map = this.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 < 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 ( 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.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 ( this.Name != null )
return this.Name;
else if ( this.RuneName != null )
return this.RuneName;
else
return this.GetType().Name;
}
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 );
m_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 );
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 )
{
m_Spawns = list.ToArray();
}
}
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Xml;
using Server;
using Server.Mobiles;
using Server.Gumps;
namespace Server.Regions
{
public class DungeonRegion : BaseRegion
{
public override bool YoungProtected { get { return false; } }
private Point3D m_EntranceLocation;
private Map m_EntranceMap;
public Point3D EntranceLocation{ get{ return m_EntranceLocation; } set{ m_EntranceLocation = value; } }
public Map EntranceMap{ get{ return m_EntranceMap; } set{ m_EntranceMap = value; } }
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 ) )
m_EntranceMap = entrMap;
}
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 ( this.Map == Map.Felucca )
return false;
return base.CanUseStuckMenu( m );
}
}
}

View file

@ -0,0 +1,40 @@
using System;
using System.Xml;
using Server;
using Server.Mobiles;
using Server.Spells;
using Server.Spells.Seventh;
using Server.Spells.Fourth;
using Server.Spells.Sixth;
using Server.Spells.Chivalry;
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;
else
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;
}
else
{
return base.OnBeginSpellCast( m, s );
}
}
}
}

View file

@ -0,0 +1,380 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using Server;
using Server.Commands;
using Server.Mobiles;
using Server.Spells;
namespace Server.Regions
{
public class GuardedRegion : BaseRegion
{
private static object[] m_GuardParams = new object[1];
private Type m_GuardType;
private bool m_Disabled;
public bool Disabled{ get{ return m_Disabled; } set{ m_Disabled = value; } }
public virtual bool IsDisabled()
{
return m_Disabled;
}
public static void Initialize()
{
CommandSystem.Register( "CheckGuarded", AccessLevel.GameMaster, new CommandEventHandler( CheckGuarded_OnCommand ) );
CommandSystem.Register( "SetGuarded", AccessLevel.Administrator, new CommandEventHandler( SetGuarded_OnCommand ) );
CommandSystem.Register( "ToggleGuarded", AccessLevel.Administrator, new CommandEventHandler( 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 = (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." );
}
}
public static GuardedRegion Disable( GuardedRegion reg )
{
reg.Disabled = true;
return reg;
}
public virtual bool AllowReds{ get{ return Core.AOS; } }
public virtual bool CheckVendorAccess( BaseVendor vendor, Mobile from )
{
if ( from.AccessLevel >= AccessLevel.GameMaster || IsDisabled() )
return true;
return ( from.Kills < 5 );
}
public virtual Type DefaultGuardType
{
get
{
if ( this.Map == Map.Ilshenar || this.Map == Map.Malas )
return typeof( ArcherGuard );
else
return typeof( WarriorGuard );
}
}
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 ) )
this.Disabled = disabled;
}
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.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 );
}
private Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
public void CheckGuardCandidate( Mobile m )
{
if ( IsDisabled() )
return;
if ( IsGuardCandidate( m ) )
{
GuardTimer timer = null;
m_GuardCandidates.TryGetValue( m, out timer );
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;
foreach ( Mobile v in m.GetMobilesInRange( 8 ) )
{
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;
}
}
}
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 ) && ( ( !AllowReds && m.Kills >= 5 && m.Region.IsPartOf( this ) ) || m_GuardCandidates.ContainsKey( m ) ) )
{
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.
break;
}
}
eable.Free();
}
public bool IsGuardCandidate( Mobile m )
{
if ( m is BaseGuard || !m.Alive || m.AccessLevel > AccessLevel.Player || m.Blessed || ( m is BaseCreature && ((BaseCreature)m).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.
}
}
}
}
}

View file

@ -0,0 +1,432 @@
using System;
using Server;
using Server.Mobiles;
using Server.Items;
using Server.Multis;
using Server.Spells;
using Server.Spells.Sixth;
using Server.Guilds;
using Server.Gumps;
namespace Server.Regions
{
public class HouseRegion : BaseRegion
{
public static readonly int HousePriority = Region.DefaultPriority + 1;
private BaseHouse m_House;
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 HouseRegion( BaseHouse house ) : base( null, house.Map, HousePriority, GetArea( house ) )
{
m_House = house;
Point3D ban = house.RelativeBanLocation;
this.GoLocation = new Point3D( house.X + ban.X, house.Y + ban.Y, house.Z + ban.Z );
}
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] = Region.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 m_House.CheckAccessibility( item, from );
}
private bool m_Recursion;
// 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 || m_House.IsInside( oldLocation, 16 )) )
{
}
else if ( (m_House.Public || !m_House.IsAosRules) && m_House.IsBanned( m ) && m_House.IsInside( m ) )
{
m.Location = m_House.BanLocation;
if( !Core.SE )
m.SendLocalizedMessage( 501284 ); // You may not enter.
}
else if ( m_House.IsAosRules && !m_House.Public && !m_House.HasAccess( m ) && m_House.IsInside( m ) )
{
m.Location = m_House.BanLocation;
if( !Core.SE )
m.SendLocalizedMessage( 501284 ); // You may not enter.
}
else if ( m_House.IsCombatRestricted( m ) && m_House.IsInside( m ) && !m_House.IsInside( oldLocation, 16 ) )
{
m.Location = m_House.BanLocation;
m.SendLocalizedMessage( 1061637 ); // You are not allowed to access this.
}
else if ( m_House is HouseFoundation )
{
HouseFoundation foundation = (HouseFoundation)m_House;
if ( foundation.Customizer != null && foundation.Customizer != m && m_House.IsInside( m ) )
m.Location = m_House.BanLocation;
}
if ( m_House.InternalizedVendors.Count > 0 && m_House.IsInside( m ) && !m_House.IsInside( oldLocation, 16 ) && m_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 || m_House.IsInside( oldLocation, 16 )) )
{
return false;
}
else if ( from is BaseCreature && !((BaseCreature)from).Controlled && m_House.IsAosRules && !m_House.Public)
{
return false;
}
else if ( (m_House.Public || !m_House.IsAosRules) && m_House.IsBanned( from ) && m_House.IsInside( newLocation, 16 ) )
{
from.Location = m_House.BanLocation;
if( !Core.SE )
from.SendLocalizedMessage( 501284 ); // You may not enter.
return false;
}
else if ( m_House.IsAosRules && !m_House.Public && !m_House.HasAccess( from ) && m_House.IsInside( newLocation, 16 ) )
{
if( !Core.SE )
from.SendLocalizedMessage( 501284 ); // You may not enter.
return false;
}
else if ( m_House.IsCombatRestricted( from ) && !m_House.IsInside( oldLocation, 16 ) && m_House.IsInside( newLocation, 16 ) )
{
from.SendLocalizedMessage( 1061637 ); // You are not allowed to access this.
return false;
}
else if ( m_House is HouseFoundation )
{
HouseFoundation foundation = (HouseFoundation)m_House;
if ( foundation.Customizer != null && foundation.Customizer != from && m_House.IsInside( newLocation, 16 ) )
return false;
}
if ( m_House.InternalizedVendors.Count > 0 && m_House.IsInside( from ) && !m_House.IsInside( oldLocation, 16 ) && m_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 ) );
}
return true;
}
public override bool OnDecay( Item item )
{
if ( (m_House.IsLockedDown( item ) || m_House.IsSecure( item )) && m_House.IsInside( item ) )
return false;
else
return base.OnDecay(item );
}
public static TimeSpan CombatHeatDelay = TimeSpan.FromSeconds( 30.0 );
public override TimeSpan GetLogoutDelay( Mobile m )
{
if ( m_House.IsFriend( m ) && 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 = m_House.Sign;
bool isOwner = m_House.IsOwner( from );
bool isCoOwner = isOwner || m_House.IsCoOwner( from );
bool isFriend = isCoOwner || m_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 <= m_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, m_House ) );
}
else
{
from.SendLocalizedMessage( 501320 ); // Only the house owner may do this.
}
}
if ( !m_House.IsInside( from ) || !m_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( m_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 ( !m_House.Public && m_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, m_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, m_House );
}
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( 0x24 ) ) // I wish to release this
{
if ( isCoOwner )
{
from.SendLocalizedMessage( 502100 ); // Choose the item you wish to release
from.Target = new LockdownTarget( true, m_House );
}
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( 0x25 ) ) // I wish to secure this
{
if ( isOwner )
{
from.SendLocalizedMessage( 502103 ); // Choose the item you wish to secure
from.Target = new SecureTarget( false, m_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, m_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 )
{
m_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 )
{
m_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 = m_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 ( m_House.IsLockedDown( item ) )
item.LabelTo( from, 501643 ); // [locked down]
else if ( m_House.IsSecure( item ) )
item.LabelTo( from, 501644 ); // [locked down & secure]
}
return base.OnSingleClick( from, o );
}
public BaseHouse House
{
get
{
return m_House;
}
}
}
}

61
Scripts/Regions/Jail.cs Normal file
View file

@ -0,0 +1,61 @@
using System;
using System.Xml;
using Server;
using Server.Spells;
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 );
}
}
}

View file

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

View file

@ -0,0 +1,409 @@
using System;
using System.Collections;
using System.IO;
using System.Xml;
using Server;
using Server.Mobiles;
using Server.Items;
using System.Collections.Generic;
namespace Server.Regions
{
public abstract class SpawnDefinition
{
protected 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 );
}
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 class SpawnType : SpawnDefinition
{
private Type m_Type;
private bool m_Init;
public Type Type{ get{ return m_Type; } }
public abstract int Height{ get; }
public abstract bool Land{ get; }
public abstract bool Water{ get; }
protected SpawnType( Type type )
{
m_Type = type;
m_Init = false;
}
protected void EnsureInit()
{
if ( m_Init )
return;
Init();
m_Init = true;
}
protected virtual void Init()
{
}
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 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] == m_Type )
return true;
}
return false;
}
}
public class SpawnMobile : SpawnType
{
private static Hashtable m_Table = new Hashtable();
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 bool m_Land;
protected bool m_Water;
public override int Height{ get{ return 16; } }
public override bool Land{ get{ EnsureInit(); return m_Land; } }
public override bool Water{ get{ EnsureInit(); return m_Water; } }
protected SpawnMobile( Type type ) : base( type )
{
}
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();
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( Type );
}
}
public class SpawnItem : SpawnType
{
private static Hashtable m_Table = new Hashtable();
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 int m_Height;
public override int Height{ get{ EnsureInit(); return m_Height; } }
public override bool Land{ get{ return true; } }
public override bool Water{ get{ return false; } }
protected SpawnItem( Type type ) : base( type )
{
}
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
{
private int m_ItemID;
private BaseTreasureChest.TreasureLevel m_Level;
public int ItemID{ get{ return m_ItemID; } }
public BaseTreasureChest.TreasureLevel Level{ get{ return m_Level; } }
public SpawnTreasureChest( int itemID, BaseTreasureChest.TreasureLevel level ) : base( typeof( BaseTreasureChest ) )
{
m_ItemID = itemID;
m_Level = level;
}
protected override void Init()
{
m_Height = TileData.ItemTable[m_ItemID & TileData.MaxItemValue].Height;
}
protected override Item CreateItem()
{
return new BaseTreasureChest( m_ItemID, m_Level );
}
}
public class SpawnGroupElement
{
private SpawnDefinition m_SpawnDefinition;
private int m_Weight;
public SpawnDefinition SpawnDefinition{ get{ return m_SpawnDefinition; } }
public int Weight{ get{ return m_Weight; } }
public SpawnGroupElement( SpawnDefinition spawnDefinition, int weight )
{
m_SpawnDefinition = spawnDefinition;
m_Weight = weight;
}
}
public class SpawnGroup : SpawnDefinition
{
private static Hashtable m_Table = new Hashtable();
public static Hashtable Table{ get{ return m_Table; } }
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;
}
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 );
}
}
private string m_Name;
private SpawnGroupElement[] m_Elements;
private int m_TotalWeight;
public string Name{ get{ return m_Name; } }
public SpawnGroupElement[] Elements{ get{ return m_Elements; } }
public SpawnGroup( string name, SpawnGroupElement[] elements )
{
m_Name = name;
m_Elements = elements;
m_TotalWeight = 0;
for ( int i = 0; i < elements.Length; i++ )
m_TotalWeight += elements[i].Weight;
}
public override ISpawnable Spawn(SpawnEntry entry)
{
int index = Utility.Random( m_TotalWeight );
for ( int i = 0; i < m_Elements.Length; i++ )
{
SpawnGroupElement element = 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 < m_Elements.Length; i++ )
{
if ( m_Elements[i].SpawnDefinition.CanSpawn( types ) )
return true;
}
return false;
}
}
}

View file

@ -0,0 +1,465 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Mobiles;
using Server.Commands;
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 );
private static Hashtable m_Table = new Hashtable();
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 static readonly Direction InvalidDirection = Direction.Running;
private int m_ID;
private BaseRegion m_Region;
private Point3D m_Home;
private int m_Range;
private Direction m_Direction;
private SpawnDefinition m_Definition;
private List<ISpawnable> m_SpawnedObjects;
private int m_Max;
private TimeSpan m_MinSpawnTime;
private TimeSpan m_MaxSpawnTime;
private bool m_Running;
private DateTime m_NextSpawn;
private Timer m_SpawnTimer;
public int ID{ get{ return m_ID; } }
public BaseRegion Region{ get{ return m_Region; } }
public Point3D HomeLocation{ get{ return m_Home; } }
public int HomeRange{ get{ return m_Range; } }
public Direction Direction{ get{ return m_Direction; } }
public SpawnDefinition Definition{ get{ return m_Definition; } }
public List<ISpawnable> SpawnedObjects{ get{ return m_SpawnedObjects; } }
public int Max{ get{ return m_Max; } }
public TimeSpan MinSpawnTime{ get{ return m_MinSpawnTime; } }
public TimeSpan MaxSpawnTime{ get{ return m_MaxSpawnTime; } }
public bool Running{ get{ return m_Running; } }
public bool Complete{ get{ return m_SpawnedObjects.Count >= m_Max; } }
public bool Spawning{ get{ return m_Running && !this.Complete; } }
public SpawnEntry( int id, BaseRegion region, Point3D home, int range, Direction direction, SpawnDefinition definition, int max, TimeSpan minSpawnTime, TimeSpan maxSpawnTime )
{
m_ID = id;
m_Region = region;
m_Home = home;
m_Range = range;
m_Direction = direction;
m_Definition = definition;
m_SpawnedObjects = new List<ISpawnable>();
m_Max = max;
m_MinSpawnTime = minSpawnTime;
m_MaxSpawnTime = maxSpawnTime;
m_Running = false;
if ( m_Table.Contains( id ) )
Console.WriteLine( "Warning: double SpawnEntry ID '{0}'", id );
else
m_Table[id] = this;
}
public Point3D RandomSpawnLocation( int spawnHeight, bool land, bool water )
{
return m_Region.RandomSpawnLocation( spawnHeight, land, water, m_Home, m_Range );
}
public void Start()
{
if ( m_Running )
return;
m_Running = true;
CheckTimer();
}
public void Stop()
{
if ( !m_Running )
return;
m_Running = false;
CheckTimer();
}
private void Spawn()
{
ISpawnable spawn = m_Definition.Spawn(this);
if ( spawn != null )
Add( spawn );
}
private void Add( ISpawnable spawn )
{
m_SpawnedObjects.Add( spawn );
spawn.Spawner = this;
if ( spawn is BaseCreature )
((BaseCreature)spawn).RemoveIfUntamed = this.RemoveIfUntamed;
}
void ISpawner.Remove( ISpawnable spawn )
{
m_SpawnedObjects.Remove( spawn );
CheckTimer();
}
private TimeSpan RandomTime()
{
int min = (int) m_MinSpawnTime.TotalSeconds;
int max = (int) m_MaxSpawnTime.TotalSeconds;
int rand = Utility.RandomMinMax( min, max );
return TimeSpan.FromSeconds( rand );
}
private void CheckTimer()
{
if ( this.Spawning )
{
if ( m_SpawnTimer == null )
{
TimeSpan time = RandomTime();
m_SpawnTimer = Timer.DelayCall( time, new TimerCallback( TimerCallback ) );
m_NextSpawn = DateTime.UtcNow + time;
}
}
else if ( m_SpawnTimer != null )
{
m_SpawnTimer.Stop();
m_SpawnTimer = null;
}
}
private void TimerCallback()
{
int amount = Math.Max( (m_Max - m_SpawnedObjects.Count) / 3, 1 );
for ( int i = 0; i < amount; i++ )
Spawn();
m_SpawnTimer = null;
CheckTimer();
}
public void DeleteSpawnedObjects()
{
InternalDeleteSpawnedObjects();
m_Running = false;
CheckTimer();
}
private void InternalDeleteSpawnedObjects()
{
foreach ( ISpawnable spawnable in m_SpawnedObjects )
{
spawnable.Spawner = null;
bool uncontrolled = !(spawnable is BaseCreature) || !((BaseCreature)spawnable).Controlled;
if( uncontrolled )
spawnable.Delete();
}
m_SpawnedObjects.Clear();
}
public void Respawn()
{
InternalDeleteSpawnedObjects();
for ( int i = 0; !this.Complete && i < m_Max; i++ )
Spawn();
m_Running = true;
CheckTimer();
}
public void Delete()
{
m_Max = 0;
InternalDeleteSpawnedObjects();
if ( m_SpawnTimer != null )
{
m_SpawnTimer.Stop();
m_SpawnTimer = null;
}
if ( m_Table[m_ID] == this )
m_Table.Remove( m_ID );
}
public void Serialize( GenericWriter writer )
{
writer.Write( (int) m_SpawnedObjects.Count );
for ( int i = 0; i < m_SpawnedObjects.Count; i++ )
{
ISpawnable spawn = m_SpawnedObjects[i];
int serial = spawn.Serial;
writer.Write( (int) serial );
}
writer.Write( (bool) m_Running );
if ( m_SpawnTimer != null )
{
writer.Write( true );
writer.WriteDeltaTime( (DateTime) 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)
Add(spawnableEntity);
}
m_Running = reader.ReadBool();
if ( reader.ReadBool() )
{
m_NextSpawn = reader.ReadDeltaTime();
if ( this.Spawning )
{
if ( m_SpawnTimer != null )
m_SpawnTimer.Stop();
TimeSpan delay = m_NextSpawn - DateTime.UtcNow;
m_SpawnTimer = Timer.DelayCall( delay > TimeSpan.Zero ? delay : TimeSpan.Zero, new TimerCallback( TimerCallback ) );
}
}
CheckTimer();
}
private static List<IEntity> m_RemoveList;
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 ) );
}
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 );
}
}
}

View file

@ -0,0 +1,69 @@
using System;
using System.Collections;
using Server;
namespace Server.Regions
{
public class SpawnPersistence : Item
{
private static SpawnPersistence m_Instance;
public SpawnPersistence Instance{ get{ return m_Instance; } }
public static void EnsureExistence()
{
if ( m_Instance == null )
m_Instance = new SpawnPersistence();
}
public override string DefaultName
{
get { return "Region spawn persistence - Internal"; }
}
private SpawnPersistence() : base( 1 )
{
Movable = false;
}
public SpawnPersistence( Serial serial ) : base( serial )
{
m_Instance = this;
}
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,13 @@
using System;
using System.Xml;
using Server;
namespace Server.Regions
{
public class TownRegion : GuardedRegion
{
public TownRegion( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
{
}
}
}