示例#1
0
 public static bool MatchTargetTabItem(Item item, TargetTab targetTab)
 {
     foreach (string rG in targetTab.regexGroups)
     {
         if (RegexGroup.MatchItem(item, rG))
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        private void CreatePlan()
        {
            #region Clean inventory
            //Clean inventory
            Queue <Item> currentInventory_initial = new Queue <Item>(inventory.items.Where(x => true));

            Item inventItem_initial = null;
            while (currentInventory_initial.TryDequeue(out inventItem_initial))
            {
                if (!ToolBox.MoveItem(inventory, trashTab, inventItem_initial, moveOrganizer))
                {
                    //Move to trashtab if full
                    if (!ToolBox.MoveItem(inventory, trashTab, inventItem_initial, moveOrganizer))
                    {
                        throw new Exception("No room in trash tab, terminating!");
                    }
                }
            }
            #endregion

            #region Clean Droptabs
            //Clean drop tabs
            List <TargetTab> sortedTargetTabs = config.targetTabs.OrderBy(x => x.order).ToList();

            foreach (StashTab source in sourceTabs)
            {
                foreach (TargetTab target in sortedTargetTabs)
                {
                    StashTab targetTab = targetTabs.Single(x => target.targetStashes.Contains(x.name));

                    Queue <Item> matchesTarg = new Queue <Item>(source.items.Where(x => ToolBox.MatchTargetTabItem(x, target)));

                    //Move item to inventory
                    Item currentItem = null;
                    while (matchesTarg.TryDequeue(out currentItem))
                    {
                        if (!ToolBox.MoveItem(source, inventory, currentItem, moveOrganizer))
                        {
                            //When inventory full, move items from inventory to targetTab
                            Queue <Item> currentInventory = new Queue <Item>(inventory.items.Where(x => true));

                            Item inventItem = null;
                            while (currentInventory.TryDequeue(out inventItem))
                            {
                                bool inserted = false;

                                foreach (StashTab chaosTab in chaosRecipeTabs)
                                {
                                    if (ToolBox.MoveItemToChaosRecipeTab(inventory, chaosTab, inventItem, moveOrganizer, config))
                                    {
                                        inserted = true;
                                        break;
                                    }
                                }

                                if (inserted == false && !ToolBox.MoveItem(inventory, targetTab, inventItem, moveOrganizer))
                                {
                                    //Move to trashtab if full
                                    if (!ToolBox.MoveItem(inventory, trashTab, inventItem, moveOrganizer))
                                    {
                                        throw new Exception("No room in trash tab, terminating!");
                                    }
                                }
                            }

                            if (!ToolBox.MoveItem(source, inventory, currentItem, moveOrganizer))
                            {
                                throw new Exception("No room in inventory after it was emptied");
                            }
                        }
                    }

                    //Finally move all items from inventory to targetTab
                    Queue <Item> currentInventory_final = new Queue <Item>(inventory.items.Where(x => true));
                    Item         inventItem_final       = null;
                    while (currentInventory_final.TryDequeue(out inventItem_final))
                    {
                        bool inserted_final = false;

                        //Try moving to chaos recipe tab
                        foreach (StashTab chaosTab in chaosRecipeTabs)
                        {
                            if (ToolBox.MoveItemToChaosRecipeTab(inventory, chaosTab, inventItem_final, moveOrganizer, config))
                            {
                                inserted_final = true;
                                break;
                            }
                        }


                        if (inserted_final == false && !ToolBox.MoveItem(inventory, targetTab, inventItem_final, moveOrganizer))
                        {
                            if (!ToolBox.MoveItem(inventory, trashTab, inventItem_final, moveOrganizer))
                            {
                                throw new Exception("No room in trash tab, terminating!");
                            }
                        }
                    }
                }
            }
            #endregion

            #region Setup chaos recipe tabs

            /*
             * List<TargetTab> chaosSourceTabsSorted = sortedTargetTabs.Where(x => x.chaosRecipeCount > 0).ToList();
             *
             * foreach (TargetTab target in chaosSourceTabsSorted) {
             *  StashTab targetTab = targetTabs.Single(x => target.targetStashes.Contains(x.name));
             *
             *  Queue<Item> matchesTarg = new Queue<Item>(targetTab.items.Where(x => ToolBox.MatchTargetTabItem(x, target)));
             *
             *  foreach(StashTab chaosTab in chaosRecipeTabs) {
             *
             *      if(chaosTab.items.Count > 0) {
             *          Item it = chaosTab.items.First()
             *      }
             *
             *  }
             *
             *
             *  //Move item to inventory
             *  Item currentItem = null;
             *  while (matchesTarg.TryDequeue(out currentItem)) {
             *      if (!ToolBox.MoveItem(targetTab, inventory, currentItem, moveOrganizer)) {
             *
             *          //Try moving to chaos recipe tab
             *          foreach (StashTab chaosTab in chaosRecipeTabs) {
             *              if (ToolBox.MoveItemToChaosRecipeTab(inventory, chaosTab, currentItem, moveOrganizer, config)) {
             *                  break;
             *              }
             *          }
             *
             *      }
             *  }
             *
             * }
             */
            #endregion

            #region Count item classes
            List <TargetTab> chaosSourceTabTypes = sortedTargetTabs.Where(x => x.chaosRecipeCount > 0).ToList();

            var RegenGroupsForChaosRecipe = chaosSourceTabTypes.SelectMany(x => x.regexGroups).Select(y => y).ToList();

            var StashTabsWithChaosRecipeItems = chaosSourceTabTypes.SelectMany(x => x.targetStashes).Select(y => y).ToList();

            StashTabsWithChaosRecipeItems.AddRange(config.sourceTabs);
            StashTabsWithChaosRecipeItems.AddRange(config.chaosRecipeTabs);

            var AllTabs = targetTabs.Union(sourceTabs).Union(chaosRecipeTabs).ToList();

            Console.WriteLine("Item Counts");

            foreach (string regexGrp in RegenGroupsForChaosRecipe)
            {
                int countForCurrent = 0;

                foreach (string tabName in StashTabsWithChaosRecipeItems)
                {
                    StashTab currentTab = AllTabs.Single(x => x.name == tabName);

                    foreach (Item it in currentTab.items)
                    {
                        if (RegexGroup.MatchItem(it, regexGrp))
                        {
                            countForCurrent++;
                        }
                    }
                }

                Console.WriteLine(regexGrp + ": " + countForCurrent.ToString());
            }

            #endregion


            moveOrganizer.finalize();

            int          limit  = 0;
            StreamWriter writer = File.CreateText("C:\\PoE\\Automater\\moveScript.ahk");
            foreach (string line in moveOrganizer.moves)
            {
                writer.WriteLine(line);

                //if(limit > 100) {
                //    break;
                //}

                limit++;
            }
            writer.Close();

            Console.WriteLine("Total seconds to move: " + (moveOrganizer.TotalMS / 1000).ToString());
        }