mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-14 15:40:20 +00:00
implement
This commit is contained in:
parent
e761dc071b
commit
3c9c024fcd
43
QSB/AuthoritySync/AuthWorldObject.cs
Normal file
43
QSB/AuthoritySync/AuthWorldObject.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.WorldSync;
|
||||
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; }
|
||||
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(Owner) { To = to });
|
||||
}
|
||||
|
||||
public void RequestOwnership()
|
||||
{
|
||||
if (!CanOwn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (Owner != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
|
||||
}
|
||||
|
||||
public void ReleaseOwnership()
|
||||
{
|
||||
if (Owner == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using QSB.Player;
|
||||
namespace QSB.AuthoritySync;
|
||||
|
||||
/// <summary>
|
||||
/// request ownership of a world object
|
||||
/// request or release ownership of a world object
|
||||
/// </summary>
|
||||
public class WorldObjectAuthMessage : QSBWorldObjectMessage<IAuthWorldObject, uint>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user