/// <summary> /// <para>Prevents ghost agents from using items.</para> /// </summary> /// <param name="e">The item usage event args.</param> public static void GhostCheck(OnItemUsingArgs e) { if (e.User.ghost) { if (RogueFramework.IsDebugEnabled(DebugFlags.Items)) { RogueFramework.LogDebug("---- Triggered \"Ghost\" inventory check."); } e.User.gc.audioHandler.Play(e.User, "CantDo"); e.Cancel = e.Handled = true; } }
/// <summary> /// <para>Prevents "Pea-Brained" agents from using non-Food items.</para> /// </summary> /// <param name="e">The item usage event args.</param> public static void PeaBrainedCheck(OnItemUsingArgs e) { if (e.Item.itemType != ItemTypes.Food && e.User.HasTrait("CantInteract")) { if (RogueFramework.IsDebugEnabled(DebugFlags.Items)) { RogueFramework.LogDebug("---- Triggered \"PeaBrained\" inventory check."); } e.User.SayDialogue("CantInteract"); e.User.gc.audioHandler.Play(e.User, "CantDo"); e.Cancel = e.Handled = true; } }
/// <summary> /// <para>Prevents agents with full health from consuming healing items.</para> /// </summary> /// <param name="e">The item usage event args.</param> public static void FullHealthCheck(OnItemUsingArgs e) { if (e.Item.healthChange > 0 && e.User.health == e.User.healthMax) { if (RogueFramework.IsDebugEnabled(DebugFlags.Items)) { RogueFramework.LogDebug("---- Triggered \"FullHealth\" inventory check."); } e.User.SayDialogue("HealthFullCantUseItem"); e.User.gc.audioHandler.Play(e.User, "CantDo"); e.Cancel = e.Handled = true; } }
/// <summary> /// <para>Prevents "Electronic" agents from using medicine.</para> /// </summary> /// <param name="e">The item usage event args.</param> public static void OnlyChargeMedicineCheck(OnItemUsingArgs e) { if (e.User.electronic && e.Item.itemType == ItemTypes.Consumable && e.Item.Categories.Contains("Health")) { if (RogueFramework.IsDebugEnabled(DebugFlags.Items)) { RogueFramework.LogDebug("---- Triggered \"OnlyChargeMedicine\" inventory check."); } e.User.SayDialogue("OnlyChargeGivesHealth"); e.User.gc.audioHandler.Play(e.User, "CantDo"); e.Cancel = e.Handled = true; } }
/// <summary> /// <para>Prevents "Oil-Reliant" agents from consuming food.</para> /// </summary> /// <param name="e">The item usage event args.</param> public static void OnlyOilCheck(OnItemUsingArgs e) { if (e.Item.itemType == ItemTypes.Food && (e.Item.Categories.Contains("Food") || e.Item.Categories.Contains("Alcohol")) && e.User.HasTrait("OilRestoresHealth")) { if (RogueFramework.IsDebugEnabled(DebugFlags.Items)) { RogueFramework.LogDebug("---- Triggered \"OnlyOil\" inventory check."); } e.User.SayDialogue("OnlyOilGivesHealth"); e.User.gc.audioHandler.Play(e.User, "CantDo"); e.Cancel = e.Handled = true; } }
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); }