Exemplo n.º 1
0
        /// <summary>
        /// A utility function for displaying the properties of the MapData
        /// </summary>
        /// <param name="md">The mapdata to display</param>
        private static void DisplayMapdataInfo(MapData md)
        {
            Console.WriteLine("MapData header lifecycle: " + md.Header.Lifecycle);

            foreach (ILink link in md.Links)
            {
                MapLink ml = (MapLink)link;
                Console.WriteLine("Link : ");
                Console.WriteLine("    Name: " + ml.Name);
                Console.WriteLine("    Id: " + ml.Id);
            }

            foreach (IPort port in md.Ports)
            {
                MapPort mp = (MapPort)port;
                Console.WriteLine("Port : ");
                Console.WriteLine("    Name: " + mp.Name);
                Console.WriteLine("    Id: " + mp.Id);
            }

            foreach (INode node in md.Nodes)
            {
                MapNode mn = node as MapNode;
                if (mn != null)
                {
                    Console.WriteLine("Node : ");
                    Console.WriteLine("    Name: " + mn.Name);
                    Console.WriteLine("    Id: " + mn.Id);
                }
            }

            Console.WriteLine();
        }
Exemplo n.º 2
0
    public void drawAllLinks()
    {
        Queue <MapNode> q = new Queue <MapNode>();

        q.Enqueue(allNodes[0]);

        bool[] haveVisited = new bool[allNodes.Length];

        haveVisited[allNodes[0].getNodeIndex()] = true;

        while (q.Count != 0)
        {
            MapNode   currentNode = q.Dequeue();
            MapNode[] neighbors   = currentNode.getNeighbors();
            MapLink[] links       = currentNode.getLinks();

            for (int i = 0; i < neighbors.Length; i++)
            {
                if (links[i] == null)
                {
                    MapLink link = currentNode.makeNewMapLink(mapLink, i, defaultColor, activeColor);
                    neighbors[i].setNewMapLink(currentNode, link);
                    if (!haveVisited[neighbors[i].getNodeIndex()])
                    {
                        q.Enqueue(neighbors[i]);
                        haveVisited[neighbors[i].getNodeIndex()] = true;
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
 public void setNewMapLink(MapNode from, MapLink link)
 {
     for (int i = 0; i < neighbors.Length; i++)
     {
         if (neighbors[i] == from)
         {
             links[i] = link;
             break;
         }
     }
 }
Exemplo n.º 4
0
        public void TestPreProcess_NewLinks_Accuracy()
        {
            MapData ret = instance.MockPreProcess(mapData);

            // The original link (LinkA) with id 1001 should not be present.
            Assert.IsNull(ret.GetLinkById(1001), "The link should be removed.");

            // The original link (LinkB) must be present as it had no path attributes
            Assert.IsNotNull(ret.GetLinkById(1000), "LinkB must be ignored and should still be present.");


            // check individual links
            MapLink link1 = (MapLink)ret.Links[1];

            Assert.AreEqual(-1002, link1.Id, "The id of the link should be correct.");
            Assert.AreEqual(234, ((MapNode)link1.Nodes[0]).Id, "The first link must start from NodeB");
            Assert.AreEqual(-669, ((MapNode)link1.Nodes[1]).Id,
                            "The first link must end at synthetic node of NodeX");

            Assert.AreEqual(4, link1.Attributes.Count, "The original link attributes should be copied.");


            MapLink link2 = (MapLink)ret.Links[2];

            Assert.AreEqual(-1003, link2.Id, "The id of the link should be correct.");
            Assert.AreEqual(-669, ((MapNode)link2.Nodes[0]).Id,
                            "The second link must start from synthetic node of NodeX");
            Assert.AreEqual(-670, ((MapNode)link2.Nodes[1]).Id,
                            "The second link must end at synthetic node of NodeY");

            Assert.AreEqual(4, link2.Attributes.Count, "The original link attributes should be copied.");


            MapLink link3 = (MapLink)ret.Links[3];

            Assert.AreEqual(-1004, link3.Id, "The id of the link should be correct.");
            Assert.AreEqual(-670, ((MapNode)link3.Nodes[0]).Id,
                            "The third link must start from synthetic node of NodeY");
            Assert.AreEqual(-671, ((MapNode)link3.Nodes[1]).Id,
                            "The third link must end at synthetic node of NodeZ");

            Assert.AreEqual(4, link3.Attributes.Count, "The original link attributes should be copied.");

            MapLink link4 = (MapLink)ret.Links[4];

            Assert.AreEqual(-1005, link4.Id, "The id of the link should be correct.");
            Assert.AreEqual(-671, ((MapNode)link4.Nodes[0]).Id,
                            "The fourth link must start from synthetic node of NodeY");
            Assert.AreEqual(123, ((MapNode)link4.Nodes[1]).Id,
                            "The fourth link must end at nodeA");

            Assert.AreEqual(4, link3.Attributes.Count, "The original link attributes should be copied.");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Test that the PreProcess method creates the new links correctly and also deletes the original link.
        /// </summary>
        /// <param name="md">The MapDat inputted to the PreProcess method.</param>
        public void TestPreProcessNewLinks(MapData md)
        {
            MapData ret = PreProcess(md);

            //The original link (LinkA) with id 1001 should not be present.
            //The original link (LinkB) must be present as it had no path attributes
            bool linkBFound = false;

            foreach (ILink link in ret.Links)
            {
                Assert.AreNotEqual(1001, ((MapLink)link).Id, "original link with id 1001 should not be present.");
                if (((MapLink)link).Id == 1000)
                {
                    linkBFound = true;
                }
            }
            Assert.IsTrue(linkBFound, "LinkB must be ignored and should still be present.");


            //Check individual links
            MapLink link1 = (MapLink)ret.Links[1];

            Assert.AreEqual(-1002, link1.Id, "The id of the link should be correct.");
            Assert.AreEqual(234, ((MapNode)link1.Nodes[0]).Id, "The first link must start from NodeB");
            Assert.AreEqual(-669, ((MapNode)link1.Nodes[1]).Id,
                            "The first link must end at synthetic node of NodeX");

            MapLink link2 = (MapLink)ret.Links[2];

            Assert.AreEqual(-1003, link2.Id, "The id of the link should be correct.");
            Assert.AreEqual(-669, ((MapNode)link2.Nodes[0]).Id,
                            "The second link must start from synthetic node of NodeX");
            Assert.AreEqual(-670, ((MapNode)link2.Nodes[1]).Id,
                            "The second link must end at synthetic node of NodeY");

            MapLink link3 = (MapLink)ret.Links[3];

            Assert.AreEqual(-1004, link3.Id, "The id of the link should be correct.");
            Assert.AreEqual(-670, ((MapNode)link3.Nodes[0]).Id,
                            "The third link must start from synthetic node of NodeY");
            Assert.AreEqual(-671, ((MapNode)link3.Nodes[1]).Id,
                            "The third link must end at synthetic node of NodeZ");

            MapLink link4 = (MapLink)ret.Links[4];

            Assert.AreEqual(-1005, link4.Id, "The id of the link should be correct.");
            Assert.AreEqual(-671, ((MapNode)link4.Nodes[0]).Id,
                            "The fourth link must start from synthetic node of NodeY");
            Assert.AreEqual(123, ((MapNode)link4.Nodes[1]).Id,
                            "The fourth link must end at nodeA");
        }
Exemplo n.º 6
0
 private void Game_ReceivedPath(PSXAPI.Response.Path path)
 {
     _haveToMoveLink = null;
     foreach (var link in path.Links)
     {
         var getLink = _bot.Game.Map.Links.Find(l => l.Id == link);
         if (getLink != null)
         {
             if (SelectedQuest is null is false)
                 SelectedQuest.UpdateRequests(false);
             _haveToMoveLink = getLink;
             break;
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// <para>
        /// Creates a map data used in stress tests.
        /// </para>
        /// </summary>
        ///
        /// <returns>
        /// the created <see cref="MapData"/> object.
        /// </returns>
        internal static MapData CreateMapData()
        {
            // the map data
            MapData mapdata = new MapData();

            // create nodes
            for (int i = 0; i < 100; i++)
            {
                MapNode node = new MapNode();
                node.Id   = i + 1;
                node.Name = "node" + node.Id;

                mapdata.AddNode(node);
            }

            // create links
            MapLink link = new MapLink();

            link.Id   = 50;
            link.Name = "link1";
            link.AddAttribute(CreatePathAttribute(1, 1, 2));
            link.AddAttribute(CreatePathAttribute(2, 1, "node50"));

            mapdata.AddLink(link);

            // create ports
            MapPort port = new MapPort();

            port.Id   = 1;
            port.Name = "port1";
            port.Node = mapdata.GetNodeById(1);
            port.Node.Ports.Add(port);
            link.AddPort(port);
            mapdata.AddPort(port);

            port      = new MapPort();
            port.Id   = 50;
            port.Name = "port2";
            port.Node = mapdata.GetNodeById(100);
            port.Node.Ports.Add(port);
            link.AddPort(port);
            mapdata.AddPort(port);

            mapdata.Header           = new MapHeader();
            mapdata.Header.Lifecycle = "xxx";

            return(mapdata);
        }
Exemplo n.º 8
0
        public string getValue(FieldNames whichElement)
        {
            switch (whichElement)
            {
            case FieldNames.Nothing:
                return("");

            //case FieldNames.Label:
            //  return label;
            case FieldNames.isInPath:
                return(IsInPath.ToString());

            case FieldNames.isWalkable:
                return(IsWalkable.ToString());

            case FieldNames.isCombatWalkable:
                return(IsCombatWalkable.ToString());

            case FieldNames.allowLOS:
                return(AllowLOS.ToString());

            //case FieldNames.color:
            //  return color.ToString();
            case FieldNames.speed:
                return(Speed.ToString());

            case FieldNames.coordinates:
                return(String.Format("{0},{1}", X, Y));

            case FieldNames.PathFindingInformations:
                return(DistanceSteps.ToString());

            case FieldNames.mapLink:
                return(MapLink.ToString());

            case FieldNames.cellID:
                return(this.CellId.ToString());

            //case FieldNames.firstGfx:
            //  return this.firstGfx.ToString();
            //case FieldNames.gfxCount:
            //  return this.gfxCount.ToString();
            default:
                return("???");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new link between the startNode and the endNode.
        /// The startPort and endPort are the ports for the start and end nodes.
        /// </summary>
        /// <param name="startNode">The starting node</param>
        /// <param name="endNode">The ending node</param>
        /// <param name="startPort">The starting port</param>
        /// <param name="endPort">the ending port</param>
        /// <param name="mapdata">The Mapdata to use for generating the unique id of the link.</param>
        /// <param name="origLink">The original link</param>
        /// <param name="toBeAddedLinks">The number of links yet to be added.</param>
        /// <returns>The new link created.</returns>
        private MapLink CreateNewLink(
            MapNode startNode, MapNode endNode, MapPort startPort, MapPort endPort, MapData mapdata,
            MapLink origLink, int toBeAddedLinks)
        {
            //Create new link
            long    newLinkId = GetUniqueId(typeof(MapLink), mapdata, toBeAddedLinks);
            MapLink newLink   = new MapLink();

            newLink.Id   = newLinkId;
            newLink.Name = MapLinkNamePrefix + newLinkId;

            //Add the nodes
            newLink.AddNode(startNode);
            newLink.AddNode(endNode);

            //Add the ports
            newLink.AddPort(startPort);
            newLink.AddPort(endPort);

            //Copy attributes of original link and set owner id of the new attributes. Also add to mapdata
            CopyAttributes(origLink, newLink, newLinkId, mapdata);

            //create a new attribute to store the original link id
            MapAttribute origLinkIdAttr = new MapAttribute();

            origLinkIdAttr.Name        = "origLinkId";
            origLinkIdAttr.StringValue = origLink.Id.ToString();
            long newAttrId = GetUniqueId(typeof(MapAttribute), mapdata, 0);

            origLinkIdAttr.Id        = newAttrId;
            origLinkIdAttr.OwnerType = "link";
            origLinkIdAttr.OwnerId   = newLink.Id;
            origLinkIdAttr.Type      = AttrTypeString;

            //Add the new attribute to the new link and the map data
            newLink.Attributes.Add(origLinkIdAttr);
            mapdata.AddAttribute(origLinkIdAttr);

            //Set new link's element type from original link
            newLink.ElementType = origLink.ElementType;

            return(newLink);
        }
Exemplo n.º 10
0
 public void AddNPC(NonPlayerEntity entity)
 {
     if (!NonPlayerEntities.Contains(entity))
     {
         foreach (TeleportLink link in entity.Links)
         {
             MapLink l = new MapLink()
             {
                 Start    = MapPoint,
                 End      = link.End,
                 LinkType = LinkType.Teleport,
                 Script   = link.Script
             };
             Links.Add(l);
         }
         EntityTypes = EntityTypes | entity.EntityTypes;
         NonPlayerEntities.Add(entity);
     }
 }
Exemplo n.º 11
0
        public void Update()
        {
            if (_bot.Game is null)
                return;

            _questTimeout.Update();

            if (_bot.Game != null && _bot.Game.IsInBattle)
                _haveToMoveLink = null;

            if (_haveToMoveLink != null && !_bot.Game.IsInBattle && _bot.Game != null)
            {
                if (_bot.Game.PlayerX != _haveToMoveLink.DestinationX || _bot.Game.PlayerY != _haveToMoveLink.DestinationY)
                {
                    _questTimeout.Set();
                    _bot.Game?.ClearPath();
                    _bot.MoveToCell(_haveToMoveLink.DestinationX, _haveToMoveLink.DestinationY);
                    _haveToMoveLink = null;
                    return;
                }
                else
                    _haveToMoveLink = null;
            }

            if (Quests.Count > 0)
            {               

                if (_bot.Script?.IsLoaded == true)
                {
                    var quest = Quests[0];
                    Quests.RemoveAt(0);

                    _bot.Script?.OnQuestUpdated(quest.Name, quest.Type.ToString(), quest.Description);

                    if (_bot.Game.AutoCompleteQuest(quest))
                        _questTimeout.Set();

                    _questTimeout.Set();
                }
            }
        }
Exemplo n.º 12
0
        public static FuncMethod CompareMap(DeltinScript deltinScript) => new FuncMethodBuilder()
        {
            Name          = "CompareMap",
            Documentation = "Compares the current map to a map value. Map variants are considered as well.",
            ReturnType    = deltinScript.Types.Boolean(),
            Parameters    = new[] { new MapParameter(deltinScript.Types) },
            Action        = (actionSet, methodCall) => {
                var     enumData = (ElementEnumMember)methodCall.ParameterValues[0];
                string  map      = enumData.Name;
                MapLink mapLink  = MapLink.GetMapLink(map);

                if (mapLink == null)
                {
                    return(Element.Compare(Element.Part("Current Map"), Operator.Equal, enumData.ToElement()));
                }
                else
                {
                    return(Element.Contains(mapLink.GetArray(), Element.Part("Current Map")));
                }
            }
        };
Exemplo n.º 13
0
 public void ChatOnChatMessage(XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool ishandled)
 {
     if (!Visible && !Plugin.Config.LinkTrackerAlwaysActive)
     {
         return;
     }
     foreach (var payload in message.Payloads)
     {
         if (!(payload is MapLinkPayload mapLink))
         {
             continue;
         }
         var link = new MapLink(Plugin, type, mapLink, sender.TextValue, message);
         if (link.HasAetheryte)
         {
             MapLinks.Add(link);
             if (Plugin.Config.LinkTrackerAutoPop)
             {
                 Visible = true;
             }
         }
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Copies the attributes of an old link to a new one.
        /// </summary>
        /// <param name="origLink">The old link</param>
        /// <param name="newLink">The new link</param>
        /// <param name="newLinkId">The id of the new link</param>
        /// <param name="mapdata">The mapdata into which the new attributes will be added.</param>
        private void CopyAttributes(MapLink origLink, MapLink newLink, long newLinkId, MapData mapdata)
        {
            foreach (MapAttribute attr in origLink.Attributes)
            {
                //Create a new attribute and set its properties
                MapAttribute newattr = new MapAttribute();
                newattr.Id            = GetUniqueId(typeof(MapAttribute), mapdata, 0);
                newattr.OwnerId       = newLinkId;
                newattr.Name          = attr.Name;
                newattr.OwnerType     = attr.OwnerType;
                newattr.Type          = attr.Type;
                newattr.IntValue      = attr.IntValue;
                newattr.StringValue   = attr.StringValue;
                newattr.DoubleValue   = attr.DoubleValue;
                newattr.DateTimeValue = attr.DateTimeValue;

                //Add new attribute to the new link
                newLink.AddAttribute(newattr);

                //Add new attribute to the new mapdata
                mapdata.AddAttribute(newattr);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// This method performs the following logic:
        /// For each link in the mapdata, it gets the nodes defining the link from its 'path' attributes.
        /// For each such node, it creates a new synthetic node as a child of the node.
        /// For each such synthetic node, it creates a port for it.
        /// It then forms new links between the nodes of the original link and the new ports formed.
        /// Finally it adds all the new links formed to the mapdata and removes the original link.
        /// </summary>
        /// <param name="mapdata">MapData to be processed</param>
        private void AddNewLinksAndSyntheticNodes(MapData mapdata)
        {
            IList <MapLink> linksToDelete = new List <MapLink>();
            IList <MapLink> linksToAdd    = new List <MapLink>();

            foreach (ILink link in mapdata.Links)
            {
                MapLink mapLink = (MapLink)link;

                //Get the path attributes
                IList <IAttribute> pathAttrs = mapLink.GetAttributesByName(Path);

                //Preserve the original link if no path attributes are found
                if (pathAttrs == null || pathAttrs.Count == 0)
                {
                    continue;
                }

                //Get the nodes of the path
                IList <MapNode> pathNodes = new List <MapNode>();
                foreach (IAttribute attr in pathAttrs)
                {
                    MapAttribute pathAttr = (MapAttribute)attr;
                    if (pathAttr.Type.Equals(AttrTypeInt))
                    {
                        pathNodes.Add((MapNode)mapdata.GetNodeById(pathAttr.IntValue));
                    }
                    else if (pathAttr.Type.Equals(AttrTypeString))
                    {
                        pathNodes.Add((MapNode)mapdata.GetNodeByName(pathAttr.StringValue));
                    }
                }

                //Create the synthetic nodes for each path node.
                IList <MapNode> syntheticNodes = new List <MapNode>();
                foreach (MapNode pathNode in pathNodes)
                {
                    if (mapdata.Nodes.Contains(pathNode))
                    {
                        //Get the unique id for the new synthetic node and set it
                        long    syntheticNodeId = GetUniqueId(typeof(MapNode), mapdata, 0);
                        MapNode syntheticNode   = new MapNode();
                        syntheticNode.Id   = syntheticNodeId;
                        syntheticNode.Name = MapNodeNamePrefix + syntheticNodeId;

                        //Add it as child node of pathNode
                        pathNode.AddOccupant(syntheticNode);
                        syntheticNode.Container = pathNode;

                        //Add it to the mapData
                        mapdata.AddNode(syntheticNode);

                        //Create and add port to synthetic node.
                        long    syntheticNodePortId = GetUniqueId(typeof(MapPort), mapdata, 0);
                        MapPort syntheticNodePort   = new MapPort();
                        syntheticNodePort.Id   = syntheticNodePortId;
                        syntheticNodePort.Name = MapPortNamePrefix + syntheticNodePortId;
                        syntheticNode.AddPort(syntheticNodePort);

                        //Add synthetic node to the port
                        syntheticNodePort.Node = syntheticNode;

                        //Add created port to the mapdata
                        mapdata.AddPort(syntheticNodePort);

                        //Save it further processing
                        syntheticNodes.Add(syntheticNode);
                    }
                }

                //None of the path nodes were found in the mapdata nodes.
                if (syntheticNodes.Count == 0)
                {
                    continue;
                }

                //Create new links
                //1)Note that we first get port and then get the node from the port.
                //See http://forums.topcoder.com/?module=Thread&threadID=592050&start=0&mc=24#885358
                //2)Links are guaranteed to have exactly 2 nodes
                MapPort startPort = (MapPort)mapLink.Ports[0];
                MapNode startNode = (MapNode)startPort.Node;
                MapNode endNode   = null;
                MapPort endPort   = null;
                for (int i = 0; i < syntheticNodes.Count; i++)
                {
                    endNode = syntheticNodes[i];
                    endPort = (MapPort)syntheticNodes[i].Ports[0];

                    //Create link and save it for adding later
                    linksToAdd.Add(CreateNewLink(startNode, endNode, startPort, endPort, mapdata, mapLink, linksToAdd.Count));

                    startNode = endNode;
                    startPort = endPort;
                }
                endPort = (MapPort)mapLink.Ports[1];
                endNode = (MapNode)endPort.Node;
                //Create last link and save it for adding later
                linksToAdd.Add(CreateNewLink(startNode, endNode, startPort, endPort, mapdata, mapLink, linksToAdd.Count));

                //Save original link for deleting it later
                linksToDelete.Add(mapLink);
            }

            //Remove the original links
            foreach (MapLink linkToDelete in linksToDelete)
            {
                //Remove link's attributes from mapdata
                foreach (IAttribute linkAttr in linkToDelete.Attributes)
                {
                    mapdata.RemoveAttribute((MapAttribute)linkAttr);
                }
                //REmove the link itself from mapdata
                mapdata.RemoveLink(linkToDelete);
            }

            //Add the new links
            foreach (MapLink linkToAdd in linksToAdd)
            {
                mapdata.AddLink(linkToAdd);
            }
        }
Exemplo n.º 16
0
    public MiniMap Generate(int stage)
    {
        bool Label_go = false;

        mapSize = ComputeMapSize(stage);
        int roomCount    = Mapsize(stage);
        int curRoomCount = 0;

        MiniMap miniMap = new MiniMap(mapSize);
        MapLink mapLink = new MapLink();

        int startX = Random.Range(0, mapSize.x);          // 스타트지점 x,y 지정
        int startY = Random.Range(0, mapSize.y);
        int nextX  = 0;
        int nextY  = 0;

        MiniRoom startRoom  = new MiniRoom();               // 스타트룸 생성, 포인트 지정
        Point    startPoint = new Point(startX, startY);

        MiniRoom[] Rooms  = new MiniRoom[roomCount];        // 나머지 룸, 포인트 생성
        Point[]    Points = new Point[roomCount];


        miniMap[startPoint]          = startRoom;
        miniMap[startPoint].isSource = true;
        miniMap[startPoint].isUsed   = true;

        // MiniRoom PrevRoom = startRoom;
        for (int i = 0; i < roomCount; i++)
        {
            curRoomCount++;
            Rooms[i] = new MiniRoom();

Roommake:
            nextX = startX;
            nextY = startY;
is_SameRoom:
            Label_go = false;

            int ran = Random.Range(0, 4);                   // 랜덤으로 방을 생성하기위한 int
            switch (ran)                                    // 랜덤 방생성
            {
            case 0:
                nextX--;
                if (nextX < 0)
                {
                    goto Roommake;
                }

                Points[i] = new Point(nextX, nextY);
                for (int j = 0; j < i; j++)                                              // 룸끼리 겹칠시 다시 세팅
                {
                    if ((Points[j].x == Points[i].x) && (Points[j].y == Points[i].y) || (Points[i].x == startPoint.x) && (Points[i].y == startPoint.y))
                    {
                        Label_go = true;
                    }
                }
                if (Label_go == true)
                {
                    goto is_SameRoom;
                }
                miniMap[Points[i]]        = Rooms[i];
                miniMap[Points[i]].isUsed = true;
                goto sameroom_check;

            case 1:
                nextX++;
                if (nextX >= mapSize.y)
                {
                    goto Roommake;
                }

                Points[i] = new Point(nextX, nextY);
                for (int j = 0; j < i; j++)
                {
                    if ((Points[j].x == Points[i].x) && (Points[j].y == Points[i].y) || (Points[i].x == startPoint.x) && (Points[i].y == startPoint.y))
                    {
                        Label_go = true;
                    }
                }
                if (Label_go == true)
                {
                    goto is_SameRoom;
                }
                miniMap[Points[i]]        = Rooms[i];
                miniMap[Points[i]].isUsed = true;
                goto sameroom_check;

            case 2:
                nextY--;
                if (nextY < 0)
                {
                    goto Roommake;
                }

                Points[i] = new Point(nextX, nextY);
                for (int j = 0; j < i; j++)
                {
                    if ((Points[j].x == Points[i].x) && (Points[j].y == Points[i].y) || (Points[i].x == startPoint.x) && (Points[i].y == startPoint.y))
                    {
                        Label_go = true;
                    }
                }
                if (Label_go == true)
                {
                    goto is_SameRoom;
                }
                miniMap[Points[i]]        = Rooms[i];
                miniMap[Points[i]].isUsed = true;
                goto sameroom_check;

            case 3:
                nextY++;
                if (nextY >= mapSize.x)
                {
                    goto Roommake;
                }

                Points[i] = new Point(nextX, nextY);
                for (int j = 0; j < i; j++)
                {
                    if ((Points[j].x == Points[i].x) && (Points[j].y == Points[i].y) || (Points[i].x == startPoint.x) && (Points[i].y == startPoint.y))
                    {
                        Label_go = true;
                    }
                }
                if (Label_go == true)
                {
                    goto is_SameRoom;
                }
                miniMap[Points[i]]        = Rooms[i];
                miniMap[Points[i]].isUsed = true;
                goto sameroom_check;
            }
sameroom_check:

            startX = nextX;
            startY = nextY;
        }

        mapLink.Link(miniMap, stage);      // 부르는 부분


        return(miniMap);
    }
Exemplo n.º 17
0
        public void LoadWzResource()
        {
            if (this.IsDataLoaded)
            {
                return;
            }

            //读取所有世界地图
            var worldmapNode = PluginBase.PluginManager.FindWz("Map/WorldMap");

            if (worldmapNode == null) //加载失败
            {
                return;
            }

            this.worldMaps.Clear();
            this.CurrentWorldMap = null;

            foreach (var imgNode in worldmapNode.Nodes)
            {
                var     img = imgNode.GetNodeWzImage();
                Wz_Node node;
                if (img != null && img.TryExtract())
                {
                    var worldMapInfo = new WorldMapInfo();

                    //加载地图索引
                    node = img.Node.Nodes["info"];
                    if (node != null)
                    {
                        if (!this.UseImageNameAsInfoName)
                        {
                            worldMapInfo.Name = node.Nodes["WorldMap"].GetValueEx <string>(null);
                        }
                        worldMapInfo.ParentMap = node.Nodes["parentMap"].GetValueEx <string>(null);
                    }
                    if (string.IsNullOrEmpty(worldMapInfo.Name))
                    {
                        var m = Regex.Match(img.Name, @"^(.*)\.img$");
                        worldMapInfo.Name = m.Success ? m.Result("$1") : img.Name;
                    }

                    //加载地图名称
                    {
                        var m = Regex.Match(worldMapInfo.Name, @"^WorldMap(.+)$");
                        if (m.Success)
                        {
                            var stringNode = PluginBase.PluginManager.FindWz("String/WorldMap.img/" + m.Result("$1"));
                            worldMapInfo.DisplayName = stringNode?.Nodes["name"].GetValueEx <string>(null);
                        }
                    }

                    //加载baseImg
                    node = img.Node.Nodes["BaseImg"]?.Nodes["0"];
                    if (node != null)
                    {
                        worldMapInfo.BaseImg = LoadTextureItem(node);
                    }

                    //加载地图列表
                    node = img.Node.Nodes["MapList"];
                    if (node != null)
                    {
                        foreach (var spotNode in node.Nodes)
                        {
                            var spot     = new MapSpot();
                            var location = spotNode.Nodes["spot"]?.GetValueEx <Wz_Vector>(null);
                            if (location != null)
                            {
                                spot.Spot = location.ToPointF();
                            }
                            else //兼容pre-bb的格式
                            {
                                spot.IsPreBB = true;
                                spot.Spot    = new PointF(spotNode.Nodes["x"].GetValueEx <int>(0),
                                                          spotNode.Nodes["y"].GetValueEx <int>(0));
                            }
                            spot.Type      = spotNode.Nodes["type"].GetValueEx <int>(0);
                            spot.Title     = spotNode.Nodes["title"].GetValueEx <string>(null);
                            spot.Desc      = spotNode.Nodes["desc"].GetValueEx <string>(null);
                            spot.NoTooltip = spotNode.Nodes["noToolTip"].GetValueEx <int>(0) != 0;
                            var pathNode = spotNode.Nodes["path"];
                            if (pathNode != null)
                            {
                                spot.Path = LoadTextureItem(pathNode);
                            }
                            var mapNoNode = spotNode.Nodes["mapNo"];
                            if (mapNoNode != null)
                            {
                                foreach (var subNode in mapNoNode.Nodes)
                                {
                                    spot.MapNo.Add(subNode.GetValue <int>());
                                }
                            }
                            worldMapInfo.MapList.Add(spot);
                        }
                    }

                    //加载地图链接
                    node = img.Node.Nodes["MapLink"];
                    if (node != null)
                    {
                        foreach (var mapLinkNode in node.Nodes)
                        {
                            var link = new MapLink();
                            link.Index   = int.Parse(mapLinkNode.Text);
                            link.Tooltip = mapLinkNode.Nodes["toolTip"].GetValueEx <string>(null);
                            var linkNode = mapLinkNode.Nodes["link"];
                            if (linkNode != null)
                            {
                                link.LinkMap = linkNode.Nodes["linkMap"].GetValueEx <string>(null);
                                var linkImgNode = linkNode.Nodes["linkImg"];
                                if (linkImgNode != null)
                                {
                                    link.LinkImg = LoadTextureItem(linkImgNode, true);
                                }
                            }
                            worldMapInfo.MapLinks.Add(link);
                        }
                    }

                    this.worldMaps.Add(worldMapInfo);
                }
            }

            //读取公共资源
            var worldMapResNode = PluginBase.PluginManager.FindWz("Map/MapHelper.img/worldMap");
            var mapImageNode    = worldMapResNode?.Nodes["mapImage"];

            if (mapImageNode != null)
            {
                foreach (var imgNode in mapImageNode.Nodes)
                {
                    var texture = this.LoadTextureItem(imgNode);
                    var key     = "mapImage/" + imgNode.Text;
                    this.Resources[key] = texture;
                }
            }

            var curPosNode = worldMapResNode?.FindNodeByPath(@"curPos\0");

            if (curPosNode != null)
            {
                var texture = this.LoadTextureItem(curPosNode);
                this.Resources["curPos"] = texture;
            }

            //处理当前地图信息
            foreach (var map in this.worldMaps)
            {
                if (map.ParentMap != null)
                {
                    map.ParentMapInfo = this.worldMaps.FirstOrDefault(_map => _map.Name == map.ParentMap);
                }
            }

            this.IsDataLoaded = true;
            this.JumpToCurrentMap();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates a sample Map Data for the tests.
        /// </summary>
        /// <returns>A sample MapData instance</returns>
        internal static MapData GetSampleMapData()
        {
            MapData md = new MapData();

            //Create some nodes and add them to the mapdata
            MapNode nodeA = new MapNode();

            SetMockIdAndName(nodeA, 123, "nodeA");
            AddMockPort(nodeA, null);

            MapNode nodeB = new MapNode();

            SetMockIdAndName(nodeB, 234, "nodeB");
            AddMockPort(nodeB, null);

            MapNode nodeC = new MapNode();

            SetMockIdAndName(nodeC, 012, "nodeC");

            MapNode nodeX = new MapNode();

            SetMockIdAndName(nodeX, 666, "nodeX");
            AddMockPort(nodeX, null);

            MapNode nodeY = new MapNode();

            SetMockIdAndName(nodeY, 667, "nodeY");
            AddMockPort(nodeY, null);

            MapNode nodeZ = new MapNode();

            SetMockIdAndName(nodeZ, 668, "nodeZ");
            AddMockPort(nodeZ, null);

            md.Nodes.Add(nodeA);
            md.Nodes.Add(nodeB);
            md.Nodes.Add(nodeX);
            md.Nodes.Add(nodeY);
            md.Nodes.Add(nodeZ);

            //Create a link (from A to B) and add it to the mapData
            MapLink linkA = new MapLink();

            SetMockIdAndName(linkA, 1001, "linkA");
            linkA.AddNode(nodeA);
            linkA.AddNode(nodeB);
            //Note ports do not have to be in the same order as the links
            linkA.AddPort((MapPort)nodeB.Ports[0]);
            linkA.AddPort((MapPort)nodeA.Ports[0]);

            //Create a link (from B to C) and add it to the mapData
            MapLink linkB = new MapLink();

            SetMockIdAndName(linkB, 1000, "linkB");
            linkA.AddNode(nodeB);
            linkA.AddNode(nodeC);

            md.Links.Add(linkA);
            md.Links.Add(linkB);

            //Create a linked port
            nodeB.Ports[0].Links.Add(linkA);

            //Set header
            md.Header = new MapHeader();

            //Create linkedport for NodeC
            AddMockPort(nodeC, linkB);


            //path with 3 nodes for LinkA
            MapAttribute ma1 = new MapAttribute();

            ma1.IntValue = 666;
            ma1.Type     = "int";
            ma1.Name     = "path";
            MapAttribute ma2 = new MapAttribute();

            ma2.IntValue = 667;
            ma2.Type     = "int";
            ma2.Name     = "path";
            MapAttribute ma3 = new MapAttribute();

            ma3.StringValue = "nodeZ";
            ma3.Type        = "string";
            ma3.Name        = "path";
            linkA.AddAttribute(ma1);
            linkA.AddAttribute(ma2);
            linkA.AddAttribute(ma3);

            return(md);
        }