Beispiel #1
0
        protected static void InvItem_LoadItemSprite(InvItem __instance)
        {
            CustomItem item = RogueLibs.Instance.Items.Find(i => i.Id == __instance.invItemName);

            if (item == null)
            {
                return;
            }
            __instance.itemIcon = __instance.itemIcon ?? item.Sprite;
        }
Beispiel #2
0
        protected static void InvItem_SetupDetails(InvItem __instance)
        {
            CustomItem item = RogueLibs.Instance.Items.Find(i => i.Id == __instance.invItemName);

            if (item == null)
            {
                return;
            }
            item.SetupDetails?.Invoke(__instance);
            __instance.LoadItemSprite(item.Id);
        }
Beispiel #3
0
        public static void InvSlot_LateUpdate(InvSlot __instance, Text ___itemText)
        {
            CustomItem custom = __instance.item?.GetHook <CustomItem>();

            if (custom != null)
            {
                ___itemText.enabled = true;
                CustomTooltip tooltip = custom.GetCountString();
                ___itemText.text  = tooltip.Text ?? string.Empty;
                ___itemText.color = tooltip.Color ?? Color.white;
            }
        }
Beispiel #4
0
        public static void InvInterface_HideCursorText(InvInterface __instance)
        {
            CustomItem custom = __instance.mainGUI.targetItem?.GetHook <CustomItem>();

            if (custom is IItemTargetable targetable)
            {
                CustomTooltip tooltip = targetable.TargetCursorText(null);
                __instance.cursorTextCanvas3.enabled = !string.IsNullOrEmpty(tooltip.Text);
                __instance.cursorTextString3.text    = tooltip.Text ?? string.Empty;
                __instance.cursorTextString3.color   = tooltip.Color ?? Color.white;
            }
        }
Beispiel #5
0
        public static void EquippedItemSlot_LateUpdateEquippedItemSlot(EquippedItemSlot __instance)
        {
            CustomItem custom = __instance.item?.GetHook <CustomItem>();

            if (custom != null)
            {
                __instance.countText.enabled = true;
                __instance.countText.rectTransform.localScale = new Vector3(0.2f, 0.2f, 1f);
                CustomTooltip tooltip = custom.GetCountString();
                __instance.countText.text  = tooltip.Text ?? string.Empty;
                __instance.countText.color = tooltip.Color ?? Color.white;
            }
        }
Beispiel #6
0
        protected static void ItemFunctions_UseItem(InvItem item, Agent agent)
        {
            CustomItem citem = RogueLibs.Instance.Items.Find(i => i.Id == item.invItemName);

            if (citem?.TargetObject != null)
            {
                item.invInterface.ShowOrHideTarget(item);
            }
            else if (citem != null)
            {
                citem.UseItem?.Invoke(item, agent);
            }
        }
Beispiel #7
0
        public static void InvInterface_ShowTarget(InvInterface __instance, InvItem item)
        {
            __instance.cursorTextString3.color = Color.white;

            if (item.itemType != ItemTypes.Combine)
            {
                CustomItem custom = item.GetHook <CustomItem>();
                if (custom is IItemTargetable targetable)
                {
                    CustomTooltip tooltip = targetable.TargetCursorText(item.agent.target.playfieldObject);
                    __instance.cursorTextCanvas3.enabled = !string.IsNullOrEmpty(tooltip.Text);
                    __instance.cursorTextString3.text    = tooltip.Text ?? string.Empty;
                    __instance.cursorTextString3.color   = tooltip.Color ?? Color.white;
                }
            }
        }
Beispiel #8
0
        protected static void ItemFunctions_CombineItems(InvItem item, Agent agent, InvItem otherItem, int slotNum, string combineType, ref bool __result)
        {
            CustomItem citem = RogueLibs.Instance.Items.Find(i => i.Id == item.invItemName);

            if (citem?.CombineItem == null)
            {
                return;
            }

            if ((__result = citem.CombineFilter == null || citem.CombineFilter(item, agent, otherItem)) && combineType == "Combine")
            {
                citem.CombineItem(item, agent, otherItem, slotNum);
                if (item.invItemCount < 1)
                {
                    agent.mainGUI.invInterface.HideDraggedItem();
                    agent.mainGUI.invInterface.HideTarget();
                }
            }
        }
