quantum-space-buddies/QSB/AuthoritySync/Extensions.cs
2022-08-15 23:17:50 -07:00

37 lines
803 B
C#

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));
}
}