quantum-space-buddies/QSB/OwnershipSync/IOwnedWorldObject_Extensions.cs
JohnCorby 43ecea5681 blah
2023-09-18 14:19:47 -07:00

55 lines
1.2 KiB
C#

using QSB.Messaging;
using QSB.Player;
namespace QSB.OwnershipSync;
public static class IOwnedWorldObject_Extensions
{
/// <summary>
/// try and gain ownership over the object
///
/// does nothing if we cant own this object or there is already another owner
/// </summary>
public static void RequestOwnership(this IOwnedWorldObject @this)
{
if (!@this.CanOwn)
{
return;
}
if (@this.Owner != 0)
{
return;
}
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
}
/// <summary>
/// forcibly gain ownership over the object
///
/// does nothing if you already own this
/// </summary>
public static void ForceOwnership(this IOwnedWorldObject @this)
{
if (@this.Owner == QSBPlayerManager.LocalPlayerId)
{
return;
}
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
}
/// <summary>
/// release ownership over the object,
/// potentially to giving it to someone else
///
/// does nothing if someone else already owns this
/// </summary>
public static void ReleaseOwnership(this IOwnedWorldObject @this)
{
if (@this.Owner != QSBPlayerManager.LocalPlayerId)
{
return;
}
@this.SendMessage(new OwnedWorldObjectMessage(0));
}
}