Screenshots in Diving Minigame

This commit is contained in:
Michal Pikulski
2025-12-18 10:52:12 +01:00
parent 4e992ccf53
commit ca56e748ba
22 changed files with 1516 additions and 143 deletions

View File

@@ -1,4 +1,4 @@
using AppleHills.Core.Interfaces;
using AppleHills.Core.Interfaces;
using Cinematics;
using Core;
using Core.Lifecycle;
@@ -9,6 +9,7 @@ using System.Collections;
using System.Collections.Generic;
using Core.Settings;
using Minigames.DivingForPictures.Bubbles;
using Minigames.DivingForPictures.Screenshot;
using UI.Core;
using UnityEngine;
using UnityEngine.Playables;
@@ -55,7 +56,9 @@ namespace Minigames.DivingForPictures
// Public properties
public int PlayerScore => _playerScore;
public float CurrentVelocityFactor => _currentVelocityFactor;
public int picturesTaken;
// Delegate to DivingScreenshotManager for backward compatibility
public int picturesTaken => DivingScreenshotManager.Instance != null ? DivingScreenshotManager.Instance.ScreenshotCount : 0;
// Events
public event Action<int> OnScoreChanged;
@@ -284,23 +287,7 @@ namespace Minigames.DivingForPictures
}
}
private void DoPictureTaken(Monster.Monster monster)
{
// Calculate points based on depth
int depthBonus = Mathf.FloorToInt(Mathf.Abs(monster.transform.position.y) * _settings.DepthMultiplier);
int pointsAwarded = _settings.BasePoints + depthBonus;
// Add score
_playerScore += pointsAwarded;
// Add number of pictures taken
picturesTaken += 1;
// Fire events
OnScoreChanged?.Invoke(picturesTaken);
OnPictureTaken?.Invoke(monster, picturesTaken);
}
// Photo logic moved to DivingScreenshotManager
/// <summary>
/// Called when the player takes damage from any collision
@@ -667,8 +654,13 @@ namespace Minigames.DivingForPictures
_activeMonsters.Clear();
// Calculate booster pack reward based on pictures taken
int boosterPackCount = CalculateBoosterPackReward();
Logging.Debug($"[DivingGameManager] Pictures taken: {picturesTaken}, awarding {boosterPackCount} booster pack(s)");
int boosterPackCount = DivingScreenshotManager.Instance != null
? DivingScreenshotManager.Instance.CalculateBoosterPackReward()
: 1;
int screenshotCount = DivingScreenshotManager.Instance != null
? DivingScreenshotManager.Instance.ScreenshotCount
: 0;
Logging.Debug($"[DivingGameManager] Pictures taken: {screenshotCount}, awarding {boosterPackCount} booster pack(s)");
// Show UI and grant booster packs using new async method
UIPageController.Instance.ShowAllUI();
@@ -700,29 +692,7 @@ namespace Minigames.DivingForPictures
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;
}
}
// Booster reward calculation moved to DivingScreenshotManager
/// <summary>
/// Starts a smooth transition to the new velocity factor
@@ -949,66 +919,49 @@ namespace Minigames.DivingForPictures
{
if (!_isPhotoSequenceActive || _currentPhotoTarget == null)
return;
// Stop the viewfinder animation if it's still running
if (viewfinderManager != null)
// Start coroutine to handle screenshot and cleanup
StartCoroutine(TakePictureCoroutine());
}
/// <summary>
/// Coroutine that takes screenshot and waits for completion before cleanup
/// </summary>
private IEnumerator TakePictureCoroutine()
{
// Take screenshot and WAIT for it to complete
if (DivingScreenshotManager.Instance != null)
{
viewfinderManager.StopViewfinderAnimation();
yield return DivingScreenshotManager.Instance.TakeScreenshotAsync(_currentPhotoTarget, _capturedProximity);
}
else
{
Logging.Warning("[DivingGameManager] DivingScreenshotManager not found!");
}
// Play shutter sound
if (cameraViewfinderManager != null)
{
cameraViewfinderManager.PlayShutterSound();
}
// Notify the monster that its picture was taken
_currentPhotoTarget.NotifyPictureTaken();
// Calculate score based on proximity and depth
CalculateScore(_currentPhotoTarget, _capturedProximity);
//Trigger the Flash Effect
if (flashRef != null)
if (_currentPhotoTarget != null)
{
var flash = flashRef.GetComponent<FlashBehaviour>();
if (flash != null)
{
flash.TriggerFlash();
cameraViewfinderManager.PlayShutterSound();
}
_currentPhotoTarget.NotifyPictureTaken();
}
// NOW destroy the viewfinder (screenshot is complete)
if (viewfinderManager != null)
{
viewfinderManager.StopViewfinderAnimation();
}
// Complete the sequence
CompletePhotoSequence();
}
/// <summary>
/// Calculates the score for a picture based on proximity to target and monster depth
/// </summary>
private void CalculateScore(Monster.Monster monster, float proximity)
{
if (monster == null) return;
// Calculate base points from depth
int depthBonus = Mathf.FloorToInt(Mathf.Abs(monster.transform.position.y) * _settings.DepthMultiplier);
// Apply proximity multiplier (0-100%)
float proximityMultiplier = Mathf.Clamp01(proximity); // Ensure it's in 0-1 range
int proximityBonus = Mathf.RoundToInt(_settings.BasePoints * proximityMultiplier);
// Calculate total score
int pointsAwarded = _settings.BasePoints + proximityBonus + depthBonus;
Logging.Debug($"[DivingGameManager] Picture score calculation: base={proximityBonus} (proximity={proximity:F2}), " +
$"depth bonus={depthBonus}, total={pointsAwarded}");
// Add score
_playerScore += pointsAwarded;
// Add pictures taken
picturesTaken += 1;
// Fire events
OnScoreChanged?.Invoke(picturesTaken);
OnPictureTaken?.Invoke(monster, picturesTaken);
}
// Score calculation moved to DivingScreenshotManager
/// <summary>
/// Handles completion of the viewfinder animation