mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-07 13:05:41 +00:00
LightSensorAuthorityMessage
This commit is contained in:
parent
c29f94f122
commit
7ed6fed50c
@ -0,0 +1,36 @@
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
|
||||
internal class LightSensorAuthorityMessage : QSBWorldObjectMessage<QSBLightSensor, uint>
|
||||
{
|
||||
public LightSensorAuthorityMessage(uint authorityOwner) : base(authorityOwner) { }
|
||||
|
||||
public override bool ShouldReceive
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!base.ShouldReceive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (WorldObject.AuthorityOwner == 0 || Data == 0)
|
||||
&& WorldObject.AuthorityOwner != Data;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal() => WorldObject.AuthorityOwner = Data;
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
{
|
||||
WorldObject.AuthorityOwner = Data;
|
||||
if (WorldObject.AuthorityOwner == 0 && WorldObject.AttachedObject.enabled)
|
||||
{
|
||||
// object has no owner, but is still active for this player. request ownership
|
||||
WorldObject.SendMessage(new LightSensorAuthorityMessage(QSBPlayerManager.LocalPlayerId));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,19 @@
|
||||
using QSB.WorldSync;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
|
||||
internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
||||
{
|
||||
public uint AuthorityOwner;
|
||||
|
||||
public bool LocallyIlluminated;
|
||||
|
||||
public Action OnDetectLocalLight;
|
||||
public Action OnDetectLocalDarkness;
|
||||
|
||||
public override void SendInitialState(uint to) { }
|
||||
public override void SendInitialState(uint to) =>
|
||||
this.SendMessage(new LightSensorAuthorityMessage(AuthorityOwner) { To = to });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user