2022-08-16 05:53:46 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
|
2023-05-08 18:30:59 +00:00
|
|
|
|
namespace QSB.OwnershipSync;
|
2022-08-16 05:53:46 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-09-18 22:09:34 +00:00
|
|
|
|
/// sets the owner of a world object
|
|
|
|
|
/// also potentially gives ownership to someone else if possible
|
2022-08-16 05:53:46 +00:00
|
|
|
|
/// </summary>
|
2023-05-08 18:30:59 +00:00
|
|
|
|
public class OwnedWorldObjectMessage : QSBWorldObjectMessage<IOwnedWorldObject, uint>
|
2022-08-16 05:53:46 +00:00
|
|
|
|
{
|
2023-05-08 18:30:59 +00:00
|
|
|
|
public OwnedWorldObjectMessage(uint owner) : base(owner) { }
|
2022-08-16 05:53:46 +00:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveLocal() => WorldObject.Owner = Data;
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
WorldObject.Owner = Data;
|
|
|
|
|
if (WorldObject.Owner == 0 && WorldObject.CanOwn)
|
|
|
|
|
{
|
|
|
|
|
// object has no owner, but is still active for this player. request ownership
|
2023-09-18 01:47:56 +00:00
|
|
|
|
// means you should wait and check after releasing ownership in case someone else gets it
|
2023-05-08 18:30:59 +00:00
|
|
|
|
WorldObject.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
|
2022-08-16 05:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|