Ejemplo n.º 1
0
            static void Postfix(InventoryGui __instance, Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality)
            {
                if (!AllowByKey())
                {
                    return;
                }
                Text component3 = elementRoot.transform.Find("res_amount").GetComponent <Text>();

                if (req.m_resItem != null)
                {
                    int invAmount = player.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name);
                    int amount    = req.GetAmount(quality);
                    if (amount <= 0)
                    {
                        return;
                    }
                    component3.text = amount.ToString();
                    if (invAmount < amount)
                    {
                        List <Container> nearbyContainers = GetNearbyContainers(Player.m_localPlayer.transform.position);
                        foreach (Container c in nearbyContainers)
                        {
                            invAmount += c.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name);
                        }

                        if (invAmount >= amount)
                        {
                            component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? flashColor.Value : unFlashColor.Value);
                        }
                    }
                    component3.text = string.Format(resourceString.Value, invAmount, component3.text);
                }
            }
Ejemplo n.º 2
0
        private static Recipe RepairRecipe(ItemDrop.ItemData item)
        {
            float  percent    = (item.GetMaxDurability() - item.m_durability) / item.GetMaxDurability();
            Recipe fullRecipe = ObjectDB.instance.GetRecipe(item);
            var    fullReqs   = fullRecipe.m_resources.ToList();

            bool isMagic = false;

            if (epicLootAssembly != null)
            {
                isMagic = (bool)epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("IsMagic", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(ItemDrop.ItemData) }, null).Invoke(null, new[] { item });
            }
            if (isMagic)
            {
                int rarity = (int)epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("GetRarity", BindingFlags.Public | BindingFlags.Static).Invoke(null, new[] { item });
                List <KeyValuePair <ItemDrop, int> > magicReqs = (List <KeyValuePair <ItemDrop, int> >)epicLootAssembly.GetType("EpicLoot.Crafting.EnchantTabController").GetMethod("GetEnchantCosts", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { item, rarity });
                foreach (var kvp in magicReqs)
                {
                    fullReqs.Add(new Piece.Requirement()
                    {
                        m_amount  = kvp.Value,
                        m_resItem = kvp.Key
                    });
                }
            }

            List <Piece.Requirement> reqs = new List <Piece.Requirement>();
            Recipe recipe = ScriptableObject.CreateInstance <Recipe>();

            for (int i = 0; i < fullReqs.Count; i++)
            {
                var req = new Piece.Requirement()
                {
                    m_resItem        = fullReqs[i].m_resItem,
                    m_amountPerLevel = Mathf.FloorToInt(fullReqs[i].m_amountPerLevel * percent * materialRequirementMult.Value),
                    m_amount         = Mathf.FloorToInt(fullReqs[i].m_amount * percent * materialRequirementMult.Value),
                };

                int amount = 0;
                for (int j = item.m_quality; j > 0; j--)
                {
                    amount += req.GetAmount(j);
                }


                if (amount > 0)
                {
                    reqs.Add(req);
                }
            }
            recipe.m_resources = reqs.ToArray();

            if (!reqs.Any())
            {
                return(null);
            }
            return(recipe);
        }
        private static Recipe RepairRecipe(ItemDrop.ItemData item, bool log = false)
        {
            float  percent    = (item.GetMaxDurability() - item.m_durability) / item.GetMaxDurability();
            Recipe fullRecipe = ObjectDB.instance.GetRecipe(item);

            if (log)
            {
                Dbgl($"{Localization.instance.Localize(item.m_shared.m_name)}, quality {item.m_quality} is {percent * 10000 / 100}% broken");
            }
            Recipe recipe = ScriptableObject.CreateInstance <Recipe>();

            List <Piece.Requirement> reqs = new List <Piece.Requirement>();

            for (int i = 0; i < fullRecipe.m_resources.Length; i++)
            {
                var req = new Piece.Requirement()
                {
                    m_resItem        = fullRecipe.m_resources[i].m_resItem,
                    m_amountPerLevel = Mathf.FloorToInt(fullRecipe.m_resources[i].m_amountPerLevel * percent * materialRequirementMult.Value),
                    m_amount         = Mathf.FloorToInt(fullRecipe.m_resources[i].m_amount * percent * materialRequirementMult.Value),
                };

                if (log)
                {
                    Dbgl($"full required amounts of {Localization.instance.Localize(fullRecipe.m_resources[i].m_resItem.m_itemData.m_shared.m_name)}: {fullRecipe.m_resources[i].m_amount} {fullRecipe.m_resources[i].m_amountPerLevel}; repair amounts: {req.m_amount} {req.m_amountPerLevel}");
                }


                int amount = 0;
                for (int j = item.m_quality; j > 0; j--)
                {
                    amount += req.GetAmount(j);
                }


                if (amount > 0)
                {
                    if (log)
                    {
                        Dbgl($"required amount of {Localization.instance.Localize(fullRecipe.m_resources[i].m_resItem.m_itemData.m_shared.m_name)} is {amount}");
                    }
                    reqs.Add(req);
                }
            }
            recipe.m_resources = reqs.ToArray();

            if (!reqs.Any())
            {
                if (log)
                {
                    Dbgl($"no resources required");
                }
                return(null);
            }
            return(recipe);
        }
