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>
|
2022-08-16 06:14:29 +00:00
|
|
|
|
/// request or release ownership of a world object
|
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 bool ShouldReceive
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!base.ShouldReceive)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deciding if to change the object's owner
|
|
|
|
|
// Message
|
|
|
|
|
// | = 0 | > 0 |
|
|
|
|
|
// = 0 | No | Yes |
|
|
|
|
|
// > 0 | Yes | No |
|
|
|
|
|
// if Obj==Message then No
|
|
|
|
|
// Obj
|
|
|
|
|
|
|
|
|
|
return (WorldObject.Owner == 0 || Data == 0) && WorldObject.Owner != Data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05-08 18:30:59 +00:00
|
|
|
|
WorldObject.SendMessage(new OwnedWorldObjectMessage(QSBPlayerManager.LocalPlayerId));
|
2022-08-16 05:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|