2022-08-15 23:17:50 -07:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
|
2023-05-08 11:30:59 -07:00
|
|
|
|
namespace QSB.OwnershipSync;
|
2022-08-15 23:17:50 -07:00
|
|
|
|
|
2023-05-08 11:30:59 -07:00
|
|
|
|
public static class IOwnedWorldObject_Extensions
|
2022-08-15 23:17:50 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2023-05-08 11:38:24 -07:00
|
|
|
|
/// try and gain ownership over the object
|
2022-08-15 23:17:50 -07:00
|
|
|
|
/// </summary>
|
2023-05-08 11:30:59 -07:00
|
|
|
|
public static void RequestOwnership(this IOwnedWorldObject @this)
|
2022-08-15 23:17:50 -07:00
|
|
|
|
{
|
2022-08-16 17:32:33 -07:00
|
|
|
|
if (@this.Owner != 0)
|
2022-08-15 23:17:50 -07:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-08 11:30:59 -07:00
|
|
|
|
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
|
2022-08-15 23:17:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-05-08 11:38:24 -07:00
|
|
|
|
/// release ownership over the object,
|
2022-08-15 23:17:50 -07:00
|
|
|
|
/// potentially to giving it to someone else
|
|
|
|
|
/// </summary>
|
2023-05-08 11:30:59 -07:00
|
|
|
|
public static void ReleaseOwnership(this IOwnedWorldObject @this)
|
2022-08-15 23:17:50 -07:00
|
|
|
|
{
|
2022-08-16 17:32:33 -07:00
|
|
|
|
if (@this.Owner != QSBPlayerManager.LocalPlayerId)
|
2022-08-15 23:17:50 -07:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-08 11:30:59 -07:00
|
|
|
|
@this.SendMessage(new OwnedWorldObjectMessage(0));
|
2022-08-15 23:17:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|