コード例 #1
0
        /// <summary>
        /// Spawn this into the world and live cache
        /// </summary>
        public override void SpawnNewInWorld(IGlobalPosition spawnTo)
        {
            //We can't even try this until we know if the data is there
            ILocaleTemplate bS = Template <ILocaleTemplate>() ?? throw new InvalidOperationException("Missing backing data store on locale spawn event.");

            Keywords         = new string[] { bS.Name.ToLower() };
            AlwaysDiscovered = bS.AlwaysDiscovered;
            Descriptives     = bS.Descriptives;

            if (string.IsNullOrWhiteSpace(BirthMark))
            {
                BirthMark = LiveCache.GetUniqueIdentifier(bS);
                Birthdate = DateTime.Now;
            }

            UpsertToLiveWorldCache(true);

            ParentLocation = LiveCache.Get <IZone>(bS.ParentLocation.Id);

            if (spawnTo?.CurrentZone == null)
            {
                spawnTo = new GlobalPosition(ParentLocation, this);
            }

            CurrentLocation = spawnTo;

            UpsertToLiveWorldCache(true);
        }
コード例 #2
0
        /// <summary>
        /// Render an ascii map of stored data rooms around a specific radius
        /// </summary>
        /// <param name="room">the room to render the radius around</param>
        /// <param name="radius">the radius around the room to render</param>
        /// <param name="forAdmin">include edit links for paths and rooms?</param>
        /// <param name="withPathways">include paths at all?</param>
        /// <returns>a single string that is an ascii map</returns>
        public static string RenderRadiusMap(IRoomTemplate room, int radius, bool visibleOnly = false, bool forAdmin = true, bool withPathways = true, ILocaleTemplate locale = null, MapRenderMode renderMode = MapRenderMode.Normal)
        {
            StringBuilder asciiMap = new StringBuilder();

            //Why?
            if (room == null)
            {
                //Don't show "add room" to non admins, if we're not requesting this for a locale and if the locale has actual rooms
                if (!forAdmin || locale == null || locale.Rooms().Count() > 0)
                {
                    return(string.Empty);
                }

                return(string.Format("<a href='#' class='addData pathway AdminAddInitialRoom' localeId='{0}' title='New Room'>Add Initial Room</a>", locale.Id));
            }

            //1. Get world map
            ILocaleTemplate ourLocale = room.ParentLocation;

            //2. Get slice of room from world map
            long[,,] map = Cartographer.TakeSliceOfMap(new Tuple <int, int>(Math.Max(room.Coordinates.X - radius, 0), room.Coordinates.X + radius)
                                                       , new Tuple <int, int>(Math.Max(room.Coordinates.Y - radius, 0), room.Coordinates.Y + radius)
                                                       , new Tuple <int, int>(Math.Max(room.Coordinates.Z - 1, 0), room.Coordinates.Z + 1)
                                                       , ourLocale.Interior.CoordinatePlane, true);

            //3. Flatten the map
            long[,] flattenedMap = Cartographer.GetSinglePlane(map, room.Coordinates.Z);

            //4. Render slice of room
            return(RenderMap(flattenedMap, visibleOnly, forAdmin, withPathways, room, renderMode));
        }
コード例 #3
0
        public ActionResult Edit(long zoneId, AddEditLocaleTemplateViewModel vModel, long id)
        {
            IZoneTemplate zone = TemplateCache.Get <IZoneTemplate>(zoneId);

            if (zone == null)
            {
                return(RedirectToAction("Index", "Zone", new { Id = zoneId, Message = "Invalid zone" }));
            }

            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(id);
            string          message;

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToAction("Index", new { Message = message }));
            }

            obj.Name             = vModel.DataObject.Name;
            obj.AlwaysDiscovered = vModel.DataObject.AlwaysDiscovered;

            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - EditLocale[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                message = "Edit Successful.";
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToAction("Index", "Zone", new { Id = zoneId, Message = message }));
        }