Ejemplo n.º 4
0
        private static bool Prefix(Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality, ref bool __result)
        {
            Image     component  = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      component2 = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      component3 = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip component4 = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                component.gameObject.SetActive(true);
                component2.gameObject.SetActive(true);
                component3.gameObject.SetActive(true);
                component.sprite  = req.m_resItem.m_itemData.GetIcon();
                component.color   = Color.white;
                component4.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                component2.text   = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                int num    = player.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name);
                int amount = req.GetAmount(quality);

                if (amount <= 0)
                {
                    InventoryGui.HideRequirement(elementRoot);
                    __result = false;
                    return(false);
                }
                component3.text = num + "/" + amount.ToString();

                if (num < amount)
                {
                    component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
                else
                {
                    component3.color = Color.white;
                }

                component3.fontSize = 14;
                if (component3.text.Length > 5)
                {
                    component3.fontSize -= component3.text.Length - 5;
                }
            }

            __result = true;
            return(false);
        }
Ejemplo n.º 5
0
        static bool Prefix(ref bool __result, Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality)
        {
            Image     icon       = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      nameText   = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      amountText = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip tooltip    = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                icon.gameObject.SetActive(true);
                nameText.gameObject.SetActive(true);
                amountText.gameObject.SetActive(true);
                icon.sprite    = req.m_resItem.m_itemData.GetIcon();
                icon.color     = Color.white;
                tooltip.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                nameText.text  = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                int num    = ImprovedBuildHud.GetAvailableItems(req.m_resItem.m_itemData.m_shared.m_name);
                int amount = req.GetAmount(quality);
                if (amount <= 0)
                {
                    InventoryGui.HideRequirement(elementRoot);
                    __result = false;
                    return(false);
                }

                amountText.supportRichText    = true;
                amountText.horizontalOverflow = HorizontalWrapMode.Overflow;
                var inventoryAmount = string.Format(ImprovedBuildHudConfig.InventoryAmountFormat.Value, num);
                if (!string.IsNullOrEmpty(ImprovedBuildHudConfig.InventoryAmountColor.Value))
                {
                    inventoryAmount = $"<color={ImprovedBuildHudConfig.InventoryAmountColor.Value}>{inventoryAmount}</color>";
                }
                amountText.text = $"{amount} {inventoryAmount}";

                if (num < amount)
                {
                    amountText.color = (double)Mathf.Sin(Time.time * 10f) > 0.0 ? Color.red : Color.white;
                }
                else
                {
                    amountText.color = Color.white;
                }
            }
            __result = true;
            return(false);
        }
