using System.Collections.Generic; using UnityEngine; /// /// Requirement for performing an action (item cost, etc.). /// [System.Serializable] public struct ActionRequirement { /// /// Item ID required (use -1 if no item required). /// public int ItemID; /// /// Amount of the item required. /// public int Amount; /// /// Whether the item is consumed when the action is performed. /// public bool ConsumeOnUse; public ActionRequirement(int itemID, int amount, bool consumeOnUse = true) { ItemID = itemID; Amount = amount; ConsumeOnUse = consumeOnUse; } /// /// No requirement. /// public static ActionRequirement None => new ActionRequirement(-1, 0, false); } /// /// Describes an action that can be performed. /// [System.Serializable] public class ActionDescriptor { /// /// Display name of the action. /// public string ActionName = "Action"; /// /// Total duration of the action in seconds. /// public float Duration = 0.5f; /// /// Animation trigger name. /// public string AnimTrigger = "Interact"; /// /// Animation playback speed multiplier. /// public float AnimSpeed = 1f; /// /// Time within the animation when the effect occurs (for syncing hit with animation). /// public float ImpactDelay = 0f; /// /// Sound effect to play. /// public AudioClip SoundEffect; /// /// Particle effect prefab to spawn. /// public GameObject ParticleEffect; /// /// Stamina cost to perform this action. /// public float StaminaCost = 0f; /// /// Item requirements for this action. /// public ActionRequirement[] ItemRequirements; /// /// Whether this action can be repeated by holding the button. /// public bool CanRepeat = false; /// /// Cooldown time before this action can be performed again. /// public float Cooldown = 0f; /// /// Create a simple action descriptor. /// public static ActionDescriptor Simple(string name, float duration, string animTrigger = "Interact") { return new ActionDescriptor { ActionName = name, Duration = duration, AnimTrigger = animTrigger }; } /// /// Create an action descriptor for repeatable actions (like mining). /// public static ActionDescriptor Repeatable(string name, float duration, string animTrigger, float impactDelay, float animSpeed = 1f) { return new ActionDescriptor { ActionName = name, Duration = duration, AnimTrigger = animTrigger, AnimSpeed = animSpeed, ImpactDelay = impactDelay, CanRepeat = true }; } } /// /// Interface for objects that can provide action descriptors. /// Implement this to define what actions can be performed on or with an object. /// public interface IActionProvider { /// /// Get the primary action descriptor for this provider. /// ActionDescriptor GetActionDescriptor(); /// /// Get all available actions from this provider. /// Default implementation returns only the primary action. /// IEnumerable GetAvailableActions() { yield return GetActionDescriptor(); } /// /// Check if a specific action can be performed. /// /// The GameObject attempting the action /// The action to check /// True if the action can be performed bool CanPerformAction(GameObject performer, ActionDescriptor action) { return true; } /// /// Get the reason why an action cannot be performed. /// /// The GameObject attempting the action /// The action to check /// Reason string, or null if action can be performed string GetActionBlockedReason(GameObject performer, ActionDescriptor action) { return null; } }