using System.Collections.Generic; using ProjectM.Simulation; using Unity.Entities; using Unity.NetCode; using UnityEngine; namespace ProjectM.Client { /// /// Client-side prep-loadout sender: a static enqueue (the Staging PREP panel buttons) drained into /// RPCs (the MetaSpendSendSystem idiom). Carries only the option id; the server /// prices + re-validates (Staging, affordability, once-per-run). Statics reset on play-enter. /// [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)] public partial class PrepPurchaseSendSystem : SystemBase { static readonly Queue s_Queue = new(); [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void ResetStatics() => s_Queue.Clear(); /// Queue a prep-loadout purchase by catalog option id. The Staging PREP rows drive this. public static void RequestPrep(byte optionId) => s_Queue.Enqueue(optionId); protected override void OnCreate() => RequireForUpdate(); protected override void OnUpdate() { while (s_Queue.Count > 0) { var req = EntityManager.CreateEntity(typeof(PrepPurchaseRequest), typeof(SendRpcCommandRequest)); EntityManager.SetComponentData(req, new PrepPurchaseRequest { OptionId = s_Queue.Dequeue() }); } } } }