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

33 lines
710 B
C#
Raw Normal View History

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