using UnityEngine; using System; using System.Collections; using System.Collections.Generic; public class ClawScoreManager : MonoBehaviour { public static ClawScoreManager Instance; // at the top with other events public event Action OnScoreChanged; // passes TOTAL score // expose total score public int CurrentScore => score; [Header("Scoring")] public int wolfPoints = 100; public int goldenWolfJackpot = 1000; public int starPoints = 50; public int comboBonus = 300; public int starSuperBonus = 500; [Header("Multipliers")] public float crystalNextGrabMultiplier = 2f; private bool crystalPrimed = false; [Header("Timers & Effects")] public float addTimeSeconds = 5f; // Sand Dial public float slowDuration = 5f; // Clock public float turboDuration = 5f; // Turbo public float freezeDuration = 2f; // Freeze public float bombDisableSeconds = 3f; // Bomb public float shockJamSeconds = 2f; // Shock // Events others can subscribe to public event Action OnScoreAdded; public event Action OnTimeAdded; public event Action OnPlatformSlow; // pass duration public event Action OnPlatformTurbo; // pass duration public event Action OnPlatformFreeze; // pass duration public event Action OnClawDisabled; // pass duration public event Action OnClawJam; // pass duration public event Action OnComboAchieved; private int score = 0; private readonly Queue comboQueue = new Queue(); private readonly Queue starQueue = new Queue(); void Awake() { Instance = this; } public void EvaluateBubble(ClawBubbleType type) { Debug.Log("EvaluateBubble: "+type.ToString()); int points = 0; switch (type) { case ClawBubbleType.Wolf: points += wolfPoints; EnqueueCombo(type, comboQueue, 3, () => { AddScore(comboBonus); OnComboAchieved?.Invoke(new[] { ClawBubbleType.Wolf, ClawBubbleType.Wolf, ClawBubbleType.Wolf }); }); break; case ClawBubbleType.GoldenWolf: points += goldenWolfJackpot; break; case ClawBubbleType.Star: points += starPoints; EnqueueCombo(ClawBubbleType.Star, starQueue, 3, () => { AddScore(starSuperBonus); OnComboAchieved?.Invoke(new[] { ClawBubbleType.Star, ClawBubbleType.Star, ClawBubbleType.Star }); }); break; case ClawBubbleType.Crystal: // primes next-grab multiplier crystalPrimed = true; break; case ClawBubbleType.Time: OnTimeAdded?.Invoke(addTimeSeconds); Debug.Log("TimeAdded Function"); break; case ClawBubbleType.Freeze: OnPlatformFreeze?.Invoke(freezeDuration); break; case ClawBubbleType.Turbo: OnPlatformTurbo?.Invoke(turboDuration); break; case ClawBubbleType.Bomb: OnClawDisabled?.Invoke(bombDisableSeconds); OnPlatformTurbo?.Invoke(turboDuration); break; case ClawBubbleType.Shock: OnClawJam?.Invoke(shockJamSeconds); break; } // Apply crystal multiplier if primed (and we actually scored) if (crystalPrimed && points > 0) { points = Mathf.RoundToInt(points * crystalNextGrabMultiplier); crystalPrimed = false; } if (points > 0) AddScore(points); // Tell spawner to introduce new targets if (ClawBubbleSpawner.Instance) ClawBubbleSpawner.Instance.NotifyBubbleGrabbed(type); } private void AddScore(int amount) { score += amount; OnScoreAdded?.Invoke(amount); // delta (already in your code) OnScoreChanged?.Invoke(score); // total (new) // TODO: update UI here if you have a reference } private void EnqueueCombo(ClawBubbleType t, Queue q, int target, Action onCombo) { q.Enqueue(t); while (q.Count > target) q.Dequeue(); if (q.Count == target) { // check if all same var arr = q.ToArray(); bool allSame = true; for (int i = 1; i < arr.Length; i++) if (arr[i] != arr[0]) { allSame = false; break; } if (allSame) onCombo?.Invoke(); } } }