2022-08-16 06:20:46 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
2022-08-16 06:14:29 +00:00
|
|
|
|
using QSB.WorldSync;
|
2022-08-16 06:20:46 +00:00
|
|
|
|
using System.Threading;
|
2022-08-16 06:14:29 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.AuthoritySync;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// helper implementation of the interface
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AuthWorldObject<T> : WorldObject<T>, IAuthWorldObject
|
|
|
|
|
where T : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public uint Owner { get; set; }
|
|
|
|
|
public abstract bool CanOwn { get; }
|
|
|
|
|
|
2022-08-16 06:20:46 +00:00
|
|
|
|
public override void SendInitialState(uint to) =>
|
2022-08-16 06:38:51 +00:00
|
|
|
|
((IAuthWorldObject)this).SendMessage(new AuthWorldObjectMessage(Owner) { To = to });
|
2022-08-16 06:20:46 +00:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2022-08-16 06:34:12 +00:00
|
|
|
|
// BUG: called once per player
|
2022-08-16 06:20:46 +00:00
|
|
|
|
this.ReleaseOwnership();
|
|
|
|
|
}
|
2022-08-16 06:14:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|