示例#1
0
        public static List <FFXIVGatheringNode> GetFFXIVGatheringNodesFromTable(HtmlNode iNode, string iJobName, FFXIVGatheringNode.NodeType iType = FFXIVGatheringNode.NodeType.Standard)
        {
            List <FFXIVGatheringNode> result = new List <FFXIVGatheringNode>();

            if (null == iNode)
            {
                return(result);
            }

            DirectoryInfo exeDirectory      = new DirectoryInfo(Service_Misc.GetExecutionPath());
            DirectoryInfo metadataDirectory = new DirectoryInfo(Path.Combine(exeDirectory.FullName, "Metadata"));


            int indexItems    = -1;
            int indexLocation = -1;
            int indexName     = -1;

            List <HtmlNode> listthNodes = iNode.Descendants("th").ToList();

            for (int i = 0; i < listthNodes.Count; i++)
            {
                HtmlNode thNode = listthNodes[i];
                if (null == thNode)
                {
                    continue;
                }

                string thText = thNode.InnerText.Trim().ToLower();
                if (thText == "item" || thText == "items" || thText == "fish name" || thText == "fish")
                {
                    indexItems = i;
                }
                else if (thText == "coordinate" || thText == "coordinates")
                {
                    indexLocation = i;
                }
                else if (thText == "location" || thText == "zone")
                {
                    indexName = i;
                }
            }

            if (indexItems < 0)
            {
                return(result);
            }
            if (indexName < 0)
            {
                return(result);
            }
            if (indexLocation < 0)
            {
                return(result);
            }

            foreach (HtmlNode trNode in iNode.Descendants("tr"))
            {
                List <HtmlNode> listtdNodes = trNode.Descendants("td").ToList();
                if (listtdNodes.Count <= indexItems)
                {
                    continue;
                }
                if (listtdNodes.Count <= indexLocation)
                {
                    continue;
                }
                if (listtdNodes.Count <= indexName)
                {
                    continue;
                }
                string        coordinates = listtdNodes[indexLocation].InnerText.Trim().ToLower().Replace(":", "").Replace("x", "").Replace("y", "");
                string        nameZone    = listtdNodes[indexName].InnerText.Trim();
                List <string> items       = listtdNodes[indexItems].InnerText.Trim().Split(new string[] { Environment.NewLine, ",", "\n" }, StringSplitOptions.None).ToList();

                double x = 0, y = 0;
                if (coordinates == "(shore)")
                {
                }
                else
                {
                    if (!coordinates.Contains("("))
                    {
                        coordinates = "(" + coordinates;
                    }
                    if (!coordinates.Contains(")"))
                    {
                        coordinates = coordinates + ")";
                    }
                    if (!coordinates.Contains(","))
                    {
                        coordinates = coordinates.Replace(" ", ",");
                    }

                    string xText = coordinates.Split(new string[] { "(" }, StringSplitOptions.None)[1].Split(',')[0].Trim();
                    string yText = coordinates.Split(new string[] { "," }, StringSplitOptions.None)[1].Split(')')[0].Trim();
                    double.TryParse(xText, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out x);
                    double.TryParse(yText, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out y);
                }

                string nameNode = nameZone.Replace(" ", "_") + "_" + x + "_" + y;

                FFXIVGatheringNode gatheringNode = null;
                foreach (FFXIVGatheringNode node in result)
                {
                    if (node.Name == nameNode)
                    {
                        gatheringNode = node;
                    }
                }
                if (null == gatheringNode)
                {
                    gatheringNode      = new FFXIVGatheringNode();
                    gatheringNode.Name = nameNode;

                    //Conversion aetheryte position to map position
                    double offsetX = 0;
                    double offsetY = 0;
                    if (nameZone == "Greytail Falls")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "South Banepool")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "West Banepool")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Unfrozen Pond")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Ashpool")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Riversmeet")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Dragonspit")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Clearpool")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }

                    if (nameZone == "Voor Sian Siran")
                    {
                        nameZone = "The Sea of Clouds";
                    }
                    if (nameZone == "Mok Oogl Island")
                    {
                        nameZone = "The Sea of Clouds";
                    }
                    if (nameZone == "Cloudtop")
                    {
                        nameZone = "The Sea of Clouds";
                    }
                    if (nameZone == "The Blue Window")
                    {
                        nameZone = "The Sea of Clouds";
                    }
                    if (nameZone == "The Eddies")
                    {
                        nameZone = "The Sea of Clouds";
                    }

                    if (nameZone == "Riversmeet")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Riversmeet")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    if (nameZone == "Riversmeet")
                    {
                        nameZone = "Coerthas Western Highlands";
                    }
                    FileInfo metadataFile = new FileInfo(Path.Combine(metadataDirectory.FullName, nameZone + ".txt"));
                    if (!metadataFile.Exists)
                    {
                        metadataFile = new FileInfo(Path.Combine(metadataDirectory.FullName, "The " + nameZone + ".txt"));
                        if (metadataFile.Exists)
                        {
                            nameZone = "The " + nameZone;
                        }
                    }
                    if (!metadataFile.Exists)
                    {
                        offsetX = 0;
                        offsetY = 0;
                        //File.WriteAllText(metadataFile.FullName, "21.4;21.4");
                    }
                    else
                    {
                        string        metadata            = File.ReadAllText(metadataFile.FullName);
                        List <string> coordinatesMetadata = metadata.Replace(",", ".").Split(';').ToList();
                        double.TryParse(coordinatesMetadata[0], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out offsetX);
                        double.TryParse(coordinatesMetadata[1], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out offsetY);
                    }
                    gatheringNode.Zone       = nameZone;
                    gatheringNode.Position   = new FFXIVPosition((x - offsetX) * 50, (y - offsetY) * 50);
                    gatheringNode.JobTrigram = iJobName;
                    gatheringNode.Type       = iType;
                    result.Add(gatheringNode);
                }
                gatheringNode.NodeItems.AddRange(items);
            }


            return(result);
        }
