140 lines
4.9 KiB
C#
140 lines
4.9 KiB
C#
using Core;
|
|
using UnityEngine;
|
|
using Core.Lifecycle;
|
|
using Minigames.FortFight.Core;
|
|
using Minigames.FortFight.Data;
|
|
|
|
namespace Minigames.FortFight
|
|
{
|
|
/// <summary>
|
|
/// Debug script to test Phase 1 implementation without full UI setup.
|
|
/// Attach to a GameObject in the scene to run automated tests.
|
|
/// </summary>
|
|
public class FortFightPhase1Tester : ManagedBehaviour
|
|
{
|
|
[Header("Test Settings")]
|
|
[SerializeField] private bool runAutomatedTest = true;
|
|
[SerializeField] private FortFightGameMode testMode = FortFightGameMode.SinglePlayer;
|
|
[SerializeField] private int numberOfTurnsToTest = 6;
|
|
|
|
private FortFightGameManager gameManager;
|
|
private TurnManager turnManager;
|
|
private int playerActionsExecuted = 0;
|
|
|
|
internal override void OnManagedStart()
|
|
{
|
|
base.OnManagedStart();
|
|
|
|
if (!runAutomatedTest)
|
|
{
|
|
Logging.Debug("[FortFightPhase1Tester] Automated test disabled");
|
|
return;
|
|
}
|
|
|
|
// Find managers
|
|
gameManager = FindFirstObjectByType<FortFightGameManager>();
|
|
turnManager = FindFirstObjectByType<TurnManager>();
|
|
|
|
if (gameManager == null)
|
|
{
|
|
Logging.Error("[FortFightPhase1Tester] FortFightGameManager not found!");
|
|
return;
|
|
}
|
|
|
|
if (turnManager == null)
|
|
{
|
|
Logging.Error("[FortFightPhase1Tester] TurnManager not found!");
|
|
return;
|
|
}
|
|
|
|
// Subscribe to events for testing
|
|
gameManager.OnGameModeSelected += OnGameModeSelected;
|
|
gameManager.OnGameStarted += OnGameStarted;
|
|
turnManager.OnTurnStarted += OnTurnStarted;
|
|
turnManager.OnTurnEnded += OnTurnEnded;
|
|
|
|
// Start test
|
|
Logging.Debug("=== STARTING PHASE 1 AUTOMATED TEST ===");
|
|
Logging.Debug($"Testing mode: {testMode}");
|
|
Logging.Debug($"Will execute {numberOfTurnsToTest} turns total");
|
|
|
|
// Simulate mode selection
|
|
gameManager.SelectGameMode(testMode);
|
|
}
|
|
|
|
private void OnGameModeSelected(FortFightGameMode mode)
|
|
{
|
|
Logging.Debug($"[TEST] Game mode selected: {mode}");
|
|
}
|
|
|
|
private void OnGameStarted()
|
|
{
|
|
Logging.Debug("[TEST] Game started!");
|
|
}
|
|
|
|
private void OnTurnStarted(PlayerData currentPlayer, TurnState turnState)
|
|
{
|
|
Logging.Debug($"[TEST] Turn started - Player: {currentPlayer.PlayerName}, State: {turnState}, Turn #: {turnManager.TurnCount + 1}");
|
|
|
|
// If it's a human player's turn (not AI), simulate taking action after a delay
|
|
if (turnState == TurnState.PlayerOneTurn || turnState == TurnState.PlayerTwoTurn)
|
|
{
|
|
Invoke(nameof(SimulatePlayerAction), 0.5f);
|
|
}
|
|
|
|
// Check if we've reached the test limit
|
|
if (turnManager.TurnCount >= numberOfTurnsToTest)
|
|
{
|
|
Logging.Debug("=== TEST COMPLETE ===");
|
|
Logging.Debug($"Successfully completed {numberOfTurnsToTest} turns!");
|
|
Logging.Debug($"Player actions executed: {playerActionsExecuted}");
|
|
|
|
// End the game
|
|
gameManager.EndGame();
|
|
}
|
|
}
|
|
|
|
private void OnTurnEnded(PlayerData player)
|
|
{
|
|
Logging.Debug($"[TEST] Turn ended for {player.PlayerName}");
|
|
}
|
|
|
|
private void SimulatePlayerAction()
|
|
{
|
|
if (turnManager == null) return;
|
|
|
|
TurnState state = turnManager.CurrentTurnState;
|
|
|
|
// Only simulate if it's still a player turn (not transitioned yet)
|
|
if (state == TurnState.PlayerOneTurn || state == TurnState.PlayerTwoTurn)
|
|
{
|
|
PlayerData currentPlayer = turnManager.CurrentPlayer;
|
|
Logging.Debug($"[TEST] Simulating action for {currentPlayer.PlayerName}");
|
|
playerActionsExecuted++;
|
|
|
|
// End the turn
|
|
turnManager.EndTurn();
|
|
}
|
|
}
|
|
|
|
internal override void OnManagedDestroy()
|
|
{
|
|
base.OnManagedDestroy();
|
|
|
|
// Unsubscribe from events
|
|
if (gameManager != null)
|
|
{
|
|
gameManager.OnGameModeSelected -= OnGameModeSelected;
|
|
gameManager.OnGameStarted -= OnGameStarted;
|
|
}
|
|
|
|
if (turnManager != null)
|
|
{
|
|
turnManager.OnTurnStarted -= OnTurnStarted;
|
|
turnManager.OnTurnEnded -= OnTurnEnded;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|