purchase buffs menu works

This commit is contained in:
Ian Woods 2026-06-03 00:05:52 -07:00
parent 3737ad517c
commit 79cd331141
6 changed files with 222 additions and 7 deletions

View file

@ -1,4 +1,5 @@
// Assets/_Project/Scripts/Gameplay/PlayerBuffManager.cs
using System.Collections.Generic;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
@ -27,6 +28,31 @@ namespace TD.Gameplay
/// </remarks>
public class PlayerBuffManager : NetworkBehaviour
{
// ----- Static registry (mirrors PlayerGoldManager pattern) -----------
private static readonly Dictionary<ulong, PlayerBuffManager> s_byClientId
= new Dictionary<ulong, PlayerBuffManager>();
/// <summary>Returns the PlayerBuffManager owned by the given client, or null.</summary>
public static PlayerBuffManager GetForClient(ulong clientId)
{
s_byClientId.TryGetValue(clientId, out var mgr);
return mgr;
}
/// <summary>Convenience: the local client's own buff manager.</summary>
public static PlayerBuffManager Local
{
get
{
var nm = NetworkManager.Singleton;
if (nm == null) return null;
return GetForClient(nm.LocalClientId);
}
}
// ----- Inspector ------------------------------------------------------
[Tooltip("Purchasable buff categories shown in the buff menu. Index in this " +
"array is the categoryIndex passed to RequestPurchaseBuffRpc.")]
[SerializeField] private BuffCategory[] categories;
@ -38,6 +64,19 @@ namespace TD.Gameplay
buffs = new NetworkList<ActiveBuff>();
}
// ----- NGO lifecycle ----------------------------------------------
public override void OnNetworkSpawn()
{
s_byClientId[OwnerClientId] = this;
}
public override void OnNetworkDespawn()
{
if (s_byClientId.TryGetValue(OwnerClientId, out var registered) && registered == this)
s_byClientId.Remove(OwnerClientId);
}
// ----- Public API -------------------------------------------------
/// <summary>