public void TravelerMarksNodesAsUnWalkableWhenStuck() { const string unused = @" ------------------- | e | | ? | ------------------- | x | x | | ------------------- | s | | ? | ------------------- "; // setup the world var zoneMap = ZoneMap.TinyMap(); var zone = new Zone("test") { Map = zoneMap }; var world = new World(); world.Zones.Add(zone); var walker = new Walker(new Vector3(-1, 0, -1)); // Create the map the blind traveler will move against var knownGrid = ZoneMap.TinyMap(); knownGrid.AddUnWalkableNode(Vector3.Zero); knownGrid.AddUnWalkableNode(new Vector3(-1, 0, 0)); var revealedZone = new Zone("test"); revealedZone.Map = knownGrid; walker.RevealedZone = revealedZone; var traveler = new Traveler("test", world, walker); var stubPersister = new StubPersister(); var actor = new KnownNodeActor(stubPersister, traveler.CurrentZone.Map); var watcher = new Watcher(traveler, actor); // For this to work in the FFXI Finite State Machine this currently needs to exit // Frequently to allow for mobs and other stuff to get targeted. Should customize this behavior // To either break on events in the FSM or allow for extension to choose whether to exit under // certain conditions or not. for (int i = 0; i < 10; i++) { traveler.PathfindAndWalkToFarAwayWorldMapPosition(new Vector3(-1, 0, 1)); } var want = new Vector3(-1, 0, 1); var got = traveler.Position; Assert.Equal(want, got); Assert.Equal(2, traveler.CurrentZone.Map.UnknownNodes.Count); // Assert.Equal(traveler.PositionHistory); // Assert.Equal(want, got); }
public static ZoneMap SetupSmallGrid() { var grid = ZoneMap.NewGridFromVector2(new Vector2(3f, 3f)); grid.MapName = _smallGridZoneName; return(grid); }
public static void BuildMap(ZoneMap map) { for (int x = 0; x < map.MapWidth; x++) { var result = string.Empty; for (int y = 0; y < map.MapHeight; y++) { var tile = map.GetTile(x, y); if (tile == null) { result += "[ ]"; } else { if (tile.OccupyingUnit == Player.Instance.CurrentGladiator) { //change color here somehow result += "[*]"; } else { result += $"[{tile.OccupyingUnit.Name[0]}]"; } } } Text.WriteLine(ConsoleSide.Left, x, result); } }
public static void AssertPointNotWalkable(ZoneMap zoneMap, Vector3 position) { var node = zoneMap.GetNodeFromWorldPoint(position); Assert.Equal(node.WorldPosition, position); Assert.Equal(node.Walkable, false); }
public static Zone ZoneA() { const string want = @" ------------------- | | | | ------------------- | | | C | ------------------- | | B | | ------------------- "; var zone = new Zone("tests"); zone.Map = ZoneMap.TinyMap(); zone.Name = "A"; zone.Boundaries = new List <ZoneBoundary> { new ZoneBoundary { FromZone = "A", FromPosition = new Vector3(0, 0, -1), ToZone = "B", ToPosition = new Vector3(0, 0, 1) }, new ZoneBoundary { FromZone = "A", FromPosition = new Vector3(1, 0, 0), ToZone = "C", ToPosition = new Vector3(-1, 0, 0) } }; return(zone); }
public static void AssertGridEqual(ZoneMap want, ZoneMap got) { Assert.Equal(want.GridCenter, got.GridCenter); Assert.Equal(want.GridWorldSize, got.GridWorldSize); Assert.Equal(want.MaxSize, got.MaxSize); Assert.Equal(want.MapName, got.MapName); AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestBadArguments() { var zones = new IZone[] { null, null, null, null, null, null, null, null, null }; var mapping = new int[] { 3, 2, 1, 3, 2, 1, 3, 2, 1 }; ExpectNullArgumentException(() => { ZoneMap.CreateZoneMap(null, null); }); ExpectNullArgumentException(() => { ZoneMap.CreateZoneMap(zones, null); }); ExpectNullArgumentException(() => { ZoneMap.CreateZoneMap(null, mapping); }); }
public Continent(int id, int mapId, RectangleF bounds, string name, string dataName, Zone[] zones, ZoneMap zoneMap) { Id = id; MapId = mapId; Name = name; Bounds = bounds; DataName = dataName; Zones = new ReadOnlyCollection <Zone>(zones); ZoneMap = zoneMap; }
public void CreateGridCanGenerateGridFromCorner() { var want = new Node[1, 1]; want[0, 0] = new Node(Vector3.Zero); var zoneMap = ZoneMap.NewGridFromVector2(Vector2.One); var got = zoneMap.MapGrid; Assert.Equal(want.Length, got.Length); SetupZoneMap.AssertGridMapEqual(want, got); }
public void GetNeighboursCanGetNeighborsFromEdgeNode() { //Arrange var want = SetupZoneMap.GetNeighborsListForEdgeNode(); //Act var grid = ZoneMap.NewGridFromVector2(new Vector2(3f, 3f)); var got = grid.GetNeighbours(grid.MapGrid[2, 2]); //Assert SetupZoneMap.AssertListGridNodesEqual(want, got); }
public void CanCreateGridWithMultipleNodes() { // Arrange var want = SetupZoneMap.SetupThreeByThreeGrid(); // Act var grid = ZoneMap.NewGridFromVector2(new Vector2(3f, 3f)); var got = grid.MapGrid; // Assert Assert.Equal(want.Length, got.Length); SetupZoneMap.AssertGridMapEqual(want, got); }
private ZoneMap LoadZoneMap(string filename) { MpqFile file = wowFileSystem.FindFile(filename); Stream stream = null; ZoneMap zoneMap; if (file == null) { return(null); } try { stream = file.Open(); zoneMap = new ZoneMap(stream); stream.Close(); #if DEBUG if (zoneMap != null) { Bitmap b = new Bitmap(128, 128); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { b.SetPixel(i, j, Color.FromArgb(zoneMap[i, j] | ~0xFFFFFF)); } } b.Save(Path.GetFileNameWithoutExtension(filename) + ".bmp"); } #endif return(zoneMap); } catch { if (stream != null) { stream.Close(); } return(null); } }
public static IEnumerable <ZoneMap> GetLocal() { string[] maps = { }; try { maps = Directory.GetFiles($"{Paths.ZoneMaps}", "*.db3"); } catch { } foreach (var m in maps) { var name = Path.GetFileNameWithoutExtension(m); var temp = new ZoneMap(name, $"{name}.db3", $"{name}.ABMesh"); yield return(temp); } }
public static Zone ZoneD() { const string want = @" ------------------- | | | | ------------------- | C | sig | | ------------------- | | | E | ------------------- "; var zone = new Zone("tests"); zone.Map = ZoneMap.TinyMap(); zone.Name = "D"; zone.Npcs = new ObservableCollection <Person> { BastokSignetPerson() }; zone.Boundaries = new List <ZoneBoundary> { new ZoneBoundary { FromZone = "D", FromPosition = new Vector3(1, 0, -1), ToZone = "E", ToPosition = new Vector3(-1, 0, 1) }, new ZoneBoundary { FromZone = "D", FromPosition = new Vector3(-1, 0, 0), ToZone = "C", ToPosition = new Vector3(1, 0, 0) } }; return(zone); }
public void CreateValidMap() { // 3,2,1 three times var zones = new IZone[] { null, null, null, null, null, null, null, null, null }; var mapping = new int[] { 3, 2, 1, 3, 2, 1, 3, 2, 1 }; var map = ZoneMap.CreateZoneMap(zones, mapping); Assert.IsNotNull(map); for (int i = 0; i < mapping.Length; i++) { Assert.AreEqual(mapping[i], map.Map[i]); } Assert.AreEqual(3, map.MapValues.Count); foreach (var mapKey in map.MapValues) { var containedZoneIndexes = map.KeyToZoneIndex[mapKey]; for (int i = 0; i < containedZoneIndexes.Count; i++) { Assert.AreEqual(mapping[containedZoneIndexes[i]], mapKey); } } }
/// <summary> /// Distance Tolerance is in 10x range, so if you want 1 it should be 10. /// </summary> /// <param name="zoneMap"></param> /// <param name="startPos"></param> /// <param name="targetPos"></param> /// <param name="pathfindingStyle"></param> /// <returns></returns> public static Vector3[] FindWaypoints(ZoneMap zoneMap, Vector3 startPos, Vector3 targetPos, IPathfindingStyle pathfindingStyle = null) { if (pathfindingStyle == null) pathfindingStyle = new ExactMatchStyle(); var sw = new Stopwatch(); sw.Start(); var pathSuccess = false; var startGridNode = zoneMap.GetNodeFromWorldPoint(startPos); var targetGridNode = zoneMap.GetNodeFromWorldPoint(targetPos); // // startGridNode.Walkable && // if (targetGridNode.Walkable) // { var openSet = new Heap<Node>(zoneMap.MaxSize); var closedSet = new HashSet<Node>(); openSet.Add(startGridNode); while (openSet.Count > 0) { var currentGridNode = openSet.RemoveFirst(); closedSet.Add(currentGridNode); // var distance = GridMath.GetDistance(currentGridNode, targetGridNode); // if (distance <= distanceTolerance) if (pathfindingStyle.PathIsFound(currentGridNode, targetGridNode)) { sw.Stop(); Console.WriteLine("Path found: " + sw.ElapsedMilliseconds + "ms"); pathSuccess = true; var waypoints = RetracePath(startGridNode, currentGridNode); return waypoints; } foreach (var neighbour in zoneMap.GetNeighbours(currentGridNode)) { if ((!neighbour.Walkable && neighbour != targetGridNode) || closedSet.Contains(neighbour)) continue; int newMovementCostToNeighbour = currentGridNode.GCost + GridMath.GetDistance(currentGridNode, neighbour) + neighbour.MovementPenalty; if (newMovementCostToNeighbour < neighbour.GCost || !openSet.Contains(neighbour)) { neighbour.GCost = newMovementCostToNeighbour; neighbour.HCost = GridMath.GetDistance(neighbour, targetGridNode); neighbour.Parent = currentGridNode; if (!openSet.Contains(neighbour)) openSet.Add(neighbour); else openSet.UpdateItem(neighbour); } } } // } if (!pathSuccess) return null; // var waypoints = RetracePath(startGridNode, targetGridNode); return null; }
public static ZoneMap SetupMediumGrid() { var grid = ZoneMap.NewGridFromVector2(new Vector2(5f, 5f)); return(grid); }
public static ZoneMap SetupBigGrid() { var grid = ZoneMap.NewGridFromVector2(new Vector2(51f, 51f)); return(grid); }
public string Serialize(ZoneMap map) { return(JsonConvert.SerializeObject(map, Formatting.Indented, new NodeConverter())); }
public static ZoneMap SetupSuperBigGrid() { var grid = ZoneMap.NewGridFromVector2(new Vector2(101f, 101f)); return(grid); }
public static ZoneMap SetupFfxiSizeGrid() { var grid = ZoneMap.NewGridFromVector2(new Vector2(1001f, 1001f)); return(grid); }
public KnownNodeActor(IPersister persister, ZoneMap zoneMap) { ZoneMap = zoneMap; Persister = persister; }
static void Main(string[] args) { Utility.WriteExeDetails(); Console.WriteLine("Loading level strings..."); Utility.LoadLevelStrings(root); Console.WriteLine("Loading world ids..."); Utility.LoadWorldId(root); Console.WriteLine("Loading zone maps..."); Utility.LoadZoneMaps(root); Console.WriteLine("Loading Instance Cooltimes..."); Utility.LoadInstanceCooltimeDataFile(root); var worlds = Utility.WorldIdIndex.worlds.Where(n => n.id != 0); WorldMapsTemplate outputFile = new WorldMapsTemplate(); outputFile.world_maps = new List <Map>(); // Build Enumeration output for WorldMapType.java in gameserver ;) StringBuilder worldMapType = new StringBuilder(); // Build Enumeration output for ClientLevelMap.cs StringBuilder clientLevelMap = new StringBuilder(); foreach (var worldmap in worlds) { var template = new Map(); template.id = worldmap.id; template.map = worldmap.name; clientLevelMap.Append(" {\"" + worldmap.name.ToLower() + "\", " + worldmap.id.ToString() + " }, " + Environment.NewLine); template.name = Utility.LevelStringIndex.GetString("STR_ZONE_NAME_" + worldmap.name).Replace("STR_ZONE_NAME_", String.Empty); template.twin_count = worldmap.twin_count; template.prison = Convert.ToBoolean(worldmap.prison); template.except_buff = Convert.ToBoolean(worldmap.except_buff); template.instance = Utility.InstanceCooltimesIndex[worldmap.name] > 0 ? true : false; // Load Zone Map and get level size ZoneMap zone = Utility.ZoneMapIndex.getZoneMap(worldmap.id); template.world_type = zone != null?zone.getWorldTypeFromString() : WorldType.NONE; template.world_size = zone != null ? zone.world_width : 3072; if (template.world_size == 0) { template.world_size = 3072; // additional check to overide any defaults in client xml } //if (zone != null) template.world_size = zone.world_width; // Other map / zone data must me loaded from individual level / mission files. try { // If no level data exists, most likely test level thats missing data, ignore // without level data the level can not be properly loaded in retail client if (!File.Exists(path + worldmap.name.ToLower() + @"\leveldata.xml")) { continue; } Console.WriteLine("Loading Level Data: " + worldmap.name); Utility.LoadLevelDataFile(path + worldmap.name.ToLower() + @"\leveldata.xml"); template.water_level = (int)Utility.LevelDataFile.level_info.WaterLevel; Mission mission = Utility.LevelDataFile.Missions.getMission("Mission0"); if (mission != null) { template.fly = mission.LevelOption.Fly.Fly_Whole_Level == 2 ? true : false; } } catch (Exception ex) { Debug.Print("Error Processing Level Data File: '{0}'", ex.InnerException); } // build enumeration for template worldMapType.Append(template.map + @"(" + template.id.ToString() + @"), // " + template.name + Environment.NewLine); outputFile.world_maps.Add(template); } string outputPath = Path.Combine(root, @".\output"); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // save enumertion for gameserver world type using (StreamWriter outfile = new StreamWriter(outputPath + @"\WorldMapType.txt")) { outfile.Write(worldMapType); } // save enumertion for parser client level mapping using (StreamWriter outfile = new StreamWriter(outputPath + @"\ClientLevelMap.txt")) { outfile.Write(clientLevelMap); } var settings = new XmlWriterSettings() { CheckCharacters = false, CloseOutput = false, Indent = true, IndentChars = "\t", NewLineChars = "\n", Encoding = new UTF8Encoding(false) }; try { using (var fs = new FileStream(Path.Combine(outputPath, "world_maps.xml"), FileMode.Create, FileAccess.Write)) using (var writer = XmlWriter.Create(fs, settings)) { XmlSerializer ser = new XmlSerializer(typeof(WorldMapsTemplate)); ser.Serialize(writer, outputFile); } } catch (Exception ex) { Debug.Print(ex.ToString()); } Console.Write("Parse Zone Data? (y/n) "); var answer = Console.ReadLine(); if (answer.Trim() == "y") { ZoneParse zoneParser = new ZoneParse(); zoneParser.parseZones(outputFile); } }