quantum-space-buddies/QSB/AuthoritySync/Extensions.cs

37 lines
803 B
C#
Raw Normal View History

2022-08-16 06:17:50 +00:00
using QSB.Messaging;
using QSB.Player;
namespace QSB.AuthoritySync;
public static class Extensions
{
/// <summary>
/// try and gain authority over the object
/// </summary>
public static void RequestOwnership(this IAuthWorldObject authWorldObject)
{
if (!authWorldObject.CanOwn)
{
return;
}
if (authWorldObject.Owner != 0)
{
return;
}
authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
}
/// <summary>
/// release authority over the object,
/// potentially to giving it to someone else
/// </summary>
public static void ReleaseOwnership(this IAuthWorldObject authWorldObject)
{
if (authWorldObject.Owner == 0)
{
return;
}
authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
}
}