Exemple #1
0
        public void TestFullScenarioImpl(string iItemName, FFXIVItem.TypeItem iExpectedType, int iNbExpectedItems = 1, int iPosItemInList = 0, string iRealName = "", bool iIgnoreCatalyst = false, int iQuantity = 1, bool iCollectable = false, int iNbPerSlot = 1, string iCustomTeleport = "")
        {
            InitTestEnvironment();

            string elemToSearch          = iItemName;
            int    nbExpectedSearchItems = iNbExpectedItems;
            int    nbItemInList          = iPosItemInList;
            string itemFullName          = iRealName;

            if (itemFullName.Length <= 0)
            {
                itemFullName = iItemName;
            }
            FFXIVItem.TypeItem expectedType = iExpectedType;

            List <FFXIVSearchItem> listResults = GarlandTool.Search(elemToSearch, null);

            if (listResults.Count != nbExpectedSearchItems)
            {
                throw new Exception("Erreur de recherche de " + elemToSearch + ": " + listResults.Count + " items found while " + nbExpectedSearchItems + " expected.");
            }

            FFXIVItem item = listResults[nbItemInList];

            if (item.Name != itemFullName)
            {
                throw new Exception("Item name is not the expected one: " + item.Name + ", expected : " + itemFullName);
            }

            FFXIVItem itemToCraft = GarlandTool.RecBuildCraftingTree(null, item.ID);

            if (itemToCraft.Type != expectedType)
            {
                throw new Exception("Item type is not the expected one: " + itemToCraft.Type + ", expected : " + expectedType);
            }

            string        solution_dir = Service_Misc.GetExecutionPath();
            DirectoryInfo refDirectory = new DirectoryInfo(Path.Combine(solution_dir, "References"));

            if (!refDirectory.Exists)
            {
                throw new Exception("Reference directory " + refDirectory.FullName + " does not exist");
            }

            MiqoCraftCore.MiqoCraftCore.MiqobotScenarioOption options = new MiqoCraftCore.MiqoCraftCore.MiqobotScenarioOption();
            options.GatheringRotation = "HQ +10%";
            options.CraftPreset       = "recommended";
            options.NQHQPreset        = "balanced";
            options.CustomTeleport    = iCustomTeleport;
            options.Quantity          = iQuantity;
            options.NbPerNode         = iNbPerSlot;
            options.Collectable       = iCollectable;
            options.IgnoreCatalysts   = iIgnoreCatalyst;

            string fullScenario = "";
            string res          = MiqoCraftCore.MiqoCraftCore.GenerateScenario(itemToCraft, options, null, out fullScenario);

            FileInfo refFile = new FileInfo(Path.Combine(refDirectory.FullName, itemFullName + _dumpSuffix + ".txt"));

            string pathResult = refFile.FullName.Replace(".txt", "_runresult.txt");

            File.WriteAllText(pathResult, res);
            if (_updateDumps)
            {
                File.WriteAllText(refFile.FullName, res);
            }
            string fullScenarioResult = File.ReadAllText(pathResult);

            FileInfo refScenarioFile = new FileInfo(Path.Combine(refDirectory.FullName, itemFullName + _dumpSuffix + " Scenario.txt"));

            pathResult = refScenarioFile.FullName.Replace(".txt", "_runresult.txt");
            File.WriteAllText(pathResult, fullScenario);
            if (_updateDumps)
            {
                File.WriteAllText(refScenarioFile.FullName, fullScenario);
            }

            if (!refFile.Exists)
            {
                throw new Exception("Reference file " + refFile.FullName + " does not exist");
            }
            string fullScenarioReference = File.ReadAllText(refFile.FullName);

            //Testing miqobot scenario
            if (fullScenarioResult.Trim() != fullScenarioReference.Trim())
            {
                throw new Exception("Resulting scenario does not match.; See " + refFile.FullName);
            }

            //Testing plain text scenario
            fullScenarioResult = File.ReadAllText(pathResult);

            if (!refScenarioFile.Exists)
            {
                throw new Exception("Reference file " + refScenarioFile.FullName + " does not exist");
            }
            string fullScenarioTextReference = File.ReadAllText(refScenarioFile.FullName);

            if (fullScenarioResult.Trim() != fullScenarioTextReference.Trim())
            {
                throw new Exception("Resulting scenario text does not match.; See " + refScenarioFile.FullName);
            }
        }