Ejemplo n.º 6
0
        private static int CalculateFinalAmount(ItemDrop.ItemData itemData, Piece.Requirement resource,
                                                double amountToCraftedRecipeAmountPercentage, float recyclingRate)
        {
            var amount = Enumerable.Range(1, itemData.m_quality)
                         .Select(level => resource.GetAmount(level))
                         .Sum();
            var stackCompensated = amount * amountToCraftedRecipeAmountPercentage;
            var realAmount       = Math.Floor(stackCompensated * recyclingRate);
            var finalAmount      = (int)realAmount;

            if (realAmount < 1 && itemData.m_shared.m_maxStackSize == 1 &&
                Plugin.Settings.UnstackableItemsAlwaysReturnAtLeastOneResource.Value)
            {
                finalAmount = 1;
            }
            Plugin.Log.LogDebug("Calculations report.\n" +
                                $" = = = Input: REA:{resource.m_amount} IQ:{itemData.m_quality} STK:{itemData.m_stack}({itemData.m_shared.m_maxStackSize}) SC:{stackCompensated} ATCRAP:{amountToCraftedRecipeAmountPercentage} A:{amount}, RA:{realAmount}: FA:{finalAmount}");
            return(finalAmount);
        }
Ejemplo n.º 7
0
        public bool SetupRequirement(Transform elementRoot, Piece.Requirement req, int currentAmount)
        {
            Image     imageResIcon  = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      textResName   = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      textResAmount = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip uiTooltip     = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                imageResIcon.gameObject.SetActive(value: true);
                textResName.gameObject.SetActive(value: true);
                textResAmount.gameObject.SetActive(value: true);
                imageResIcon.sprite = req.m_resItem.m_itemData.GetIcon();
                imageResIcon.color  = Color.white;

                uiTooltip.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                textResName.text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);

                int requiredAmount = req.GetAmount(0);

                int playerAmount = PlayerGetResourceCount(Player.m_localPlayer, req.m_resItem.m_itemData.m_shared.m_name);
                int remaining    = requiredAmount - currentAmount;

                textResAmount.text = currentAmount + "/" + requiredAmount;
                if (remaining > 0 && playerAmount == 0)
                {
                    imageResIcon.color  = Color.gray;
                    textResAmount.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
                else
                {
                    imageResIcon.color  = Color.white;
                    textResAmount.color = Color.white;
                }
            }
            return(true);
        }
Ejemplo n.º 8
0
        private static bool Prefix(Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality, ref bool __result)
        {
            if (!Configuration.Current.Hud.IsEnabled && !Configuration.Current.CraftFromChest.IsEnabled || !Configuration.Current.Hud.showRequiredItems && !Configuration.Current.CraftFromChest.IsEnabled)
            {
                return(true);
            }

            Image     component  = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      component2 = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      component3 = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip component4 = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                component.gameObject.SetActive(true);
                component2.gameObject.SetActive(true);
                component3.gameObject.SetActive(true);
                component.sprite  = req.m_resItem.m_itemData.GetIcon();
                component.color   = Color.white;
                component4.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                component2.text   = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                int num    = player.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name);
                int amount = req.GetAmount(quality);

                if (amount <= 0)
                {
                    InventoryGui.HideRequirement(elementRoot);
                    __result = false;
                    return(false);
                }

                if (Configuration.Current.CraftFromChest.IsEnabled)
                {
                    Stopwatch delta;

                    GameObject pos = player.GetCurrentCraftingStation()?.gameObject;
                    if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench)
                    {
                        pos   = player.gameObject;
                        delta = Inventory_NearbyChests_Cache.delta;
                    }
                    else
                    {
                        delta = GameObjectAssistant.GetStopwatch(pos);
                    }

                    int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;
                    if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
                    {
                        Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50));
                        delta.Restart();
                    }
                    num += InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), req.m_resItem.m_itemData);
                }

                component3.text = num + "/" + amount.ToString();

                if (num < amount)
                {
                    component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
                else
                {
                    component3.color = Color.white;
                }

                component3.fontSize = 14;
                if (component3.text.Length > 5)
                {
                    component3.fontSize -= component3.text.Length - 5;
                }
            }

            __result = true;
            return(false);
        }