quantum-space-buddies/QSB/OwnershipSync/IOwnedWorldObject_Extensions.cs

33 lines
715 B
C#
Raw Normal View History

2022-08-16 06:17:50 +00:00
using QSB.Messaging;
using QSB.Player;
2023-05-08 18:30:59 +00:00
namespace QSB.OwnershipSync;
2022-08-16 06:17:50 +00:00
2023-05-08 18:30:59 +00:00
public static class IOwnedWorldObject_Extensions
2022-08-16 06:17:50 +00:00
{
/// <summary>
/// try and gain authority over the object
/// </summary>
2023-05-08 18:30:59 +00:00
public static void RequestOwnership(this IOwnedWorldObject @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;
}
2023-05-08 18:30:59 +00:00
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
2022-08-16 06:17:50 +00:00
}
/// <summary>
/// release authority over the object,
/// potentially to giving it to someone else
/// </summary>
2023-05-08 18:30:59 +00:00
public static void ReleaseOwnership(this IOwnedWorldObject @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;
}
2023-05-08 18:30:59 +00:00
@this.SendMessage(new OwnedWorldObjectMessage(0));
2022-08-16 06:17:50 +00:00
}
}