Exemple #2
0
        public static List <FFXIVSearchItem> Search(string iElemToSearch, System.Windows.Forms.TextBox iLogBox = null, FFXIVItem.TypeItem iType = FFXIVItem.TypeItem.Crafted, List <string> iJobs = null, int iMinLevel = 0, int iMaxLevel = 0)
        {
            Service_Misc.LogText(iLogBox, "Let me search this item for you : " + iElemToSearch);
            CookieCollection iCookies = new CookieCollection();
            CookieCollection oCookies = new CookieCollection();
            HttpStatusCode   oCode    = HttpStatusCode.NotFound;

            bool itemAdded = true;
            int  pageNb    = 0;
            List <FFXIVSearchItem> listItems = new List <FFXIVSearchItem>();

            while (itemAdded)
            {
                itemAdded = false;

                string searchString = iElemToSearch.ToLower().Replace(" ", "+");
                //http://garlandtools.org/api/search.php?lang=en&ilvlMax=5&craftable=1
                string lvlMinString = "";
                string lvlMaxString = "";
                string category     = "";
                //if (iMinLevel > 0) lvlMinString = "&ilvlMin=" + iMinLevel;
                //if (iMaxLevel > 0) lvlMaxString = "&ilvlMax=" + iMaxLevel;
                if (iType == FFXIVItem.TypeItem.Crafted)
                {
                    category = "&craftable=1";
                }
                string searchResultContent = Service_Misc.GetContentFromRequest("GET http://garlandtools.org/api/search.php?text=" + searchString + "&lang=en&page=" + pageNb + lvlMinString + lvlMaxString + category + " 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);
                pageNb++;

                string innerHTML = "{\"Result\":" + searchResultContent + "}";

                JToken mainToken = null;
                try
                {
                    mainToken = JObject.Parse(innerHTML);
                    if (null == mainToken)
                    {
                        throw new Exception("Impossible de récupérer l'identifiant de connexion à partir du site");
                    }
                }
                catch (Exception)
                {
                    continue;
                }

                JToken listToken = mainToken["Result"];
                if (listToken.Count() > 0)
                {
                    Service_Misc.LogText(iLogBox, "Hey I found some items !");
                    itemAdded = true;
                }
                else
                {
                    Service_Misc.LogText(iLogBox, "Looks like there is no more items to find... (Page " + pageNb + ")");
                    return(listItems);
                }
                foreach (JToken childToken in listToken.Children())
                {
                    if (null == childToken)
                    {
                        continue;
                    }

                    string itemName  = "Unknown Item";
                    JToken dataToken = childToken["obj"];
                    if (null != dataToken && null != dataToken["n"])
                    {
                        itemName = dataToken["n"].Value <string>();
                    }
                    string type = childToken["type"].Value <string>();
                    if (type != "item")
                    {
                        Service_Misc.LogText(iLogBox, "Found something but it ain't an item : " + itemName + " - " + type);
                        continue;
                    }

                    try
                    {
                        FFXIVSearchItem item = new FFXIVSearchItem();

                        item.Name       = itemName;
                        item.UrlImage   = "http://garlandtools.org/files/icons/item/" + dataToken["c"].Value <string>() + ".png";
                        item.UrlGarland = "http://garlandtools.org/db/#item/" + dataToken["i"].Value <string>();

                        if (dataToken["f"] != null && iType == FFXIVItem.TypeItem.Crafted)
                        {
                            string jobID     = dataToken["f"][0]["job"].Value <string>();
                            string itemClass = GetJobName(jobID);
                            string itemLevel = dataToken["f"][0]["lvl"].Value <string>();
                            int    level     = 0;
                            int.TryParse(itemLevel, out level);
                            if (iMinLevel > 0 && level < iMinLevel)
                            {
                                Service_Misc.LogText(iLogBox, "Found something but its level is under the requested min level : " + itemName + " - Level : " + itemLevel);
                                continue;
                            }
                            if (iMaxLevel > 0 && level > iMaxLevel)
                            {
                                Service_Misc.LogText(iLogBox, "Found something but its level is over the requested max level : " + itemName + " - Level : " + itemLevel);
                                continue;
                            }

                            if (null != iJobs && iJobs.Count > 0 && !iJobs.Contains(itemClass.ToUpper()) && !iJobs.Contains(itemClass.ToLower()))
                            {
                                Service_Misc.LogText(iLogBox, "Found something but its job is not in the requested list : " + itemName + " - Job : " + itemClass);
                                continue;
                            }
                            item.Class = itemClass;
                            item.Level = itemLevel;
                        }
                        else if (iType == FFXIVItem.TypeItem.Crafted)
                        {
                            Service_Misc.LogText(iLogBox, "Found something but it ain't for crafting : " + itemName);
                            continue;
                        }

                        item.ID = childToken["id"].Value <string>();

                        Service_Misc.LogText(iLogBox, "Found this item : " + item.ToString());

                        listItems.Add(item);
                        itemAdded = true;
                    }
                    catch (Exception exc)
                    {
                        Service_Misc.LogText(iLogBox, "Oh man, I failed to retrieve an item from the list : ");
                        Service_Misc.LogText(iLogBox, itemName);
                        Service_Misc.LogText(iLogBox, exc.Message);
                    }
                }
            }

            listItems.Sort();
            return(listItems);
        }