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>
|
2023-05-08 18:38:24 +00:00
|
|
|
|
/// try and gain ownership over the object
|
2023-09-18 01:47:56 +00:00
|
|
|
|
///
|
2023-09-18 19:58:06 +00:00
|
|
|
|
/// does nothing if we cant own this object or there is already another owner
|
2022-08-16 06:17:50 +00:00
|
|
|
|
/// </summary>
|
2023-05-08 18:30:59 +00:00
|
|
|
|
public static void RequestOwnership(this IOwnedWorldObject @this)
|
2022-08-16 06:17:50 +00:00
|
|
|
|
{
|
2023-09-18 01:47:56 +00:00
|
|
|
|
if (!@this.CanOwn)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 01:47:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// forcibly gain ownership over the object
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void ForceOwnership(this IOwnedWorldObject @this)
|
|
|
|
|
{
|
|
|
|
|
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 06:17:50 +00:00
|
|
|
|
/// <summary>
|
2023-05-08 18:38:24 +00:00
|
|
|
|
/// release ownership over the object,
|
2022-08-16 06:17:50 +00:00
|
|
|
|
/// potentially to giving it to someone else
|
2023-09-18 01:47:56 +00:00
|
|
|
|
///
|
|
|
|
|
/// does nothing if someone else already owns this
|
2022-08-16 06:17:50 +00:00
|
|
|
|
/// </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
|
|
|
|
}
|
|
|
|
|
}
|