コード例 #4
0
        public ActionResult Add(long localeId)
        {
            ILocaleTemplate myLocale = TemplateCache.Get <ILocaleTemplate>(localeId);

            if (myLocale == null)
            {
                return(RedirectToAction("Index", new { Message = "Invalid Locale" }));
            }

            AddEditRoomTemplateViewModel vModel = new AddEditRoomTemplateViewModel
            {
                AuthedUser     = UserManager.FindById(User.Identity.GetUserId()),
                ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                ValidModels    = TemplateCache.GetAll <IDimensionalModelData>(),
                ValidZones     = TemplateCache.GetAll <IZoneTemplate>(),
                ValidRooms     = TemplateCache.GetAll <IRoomTemplate>(),
                ValidLocales   = TemplateCache.GetAll <ILocaleTemplate>().Where(locale => locale.Id != localeId),
                ZonePathway    = new PathwayTemplate()
                {
                    Destination = myLocale.ParentLocation
                },
                LocaleRoomPathway = new PathwayTemplate(),
                LocaleRoomPathwayDestinationLocale = new LocaleTemplate(),
                DataObject = new RoomTemplate()
                {
                    ParentLocation = myLocale
                }
            };

            return(View("~/Views/GameAdmin/Room/Add.cshtml", "_chromelessLayout", vModel));
        }
コード例 #5
0
        public ActionResult Edit(long zoneId, long id)
        {
            IZoneTemplate zone = TemplateCache.Get <IZoneTemplate>(zoneId);

            if (zone == null)
            {
                return(RedirectToAction("Index", "Zone", new { Id = zoneId, Message = "Invalid zone" }));
            }

            AddEditLocaleTemplateViewModel vModel = new AddEditLocaleTemplateViewModel
            {
                AuthedUser = UserManager.FindById(User.Identity.GetUserId())
            };

            ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(id);

            if (obj == null)
            {
                string message = "That does not exist";
                return(RedirectToAction("Index", "Zone", new { Id = zoneId, Message = message }));
            }

            vModel.DataObject = obj;

            return(View("~/Views/GameAdmin/Locale/Edit.cshtml", vModel));
        }
