private static FFXIVItem ReadReducedItem(System.Windows.Forms.TextBox iLogBox, JToken reducedToken) { FFXIVItem item; FFXIVReducedItem reducedItem = new FFXIVReducedItem(); reducedItem.Type = FFXIVItem.TypeItem.Reduced; string idReducedFrom = reducedToken[0].Value <string>(); FFXIVItem ingredient = RecBuildCraftingTree(iLogBox, idReducedFrom, 5); if (null != ingredient) { reducedItem.ReducedFrom = ingredient; if (ingredient is FFXIVGatheredItem) { FFXIVGatheredItem gatheredItem = ingredient as FFXIVGatheredItem; if (null != gatheredItem) { gatheredItem.AsCollectable = true; } } } else { Service_Misc.LogText(iLogBox, "Oups... failed to retrieve one reduced reference : ID=" + idReducedFrom); } item = reducedItem; return(item); }
public static string GenerateScenario(List <FFXIVItem> iItemToGenerate, MiqobotScenarioOption iOptions, System.Windows.Forms.TextBox iLogBox, out string fullScenario) { fullScenario = ""; if (null == iOptions) { Service_Misc.LogText(iLogBox, "Whoooops wrong options selected..."); return(null); } Service_Misc.LogText(iLogBox, "Let's whisper to miqobot ears..."); MiqoCraftOptions options = new MiqoCraftOptions(); options.Load(OptionLocation.UserOption); //Login to miqobot forums CookieCollection logMiqobotCookies = Miqobot.LogInForum(); if (null != logMiqobotCookies) { Service_Misc.LogText(iLogBox, "I'm logged into miqobot forum !"); } else { Service_Misc.LogText(iLogBox, "Failed to log into miqobot forum... well you'll have to manually gather stuff, sorry !"); } //Listing items List <FFXIVItem> allItems = new List <FFXIVItem>(); List <int> allItemsQuantity = new List <int>(); string scenarioName = ""; foreach (FFXIVItem iItem in iItemToGenerate) { if (null == iItem) { continue; } if (scenarioName != "") { scenarioName += ","; } scenarioName += iItem.Name; RecFindItems(iItem, iOptions.Quantity, ref allItems, ref allItemsQuantity, iOptions.CustomQuantities); } if (iItemToGenerate.Count > 5) { scenarioName = iItemToGenerate.Count + " Items"; } fullScenario = ""; string allGrids = ""; string allRotations = ""; string allPreset = ""; List <string> catalysts = GetCatalysts(); if (!iOptions.IgnoreCatalysts) { catalysts.Clear(); } //Creating rotations allRotations += "gatherrotation.Collect Gathering +15%" + Environment.NewLine; allRotations += "[31,9,22,26,25,[34,[35,29,36,26]],25,[34,[35,29,36,26]],23,1,32]" + Environment.NewLine; allRotations += "gatherrotation.Collect Gathering +5%" + Environment.NewLine; allRotations += "[31,9,22,26,25,[34,[35,29,36,26]],25,[34,[35,29,36,26]],23,0]" + Environment.NewLine; allRotations += "gatherrotation.Gathering +15%/HQ +10%" + Environment.NewLine; allRotations += "[31,1,3]" + Environment.NewLine; allRotations += "gatherrotation.HQ +10%" + Environment.NewLine; allRotations += "[31,3]" + Environment.NewLine; allRotations += "gatherrotation.Gathering +5%/HQ +10%" + Environment.NewLine; allRotations += "[31,0,3]" + Environment.NewLine; allRotations += MiqoCraftCore.GetCacheRotations() + Environment.NewLine;; //Creating default preset allPreset += "solverpreset.recommended" + Environment.NewLine; allPreset += "{\"cpchunk\":4,\"skillinnovation\":true,\"skillmanipulation\":false,\"skillwastenot1\":false,\"skillwastenot2\":false,\"skillwhistle\":false,\"progresssolver\":true,\"enforcebb100\":true,\"enforcepbp100\":true,\"ignorequality\":false,\"reclaimhqon\":false,\"reclaimhqvalue\":85,\"reclaimqualityon\":false,\"reclaimqualityvalue\":4000}" + Environment.NewLine; allPreset += MiqoCraftCore.GetCacheSolverPresets() + Environment.NewLine;; //Header Service_Misc.LogText(iLogBox, "Creating scenario header..."); fullScenario += "\""; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "// " + scenarioName + Environment.NewLine; fullScenario += "// Script Generated by MiqoCrafter" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "// Copyright 2019 - Shishio Valentine" + Environment.NewLine; fullScenario += "// [email protected]" + Environment.NewLine; fullScenario += "// http://patreon.com/miqocrafter" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; //Prerequisite fullScenario += Environment.NewLine; fullScenario += Environment.NewLine; fullScenario += "// Prerequisite" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "//" + Environment.NewLine; if (iOptions.IgnoreCatalysts) { fullScenario += "// You will need to buy or obtain those items using external means, cause Miqocrafter can't automate it [Yet], or they are ignored catalysts" + Environment.NewLine; } else { fullScenario += "// You will need to buy or obtain those items using external means, cause Miqocrafter can't automate it [Yet]" + Environment.NewLine; } for (int i = 0; i < allItems.Count && i < allItemsQuantity.Count; i++) { FFXIVItem iItem = allItems[i]; if (null == iItem) { continue; } int quantity = allItemsQuantity[i]; FFXIVCraftingOptions itemOptions = options.GetOption(iItem); if (iItem.Type == FFXIVItem.TypeItem.NPC || iItem.Type == FFXIVItem.TypeItem.Unkwown || null != catalysts.Find(x => x != null && x.ToLower() == iItem.Name.ToLower()) || (null != itemOptions && itemOptions.IgnoreItem)) { fullScenario += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; } } //Reduced fullScenario += Environment.NewLine; fullScenario += Environment.NewLine; fullScenario += "// Reduced Items" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "//" + Environment.NewLine; fullScenario += "// You will need to manually reduce those items, cause Miqocrafter can't automate it [Yet]" + Environment.NewLine; fullScenario += "// However Miqocrafter will try to gather/craft/retrieve the items that need to be reduced." + Environment.NewLine; for (int i = 0; i < allItems.Count && i < allItemsQuantity.Count; i++) { FFXIVItem iItem = allItems[i]; if (null == iItem) { continue; } int quantity = allItemsQuantity[i]; FFXIVReducedItem reducedItem = null; if (iItem is FFXIVReducedItem) { reducedItem = iItem as FFXIVReducedItem; } if (null != reducedItem) { if (null != reducedItem.ReducedFrom) { fullScenario += "// - " + iItem.Name + " (Reduced from " + reducedItem.ReducedFrom + " - " + iItem.UrlGarland + ")" + Environment.NewLine; } else { fullScenario += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; } } } //Errors fullScenario += "ERRORS_ITEMS_DUMMY"; fullScenario += "\","; //Getting miqo preset content string miqoPresetContent = ""; if (null != iOptions.MiqoPresetPath && "" != iOptions.MiqoPresetPath) { FileInfo presetFile = new FileInfo(Path.Combine(iOptions.MiqoPresetPath, "presets.miqo")); if (presetFile.Exists) { miqoPresetContent = File.ReadAllText(presetFile.FullName); } } if (miqoPresetContent == "" && null != options.MiqoPresetPath && "" != options.MiqoPresetPath) { FileInfo presetFile = new FileInfo(Path.Combine(options.MiqoPresetPath, "presets.miqo")); if (presetFile.Exists) { miqoPresetContent = File.ReadAllText(presetFile.FullName); } } //Gathering stuff string lastTeleport = ""; string errorContent = ""; Service_Misc.LogText(iLogBox, "Creating gathering grids..."); fullScenario += "\""; fullScenario += Environment.NewLine; fullScenario += Environment.NewLine; fullScenario += "// Gathered Items" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "//" + Environment.NewLine; fullScenario += "// Miqocrafter will use the gathering scenario from https://miqobot.com/forum/forums/topic/index-gathering-grids/ to retrieve those." + Environment.NewLine; for (int i = 0; i < allItems.Count && i < allItemsQuantity.Count; i++) { FFXIVItem iItem = allItems[i]; if (null == iItem) { continue; } int quantity = allItemsQuantity[i] / iOptions.NbPerNode + 1; if (!(iItem is FFXIVGatheredItem)) { continue; } FFXIVGatheredItem gatheredItem = iItem as FFXIVGatheredItem; if (null != catalysts.Find(x => x != null && x.ToLower() == iItem.Name.ToLower())) { continue; } FFXIVCraftingOptions itemOptions = options.GetOption(iItem); if (null != itemOptions && itemOptions.IgnoreItem) { continue; } if (null != gatheredItem) { Service_Misc.LogText(iLogBox, "Searching for item grid : " + iItem + ""); if (gatheredItem.Slot.Count <= 0) { errorContent += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; fullScenario += "// Failed to retrieve item gathering slot from FGarlandTool, can't gather this item " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; continue; } if (null != logMiqobotCookies) { List <MiqoItemPage> listItemPage = Miqobot.GetURLItem(iItem.Name, logMiqobotCookies, null); if (listItemPage.Count <= 0) { errorContent += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; fullScenario += "// Failed to retrieve item gathering scenario from miqobot forums, can't gather this item " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; } else { string initName = ""; string grid = null; for (int j = 0; j < listItemPage.Count && null == grid; j++) { grid = Miqobot.GetLastGrid(iItem.Name, logMiqobotCookies, listItemPage[j], out initName); } if (null != grid) { //Finding right zone string zone = ""; string type = ""; string slot = ""; string time = ""; string gatheringType = ""; if (gatheredItem.Slot.Count == 1) { //No ambiguity zone = gatheredItem.Zones[0]; type = gatheredItem.Types[0]; slot = gatheredItem.Slot[0]; time = gatheredItem.Times[0]; gatheringType = gatheredItem.GatheringTypes[0]; } else { if (zone == "") { foreach (string zoneName in gatheredItem.Zones) { string initNameCorrected = initName.Replace(" ", "").ToLower(); string gridDataCorrected = grid.Replace(" ", "").ToLower(); string zoneNameCorrected = zoneName.ToLower().Replace("the ", "").Replace(" ", "").Trim(); if (initNameCorrected.Contains(zoneNameCorrected)) { int index = gatheredItem.Zones.IndexOf(zoneName); zone = gatheredItem.Zones[index]; type = gatheredItem.Types[index]; slot = gatheredItem.Slot[index]; time = gatheredItem.Times[index]; gatheringType = gatheredItem.GatheringTypes[index]; break; } if (gridDataCorrected.Contains(zoneNameCorrected)) { int index = gatheredItem.Zones.IndexOf(zoneName); zone = gatheredItem.Zones[index]; type = gatheredItem.Types[index]; slot = gatheredItem.Slot[index]; time = gatheredItem.Times[index]; gatheringType = gatheredItem.GatheringTypes[index]; break; } } } } if (zone == "") { errorContent += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; fullScenario += "// Failed to retrieve item gathering zone from miqobot grid, can't gather this item " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; continue; } //Find teleport item string teleportTo = GarlandTool.GetTeleportName(zone, grid, gatheredItem); //Compute grid name from miqo presets, to avoid duplicates string gridName = iItem.Name + " Grid"; int indexGrid = 1; while (miqoPresetContent.Contains("grid." + gridName + Environment.NewLine)) { string oldGridName = gridName; gridName = iItem.Name + " Grid" + indexGrid; grid = grid.Replace("grid." + oldGridName + Environment.NewLine, "grid." + gridName + Environment.NewLine); indexGrid++; } //Embed grid allGrids += grid + Environment.NewLine; //Get preset string preset = MiqoCraftCore.GetCraftingPreset(gatheringType, slot, gatheredItem, iOptions.GatheringRotation, gridName, time); //Compute preset name from miqo presets, to avoid duplicates string presetName = iItem.Name + " preset"; int indexpreset = 1; while (miqoPresetContent.Contains("gatherpreset." + presetName + Environment.NewLine)) { string oldpresetName = presetName; presetName = iItem.Name + " preset" + indexpreset; preset = preset.Replace("gatherpreset." + oldpresetName + Environment.NewLine, "gatherpreset." + presetName + Environment.NewLine); indexpreset++; } //Embed a new preset allPreset += preset; //Add gathering rotation to scenario //Add gathering rotation to scenario //teleportIf(Black Brush Station)\r\nunstealth()\r\nchangeJob(Miner)\r\nselectGrid(Min5-Copper Ore)\r\nselectGatherPreset(Metal Worm Jar- Copper Ore)\r\nstartGathering(4) //teleportIfNotThere fullScenario += "// Gathering " + iItem.Name + Environment.NewLine; if (lastTeleport == "" || lastTeleport == teleportTo) { fullScenario += "teleport(" + teleportTo + ")" + Environment.NewLine; } else { fullScenario += "teleportIfNotThere(" + teleportTo + ")" + Environment.NewLine; } lastTeleport = teleportTo; //Adding custom scenario after teleport DirectoryInfo customDirectory = new DirectoryInfo(Path.Combine(Service_Misc.GetExecutionPath(), "CustomTeleport")); if (!customDirectory.Exists) { customDirectory.Create(); } FileInfo customTeleportScenarioFile = new FileInfo(Path.Combine(customDirectory.FullName, teleportTo + " Scenario.txt")); if (customTeleportScenarioFile.Exists) { fullScenario += File.ReadAllText(customTeleportScenarioFile.FullName) + Environment.NewLine; } FileInfo customTeleportGridFile = new FileInfo(Path.Combine(customDirectory.FullName, teleportTo + " Grid.txt")); if (customTeleportGridFile.Exists) { allGrids += File.ReadAllText(customTeleportGridFile.FullName) + Environment.NewLine; } //fullScenario += "unstealth()" + Environment.NewLine; fullScenario += "changeJob(" + GarlandTool.GetGatheringJobName(gatheringType, iItem) + ")" + Environment.NewLine; fullScenario += "selectGrid(" + gridName + ")" + Environment.NewLine; fullScenario += "selectGatherPreset(" + presetName + ")" + Environment.NewLine; if (null != gatheredItem && gatheredItem.AsCollectable) { fullScenario += "rotationIfGP(470 Collect 5% Gathering)" + Environment.NewLine; fullScenario += "rotationIfGP(470 Collect 15% Gathering)" + Environment.NewLine; } else { fullScenario += "rotationIfGP(" + iOptions.GatheringRotation + ")" + Environment.NewLine; } fullScenario += "startGathering(" + quantity + ")" + Environment.NewLine; fullScenario += Environment.NewLine; } else { errorContent += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; fullScenario += "// Failed to retrieve the grid from miqobot forums, can't gather this item " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; } } } else { errorContent += "// - " + quantity + "x " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; fullScenario += "// Failed to log into miqobot forums, can't gather this item " + iItem.Name + " (see " + iItem.UrlGarland + ")" + Environment.NewLine; } } } fullScenario += "\","; //Crafting stuff Service_Misc.LogText(iLogBox, "Generating craft scenario..."); fullScenario += "\""; fullScenario += Environment.NewLine; fullScenario += Environment.NewLine; fullScenario += "// Crafted Items" + Environment.NewLine; fullScenario += "//--------------------------------------------------------------" + Environment.NewLine; fullScenario += "//" + Environment.NewLine; fullScenario += "solverPreset(" + iOptions.CraftPreset + ")" + Environment.NewLine; fullScenario += "nqhq(" + iOptions.NQHQPreset + ")" + Environment.NewLine; fullScenario += "reclaimOff()" + Environment.NewLine; string teleportCraft = iOptions.CustomTeleport; if (teleportCraft != "") { fullScenario += "teleport(" + teleportCraft + ")" + Environment.NewLine; } List <FFXIVCraftedItem> listAllCraftedItems = new List <FFXIVCraftedItem>(); for (int i = 0; i < allItems.Count && i < allItemsQuantity.Count; i++) { FFXIVItem iItem = allItems[i]; if (null == iItem) { continue; } int quantity = allItemsQuantity[i]; FFXIVCraftedItem craftedItem = null; if (iItem is FFXIVCraftedItem) { craftedItem = iItem as FFXIVCraftedItem; } if (null != craftedItem) { listAllCraftedItems.Add(craftedItem); } } for (int i = 0; i < allItems.Count && i < allItemsQuantity.Count; i++) { FFXIVItem iItem = allItems[i]; if (null == iItem) { continue; } int quantity = allItemsQuantity[i]; FFXIVCraftedItem craftedItem = null; if (iItem is FFXIVCraftedItem) { craftedItem = iItem as FFXIVCraftedItem; } FFXIVCraftingOptions itemOptions = options.GetOption(iItem); if (null != itemOptions && itemOptions.IgnoreItem) { continue; } if (null != craftedItem) { fullScenario += "// " + craftedItem + Environment.NewLine; int indexCraftedItem = listAllCraftedItems.IndexOf(craftedItem); if (listAllCraftedItems.IndexOf(craftedItem) >= listAllCraftedItems.Count - 1 && iOptions.Collectable) { fullScenario += "setCraftCollect(on)" + Environment.NewLine; } else { fullScenario += "setCraftCollect(off)" + Environment.NewLine; } fullScenario += "job(" + craftedItem.Class + ")" + Environment.NewLine; fullScenario += "recipe(" + craftedItem.Name + ")" + Environment.NewLine; if (null != itemOptions && itemOptions.CustomCraftingMacro != "") { fullScenario += "selectCraftMacro(" + itemOptions.CustomCraftingMacro + ")" + Environment.NewLine; } fullScenario += "craft(" + quantity + ")" + Environment.NewLine; if (listAllCraftedItems.IndexOf(craftedItem) >= listAllCraftedItems.Count - 1 && iOptions.Collectable) { fullScenario += "setCraftCollect(off)" + Environment.NewLine; } if (null != itemOptions && itemOptions.CustomCraftingMacro != "") { fullScenario += "solverPreset(" + iOptions.CraftPreset + ")" + Environment.NewLine; } fullScenario += Environment.NewLine; } } fullScenario += "\""; if (errorContent == "") { fullScenario = fullScenario.Replace("ERRORS_ITEMS_DUMMY", ""); } else { string scenarioError = ""; scenarioError += Environment.NewLine; scenarioError += Environment.NewLine; scenarioError += "// Items without grid / Miqocrafter couldn't automate" + Environment.NewLine; scenarioError += "//--------------------------------------------------------------" + Environment.NewLine; scenarioError += "//" + Environment.NewLine; scenarioError += "// You will need to buy or obtain those items using external means, cause Miqocrafter can't automate it [Yet]" + Environment.NewLine; scenarioError += errorContent; scenarioError += Environment.NewLine; fullScenario = fullScenario.Replace("ERRORS_ITEMS_DUMMY", scenarioError); } string textFileContent = "scenario.Craft " + scenarioName + Environment.NewLine; textFileContent += "{ \"chapters\":["; textFileContent += fullScenario.Replace(Environment.NewLine, "\\r\\n").Replace("/", "\\/"); textFileContent += "]}" + Environment.NewLine; textFileContent += allRotations + Environment.NewLine; textFileContent += allGrids + Environment.NewLine; textFileContent += allPreset + Environment.NewLine; while (textFileContent.Contains(Environment.NewLine + Environment.NewLine)) { textFileContent = textFileContent.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); } return(textFileContent); }
/// <summary> /// Recursively build an item craft tree /// </summary> /// <param name="iItem"></param> public static FFXIVItem RecBuildCraftingTree(System.Windows.Forms.TextBox iLogBox, string iItemID, int quantity = 1) { if (null == iItemID) { return(null); } //https://www.garlandtools.org/db/doc/item/en/3/26498.json FFXIVItem item = null; CookieCollection iCookies = new CookieCollection(); CookieCollection oCookies = new CookieCollection(); HttpStatusCode oCode = HttpStatusCode.NotFound; string searchResultContent = Service_Misc.GetContentFromRequest("GET https://www.garlandtools.org/db/doc/item/en/3/" + iItemID + ".json HTTP/1.1|Host: www.garlandtools.org|Connection: keep-alive|Pragma: no-cache|Cache-Control: no-cache|Upgrade-Insecure-Requests: 1|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|Sec-Fetch-Mode: navigate|Sec-Fetch-User: ?1|Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3|Sec-Fetch-Site: cross-site|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(), "Searchlog.log"); File.WriteAllText(logName2, searchResultContent); } catch { } string logName = Path.Combine(Service_Misc.GetExecutionPath(), "GeneralDataBase.log"); string dataResultContent = ""; if (File.Exists(logName)) { dataResultContent = File.ReadAllText(logName); } if (dataResultContent == "") { dataResultContent = Service_Misc.RemoveIllegalCharacters(Service_Misc.GetContentFromRequest("GET http://garlandtools.org/db/doc/core/en/3/data.json HTTP/1.1|Host: garlandtools.org|Connection: keep-alive|Pragma: no-cache|Cache-Control: no-cache|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 { File.WriteAllText(logName, dataResultContent); } catch { } } try { JToken mainToken = JObject.Parse(searchResultContent); if (null == mainToken) { return(item); } JToken dataToken = JObject.Parse(dataResultContent); if (null == dataToken) { return(item); } JToken itemToken = mainToken["item"]; if (null == itemToken) { return(item); } JToken mainIngredientToken = mainToken["ingredients"]; List <JToken> allIngredientsToken = new List <JToken>(); List <string> allIngredientsIDs = new List <string>(); if (null != mainIngredientToken) { //Listing ingredients nodes and ID foreach (JToken ingredientToken in mainIngredientToken.Children()) { if (null == ingredientToken) { continue; } string ID = ingredientToken["id"].Value <string>(); allIngredientsIDs.Add(ID); allIngredientsToken.Add(ingredientToken); } } item = CreateItemFromNode(iLogBox, iCookies, ref oCookies, ref oCode, itemToken, dataToken, allIngredientsToken, allIngredientsIDs); if (null != item) { item.Quantity = quantity; } } catch (Exception exc) { Service_Misc.LogText(iLogBox, "Ouch I failed !"); Service_Misc.LogText(iLogBox, exc.Message); } if (null != item) { Service_Misc.LogText(iLogBox, "Got this item ! " + item); } return(item); }
private static FFXIVItem CreateItemFromNode(System.Windows.Forms.TextBox iLogBox, CookieCollection iCookies, ref CookieCollection oCookies, ref HttpStatusCode oCode, JToken iItemNode, JToken iDataNode, List <JToken> iIngredientsToken, List <string> iIngredienstIDs) { FFXIVItem item = null; if (null == iItemNode) { return(null); } JToken itemToken = iItemNode; if (null == itemToken) { return(item); } JToken craftToken = itemToken["craft"]; JToken nodeToken = itemToken["nodes"]; JToken reducedToken = itemToken["reducedFrom"]; JToken tradeShop = itemToken["tradeShops"]; JToken vendor = itemToken["vendors"]; if (null != craftToken) { FFXIVCraftedItem craftedItem = new FFXIVCraftedItem(); craftedItem.Type = FFXIVItem.TypeItem.Crafted; string jobID = craftToken[0]["job"].Value <string>(); craftedItem.Class = GetJobName(jobID); craftedItem.UrlClass = "http://garlandtools.org/files/icons/job/" + craftedItem.Class + ".png"; craftedItem.Level = craftToken[0]["lvl"].Value <string>(); int yieldQuantity = 1; JToken yieldToken = craftToken[0]["yield"]; if (null != yieldToken) { yieldQuantity = yieldToken.Value <int>(); } craftedItem.RecipeQuantity = yieldQuantity; //Building craft requirement list foreach (JToken ingredientToken in craftToken[0]["ingredients"].Children()) { if (null == ingredientToken) { continue; } string ingredientID = ingredientToken["id"].Value <string>(); //Finding right ingredient token from input list, with all informations JToken fullIngredientNode = ingredientToken; int indexInList = iIngredienstIDs.IndexOf(ingredientID); FFXIVItem ingredient = null; if (indexInList >= 0 && indexInList < iIngredientsToken.Count) { fullIngredientNode = iIngredientsToken[indexInList]; ingredient = CreateItemFromNode(iLogBox, iCookies, ref oCookies, ref oCode, fullIngredientNode, iDataNode, iIngredientsToken, iIngredienstIDs); } else { ingredient = RecBuildCraftingTree(iLogBox, ingredientID, 1); } //Adding Item if (null != ingredient) { ingredient.Quantity = ingredientToken["amount"].Value <int>(); craftedItem.ListNeededItems.Add(ingredient); } else { Service_Misc.LogText(iLogBox, "Oups... failed to retrieve one ingredient : ID=" + ingredientToken["id"].Value <string>()); } } item = craftedItem; } else if (null != nodeToken) { FFXIVGatheredItem gatheredItem = ReadGatheredItem(iCookies, ref oCookies, ref oCode, iDataNode, itemToken, nodeToken); item = gatheredItem; item.Type = FFXIVItem.TypeItem.Gathered; } else if (null != reducedToken) { item = ReadReducedItem(iLogBox, reducedToken); } else if (null != tradeShop || null != vendor) { item = new FFXIVItem(); item.Type = FFXIVItem.TypeItem.NPC; } else { item = new FFXIVItem(); item.Type = FFXIVItem.TypeItem.Unkwown; Service_Misc.LogText(iLogBox, "Oups... one ingredient is unknown, don't know how to get this one."); } if (null != item) { try { item.Name = itemToken["name"].Value <string>(); item.UrlImage = "http://garlandtools.org/files/icons/item/" + itemToken["icon"].Value <string>() + ".png"; item.UrlGarland = "http://garlandtools.org/db/#item/" + itemToken["id"].Value <string>(); item.ID = itemToken["id"].Value <string>(); } catch (Exception) { Service_Misc.LogText(iLogBox, "Oups... failed to retrieve one item : Token=" + Environment.NewLine + iItemNode.ToString()); } } return(item); }
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); }