Beispiel #9
0
        protected static void ItemFunctions_TargetObject(InvItem item, Agent agent, PlayfieldObject otherObject, string combineType, ref bool __result)
        {
            CustomItem citem = RogueLibs.Instance.Items.Find(i => i.Id == item.invItemName);

            if (citem?.TargetObject == null)
            {
                return;
            }

            if ((__result = citem.TargetFilter == null || citem.TargetFilter(item, agent, otherObject)) && combineType == "Combine")
            {
                citem.TargetObject(item, agent, otherObject);
                if (item.invItemCount < 1)
                {
                    agent.mainGUI.invInterface.HideDraggedItem();
                    agent.mainGUI.invInterface.HideTarget();
                }
            }
        }
Beispiel #10
0
        public static bool ItemFunctions_UseItem(InvItem item, Agent agent)
        {
            bool       debug  = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            CustomItem custom = item.GetHook <CustomItem>();

            if (custom is IItemTargetable || custom is IItemTargetableAnywhere)
            {
                if (debug)
                {
                    RogueFramework.LogDebug($"Showing target for {custom} ({item.invItemName}).");
                }
                item.invInterface.ShowOrHideTarget(item);
                return(false);
            }

            if (debug)
            {
                RogueFramework.LogDebug($"Using {custom} ({item.invItemName}):");
            }

            Agent           originalAgent = agent;
            OnItemUsingArgs args          = new OnItemUsingArgs(item, agent);

            if (InventoryChecks.onItemUsing.Raise(args, custom?.ItemInfo.IgnoredChecks))
            {
                agent = args.User;
                // in case an inventory check redirected the use of an item on someone else
                using (AgentSwapper swapper = new AgentSwapper(item, agent))
                {
                    if (agent.localPlayer)
                    {
                        if (!originalAgent.inventory.HasItem(item.invItemName) &&
                            originalAgent.inventory.equippedSpecialAbility?.invItemName != item.invItemName)
                        {
                            return(false);
                        }
                        else if (!item.used && (item.Categories.Contains(RogueCategories.Usable) || item.itemType == ItemTypes.Consumable))
                        {
                            item.used = true;
                            if (agent.isPlayer > 0)
                            {
                                agent.gc.sessionData.endStats[agent.isPlayer].itemsUsed++;
                            }
                        }
                    }
                    // if it's not a custom item, run the original method
                    if (!(custom is IItemUsable usable))
                    {
                        if (debug)
                        {
                            RogueFramework.LogDebug("---- Running the original method.");
                        }
                        return(true);
                    }

                    bool success = usable.UseItem();
                    if (debug)
                    {
                        RogueFramework.LogDebug($"---- Usage {(success ? "was successful" : "failed")}.");
                    }
                    if (success)
                    {
                        new ItemFunctions().UseItemAnim(item, agent);
                    }
                }
            }
            else
            {
                if (debug)
                {
                    RogueFramework.LogDebug("---- Usage was prevented by an inventory check.");
                }
            }
            return(false);
        }
Beispiel #11
0
        public static void InvInterface_TargetAnywhere(InvInterface __instance, Vector2 myPos, bool pressedButton)
        {
            __instance.cursorTextString3.color = Color.white;

            bool    debug   = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            InvItem invItem = __instance.mainGUI.targetItem;

            if (invItem != null)
            {
                CustomItem custom = invItem.GetHook <CustomItem>();
                __instance.cursorHighlightTargetObjects = custom is IItemTargetable;
                if (custom is IItemTargetableAnywhere targetable)
                {
                    if (debug && pressedButton)
                    {
                        RogueFramework.LogDebug($"Targeting {custom} ({invItem.invItemName}) anywhere:");
                    }

                    bool filter = targetable.TargetFilter(myPos);
                    __instance.cursorHighlight = filter;
                    __instance.cursorHighlightTargetAnywhere           = filter;
                    __instance.mainGUI.agent.targetImage.tr.localScale = Vector3.one;

                    CustomTooltip tooltip = targetable.TargetCursorText(myPos);
                    __instance.cursorTextCanvas3.enabled = !string.IsNullOrEmpty(tooltip.Text);
                    __instance.cursorTextString3.text    = tooltip.Text ?? string.Empty;
                    __instance.cursorTextString3.color   = tooltip.Color ?? Color.white;

                    if (pressedButton)
                    {
                        OnItemTargetingAnywhereArgs args = new OnItemTargetingAnywhereArgs(invItem, myPos, invItem.agent);
                        if (InventoryChecks.onItemTargetingAnywhere.Raise(args, custom?.ItemInfo.IgnoredChecks))
                        {
                            myPos = args.Target;
                            using (AgentSwapper swapper = new AgentSwapper(invItem, args.User))
                            {
                                bool success = targetable.TargetPosition(myPos);
                                if (debug)
                                {
                                    RogueFramework.LogDebug($"---- Targeting {(success ? "was successful" : "failed")}.");
                                }
                                if (success)
                                {
                                    new ItemFunctions().UseItemAnim(invItem, invItem.agent);
                                }

                                if (custom.Count < 1 || !custom.Inventory.InvItemList.Contains(custom.Item) &&
                                    InventoryChecks.IsCheckAllowed(custom, "StopOnZero"))
                                {
                                    if (debug)
                                    {
                                        RogueFramework.LogDebug("---- Triggered \"StopOnZero\" inventory check.");
                                    }
                                    __instance.HideDraggedItem();
                                    __instance.HideTarget();
                                }
                            }
                        }
                        else
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                            }
                        }
                    }
                }
            }
        }
