diff --git a/QSB/AuthoritySync/AuthWorldObject.cs b/QSB/AuthoritySync/AuthWorldObject.cs index 1b5d11f1..e489a8ec 100644 --- a/QSB/AuthoritySync/AuthWorldObject.cs +++ b/QSB/AuthoritySync/AuthWorldObject.cs @@ -1,5 +1,4 @@ using QSB.Messaging; -using QSB.Player; using QSB.WorldSync; using UnityEngine; @@ -18,26 +17,4 @@ public abstract class AuthWorldObject : WorldObject, IAuthWorldObject { ((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(Owner) { To = to }); } - - public void RequestOwnership() - { - if (!CanOwn) - { - return; - } - if (Owner != 0) - { - return; - } - ((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId)); - } - - public void ReleaseOwnership() - { - if (Owner == 0) - { - return; - } - ((IAuthWorldObject)this).SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId)); - } } diff --git a/QSB/AuthoritySync/Extensions.cs b/QSB/AuthoritySync/Extensions.cs new file mode 100644 index 00000000..9d9e5c3c --- /dev/null +++ b/QSB/AuthoritySync/Extensions.cs @@ -0,0 +1,36 @@ +using QSB.Messaging; +using QSB.Player; + +namespace QSB.AuthoritySync; + +public static class Extensions +{ + /// + /// try and gain authority over the object + /// + public static void RequestOwnership(this IAuthWorldObject authWorldObject) + { + if (!authWorldObject.CanOwn) + { + return; + } + if (authWorldObject.Owner != 0) + { + return; + } + authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId)); + } + + /// + /// release authority over the object, + /// potentially to giving it to someone else + /// + public static void ReleaseOwnership(this IAuthWorldObject authWorldObject) + { + if (authWorldObject.Owner == 0) + { + return; + } + authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId)); + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs index 0c11cc45..c2f15889 100644 --- a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs +++ b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBLightSensor.cs @@ -25,19 +25,18 @@ namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects; /// the sector it's enabled in is bigger than the sector the zone2 walls are enabled in :( /// maybe this can be fixed by making the collision group use the same sector. /// -internal class QSBLightSensor : WorldObject, IAuthWorldObject +internal class QSBLightSensor : AuthWorldObject { internal bool _locallyIlluminated; public Action OnDetectLocalLight; public Action OnDetectLocalDarkness; - public uint Owner { get; set; } - public bool CanOwn => AttachedObject.enabled; - + public override bool CanOwn => AttachedObject.enabled; public override void SendInitialState(uint to) { + base.SendInitialState(to); // todo initial state }