Beispiel #1
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));
        }
Beispiel #2
0
        private static void FillRoomDimensions(long[,,] coordinatePlane)
        {
            if (coordinatePlane == null)
            {
                return;
            }

            int x, y, z;

            for (x = 0; x <= coordinatePlane.GetUpperBound(0); x++)
            {
                for (y = 0; y <= coordinatePlane.GetUpperBound(1); y++)
                {
                    for (z = 0; z <= coordinatePlane.GetUpperBound(2); z++)
                    {
                        if (coordinatePlane[x, y, z] < 0)
                        {
                            continue;
                        }

                        IRoomTemplate room = TemplateCache.Get <IRoomTemplate>(coordinatePlane[x, y, z]);

                        if (room == null)
                        {
                            continue;
                        }

                        room.Coordinates = new Coordinate(x, y, z);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generate a room map starting in a room backing data with a radius around it
        /// </summary>
        /// <param name="room">the starting room</param>
        /// <param name="radius">the radius of rooms to go out to. -1 means "generate the entire world"</param>
        /// <param name="recenter">find the center node of the array and return an array with that node at absolute center</param>
        /// <returns>a 3d array of rooms</returns>
        public static long[,,] GenerateMapFromRoom(IRoomTemplate room, HashSet <IRoomTemplate> roomPool, bool shrink = false)
        {
            if (room == null)
            {
                return(new long[0, 0, 0]);
            }

            int diameter = 50;
            int center   = 25;

            //+1 for center room
            diameter++;
            center++;

            long[,,] returnMap = new long[diameter, diameter, diameter];
            returnMap          = returnMap.Populate(-1);

            //The origin room
            returnMap = AddFullRoomToMap(returnMap, room, diameter, center, center, center, roomPool);

            if (shrink)
            {
                returnMap = ShrinkMap(returnMap);
            }

            FillRoomDimensions(returnMap);

            return(returnMap);
        }
Beispiel #4
0
        public ActionResult RemoveDescriptive(long id, 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
                {
                    short  type   = short.Parse(values[0]);
                    string phrase = values[1];

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

                    if (obj == null)
                    {
                        message = "That does not exist";
                    }
                    else
                    {
                        GrammaticalType grammaticalType    = (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 }));
        }
Beispiel #5
0
        public ActionResult AddEditDescriptive(long id, OccurrenceViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IRoomTemplate obj = TemplateCache.Get <IRoomTemplate>(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* - Room AddEditDescriptive[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
Beispiel #6
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 #7
0
        public ActionResult Add(long id, long originRoomId, long destinationRoomId, int degreesFromNorth = 0, int incline = 0)
        {
            //New room or existing room
            if (destinationRoomId.Equals(-1))
            {
                IRoomTemplate origin = TemplateCache.Get <IRoomTemplate>(originRoomId);

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

                    ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                    ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                    ValidRooms     = TemplateCache.GetAll <IRoomTemplate>(),
                    Origin         = origin,
                    DataObject     = new PathwayTemplate()
                    {
                        DegreesFromNorth = degreesFromNorth, InclineGrade = incline
                    },
                    Destination = new RoomTemplate()
                    {
                        ParentLocation = origin.ParentLocation
                    }
                };

                vModel.Destination.ParentLocation = vModel.Origin.ParentLocation;

                return(View("~/Views/GameAdmin/Pathway/AddWithRoom.cshtml", "_chromelessLayout", vModel));
            }
            else
            {
                IRoomTemplate    origin          = TemplateCache.Get <IRoomTemplate>(originRoomId);
                IRoomTemplate    destination     = TemplateCache.Get <IRoomTemplate>(destinationRoomId);
                IPathwayTemplate pathwayTemplate = TemplateCache.Get <IPathwayTemplate>(id);

                if (pathwayTemplate == null)
                {
                    pathwayTemplate = new PathwayTemplate()
                    {
                        Origin = origin, Destination = destination, DegreesFromNorth = degreesFromNorth, InclineGrade = incline
                    };
                }

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

                    ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                    ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                    ValidRooms     = TemplateCache.GetAll <IRoomTemplate>().Where(rm => !rm.Id.Equals(originRoomId)),
                    DataObject     = pathwayTemplate
                };

                return(View("~/Views/GameAdmin/Pathway/AddEdit.cshtml", "_chromelessLayout", vModel));
            }
        }
Beispiel #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));
        }
Beispiel #9
0
        /// <summary>
        /// News up an entity with its backing data
        /// </summary>
        /// <param name="room">the backing data</param>
        public Room(IRoomTemplate room)
        {
            Contents      = new EntityContainer <IInanimate>();
            MobilesInside = new EntityContainer <IMobile>();
            Coordinates   = new Coordinate(-1, -1, -1);

            TemplateId = room.Id;

            GetFromWorldOrSpawn();
        }
Beispiel #10
0
        public string RenderRoomForEditWithRadius(long id, int radius)
        {
            IRoomTemplate centerRoom = TemplateCache.Get <IRoomTemplate>(id);

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

            return(Rendering.RenderRadiusMap(centerRoom, radius));
        }
Beispiel #11
0
        /// <summary>
        /// Isolates the main world map to just one zone
        /// </summary>
        /// <param name="fullMap">the world map</param>
        /// <param name="zoneId">the zone to isolate</param>
        /// <param name="recenter">recenter the map or not, defaults to not</param>
        /// <returns>the zone's map</returns>
        public static long[,,] GetLocaleMap(long[,,] fullMap, long localeId, bool recenter = false)
        {
            long[,,] newMap = new long[fullMap.GetUpperBound(0) + 1, fullMap.GetUpperBound(1) + 1, fullMap.GetUpperBound(2) + 1];
            newMap.Populate(-1);

            int x, y, z, xLowest = 0, yLowest = 0, zLowest = 0;

            for (x = 0; x <= fullMap.GetUpperBound(0); x++)
            {
                for (y = 0; y <= fullMap.GetUpperBound(1); y++)
                {
                    for (z = 0; z <= fullMap.GetUpperBound(2); z++)
                    {
                        IRoomTemplate room = TemplateCache.Get <IRoomTemplate>(fullMap[x, y, z]);

                        if (room == null || room.ParentLocation == null || !room.ParentLocation.Id.Equals(localeId))
                        {
                            continue;
                        }

                        newMap[x, y, z] = fullMap[x, y, z];

                        if (xLowest > x)
                        {
                            xLowest = x;
                        }

                        if (yLowest > y)
                        {
                            yLowest = y;
                        }

                        if (zLowest > z)
                        {
                            zLowest = z;
                        }
                    }
                }
            }

            //Maps were the same size or we didnt want to shrink
            if (!false || (xLowest <= 0 && yLowest <= 0 && zLowest <= 0))
            {
                return(newMap);
            }

            return(ShrinkMap(newMap, xLowest, yLowest, zLowest
                             , new Tuple <int, int>(newMap.GetLowerBound(0), newMap.GetUpperBound(0))
                             , new Tuple <int, int>(newMap.GetLowerBound(1), newMap.GetUpperBound(1))
                             , new Tuple <int, int>(newMap.GetLowerBound(2), newMap.GetUpperBound(2))));
        }
Beispiel #12
0
        public ActionResult Remove(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());

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

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.Remove(authedUser.GameAccount, authedUser.GetStaffRank(User)))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - RemoveRoom[" + 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());

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

                if (obj == null)
                {
                    message = "That does not exist";
                }
                else if (obj.ChangeApprovalStatus(authedUser.GameAccount, authedUser.GetStaffRank(User), ApprovalState.Returned))
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - UnapproveRoom[" + 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("Index", new { Message = message }));
        }
Beispiel #13
0
        public ActionResult AddWithRoom(AddPathwayWithRoomTemplateViewModel vModel)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IRoomTemplate origin  = TemplateCache.Get <IRoomTemplate>(vModel.Origin.Id);
            IRoomTemplate newRoom = vModel.Destination;

            newRoom.ParentLocation = origin.ParentLocation;

            string message = string.Empty;

            if (newRoom.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) != null)
            {
                IPathwayTemplate newObj = vModel.DataObject;
                newObj.Destination = newRoom;
                newObj.Origin      = origin;

                if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                {
                    message = "Error; Creation failed.";
                }
                else
                {
                    if (vModel.CreateReciprocalPath)
                    {
                        PathwayTemplate reversePath = new PathwayTemplate
                        {
                            Name             = newObj.Name,
                            DegreesFromNorth = Utilities.ReverseDirection(newObj.DegreesFromNorth),
                            Origin           = newObj.Destination,
                            Destination      = newObj.Origin,
                            Model            = newObj.Model,
                            InclineGrade     = newObj.InclineGrade * -1
                        };

                        if (reversePath.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                        {
                            message = "Reverse Path creation FAILED. Origin path creation SUCCESS.";
                        }
                    }

                    LoggingUtility.LogAdminCommandUsage("*WEB* - AddPathwayWithRoom[" + newObj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                }
            }
            else
            {
                message = "Error; Creation failed.";
            }
            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
Beispiel #14
0
        /// <summary>
        /// Get the visibile celestials. Depends on luminosity, viewer perception and celestial positioning
        /// </summary>
        /// <param name="viewer">Whom is looking</param>
        /// <returns>What celestials are visible</returns>
        public override IEnumerable <ICelestial> GetVisibileCelestials(IEntity viewer)
        {
            IRoomTemplate dT   = Template <IRoomTemplate>();
            IZone         zone = CurrentLocation.CurrentZone;

            bool canSeeSky = IsOutside() && dT.Coordinates.Z >= zone.Template <IZoneTemplate>().BaseElevation;

            if (!canSeeSky)
            {
                return(Enumerable.Empty <ICelestial>());
            }

            //The zone knows about the celestial positioning
            return(zone.GetVisibileCelestials(viewer));
        }
Beispiel #15
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(IGlobalPosition spawnTo)
        {
            //We can't even try this until we know if the data is there
            IRoomTemplate bS = Template <IRoomTemplate>() ?? throw new InvalidOperationException("Missing backing data store on room spawn event.");

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

            if (FloraNaturalResources == null)
            {
                FloraNaturalResources = new HashSet <INaturalResourceSpawn <IFlora> >();
            }

            if (FaunaNaturalResources == null)
            {
                FaunaNaturalResources = new HashSet <INaturalResourceSpawn <IFauna> >();
            }

            if (MineralNaturalResources == null)
            {
                MineralNaturalResources = new HashSet <INaturalResourceSpawn <IMineral> >();
            }

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

            UpsertToLiveWorldCache(true);

            ParentLocation        = LiveCache.Get <ILocale>(bS.ParentLocation.Id);
            spawnTo.CurrentLocale = ParentLocation;
            spawnTo.CurrentZone   = ParentLocation.ParentLocation;

            if (spawnTo?.CurrentLocale == null || spawnTo?.CurrentZone == null)
            {
                spawnTo = new GlobalPosition(this);
            }

            CurrentLocation = spawnTo;

            UpsertToLiveWorldCache(true);

            Save();
        }
Beispiel #16
0
        //We have to render our pathway out, an empty space for the potential pathway back and the destination room
        private static long[,,] AddDirectionToMap(long[,,] dataMap, MovementDirectionType transversalDirection, IRoomTemplate origin, int diameter, int centerX, int centerY, int centerZ, HashSet <IRoomTemplate> roomPool)
        {
            IEnumerable <IPathwayTemplate> pathways         = origin.GetPathways(true);
            Tuple <int, int, int>          directionalSteps = Utilities.GetDirectionStep(transversalDirection);

            int xStepped = centerX + directionalSteps.Item1;
            int yStepped = centerY + directionalSteps.Item2;
            int zStepped = centerZ + directionalSteps.Item3;

            //If we're not over diameter budget and there is nothing there already (we might have already rendered the path and room) then render it
            //When the next room tries to render backwards it'll run into the existant path it came from and stop the chain here
            if (xStepped > 0 && xStepped <= diameter &&
                yStepped > 0 && yStepped <= diameter &&
                zStepped > 0 && zStepped <= diameter &&
                dataMap[xStepped - 1, yStepped - 1, zStepped - 1] < 0)
            {
                IPathwayTemplate thisPath = pathways.FirstOrDefault(path =>
                                                                    (path.DirectionType == transversalDirection && path.Origin.Equals(origin) && path.Destination.EntityClass.GetInterfaces().Contains(typeof(IRoom))) ||
                                                                    (path.DirectionType == Utilities.ReverseDirection(transversalDirection) && path.Destination.Equals(origin) && path.Origin.EntityClass.GetInterfaces().Contains(typeof(IRoom)))
                                                                    );
                if (thisPath != null)
                {
                    long locId = thisPath.Destination.Id;

                    if (thisPath.Destination.Id.Equals(origin.Id))
                    {
                        locId = thisPath.Origin.Id;
                    }

                    IRoomTemplate passdownOrigin = TemplateCache.Get <IRoomTemplate>(locId);

                    if (passdownOrigin != null)
                    {
                        dataMap[xStepped - 1, yStepped - 1, zStepped - 1] = passdownOrigin.Id;
                        dataMap = AddFullRoomToMap(dataMap, passdownOrigin, diameter, xStepped, yStepped, zStepped, roomPool);
                    }
                }
            }

            return(dataMap);
        }
Beispiel #17
0
        public ActionResult AddEditDescriptive(long id, short descriptiveType, string phrase)
        {
            string message = string.Empty;

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

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

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

            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/Room/SensoryEvent.cshtml", "_chromelessLayout", vModel));
        }
Beispiel #18
0
        /// <summary>
        /// Gets the opposite room from the origin based on direction
        /// </summary>
        /// <param name="origin">The room we're looking to oppose</param>
        /// <param name="direction">The direction the room would be in (this method will reverse the direction itself)</param>
        /// <returns>The room that is in the direction from our room</returns>
        public static IRoomTemplate GetOpposingRoom(IRoomTemplate origin, MovementDirectionType direction)
        {
            //There is no opposite of none directionals
            if (origin == null || direction == MovementDirectionType.None)
            {
                return(null);
            }

            MovementDirectionType oppositeDirection = ReverseDirection(direction);

            System.Collections.Generic.IEnumerable <IPathwayTemplate> paths = TemplateCache.GetAll <IPathwayTemplate>();

            IPathwayTemplate ourPath = paths.FirstOrDefault(pt => origin.Equals(pt.Destination) &&
                                                            pt.DirectionType == oppositeDirection);

            if (ourPath != null)
            {
                return((IRoomTemplate)ourPath.Destination);
            }

            return(null);
        }
Beispiel #19
0
        //It's just easier to pass the ints we already calculated along instead of doing the math every single time, this cascades each direction fully because it calls itself for existant rooms
        private static long[,,] AddFullRoomToMap(long[,,] dataMap, IRoomTemplate origin, int diameter, int centerX, int centerY, int centerZ, HashSet <IRoomTemplate> roomPool)
        {
            if (roomPool != null && roomPool.Count > 0 && roomPool.Any(room => room.Id == origin.Id))
            {
                roomPool.Remove(origin);
            }

            //Render the room itself
            dataMap[centerX - 1, centerY - 1, centerZ - 1] = origin.Id;
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.North, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.NorthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.NorthWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.East, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.West, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.South, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.SouthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.SouthWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.Up, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpNorth, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpNorthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpNorthWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpSouth, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpSouthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.UpSouthWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.Down, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownNorth, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownNorthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownNorthWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownWest, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownSouth, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownSouthEast, origin, diameter, centerX, centerY, centerZ, roomPool);
            dataMap = AddDirectionToMap(dataMap, MovementDirectionType.DownSouthWest, origin, diameter, centerX, centerY, centerZ, roomPool);

            return(dataMap);
        }
Beispiel #20
0
        public string Quickbuild(long originId, long destinationId, int direction, int incline)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IRoomTemplate origin      = TemplateCache.Get <IRoomTemplate>(originId);
            IRoomTemplate destination = TemplateCache.Get <IRoomTemplate>(destinationId);

            string message = string.Empty;

            if (destination == null)
            {
                destination = new RoomTemplate
                {
                    Name           = "Room",
                    Medium         = origin.Medium,
                    ParentLocation = origin.ParentLocation,
                    Model          = new DimensionalModel()
                    {
                        ModelTemplate     = origin.Model.ModelTemplate,
                        Composition       = origin.Model.Composition,
                        Height            = origin.Model.Height,
                        Length            = origin.Model.Length,
                        Width             = origin.Model.Width,
                        SurfaceCavitation = origin.Model.SurfaceCavitation,
                        Vacuity           = origin.Model.Vacuity
                    }
                };

                destination = (IRoomTemplate)destination.Create(authedUser.GameAccount, authedUser.GetStaffRank(User));
            }


            if (destination != null)
            {
                IPathwayTemplate newObj = new PathwayTemplate
                {
                    Name             = "Pathway",
                    Destination      = destination,
                    Origin           = origin,
                    InclineGrade     = incline,
                    DegreesFromNorth = direction,
                    Model            = new DimensionalModel()
                    {
                        ModelTemplate     = origin.Model.ModelTemplate,
                        Composition       = origin.Model.Composition,
                        Height            = origin.Model.Height,
                        Length            = origin.Model.Length,
                        Width             = origin.Model.Width,
                        SurfaceCavitation = origin.Model.SurfaceCavitation,
                        Vacuity           = origin.Model.Vacuity
                    }
                };

                if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                {
                    message = "Error; Creation failed.";
                }
                else
                {
                    PathwayTemplate reversePath = new PathwayTemplate
                    {
                        Name             = newObj.Name,
                        DegreesFromNorth = Utilities.ReverseDirection(newObj.DegreesFromNorth),
                        Origin           = newObj.Destination,
                        Destination      = newObj.Origin,
                        Model            = newObj.Model,
                        InclineGrade     = newObj.InclineGrade * -1
                    };

                    if (reversePath.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                    {
                        message = "Reverse Path creation FAILED. Origin path creation SUCCESS.";
                    }

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

            return(message);
        }
Beispiel #21
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 }));
        }
Beispiel #22
0
        private static string RenderRoomToAscii(IRoomTemplate destination, bool hasZoneExits, bool hasLocaleExits, bool isCurrentLocation, bool forAdmin = false)
        {
            MovementDirectionType[] upPaths = new MovementDirectionType[] {
                MovementDirectionType.Up,
                MovementDirectionType.UpEast,
                MovementDirectionType.UpNorth,
                MovementDirectionType.UpNorthEast,
                MovementDirectionType.UpNorthWest,
                MovementDirectionType.UpSouth,
                MovementDirectionType.UpSouthEast,
                MovementDirectionType.UpSouthWest,
                MovementDirectionType.UpWest
            };

            MovementDirectionType[] downPaths = new MovementDirectionType[] {
                MovementDirectionType.Down,
                MovementDirectionType.DownEast,
                MovementDirectionType.DownNorth,
                MovementDirectionType.DownNorthEast,
                MovementDirectionType.DownNorthWest,
                MovementDirectionType.DownSouth,
                MovementDirectionType.DownSouthEast,
                MovementDirectionType.DownSouthWest,
                MovementDirectionType.DownWest
            };

            bool   hasUp      = destination.GetPathways().Any(path => upPaths.Contains(path.DirectionType));
            bool   hasDown    = destination.GetPathways().Any(path => downPaths.Contains(path.DirectionType));
            string extraClass = "";

            string character = "O";

            if (forAdmin)
            {
                if (hasZoneExits && hasLocaleExits)
                {
                    character = "$";
                }
                else if (hasZoneExits)
                {
                    character = "Z";
                }
                else if (hasLocaleExits)
                {
                    character = "L";
                }
            }
            else
            {
                if (isCurrentLocation)
                {
                    character  = "@";
                    extraClass = "isHere";
                }
                else if (hasUp)
                {
                    if (hasDown)
                    {
                        character = "X";
                    }
                    else
                    {
                        character = "A";
                    }
                }
                else if (hasDown)
                {
                    character = "V";
                }
            }

            if (forAdmin)
            {
                return(string.Format("<a href='#' class='editData AdminEditRoom' roomId='{0}' title='Edit - {2}'>{1}</a>", destination.Id, character, destination.Name));
            }
            else
            {
                return(string.Format("<a href='#' class='room nonAdminRoom {3}' title='{1}{2}'>{0}</a>", character, destination.Name, destination.Id, extraClass));
            }
        }
Beispiel #23
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 #24
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 #25
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"));
        }
Beispiel #26
0
        /// <summary>
        /// Finds the central room of a given map
        /// </summary>
        /// <param name="map">the map x,y,z</param>
        /// <param name="zIndex">If > -1 we're looking for the x,y center of the single plane as opposed to the actual x,y,z center of the whole map</param>
        /// <returns>the central room</returns>
        public static IRoomTemplate FindCenterOfMap(long[,,] map, int zIndex = -1)
        {
            int zCenter = zIndex;

            //If we want a specific z index thats fine, otherwise we find the middle Z
            if (zIndex == -1)
            {
                zCenter = (map.GetUpperBound(2) - map.GetLowerBound(2)) / 2 + map.GetLowerBound(2);
            }

            int xCenter = (map.GetUpperBound(0) - map.GetLowerBound(0)) / 2 + map.GetLowerBound(0);
            int yCenter = (map.GetUpperBound(1) - map.GetLowerBound(1)) / 2 + map.GetLowerBound(1);

            long roomId = map[xCenter, yCenter, zCenter];

            if (roomId < 0)
            {
                for (int variance = 1;
                     variance <= xCenter - map.GetLowerBound(0) && variance <= map.GetUpperBound(0) - xCenter &&
                     variance <= yCenter - map.GetLowerBound(1) && variance <= map.GetUpperBound(1) - yCenter
                     ; variance++)
                {
                    //Check around it
                    if (map[xCenter - variance, yCenter, zCenter] >= 0)
                    {
                        roomId = map[xCenter - variance, yCenter, zCenter];
                    }
                    else if (map[xCenter + variance, yCenter, zCenter] >= 0)
                    {
                        roomId = map[xCenter + variance, yCenter, zCenter];
                    }
                    else if (map[xCenter, yCenter - variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter, yCenter - variance, zCenter];
                    }
                    else if (map[xCenter, yCenter + variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter, yCenter + variance, zCenter];
                    }
                    else if (map[xCenter - variance, yCenter - variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter - variance, yCenter - variance, zCenter];
                    }
                    else if (map[xCenter - variance, yCenter + variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter - variance, yCenter + variance, zCenter];
                    }
                    else if (map[xCenter + variance, yCenter - variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter + variance, yCenter - variance, zCenter];
                    }
                    else if (map[xCenter + variance, yCenter + variance, zCenter] >= 0)
                    {
                        roomId = map[xCenter + variance, yCenter + variance, zCenter];
                    }

                    if (roomId >= 0)
                    {
                        break;
                    }
                }
            }

            //Well, no valid rooms on this Z so try another Z unless all we got was this one Z
            if (roomId < 0 && zIndex == -1)
            {
                IRoomTemplate returnRoom = null;

                for (int variance = 1;
                     variance < zCenter - map.GetLowerBound(2) && variance < map.GetUpperBound(2) - zCenter
                     ; variance++)
                {
                    returnRoom = FindCenterOfMap(map, zCenter - variance);

                    if (returnRoom != null)
                    {
                        break;
                    }

                    returnRoom = FindCenterOfMap(map, zCenter + variance);

                    if (returnRoom != null)
                    {
                        break;
                    }
                }

                return(returnRoom);
            }

            return(TemplateCache.Get <IRoomTemplate>(roomId));
        }