using UnityEngine; /// /// Base class for item behaviors. Allows different items to have /// completely different use effects without modifying ItemData. /// This is the Strategy pattern for item actions. /// public abstract class ItemBehavior : ScriptableObject { [Header("Basic Settings")] [SerializeField] protected string behaviorName = "Use"; [SerializeField] protected float duration = 0.5f; [SerializeField] protected string animTrigger = "Use"; [SerializeField] protected float animSpeed = 1f; [SerializeField] protected float impactDelay = 0.2f; [SerializeField] protected bool canRepeat = false; [Header("Effects")] [SerializeField] protected AudioClip useSound; [SerializeField] protected GameObject useEffect; /// /// Whether this behavior consumes the item when used. /// public virtual bool IsConsumable => false; /// /// Check if this behavior can be used with the given user and target. /// /// The player/entity using the item /// Optional target of the use /// True if the behavior can be executed public abstract bool CanUse(GameObject user, GameObject target); /// /// Execute the behavior's effect. /// /// The player/entity using the item /// Optional target of the use public abstract void Use(GameObject user, GameObject target); /// /// Get the action descriptor for this behavior. /// public virtual ActionDescriptor GetActionDescriptor() { return new ActionDescriptor { ActionName = behaviorName, Duration = duration, AnimTrigger = animTrigger, AnimSpeed = animSpeed, ImpactDelay = impactDelay, CanRepeat = canRepeat, SoundEffect = useSound, ParticleEffect = useEffect }; } /// /// Get a description of why the behavior cannot be used. /// public virtual string GetBlockedReason(GameObject user, GameObject target) { return null; } }