67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Whether this behavior consumes the item when used.
|
|
/// </summary>
|
|
public virtual bool IsConsumable => false;
|
|
|
|
/// <summary>
|
|
/// Check if this behavior can be used with the given user and target.
|
|
/// </summary>
|
|
/// <param name="user">The player/entity using the item</param>
|
|
/// <param name="target">Optional target of the use</param>
|
|
/// <returns>True if the behavior can be executed</returns>
|
|
public abstract bool CanUse(GameObject user, GameObject target);
|
|
|
|
/// <summary>
|
|
/// Execute the behavior's effect.
|
|
/// </summary>
|
|
/// <param name="user">The player/entity using the item</param>
|
|
/// <param name="target">Optional target of the use</param>
|
|
public abstract void Use(GameObject user, GameObject target);
|
|
|
|
/// <summary>
|
|
/// Get the action descriptor for this behavior.
|
|
/// </summary>
|
|
public virtual ActionDescriptor GetActionDescriptor()
|
|
{
|
|
return new ActionDescriptor
|
|
{
|
|
ActionName = behaviorName,
|
|
Duration = duration,
|
|
AnimTrigger = animTrigger,
|
|
AnimSpeed = animSpeed,
|
|
ImpactDelay = impactDelay,
|
|
CanRepeat = canRepeat,
|
|
SoundEffect = useSound,
|
|
ParticleEffect = useEffect
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a description of why the behavior cannot be used.
|
|
/// </summary>
|
|
public virtual string GetBlockedReason(GameObject user, GameObject target)
|
|
{
|
|
return null;
|
|
}
|
|
} |