Add score to FortFight, clean up the resets
This commit is contained in:
@@ -5529,7 +5529,7 @@ GameObject:
|
|||||||
- component: {fileID: 1156219949}
|
- component: {fileID: 1156219949}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: MainCanvas
|
m_Name: MainCanvas
|
||||||
m_TagString: Untagged
|
m_TagString: MainCanvas
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
@@ -5613,7 +5613,7 @@ RectTransform:
|
|||||||
- {fileID: 1585033672}
|
- {fileID: 1585033672}
|
||||||
- {fileID: 805585728}
|
- {fileID: 805585728}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -0.079}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
@@ -8511,7 +8511,7 @@ Camera:
|
|||||||
far clip plane: 1000
|
far clip plane: 1000
|
||||||
field of view: 60
|
field of view: 60
|
||||||
orthographic: 1
|
orthographic: 1
|
||||||
orthographic size: 20
|
orthographic size: 35
|
||||||
m_Depth: -1
|
m_Depth: -1
|
||||||
m_CullingMask:
|
m_CullingMask:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -8536,7 +8536,7 @@ Transform:
|
|||||||
m_GameObject: {fileID: 1810521056}
|
m_GameObject: {fileID: 1810521056}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
m_LocalPosition: {x: 0, y: 13.5999975, z: -10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ namespace Minigames.FortFight.Core
|
|||||||
private PlayerData playerTwo;
|
private PlayerData playerTwo;
|
||||||
private bool isGameActive = false;
|
private bool isGameActive = false;
|
||||||
private float gameStartTime = 0f;
|
private float gameStartTime = 0f;
|
||||||
|
private float completionTime = 0f; // Store completion time when game ends
|
||||||
|
|
||||||
public FortFightGameMode CurrentGameMode => currentGameMode;
|
public FortFightGameMode CurrentGameMode => currentGameMode;
|
||||||
public bool IsGameActive => isGameActive;
|
public bool IsGameActive => isGameActive;
|
||||||
@@ -73,6 +74,11 @@ namespace Minigames.FortFight.Core
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (!isGameActive && completionTime > 0f)
|
||||||
|
{
|
||||||
|
// Game ended, return the stored completion time
|
||||||
|
return completionTime;
|
||||||
|
}
|
||||||
if (!isGameActive) return 0f;
|
if (!isGameActive) return 0f;
|
||||||
return Time.time - gameStartTime;
|
return Time.time - gameStartTime;
|
||||||
}
|
}
|
||||||
@@ -333,6 +339,8 @@ namespace Minigames.FortFight.Core
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store completion time before setting isGameActive to false
|
||||||
|
completionTime = Time.time - gameStartTime;
|
||||||
isGameActive = false;
|
isGameActive = false;
|
||||||
|
|
||||||
// Stop turn manager
|
// Stop turn manager
|
||||||
@@ -341,12 +349,123 @@ namespace Minigames.FortFight.Core
|
|||||||
TurnManager.Instance.SetGameOver();
|
TurnManager.Instance.SetGameOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage UI transitions
|
// Start the end game sequence (show boosters, then game over screen)
|
||||||
ShowGameOver();
|
StartCoroutine(EndGameSequence());
|
||||||
|
|
||||||
OnGameEnded?.Invoke();
|
OnGameEnded?.Invoke();
|
||||||
|
|
||||||
Logging.Debug("[FortFightGameManager] Game ended");
|
Logging.Debug($"[FortFightGameManager] Game ended - Duration: {completionTime:F2}s");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// End game sequence: award boosters, wait for completion, then show game over screen
|
||||||
|
/// </summary>
|
||||||
|
private System.Collections.IEnumerator EndGameSequence()
|
||||||
|
{
|
||||||
|
// Determine if player won
|
||||||
|
bool playerWon = DidPlayerWin();
|
||||||
|
|
||||||
|
// Calculate booster reward based on completion time and win/loss
|
||||||
|
int boosterReward = CalculateBoosterReward(completionTime, playerWon);
|
||||||
|
|
||||||
|
string resultText = playerWon ? "WON" : "LOST";
|
||||||
|
Logging.Debug($"[FortFightGameManager] Game completed in {completionTime:F2}s - Player {resultText}, awarding {boosterReward} booster pack(s)");
|
||||||
|
|
||||||
|
// Show booster pack reward UI and wait for completion
|
||||||
|
if (boosterReward > 0)
|
||||||
|
{
|
||||||
|
Logging.Debug("[FortFightGameManager] Starting booster giver sequence via GameManager");
|
||||||
|
|
||||||
|
var task = GameManager.Instance.GiveBoosterPacksAsync(boosterReward);
|
||||||
|
|
||||||
|
// Wait for the task to complete
|
||||||
|
while (!task.IsCompleted)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for exceptions
|
||||||
|
if (task.IsFaulted)
|
||||||
|
{
|
||||||
|
Logging.Warning($"[FortFightGameManager] Booster pack reward failed: {task.Exception?.GetBaseException().Message}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Debug("[FortFightGameManager] Booster giver sequence finished, proceeding to game over screen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Debug("[FortFightGameManager] No boosters to award, proceeding directly to game over screen");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now show game over screen
|
||||||
|
ShowGameOver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine if the player won the game
|
||||||
|
/// </summary>
|
||||||
|
private bool DidPlayerWin()
|
||||||
|
{
|
||||||
|
var fortManager = FortManager.Instance;
|
||||||
|
if (fortManager == null)
|
||||||
|
{
|
||||||
|
Logging.Warning("[FortFightGameManager] Cannot determine winner - FortManager not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool playerDefeated = fortManager.PlayerFort?.IsDefeated ?? false;
|
||||||
|
bool enemyDefeated = fortManager.EnemyFort?.IsDefeated ?? false;
|
||||||
|
|
||||||
|
// Player wins if enemy fort is defeated and player fort is not
|
||||||
|
return enemyDefeated && !playerDefeated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate booster pack reward based on completion time and game result.
|
||||||
|
///
|
||||||
|
/// If player WON:
|
||||||
|
/// < 1min: 5 Booster Packs
|
||||||
|
/// < 3min: 4 Booster Packs
|
||||||
|
/// < 5min: 3 Booster Packs
|
||||||
|
/// < 7min: 2 Booster Packs
|
||||||
|
/// >= 7min: 1 Booster Pack
|
||||||
|
///
|
||||||
|
/// If player LOST:
|
||||||
|
/// 1 Booster Pack (participation reward)
|
||||||
|
/// </summary>
|
||||||
|
private int CalculateBoosterReward(float timeInSeconds, bool playerWon)
|
||||||
|
{
|
||||||
|
// If player lost, give participation reward
|
||||||
|
if (!playerWon)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If player won, calculate reward based on completion time
|
||||||
|
float minutes = timeInSeconds / 60f;
|
||||||
|
|
||||||
|
if (minutes < 1f)
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
else if (minutes < 3f)
|
||||||
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
else if (minutes < 5f)
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else if (minutes < 7f)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Core;
|
using System;
|
||||||
|
using Core;
|
||||||
using Core.Lifecycle;
|
using Core.Lifecycle;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -220,12 +221,10 @@ namespace Minigames.FortFight.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restart the game by reloading the current scene
|
/// Restart the game by reloading the current scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RestartGame()
|
private async void RestartGame()
|
||||||
{
|
{
|
||||||
// Use Unity's SceneManager to reload current scene
|
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||||
string currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
await SceneManagerService.Instance.ReloadCurrentScene(progress);
|
||||||
Logging.Debug($"[GameOverUI] Reloading scene: {currentScene}");
|
|
||||||
UnityEngine.SceneManagement.SceneManager.LoadScene(currentScene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user