Пример #1
0
        public new ConsumableItemMaster GetItemMaster()
        {
            if (consumableItemMaster != null)
            {
                return(consumableItemMaster);
            }

            if (ItemRegister.TryGetItem <ConsumableItemMaster>(Name, out var result))
            {
                consumableItemMaster = result;
                return(consumableItemMaster);
            }

            consumableItemMaster = new ConsumableItemMaster();
            consumableItemMaster = ItemDatabase.GetItemByName("HP Potion I").DuplicateAs <ConsumableItemMaster>();
            consumableItemMaster.SetItemName(NameKey, Name);
            consumableItemMaster.SetItemDescription(DescriptionKey, Description);
            consumableItemMaster.worldSpriteName = SpriteKey;

            consumableItemMaster.stats         = new StatsModificator();
            consumableItemMaster.equipmentSlot = EquipmentItemMaster.EquipmentSlot.Potion;


            ItemRegister.AddItemMaster(consumableItemMaster);

            return(consumableItemMaster);
        }
Пример #2
0
        internal static void Postfix(InventoryPanel __instance, ref bool __result)
        {
            System.Console.WriteLine("===========================================");
            System.Console.WriteLine("Fix null refrence exception when consuming last potion");
            System.Console.WriteLine("===========================================");
            __result = true;
            if (!__instance.IsActive() || !__instance.receiveInput || __instance.blockInput)
            {
                __result = false;
                return;
            }

            if (!InventoryPanel.currentSelectedSlot)
            {
                return;
            }


            InventorySlotGUI component = InventoryPanel.currentSelectedSlot.GetComponent <InventorySlotGUI>();

            if (!component.itemStack || !component.itemStack.Consumable)
            {
                return;
            }


            Consumable consumable = component.itemStack.Consumable;

            if (!consumable.SendConsumeEvent())
            {
                component.PlayWrongAnimation();
                return;
            }


            component.PlaySelectedAnimation(Constants.GetFloat("inventorySlotPressPunchValue"));
            BagInventorySlotGUI component2 = InventoryPanel.currentSelectedSlot.GetComponent <BagInventorySlotGUI>();

            if (component2)
            {
                if (component2.itemStack.Quantity == 0)
                {
                    HeroMerchant.Instance.heroMerchantInventory.SetItem(null, component2.slotIndex);
                }
                else
                {
                    HeroMerchant.Instance.heroMerchantInventory.RefreshSlotAt(component2.slotIndex);
                }
            }
            else
            {
                EquipmentInventorySlotGUI component3 = InventoryPanel.currentSelectedSlot.GetComponent <EquipmentInventorySlotGUI>();
                if (component3)
                {
                    if (component3.type == HeroMerchantInventory.EquipmentSlot.Potion)
                    {
                        if (component3.itemStack.Quantity > 0)
                        {
                            component3.UpdateItem();
                            HUDManager.Instance.SetPotionQuantity(component3.itemStack.Quantity);
                        }
                        else
                        {
                            HeroMerchant.Instance.heroMerchantInventory.SetEquippedItemByType(null, HeroMerchantInventory.EquipmentSlot.Potion);
                            HUDManager.Instance.SetEmptyConsumableIcon();
                        }
                    }
                }
                else
                {
                    ChestSlotGUI component4 = InventoryPanel.currentSelectedSlot.GetComponent <ChestSlotGUI>();
                    if (component4)
                    {
                        component4.UpdateItem();
                    }
                }
            }


            // Check ItemRegistry to see if this is a custom item
            ConsumableItemMaster consumableItemMaster = ItemRegister.GetItem <ConsumableItemMaster>(component.item.name);

            if (consumableItemMaster is null)
            {
                consumableItemMaster = component.item as ConsumableItemMaster;
            }


            bool isGuidenceEffect = (consumableItemMaster?.consumableEffectName is null) ? false : consumableItemMaster.consumableEffectName.Contains("Guidance");

            if (isGuidenceEffect)
            {
                DOVirtual.DelayedCall(0.1f, delegate
                {
                    GUIManager.Instance.DisableCurrentPanel();
                }, true);
            }
        }
 public static void Init <T>(this Consumable consumable, ConsumableItemMaster master) where T : MonoBehaviour
 {
     consumable.consumableMaster = master;
     consumable.gameObject.AddComponent <T>();
     consumable._stack = consumable.GetComponent <ItemStack>();
 }
 public static Consumable AddConsumable(this ItemStack itemStack, ConsumableItemMaster consumableItemMaster)
 {
     itemStack._consumable = itemStack.gameObject.GetOrAddComponent <Consumable>();
     itemStack._consumable.Init(consumableItemMaster);
     return(itemStack._consumable);
 }