Make a generic booster pack giver
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using AppleHills.Core.Interfaces;
|
||||
using AppleHills.Core.Settings;
|
||||
using Cinematics;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
@@ -8,10 +7,10 @@ using Minigames.DivingForPictures.PictureCamera;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Core.Settings;
|
||||
using Minigames.DivingForPictures.Bubbles;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
@@ -664,40 +663,64 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
_activeMonsters.Clear();
|
||||
|
||||
// 1) Call the booster pack giver if available
|
||||
bool completed = false;
|
||||
var giver = UI.CardSystem.MinigameBoosterGiver.Instance;
|
||||
if (giver != null)
|
||||
{
|
||||
UIPageController.Instance.ShowAllUI();
|
||||
Logging.Debug("[DivingGameManager] Starting booster giver sequence");
|
||||
giver.GiveBooster(() =>
|
||||
{
|
||||
completed = true;
|
||||
Logging.Debug("[DivingGameManager] Booster giver completed callback received");
|
||||
});
|
||||
// Calculate booster pack reward based on pictures taken
|
||||
int boosterPackCount = CalculateBoosterPackReward();
|
||||
Logging.Debug($"[DivingGameManager] Pictures taken: {picturesTaken}, awarding {boosterPackCount} booster pack(s)");
|
||||
|
||||
// 2) Wait for it to finish (NO timeout - wait indefinitely for user interaction)
|
||||
while (!completed)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Logging.Debug("[DivingGameManager] Booster giver sequence finished, proceeding to game over");
|
||||
// Show UI and grant booster packs using new async method
|
||||
UIPageController.Instance.ShowAllUI();
|
||||
Logging.Debug("[DivingGameManager] Starting booster giver sequence via GameManager");
|
||||
|
||||
// Use the new GameManager method to handle the booster pack reward
|
||||
var task = GameManager.Instance.GiveBoosterPacksAsync(boosterPackCount);
|
||||
|
||||
// Wait for the task to complete
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Check for exceptions
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Logging.Warning($"[DivingGameManager] Booster pack reward failed: {task.Exception?.GetBaseException().Message}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// If no giver is present, proceed immediately
|
||||
Logging.Debug("[DivingGameManager] MinigameBoosterGiver not found; skipping booster animation.");
|
||||
Logging.Debug("[DivingGameManager] Booster giver sequence finished, proceeding to game over");
|
||||
}
|
||||
|
||||
// 3) Only then show the game over screen
|
||||
// Show the game over screen
|
||||
CinematicsManager.Instance.ShowGameOverScreen();
|
||||
|
||||
// Final score could be saved to player prefs or other persistence
|
||||
Logging.Debug($"Final Score: {_playerScore}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates how many booster packs to award based on the number of pictures taken.
|
||||
/// </summary>
|
||||
/// <returns>Number of booster packs to award</returns>
|
||||
private int CalculateBoosterPackReward()
|
||||
{
|
||||
if (picturesTaken <= 3)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (picturesTaken <= 5)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if (picturesTaken <= 10)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts a smooth transition to the new velocity factor
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user