using System; using System.IO; using System.Reflection; using System.Collections; using System.Collections.Generic; using Server; using Server.Commands; using Server.Network; using Server.Items; using Server.Mobiles; using Server.Regions; using Server.Spells; namespace Server.Regions { public class DuelRegion : GuardedRegion { private static Hashtable m_OldLocations = new Hashtable(); private DuelingPit m_Pit; public DuelingPit Pit{ get{ return m_Pit; } } public DuelRegion( DuelingPit m, params Rectangle3D[] area ) : base( "DuelingPit", Pit.Map, DefaultPriority, area ) { //Priority = Region.HighestPriority; //LoadFromXml = false; m_Pit = pit; } public override void OnEnter( Mobile m ) { if ( m.Spell != null ) ((Spell)m.Spell).Disturb( DisturbType.Unspecified ); Targeting.Target.Cancel( m ); } public override void OnExit( Mobile m ) { if ( m_Pit.IsContender( m ) && !Contains( m.Location ) && !m_Pit.Disposing ) { Point3D loc = OldLocation( m ); if ( loc != m.Location ) { m.MoveToWorld( loc, Map ); m.SendMessage( "You cannot leave the pit until the duel has ended." ); } else { m_Pit.Dispose(); } } else { if ( m_OldLocations.Contains( m ) ) m_OldLocations.Remove( m ); } } #region Restricted skills, spells, and items public override bool OnSkillUse( Mobile m, int Skill ) { bool value = base.OnSkillUse( m, Skill ); if ( Skill == (int)SkillName.Stealing ) value = false; if( Skill == (int)SkillName.Hiding ) value = false; if ( !value ) m.SendMessage( "You cannot use that skill at this time." ); return value; } public override bool OnBeginSpellCast( Mobile m, ISpell s ) { if ( m_Pit.InProgress && DuelHelper.ValidSpell( s ) ) return base.OnBeginSpellCast( m, s ); m.SendMessage( "You cannot use that spell at this time." ); return false; } public override bool OnDoubleClick( Mobile m, object o ) { if ( !DuelHelper.ValidType( o ) ) return base.OnDoubleClick( m, o ); m.SendMessage( "You cannot use that item at this time." ); return false; } #endregion private Point3D OldLocation( Mobile m ) { object o = m_OldLocations[m]; if ( o == null ) return m.Location; return (Point3D)o; } private bool InRange( Point3D loc ) { int x1 = m_Pit.X, y1 = m_Pit.Y, x2 = loc.X, y2 = loc.Y; double dist = Math.Sqrt( Math.Pow( x1 - x2, 2.0) + Math.Pow( y1 - y2, 2.0) ); if ( dist < 20 ) return true; return false; } public override void OnLocationChanged( Mobile m, Point3D oldLocation ) { if ( m_Pit.IsContender( m ) ) { m_OldLocations[m] = m.Location; return; } if ( Contains( oldLocation ) ) m.Location = GoLocation; else if ( !InRange( oldLocation ) ) m.Location = GoLocation; else m.Location = oldLocation; if ( m is BaseCreature && ((BaseCreature)m).Controlled ) ((BaseCreature)m).ControlOrder = OrderType.Stay; m.SendLocalizedMessage( 501284 ); // You may not enter. } public override bool OnMoveInto( Mobile from, Direction d, Point3D newLocation, Point3D oldLocation ) { if ( m_Pit.IsContender( from ) ) return true; if ( Contains( oldLocation ) ) from.Location = GoLocation; else if ( !InRange( oldLocation ) ) from.Location = GoLocation; else from.Location = oldLocation; if ( from is BaseCreature && ((BaseCreature)from).Controlled ) ((BaseCreature)from).ControlOrder = OrderType.Stay; from.SendLocalizedMessage( 501284 ); // You may not enter. return false; } public override void OnSpellCast( Mobile m, ISpell s ) { if ( m_Pit.InProgress ) base.OnSpellCast( m, s ); else ((Spell)s).Disturb( DisturbType.Unspecified ); } public override bool OnTarget( Mobile m, Targeting.Target t, object o ) { if ( m_Pit.IsContender( m ) && m_Pit.InProgress ) return base.OnTarget( m, t, o ); return false; } public override void AlterLightLevel( Mobile m, ref int global, ref int personal ) { global = 0; } public override bool AllowHousing( Mobile from, Point3D p ) { return false; } public override bool AllowSpawn() { return false; } public override bool CanUseStuckMenu( Mobile m ) { return false; } } }