Beispiel #12
0
        public static void InvSlot_SetColor(InvSlot __instance)
        {
            // set default color
            __instance.toolbarNumText.color = new Color32(255, 237, 0, 255);

            InvItem combiner = __instance.mainGUI.targetItem ?? __instance.database.invInterface.draggedInvItem;

            if (combiner is null)
            {
                return;
            }
            InvItem combinee = __instance.curItemList[__instance.slotNumber];

            CustomItem custom = combiner.GetHook <CustomItem>();

            if (!(custom is IItemCombinable combinable))
            {
                return;
            }

            if (__instance.slotType == "Player" || __instance.slotType == "Toolbar" || __instance.slotType == "Chest" || __instance.slotType == "NPCChest")
            {
                if (combinee.invItemName != null && combiner.itemType == ItemTypes.Combine)
                {
                    if (combiner.CombineItems(combinee, __instance.slotNumber, string.Empty, __instance.agent) && __instance.slotType != "NPCChest")
                    {
                        __instance.myImage.color   = new Color32(0, __instance.br, __instance.br, __instance.standardAlpha);
                        __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
                        __instance.myImage.sprite  = __instance.invBoxCanUse;
                    }
                    else if ((__instance.slotType != "Toolbar" || __instance.mainGUI.openedInventory) && __instance.slotType != "NPCChest")
                    {
                        __instance.myImage.color   = new Color32(__instance.br, 0, __instance.br, __instance.standardAlpha);
                        __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, __instance.fadedItemAlpha);
                        __instance.myImage.sprite  = __instance.invBoxNormal;
                        __instance.toolbarNumTextGo.SetActive(false);
                    }

                    if (__instance.slotType != "NPCChest" && __instance.slotType != "Chest")
                    {
                        CustomTooltip tooltip = combinable.CombineTooltip(combinee);
                        __instance.toolbarNumTextGo.SetActive(true);
                        __instance.toolbarNumText.text  = tooltip.Text ?? string.Empty;
                        __instance.toolbarNumText.color = tooltip.Color ?? new Color32(255, 237, 0, 255);
                    }
                }
                else if (__instance.slotType != "NPCChest" && (combinee.invItemName != null || combiner.itemType != ItemTypes.Combine))
                {
                    __instance.myImage.color = __instance.overSlot
                                                ? (Color) new Color32(0, __instance.br, __instance.br, __instance.standardAlpha)
                                                : (Color) new Color32(__instance.br, __instance.br, __instance.br, __instance.standardAlpha);

                    __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
                    __instance.myImage.sprite  = __instance.invBoxNormal;
                    if (__instance.slotType == "Toolbar")
                    {
                        __instance.toolbarNumTextGo.SetActive(false);
                    }
                }
                if (__instance.mainGUI.curSelected == __instance.mySelectable && __instance.agent.controllerType != "Keyboard")
                {
                    __instance.invInterface.OnSelectionBox(__instance.slotType, __instance.tr.position);
                }
            }
        }