コード例 #6
0
        public ActionResult RemoveDescriptive(long id = -1, string authorize = "")
        {
            string message = string.Empty;

            if (string.IsNullOrWhiteSpace(authorize))
            {
                message = "You must check the proper authorize radio button first.";
            }
            else
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());
                string[]        values     = authorize.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);

                if (values.Count() != 2)
                {
                    message = "You must check the proper authorize radio button first.";
                }
                else
                {
                    string type   = values[0];
                    string phrase = values[1];

                    ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(id);

                    if (obj == null)
                    {
                        message = "That does not exist";
                    }
                    else
                    {
                        GrammaticalType grammaticalType    = (GrammaticalType)Enum.Parse(typeof(GrammaticalType), type);
                        ISensoryEvent   existingOccurrence = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == grammaticalType &&
                                                                                             occurrence.Event.Phrase.Equals(phrase, StringComparison.InvariantCultureIgnoreCase));

                        if (existingOccurrence != null)
                        {
                            obj.Descriptives.Remove(existingOccurrence);

                            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
                            {
                                LoggingUtility.LogAdminCommandUsage("*WEB* - RemoveDescriptive[" + id.ToString() + "|" + type.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                                message = "Delete Successful.";
                            }
                            else
                            {
                                message = "Error; Removal failed.";
                            }
                        }
                        else
                        {
                            message = "That does not exist";
                        }
                    }
                }
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
コード例 #7
0
        public ActionResult AddEditDescriptive(long id, OccurrenceViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(id);

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
            }

            ISensoryEvent existingOccurrence = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                                                               occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            if (existingOccurrence == null)
            {
                existingOccurrence = new SensoryEvent(vModel.SensoryEventDataObject.SensoryType)
                {
                    Strength = vModel.SensoryEventDataObject.Strength,
                    Event    = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                          vModel.SensoryEventDataObject.Event.Role,
                                          vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                    {
                        Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                    }
                };
            }
            else
            {
                existingOccurrence.Strength    = vModel.SensoryEventDataObject.Strength;
                existingOccurrence.SensoryType = vModel.SensoryEventDataObject.SensoryType;
                existingOccurrence.Event       = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                                            vModel.SensoryEventDataObject.Event.Role,
                                                            vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                {
                    Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                };
            }

            obj.Descriptives.RemoveWhere(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                         occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            obj.Descriptives.Add(existingOccurrence);

            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - Locale AddEditDescriptive[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
コード例 #8
0
        /// <summary>
        /// Render the ascii map of room data for the locale based around the center room of the zIndex (negative 1 zIndex is treated as central room of entire set)
        /// </summary>
        /// <param name="locale">The locale to render for</param>
        /// <param name="radius">The radius of rooms to go out to</param>
        /// <param name="zIndex">The zIndex plane to get</param>
        /// <param name="forAdmin">Is this for admin purposes? (makes it have editor links)</param>
        /// <param name="withPathways">Include pathways? (inflated map)</param>
        /// <returns>a single string that is an ascii map</returns>
        public static Tuple <string, string, string> RenderRadiusMap(ILocaleTemplate locale, int radius, int zIndex, bool forAdmin = true, bool withPathways = true)
        {
            IRoomTemplate centerRoom = locale.CentralRoom(zIndex);

            string over  = RenderRadiusMap(centerRoom, radius, false, forAdmin, withPathways, locale, MapRenderMode.Upwards);
            string here  = RenderRadiusMap(centerRoom, radius, false, forAdmin, withPathways, locale, MapRenderMode.Normal);
            string under = RenderRadiusMap(centerRoom, radius, false, forAdmin, withPathways, locale, MapRenderMode.Downwards);

            return(new Tuple <string, string, string>(over, here, under));
        }
コード例 #9
0
        public string[] RenderLocaleMapForEdit(long id, int zIndex)
        {
            ILocaleTemplate locale = TemplateCache.Get <ILocaleTemplate>(id);

            if (locale == null)
            {
                return(new string[] { "Invalid inputs." });
            }

            System.Tuple <string, string, string> maps = Rendering.RenderRadiusMap(locale, 10, zIndex);

            return(new string[] { maps.Item1, maps.Item2, maps.Item3 });
        }
コード例 #10
0
        public ActionResult Remove(long zoneId, long removeId = -1, string authorizeRemove = "", long unapproveId = -1, string authorizeUnapprove = "")
        {
            string message;

            if (!string.IsNullOrWhiteSpace(authorizeRemove) && removeId.ToString().Equals(authorizeRemove))
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

                ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(removeId);

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.Remove(authedUser.GameAccount, authedUser.GetStaffRank(User)))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - RemoveLocale[" + removeId.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                    message = "Delete Successful.";
                }
                else
                {
                    message = "Error; Removal failed.";
                }
            }
            else if (!string.IsNullOrWhiteSpace(authorizeUnapprove) && unapproveId.ToString().Equals(authorizeUnapprove))
            {
                ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

                ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(unapproveId);

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.ChangeApprovalStatus(authedUser.GameAccount, authedUser.GetStaffRank(User), ApprovalState.Returned))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - UnapproveLocale[" + unapproveId.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                    message = "Unapproval Successful.";
                }
                else
                {
                    message = "Error; Unapproval failed.";
                }
            }
            else
            {
                message = "You must check the proper remove or unapprove authorization radio button first.";
            }

            return(RedirectToAction("Edit", "Zone", new { Id = zoneId, Message = message }));
        }
コード例 #11
0
        public ActionResult AddEditLocalePath(long id, long localeId)
        {
            ILocaleTemplate locale = TemplateCache.Get <ILocaleTemplate>(localeId);

            if (locale == null)
            {
                return(RedirectToAction("Edit", new { Message = "Locale is invalid.", id }));
            }

            IEnumerable <IRoomTemplate> validRooms = TemplateCache.GetAll <IRoomTemplate>().Where(rm => rm.ParentLocation.Equals(locale));

            if (validRooms.Count() == 0)
            {
                return(RedirectToAction("Edit", new { Message = "Locale has no rooms.", id }));
            }

            IZoneTemplate origin = TemplateCache.Get <IZoneTemplate>(id);

            IPathwayTemplate existingPathway = origin.GetLocalePathways().FirstOrDefault(path => ((IRoomTemplate)path.Destination).ParentLocation.Equals(locale));

            AddEditZonePathwayTemplateViewModel vModel = new AddEditZonePathwayTemplateViewModel
            {
                AuthedUser = UserManager.FindById(User.Identity.GetUserId()),

                ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                ValidRooms     = validRooms,
            };

            if (existingPathway != null)
            {
                vModel.DataObject      = existingPathway;
                vModel.DestinationRoom = (IRoomTemplate)existingPathway.Destination;
            }
            else
            {
                vModel.DataObject = new PathwayTemplate()
                {
                    Origin = origin
                };
            }

            return(View("~/Views/GameAdmin/Zone/AddEditLocalePath.cshtml", vModel));
        }
