public static double GetBaseInclineGrade(MovementDirectionType direction) { switch (direction) { case MovementDirectionType.Up: return(1); case MovementDirectionType.Down: return(-1); case MovementDirectionType.UpEast: case MovementDirectionType.UpNorth: case MovementDirectionType.UpNorthEast: case MovementDirectionType.UpNorthWest: case MovementDirectionType.UpSouth: case MovementDirectionType.UpSouthEast: case MovementDirectionType.UpSouthWest: case MovementDirectionType.UpWest: return(0.5); case MovementDirectionType.DownEast: case MovementDirectionType.DownNorth: case MovementDirectionType.DownNorthEast: case MovementDirectionType.DownNorthWest: case MovementDirectionType.DownSouth: case MovementDirectionType.DownSouthEast: case MovementDirectionType.DownSouthWest: case MovementDirectionType.DownWest: return(-0.5); } return(0); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { var bS = (IPathwayData)DataTemplate; var locationAssembly = Assembly.GetAssembly(typeof(Room)); MovementDirection = MessagingUtility.TranslateDegreesToDirection(bS.DegreesFromNorth); BirthMark = Birthmarker.GetBirthmark(bS); Keywords = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() }; Birthdate = DateTime.Now; //paths need two locations ILocation fromLocation = null; var fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType)); if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID)) { if (fromLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton))) { long fromLocationID = long.Parse(bS.FromLocationID); fromLocation = LiveCache.Get <ILocation>(fromLocationID, fromLocationType); } else { var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID); fromLocation = LiveCache.Get <ILocation>(cacheKey); } } ILocation toLocation = null; var toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType)); if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID)) { if (toLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton))) { long toLocationID = long.Parse(bS.ToLocationID); toLocation = LiveCache.Get <ILocation>(toLocationID, toLocationType); } else { var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID); toLocation = LiveCache.Get <ILocation>(cacheKey); } } FromLocation = fromLocation; ToLocation = toLocation; CurrentLocation = fromLocation; Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination }); Enter.ToSurrounding.Add(bS.VisibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.VisibleToSurroundings })); Enter.ToSurrounding.Add(bS.AudibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.AudibleToSurroundings })); fromLocation.MoveInto <IPathway>(this); }
/// <summary> /// Gets a room in a direction if there is one based on the world map the room belongs to /// </summary> /// <param name="origin">The room we're starting in</param> /// <param name="direction">The direction we're moving in</param> /// <returns>null or a RoomTemplate</returns> public static ILocationData GetLocationInDirection(ILocationData origin, MovementDirectionType direction) { //We can't find none directions on a map if (origin == null || direction == MovementDirectionType.None) { return(null); } IEnumerable <IPathwayTemplate> paths = origin.GetPathways(); IPathwayTemplate dirPath = paths.FirstOrDefault(path => path.DirectionType == direction); if (dirPath != null) { return(dirPath.Destination); } return(null); }
//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); }
/// <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); }
/// <summary> /// Tries to find this entity in the world based on its ID or gets a new one from the db and puts it in the world /// </summary> public void GetFromWorldOrSpawn() { //Try to see if they are already there var me = LiveCache.Get <Pathway>(DataTemplate.ID); //Isn't in the world currently if (me == default(IPathway)) { SpawnNewInWorld(); } else { BirthMark = me.BirthMark; Keywords = me.Keywords; Birthdate = me.Birthdate; CurrentLocation = me.CurrentLocation; DataTemplate = me.DataTemplate; FromLocation = me.FromLocation; ToLocation = me.ToLocation; Enter = me.Enter; MovementDirection = me.MovementDirection; } }
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)); } }
private static string RenderPathwayToAsciiForModals(IPathwayTemplate path, long originId, MovementDirectionType directionType, bool forAdmin = false) { string returnValue = string.Empty; string asciiCharacter = Utilities.TranslateDirectionToAsciiCharacter(directionType); long destinationId = -1; string destinationName = string.Empty; PathwayType pathType = PathwayType.None; if (path != null && path.Destination != null) { destinationName = path.Destination.Name; destinationId = path.Destination.Id; pathType = path.Type; } if (forAdmin) { if (path != null) { if (pathType == PathwayType.Rooms) { returnValue = string.Format("<a href='#' class='editData pathway AdminEditPathway' pathwayId='{0}' fromRoom='{3}' toRoom='{4}' title='Edit - {5} path to {1}' data-id='{0}'>{2}</a>", path.Id, destinationName, asciiCharacter, originId, destinationId, directionType.ToString()); } else { string classString = "zone"; if (pathType == PathwayType.Locale) { classString = "locale"; } returnValue = string.Format("<a class='pathway {4}' title='{5}: {3} to {1}' data-id='{0}'>{2}</a>", path.Id, destinationName, asciiCharacter, directionType.ToString(), classString, path.Name); } } else { string roomString = string.Format("Add - {0} path and room", directionType.ToString()); if (!string.IsNullOrWhiteSpace(destinationName)) { roomString = string.Format("Add {0} path to {1}", directionType.ToString(), destinationName); } returnValue = string.Format("<a href='#' class='addData pathway AdminAddPathway' pathwayId='-1' fromRoom='{0}' toRoom='{4}' data-direction='{1}' data-incline='{2}' title='{3}'>+</a>", originId, Utilities.TranslateDirectionToDegrees(directionType).Item1, Utilities.GetBaseInclineGrade(directionType), roomString, destinationId); } } else if (path != null) { if (pathType == PathwayType.Rooms) { returnValue = string.Format("<a href='#' class='pathway nonAdminPathway' title='{3}: {1}{4} to {2}{5}' data-id='{6}'>{0}</a>", asciiCharacter, directionType, destinationName, path.Name, originId, destinationId, path.Id); } else { string classString = "zone"; if (pathType == PathwayType.Locale) { classString = "locale"; } returnValue = string.Format("<a class='pathway {4}' title='{5}: {3} to {1}' data-id='{0}'>{2}</a>", path.Id, destinationName, asciiCharacter, directionType.ToString(), classString, path.Name); } } return(returnValue); }
/// <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 IRoomData GetOpposingRoom(IRoomData origin, MovementDirectionType direction) { //There is no opposite of none directionals if (origin == null || direction == MovementDirectionType.None) return null; var oppositeDirection = ReverseDirection(direction); var paths = BackingDataCache.GetAll<IPathwayData>(); var ourPath = paths.FirstOrDefault(pt => pt.ToLocationType == "Room" && origin.ID.Equals(int.Parse(pt.ToLocationID)) && pt.DirectionType == oppositeDirection); if(ourPath != null) return BackingDataCache.Get<IRoomData>(long.Parse(ourPath.ToLocationID)); return null; }
/// <summary> /// X, Y, Z /// </summary> /// <param name="transversalDirection">The direction being faced</param> /// <returns>the coordinates for the direction needed to move one unit "forward"</returns> public static Tuple<int, int, int> GetDirectionStep(MovementDirectionType transversalDirection) { switch (transversalDirection) { default: //We already defaulted to 0,0,0 break; case MovementDirectionType.East: return new Tuple<int, int, int>(1, 0, 0); case MovementDirectionType.North: return new Tuple<int, int, int>(0, 1, 0); case MovementDirectionType.NorthEast: return new Tuple<int, int, int>(1, 1, 0); case MovementDirectionType.NorthWest: return new Tuple<int, int, int>(-1, 1, 0); case MovementDirectionType.South: return new Tuple<int, int, int>(0, -1, 0); case MovementDirectionType.SouthEast: return new Tuple<int, int, int>(1, -1, 0); case MovementDirectionType.SouthWest: return new Tuple<int, int, int>(-1, -1, 0); case MovementDirectionType.West: return new Tuple<int, int, int>(-1, 0, 0); case MovementDirectionType.Up: return new Tuple<int, int, int>(0, 0, 1); case MovementDirectionType.Down: return new Tuple<int, int, int>(0, 0, -1); case MovementDirectionType.UpEast: return new Tuple<int, int, int>(1, 0, 1); case MovementDirectionType.UpNorth: return new Tuple<int, int, int>(0, 1, 1); case MovementDirectionType.UpNorthEast: return new Tuple<int, int, int>(1, 1, 1); case MovementDirectionType.UpNorthWest: return new Tuple<int, int, int>(-1, 1, 1); case MovementDirectionType.UpSouth: return new Tuple<int, int, int>(0, -1, 1); case MovementDirectionType.UpSouthEast: return new Tuple<int, int, int>(1, -1, 1); case MovementDirectionType.UpSouthWest: return new Tuple<int, int, int>(-1, -1, 1); case MovementDirectionType.UpWest: return new Tuple<int, int, int>(-1, 0, 1); case MovementDirectionType.DownEast: return new Tuple<int, int, int>(1, 0, -1); case MovementDirectionType.DownNorth: return new Tuple<int, int, int>(0, 1, -1); case MovementDirectionType.DownNorthEast: return new Tuple<int, int, int>(1, 1, -1); case MovementDirectionType.DownNorthWest: return new Tuple<int, int, int>(-1, 1, -1); case MovementDirectionType.DownSouth: return new Tuple<int, int, int>(0, -1, -1); case MovementDirectionType.DownSouthEast: return new Tuple<int, int, int>(1, -1, -1); case MovementDirectionType.DownSouthWest: return new Tuple<int, int, int>(-1, -1, -1); case MovementDirectionType.DownWest: return new Tuple<int, int, int>(-1, 0, -1); } return new Tuple<int, int, int>(0, 0, 0); }
public void DoTheThing(Motivator motivator) { Accomplisher action = Hypothalamus.HowToDo(motivator); bool wander = false; switch (action) { case Accomplisher.Drink: IInanimate waterBottle = Inventory.EntitiesContained().FirstOrDefault(ent => ent.GetQuality("Water") > 0); if (waterBottle != null) { waterBottle.SetQuality(-1, "Water", true); Hypothalamus.ApplyPressure(Motivator.Thirst, -10); Exhaust(-10); } else { wander = true; } break; case Accomplisher.Eat: IInanimate food = Inventory.EntitiesContained().FirstOrDefault(ent => ent.GetQuality("Food") > 0); if (food != null) { //TODO: turn this into an eat command int foodValue = food.GetQuality("Food"); food.Remove(); Hypothalamus.ApplyPressure(Motivator.Hunger, -1 * foodValue); Harm(-1 * foodValue); } else { wander = true; } break; case Accomplisher.Sleep: //Can't sleep yet break; case Accomplisher.Speak: if (CurrentLocation.CurrentZone != null) { CurrentLocation.CurrentZone.BroadcastEvent("$A$ moos.", this); } break; case Accomplisher.Wander: wander = true; break; } if (wander) { Random rand = new Random(); MovementDirectionType direction = (MovementDirectionType)rand.Next(0, 7); //Run the command like anyone else //Interpret.Render(direction.ToString(), this); } }
/// <summary> /// X, Y, Z /// </summary> /// <param name="transversalDirection">The direction being faced</param> /// <returns>the coordinates for the direction needed to move one unit "forward"</returns> public static Tuple <int, int, int> GetDirectionStep(MovementDirectionType transversalDirection) { switch (transversalDirection) { default: //We already defaulted to 0,0,0 break; case MovementDirectionType.East: return(new Tuple <int, int, int>(1, 0, 0)); case MovementDirectionType.North: return(new Tuple <int, int, int>(0, 1, 0)); case MovementDirectionType.NorthEast: return(new Tuple <int, int, int>(1, 1, 0)); case MovementDirectionType.NorthWest: return(new Tuple <int, int, int>(-1, 1, 0)); case MovementDirectionType.South: return(new Tuple <int, int, int>(0, -1, 0)); case MovementDirectionType.SouthEast: return(new Tuple <int, int, int>(1, -1, 0)); case MovementDirectionType.SouthWest: return(new Tuple <int, int, int>(-1, -1, 0)); case MovementDirectionType.West: return(new Tuple <int, int, int>(-1, 0, 0)); case MovementDirectionType.Up: return(new Tuple <int, int, int>(0, 0, 1)); case MovementDirectionType.Down: return(new Tuple <int, int, int>(0, 0, -1)); case MovementDirectionType.UpEast: return(new Tuple <int, int, int>(1, 0, 1)); case MovementDirectionType.UpNorth: return(new Tuple <int, int, int>(0, 1, 1)); case MovementDirectionType.UpNorthEast: return(new Tuple <int, int, int>(1, 1, 1)); case MovementDirectionType.UpNorthWest: return(new Tuple <int, int, int>(-1, 1, 1)); case MovementDirectionType.UpSouth: return(new Tuple <int, int, int>(0, -1, 1)); case MovementDirectionType.UpSouthEast: return(new Tuple <int, int, int>(1, -1, 1)); case MovementDirectionType.UpSouthWest: return(new Tuple <int, int, int>(-1, -1, 1)); case MovementDirectionType.UpWest: return(new Tuple <int, int, int>(-1, 0, 1)); case MovementDirectionType.DownEast: return(new Tuple <int, int, int>(1, 0, -1)); case MovementDirectionType.DownNorth: return(new Tuple <int, int, int>(0, 1, -1)); case MovementDirectionType.DownNorthEast: return(new Tuple <int, int, int>(1, 1, -1)); case MovementDirectionType.DownNorthWest: return(new Tuple <int, int, int>(-1, 1, -1)); case MovementDirectionType.DownSouth: return(new Tuple <int, int, int>(0, -1, -1)); case MovementDirectionType.DownSouthEast: return(new Tuple <int, int, int>(1, -1, -1)); case MovementDirectionType.DownSouthWest: return(new Tuple <int, int, int>(-1, -1, -1)); case MovementDirectionType.DownWest: return(new Tuple <int, int, int>(-1, 0, -1)); } return(new Tuple <int, int, int>(0, 0, 0)); }
/// <summary> /// Translates hard directions to ascii characters. UP inclines are always brackets open to the left, DOWN is always bracket open to the right /// </summary> /// <param name="direction">the hard direction to turn into a character</param> /// <returns>a single ascii character in a string</returns> public static string TranslateDirectionToAsciiCharacter(MovementDirectionType direction) { switch (direction) { default: return("#"); case MovementDirectionType.West: case MovementDirectionType.East: return("-"); case MovementDirectionType.South: case MovementDirectionType.North: return("|"); case MovementDirectionType.SouthWest: case MovementDirectionType.NorthEast: return("/"); case MovementDirectionType.SouthEast: case MovementDirectionType.NorthWest: return(@"\"); case MovementDirectionType.Up: return("^"); case MovementDirectionType.UpEast: case MovementDirectionType.UpWest: return("3"); case MovementDirectionType.UpSouth: case MovementDirectionType.UpNorth: return("}"); case MovementDirectionType.UpSouthWest: case MovementDirectionType.UpNorthEast: return(">"); case MovementDirectionType.UpSouthEast: case MovementDirectionType.UpNorthWest: return("]"); case MovementDirectionType.Down: return("v"); case MovementDirectionType.DownEast: case MovementDirectionType.DownWest: return("E"); case MovementDirectionType.DownSouth: case MovementDirectionType.DownNorth: return("{"); case MovementDirectionType.DownSouthWest: case MovementDirectionType.DownNorthEast: return("<"); case MovementDirectionType.DownSouthEast: case MovementDirectionType.DownNorthWest: return("["); } }
public static MovementDirectionType ReverseDirection(MovementDirectionType direction) { switch (direction) { case MovementDirectionType.East: return(MovementDirectionType.West); case MovementDirectionType.North: return(MovementDirectionType.South); case MovementDirectionType.NorthEast: return(MovementDirectionType.SouthWest); case MovementDirectionType.NorthWest: return(MovementDirectionType.SouthEast); case MovementDirectionType.South: return(MovementDirectionType.North); case MovementDirectionType.SouthEast: return(MovementDirectionType.NorthWest); case MovementDirectionType.SouthWest: return(MovementDirectionType.NorthEast); case MovementDirectionType.West: return(MovementDirectionType.East); case MovementDirectionType.Up: return(MovementDirectionType.Down); case MovementDirectionType.Down: return(MovementDirectionType.Up); case MovementDirectionType.UpEast: return(MovementDirectionType.DownWest); case MovementDirectionType.UpNorth: return(MovementDirectionType.DownSouth); case MovementDirectionType.UpNorthEast: return(MovementDirectionType.DownSouthWest); case MovementDirectionType.UpNorthWest: return(MovementDirectionType.DownSouthEast); case MovementDirectionType.UpSouth: return(MovementDirectionType.DownNorth); case MovementDirectionType.UpSouthEast: return(MovementDirectionType.DownNorthWest); case MovementDirectionType.UpSouthWest: return(MovementDirectionType.DownNorthEast); case MovementDirectionType.UpWest: return(MovementDirectionType.DownEast); case MovementDirectionType.DownEast: return(MovementDirectionType.UpWest); case MovementDirectionType.DownNorth: return(MovementDirectionType.UpSouth); case MovementDirectionType.DownNorthEast: return(MovementDirectionType.UpSouthWest); case MovementDirectionType.DownNorthWest: return(MovementDirectionType.UpSouthEast); case MovementDirectionType.DownSouth: return(MovementDirectionType.UpNorth); case MovementDirectionType.DownSouthEast: return(MovementDirectionType.UpNorthWest); case MovementDirectionType.DownSouthWest: return(MovementDirectionType.UpNorthEast); case MovementDirectionType.DownWest: return(MovementDirectionType.UpEast); } //return none, neutral for anything not counted return(MovementDirectionType.None); }
/// <summary> /// Translates direction words into degreesFromNorth and inclineGrade for pathways, returns the absolute default value /// </summary> /// <param name="direction">the value to translate</param> /// <returns>degrees from north, incline grade</returns> public static Tuple <int, int> TranslateDirectionToDegrees(MovementDirectionType direction) { switch (direction) { case MovementDirectionType.East: return(new Tuple <int, int>(90, 0)); case MovementDirectionType.North: return(new Tuple <int, int>(0, 0)); case MovementDirectionType.NorthEast: return(new Tuple <int, int>(45, 0)); case MovementDirectionType.NorthWest: return(new Tuple <int, int>(315, 0)); case MovementDirectionType.South: return(new Tuple <int, int>(180, 0)); case MovementDirectionType.SouthEast: return(new Tuple <int, int>(135, 0)); case MovementDirectionType.SouthWest: return(new Tuple <int, int>(225, 0)); case MovementDirectionType.West: return(new Tuple <int, int>(270, 0)); case MovementDirectionType.Up: return(new Tuple <int, int>(-1, 25)); case MovementDirectionType.Down: return(new Tuple <int, int>(-1, -25)); case MovementDirectionType.UpEast: return(new Tuple <int, int>(90, 23)); case MovementDirectionType.UpNorth: return(new Tuple <int, int>(0, 25)); case MovementDirectionType.UpNorthEast: return(new Tuple <int, int>(45, 25)); case MovementDirectionType.UpNorthWest: return(new Tuple <int, int>(315, 25)); case MovementDirectionType.UpSouth: return(new Tuple <int, int>(180, 25)); case MovementDirectionType.UpSouthEast: return(new Tuple <int, int>(135, 25)); case MovementDirectionType.UpSouthWest: return(new Tuple <int, int>(225, 25)); case MovementDirectionType.UpWest: return(new Tuple <int, int>(270, 25)); case MovementDirectionType.DownEast: return(new Tuple <int, int>(90, -25)); case MovementDirectionType.DownNorth: return(new Tuple <int, int>(0, -25)); case MovementDirectionType.DownNorthEast: return(new Tuple <int, int>(45, -25)); case MovementDirectionType.DownNorthWest: return(new Tuple <int, int>(315, -25)); case MovementDirectionType.DownSouth: return(new Tuple <int, int>(180, -25)); case MovementDirectionType.DownSouthEast: return(new Tuple <int, int>(135, -25)); case MovementDirectionType.DownSouthWest: return(new Tuple <int, int>(225, -25)); case MovementDirectionType.DownWest: return(new Tuple <int, int>(270, -25)); } //return none, neutral for anything not counted return(new Tuple <int, int>(-1, 0)); }
public static MovementDirectionType ReverseDirection(MovementDirectionType direction) { switch (direction) { case MovementDirectionType.East: return MovementDirectionType.West; case MovementDirectionType.North: return MovementDirectionType.South; case MovementDirectionType.NorthEast: return MovementDirectionType.SouthWest; case MovementDirectionType.NorthWest: return MovementDirectionType.SouthEast; case MovementDirectionType.South: return MovementDirectionType.North; case MovementDirectionType.SouthEast: return MovementDirectionType.NorthWest; case MovementDirectionType.SouthWest: return MovementDirectionType.NorthEast; case MovementDirectionType.West: return MovementDirectionType.East; case MovementDirectionType.Up: return MovementDirectionType.Down; case MovementDirectionType.Down: return MovementDirectionType.Up; case MovementDirectionType.UpEast: return MovementDirectionType.DownWest; case MovementDirectionType.UpNorth: return MovementDirectionType.DownSouth; case MovementDirectionType.UpNorthEast: return MovementDirectionType.DownSouthWest; case MovementDirectionType.UpNorthWest: return MovementDirectionType.DownSouthEast; case MovementDirectionType.UpSouth: return MovementDirectionType.DownNorth; case MovementDirectionType.UpSouthEast: return MovementDirectionType.DownNorthWest; case MovementDirectionType.UpSouthWest: return MovementDirectionType.DownNorthEast; case MovementDirectionType.UpWest: return MovementDirectionType.DownEast; case MovementDirectionType.DownEast: return MovementDirectionType.UpWest; case MovementDirectionType.DownNorth: return MovementDirectionType.UpSouth; case MovementDirectionType.DownNorthEast: return MovementDirectionType.UpSouthWest; case MovementDirectionType.DownNorthWest: return MovementDirectionType.UpSouthEast; case MovementDirectionType.DownSouth: return MovementDirectionType.UpNorth; case MovementDirectionType.DownSouthEast: return MovementDirectionType.UpNorthWest; case MovementDirectionType.DownSouthWest: return MovementDirectionType.UpNorthEast; case MovementDirectionType.DownWest: return MovementDirectionType.UpEast; } //return none, neutral for anything not counted return MovementDirectionType.None; }
/// <summary> /// Translates hard directions to ascii characters. UP inclines are always brackets open to the left, DOWN is always bracket open to the right /// </summary> /// <param name="direction">the hard direction to turn into a character</param> /// <returns>a single ascii character in a string</returns> public static string TranslateDirectionToAsciiCharacter(MovementDirectionType direction) { switch (direction) { default: return "#"; case MovementDirectionType.West: case MovementDirectionType.East: return "-"; case MovementDirectionType.South: case MovementDirectionType.North: return "|"; case MovementDirectionType.SouthWest: case MovementDirectionType.NorthEast: return "/"; case MovementDirectionType.SouthEast: case MovementDirectionType.NorthWest: return @"\"; case MovementDirectionType.Up: return "^"; case MovementDirectionType.UpEast: case MovementDirectionType.UpWest: return "3"; case MovementDirectionType.UpSouth: case MovementDirectionType.UpNorth: return "}"; case MovementDirectionType.UpSouthWest: case MovementDirectionType.UpNorthEast: return ">"; case MovementDirectionType.UpSouthEast: case MovementDirectionType.UpNorthWest: return "]"; case MovementDirectionType.Down: return "v"; case MovementDirectionType.DownEast: case MovementDirectionType.DownWest: return "E"; case MovementDirectionType.DownSouth: case MovementDirectionType.DownNorth: return "{"; case MovementDirectionType.DownSouthWest: case MovementDirectionType.DownNorthEast: return "<"; case MovementDirectionType.DownSouthEast: case MovementDirectionType.DownNorthWest: return "["; } }
/// <summary> /// Gets a room in a direction if there is one based on the world map the room belongs to /// </summary> /// <param name="origin">The room we're starting in</param> /// <param name="direction">The direction we're moving in</param> /// <returns>null or a RoomData</returns> public static IRoomData GetRoomInDirection(IRoomData origin, MovementDirectionType direction) { //We can't find none directions on a map if (origin == null || direction == MovementDirectionType.None) return null; var worldMap = origin.ZoneAffiliation.World.WorldMap.CoordinatePlane; var steps = Utilities.GetDirectionStep(direction); var newX = origin.Coordinates.Item1 + steps.Item1; var newY = origin.Coordinates.Item2 + steps.Item2; var newZ = origin.Coordinates.Item3 + steps.Item3; //out of bounds if (Utilities.IsOutOfBounds(new Tuple<int,int,int>(newX, newY, newZ), worldMap)) return null; if (worldMap[newX, newY, newZ] > -1) return BackingDataCache.Get<IRoomData>(worldMap[newX, newY, newZ]); return null; }
/// <summary> /// Translates direction words into degreesFromNorth and inclineGrade for pathways, returns the absolute default value /// </summary> /// <param name="direction">the value to translate</param> /// <returns>degrees from north, incline grade</returns> public static Tuple<int, int> TranslateDirectionToDegrees(MovementDirectionType direction) { switch (direction) { case MovementDirectionType.East: return new Tuple<int, int>(90, 0); case MovementDirectionType.North: return new Tuple<int, int>(0, 0); case MovementDirectionType.NorthEast: return new Tuple<int, int>(45, 0); case MovementDirectionType.NorthWest: return new Tuple<int, int>(315, 0); case MovementDirectionType.South: return new Tuple<int, int>(180, 0); case MovementDirectionType.SouthEast: return new Tuple<int, int>(135, 0); case MovementDirectionType.SouthWest: return new Tuple<int, int>(225, 0); case MovementDirectionType.West: return new Tuple<int, int>(270, 0); case MovementDirectionType.Up: return new Tuple<int, int>(-1, 25); case MovementDirectionType.Down: return new Tuple<int, int>(-1, -25); case MovementDirectionType.UpEast: return new Tuple<int, int>(90, 23); case MovementDirectionType.UpNorth: return new Tuple<int, int>(0, 25); case MovementDirectionType.UpNorthEast: return new Tuple<int, int>(45, 25); case MovementDirectionType.UpNorthWest: return new Tuple<int, int>(315, 25); case MovementDirectionType.UpSouth: return new Tuple<int, int>(180, 25); case MovementDirectionType.UpSouthEast: return new Tuple<int, int>(135, 25); case MovementDirectionType.UpSouthWest: return new Tuple<int, int>(225, 25); case MovementDirectionType.UpWest: return new Tuple<int, int>(270, 25); case MovementDirectionType.DownEast: return new Tuple<int, int>(90, -25); case MovementDirectionType.DownNorth: return new Tuple<int, int>(0, -25); case MovementDirectionType.DownNorthEast: return new Tuple<int, int>(45, -25); case MovementDirectionType.DownNorthWest: return new Tuple<int, int>(315, -25); case MovementDirectionType.DownSouth: return new Tuple<int, int>(180, -25); case MovementDirectionType.DownSouthEast: return new Tuple<int, int>(135, -25); case MovementDirectionType.DownSouthWest: return new Tuple<int, int>(225, -25); case MovementDirectionType.DownWest: return new Tuple<int, int>(270, -25); } //return none, neutral for anything not counted return new Tuple<int, int>(-1, 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, IRoomData origin, int diameter, int centerX, int centerY, int centerZ, HashSet<IRoomData> roomPool) { var pathways = origin.GetPathways(true); var directionalSteps = Utilities.GetDirectionStep(transversalDirection); var xStepped = centerX + directionalSteps.Item1; var yStepped = centerY + directionalSteps.Item2; var 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 < diameter && xStepped > 0 && yStepped > 0 && yStepped < diameter && zStepped > 0 && zStepped < diameter && dataMap[xStepped - 1, yStepped - 1, zStepped - 1] <= 0) { var thisPath = pathways.FirstOrDefault(path => (path.DirectionType == transversalDirection && path.FromLocationID.Equals(origin.ID.ToString())) || (path.DirectionType == Utilities.ReverseDirection(transversalDirection) && path.ToLocationID.Equals(origin.ID.ToString())) ); if (thisPath != null) { var locId = long.Parse(thisPath.ToLocationID); if (thisPath.ToLocationID.Equals(origin.ID.ToString())) locId = long.Parse(thisPath.FromLocationID); var passdownOrigin = BackingDataCache.Get<IRoomData>(locId); if (passdownOrigin != null) { dataMap[xStepped - 1, yStepped - 1, zStepped - 1] = passdownOrigin.ID; dataMap = AddFullRoomToMap(dataMap, passdownOrigin, diameter, xStepped, yStepped, zStepped, roomPool); } } } return dataMap; }
public bool TryMoveDirection(MovementDirectionType direction, IGlobalPosition newPosition) { return(true); }
private static string RenderPathwayToAsciiForModals(IPathwayData path, long originId, MovementDirectionType directionType, IRoomData destination, bool forAdmin = false) { var returnValue = String.Empty; var asciiCharacter = Utilities.TranslateDirectionToAsciiCharacter(directionType); if (!forAdmin) return " "; if (path != null) destination = BackingDataCache.Get<IRoomData>(int.Parse(path.ToLocationID)); long destinationId = -1; var destinationName = String.Empty; if (destination != null) { destinationName = destination.Name; destinationId = destination.ID; } if (path != null) { returnValue = String.Format("<a href='#' class='editData pathway AdminEditPathway' pathwayId='{0}' fromRoom='{3}' toRoom='{4}' title='Edit - {5} path to {1}' data-id='{0}'>{2}</a>", path.ID, destinationName, asciiCharacter, originId, destinationId, directionType.ToString()); } else { var roomString = String.Format("Add - {0} path and room", directionType.ToString()); if (!string.IsNullOrWhiteSpace(destinationName)) roomString = String.Format("Add {0} path to {1}", directionType.ToString(), destinationName); returnValue = String.Format("<a href='#' class='addData pathway AdminAddPathway' pathwayId='-1' fromRoom='{0}' toRoom='{3}' data-direction='{1}' title='{2}'>+</a>", originId, Utilities.TranslateDirectionToDegrees(directionType), roomString, destinationId); } return returnValue; }