internal static List <GameLocation> adjustInboundWarps(GameLocation location, GameLocation toLocation = null) { if (location == null) { return(new List <GameLocation>()); } List <GameLocation> locations = new List <GameLocation>(); foreach (Warp warp in location.warps) { Point move = Point.Zero; if (warp.X >= location.map.DisplayWidth / Game1.tileSize) { move.X++; } else if (warp.X <= 0) { move.X--; } else if (warp.Y >= location.map.DisplayHeight / Game1.tileSize) { move.Y++; } else { move.Y--; } var target = Game1.getLocationFromName(warp.TargetName); if (target == null) { continue; } if (toLocation == null || target == toLocation) { locations.AddOrReplace(target); Warp inbound = target.warps.Where(w => w.TargetName == location.Name).OrderBy(w => LuaUtils.getDistance(new Vector2(w.X + move.X, w.Y + move.Y), new Vector2(warp.TargetX, warp.TargetY))).First(); if (inbound != null && !(inbound.X == 0 && inbound.Y == 0)) { warp.TargetX = inbound.X + move.X; warp.TargetY = inbound.Y + move.Y; } } } Monitor.Log("Adjusted Warps: " + location.Name, LogLevel.Trace); return(locations); }