示例#2
0
        public void Analyze(List <FFXIVAetheryte> iAetherytes, List <FFXIVGatheringNode> iNodes, ref Dictionary <string, double> dictionaryClosestAetherytes)
        {
            Status  = "Unknown";
            IsValid = false;
            try
            {
                string contentGrid = File.ReadAllText(GridFile.FullName);
                if (contentGrid == "")
                {
                    Status = "Empty Grid";
                    return;
                }

                ParseFromLine(contentGrid);

                //Finding item gathering nodes
                bool noGatheringNodeMode = false;
                List <FFXIVGatheringNode> correspondingNodes = new List <FFXIVGatheringNode>();
                foreach (FFXIVGatheringNode node in iNodes)
                {
                    if (null == node)
                    {
                        continue;
                    }

                    string foundItemName = node.NodeItems.Find(x => x != null && x.ToLower().Trim() == ItemName.ToLower().Trim());
                    if (foundItemName != null && foundItemName != "")
                    {
                        correspondingNodes.Add(node);
                    }
                }
                if (correspondingNodes.Count <= 0 && ItemName != "")
                {
                    List <FFXIVSearchItem> resultGarlandTools = GarlandTool.Search(ItemName, null, FFXIVItem.TypeItem.Gathered);
                    if (resultGarlandTools.Count > 0)
                    {
                        List <FFXIVGatheringNode> correspondingNodesFromGarland = GarlandTool.GetGatheringNodesFromItem(resultGarlandTools[0].ID);

                        foreach (FFXIVGatheringNode garlandNode in correspondingNodesFromGarland)
                        {
                            string foundItemName = garlandNode.NodeItems.Find(x => x != null && x.ToLower().Trim() == ItemName.ToLower().Trim());
                            if (foundItemName != null && foundItemName != "")
                            {
                                correspondingNodes.Add(garlandNode);
                            }

                            /*
                             *  FFXIVGatheringNode bestNode = null;
                             *  double maxCorrespondance = -1;
                             *  foreach (FFXIVGatheringNode node in iNodes)
                             *  {
                             *      if(node.Zone.ToLower().Trim() != garlandNode.Zone.ToLower().Trim())
                             *      {
                             *          continue;
                             *      }
                             *
                             *      double nbSameItem = 0;
                             *      double nbTotalItem = node.NodeItems.Count;
                             *
                             *      foreach(string itemName in node.NodeItems)
                             *      {
                             *          if (null != garlandNode.NodeItems.Find(x => x != null && x.ToLower().Trim() == itemName.ToLower().Trim()))
                             *          {
                             *              nbSameItem += 1.0;
                             *          }
                             *      }
                             *      double correspondance = 100.0 * nbSameItem / nbTotalItem;
                             *      if(maxCorrespondance < correspondance)
                             *      {
                             *          maxCorrespondance = correspondance;
                             *          bestNode = node;
                             *      }
                             *  }
                             *  if (maxCorrespondance < 0) continue;
                             *  if (null == bestNode) continue;
                             *  correspondingNodes.Add(bestNode);
                             */
                        }
                    }
                    noGatheringNodeMode = correspondingNodes.Count > 0;
                }
                AllNodes = correspondingNodes;

                //Finding closest node
                double minDistance = -1;
                if (!noGatheringNodeMode)
                {
                    foreach (FFXIVGatheringNode node in correspondingNodes)
                    {
                        if (null == node)
                        {
                            continue;
                        }

                        double nodeDistance = -1;
                        foreach (FFXIVPosition point in Points)
                        {
                            double distance = node.Position.PlanarDistanceTo(point);
                            if (minDistance < 0 || distance < minDistance)
                            {
                                minDistance         = distance;
                                ClosestNode         = node;
                                ClosestNodeDistance = minDistance;
                            }
                            if (nodeDistance < 0 || distance < nodeDistance)
                            {
                                nodeDistance = distance;
                            }
                        }
                        AllNodesDistance.Add(nodeDistance);
                    }
                    if (minDistance > 50)
                    {
                        Status = "Too far from closest gathering node.";
                        return;
                    }
                    if (null == ClosestNode)
                    {
                        Status = "No gathering node.";
                        return;
                    }
                }
                else
                {
                    if (AllNodes.Count == 1)
                    {
                        ClosestNode = AllNodes[0];
                    }
                    foreach (FFXIVGatheringNode node in correspondingNodes)
                    {
                        AllNodesDistance.Add(-1);
                    }
                }

                string statusPrefix = "";
                if (noGatheringNodeMode)
                {
                    statusPrefix = "[No-Node] ";
                }
                //Finding zone aetherytes
                List <FFXIVAetheryte> listZoneAetherytes = new List <FFXIVAetheryte>();
                foreach (FFXIVAetheryte aetherythe in iAetherytes)
                {
                    if (noGatheringNodeMode)
                    {
                        foreach (FFXIVGatheringNode node in correspondingNodes)
                        {
                            if (aetherythe.Zone == node.Zone)
                            {
                                listZoneAetherytes.Add(aetherythe);
                            }
                        }
                    }
                    else
                    {
                        if (aetherythe.Zone == ClosestNode.Zone)
                        {
                            listZoneAetherytes.Add(aetherythe);
                        }
                    }
                }

                //Finding closest aetheryte
                double minDistanceAetheryte = -1;
                List <FFXIVPosition> listAetheryteClosePoints = new List <FFXIVPosition>();
                foreach (FFXIVAetheryte aetherythe in listZoneAetherytes)
                {
                    if (null == aetherythe)
                    {
                        continue;
                    }

                    double distanceAetheryte = -1;
                    foreach (FFXIVPosition point in Points)
                    {
                        double distance = aetherythe.Position.PlanarDistanceTo(point);
                        if (minDistanceAetheryte < 0 || distance < minDistanceAetheryte)
                        {
                            minDistanceAetheryte     = distance;
                            ClosestAetheryte         = aetherythe;
                            ClosestAetheryteDistance = minDistanceAetheryte;
                        }
                        if (distanceAetheryte < 0 || distance < distanceAetheryte)
                        {
                            distanceAetheryte = distance;
                        }
                        if (distance < 50)
                        {
                            listAetheryteClosePoints.Add(point);
                        }
                    }
                    ZoneAetherytes.Add(aetherythe);
                    ZoneAetherytesDistance.Add(distanceAetheryte);
                }
                if (minDistanceAetheryte > 40)
                {
                    Status = statusPrefix + "Too far from closest aetheryte.";
                    return;
                }
                if (null == ClosestAetheryte)
                {
                    Status = statusPrefix + "No Aetheryte.";
                    return;
                }
                if (listAetheryteClosePoints.Count < 1)
                {
                    Status = statusPrefix + "Not enough close points.";
                    return;
                }
                ListAetheryteClosePoints = listAetheryteClosePoints;
                if (dictionaryClosestAetherytes.ContainsKey(ItemName))
                {
                    double distance = dictionaryClosestAetherytes[ItemName];
                    if (distance < minDistanceAetheryte)
                    {
                        Status = statusPrefix + "Other grid is closer to grid points.";
                        return;
                    }
                }
                dictionaryClosestAetherytes[ItemName] = minDistanceAetheryte;

                Status  = statusPrefix + "OK";
                IsValid = true;
            }
            catch (Exception e)
            {
                Status = e.Message;
            }
        }