Beispiel #13
0
        public static bool InvItem_TargetObject(InvItem __instance, PlayfieldObject otherObject, string combineType, ref bool __result)
        {
            bool       debug           = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            bool       actualCombining = combineType == "Combine";
            CustomItem custom          = __instance.GetHook <CustomItem>();

            if (debug && actualCombining)
            {
                RogueFramework.LogDebug($"Targeting {custom} ({__instance.invItemName}) on {otherObject.objectName}:");
            }

            if (Vector2.Distance(__instance.agent.curPosition, otherObject.curPosition) > 15f &&
                InventoryChecks.IsCheckAllowed(custom, "Distance"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"Distance\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }
            if ((otherObject as Agent)?.butlerBot == true && InventoryChecks.IsCheckAllowed(custom, "ButlerBot"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"ButlerBot\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }
            if ((otherObject as Agent)?.mechEmpty == true && InventoryChecks.IsCheckAllowed(custom, "EmptyMech"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"EmptyMech\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }

            __result = custom is IItemTargetable targetable
                                ? targetable.TargetFilter(otherObject)
                                : new ItemFunctions().TargetObject(__instance, __instance.agent, otherObject, string.Empty);

            if (actualCombining)
            {
                OnItemTargetingArgs args = new OnItemTargetingArgs(__instance, otherObject, __instance.agent);
                if (InventoryChecks.onItemTargeting.Raise(args, custom?.ItemInfo.IgnoredChecks))
                {
                    otherObject = args.Target;
                    using (AgentSwapper swapper = new AgentSwapper(__instance, args.User))
                    {
                        if (custom is IItemTargetable targetable2)
                        {
                            bool success = targetable2.TargetObject(otherObject);
                            if (debug)
                            {
                                RogueFramework.LogDebug($"---- Targeting {(success ? "was successful" : "failed")}.");
                            }
                            if (success)
                            {
                                new ItemFunctions().UseItemAnim(__instance, __instance.agent);
                            }
                        }
                        else
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Running the original method.");
                            }
                            new ItemFunctions().TargetObject(__instance, __instance.agent, otherObject, "Combine");
                        }

                        if (__instance.invItemCount < 1 || !__instance.database.InvItemList.Contains(__instance) &&
                            InventoryChecks.IsCheckAllowed(custom, "StopOnZero"))
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Triggered \"StopOnZero\" inventory check.");
                            }
                            __instance.agent.mainGUI.invInterface.HideDraggedItem();
                            __instance.agent.mainGUI.invInterface.HideTarget();
                        }
                    }
                }
                else
                {
                    if (debug)
                    {
                        RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                    }
                }
            }
            return(false);
        }
Beispiel #14
0
        public static bool InvItem_CombineItems(InvItem __instance, InvItem otherItem, int slotNum, Agent myAgent, string combineType, ref bool __result)
        {
            bool       debug           = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            bool       actualCombining = combineType == "Combine";
            CustomItem custom          = __instance.GetHook <CustomItem>();

            if (debug && actualCombining)
            {
                RogueFramework.LogDebug($"Combining {custom} ({__instance.invItemName}) with {otherItem.invItemName}:");
            }

            if (__instance.stackable && __instance.invItemName == otherItem.invItemName &&
                InventoryChecks.IsCheckAllowed(custom, "AutoStacking"))
            {
                if (__instance.invItemName == VanillaItems.Syringe && __instance.contents[0] != otherItem.contents[0])
                {
                    __result = false;
                    return(false);
                }
                if (actualCombining)
                {
                    if (debug)
                    {
                        RogueFramework.LogDebug("---- Triggered \"AutoStacking\" inventory check.");
                        RogueFramework.LogDebug("---- Combining was prevented by an inventory check.");
                    }
                    if (myAgent.controllerType != "Keyboard")
                    {
                        myAgent.gc.audioHandler.Play(myAgent, VanillaAudio.BeginCombine);
                    }
                    otherItem.agent.mainGUI.invInterface.PutDraggedItemBack();
                }
                __result = true;
                return(false);
            }

            if (custom is IItemCombinable combinable)
            {
                using (AgentSwapper swapper = new AgentSwapper(__instance, myAgent))
                    __result = combinable.CombineFilter(otherItem);
            }
            else
            {
                __result = new ItemFunctions().CombineItems(__instance, myAgent, otherItem, slotNum, string.Empty);
            }

            if (actualCombining)
            {
                OnItemsCombiningArgs args = new OnItemsCombiningArgs(__instance, otherItem, myAgent);
                if (InventoryChecks.onItemsCombining.Raise(args, custom?.ItemInfo.IgnoredChecks))
                {
                    myAgent   = args.Combiner;
                    otherItem = args.OtherItem;
                    if (custom is IItemCombinable combinable2)
                    {
                        using (AgentSwapper swapper = new AgentSwapper(__instance, myAgent))
                        {
                            bool success = combinable2.CombineItems(otherItem);
                            if (debug)
                            {
                                RogueFramework.LogDebug($"---- Combining {(success ? "was successful" : "failed")}.");
                            }
                            if (success)
                            {
                                new ItemFunctions().UseItemAnim(__instance, myAgent);
                            }
                        }
                    }
                    else
                    {
                        if (debug)
                        {
                            RogueFramework.LogDebug("---- Running the original method.");
                        }
                        new ItemFunctions().CombineItems(__instance, myAgent, otherItem, slotNum, "Combine");
                    }

                    if (__instance.invItemCount < 1 || !__instance.database.InvItemList.Contains(__instance) &&
                        InventoryChecks.IsCheckAllowed(custom, "StopOnZero"))
                    {
                        if (debug)
                        {
                            RogueFramework.LogDebug("---- Triggered \"StopOnZero\" inventory check.");
                        }
                        myAgent.mainGUI.invInterface.HideDraggedItem();
                        myAgent.mainGUI.invInterface.HideTarget();
                    }
                }
                else
                {
                    if (debug)
                    {
                        RogueFramework.LogDebug("---- Combining was prevented by an inventory check.");
                    }
                }
            }
            return(false);
        }
Beispiel #15
0
        protected static void InvSlot_SetColor(InvSlot __instance, Text ___itemText)
        {
            __instance.toolbarNumTextGo.SetActive(false);
            InvItem targetItem = __instance.mainGUI.targetItem ?? __instance.database.invInterface.draggedInvItem;

            if (targetItem == null)
            {
                return;
            }
            InvItem thisItem = __instance.curItemList[__instance.slotNumber];

            CustomItem cItem = RogueLibs.Instance.Items.Find(i => i.Id == targetItem.invItemName);

            if (cItem?.CombineTooltip == null)
            {
                return;
            }

            if (targetItem != null && (__instance.slotType == "Player" || __instance.slotType == "Toolbar" || __instance.slotType == "Chest" || __instance.slotType == "NPCChest"))
            {
                if (thisItem.invItemName != null && targetItem.itemType == "Combine")
                {
                    if (targetItem.CombineItems(thisItem, __instance.slotNumber, string.Empty, __instance.agent) && __instance.slotType != "NPCChest")
                    {
                        __instance.myImage.color   = new Color32(0, __instance.br, __instance.br, __instance.standardAlpha);
                        __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
                        __instance.myImage.sprite  = __instance.invBoxCanUse;

                        if (__instance.slotType != "NPCChest" && __instance.slotType != "Chest")
                        {
                            string result = cItem.CombineTooltip(targetItem, targetItem.agent, thisItem) ?? string.Empty;
                            __instance.toolbarNumTextGo.SetActive(result != string.Empty);
                            __instance.toolbarNumText.text = result;
                        }
                    }
                    else if ((!(__instance.slotType == "Toolbar") || __instance.mainGUI.openedInventory) && __instance.slotType != "NPCChest")
                    {
                        __instance.myImage.color   = new Color32(__instance.br, 0, __instance.br, __instance.standardAlpha);
                        __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, __instance.fadedItemAlpha);
                        __instance.myImage.sprite  = __instance.invBoxNormal;
                        ___itemText.color          = __instance.whiteTransparent;
                        __instance.toolbarNumTextGo.SetActive(false);
                    }
                }
                else if (__instance.slotType != "NPCChest" && (thisItem.invItemName != null || targetItem.itemType != "Combine"))
                {
                    __instance.myImage.color = __instance.overSlot
                                                ? (Color) new Color32(0, __instance.br, __instance.br, __instance.standardAlpha)
                                                : (Color) new Color32(__instance.br, __instance.br, __instance.br, __instance.standardAlpha);

                    __instance.itemImage.color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
                    __instance.myImage.sprite  = __instance.invBoxNormal;
                    if (__instance.slotType == "Toolbar")
                    {
                        __instance.toolbarNumTextGo.SetActive(false);
                    }
                }
                if (__instance.mainGUI.curSelected == __instance.mySelectable && __instance.agent.controllerType != "Keyboard")
                {
                    __instance.invInterface.OnSelectionBox(__instance.slotType, __instance.tr.position);
                }
            }
        }