Пример #1
0
        /// <summary>
        /// Create list of items to display
        /// </summary>
        /// <param name="iItem"></param>
        /// <param name="iQuantity"></param>
        /// <param name="allItems"></param>
        /// <param name="allItemsQuantity"></param>
        public static void RecFindItems(FFXIVItem iItem, int iQuantity, ref List <FFXIVItem> allItems, ref List <int> allItemsQuantity, Dictionary <string, int> CustomQuantities)
        {
            if (null == iItem)
            {
                return;
            }
            FFXIVCraftedItem craftedItem = null;

            if (iItem is FFXIVCraftedItem)
            {
                craftedItem = iItem as FFXIVCraftedItem;
            }

            FFXIVReducedItem reducedItem = null;

            if (iItem is FFXIVReducedItem)
            {
                reducedItem = iItem as FFXIVReducedItem;
            }

            int quantity = iQuantity * iItem.Quantity;

            bool hasFixedQuantity = false;

            if (CustomQuantities.ContainsKey(iItem.ID))
            {
                hasFixedQuantity = true;
                quantity         = CustomQuantities[iItem.ID];
            }
            //if (quantity <= 0) return;

            //Correcting quantity by yield value
            double currentQuantity = (double)quantity;
            double yieldQuantityD  = (double)1;

            if (null != craftedItem)
            {
                yieldQuantityD = (double)craftedItem.RecipeQuantity;
            }
            double correctedQuantity = currentQuantity / yieldQuantityD + (yieldQuantityD - 0.95 /*For numeric error*/) / yieldQuantityD;

            quantity = (int)correctedQuantity;

            if (null != craftedItem)
            {
                foreach (FFXIVItem ingredient in craftedItem.ListNeededItems)
                {
                    RecFindItems(ingredient, quantity, ref allItems, ref allItemsQuantity, CustomQuantities);
                }
            }
            if (null != reducedItem)
            {
                RecFindItems(reducedItem.ReducedFrom, quantity, ref allItems, ref allItemsQuantity, CustomQuantities);
            }

            FFXIVItem existingItem = allItems.Find(x => x != null && x.ID == iItem.ID);

            if (null != existingItem)
            {
                int index = allItems.IndexOf(existingItem);
                if (index >= 0 && index < allItemsQuantity.Count)
                {
                    if (hasFixedQuantity)
                    {
                        allItemsQuantity[index] = quantity;
                    }
                    else
                    {
                        allItemsQuantity[index] = allItemsQuantity[index] + (quantity);
                    }
                }
            }
            else
            {
                allItems.Add(iItem);
                allItemsQuantity.Add(quantity);
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }