Beispiel #1
0
        public ActionResult Edit(int id)
        {
            string        message = string.Empty;
            IRoomTemplate obj     = TemplateCache.Get <IRoomTemplate>(id);

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

            AddEditRoomTemplateViewModel vModel = new AddEditRoomTemplateViewModel
            {
                AuthedUser       = UserManager.FindById(User.Identity.GetUserId()),
                ValidMaterials   = TemplateCache.GetAll <IMaterial>(),
                ValidZones       = TemplateCache.GetAll <IZoneTemplate>(),
                ValidLocales     = TemplateCache.GetAll <ILocaleTemplate>().Where(locale => locale.Id != obj.ParentLocation.Id),
                ValidLocaleRooms = TemplateCache.GetAll <IRoomTemplate>().Where(room => room.Id != obj.Id && room.ParentLocation.Id == obj.ParentLocation.Id),
                ValidRooms       = TemplateCache.GetAll <IRoomTemplate>().Where(room => room.Id != obj.Id),
                ValidModels      = TemplateCache.GetAll <IDimensionalModelData>(),
                DataObject       = obj,
            };

            IPathwayTemplate zoneDestination = obj.GetZonePathways().FirstOrDefault();

            if (zoneDestination != null)
            {
                vModel.ZonePathway = zoneDestination;
            }
            else
            {
                vModel.ZonePathway = new PathwayTemplate()
                {
                    Destination = obj.ParentLocation.ParentLocation, Origin = obj
                };
            }

            IPathwayTemplate localeRoomPathway = obj.GetLocalePathways().FirstOrDefault();

            if (localeRoomPathway != null)
            {
                vModel.LocaleRoomPathway = localeRoomPathway;
                vModel.LocaleRoomPathwayDestinationLocale = ((IRoomTemplate)localeRoomPathway.Destination).ParentLocation;
                vModel.ValidLocaleRooms = TemplateCache.GetAll <IRoomTemplate>().Where(room => localeRoomPathway.Id == room.ParentLocation.Id);
            }
            else
            {
                vModel.LocaleRoomPathway = new PathwayTemplate()
                {
                    Origin = obj
                };
                vModel.LocaleRoomPathwayDestinationLocale = new LocaleTemplate();
            }


            return(View("~/Views/GameAdmin/Room/Edit.cshtml", "_chromelessLayout", vModel));
        }
