helpers helpers helpers

This commit is contained in:
JohnCorby 2022-08-15 23:17:50 -07:00
parent 3c9c024fcd
commit 635eeca04c
3 changed files with 39 additions and 27 deletions

View File

@ -1,5 +1,4 @@
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
using UnityEngine;
@ -18,26 +17,4 @@ public abstract class AuthWorldObject<T> : WorldObject<T>, 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));
}
}

View File

@ -0,0 +1,36 @@
using QSB.Messaging;
using QSB.Player;
namespace QSB.AuthoritySync;
public static class Extensions
{
/// <summary>
/// try and gain authority over the object
/// </summary>
public static void RequestOwnership(this IAuthWorldObject authWorldObject)
{
if (!authWorldObject.CanOwn)
{
return;
}
if (authWorldObject.Owner != 0)
{
return;
}
authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
}
/// <summary>
/// release authority over the object,
/// potentially to giving it to someone else
/// </summary>
public static void ReleaseOwnership(this IAuthWorldObject authWorldObject)
{
if (authWorldObject.Owner == 0)
{
return;
}
authWorldObject.SendMessage(new WorldObjectAuthMessage(QSBPlayerManager.LocalPlayerId));
}
}

View File

@ -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.
/// </summary>
internal class QSBLightSensor : WorldObject<SingleLightSensor>, IAuthWorldObject
internal class QSBLightSensor : AuthWorldObject<SingleLightSensor>
{
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
}