示例#3
0
        private static List <FFXIVGatheringNode> ReadGatheredNodes(CookieCollection iCookies, ref CookieCollection oCookies, ref HttpStatusCode oCode, JToken dataToken, JToken itemToken, JToken nodeToken)
        {
            List <FFXIVGatheringNode> result = new List <FFXIVGatheringNode>();

            //Adding nodes info
            foreach (JToken gatherNodeToken in nodeToken.Children())
            {
                try
                {
                    string nodeSearchContent = Service_Misc.GetContentFromRequest("GET http://garlandtools.org/db/doc/node/en/2/" + gatherNodeToken.Value <string>() + ".json HTTP/1.1|Host: garlandtools.org|Connection: keep-alive|Accept: application/json, text/javascript, */*; q=0.01|X-Requested-With: XMLHttpRequest|User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36|Referer: http://garlandtools.org/db/|Accept-Encoding: gzip, deflate|Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7|",
                                                                                  iCookies, ref oCookies, ref oCode);

                    try
                    {
                        string logName2 = Path.Combine(Service_Misc.GetExecutionPath(), "Node.log");
                        File.WriteAllText(logName2, nodeSearchContent);
                    }
                    catch
                    {
                    }

                    JToken gatherResultToken = JObject.Parse(nodeSearchContent);
                    if (null == gatherResultToken)
                    {
                        continue;
                    }

                    JToken gatherResultNodeToken = gatherResultToken.Children().ToList()[0].Children().ToList()[0];
                    if (null == gatherResultNodeToken)
                    {
                        continue;
                    }

                    string zoneID = gatherResultNodeToken["zoneid"].Value <string>();

                    JToken locationToken = dataToken["locationIndex"];
                    if (null == locationToken)
                    {
                        continue;
                    }

                    JToken zoneIDToken = locationToken[zoneID];
                    if (null == zoneIDToken)
                    {
                        continue;
                    }

                    JToken zoneNameToken = zoneIDToken["name"];
                    if (null == zoneNameToken)
                    {
                        continue;
                    }

                    string zone          = zoneNameToken.Value <string>();
                    string gatheringType = gatherResultNodeToken["type"].Value <string>();
                    string type          = "";
                    if (null != gatherResultNodeToken["limitType"])
                    {
                        type = gatherResultNodeToken["limitType"].Value <string>();
                    }
                    string name = gatherResultNodeToken["name"].Value <string>();

                    FFXIVGatheringNode gatheringNode = new FFXIVGatheringNode();
                    gatheringNode.JobTrigram = GetGatheringJobName(gatheringType, null);
                    gatheringNode.Name       = name;
                    //gatheringNode.Type = type;
                    gatheringNode.Zone = zone;

                    if (null != gatherResultNodeToken["items"])
                    {
                        foreach (JToken nodeItemToken in gatherResultNodeToken["items"].Children())
                        {
                            if (null == nodeItemToken)
                            {
                                continue;
                            }
                            gatheringNode.NodeItems.Add(GetItemName(nodeItemToken["id"].Value <string>()));
                        }
                    }
                    result.Add(gatheringNode);
                }
                catch (Exception exc)
                {
                    string msg = exc.Message;
                }
            }

            return(result);
        }