Exemple #1
0
 public IEnumerable<MudObject> EnumerateObjects(RelativeLocations Locations)
 {
     foreach (var list in Lists)
         if ((list.Key & Locations) == list.Key)
             foreach (var item in list.Value)
                 yield return item;
 }
Exemple #2
0
 public IEnumerable<T> EnumerateObjects<T>(RelativeLocations Locations) where T : MudObject
 {
     foreach (var list in Lists)
         if ((list.Key & Locations) == list.Key)
             foreach (var item in list.Value)
                 if (item is T) yield return item as T;
 }
Exemple #3
0
        public void Container(RelativeLocations Locations, RelativeLocations Default)
        {
            ContentLocationsAllowed = Locations;
            DefaultContentLocation  = Default;
            Contents = new Dictionary <RelativeLocations, List <MudObject> >();

            SetProperty("container?", true);
        }
Exemple #4
0
        public bool Contains(MudObject Object, RelativeLocations Locations)
        {
            if (Locations == RelativeLocations.Default) Locations = Default;

            if (Lists.ContainsKey(Locations))
                return Lists[Locations].Contains(Object);
            return false;
        }
Exemple #5
0
        private static String RelativeLocationToString(RelativeLocations Relloc)
        {
            var parts = Relloc.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length > 2)
            {
                throw new InvalidOperationException();
            }
            return(parts[1].Trim());
        }
Exemple #6
0
        public void Add(MudObject Object, RelativeLocations Locations)
        {
            if (Locations == RelativeLocations.Default) Locations = Default;

            if ((Supported & Locations) == Locations)
            {
                if (!Lists.ContainsKey(Locations)) Lists.Add(Locations, new List<MudObject>());
                Lists[Locations].Add(Object);
            }
        }
Exemple #7
0
 public static String GetRelativeLocationName(RelativeLocations Location)
 {
     if ((Location & RelativeLocations.On) == RelativeLocations.On)
         return "on";
     else if ((Location & RelativeLocations.In) == RelativeLocations.In)
         return "in";
     else if ((Location & RelativeLocations.Under) == RelativeLocations.Under)
         return "under";
     else if ((Location & RelativeLocations.Behind) == RelativeLocations.Behind)
         return "behind";
     else
         return "relloc";
 }
