/// <summary> /// Move an entity out of this' named container /// </summary> /// <typeparam name="T">the type of entity to remove</typeparam> /// <param name="thing">the entity</param> /// <param name="containerName">the name of the container</param> /// <returns>errors</returns> public string MoveFrom <T>(T thing, string containerName) { var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T)); if (implimentedTypes.Contains(typeof(IInanimate))) { var obj = (IInanimate)thing; if (!Contents.Contains(obj, containerName)) { return("That is not in the container"); } Contents.Remove(obj, containerName); obj.CurrentLocation = null; this.UpsertToLiveWorldCache(); return(string.Empty); } if (implimentedTypes.Contains(typeof(IMobile))) { var obj = (IMobile)thing; if (!MobilesInside.Contains(obj, containerName)) { return("That is not in the container"); } MobilesInside.Remove(obj, containerName); obj.CurrentLocation = null; this.UpsertToLiveWorldCache(); return(string.Empty); } if (implimentedTypes.Contains(typeof(IPathway))) { var obj = (IPathway)thing; if (!Pathways.Contains(obj, containerName)) { return("That is not in the container"); } Pathways.Remove(obj, containerName); obj.CurrentLocation = null; this.UpsertToLiveWorldCache(); return(string.Empty); } return("Invalid type to move from container."); }
/// <summary> /// Move an entity into a named container in this /// </summary> /// <typeparam name="T">the type of the entity to add</typeparam> /// <param name="thing">the entity to add</param> /// <param name="containerName">the name of the container</param> /// <returns>errors</returns> public string MoveInto <T>(T thing, string containerName) { var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T)); if (implimentedTypes.Contains(typeof(IInanimate))) { var obj = (IInanimate)thing; if (Contents.Contains(obj, containerName)) { return("That is already in the container"); } Contents.Add(obj, containerName); obj.CurrentLocation = this; this.UpsertToLiveWorldCache(); return(string.Empty); } if (implimentedTypes.Contains(typeof(IMobile))) { var obj = (IMobile)thing; if (MobilesInside.Contains(obj, containerName)) { return("That is already in the container"); } MobilesInside.Add(obj, containerName); obj.CurrentLocation = this; this.UpsertToLiveWorldCache(); return(string.Empty); } if (implimentedTypes.Contains(typeof(IPathway))) { var obj = (IPathway)thing; if (Pathways.Contains(obj, containerName)) { return("That is already in the container"); } Pathways.Add(obj, containerName); obj.CurrentLocation = this; this.UpsertToLiveWorldCache(); return(string.Empty); } return("Invalid type to move to container."); }