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