Exemple #8
0
        private static RelativeLocations StringToRelativeLocation(String Str)
        {
            RelativeLocations r = RelativeLocations.None;

            if (Enum.TryParse(Str, out r))
            {
                return(r);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Exemple #9
0
        /// <summary>
        /// Move Object to Destination.
        /// </summary>
        /// <param name="Object">Object to move.</param>
        /// <param name="Destination">Destination to move too.</param>
        /// <param name="Location">The relative location within destination to move too.</param>
        public static void Move(MudObject Object, MudObject Destination, RelativeLocations Location = RelativeLocations.Default)
        {
            if (Object == null) return;

            if (Object.Location != null && Object.Location is Container) (Object.Location as Container).Remove(Object);

            if (Destination is Container)
            {
                (Destination as Container).Add(Object, Location);
                Object.Location = Destination;
            }
            else
                Object.Location = null;
        }
Exemple #10
0
        public bool Contains(MudObject Object, RelativeLocations Locations)
        {
            if (Locations == RelativeLocations.DEFAULT)
            {
                Locations = DefaultContentLocation;
            }

            if (Contents != null)
            {
                if (Contents.ContainsKey(Locations))
                {
                    return(Contents[Locations].Contains(Object));
                }
            }
            return(false);
        }
Exemple #11
0
 public IEnumerable <MudObject> EnumerateObjects(RelativeLocations Locations)
 {
     if (Contents != null)
     {
         foreach (var list in Contents)
         {
             if ((list.Key & Locations) == list.Key)
             {
                 foreach (var item in list.Value)
                 {
                     yield return(item);
                 }
             }
         }
     }
 }
Exemple #12
0
        /// <summary>
        /// Move Object to Destination.
        /// </summary>
        /// <param name="Object">Object to move.</param>
        /// <param name="Destination">Destination to move too.</param>
        /// <param name="Location">The relative location within destination to move too.</param>
        public static void Move(MudObject Object, MudObject Destination, RelativeLocations Location = RelativeLocations.DEFAULT)
        {
            if (Object == null)
            {
                return;
            }

            if (Object.Location.HasValue(out var loc))
            {
                loc.Remove(Object);
            }

            if (Destination != null)
            {
                Destination.Add(Object, Location);
            }
            Object.Location = Destination;
        }
Exemple #13
0
 public IEnumerable <T> EnumerateObjects <T>(RelativeLocations Locations) where T : MudObject
 {
     if (Contents != null)
     {
         foreach (var list in Contents)
         {
             if ((list.Key & Locations) == list.Key)
             {
                 foreach (var item in list.Value)
                 {
                     if (item is T)
                     {
                         yield return(item as T);
                     }
                 }
             }
         }
     }
 }
Exemple #14
0
        public void Add(MudObject Object, RelativeLocations Locations)
        {
            if (Contents == null)
            {
                return;
            }

            if (Locations == RelativeLocations.DEFAULT)
            {
                Locations = DefaultContentLocation;
            }

            if ((ContentLocationsAllowed & Locations) == Locations)
            {
                if (!Contents.ContainsKey(Locations))
                {
                    Contents.Add(Locations, new List <MudObject>());
                }
                Contents[Locations].Add(Object);
            }
        }
Exemple #15
0
        /// <summary>
        /// Move Object to Destination.
        /// </summary>
        /// <param name="Object">Object to move.</param>
        /// <param name="Destination">Destination to move too.</param>
        /// <param name="Location">The relative location within destination to move too.</param>
        public static void Move(MudObject Object, MudObject Destination, RelativeLocations Location = RelativeLocations.Default)
        {
            if (Object == null)
            {
                return;
            }

            if (Object.Location != null && Object.Location is Container)
            {
                (Object.Location as Container).Remove(Object);
            }

            if (Destination is Container)
            {
                (Destination as Container).Add(Object, Location);
                Object.Location = Destination;
            }
            else
            {
                Object.Location = null;
            }
        }
Exemple #16
0
 public static String GetRelativeLocationName(RelativeLocations Location)
 {
     if ((Location & RelativeLocations.On) == RelativeLocations.On)
     {
         return("on");
     }
     else if ((Location & RelativeLocations.In) == RelativeLocations.In)
     {
         return("in");
     }
     else if ((Location & RelativeLocations.Under) == RelativeLocations.Under)
     {
         return("under");
     }
     else if ((Location & RelativeLocations.Behind) == RelativeLocations.Behind)
     {
         return("behind");
     }
     else
     {
         return("relloc");
     }
 }
 public static String GetRelativeLocationName(RelativeLocations Location)
 {
     if ((Location & RelativeLocations.ON) == RelativeLocations.ON)
     {
         return("on");
     }
     else if ((Location & RelativeLocations.IN) == RelativeLocations.IN)
     {
         return("in");
     }
     else if ((Location & RelativeLocations.UNDER) == RelativeLocations.UNDER)
     {
         return("under");
     }
     else if ((Location & RelativeLocations.BEHIND) == RelativeLocations.BEHIND)
     {
         return("behind");
     }
     else
     {
         return("relloc");
     }
 }
Exemple #18
0
 public List<MudObject> GetContents(RelativeLocations Locations)
 {
     return new List<MudObject>(EnumerateObjects(Locations));
 }
Exemple #19
0
 public Container(RelativeLocations Locations, RelativeLocations Default)
 {
     this.Supported = Locations;
     this.Default = Default;
     this.Lists = new Dictionary<RelativeLocations, List<MudObject>>();
 }
 private static String RelativeLocationToString(RelativeLocations Relloc)
 {
     var parts = Relloc.ToString().Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
     if (parts.Length > 2) throw new InvalidOperationException();
     return parts[1].Trim();
 }