| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using UnityEngine;
- using System.Collections.Generic;
- /// <summary>
- /// Defines all possible battle actions a character can take
- /// </summary>
- public enum BattleActionType
- {
- Move,
- Attack,
- UseItem,
- CastSpell,
- RunAway,
- Defend, // Optional: block/defend action
- Wait // Optional: skip turn but maintain position
- }
- /// <summary>
- /// Enhanced action data to support multiple action types
- /// </summary>
- [System.Serializable]
- public class EnhancedCharacterActionData
- {
- [Header("Action State")]
- public ActionDecisionState state = ActionDecisionState.NoAction;
- public BattleActionType actionType = BattleActionType.Move;
- [Header("Targeting")]
- public Vector3 targetPosition = Vector3.zero;
- public GameObject targetEnemy;
- public Character targetCharacter; // For healing spells/items
- [Header("Item/Spell Data")]
- public string selectedItemName = "";
- public string selectedSpellName = "";
- public int selectedItemIndex = -1;
- [Header("Action Properties")]
- public bool requiresTarget = false;
- public bool isAreaOfEffect = false;
- public float aoeRadius = 0f;
- public bool hasTarget => targetEnemy != null || targetCharacter != null || targetPosition != Vector3.zero;
- public bool hasValidAction => state == ActionDecisionState.ActionSelected &&
- (actionType == BattleActionType.Wait ||
- actionType == BattleActionType.Defend ||
- actionType == BattleActionType.RunAway ||
- hasTarget ||
- (!string.IsNullOrEmpty(selectedItemName) && selectedItemIndex >= 0) ||
- !string.IsNullOrEmpty(selectedSpellName));
- public void Reset()
- {
- state = ActionDecisionState.NoAction;
- actionType = BattleActionType.Move;
- targetPosition = Vector3.zero;
- targetEnemy = null;
- targetCharacter = null;
- selectedItemName = "";
- selectedSpellName = "";
- selectedItemIndex = -1;
- requiresTarget = false;
- isAreaOfEffect = false;
- aoeRadius = 0f;
- }
- public void SetMoveAction(Vector3 position)
- {
- Reset();
- actionType = BattleActionType.Move;
- targetPosition = position;
- state = ActionDecisionState.ActionSelected;
- }
- public void SetAttackAction(GameObject enemy)
- {
- Reset();
- actionType = BattleActionType.Attack;
- targetEnemy = enemy;
- requiresTarget = true;
- state = ActionDecisionState.ActionSelected;
- }
- public void SetItemAction(string itemName, int itemIndex, bool requiresTargeting = false)
- {
- Reset();
- actionType = BattleActionType.UseItem;
- selectedItemName = itemName;
- selectedItemIndex = itemIndex;
- requiresTarget = requiresTargeting;
- state = requiresTargeting ? ActionDecisionState.NoAction : ActionDecisionState.ActionSelected;
- }
- public void SetSpellAction(string spellName, bool requiresTargeting = false, bool isAoE = false, float radius = 0f)
- {
- Reset();
- actionType = BattleActionType.CastSpell;
- selectedSpellName = spellName;
- requiresTarget = requiresTargeting;
- isAreaOfEffect = isAoE;
- aoeRadius = radius;
- state = requiresTargeting ? ActionDecisionState.NoAction : ActionDecisionState.ActionSelected;
- }
- public void SetDefendAction()
- {
- Reset();
- actionType = BattleActionType.Defend;
- state = ActionDecisionState.ActionSelected;
- }
- public void SetWaitAction()
- {
- Reset();
- actionType = BattleActionType.Wait;
- state = ActionDecisionState.ActionSelected;
- }
- public void SetRunAwayAction()
- {
- Reset();
- actionType = BattleActionType.RunAway;
- state = ActionDecisionState.ActionSelected;
- }
- public void SetTarget(GameObject enemy)
- {
- targetEnemy = enemy;
- if (requiresTarget)
- {
- state = ActionDecisionState.ActionSelected;
- }
- }
- public void SetTarget(Character character)
- {
- targetCharacter = character;
- if (requiresTarget)
- {
- state = ActionDecisionState.ActionSelected;
- }
- }
- public void SetTarget(Vector3 position)
- {
- targetPosition = position;
- if (requiresTarget && (isAreaOfEffect || actionType == BattleActionType.CastSpell))
- {
- state = ActionDecisionState.ActionSelected;
- }
- }
- public string GetActionDescription()
- {
- switch (actionType)
- {
- case BattleActionType.Move:
- return $"Move to {targetPosition}";
- case BattleActionType.Attack:
- return $"Attack {(targetEnemy ? targetEnemy.name : "target")}";
- case BattleActionType.UseItem:
- return $"Use {selectedItemName}";
- case BattleActionType.CastSpell:
- return $"Cast {selectedSpellName}";
- case BattleActionType.Defend:
- return "Defend";
- case BattleActionType.Wait:
- return "Wait";
- case BattleActionType.RunAway:
- return "Run Away";
- default:
- return "No Action";
- }
- }
- }
|