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; }
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; }
public void Container(RelativeLocations Locations, RelativeLocations Default) { ContentLocationsAllowed = Locations; DefaultContentLocation = Default; Contents = new Dictionary <RelativeLocations, List <MudObject> >(); SetProperty("container?", true); }
public bool Contains(MudObject Object, RelativeLocations Locations) { if (Locations == RelativeLocations.Default) Locations = Default; if (Lists.ContainsKey(Locations)) return Lists[Locations].Contains(Object); return false; }
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()); }
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); } }
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"; }
private static RelativeLocations StringToRelativeLocation(String Str) { RelativeLocations r = RelativeLocations.None; if (Enum.TryParse(Str, out r)) { return(r); } else { throw new InvalidOperationException(); } }
/// <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; }
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); }
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); } } } } }
/// <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; }
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); } } } } } }
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); } }
/// <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; } }
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"); } }
public List<MudObject> GetContents(RelativeLocations Locations) { return new List<MudObject>(EnumerateObjects(Locations)); }
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(); }