Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -2,44 +2,47 @@ using System.Xml;
|
|||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class DungeonRegion : BaseRegion
|
||||
{
|
||||
public override bool YoungProtected => false;
|
||||
public class DungeonRegion : BaseRegion
|
||||
{
|
||||
private Point3D m_EntranceLocation;
|
||||
|
||||
private Point3D m_EntranceLocation;
|
||||
public DungeonRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
XmlElement entrEl = xml["entrance"];
|
||||
|
||||
public Point3D EntranceLocation{ get => m_EntranceLocation;
|
||||
set => m_EntranceLocation = value;
|
||||
}
|
||||
public Map EntranceMap { get; set; }
|
||||
Map entrMap = map;
|
||||
ReadMap(entrEl, "map", ref entrMap, false);
|
||||
|
||||
public DungeonRegion( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
|
||||
{
|
||||
XmlElement entrEl = xml["entrance"];
|
||||
if (ReadPoint3D(entrEl, entrMap, ref m_EntranceLocation, false))
|
||||
EntranceMap = entrMap;
|
||||
}
|
||||
|
||||
Map entrMap = map;
|
||||
ReadMap( entrEl, "map", ref entrMap, false );
|
||||
public override bool YoungProtected => false;
|
||||
|
||||
if ( ReadPoint3D( entrEl, entrMap, ref m_EntranceLocation, false ) )
|
||||
EntranceMap = entrMap;
|
||||
}
|
||||
public Point3D EntranceLocation
|
||||
{
|
||||
get => m_EntranceLocation;
|
||||
set => m_EntranceLocation = value;
|
||||
}
|
||||
|
||||
public override bool AllowHousing( Mobile from, Point3D p )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public Map EntranceMap{ get; set; }
|
||||
|
||||
public override void AlterLightLevel( Mobile m, ref int global, ref int personal )
|
||||
{
|
||||
global = LightCycle.DungeonLevel;
|
||||
}
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool CanUseStuckMenu( Mobile m )
|
||||
{
|
||||
if ( Map == Map.Felucca )
|
||||
return false;
|
||||
public override void AlterLightLevel(Mobile m, ref int global, ref int personal)
|
||||
{
|
||||
global = LightCycle.DungeonLevel;
|
||||
}
|
||||
|
||||
return base.CanUseStuckMenu( m );
|
||||
}
|
||||
}
|
||||
}
|
||||
public override bool CanUseStuckMenu(Mobile m)
|
||||
{
|
||||
if (Map == Map.Felucca)
|
||||
return false;
|
||||
|
||||
return base.CanUseStuckMenu(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +1,34 @@
|
|||
using System.Xml;
|
||||
using Server.Spells.Seventh;
|
||||
using Server.Spells.Fourth;
|
||||
using Server.Spells.Sixth;
|
||||
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 class GreenAcres : BaseRegion
|
||||
{
|
||||
public GreenAcres(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool AllowHousing( Mobile from, Point3D p )
|
||||
{
|
||||
if ( from.AccessLevel == AccessLevel.Player )
|
||||
return false;
|
||||
return base.AllowHousing( from, p );
|
||||
}
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
if (from.AccessLevel == AccessLevel.Player)
|
||||
return false;
|
||||
return base.AllowHousing(from, p);
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast( Mobile m, ISpell s )
|
||||
{
|
||||
if ( ( s is GateTravelSpell || s is RecallSpell || s is MarkSpell || s is SacredJourneySpell ) && m.AccessLevel == AccessLevel.Player )
|
||||
{
|
||||
m.SendMessage( "You cannot cast that spell here." );
|
||||
return false;
|
||||
}
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if ((s is GateTravelSpell || s is RecallSpell || s is MarkSpell || s is SacredJourneySpell) &&
|
||||
m.AccessLevel == AccessLevel.Player)
|
||||
{
|
||||
m.SendMessage("You cannot cast that spell here.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast( m, s );
|
||||
}
|
||||
}
|
||||
}
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,363 +6,369 @@ using Server.Mobiles;
|
|||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class GuardedRegion : BaseRegion
|
||||
{
|
||||
private static object[] m_GuardParams = new object[1];
|
||||
private Type m_GuardType;
|
||||
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
public virtual bool IsDisabled()
|
||||
{
|
||||
return Disabled;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register( "CheckGuarded", AccessLevel.GameMaster, CheckGuarded_OnCommand );
|
||||
CommandSystem.Register( "SetGuarded", AccessLevel.Administrator, SetGuarded_OnCommand );
|
||||
CommandSystem.Register( "ToggleGuarded", AccessLevel.Administrator, ToggleGuarded_OnCommand );
|
||||
}
|
||||
|
||||
[Usage( "CheckGuarded" )]
|
||||
[Description( "Returns a value indicating if the current region is guarded or not." )]
|
||||
private static void CheckGuarded_OnCommand( CommandEventArgs e )
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
GuardedRegion reg = (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 => 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 ( Map == Map.Ilshenar || Map == Map.Malas )
|
||||
return typeof( ArcherGuard );
|
||||
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 ) )
|
||||
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<BaseGuard> eable = focus.GetMobilesInRange<BaseGuard>( 8 );
|
||||
foreach (BaseGuard m in eable)
|
||||
{
|
||||
if ( m.Focus == null ) // idling
|
||||
{
|
||||
useGuard = m;
|
||||
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 ) )
|
||||
{
|
||||
m_GuardCandidates.TryGetValue( m, out GuardTimer 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 as BaseCreature)?.IsHumanInTown() ?? (v.Body.IsHuman && v.Region.IsPartOf( this ))) )
|
||||
{
|
||||
double dist = m.GetDistanceToSqrt( v );
|
||||
|
||||
if ( fakeCall == null || dist < prio )
|
||||
{
|
||||
fakeCall = v;
|
||||
prio = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( fakeCall != null )
|
||||
{
|
||||
fakeCall.Say( Utility.RandomList( 1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042, 1013043, 1013052 ) );
|
||||
MakeGuard( m );
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove( m );
|
||||
m.SendLocalizedMessage( 502276 ); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CallGuards( Point3D p )
|
||||
{
|
||||
if ( IsDisabled() )
|
||||
return;
|
||||
|
||||
IPooledEnumerable<Mobile> eable = Map.GetMobilesInRange( p, 14 );
|
||||
|
||||
foreach ( Mobile m in eable )
|
||||
{
|
||||
if ( IsGuardCandidate( m ) && ( ( !AllowReds && m.Kills >= 5 && m.Region.IsPartOf( this ) ) || m_GuardCandidates.ContainsKey( m ) ) )
|
||||
{
|
||||
m_GuardCandidates.TryGetValue( m, out GuardTimer 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class GuardedRegion : BaseRegion
|
||||
{
|
||||
private static object[] m_GuardParams = new object[1];
|
||||
|
||||
private Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
|
||||
private Type m_GuardType;
|
||||
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle3D[] area) : base(name, map, priority, area)
|
||||
{
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area)
|
||||
: base(name, map, priority, area)
|
||||
{
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
public GuardedRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
XmlElement el = xml["guards"];
|
||||
|
||||
if (ReadType(el, "type", ref m_GuardType, false))
|
||||
{
|
||||
if (!typeof(Mobile).IsAssignableFrom(m_GuardType))
|
||||
{
|
||||
Console.WriteLine("Invalid guard type for region '{0}'", this);
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_GuardType = DefaultGuardType;
|
||||
}
|
||||
|
||||
bool disabled = false;
|
||||
if (ReadBoolean(el, "disabled", ref disabled, false))
|
||||
Disabled = disabled;
|
||||
}
|
||||
|
||||
public bool Disabled{ get; set; }
|
||||
|
||||
public virtual bool AllowReds => Core.AOS;
|
||||
|
||||
public virtual Type DefaultGuardType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Map == Map.Ilshenar || Map == Map.Malas)
|
||||
return typeof(ArcherGuard);
|
||||
return typeof(WarriorGuard);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsDisabled()
|
||||
{
|
||||
return Disabled;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("CheckGuarded", AccessLevel.GameMaster, CheckGuarded_OnCommand);
|
||||
CommandSystem.Register("SetGuarded", AccessLevel.Administrator, SetGuarded_OnCommand);
|
||||
CommandSystem.Register("ToggleGuarded", AccessLevel.Administrator, ToggleGuarded_OnCommand);
|
||||
}
|
||||
|
||||
[Usage("CheckGuarded")]
|
||||
[Description("Returns a value indicating if the current region is guarded or not.")]
|
||||
private static void CheckGuarded_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
GuardedRegion reg = (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 CheckVendorAccess(BaseVendor vendor, Mobile from)
|
||||
{
|
||||
if (from.AccessLevel >= AccessLevel.GameMaster || IsDisabled())
|
||||
return true;
|
||||
|
||||
return from.Kills < 5;
|
||||
}
|
||||
|
||||
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
||||
{
|
||||
if (!IsDisabled() && !s.OnCastInTown(this))
|
||||
{
|
||||
m.SendLocalizedMessage(500946); // You cannot cast this in town!
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeginSpellCast(m, s);
|
||||
}
|
||||
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void MakeGuard(Mobile focus)
|
||||
{
|
||||
BaseGuard useGuard = null;
|
||||
|
||||
IPooledEnumerable<BaseGuard> eable = focus.GetMobilesInRange<BaseGuard>(8);
|
||||
foreach (BaseGuard m in eable)
|
||||
if (m.Focus == null) // idling
|
||||
{
|
||||
useGuard = m;
|
||||
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);
|
||||
}
|
||||
|
||||
public void CheckGuardCandidate(Mobile m)
|
||||
{
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
if (IsGuardCandidate(m))
|
||||
{
|
||||
m_GuardCandidates.TryGetValue(m, out GuardTimer 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 as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
|
||||
{
|
||||
double dist = m.GetDistanceToSqrt(v);
|
||||
|
||||
if (fakeCall == null || dist < prio)
|
||||
{
|
||||
fakeCall = v;
|
||||
prio = dist;
|
||||
}
|
||||
}
|
||||
|
||||
if (fakeCall != null)
|
||||
{
|
||||
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
|
||||
1013043, 1013052));
|
||||
MakeGuard(m);
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CallGuards(Point3D p)
|
||||
{
|
||||
if (IsDisabled())
|
||||
return;
|
||||
|
||||
IPooledEnumerable<Mobile> eable = Map.GetMobilesInRange(p, 14);
|
||||
|
||||
foreach (Mobile m in eable)
|
||||
if (IsGuardCandidate(m) &&
|
||||
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
|
||||
{
|
||||
m_GuardCandidates.TryGetValue(m, out GuardTimer 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,419 +1,399 @@
|
|||
using System;
|
||||
using Server.Mobiles;
|
||||
using Server.Items;
|
||||
using Server.Multis;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Multis;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class HouseRegion : BaseRegion
|
||||
{
|
||||
public static readonly int HousePriority = DefaultPriority + 1;
|
||||
public class HouseRegion : BaseRegion
|
||||
{
|
||||
public static readonly int HousePriority = DefaultPriority + 1;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.Login += OnLogin;
|
||||
}
|
||||
public static TimeSpan CombatHeatDelay = TimeSpan.FromSeconds(30.0);
|
||||
|
||||
public static void OnLogin( LoginEventArgs e )
|
||||
{
|
||||
BaseHouse house = BaseHouse.FindHouseAt( e.Mobile );
|
||||
private bool m_Recursion;
|
||||
|
||||
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))
|
||||
{
|
||||
House = house;
|
||||
|
||||
public HouseRegion( BaseHouse house ) : base( null, house.Map, HousePriority, GetArea( house ) )
|
||||
{
|
||||
House = house;
|
||||
Point3D ban = house.RelativeBanLocation;
|
||||
|
||||
Point3D ban = house.RelativeBanLocation;
|
||||
GoLocation = new Point3D(house.X + ban.X, house.Y + ban.Y, house.Z + ban.Z);
|
||||
}
|
||||
|
||||
GoLocation = new Point3D( house.X + ban.X, house.Y + ban.Y, house.Z + ban.Z );
|
||||
}
|
||||
public BaseHouse House{ get; }
|
||||
|
||||
public override bool AllowHousing( Mobile from, Point3D p )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public static void Initialize()
|
||||
{
|
||||
EventSink.Login += OnLogin;
|
||||
}
|
||||
|
||||
private static Rectangle3D[] GetArea( BaseHouse house )
|
||||
{
|
||||
int x = house.X;
|
||||
int y = house.Y;
|
||||
int z = house.Z;
|
||||
public static void OnLogin(LoginEventArgs e)
|
||||
{
|
||||
BaseHouse house = BaseHouse.FindHouseAt(e.Mobile);
|
||||
|
||||
Rectangle2D[] houseArea = house.Area;
|
||||
Rectangle3D[] area = new Rectangle3D[houseArea.Length];
|
||||
if (house != null && !house.Public && !house.IsFriend(e.Mobile))
|
||||
e.Mobile.Location = house.BanLocation;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < area.Length; i++ )
|
||||
{
|
||||
Rectangle2D rect = houseArea[i];
|
||||
area[i] = ConvertTo3D( new Rectangle2D( x + rect.Start.X, y + rect.Start.Y, rect.Width, rect.Height ) );
|
||||
}
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return area;
|
||||
}
|
||||
private static Rectangle3D[] GetArea(BaseHouse house)
|
||||
{
|
||||
int x = house.X;
|
||||
int y = house.Y;
|
||||
int z = house.Z;
|
||||
|
||||
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.
|
||||
Rectangle2D[] houseArea = house.Area;
|
||||
Rectangle3D[] area = new Rectangle3D[houseArea.Length];
|
||||
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < area.Length; i++)
|
||||
{
|
||||
Rectangle2D rect = houseArea[i];
|
||||
area[i] = ConvertTo3D(new Rectangle2D(x + rect.Start.X, y + rect.Start.Y, rect.Width, rect.Height));
|
||||
}
|
||||
|
||||
public override bool CheckAccessibility( Item item, Mobile from )
|
||||
{
|
||||
return House.CheckAccessibility( item, from );
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
private bool m_Recursion;
|
||||
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.
|
||||
|
||||
// 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
base.OnLocationChanged( m, oldLocation );
|
||||
public override bool CheckAccessibility(Item item, Mobile from)
|
||||
{
|
||||
return House.CheckAccessibility(item, from);
|
||||
}
|
||||
|
||||
m_Recursion = true;
|
||||
// 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;
|
||||
|
||||
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;
|
||||
base.OnLocationChanged(m, oldLocation);
|
||||
|
||||
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;
|
||||
m_Recursion = true;
|
||||
|
||||
if ( !Core.SE )
|
||||
m.SendLocalizedMessage( 501284 ); // You may not enter.
|
||||
}
|
||||
else if ( House.IsCombatRestricted( m ) && House.IsInside( m ) && !House.IsInside( oldLocation, 16 ) )
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
m.SendLocalizedMessage( 1061637 ); // You are not allowed to access this.
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
if (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 ( foundation?.Customizer != null && foundation.Customizer != 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 ( 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 ) );
|
||||
}
|
||||
if (!Core.SE)
|
||||
m.SendLocalizedMessage(501284); // You may not enter.
|
||||
}
|
||||
else if (House.IsCombatRestricted(m) && House.IsInside(m) && !House.IsInside(oldLocation, 16))
|
||||
{
|
||||
m.Location = House.BanLocation;
|
||||
m.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
|
||||
m_Recursion = false;
|
||||
}
|
||||
if (foundation?.Customizer != null && foundation.Customizer != m && House.IsInside(m))
|
||||
m.Location = House.BanLocation;
|
||||
}
|
||||
|
||||
public override bool OnMoveInto( Mobile from, Direction d, Point3D newLocation, Point3D oldLocation )
|
||||
{
|
||||
if ( !base.OnMoveInto( from, d, newLocation, oldLocation ) )
|
||||
return false;
|
||||
if (House.InternalizedVendors.Count > 0 && House.IsInside(m) && !House.IsInside(oldLocation, 16) &&
|
||||
House.IsOwner(m) && m.Alive &&
|
||||
!m.HasGump(typeof(NoticeGump)))
|
||||
m.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null));
|
||||
|
||||
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;
|
||||
m_Recursion = false;
|
||||
}
|
||||
|
||||
if ( !Core.SE )
|
||||
from.SendLocalizedMessage( 501284 ); // You may not enter.
|
||||
public override bool OnMoveInto(Mobile from, Direction d, Point3D newLocation, Point3D oldLocation)
|
||||
{
|
||||
if (!base.OnMoveInto(from, d, newLocation, oldLocation))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
else if ( House.IsAosRules && !House.Public && !House.HasAccess( from ) && House.IsInside( newLocation, 16 ) )
|
||||
{
|
||||
if ( !Core.SE )
|
||||
from.SendLocalizedMessage( 501284 ); // You may not enter.
|
||||
if (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;
|
||||
|
||||
return false;
|
||||
}
|
||||
else if ( House.IsCombatRestricted( from ) && !House.IsInside( oldLocation, 16 ) && House.IsInside( newLocation, 16 ) )
|
||||
{
|
||||
from.SendLocalizedMessage( 1061637 ); // You are not allowed to access this.
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
|
||||
if ( foundation?.Customizer != null && foundation.Customizer != from && House.IsInside( newLocation, 16 ) )
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (House.IsAosRules && !House.Public && !House.HasAccess(from) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
if (!Core.SE)
|
||||
from.SendLocalizedMessage(501284); // You may not enter.
|
||||
|
||||
if ( 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 ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (House.IsCombatRestricted(from) && !House.IsInside(oldLocation, 16) && House.IsInside(newLocation, 16))
|
||||
{
|
||||
from.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
HouseFoundation foundation = House as HouseFoundation;
|
||||
|
||||
return true;
|
||||
}
|
||||
if (foundation?.Customizer != null && foundation.Customizer != from && House.IsInside(newLocation, 16))
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool OnDecay( Item item )
|
||||
{
|
||||
if ( (House.IsLockedDown( item ) || House.IsSecure( item )) && House.IsInside( item ) )
|
||||
return false;
|
||||
return base.OnDecay(item );
|
||||
}
|
||||
if (House.InternalizedVendors.Count > 0 && House.IsInside(from) && !House.IsInside(oldLocation, 16) &&
|
||||
House.IsOwner(from) && from.Alive &&
|
||||
!from.HasGump(typeof(NoticeGump)))
|
||||
from.SendGump(new NoticeGump(1060635, 30720, 1061826, 32512, 320, 180, null, null));
|
||||
|
||||
public static TimeSpan CombatHeatDelay = TimeSpan.FromSeconds( 30.0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
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];
|
||||
public override bool OnDecay(Item item)
|
||||
{
|
||||
if ((House.IsLockedDown(item) || House.IsSecure(item)) && House.IsInside(item))
|
||||
return false;
|
||||
return base.OnDecay(item);
|
||||
}
|
||||
|
||||
if ( info.Defender.Player && (DateTime.UtcNow - info.LastCombatTime) < CombatHeatDelay )
|
||||
return base.GetLogoutDelay( m );
|
||||
}
|
||||
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];
|
||||
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
if (info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatHeatDelay)
|
||||
return base.GetLogoutDelay(m);
|
||||
}
|
||||
|
||||
return base.GetLogoutDelay( m );
|
||||
}
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
public override void OnSpeech( SpeechEventArgs e )
|
||||
{
|
||||
base.OnSpeech( e );
|
||||
return base.GetLogoutDelay(m);
|
||||
}
|
||||
|
||||
Mobile from = e.Mobile;
|
||||
Item sign = House.Sign;
|
||||
public override void OnSpeech(SpeechEventArgs e)
|
||||
{
|
||||
base.OnSpeech(e);
|
||||
|
||||
bool isOwner = House.IsOwner( from );
|
||||
bool isCoOwner = isOwner || House.IsCoOwner( from );
|
||||
bool isFriend = isCoOwner || House.IsFriend( from );
|
||||
Mobile from = e.Mobile;
|
||||
Item sign = House.Sign;
|
||||
|
||||
if ( !isFriend )
|
||||
return;
|
||||
bool isOwner = House.IsOwner(from);
|
||||
bool isCoOwner = isOwner || House.IsCoOwner(from);
|
||||
bool isFriend = isCoOwner || House.IsFriend(from);
|
||||
|
||||
if ( !from.Alive )
|
||||
return;
|
||||
if (!isFriend)
|
||||
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 this.
|
||||
}
|
||||
}
|
||||
if (!from.Alive)
|
||||
return;
|
||||
|
||||
if ( !House.IsInside( from ) || !House.IsActive )
|
||||
return;
|
||||
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 ( isCoOwner )
|
||||
{
|
||||
from.SendLocalizedMessage( 502097 ); // Lock what down?
|
||||
from.Target = new LockdownTarget( false, 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, 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, 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
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 this.
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnDoubleClick( Mobile from, object o )
|
||||
{
|
||||
if ( o is Container )
|
||||
{
|
||||
Container c = (Container)o;
|
||||
if (!House.IsInside(from) || !House.IsActive)
|
||||
return;
|
||||
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 (isCoOwner)
|
||||
{
|
||||
from.SendLocalizedMessage(502097); // Lock what down?
|
||||
from.Target = new LockdownTarget(false, 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, 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, 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.
|
||||
}
|
||||
}
|
||||
|
||||
SecureAccessResult res = House.CheckSecureAccess( from, c );
|
||||
public override bool OnDoubleClick(Mobile from, object o)
|
||||
{
|
||||
if (o is Container)
|
||||
{
|
||||
Container c = (Container)o;
|
||||
|
||||
switch ( res )
|
||||
{
|
||||
case SecureAccessResult.Insecure: break;
|
||||
case SecureAccessResult.Accessible: return true;
|
||||
case SecureAccessResult.Inaccessible: c.SendLocalizedMessageTo( from, 1010563 ); return false;
|
||||
}
|
||||
}
|
||||
SecureAccessResult res = House.CheckSecureAccess(from, c);
|
||||
|
||||
return base.OnDoubleClick( from, o );
|
||||
}
|
||||
switch (res)
|
||||
{
|
||||
case SecureAccessResult.Insecure: break;
|
||||
case SecureAccessResult.Accessible: return true;
|
||||
case SecureAccessResult.Inaccessible:
|
||||
c.SendLocalizedMessageTo(from, 1010563);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnSingleClick( Mobile from, object o )
|
||||
{
|
||||
if ( o is Item )
|
||||
{
|
||||
Item item = (Item)o;
|
||||
return base.OnDoubleClick(from, o);
|
||||
}
|
||||
|
||||
if ( House.IsLockedDown( item ) )
|
||||
item.LabelTo( from, 501643 ); // [locked down]
|
||||
else if ( House.IsSecure( item ) )
|
||||
item.LabelTo( from, 501644 ); // [locked down & secure]
|
||||
}
|
||||
public override bool OnSingleClick(Mobile from, object o)
|
||||
{
|
||||
if (o is Item)
|
||||
{
|
||||
Item item = (Item)o;
|
||||
|
||||
return base.OnSingleClick( from, o );
|
||||
}
|
||||
if (House.IsLockedDown(item))
|
||||
item.LabelTo(from, 501643); // [locked down]
|
||||
else if (House.IsSecure(item))
|
||||
item.LabelTo(from, 501644); // [locked down & secure]
|
||||
}
|
||||
|
||||
public BaseHouse House { get; }
|
||||
}
|
||||
}
|
||||
return base.OnSingleClick(from, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,57 +2,57 @@ using System.Xml;
|
|||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class Jail : BaseRegion
|
||||
{
|
||||
public Jail( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
|
||||
{
|
||||
}
|
||||
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." );
|
||||
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 );
|
||||
}
|
||||
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." );
|
||||
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 );
|
||||
}
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool AllowHousing( Mobile from, Point3D p )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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 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.
|
||||
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 );
|
||||
}
|
||||
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." );
|
||||
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 );
|
||||
}
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
|
||||
public override bool OnCombatantChange( Mobile from, Mobile Old, Mobile New )
|
||||
{
|
||||
return ( from.AccessLevel > AccessLevel.Player );
|
||||
}
|
||||
}
|
||||
public override bool OnCombatantChange(Mobile from, Mobile Old, Mobile New)
|
||||
{
|
||||
return from.AccessLevel > AccessLevel.Player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,23 +2,23 @@ using System.Xml;
|
|||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class NoHousingRegion : BaseRegion
|
||||
{
|
||||
/* - False: this uses 'stupid OSI' house placement checking: part of the house may be placed here provided that the center is not in the region
|
||||
* - True: this uses 'smart RunUO' house placement checking: no part of the house may be in the region
|
||||
*/
|
||||
private bool m_SmartChecking;
|
||||
public 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 => m_SmartChecking;
|
||||
public NoHousingRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
ReadBoolean(xml["smartNoHousing"], "active", ref m_SmartChecking, false);
|
||||
}
|
||||
|
||||
public NoHousingRegion( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
|
||||
{
|
||||
ReadBoolean( xml["smartNoHousing"], "active", ref m_SmartChecking, false );
|
||||
}
|
||||
public bool SmartChecking => m_SmartChecking;
|
||||
|
||||
public override bool AllowHousing( Mobile from, Point3D p )
|
||||
{
|
||||
return m_SmartChecking;
|
||||
}
|
||||
}
|
||||
public override bool AllowHousing(Mobile from, Point3D p)
|
||||
{
|
||||
return m_SmartChecking;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,397 +1,407 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Server.Mobiles;
|
||||
using Server.Items;
|
||||
using System.Collections.Generic;
|
||||
using Server.Mobiles;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
if ( typeof( Item ).IsAssignableFrom( type ) )
|
||||
{
|
||||
return SpawnItem.Get( type );
|
||||
}
|
||||
Console.WriteLine( "Invalid type '{0}' in a SpawnDefinition", type.FullName );
|
||||
return null;
|
||||
}
|
||||
case "group":
|
||||
{
|
||||
string group = null;
|
||||
if ( !Region.ReadString( xml, "name", ref group ) )
|
||||
return null;
|
||||
|
||||
SpawnDefinition def = (SpawnDefinition) SpawnGroup.Table[group];
|
||||
|
||||
if ( def == null )
|
||||
{
|
||||
Console.WriteLine( "Could not find group '{0}' in a SpawnDefinition", group );
|
||||
return null;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
case "treasureChest":
|
||||
{
|
||||
int itemID = 0xE43;
|
||||
Region.ReadInt32( xml, "itemID", ref itemID, false );
|
||||
|
||||
BaseTreasureChest.TreasureLevel level = BaseTreasureChest.TreasureLevel.Level2;
|
||||
|
||||
Region.ReadEnum( xml, "level", ref level, false );
|
||||
|
||||
return new SpawnTreasureChest( itemID, level );
|
||||
}
|
||||
default:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SpawnType : SpawnDefinition
|
||||
{
|
||||
private bool m_Init;
|
||||
|
||||
public Type Type { get; }
|
||||
|
||||
public abstract int Height{ get; }
|
||||
public abstract bool Land{ get; }
|
||||
public abstract bool Water{ get; }
|
||||
|
||||
protected SpawnType( Type type )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
Region region = entry.Region;
|
||||
Map map = region.Map;
|
||||
|
||||
Point3D loc = entry.RandomSpawnLocation( Height, Land, Water );
|
||||
|
||||
if ( loc == Point3D.Zero )
|
||||
return null;
|
||||
|
||||
return Construct( entry, loc, map );
|
||||
}
|
||||
|
||||
protected abstract ISpawnable Construct( SpawnEntry entry, Point3D loc, Map map );
|
||||
|
||||
public override bool CanSpawn( params Type[] types )
|
||||
{
|
||||
for ( int i = 0; i < types.Length; i++ )
|
||||
{
|
||||
if ( types[i] == Type )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnMobile : SpawnType
|
||||
{
|
||||
private static 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 => 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.HomeMap = map;
|
||||
creature.RangeHome = entry.HomeRange;
|
||||
}
|
||||
|
||||
if ( entry.Direction != SpawnEntry.InvalidDirection )
|
||||
mobile.Direction = entry.Direction;
|
||||
|
||||
mobile.OnBeforeSpawn( loc, map );
|
||||
mobile.MoveToWorld( loc, map );
|
||||
mobile.OnAfterSpawn();
|
||||
|
||||
return mobile;
|
||||
}
|
||||
|
||||
protected virtual Mobile CreateMobile()
|
||||
{
|
||||
return (Mobile) Activator.CreateInstance( Type );
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnItem : SpawnType
|
||||
{
|
||||
private static 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 => true;
|
||||
public override bool Water => 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
|
||||
{
|
||||
public int ItemID { get; }
|
||||
|
||||
public BaseTreasureChest.TreasureLevel Level { get; }
|
||||
|
||||
public SpawnTreasureChest( int itemID, BaseTreasureChest.TreasureLevel level ) : base( typeof( BaseTreasureChest ) )
|
||||
{
|
||||
ItemID = itemID;
|
||||
Level = level;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
m_Height = TileData.ItemTable[ItemID & TileData.MaxItemValue].Height;
|
||||
}
|
||||
|
||||
protected override Item CreateItem()
|
||||
{
|
||||
return new BaseTreasureChest( ItemID, Level );
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnGroupElement
|
||||
{
|
||||
public SpawnDefinition SpawnDefinition { get; }
|
||||
|
||||
public int Weight { get; }
|
||||
|
||||
public SpawnGroupElement( SpawnDefinition spawnDefinition, int weight )
|
||||
{
|
||||
SpawnDefinition = spawnDefinition;
|
||||
Weight = weight;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnGroup : SpawnDefinition
|
||||
{
|
||||
public static Hashtable Table { get; } = new Hashtable();
|
||||
|
||||
public static void Register( SpawnGroup group )
|
||||
{
|
||||
if ( Table.Contains( group.Name ) )
|
||||
Console.WriteLine( "Warning: Double SpawnGroup name '{0}'", group.Name );
|
||||
else
|
||||
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 int m_TotalWeight;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public SpawnGroupElement[] Elements { get; }
|
||||
|
||||
public SpawnGroup( string name, SpawnGroupElement[] elements )
|
||||
{
|
||||
Name = name;
|
||||
Elements = elements;
|
||||
|
||||
m_TotalWeight = 0;
|
||||
for ( int i = 0; i < elements.Length; i++ )
|
||||
m_TotalWeight += elements[i].Weight;
|
||||
}
|
||||
|
||||
public override ISpawnable Spawn(SpawnEntry entry)
|
||||
{
|
||||
int index = Utility.Random( m_TotalWeight );
|
||||
|
||||
for ( int i = 0; i < Elements.Length; i++ )
|
||||
{
|
||||
SpawnGroupElement element = Elements[i];
|
||||
|
||||
if ( index < element.Weight )
|
||||
return element.SpawnDefinition.Spawn( entry );
|
||||
|
||||
index -= element.Weight;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool CanSpawn( params Type[] types )
|
||||
{
|
||||
for ( int i = 0; i < Elements.Length; i++ )
|
||||
{
|
||||
if ( Elements[i].SpawnDefinition.CanSpawn( types ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract class SpawnDefinition
|
||||
{
|
||||
public abstract ISpawnable Spawn(SpawnEntry entry);
|
||||
|
||||
public abstract bool CanSpawn(params Type[] types);
|
||||
|
||||
public static SpawnDefinition GetSpawnDefinition(XmlElement xml)
|
||||
{
|
||||
switch (xml.Name)
|
||||
{
|
||||
case "object":
|
||||
{
|
||||
Type type = null;
|
||||
if (!Region.ReadType(xml, "type", ref type))
|
||||
return null;
|
||||
|
||||
if (typeof(Mobile).IsAssignableFrom(type)) return SpawnMobile.Get(type);
|
||||
|
||||
if (typeof(Item).IsAssignableFrom(type)) return SpawnItem.Get(type);
|
||||
Console.WriteLine("Invalid type '{0}' in a SpawnDefinition", type.FullName);
|
||||
return null;
|
||||
}
|
||||
case "group":
|
||||
{
|
||||
string group = null;
|
||||
if (!Region.ReadString(xml, "name", ref group))
|
||||
return null;
|
||||
|
||||
SpawnDefinition def = (SpawnDefinition)SpawnGroup.Table[group];
|
||||
|
||||
if (def == null)
|
||||
{
|
||||
Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group);
|
||||
return null;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
case "treasureChest":
|
||||
{
|
||||
int itemID = 0xE43;
|
||||
Region.ReadInt32(xml, "itemID", ref itemID, false);
|
||||
|
||||
BaseTreasureChest.TreasureLevel level = BaseTreasureChest.TreasureLevel.Level2;
|
||||
|
||||
Region.ReadEnum(xml, "level", ref level, false);
|
||||
|
||||
return new SpawnTreasureChest(itemID, level);
|
||||
}
|
||||
default:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SpawnType : SpawnDefinition
|
||||
{
|
||||
private bool m_Init;
|
||||
|
||||
protected SpawnType(Type type)
|
||||
{
|
||||
Type = type;
|
||||
m_Init = false;
|
||||
}
|
||||
|
||||
public Type Type{ get; }
|
||||
|
||||
public abstract int Height{ get; }
|
||||
public abstract bool Land{ get; }
|
||||
public abstract bool Water{ get; }
|
||||
|
||||
protected void EnsureInit()
|
||||
{
|
||||
if (m_Init)
|
||||
return;
|
||||
|
||||
Init();
|
||||
m_Init = true;
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public override ISpawnable Spawn(SpawnEntry entry)
|
||||
{
|
||||
Region region = entry.Region;
|
||||
Map map = region.Map;
|
||||
|
||||
Point3D loc = entry.RandomSpawnLocation(Height, Land, Water);
|
||||
|
||||
if (loc == Point3D.Zero)
|
||||
return null;
|
||||
|
||||
return Construct(entry, loc, map);
|
||||
}
|
||||
|
||||
protected abstract ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map);
|
||||
|
||||
public override bool CanSpawn(params Type[] types)
|
||||
{
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
if (types[i] == Type)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnMobile : SpawnType
|
||||
{
|
||||
private static Hashtable m_Table = new Hashtable();
|
||||
|
||||
protected bool m_Land;
|
||||
protected bool m_Water;
|
||||
|
||||
protected SpawnMobile(Type type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Height => 16;
|
||||
|
||||
public override bool Land
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Land;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Water
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Water;
|
||||
}
|
||||
}
|
||||
|
||||
public static SpawnMobile Get(Type type)
|
||||
{
|
||||
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(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.HomeMap = map;
|
||||
creature.RangeHome = entry.HomeRange;
|
||||
}
|
||||
|
||||
if (entry.Direction != SpawnEntry.InvalidDirection)
|
||||
mobile.Direction = entry.Direction;
|
||||
|
||||
mobile.OnBeforeSpawn(loc, map);
|
||||
mobile.MoveToWorld(loc, map);
|
||||
mobile.OnAfterSpawn();
|
||||
|
||||
return mobile;
|
||||
}
|
||||
|
||||
protected virtual Mobile CreateMobile()
|
||||
{
|
||||
return (Mobile)Activator.CreateInstance(Type);
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnItem : SpawnType
|
||||
{
|
||||
private static Hashtable m_Table = new Hashtable();
|
||||
|
||||
protected int m_Height;
|
||||
|
||||
protected SpawnItem(Type type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureInit();
|
||||
return m_Height;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Land => true;
|
||||
public override bool Water => false;
|
||||
|
||||
public static SpawnItem Get(Type type)
|
||||
{
|
||||
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(Type);
|
||||
|
||||
m_Height = item.ItemData.Height;
|
||||
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
protected override ISpawnable Construct(SpawnEntry entry, Point3D loc, Map map)
|
||||
{
|
||||
Item item = CreateItem();
|
||||
|
||||
item.OnBeforeSpawn(loc, map);
|
||||
item.MoveToWorld(loc, map);
|
||||
item.OnAfterSpawn();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual Item CreateItem()
|
||||
{
|
||||
return (Item)Activator.CreateInstance(Type);
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnTreasureChest : SpawnItem
|
||||
{
|
||||
public SpawnTreasureChest(int itemID, BaseTreasureChest.TreasureLevel level) : base(typeof(BaseTreasureChest))
|
||||
{
|
||||
ItemID = itemID;
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public int ItemID{ get; }
|
||||
|
||||
public BaseTreasureChest.TreasureLevel Level{ get; }
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
m_Height = TileData.ItemTable[ItemID & TileData.MaxItemValue].Height;
|
||||
}
|
||||
|
||||
protected override Item CreateItem()
|
||||
{
|
||||
return new BaseTreasureChest(ItemID, Level);
|
||||
}
|
||||
}
|
||||
|
||||
public class SpawnGroupElement
|
||||
{
|
||||
public SpawnGroupElement(SpawnDefinition spawnDefinition, int weight)
|
||||
{
|
||||
SpawnDefinition = spawnDefinition;
|
||||
Weight = weight;
|
||||
}
|
||||
|
||||
public SpawnDefinition SpawnDefinition{ get; }
|
||||
|
||||
public int Weight{ get; }
|
||||
}
|
||||
|
||||
public class SpawnGroup : SpawnDefinition
|
||||
{
|
||||
private int m_TotalWeight;
|
||||
|
||||
static SpawnGroup()
|
||||
{
|
||||
string path = Path.Combine(Core.BaseDirectory, "Data/SpawnDefinitions.xml");
|
||||
if (!File.Exists(path))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(path);
|
||||
|
||||
XmlElement root = doc["spawnDefinitions"];
|
||||
if (root == null)
|
||||
return;
|
||||
|
||||
foreach (XmlElement xmlDef in root.SelectNodes("spawnGroup"))
|
||||
{
|
||||
string name = null;
|
||||
if (!Region.ReadString(xmlDef, "name", ref name))
|
||||
continue;
|
||||
|
||||
List<SpawnGroupElement> list = new List<SpawnGroupElement>();
|
||||
foreach (XmlNode node in xmlDef.ChildNodes)
|
||||
{
|
||||
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 SpawnGroup(string name, SpawnGroupElement[] elements)
|
||||
{
|
||||
Name = name;
|
||||
Elements = elements;
|
||||
|
||||
m_TotalWeight = 0;
|
||||
for (int i = 0; i < elements.Length; i++)
|
||||
m_TotalWeight += elements[i].Weight;
|
||||
}
|
||||
|
||||
public static Hashtable Table{ get; } = new Hashtable();
|
||||
|
||||
public string Name{ get; }
|
||||
|
||||
public SpawnGroupElement[] Elements{ get; }
|
||||
|
||||
public static void Register(SpawnGroup group)
|
||||
{
|
||||
if (Table.Contains(group.Name))
|
||||
Console.WriteLine("Warning: Double SpawnGroup name '{0}'", group.Name);
|
||||
else
|
||||
Table[group.Name] = group;
|
||||
}
|
||||
|
||||
public override ISpawnable Spawn(SpawnEntry entry)
|
||||
{
|
||||
int index = Utility.Random(m_TotalWeight);
|
||||
|
||||
for (int i = 0; i < Elements.Length; i++)
|
||||
{
|
||||
SpawnGroupElement element = Elements[i];
|
||||
|
||||
if (index < element.Weight)
|
||||
return element.SpawnDefinition.Spawn(entry);
|
||||
|
||||
index -= element.Weight;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool CanSpawn(params Type[] types)
|
||||
{
|
||||
for (int i = 0; i < Elements.Length; i++)
|
||||
if (Elements[i].SpawnDefinition.CanSpawn(types))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,458 +1,445 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Mobiles;
|
||||
using Server.Commands;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class SpawnEntry : ISpawner
|
||||
{
|
||||
public static readonly TimeSpan DefaultMinSpawnTime = TimeSpan.FromMinutes( 2.0 );
|
||||
public static readonly TimeSpan DefaultMaxSpawnTime = TimeSpan.FromMinutes( 5.0 );
|
||||
public class SpawnEntry : ISpawner
|
||||
{
|
||||
public static readonly TimeSpan DefaultMinSpawnTime = TimeSpan.FromMinutes(2.0);
|
||||
public static readonly TimeSpan DefaultMaxSpawnTime = TimeSpan.FromMinutes(5.0);
|
||||
|
||||
public static Hashtable Table { get; } = new Hashtable();
|
||||
|
||||
public static readonly Direction InvalidDirection = Direction.Running;
|
||||
|
||||
// When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home?
|
||||
public bool ReturnOnDeactivate => true;
|
||||
private static List<IEntity> m_RemoveList;
|
||||
|
||||
// Are creatures unlinked on taming (true) or should they also go out of the region (false)?
|
||||
public bool UnlinkOnTaming => false;
|
||||
private DateTime m_NextSpawn;
|
||||
private Timer m_SpawnTimer;
|
||||
|
||||
// Are unlinked and untamed creatures removed after 20 hours?
|
||||
public bool RemoveIfUntamed => true;
|
||||
public SpawnEntry(int id, BaseRegion region, Point3D home, int range, Direction direction,
|
||||
SpawnDefinition definition, int max, TimeSpan minSpawnTime, TimeSpan maxSpawnTime)
|
||||
{
|
||||
ID = id;
|
||||
Region = region;
|
||||
HomeLocation = home;
|
||||
HomeRange = range;
|
||||
Direction = direction;
|
||||
Definition = definition;
|
||||
SpawnedObjects = new List<ISpawnable>();
|
||||
Max = max;
|
||||
MinSpawnTime = minSpawnTime;
|
||||
MaxSpawnTime = maxSpawnTime;
|
||||
Running = false;
|
||||
|
||||
if (Table.Contains(id))
|
||||
Console.WriteLine("Warning: double SpawnEntry ID '{0}'", id);
|
||||
else
|
||||
Table[id] = this;
|
||||
}
|
||||
|
||||
public static readonly Direction InvalidDirection = Direction.Running;
|
||||
public static Hashtable Table{ get; } = new Hashtable();
|
||||
|
||||
private DateTime m_NextSpawn;
|
||||
private Timer m_SpawnTimer;
|
||||
|
||||
public int ID { get; }
|
||||
// When a creature's AI is deactivated (PlayerRangeSensitive optimization) does it return home?
|
||||
public bool ReturnOnDeactivate => true;
|
||||
|
||||
public BaseRegion Region { get; }
|
||||
// Are unlinked and untamed creatures removed after 20 hours?
|
||||
public bool RemoveIfUntamed => true;
|
||||
|
||||
Region ISpawner.Region => Region;
|
||||
public Point3D HomeLocation { get; }
|
||||
public int ID{ get; }
|
||||
|
||||
public int HomeRange { get; }
|
||||
public BaseRegion Region{ get; }
|
||||
|
||||
public Direction Direction { get; }
|
||||
public Direction Direction{ get; }
|
||||
|
||||
public SpawnDefinition Definition { get; }
|
||||
public SpawnDefinition Definition{ get; }
|
||||
|
||||
public List<ISpawnable> SpawnedObjects { get; }
|
||||
public List<ISpawnable> SpawnedObjects{ get; }
|
||||
|
||||
public int Max { get; private set; }
|
||||
public int Max{ get; private set; }
|
||||
|
||||
public TimeSpan MinSpawnTime { get; }
|
||||
public TimeSpan MinSpawnTime{ get; }
|
||||
|
||||
public TimeSpan MaxSpawnTime { get; }
|
||||
public TimeSpan MaxSpawnTime{ get; }
|
||||
|
||||
public bool Running { get; private set; }
|
||||
public bool Running{ get; private set; }
|
||||
|
||||
public bool Complete => SpawnedObjects.Count >= Max;
|
||||
public bool Spawning => Running && !Complete;
|
||||
public bool Complete => SpawnedObjects.Count >= Max;
|
||||
public bool Spawning => Running && !Complete;
|
||||
|
||||
public SpawnEntry( int id, BaseRegion region, Point3D home, int range, Direction direction, SpawnDefinition definition, int max, TimeSpan minSpawnTime, TimeSpan maxSpawnTime )
|
||||
{
|
||||
ID = id;
|
||||
Region = region;
|
||||
HomeLocation = home;
|
||||
HomeRange = range;
|
||||
Direction = direction;
|
||||
Definition = definition;
|
||||
SpawnedObjects = new List<ISpawnable>();
|
||||
Max = max;
|
||||
MinSpawnTime = minSpawnTime;
|
||||
MaxSpawnTime = maxSpawnTime;
|
||||
Running = false;
|
||||
// Are creatures unlinked on taming (true) or should they also go out of the region (false)?
|
||||
public bool UnlinkOnTaming => false;
|
||||
|
||||
if ( Table.Contains( id ) )
|
||||
Console.WriteLine( "Warning: double SpawnEntry ID '{0}'", id );
|
||||
else
|
||||
Table[id] = this;
|
||||
}
|
||||
Region ISpawner.Region => Region;
|
||||
public Point3D HomeLocation{ get; }
|
||||
|
||||
public Point3D RandomSpawnLocation( int spawnHeight, bool land, bool water )
|
||||
{
|
||||
return Region.RandomSpawnLocation( spawnHeight, land, water, HomeLocation, HomeRange );
|
||||
}
|
||||
public int HomeRange{ get; }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if ( Running )
|
||||
return;
|
||||
void ISpawner.Remove(ISpawnable spawn)
|
||||
{
|
||||
SpawnedObjects.Remove(spawn);
|
||||
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if ( !Running )
|
||||
return;
|
||||
public Point3D RandomSpawnLocation(int spawnHeight, bool land, bool water)
|
||||
{
|
||||
return Region.RandomSpawnLocation(spawnHeight, land, water, HomeLocation, HomeRange);
|
||||
}
|
||||
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
if (Running)
|
||||
return;
|
||||
|
||||
private void Spawn()
|
||||
{
|
||||
ISpawnable spawn = Definition.Spawn(this);
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
if ( spawn != null )
|
||||
Add( spawn );
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
if (!Running)
|
||||
return;
|
||||
|
||||
private void Add( ISpawnable spawn )
|
||||
{
|
||||
SpawnedObjects.Add( spawn );
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
spawn.Spawner = this;
|
||||
private void Spawn()
|
||||
{
|
||||
ISpawnable spawn = Definition.Spawn(this);
|
||||
|
||||
if ( spawn is BaseCreature )
|
||||
((BaseCreature)spawn).RemoveIfUntamed = RemoveIfUntamed;
|
||||
}
|
||||
if (spawn != null)
|
||||
Add(spawn);
|
||||
}
|
||||
|
||||
void ISpawner.Remove( ISpawnable spawn )
|
||||
{
|
||||
SpawnedObjects.Remove( spawn );
|
||||
private void Add(ISpawnable spawn)
|
||||
{
|
||||
SpawnedObjects.Add(spawn);
|
||||
|
||||
CheckTimer();
|
||||
}
|
||||
spawn.Spawner = this;
|
||||
|
||||
private TimeSpan RandomTime()
|
||||
{
|
||||
int min = (int) MinSpawnTime.TotalSeconds;
|
||||
int max = (int) MaxSpawnTime.TotalSeconds;
|
||||
if (spawn is BaseCreature)
|
||||
((BaseCreature)spawn).RemoveIfUntamed = RemoveIfUntamed;
|
||||
}
|
||||
|
||||
int rand = Utility.RandomMinMax( min, max );
|
||||
return TimeSpan.FromSeconds( rand );
|
||||
}
|
||||
|
||||
private void CheckTimer()
|
||||
{
|
||||
if ( Spawning )
|
||||
{
|
||||
if ( m_SpawnTimer == null )
|
||||
{
|
||||
TimeSpan time = RandomTime();
|
||||
m_SpawnTimer = Timer.DelayCall( time, TimerCallback );
|
||||
m_NextSpawn = DateTime.UtcNow + time;
|
||||
}
|
||||
}
|
||||
else if ( m_SpawnTimer != null )
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void TimerCallback()
|
||||
{
|
||||
int amount = Math.Max( (Max - SpawnedObjects.Count) / 3, 1 );
|
||||
|
||||
for ( int i = 0; i < amount; i++ )
|
||||
Spawn();
|
||||
|
||||
m_SpawnTimer = null;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void DeleteSpawnedObjects()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
private void InternalDeleteSpawnedObjects()
|
||||
{
|
||||
foreach ( ISpawnable spawnable in SpawnedObjects )
|
||||
{
|
||||
spawnable.Spawner = null;
|
||||
|
||||
bool uncontrolled = !(spawnable is BaseCreature) || !((BaseCreature)spawnable).Controlled;
|
||||
|
||||
if ( uncontrolled )
|
||||
spawnable.Delete();
|
||||
}
|
||||
|
||||
SpawnedObjects.Clear();
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
for ( int i = 0; !Complete && i < Max; i++ )
|
||||
Spawn();
|
||||
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Max = 0;
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
if ( m_SpawnTimer != null )
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
|
||||
if ( Table[ID] == this )
|
||||
Table.Remove( ID );
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.Write( (int) SpawnedObjects.Count );
|
||||
|
||||
for ( int i = 0; i < SpawnedObjects.Count; i++ )
|
||||
{
|
||||
ISpawnable spawn = SpawnedObjects[i];
|
||||
|
||||
int serial = spawn.Serial;
|
||||
|
||||
writer.Write( (int) serial );
|
||||
}
|
||||
|
||||
writer.Write( (bool) 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);
|
||||
}
|
||||
|
||||
Running = reader.ReadBool();
|
||||
|
||||
if ( reader.ReadBool() )
|
||||
{
|
||||
m_NextSpawn = reader.ReadDeltaTime();
|
||||
|
||||
if ( Spawning )
|
||||
{
|
||||
m_SpawnTimer?.Stop();
|
||||
|
||||
TimeSpan delay = m_NextSpawn - DateTime.UtcNow;
|
||||
m_SpawnTimer = Timer.DelayCall( delay > TimeSpan.Zero ? delay : TimeSpan.Zero, TimerCallback );
|
||||
}
|
||||
}
|
||||
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
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, RespawnAllRegions_OnCommand );
|
||||
CommandSystem.Register( "RespawnRegion", AccessLevel.GameMaster, RespawnRegion_OnCommand );
|
||||
CommandSystem.Register( "DelAllRegionSpawns", AccessLevel.Administrator, DelAllRegionSpawns_OnCommand );
|
||||
CommandSystem.Register( "DelRegionSpawns", AccessLevel.GameMaster, DelRegionSpawns_OnCommand );
|
||||
CommandSystem.Register( "StartAllRegionSpawns", AccessLevel.Administrator, StartAllRegionSpawns_OnCommand );
|
||||
CommandSystem.Register( "StartRegionSpawns", AccessLevel.GameMaster, StartRegionSpawns_OnCommand );
|
||||
CommandSystem.Register( "StopAllRegionSpawns", AccessLevel.Administrator, StopAllRegionSpawns_OnCommand );
|
||||
CommandSystem.Register( "StopRegionSpawns", AccessLevel.GameMaster, StopRegionSpawns_OnCommand );
|
||||
}
|
||||
|
||||
private static BaseRegion GetCommandData( CommandEventArgs args )
|
||||
{
|
||||
Mobile from = args.Mobile;
|
||||
|
||||
Region reg;
|
||||
if ( args.Length == 0 )
|
||||
{
|
||||
reg = from.Region;
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = args.GetString( 0 );
|
||||
//reg = if (!from.Map.Regions.TryGetValue( name, out (Region) from.Map.Regions[name] ))
|
||||
{
|
||||
from.SendMessage( "Could not find region '{0}'.", name );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
BaseRegion br = reg as BaseRegion;
|
||||
|
||||
if ( 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 Table.Values )
|
||||
{
|
||||
entry.Respawn();
|
||||
}
|
||||
|
||||
args.Mobile.SendMessage( "All regions have respawned." );
|
||||
}
|
||||
|
||||
[Usage( "RespawnRegion [<region name>]" )]
|
||||
[Description( "Respawns the region in which you are (or that you provided) and sets the spawners as running." )]
|
||||
private static void RespawnRegion_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
BaseRegion region = GetCommandData( args );
|
||||
|
||||
if ( region == null )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < region.Spawns.Length; i++ )
|
||||
region.Spawns[i].Respawn();
|
||||
|
||||
args.Mobile.SendMessage( "Region '{0}' has respawned.", region );
|
||||
}
|
||||
|
||||
[Usage( "DelAllRegionSpawns" )]
|
||||
[Description( "Deletes all spawned objects of every regions and sets the spawners as not running." )]
|
||||
private static void DelAllRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
foreach ( SpawnEntry entry in Table.Values )
|
||||
{
|
||||
entry.DeleteSpawnedObjects();
|
||||
}
|
||||
|
||||
args.Mobile.SendMessage( "All region spawned objects have been deleted." );
|
||||
}
|
||||
|
||||
[Usage( "DelRegionSpawns [<region name>]" )]
|
||||
[Description( "Deletes all spawned objects of the region in which you are (or that you provided) and sets the spawners as not running." )]
|
||||
private static void DelRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
BaseRegion region = GetCommandData( args );
|
||||
|
||||
if ( region == null )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < region.Spawns.Length; i++ )
|
||||
region.Spawns[i].DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage( "Spawned objects of region '{0}' have been deleted.", region );
|
||||
}
|
||||
|
||||
[Usage( "StartAllRegionSpawns" )]
|
||||
[Description( "Sets the region spawners of all regions as running." )]
|
||||
private static void StartAllRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
foreach ( SpawnEntry entry in Table.Values )
|
||||
{
|
||||
entry.Start();
|
||||
}
|
||||
|
||||
args.Mobile.SendMessage( "All region spawners have started." );
|
||||
}
|
||||
|
||||
[Usage( "StartRegionSpawns [<region name>]" )]
|
||||
[Description( "Sets the region spawners of the region in which you are (or that you provided) as running." )]
|
||||
private static void StartRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
BaseRegion region = GetCommandData( args );
|
||||
|
||||
if ( region == null )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < region.Spawns.Length; i++ )
|
||||
region.Spawns[i].Start();
|
||||
|
||||
args.Mobile.SendMessage( "Spawners of region '{0}' have started.", region );
|
||||
}
|
||||
|
||||
[Usage( "StopAllRegionSpawns" )]
|
||||
[Description( "Sets the region spawners of all regions as not running." )]
|
||||
private static void StopAllRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
foreach ( SpawnEntry entry in Table.Values )
|
||||
{
|
||||
entry.Stop();
|
||||
}
|
||||
|
||||
args.Mobile.SendMessage( "All region spawners have stopped." );
|
||||
}
|
||||
|
||||
[Usage( "StopRegionSpawns [<region name>]" )]
|
||||
[Description( "Sets the region spawners of the region in which you are (or that you provided) as not running." )]
|
||||
private static void StopRegionSpawns_OnCommand( CommandEventArgs args )
|
||||
{
|
||||
BaseRegion region = GetCommandData( args );
|
||||
|
||||
if ( region == null )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < region.Spawns.Length; i++ )
|
||||
region.Spawns[i].Stop();
|
||||
|
||||
args.Mobile.SendMessage( "Spawners of region '{0}' have stopped.", region );
|
||||
}
|
||||
}
|
||||
}
|
||||
private TimeSpan RandomTime()
|
||||
{
|
||||
int min = (int)MinSpawnTime.TotalSeconds;
|
||||
int max = (int)MaxSpawnTime.TotalSeconds;
|
||||
|
||||
int rand = Utility.RandomMinMax(min, max);
|
||||
return TimeSpan.FromSeconds(rand);
|
||||
}
|
||||
|
||||
private void CheckTimer()
|
||||
{
|
||||
if (Spawning)
|
||||
{
|
||||
if (m_SpawnTimer == null)
|
||||
{
|
||||
TimeSpan time = RandomTime();
|
||||
m_SpawnTimer = Timer.DelayCall(time, TimerCallback);
|
||||
m_NextSpawn = DateTime.UtcNow + time;
|
||||
}
|
||||
}
|
||||
else if (m_SpawnTimer != null)
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void TimerCallback()
|
||||
{
|
||||
int amount = Math.Max((Max - SpawnedObjects.Count) / 3, 1);
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
Spawn();
|
||||
|
||||
m_SpawnTimer = null;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void DeleteSpawnedObjects()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
Running = false;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
private void InternalDeleteSpawnedObjects()
|
||||
{
|
||||
foreach (ISpawnable spawnable in SpawnedObjects)
|
||||
{
|
||||
spawnable.Spawner = null;
|
||||
|
||||
bool uncontrolled = !(spawnable is BaseCreature) || !((BaseCreature)spawnable).Controlled;
|
||||
|
||||
if (uncontrolled)
|
||||
spawnable.Delete();
|
||||
}
|
||||
|
||||
SpawnedObjects.Clear();
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
for (int i = 0; !Complete && i < Max; i++)
|
||||
Spawn();
|
||||
|
||||
Running = true;
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Max = 0;
|
||||
InternalDeleteSpawnedObjects();
|
||||
|
||||
if (m_SpawnTimer != null)
|
||||
{
|
||||
m_SpawnTimer.Stop();
|
||||
m_SpawnTimer = null;
|
||||
}
|
||||
|
||||
if (Table[ID] == this)
|
||||
Table.Remove(ID);
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.Write(SpawnedObjects.Count);
|
||||
|
||||
for (int i = 0; i < SpawnedObjects.Count; i++)
|
||||
{
|
||||
ISpawnable spawn = SpawnedObjects[i];
|
||||
|
||||
int serial = spawn.Serial;
|
||||
|
||||
writer.Write(serial);
|
||||
}
|
||||
|
||||
writer.Write(Running);
|
||||
|
||||
if (m_SpawnTimer != null)
|
||||
{
|
||||
writer.Write(true);
|
||||
writer.WriteDeltaTime(m_NextSpawn);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Deserialize(GenericReader reader, int version)
|
||||
{
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int serial = reader.ReadInt();
|
||||
ISpawnable spawnableEntity = World.FindEntity(serial) as ISpawnable;
|
||||
|
||||
if (spawnableEntity != null)
|
||||
Add(spawnableEntity);
|
||||
}
|
||||
|
||||
Running = reader.ReadBool();
|
||||
|
||||
if (reader.ReadBool())
|
||||
{
|
||||
m_NextSpawn = reader.ReadDeltaTime();
|
||||
|
||||
if (Spawning)
|
||||
{
|
||||
m_SpawnTimer?.Stop();
|
||||
|
||||
TimeSpan delay = m_NextSpawn - DateTime.UtcNow;
|
||||
m_SpawnTimer = Timer.DelayCall(delay > TimeSpan.Zero ? delay : TimeSpan.Zero, TimerCallback);
|
||||
}
|
||||
}
|
||||
|
||||
CheckTimer();
|
||||
}
|
||||
|
||||
public static void Remove(GenericReader reader, int version)
|
||||
{
|
||||
int count = reader.ReadInt();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
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, RespawnAllRegions_OnCommand);
|
||||
CommandSystem.Register("RespawnRegion", AccessLevel.GameMaster, RespawnRegion_OnCommand);
|
||||
CommandSystem.Register("DelAllRegionSpawns", AccessLevel.Administrator, DelAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("DelRegionSpawns", AccessLevel.GameMaster, DelRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StartAllRegionSpawns", AccessLevel.Administrator, StartAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StartRegionSpawns", AccessLevel.GameMaster, StartRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StopAllRegionSpawns", AccessLevel.Administrator, StopAllRegionSpawns_OnCommand);
|
||||
CommandSystem.Register("StopRegionSpawns", AccessLevel.GameMaster, StopRegionSpawns_OnCommand);
|
||||
}
|
||||
|
||||
private static BaseRegion GetCommandData(CommandEventArgs args)
|
||||
{
|
||||
Mobile from = args.Mobile;
|
||||
|
||||
Region reg;
|
||||
if (args.Length == 0)
|
||||
{
|
||||
reg = from.Region;
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = args.GetString(0);
|
||||
//reg = if (!from.Map.Regions.TryGetValue( name, out (Region) from.Map.Regions[name] ))
|
||||
{
|
||||
from.SendMessage("Could not find region '{0}'.", name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
BaseRegion br = reg as BaseRegion;
|
||||
|
||||
if (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 Table.Values) entry.Respawn();
|
||||
|
||||
args.Mobile.SendMessage("All regions have respawned.");
|
||||
}
|
||||
|
||||
[Usage("RespawnRegion [<region name>]")]
|
||||
[Description("Respawns the region in which you are (or that you provided) and sets the spawners as running.")]
|
||||
private static void RespawnRegion_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Respawn();
|
||||
|
||||
args.Mobile.SendMessage("Region '{0}' has respawned.", region);
|
||||
}
|
||||
|
||||
[Usage("DelAllRegionSpawns")]
|
||||
[Description("Deletes all spawned objects of every regions and sets the spawners as not running.")]
|
||||
private static void DelAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage("All region spawned objects have been deleted.");
|
||||
}
|
||||
|
||||
[Usage("DelRegionSpawns [<region name>]")]
|
||||
[Description(
|
||||
"Deletes all spawned objects of the region in which you are (or that you provided) and sets the spawners as not running.")]
|
||||
private static void DelRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage("Spawned objects of region '{0}' have been deleted.", region);
|
||||
}
|
||||
|
||||
[Usage("StartAllRegionSpawns")]
|
||||
[Description("Sets the region spawners of all regions as running.")]
|
||||
private static void StartAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.Start();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have started.");
|
||||
}
|
||||
|
||||
[Usage("StartRegionSpawns [<region name>]")]
|
||||
[Description("Sets the region spawners of the region in which you are (or that you provided) as running.")]
|
||||
private static void StartRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Start();
|
||||
|
||||
args.Mobile.SendMessage("Spawners of region '{0}' have started.", region);
|
||||
}
|
||||
|
||||
[Usage("StopAllRegionSpawns")]
|
||||
[Description("Sets the region spawners of all regions as not running.")]
|
||||
private static void StopAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.Stop();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have stopped.");
|
||||
}
|
||||
|
||||
[Usage("StopRegionSpawns [<region name>]")]
|
||||
[Description("Sets the region spawners of the region in which you are (or that you provided) as not running.")]
|
||||
private static void StopRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
BaseRegion region = GetCommandData(args);
|
||||
|
||||
if (region == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < region.Spawns.Length; i++)
|
||||
region.Spawns[i].Stop();
|
||||
|
||||
args.Mobile.SendMessage("Spawners of region '{0}' have stopped.", region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +1,63 @@
|
|||
namespace Server.Regions
|
||||
{
|
||||
[TypeAlias( "Server.Regions.SpawnPersistance" )]
|
||||
public class SpawnPersistence : Item
|
||||
{
|
||||
private static SpawnPersistence m_Instance;
|
||||
[TypeAlias("Server.Regions.SpawnPersistance")]
|
||||
public class SpawnPersistence : Item
|
||||
{
|
||||
private static SpawnPersistence m_Instance;
|
||||
|
||||
public SpawnPersistence Instance => m_Instance;
|
||||
private SpawnPersistence() : base(1)
|
||||
{
|
||||
Movable = false;
|
||||
}
|
||||
|
||||
public static void EnsureExistence()
|
||||
{
|
||||
if ( m_Instance == null )
|
||||
m_Instance = new SpawnPersistence();
|
||||
}
|
||||
public SpawnPersistence(Serial serial) : base(serial)
|
||||
{
|
||||
m_Instance = this;
|
||||
}
|
||||
|
||||
public override string DefaultName => "Region spawn persistence - Internal";
|
||||
public SpawnPersistence Instance => m_Instance;
|
||||
|
||||
private SpawnPersistence() : base( 1 )
|
||||
{
|
||||
Movable = false;
|
||||
}
|
||||
public override string DefaultName => "Region spawn persistence - Internal";
|
||||
|
||||
public SpawnPersistence( Serial serial ) : base( serial )
|
||||
{
|
||||
m_Instance = this;
|
||||
}
|
||||
public static void EnsureExistence()
|
||||
{
|
||||
if (m_Instance == null)
|
||||
m_Instance = new SpawnPersistence();
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt( 0 ); // version
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
writer.Write( (int) SpawnEntry.Table.Values.Count );
|
||||
foreach ( SpawnEntry entry in SpawnEntry.Table.Values )
|
||||
{
|
||||
writer.Write( (int) entry.ID );
|
||||
writer.Write(SpawnEntry.Table.Values.Count);
|
||||
foreach (SpawnEntry entry in SpawnEntry.Table.Values)
|
||||
{
|
||||
writer.Write(entry.ID);
|
||||
|
||||
entry.Serialize( writer );
|
||||
}
|
||||
}
|
||||
entry.Serialize(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadEncodedInt();
|
||||
int version = reader.ReadEncodedInt();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
int id = reader.ReadInt();
|
||||
int count = reader.ReadInt();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int id = reader.ReadInt();
|
||||
|
||||
SpawnEntry entry = (SpawnEntry) SpawnEntry.Table[id];
|
||||
SpawnEntry entry = (SpawnEntry)SpawnEntry.Table[id];
|
||||
|
||||
if ( entry != null )
|
||||
entry.Deserialize( reader, version );
|
||||
else
|
||||
SpawnEntry.Remove( reader, version );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entry != null)
|
||||
entry.Deserialize(reader, version);
|
||||
else
|
||||
SpawnEntry.Remove(reader, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,10 @@ using System.Xml;
|
|||
|
||||
namespace Server.Regions
|
||||
{
|
||||
public class TownRegion : GuardedRegion
|
||||
{
|
||||
public TownRegion( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
|
||||
{
|
||||
}
|
||||
}
|
||||
public class TownRegion : GuardedRegion
|
||||
{
|
||||
public TownRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue