Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.04 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: Bags
  3. // Assembly: HumanMasterPlugin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: 26BB80D3-825F-40BA-9658-12D2F352D027
  5. // Assembly location: C:\Users\ludde\Desktop\Everything\WRobot\Plugins\HumanMasterPlugin.dll
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using wManager;
  12. using wManager.Wow.Helpers;
  13. using wManager.Wow.ObjectManager;
  14.  
  15. public class Bags
  16. {
  17.   private static Dictionary<uint, uint> _bagDictionary = new Dictionary<uint, uint>()
  18.   {
  19.     {
  20.       22976U,
  21.       4U
  22.     },
  23.     {
  24.       1537U,
  25.       4U
  26.     },
  27.     {
  28.       11845U,
  29.       4U
  30.     },
  31.     {
  32.       20474U,
  33.       4U
  34.     },
  35.     {
  36.       2082U,
  37.       6U
  38.     },
  39.     {
  40.       4496U,
  41.       6U
  42.     },
  43.     {
  44.       828U,
  45.       6U
  46.     },
  47.     {
  48.       5571U,
  49.       6U
  50.     },
  51.     {
  52.       4238U,
  53.       6U
  54.     },
  55.     {
  56.       805U,
  57.       6U
  58.     },
  59.     {
  60.       5572U,
  61.       6U
  62.     },
  63.     {
  64.       6756U,
  65.       6U
  66.     },
  67.     {
  68.       5081U,
  69.       6U
  70.     },
  71.     {
  72.       4957U,
  73.       6U
  74.     },
  75.     {
  76.       3343U,
  77.       8U
  78.     },
  79.     {
  80.       5574U,
  81.       8U
  82.     },
  83.     {
  84.       856U,
  85.       8U
  86.     },
  87.     {
  88.       4240U,
  89.       8U
  90.     },
  91.     {
  92.       3233U,
  93.       8U
  94.     },
  95.     {
  96.       5763U,
  97.       8U
  98.     },
  99.     {
  100.       2657U,
  101.       8U
  102.     },
  103.     {
  104.       4241U,
  105.       8U
  106.     },
  107.     {
  108.       4498U,
  109.       8U
  110.     },
  111.     {
  112.       5573U,
  113.       8U
  114.     },
  115.     {
  116.       804U,
  117.       10U
  118.     },
  119.     {
  120.       4245U,
  121.       10U
  122.     },
  123.     {
  124.       6446U,
  125.       10U
  126.     },
  127.     {
  128.       3352U,
  129.       10U
  130.     },
  131.     {
  132.       1470U,
  133.       10U
  134.     },
  135.     {
  136.       933U,
  137.       10U
  138.     },
  139.     {
  140.       1729U,
  141.       10U
  142.     },
  143.     {
  144.       857U,
  145.       10U
  146.     },
  147.     {
  148.       5575U,
  149.       10U
  150.     },
  151.     {
  152.       5576U,
  153.       10U
  154.     },
  155.     {
  156.       4497U,
  157.       10U
  158.     },
  159.     {
  160.       5764U,
  161.       10U
  162.     },
  163.     {
  164.       5765U,
  165.       10U
  166.     },
  167.     {
  168.       918U,
  169.       10U
  170.     },
  171.     {
  172.       1725U,
  173.       12U
  174.     },
  175.     {
  176.       16057U,
  177.       12U
  178.     },
  179.     {
  180.       4499U,
  181.       12U
  182.     },
  183.     {
  184.       10051U,
  185.       12U
  186.     },
  187.     {
  188.       1652U,
  189.       12U
  190.     },
  191.     {
  192.       10050U,
  193.       12U
  194.     },
  195.     {
  196.       14046U,
  197.       14U
  198.     },
  199.     {
  200.       1685U,
  201.       14U
  202.     },
  203.     {
  204.       3914U,
  205.       14U
  206.     },
  207.     {
  208.       4500U,
  209.       16U
  210.     },
  211.     {
  212.       14155U,
  213.       16U
  214.     },
  215.     {
  216.       41599U,
  217.       20U
  218.     }
  219.   };
  220.   private static Dictionary<string, uint> _bagNameDictionary = new Dictionary<string, uint>();
  221.   private static Dictionary<uint, uint> _slotToBag = new Dictionary<uint, uint>()
  222.   {
  223.     {
  224.       20U,
  225.       1U
  226.     },
  227.     {
  228.       21U,
  229.       2U
  230.     },
  231.     {
  232.       22U,
  233.       3U
  234.     },
  235.     {
  236.       23U,
  237.       4U
  238.     }
  239.   };
  240.   private static HashSet<string> _bagBlacklist = new HashSet<string>();
  241.  
  242.   public static void EquipBetterBags()
  243.   {
  244.     if (((WoWUnit) wManager.Wow.ObjectManager.ObjectManager.get_Me()).get_InCombatFlagOnly())
  245.       return;
  246.     foreach (KeyValuePair<uint, uint> bag in Bags._bagDictionary)
  247.     {
  248.       string str = ItemsManager.GetNameById(bag.Key).Trim();
  249.       if (!str.IsNullOrEmpty<char>() && !Bags._bagNameDictionary.ContainsKey(str))
  250.       {
  251.         Bags._bagNameDictionary.Add(str, bag.Value);
  252.         Bags._bagBlacklist.Remove(str);
  253.       }
  254.     }
  255.     string str1 = ((string) Lua.LuaDoString<string>(string.Format("\r\n            for bag = 0,4 do\r\n                for slot = 1,GetContainerNumSlots(bag) do\r\n                    local link = GetContainerItemLink(bag,slot);\r\n                    if link then\r\n                        local itemName, itemLink, itemQuality, itemLevel, itemType, itemSubType, itemCount, itemTexture = GetItemInfoFromItemLink(link);\r\n                        if ((itemSubType == 'Bag') and {0}) then\r\n                            return itemName;\r\n                        end\r\n                    end\r\n                end;\r\n            end", (object) Bags.LuaAndNotCondition((IEnumerable<string>) Bags._bagBlacklist, "itemName")), "")).Trim();
  256.     if (str1.IsNullOrEmpty<char>())
  257.       return;
  258.     uint num = (uint) Lua.LuaDoString<uint>("\r\n                for slot = 20,23,1 do\r\n                    if (not GetInventoryItemLink('player', slot)) then\r\n                        return slot;\r\n                    end\r\n                end    \r\n            ", "");
  259.     if (num > 0U)
  260.     {
  261.       PluginLog.Log(string.Format("Equipping bag: {0} to empty slot", (object) str1));
  262.       Lua.LuaDoString<string>(string.Format("\r\n                    for bag = 0,4 do\r\n                        for slot = 1,GetContainerNumSlots(bag) do\r\n                            local link = GetContainerItemLink(bag,slot);\r\n                            if link then\r\n                                local itemName, itemLink, itemQuality, itemLevel, itemType, itemSubType, itemCount, itemTexture = GetItemInfoFromItemLink(link);\r\n                                if (itemName == \"{0}\") then\r\n                                    ClearCursor();\r\n                                    PickupContainerItem(bag, slot);\r\n                                    PickupInventoryItem({1});\r\n                                end\r\n                            end\r\n                        end;\r\n                    end", (object) str1, (object) num), "");
  263.     }
  264.     else
  265.     {
  266.       uint newSlotCount = 0;
  267.       bool flag = Bags._bagNameDictionary.TryGetValue(str1, out newSlotCount);
  268.       if (newSlotCount == 0U || !flag)
  269.       {
  270.         PluginLog.Log(string.Format("Couldn't find bag slot count for {0}, please report this", (object) str1));
  271.       }
  272.       else
  273.       {
  274.         uint index = Bags._slotToBag.Keys.FirstOrDefault<uint>((Func<uint, bool>) (b => Bags.HasLessSlots(b, newSlotCount)));
  275.         if (index > 0U)
  276.         {
  277.           PluginLog.Log(string.Format("Moving all items out of bag slot {0} and equipping {1}", (object) index, (object) str1));
  278.           Bags.MoveAllItemsOutOfContainer(Bags._slotToBag[index]);
  279.           Lua.LuaDoString<string>(string.Format("\r\n                    for bag = 0,4 do\r\n                        for slot = 1,GetContainerNumSlots(bag) do\r\n                            local link = GetContainerItemLink(bag,slot);\r\n                            if link then\r\n                                local itemName, itemLink, itemQuality, itemLevel, itemType, itemSubType, itemCount, itemTexture = GetItemInfoFromItemLink(link);\r\n                                if (itemName == \"{0}\") then\r\n                                    ClearCursor();\r\n                                    PickupContainerItem(bag, slot);\r\n                                    PickupInventoryItem({1});\r\n                                end\r\n                            end\r\n                        end;\r\n                    end", (object) str1, (object) index), "");
  280.         }
  281.         else
  282.         {
  283.           Bags._bagBlacklist.Add(str1);
  284.           wManagerSetting.get_CurrentSetting().get_DoNotSellList().Remove(str1);
  285.         }
  286.       }
  287.     }
  288.   }
  289.  
  290.   private static void MoveAllItemsOutOfContainer(uint container)
  291.   {
  292.     Lua.LuaDoString(string.Format("\r\n        for slot = 1,GetContainerNumSlots({0}) do\r\n            local itemExists = GetContainerItemLink({1}, slot);\r\n            -- item exists in this slot, needs to be MOVED\r\n            if itemExists then\r\n                for bag = 0,4 do\r\n                    if bag ~= {2} then\r\n                        for slotInBag = 1,GetContainerNumSlots(bag) do\r\n                            local link = GetContainerItemLink(bag, slotInBag);\r\n                            if not link then\r\n                                ClearCursor();\r\n                                PickupContainerItem({3}, slot);\r\n                                PickupContainerItem(bag, slotInBag);\r\n                            end\r\n                        end\r\n                    end\r\n                end\r\n            end\r\n        end", (object) container, (object) container, (object) container, (object) container), false);
  293.   }
  294.  
  295.   private static bool HasLessSlots(uint slotId, uint slotCount)
  296.   {
  297.     try
  298.     {
  299.       string index = ((string) Lua.LuaDoString<string>(string.Format("\r\n            local itemName, itemLink, itemQuality, itemLevel, itemType, itemSubType, itemCount, itemTexture = GetItemInfoFromItemLink(GetInventoryItemLink('player', {0}));\r\n            return itemName;\r\n            ", (object) slotId), "")).Trim();
  300.       return Bags._bagNameDictionary[index] < slotCount;
  301.     }
  302.     catch (Exception ex)
  303.     {
  304.     }
  305.     return false;
  306.   }
  307.  
  308.   private static string LuaAndNotCondition(IEnumerable<string> names, string varname)
  309.   {
  310.     if (names.IsNullOrEmpty<string>())
  311.       return "true";
  312.     StringBuilder stringBuilder = new StringBuilder();
  313.     foreach (string name in names)
  314.       stringBuilder.Append(string.Format(" and {0} ~= \"{1}\"", (object) varname, (object) name));
  315.     return stringBuilder.ToString().Substring(5);
  316.   }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement