2022-03-10 17:57:50 -08:00

38 lines
1.1 KiB
C#

using QSB.ItemSync.WorldObjects.Items;
using QSB.Messaging;
using QSB.Player;
using QSB.Utility;
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
internal class DreamLanternStateMessage : QSBMessage<(DreamLanternActionType Type, bool BoolValue, float FloatValue)>
{
public DreamLanternStateMessage(DreamLanternActionType actionType, bool boolValue = false, float floatValue = 0f)
: base((actionType, boolValue, floatValue)) { }
public override void OnReceiveRemote()
{
DebugLog.DebugWrite($"{From} Action:{Data.Type} BoolValue:{Data.BoolValue} FloatValue:{Data.FloatValue}");
var heldItem = QSBPlayerManager.GetPlayer(From).HeldItem;
if (heldItem is not QSBDreamLanternItem lantern)
{
DebugLog.ToConsole($"Error - Got DreamLanternStateMessage from player {From}, but they are not holding a QSBDreamLanternItem!");
return;
}
var controller = lantern.AttachedObject._lanternController;
switch (Data.Type)
{
case DreamLanternActionType.CONCEAL:
controller.SetConcealed(Data.BoolValue);
break;
case DreamLanternActionType.FOCUS:
controller.SetFocus(Data.FloatValue);
break;
}
}
}