BattleActionData.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. /// <summary>
  4. /// Defines all possible battle actions a character can take
  5. /// </summary>
  6. public enum BattleActionType
  7. {
  8. Move,
  9. Attack,
  10. UseItem,
  11. CastSpell,
  12. RunAway,
  13. Defend, // Optional: block/defend action
  14. Wait // Optional: skip turn but maintain position
  15. }
  16. /// <summary>
  17. /// Enhanced action data to support multiple action types
  18. /// </summary>
  19. [System.Serializable]
  20. public class EnhancedCharacterActionData
  21. {
  22. [Header("Action State")]
  23. public ActionDecisionState state = ActionDecisionState.NoAction;
  24. public BattleActionType actionType = BattleActionType.Move;
  25. [Header("Targeting")]
  26. public Vector3 targetPosition = Vector3.zero;
  27. public GameObject targetEnemy;
  28. public Character targetCharacter; // For healing spells/items
  29. [Header("Item/Spell Data")]
  30. public string selectedItemName = "";
  31. public string selectedSpellName = "";
  32. public int selectedItemIndex = -1;
  33. [Header("Action Properties")]
  34. public bool requiresTarget = false;
  35. public bool isAreaOfEffect = false;
  36. public float aoeRadius = 0f;
  37. public bool hasTarget => targetEnemy != null || targetCharacter != null || targetPosition != Vector3.zero;
  38. public bool hasValidAction => state == ActionDecisionState.ActionSelected &&
  39. (actionType == BattleActionType.Wait ||
  40. actionType == BattleActionType.Defend ||
  41. actionType == BattleActionType.RunAway ||
  42. hasTarget ||
  43. (!string.IsNullOrEmpty(selectedItemName) && selectedItemIndex >= 0) ||
  44. !string.IsNullOrEmpty(selectedSpellName));
  45. public void Reset()
  46. {
  47. state = ActionDecisionState.NoAction;
  48. actionType = BattleActionType.Move;
  49. targetPosition = Vector3.zero;
  50. targetEnemy = null;
  51. targetCharacter = null;
  52. selectedItemName = "";
  53. selectedSpellName = "";
  54. selectedItemIndex = -1;
  55. requiresTarget = false;
  56. isAreaOfEffect = false;
  57. aoeRadius = 0f;
  58. }
  59. public void SetMoveAction(Vector3 position)
  60. {
  61. Reset();
  62. actionType = BattleActionType.Move;
  63. targetPosition = position;
  64. state = ActionDecisionState.ActionSelected;
  65. }
  66. public void SetAttackAction(GameObject enemy)
  67. {
  68. Reset();
  69. actionType = BattleActionType.Attack;
  70. targetEnemy = enemy;
  71. requiresTarget = true;
  72. state = ActionDecisionState.ActionSelected;
  73. }
  74. public void SetItemAction(string itemName, int itemIndex, bool requiresTargeting = false)
  75. {
  76. Reset();
  77. actionType = BattleActionType.UseItem;
  78. selectedItemName = itemName;
  79. selectedItemIndex = itemIndex;
  80. requiresTarget = requiresTargeting;
  81. state = requiresTargeting ? ActionDecisionState.NoAction : ActionDecisionState.ActionSelected;
  82. }
  83. public void SetSpellAction(string spellName, bool requiresTargeting = false, bool isAoE = false, float radius = 0f)
  84. {
  85. Reset();
  86. actionType = BattleActionType.CastSpell;
  87. selectedSpellName = spellName;
  88. requiresTarget = requiresTargeting;
  89. isAreaOfEffect = isAoE;
  90. aoeRadius = radius;
  91. state = requiresTargeting ? ActionDecisionState.NoAction : ActionDecisionState.ActionSelected;
  92. }
  93. public void SetDefendAction()
  94. {
  95. Reset();
  96. actionType = BattleActionType.Defend;
  97. state = ActionDecisionState.ActionSelected;
  98. }
  99. public void SetWaitAction()
  100. {
  101. Reset();
  102. actionType = BattleActionType.Wait;
  103. state = ActionDecisionState.ActionSelected;
  104. }
  105. public void SetRunAwayAction()
  106. {
  107. Reset();
  108. actionType = BattleActionType.RunAway;
  109. state = ActionDecisionState.ActionSelected;
  110. }
  111. public void SetTarget(GameObject enemy)
  112. {
  113. targetEnemy = enemy;
  114. if (requiresTarget)
  115. {
  116. state = ActionDecisionState.ActionSelected;
  117. }
  118. }
  119. public void SetTarget(Character character)
  120. {
  121. targetCharacter = character;
  122. if (requiresTarget)
  123. {
  124. state = ActionDecisionState.ActionSelected;
  125. }
  126. }
  127. public void SetTarget(Vector3 position)
  128. {
  129. targetPosition = position;
  130. if (requiresTarget && (isAreaOfEffect || actionType == BattleActionType.CastSpell))
  131. {
  132. state = ActionDecisionState.ActionSelected;
  133. }
  134. }
  135. public string GetActionDescription()
  136. {
  137. switch (actionType)
  138. {
  139. case BattleActionType.Move:
  140. return $"Move to {targetPosition}";
  141. case BattleActionType.Attack:
  142. return $"Attack {(targetEnemy ? targetEnemy.name : "target")}";
  143. case BattleActionType.UseItem:
  144. return $"Use {selectedItemName}";
  145. case BattleActionType.CastSpell:
  146. return $"Cast {selectedSpellName}";
  147. case BattleActionType.Defend:
  148. return "Defend";
  149. case BattleActionType.Wait:
  150. return "Wait";
  151. case BattleActionType.RunAway:
  152. return "Run Away";
  153. default:
  154. return "No Action";
  155. }
  156. }
  157. }