using Cysharp.Threading.Tasks; using QSB.Messaging; using QSB.Player; using QSB.WorldSync; using System.Threading; using UnityEngine; namespace QSB.AuthoritySync; /// /// helper implementation of the interface /// public abstract class AuthWorldObject : WorldObject, IAuthWorldObject where T : MonoBehaviour { public uint Owner { get; set; } public abstract bool CanOwn { get; } public override void SendInitialState(uint to) => ((IAuthWorldObject)this).SendMessage(new AuthWorldObjectMessage(Owner) { To = to }); public override async UniTask Init(CancellationToken ct) => QSBPlayerManager.OnRemovePlayer += OnPlayerLeave; public override void OnRemoval() => QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave; private void OnPlayerLeave(PlayerInfo player) { if (Owner == player.PlayerId) { // BUG: called once per player this.ReleaseOwnership(); } } }