Beispiel #2
0
        private static string[,] RenderRoomAndPathwaysForMapNode(int x, int y, IRoomTemplate RoomTemplate, IRoomTemplate centerRoom, string[,] expandedMap, bool currentRoom, bool forAdmin, MapRenderMode renderMode)
        {
            IEnumerable <IPathwayTemplate> pathways = RoomTemplate.GetPathways();
            int expandedRoomX = x * 3 + 1;
            int expandedRoomY = y * 3 + 1;

            switch (renderMode)
            {
            case MapRenderMode.Normal:
                IPathwayTemplate ePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.East);
                IPathwayTemplate nPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.North);
                IPathwayTemplate nePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthEast);
                IPathwayTemplate nwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthWest);
                IPathwayTemplate sPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.South);
                IPathwayTemplate sePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthEast);
                IPathwayTemplate swPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthWest);
                IPathwayTemplate wPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.West);

                //The room
                expandedMap[expandedRoomX, expandedRoomY] = RenderRoomToAscii(RoomTemplate, RoomTemplate.GetZonePathways().Any(), RoomTemplate.GetLocalePathways().Any()
                                                                              , !forAdmin && currentRoom, forAdmin);

                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nwPath, RoomTemplate.Id, MovementDirectionType.NorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(nPath, RoomTemplate.Id, MovementDirectionType.North, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nePath, RoomTemplate.Id, MovementDirectionType.NorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(wPath, RoomTemplate.Id, MovementDirectionType.West, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(ePath, RoomTemplate.Id, MovementDirectionType.East, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(swPath, RoomTemplate.Id, MovementDirectionType.SouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(sPath, RoomTemplate.Id, MovementDirectionType.South, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(sePath, RoomTemplate.Id, MovementDirectionType.SouthEast, forAdmin);

                break;

            case MapRenderMode.Upwards:
                IPathwayTemplate upPath   = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Up);
                IPathwayTemplate upePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpEast);
                IPathwayTemplate upnPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorth);
                IPathwayTemplate upnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthEast);
                IPathwayTemplate upnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthWest);
                IPathwayTemplate upsPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouth);
                IPathwayTemplate upsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthEast);
                IPathwayTemplate upswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthWest);
                IPathwayTemplate upwPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpWest);

                expandedMap[expandedRoomX, expandedRoomY]         = RenderPathwayToAsciiForModals(upPath, RoomTemplate.Id, MovementDirectionType.Up, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnwPath, RoomTemplate.Id, MovementDirectionType.UpNorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(upnPath, RoomTemplate.Id, MovementDirectionType.UpNorth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnePath, RoomTemplate.Id, MovementDirectionType.UpNorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(upwPath, RoomTemplate.Id, MovementDirectionType.UpWest, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(upePath, RoomTemplate.Id, MovementDirectionType.UpEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upswPath, RoomTemplate.Id, MovementDirectionType.UpSouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(upsPath, RoomTemplate.Id, MovementDirectionType.UpSouth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upsePath, RoomTemplate.Id, MovementDirectionType.UpSouthEast, forAdmin);

                break;

            case MapRenderMode.Downwards:
                IPathwayTemplate downPath   = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Down);
                IPathwayTemplate downePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownEast);
                IPathwayTemplate downnPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorth);
                IPathwayTemplate downnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthEast);
                IPathwayTemplate downnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthWest);
                IPathwayTemplate downsPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouth);
                IPathwayTemplate downsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthEast);
                IPathwayTemplate downswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthWest);
                IPathwayTemplate downwPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownWest);

                expandedMap[expandedRoomX, expandedRoomY]         = RenderPathwayToAsciiForModals(downPath, RoomTemplate.Id, MovementDirectionType.Down, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnwPath, RoomTemplate.Id, MovementDirectionType.DownNorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(downnPath, RoomTemplate.Id, MovementDirectionType.DownNorth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnePath, RoomTemplate.Id, MovementDirectionType.DownNorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(downwPath, RoomTemplate.Id, MovementDirectionType.DownWest, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(downePath, RoomTemplate.Id, MovementDirectionType.DownEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downswPath, RoomTemplate.Id, MovementDirectionType.DownSouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(downsPath, RoomTemplate.Id, MovementDirectionType.DownSouth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downsePath, RoomTemplate.Id, MovementDirectionType.DownSouthEast, forAdmin);

                break;
            }

            return(expandedMap);
        }
Beispiel #3
0
        /// <summary>
        /// Renders a map from a single z,y plane
        /// </summary>
        /// <param name="map">The map to render</param>
        /// <param name="forAdmin">is this for admin (with edit links)</param>
        /// <param name="withPathways">include pathway symbols</param>
        /// <param name="centerRoom">the room considered "center"</param>
        /// <returns>the rendered map</returns>
        public static string RenderMap(long[,] map, bool visibileOnly, bool forAdmin, bool withPathways, IRoomTemplate centerRoom, MapRenderMode renderMode = MapRenderMode.Normal)
        {
            StringBuilder sb = new StringBuilder();

            if (!withPathways)
            {
                int x, y;
                for (y = map.GetUpperBound(1); y >= 0; y--)
                {
                    string rowString = string.Empty;
                    for (x = 0; x < map.GetUpperBound(0); x++)
                    {
                        IRoomTemplate RoomTemplate = TemplateCache.Get <IRoomTemplate>(map[x, y]);

                        if (RoomTemplate != null)
                        {
                            rowString += RenderRoomToAscii(RoomTemplate, RoomTemplate.GetZonePathways().Any(), RoomTemplate.GetLocalePathways().Any(), !forAdmin && RoomTemplate.Id == centerRoom.Id, forAdmin);
                        }
                        else
                        {
                            rowString += "&nbsp;";
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(rowString.Replace("&nbsp;", "")))
                    {
                        sb.AppendLine(rowString);
                    }
                }
            }
            else
            {
                string[,] expandedMap = new string[(map.GetUpperBound(0) + 1) * 3 + 1, (map.GetUpperBound(1) + 1) * 3 + 1];

                int x, y;
                int xMax = 0;
                for (y = map.GetUpperBound(1); y >= 0; y--)
                {
                    for (x = 0; x <= map.GetUpperBound(0); x++)
                    {
                        IRoomTemplate RoomTemplate = TemplateCache.Get <IRoomTemplate>(map[x, y]);

                        if (RoomTemplate != null)
                        {
                            if (x > xMax)
                            {
                                xMax = x;
                            }

                            expandedMap = RenderRoomAndPathwaysForMapNode(x, y, RoomTemplate, centerRoom, expandedMap, RoomTemplate.Id == centerRoom.Id, forAdmin, renderMode);
                        }
                    }
                }

                //3 for inflation
                if (withPathways)
                {
                    xMax += 3;
                }

                for (y = expandedMap.GetUpperBound(1); y >= 0; y--)
                {
                    string rowString = string.Empty;
                    for (x = 0; x <= expandedMap.GetUpperBound(0); x++)
                    {
                        string xString = expandedMap[x, y];
                        if (string.IsNullOrWhiteSpace(xString))
                        {
                            if (!forAdmin || x <= xMax)
                            {
                                rowString += "&nbsp;";
                            }
                        }
                        else
                        {
                            rowString += expandedMap[x, y];
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(rowString.Replace("&nbsp;", "")))
                    {
                        sb.AppendLine(rowString);
                    }
                }
            }

            return(sb.ToString());
        }
Beispiel #4
0
        public ActionResult Edit(int id, AddEditRoomTemplateViewModel vModel)
        {
            ApplicationUser  authedUser        = UserManager.FindById(User.Identity.GetUserId());
            IPathwayTemplate zoneDestination   = null;
            IPathwayTemplate localeRoomPathway = null;

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

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

            obj.Name      = vModel.DataObject.Name;
            obj.Medium    = vModel.DataObject.Medium;
            obj.Qualities = vModel.DataObject.Qualities;

            if (vModel.ZonePathway?.Destination != null && !string.IsNullOrWhiteSpace(vModel.ZonePathway.Name))
            {
                IZoneTemplate destination = TemplateCache.Get <IZoneTemplate>(vModel.ZonePathway.Destination.Id);
                zoneDestination = obj.GetZonePathways().FirstOrDefault();

                if (zoneDestination == null)
                {
                    zoneDestination = new PathwayTemplate()
                    {
                        DegreesFromNorth = vModel.ZonePathway.DegreesFromNorth,
                        Name             = vModel.ZonePathway.Name,
                        Origin           = obj,
                        Destination      = destination,
                        InclineGrade     = vModel.ZonePathway.InclineGrade,
                        Model            = vModel.ZonePathway.Model
                    };
                }
                else
                {
                    zoneDestination.Model        = vModel.ZonePathway.Model;
                    zoneDestination.Name         = vModel.ZonePathway.Name;
                    zoneDestination.InclineGrade = vModel.ZonePathway.InclineGrade;

                    //We switched zones, this makes things more complicated
                    if (zoneDestination.Id != vModel.ZonePathway.Destination.Id)
                    {
                        zoneDestination.Destination = destination;
                    }
                }
            }

            if (vModel.LocaleRoomPathwayDestination != null && !string.IsNullOrWhiteSpace(vModel.LocaleRoomPathwayDestination.Name))
            {
                IRoomTemplate destination = TemplateCache.Get <IRoomTemplate>(vModel.LocaleRoomPathwayDestination.Id);
                localeRoomPathway = obj.GetLocalePathways().FirstOrDefault();

                if (localeRoomPathway == null)
                {
                    localeRoomPathway = new PathwayTemplate()
                    {
                        DegreesFromNorth = vModel.LocaleRoomPathway.DegreesFromNorth,
                        Name             = vModel.LocaleRoomPathway.Name,
                        Origin           = obj,
                        Destination      = destination,
                        InclineGrade     = vModel.LocaleRoomPathway.InclineGrade,
                        Model            = vModel.LocaleRoomPathway.Model
                    };
                }
                else
                {
                    localeRoomPathway.Model        = vModel.LocaleRoomPathway.Model;
                    localeRoomPathway.Name         = vModel.LocaleRoomPathway.Name;
                    localeRoomPathway.InclineGrade = vModel.LocaleRoomPathway.InclineGrade;
                    localeRoomPathway.Destination  = destination;
                }
            }

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

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

                LoggingUtility.LogAdminCommandUsage("*WEB* - EditRoomTemplate[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
            }

            return(RedirectToRoute("ModalErrorOrClose"));
        }