コード例 #12
0
        public ActionResult AddEditDescriptive(long id, short descriptiveType, string phrase)
        {
            string message = string.Empty;

            ILocaleTemplate obj = TemplateCache.Get <ILocaleTemplate>(id);

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
            }

            OccurrenceViewModel vModel = new OccurrenceViewModel
            {
                AuthedUser    = UserManager.FindById(User.Identity.GetUserId()),
                DataObject    = obj,
                AdminTypeName = "Locale"
            };

            if (descriptiveType > -1)
            {
                GrammaticalType grammaticalType = (GrammaticalType)descriptiveType;
                vModel.SensoryEventDataObject = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == grammaticalType &&
                                                                                occurrence.Event.Phrase.Equals(phrase, StringComparison.InvariantCultureIgnoreCase));
            }

            if (vModel.SensoryEventDataObject != null)
            {
                vModel.LexicaDataObject = vModel.SensoryEventDataObject.Event;
            }
            else
            {
                vModel.SensoryEventDataObject = new SensoryEvent
                {
                    Event = new Lexica()
                };
            }

            return(View("~/Views/GameAdmin/Locale/SensoryEvent.cshtml", "_chromelessLayout", vModel));
        }
コード例 #13
0
        /// <summary>
        /// News up an entity with its backing data
        /// </summary>
        /// <param name="room">the backing data</param>
        public Locale(ILocaleTemplate locale)
        {
            TemplateId = locale.Id;

            GetFromWorldOrSpawn();
        }
コード例 #14
0
        public ActionResult Add(long localeId, AddEditRoomTemplateViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());
            ILocaleTemplate locale     = TemplateCache.Get <ILocaleTemplate>(localeId);

            IRoomTemplate newObj = vModel.DataObject;

            newObj.ParentLocation = locale;
            newObj.Coordinates    = new Coordinate(0, 0, 0); //TODO: fix this

            IPathwayTemplate zoneDestination = null;

            if (vModel.ZonePathway?.Destination != null && !string.IsNullOrWhiteSpace(vModel.ZonePathway.Name))
            {
                IZoneTemplate destination = TemplateCache.Get <IZoneTemplate>(vModel.ZonePathway.Destination.Id);
                zoneDestination = new PathwayTemplate()
                {
                    DegreesFromNorth = -1,
                    Name             = vModel.ZonePathway.Name,
                    Origin           = newObj,
                    Destination      = destination,
                    InclineGrade     = vModel.ZonePathway.InclineGrade,
                    Model            = vModel.ZonePathway.Model
                };
            }

            IPathwayTemplate localeRoomPathway = null;

            if (vModel.LocaleRoomPathwayDestination != null && !string.IsNullOrWhiteSpace(vModel.LocaleRoomPathwayDestination.Name))
            {
                IRoomTemplate destination = TemplateCache.Get <IRoomTemplate>(vModel.LocaleRoomPathwayDestination.Id);
                localeRoomPathway = new PathwayTemplate()
                {
                    DegreesFromNorth = vModel.LocaleRoomPathway.DegreesFromNorth,
                    Name             = vModel.LocaleRoomPathway.Name,
                    Origin           = newObj,
                    Destination      = destination,
                    InclineGrade     = vModel.LocaleRoomPathway.InclineGrade,
                    Model            = vModel.LocaleRoomPathway.Model
                };
            }


            if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
            {
                if (zoneDestination != null)
                {
                    zoneDestination.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                if (localeRoomPathway != null)
                {
                    localeRoomPathway.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                message = "Error; Creation failed.";
            }
            else
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - AddRoomTemplate[" + newObj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }