ownership comments

This commit is contained in:
JohnCorby 2023-09-17 18:47:56 -07:00
parent 3dba6b9396
commit 5f7a7a8969
2 changed files with 18 additions and 0 deletions

View File

@ -7,9 +7,15 @@ public static class IOwnedWorldObject_Extensions
{
/// <summary>
/// try and gain ownership over the object
///
/// does nothing if object 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;
@ -17,9 +23,19 @@ public static class IOwnedWorldObject_Extensions
@this.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
}
/// <summary>
/// forcibly gain ownership over the object
/// </summary>
public static void ForceOwnership(this IOwnedWorldObject @this)
{
@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)
{

View File

@ -27,6 +27,7 @@ public class OwnedWorldObjectMessage : QSBWorldObjectMessage<IOwnedWorldObject,
// if Obj==Message then No
// Obj
// ie if no owner, or we're trying to release ownership, and we're actually changing what the owner already is
return (WorldObject.Owner == 0 || Data == 0) && WorldObject.Owner != Data;
}
}
@ -39,6 +40,7 @@ public class OwnedWorldObjectMessage : QSBWorldObjectMessage<IOwnedWorldObject,
if (WorldObject.Owner == 0 && WorldObject.CanOwn)
{
// object has no owner, but is still active for this player. request ownership
// means you should wait and check after releasing ownership in case someone else gets it
WorldObject.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
}
}