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); }
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); }
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."); } } } } } }
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); }