Example #1
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IContains spawnTo)
        {
            var bS = (IPathwayData)DataTemplate;
            var locationAssembly = Assembly.GetAssembly(typeof(Room));

            MovementDirection = MessagingUtility.TranslateDegreesToDirection(bS.DegreesFromNorth);

            BirthMark = Birthmarker.GetBirthmark(bS);
            Keywords  = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() };
            Birthdate = DateTime.Now;

            //paths need two locations
            ILocation fromLocation     = null;
            var       fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType));

            if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID))
            {
                if (fromLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                {
                    long fromLocationID = long.Parse(bS.FromLocationID);
                    fromLocation = LiveCache.Get <ILocation>(fromLocationID, fromLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID);
                    fromLocation = LiveCache.Get <ILocation>(cacheKey);
                }
            }

            ILocation toLocation     = null;
            var       toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType));

            if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID))
            {
                if (toLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                {
                    long toLocationID = long.Parse(bS.ToLocationID);
                    toLocation = LiveCache.Get <ILocation>(toLocationID, toLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID);
                    toLocation = LiveCache.Get <ILocation>(cacheKey);
                }
            }

            FromLocation    = fromLocation;
            ToLocation      = toLocation;
            CurrentLocation = fromLocation;

            Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination });
            Enter.ToSurrounding.Add(bS.VisibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.VisibleToSurroundings }));
            Enter.ToSurrounding.Add(bS.AudibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.AudibleToSurroundings }));

            fromLocation.MoveInto <IPathway>(this);
        }
Example #2
0
        /// <summary>
        /// Method by which this entity has output (from commands and events) "shown" to it
        /// </summary>
        public virtual bool WriteTo(IEnumerable <string> output, bool delayed = false)
        {
            //null output means send wrapper to players
            if (output == null)
            {
                if (IsPlayer())
                {
                    var thisPlayer = (IPlayer)this;

                    thisPlayer.Descriptor.SendWrapper();
                }

                return(true);
            }

            IEnumerable <string> strings = MessagingUtility.TranslateColorVariables(output.ToArray(), this);

            return(TriggerAIAction(strings));
        }
Example #3
0
        /// <summary>
        /// Method by which this entity has output (from commands and events) "shown" to it
        /// </summary>
        public virtual bool WriteTo(IEnumerable <string> input)
        {
            IEnumerable <string> strings = MessagingUtility.TranslateColorVariables(input.ToArray(), this);

            return(TriggerAIAction(strings));
        }
        public string RenderRoomForEdit(long id, int radius)
        {
            var room = DataWrapper.GetOne <IRoomData>(id);
            var sb   = new StringBuilder();

            if (room == null || radius < 0)
            {
                return("Invalid inputs.");
            }

            var pathways = DataWrapper.GetAll <IPathwayData>().Where(path => path.FromLocationID.Equals(room.ID.ToString()));

            var nw = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.NorthWest);
            var n  = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.North);
            var ne = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.NorthEast);

            var northString = String.Empty;

            if (nw != null && !string.IsNullOrWhiteSpace(nw.ToLocationID) && nw.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(nw.ToLocationID));
                northString += String.Format("<a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", nw.ID, location.Name);
            }
            else
            {
                northString += String.Format("<a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='315'>+</a>", id);
            }

            if (n != null && !string.IsNullOrWhiteSpace(n.ToLocationID) && n.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(n.ToLocationID));
                northString += String.Format(" <a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", n.ID, location.Name);
            }
            else
            {
                northString += String.Format(" <a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='0'>+</a>", id);
            }

            if (ne != null && !string.IsNullOrWhiteSpace(ne.ToLocationID) && ne.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(ne.ToLocationID));
                northString += String.Format(" <a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", ne.ID, location.Name);
            }
            else
            {
                northString += String.Format(" <a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='45'>+</a>", id);
            }

            sb.AppendLine(northString);
            sb.AppendLine("\\ | /");

            var w = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.West);
            var e = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.East);

            var middleString = String.Empty;

            if (w != null && !string.IsNullOrWhiteSpace(w.ToLocationID) && w.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(w.ToLocationID));
                middleString += String.Format("<a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", w.ID, location.Name);
            }
            else
            {
                middleString += String.Format("<a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='270'>+</a>", id);
            }

            middleString += "--*--";

            if (e != null && !string.IsNullOrWhiteSpace(e.ToLocationID) && e.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(e.ToLocationID));
                middleString += String.Format("<a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", e.ID, location.Name);
            }
            else
            {
                middleString += String.Format("<a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='90'>+</a>", id);
            }

            sb.AppendLine(middleString);
            sb.AppendLine("/ | \\");

            var sw = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.SouthWest);
            var s  = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.South);
            var se = pathways.FirstOrDefault(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.SouthEast);

            var southString = String.Empty;

            if (sw != null && !string.IsNullOrWhiteSpace(sw.ToLocationID) && sw.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(sw.ToLocationID));
                southString += String.Format("<a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", sw.ID, location.Name);
            }
            else
            {
                southString += String.Format("<a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='225'>+</a>", id);
            }

            if (s != null && !string.IsNullOrWhiteSpace(s.ToLocationID) && s.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(s.ToLocationID));
                southString += String.Format(" <a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", s.ID, location.Name);
            }
            else
            {
                southString += String.Format(" <a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='180'>+</a>", id);
            }

            if (se != null && !string.IsNullOrWhiteSpace(se.ToLocationID) && se.ToLocationType.Equals("Room"))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(se.ToLocationID));
                southString += String.Format(" <a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", se.ID, location.Name);
            }
            else
            {
                southString += String.Format(" <a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='135'>+</a>", id);
            }

            sb.AppendLine(southString);

            var extraString = String.Empty;

            foreach (var path in pathways.Where(path => MessagingUtility.TranslateDegreesToDirection(path.DegreesFromNorth) == MovementDirectionType.None &&
                                                !string.IsNullOrWhiteSpace(path.ToLocationID) &&
                                                path.ToLocationType.Equals("Room")))
            {
                var location = DataWrapper.GetOne <IRoomData>(long.Parse(path.ToLocationID));

                if (location != null)
                {
                    extraString += String.Format(" <a href='/GameAdmin/EditPathway/{0}' target='_blank' class='editPathway' title='{1}' data-id='{0}'>#</a>", path.ID, location.Name);
                }
            }

            //One last for adding non-directional ones
            extraString += String.Format(" <a href='/GameAdmin/AddPathway/{0}' class='addPathway' target='_blank' data-direction='-1'>+</a>", id);

            if (extraString.Length > 0)
            {
                sb.AppendLine("&nbsp;");
                sb.AppendLine(extraString);
            }

            return(sb.ToString());
        }