|
|
@@ -0,0 +1,595 @@
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.UIElements;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// Integration script that connects the new battle action system with existing character selection
|
|
|
+/// This allows switching between the old click-drag system and the new action wheel system
|
|
|
+/// </summary>
|
|
|
+public class BattleActionIntegration : MonoBehaviour
|
|
|
+{
|
|
|
+ [Header("System References")]
|
|
|
+ public PlayerDecisionController playerDecisionController;
|
|
|
+ public BattleActionSystem battleActionSystem;
|
|
|
+ public BattleActionWheel actionWheel; // Legacy Canvas-based wheel
|
|
|
+ public EnemySelectionUI enemySelectionUI; // TODO: Add after compilation
|
|
|
+ public BattleItemSelector itemSelectionUI;
|
|
|
+
|
|
|
+ [Header("Settings")]
|
|
|
+ public bool useNewActionSystem = true;
|
|
|
+ public KeyCode actionWheelKey = KeyCode.Q; // Use Q consistently
|
|
|
+
|
|
|
+ private Character lastSelectedCharacter;
|
|
|
+ private MonoBehaviour simpleWheelComponent;
|
|
|
+ private string currentInstruction = "";
|
|
|
+ private float instructionTimer = 0f;
|
|
|
+ private float instructionDuration = 5f;
|
|
|
+
|
|
|
+ void Start()
|
|
|
+ {
|
|
|
+ Debug.Log("🚀 BattleActionIntegration starting...");
|
|
|
+
|
|
|
+ // Find components if not assigned
|
|
|
+ if (playerDecisionController == null)
|
|
|
+ playerDecisionController = FindFirstObjectByType<PlayerDecisionController>();
|
|
|
+
|
|
|
+ if (battleActionSystem == null)
|
|
|
+ battleActionSystem = FindFirstObjectByType<BattleActionSystem>();
|
|
|
+
|
|
|
+ if (actionWheel == null)
|
|
|
+ actionWheel = FindFirstObjectByType<BattleActionWheel>();
|
|
|
+
|
|
|
+ if (enemySelectionUI == null)
|
|
|
+ enemySelectionUI = FindFirstObjectByType<EnemySelectionUI>();
|
|
|
+
|
|
|
+ if (itemSelectionUI == null)
|
|
|
+ itemSelectionUI = FindFirstObjectByType<BattleItemSelector>();
|
|
|
+
|
|
|
+ // Disable old drag system if using new action system (but allow re-enabling for targeting)
|
|
|
+ if (useNewActionSystem && playerDecisionController != null)
|
|
|
+ {
|
|
|
+ // Don't completely disable - we'll use it for targeting after action selection
|
|
|
+ Debug.Log("🎮 PlayerDecisionController will be used for targeting after action selection");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Try to find or create a simple wheel component
|
|
|
+ var existingWheels = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
|
|
|
+ foreach (var comp in existingWheels)
|
|
|
+ {
|
|
|
+ if (comp.GetType().Name == "SimpleActionWheel")
|
|
|
+ {
|
|
|
+ simpleWheelComponent = comp;
|
|
|
+ Debug.Log("🎮 Found existing SimpleActionWheel");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (simpleWheelComponent == null)
|
|
|
+ {
|
|
|
+ // Create simple wheel if it doesn't exist
|
|
|
+ GameObject wheelObj = new GameObject("SimpleActionWheel");
|
|
|
+ // Use reflection to add the component
|
|
|
+ var componentType = System.Type.GetType("SimpleActionWheel");
|
|
|
+ if (componentType != null)
|
|
|
+ {
|
|
|
+ simpleWheelComponent = wheelObj.AddComponent(componentType) as MonoBehaviour;
|
|
|
+ Debug.Log("🎮 Created SimpleActionWheel automatically");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ Could not find SimpleActionWheel type");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Subscribe to events
|
|
|
+ if (battleActionSystem != null)
|
|
|
+ {
|
|
|
+ battleActionSystem.OnActionCompleted += OnCharacterActionCompleted;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Connect SimpleActionWheel events using reflection
|
|
|
+ if (simpleWheelComponent != null)
|
|
|
+ {
|
|
|
+ ConnectSimpleWheelEvents();
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"✅ BattleActionIntegration initialized - useNewActionSystem: {useNewActionSystem}, actionWheelKey: {actionWheelKey}");
|
|
|
+ }
|
|
|
+
|
|
|
+ void Update()
|
|
|
+ {
|
|
|
+ if (useNewActionSystem)
|
|
|
+ {
|
|
|
+ HandleNewActionSystemInput();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update instruction timer
|
|
|
+ if (instructionTimer > 0f)
|
|
|
+ {
|
|
|
+ instructionTimer -= Time.deltaTime;
|
|
|
+ if (instructionTimer <= 0f)
|
|
|
+ {
|
|
|
+ currentInstruction = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void OnGUI()
|
|
|
+ {
|
|
|
+ // Show instruction message if active
|
|
|
+ if (!string.IsNullOrEmpty(currentInstruction))
|
|
|
+ {
|
|
|
+ GUIStyle instructionStyle = new GUIStyle(GUI.skin.label);
|
|
|
+ instructionStyle.fontSize = 18;
|
|
|
+ instructionStyle.fontStyle = FontStyle.Bold;
|
|
|
+ instructionStyle.alignment = TextAnchor.MiddleCenter;
|
|
|
+ instructionStyle.normal.textColor = Color.yellow;
|
|
|
+
|
|
|
+ Rect instructionRect = new Rect(0, 50, Screen.width, 30);
|
|
|
+
|
|
|
+ // Background
|
|
|
+ GUI.color = new Color(0, 0, 0, 0.7f);
|
|
|
+ GUI.Box(instructionRect, "");
|
|
|
+
|
|
|
+ // Text
|
|
|
+ GUI.color = Color.white;
|
|
|
+ GUI.Label(instructionRect, currentInstruction, instructionStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!useNewActionSystem) return;
|
|
|
+
|
|
|
+ // Simple UI for testing
|
|
|
+ GUILayout.BeginArea(new Rect(10, 10, 300, 250));
|
|
|
+ GUILayout.Label("Battle Action System");
|
|
|
+ GUILayout.Label($"Action Key: {actionWheelKey}");
|
|
|
+ GUILayout.Label($"Simple Wheel: {(simpleWheelComponent != null ? "✅" : "❌")}");
|
|
|
+
|
|
|
+ if (lastSelectedCharacter != null)
|
|
|
+ {
|
|
|
+ GUILayout.Label($"Selected: {lastSelectedCharacter.CharacterName}");
|
|
|
+
|
|
|
+ var actionData = lastSelectedCharacter.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData != null && actionData.hasValidAction)
|
|
|
+ {
|
|
|
+ GUILayout.Label($"Action: {actionData.GetActionDescription()}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GUILayout.Label("No character selected");
|
|
|
+ GUILayout.Label("Click a player character to select");
|
|
|
+ }
|
|
|
+
|
|
|
+ GUILayout.Label($"Press {actionWheelKey} to show action wheel");
|
|
|
+
|
|
|
+ if (GUILayout.Button("Test Action Wheel"))
|
|
|
+ {
|
|
|
+ var testCharacter = FindFirstObjectByType<Character>();
|
|
|
+ if (testCharacter != null)
|
|
|
+ {
|
|
|
+ ShowActionWheelForCharacter(testCharacter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ GUILayout.EndArea();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void HandleNewActionSystemInput()
|
|
|
+ {
|
|
|
+ // Check for character selection
|
|
|
+ if (Input.GetMouseButtonDown(0))
|
|
|
+ {
|
|
|
+ Character selectedCharacter = GetCharacterAtMousePosition();
|
|
|
+ if (selectedCharacter != null)
|
|
|
+ {
|
|
|
+ Debug.Log($"🖱️ Clicked on character: {selectedCharacter.CharacterName} - Tag: {selectedCharacter.tag}");
|
|
|
+
|
|
|
+ if (selectedCharacter.CompareTag("Player"))
|
|
|
+ {
|
|
|
+ Debug.Log($"✅ Confirmed player character: {selectedCharacter.CharacterName}");
|
|
|
+ SelectCharacterForAction(selectedCharacter);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"❌ Not a player character: {selectedCharacter.CharacterName} (Tag: {selectedCharacter.tag})");
|
|
|
+ // Try to force selection anyway for testing
|
|
|
+ Debug.Log($"🧪 Trying to select anyway for testing...");
|
|
|
+ SelectCharacterForAction(selectedCharacter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log("🖱️ Clicked but no character found");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Show action wheel with Q key
|
|
|
+ if (Input.GetKeyDown(actionWheelKey))
|
|
|
+ {
|
|
|
+ if (lastSelectedCharacter != null)
|
|
|
+ {
|
|
|
+ Debug.Log($"⌨️ {actionWheelKey} pressed, showing wheel for {lastSelectedCharacter.CharacterName}");
|
|
|
+ ShowActionWheelForCharacter(lastSelectedCharacter);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"⌨️ {actionWheelKey} pressed but no character selected");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Character GetCharacterAtMousePosition()
|
|
|
+ {
|
|
|
+ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
|
+ RaycastHit hit;
|
|
|
+
|
|
|
+ if (Physics.Raycast(ray, out hit))
|
|
|
+ {
|
|
|
+ return hit.collider.GetComponent<Character>();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SelectCharacterForAction(Character character)
|
|
|
+ {
|
|
|
+ // Clear previous selection
|
|
|
+ if (lastSelectedCharacter != null)
|
|
|
+ {
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.NoAction);
|
|
|
+ }
|
|
|
+
|
|
|
+ lastSelectedCharacter = character;
|
|
|
+
|
|
|
+ // Initialize enhanced action data if needed
|
|
|
+ var actionData = character.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData == null)
|
|
|
+ {
|
|
|
+ // Create instance at runtime to avoid compilation issues
|
|
|
+ actionData = new EnhancedCharacterActionData();
|
|
|
+ character.SetEnhancedActionData(actionData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Highlight selected character
|
|
|
+ character.SetVisualState(ActionDecisionState.NoAction);
|
|
|
+
|
|
|
+ Debug.Log($"🎯 Selected character for action: {character.CharacterName}");
|
|
|
+
|
|
|
+ // Don't auto-show wheel - let user press Q manually
|
|
|
+ // if (useNewActionSystem)
|
|
|
+ // {
|
|
|
+ // ShowActionWheelForCharacter(character);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowActionWheelForCharacter(Character character)
|
|
|
+ {
|
|
|
+ Debug.Log($"🎯 ShowActionWheelForCharacter called for: {character.CharacterName}");
|
|
|
+
|
|
|
+ // Try simple wheel first
|
|
|
+ if (simpleWheelComponent != null)
|
|
|
+ {
|
|
|
+ Debug.Log($"🎮 Found SimpleActionWheel component: {simpleWheelComponent.GetType().Name}");
|
|
|
+
|
|
|
+ // Use reflection to call ShowWheelForCharacter
|
|
|
+ var method = simpleWheelComponent.GetType().GetMethod("ShowWheelForCharacter");
|
|
|
+ if (method != null)
|
|
|
+ {
|
|
|
+ Debug.Log("🔧 Calling ShowWheelForCharacter via reflection...");
|
|
|
+ method.Invoke(simpleWheelComponent, new object[] { character });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ ShowWheelForCharacter method not found on SimpleActionWheel!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ simpleWheelComponent is null!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Fallback to battle action system
|
|
|
+ if (battleActionSystem != null)
|
|
|
+ {
|
|
|
+ Debug.Log("🔄 Falling back to BattleActionSystem...");
|
|
|
+ battleActionSystem.ShowActionWheel(character);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("BattleActionIntegration: No action wheel system found!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConnectSimpleWheelEvents()
|
|
|
+ {
|
|
|
+ if (simpleWheelComponent == null)
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ simpleWheelComponent is null in ConnectSimpleWheelEvents");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"🔧 Connecting events for SimpleActionWheel component: {simpleWheelComponent.GetType().Name}");
|
|
|
+
|
|
|
+ // Use reflection to connect to OnActionSelected event
|
|
|
+ var eventInfo = simpleWheelComponent.GetType().GetEvent("OnActionSelected");
|
|
|
+ if (eventInfo != null)
|
|
|
+ {
|
|
|
+ Debug.Log($"✅ Found OnActionSelected event: {eventInfo.EventHandlerType}");
|
|
|
+
|
|
|
+ // Create delegate that matches the event signature: Action<BattleActionType>
|
|
|
+ var delegateType = eventInfo.EventHandlerType;
|
|
|
+ var methodInfo = this.GetType().GetMethod("OnActionSelected", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
|
|
+
|
|
|
+ if (methodInfo != null)
|
|
|
+ {
|
|
|
+ Debug.Log($"✅ Found OnActionSelected method: {methodInfo.Name}");
|
|
|
+ var handler = System.Delegate.CreateDelegate(delegateType, this, methodInfo);
|
|
|
+ eventInfo.AddEventHandler(simpleWheelComponent, handler);
|
|
|
+ Debug.Log("✅ Successfully connected SimpleActionWheel.OnActionSelected event");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ Could not find OnActionSelected method in BattleActionIntegration");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ Could not find OnActionSelected event in SimpleActionWheel");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnActionSelected(BattleActionType actionType)
|
|
|
+ {
|
|
|
+ Debug.Log($"🔥 OnActionSelected called with: {actionType}");
|
|
|
+
|
|
|
+ if (lastSelectedCharacter == null)
|
|
|
+ {
|
|
|
+ Debug.LogWarning("❌ Action selected but no character selected!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"🎯 {lastSelectedCharacter.CharacterName} selected action: {actionType}");
|
|
|
+
|
|
|
+ // Set action data for the character
|
|
|
+ var actionData = lastSelectedCharacter.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData == null)
|
|
|
+ {
|
|
|
+ actionData = new EnhancedCharacterActionData();
|
|
|
+ lastSelectedCharacter.SetEnhancedActionData(actionData);
|
|
|
+ Debug.Log($"📝 Created new EnhancedCharacterActionData for {lastSelectedCharacter.CharacterName}");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Configure action based on type and enable targeting mode
|
|
|
+ switch (actionType)
|
|
|
+ {
|
|
|
+ case BattleActionType.Attack:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ Debug.Log("🗡️ Attack selected - Now drag from character to target enemy!");
|
|
|
+ ShowInstructionMessage("ATTACK: Drag from character to enemy");
|
|
|
+ StartTargetingMode(lastSelectedCharacter, actionType);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BattleActionType.Move:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ Debug.Log("👟 Move selected - Now drag from character to target position!");
|
|
|
+ ShowInstructionMessage("MOVE: Drag from character to target position");
|
|
|
+ StartTargetingMode(lastSelectedCharacter, actionType);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BattleActionType.UseItem:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ Debug.Log("🧪 Use Item selected - showing item selection UI");
|
|
|
+ ShowInstructionMessage("USE ITEM: Select item from list");
|
|
|
+ ShowItemSelection(lastSelectedCharacter);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BattleActionType.CastSpell:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ actionData.state = ActionDecisionState.ActionSelected;
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.ActionSelected);
|
|
|
+ Debug.Log("✨ Cast Spell selected - implement spell selection UI");
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BattleActionType.Defend:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ actionData.state = ActionDecisionState.ActionSelected;
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.ActionSelected);
|
|
|
+ Debug.Log("🛡️ Defend action set - character will defend this turn");
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BattleActionType.RunAway:
|
|
|
+ actionData.actionType = actionType;
|
|
|
+ actionData.state = ActionDecisionState.ActionSelected;
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.ActionSelected);
|
|
|
+ Debug.Log("💨 Run Away action set - character will attempt to flee");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"✅ Action {actionType} configured for {lastSelectedCharacter.CharacterName}");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void StartTargetingMode(Character character, BattleActionType actionType)
|
|
|
+ {
|
|
|
+ Debug.Log($"🎯 Starting targeting mode for {character.CharacterName} with action {actionType}");
|
|
|
+
|
|
|
+ // Enable the PlayerDecisionController to handle targeting
|
|
|
+ if (playerDecisionController != null)
|
|
|
+ {
|
|
|
+ // Use the new public method to start targeting
|
|
|
+ playerDecisionController.StartTargetingForCharacter(character, actionType);
|
|
|
+ Debug.Log($"✅ PlayerDecisionController targeting started for {actionType}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ PlayerDecisionController not found - cannot start targeting mode");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowItemSelection(Character character)
|
|
|
+ {
|
|
|
+ Debug.Log($"🧪 Showing item selection for {character.CharacterName}");
|
|
|
+
|
|
|
+ if (itemSelectionUI != null)
|
|
|
+ {
|
|
|
+ // Subscribe to item selection events
|
|
|
+ itemSelectionUI.OnItemSelected -= OnItemSelected;
|
|
|
+ itemSelectionUI.OnSelectionCancelled -= OnItemSelectionCancelled;
|
|
|
+ itemSelectionUI.OnItemSelected += OnItemSelected;
|
|
|
+ itemSelectionUI.OnSelectionCancelled += OnItemSelectionCancelled;
|
|
|
+
|
|
|
+ itemSelectionUI.ShowItemSelection(character);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError("❌ BattleItemSelector not found!");
|
|
|
+ // Fallback: Complete action immediately
|
|
|
+ var actionData = character.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData != null)
|
|
|
+ {
|
|
|
+ actionData.state = ActionDecisionState.ActionSelected;
|
|
|
+ character.SetVisualState(ActionDecisionState.ActionSelected);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnItemSelected(string itemName, int itemIndex)
|
|
|
+ {
|
|
|
+ Debug.Log($"📦 Item selected: {itemName} (index: {itemIndex})");
|
|
|
+
|
|
|
+ if (lastSelectedCharacter != null)
|
|
|
+ {
|
|
|
+ var actionData = lastSelectedCharacter.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData != null)
|
|
|
+ {
|
|
|
+ actionData.selectedItemName = itemName;
|
|
|
+ actionData.selectedItemIndex = itemIndex;
|
|
|
+ actionData.state = ActionDecisionState.ActionSelected;
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.ActionSelected);
|
|
|
+
|
|
|
+ Debug.Log($"✅ {lastSelectedCharacter.CharacterName} will use {itemName}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnItemSelectionCancelled()
|
|
|
+ {
|
|
|
+ Debug.Log("❌ Item selection cancelled");
|
|
|
+
|
|
|
+ if (lastSelectedCharacter != null)
|
|
|
+ {
|
|
|
+ var actionData = lastSelectedCharacter.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData != null)
|
|
|
+ {
|
|
|
+ actionData.Reset();
|
|
|
+ lastSelectedCharacter.SetVisualState(ActionDecisionState.NoAction);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnCharacterActionCompleted(Character character)
|
|
|
+ {
|
|
|
+ Debug.Log($"✅ Action completed for {character.CharacterName}");
|
|
|
+
|
|
|
+ // Clear selection after action is complete
|
|
|
+ if (character == lastSelectedCharacter)
|
|
|
+ {
|
|
|
+ lastSelectedCharacter = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Manually trigger action selection for a character (for use by other systems)
|
|
|
+ /// </summary>
|
|
|
+ public void SelectCharacter(Character character)
|
|
|
+ {
|
|
|
+ SelectCharacterForAction(character);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Execute all selected actions (for turn-based systems)
|
|
|
+ /// </summary>
|
|
|
+ public void ExecuteAllPlayerActions()
|
|
|
+ {
|
|
|
+ Character[] playerCharacters = FindObjectsByType<Character>(FindObjectsSortMode.None);
|
|
|
+
|
|
|
+ foreach (Character character in playerCharacters)
|
|
|
+ {
|
|
|
+ var actionData = character.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (character.CompareTag("Player") && actionData != null && actionData.hasValidAction)
|
|
|
+ {
|
|
|
+ if (battleActionSystem != null)
|
|
|
+ {
|
|
|
+ battleActionSystem.ExecuteCharacterAction(character);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Switch between old and new action systems
|
|
|
+ /// </summary>
|
|
|
+ public void ToggleActionSystem()
|
|
|
+ {
|
|
|
+ useNewActionSystem = !useNewActionSystem;
|
|
|
+
|
|
|
+ // Enable/disable appropriate systems
|
|
|
+ if (playerDecisionController != null)
|
|
|
+ {
|
|
|
+ playerDecisionController.enabled = !useNewActionSystem;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"🎯 Action system switched to: {(useNewActionSystem ? "New Action Wheel" : "Old Click-Drag")}");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Check if all players have selected actions
|
|
|
+ /// </summary>
|
|
|
+ public bool AllPlayersHaveActions()
|
|
|
+ {
|
|
|
+ Character[] playerCharacters = FindObjectsByType<Character>(FindObjectsSortMode.None);
|
|
|
+
|
|
|
+ foreach (Character character in playerCharacters)
|
|
|
+ {
|
|
|
+ if (character.CompareTag("Player"))
|
|
|
+ {
|
|
|
+ var actionData = character.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData == null || !actionData.hasValidAction)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Reset all player actions (useful for new turns)
|
|
|
+ /// </summary>
|
|
|
+ public void ResetAllPlayerActions()
|
|
|
+ {
|
|
|
+ Character[] playerCharacters = FindObjectsByType<Character>(FindObjectsSortMode.None);
|
|
|
+
|
|
|
+ foreach (Character character in playerCharacters)
|
|
|
+ {
|
|
|
+ if (character.CompareTag("Player"))
|
|
|
+ {
|
|
|
+ var actionData = character.GetEnhancedActionData<EnhancedCharacterActionData>();
|
|
|
+ if (actionData != null)
|
|
|
+ actionData.Reset();
|
|
|
+
|
|
|
+ character.SetVisualState(ActionDecisionState.NoAction);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lastSelectedCharacter = null;
|
|
|
+ Debug.Log("🔄 All player actions reset");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowInstructionMessage(string message)
|
|
|
+ {
|
|
|
+ currentInstruction = message;
|
|
|
+ instructionTimer = instructionDuration;
|
|
|
+ Debug.Log($"📢 Instruction: {message}");
|
|
|
+ }
|
|
|
+}
|