예제 #1
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);
            }
        }