2022-01-14 07:38:45 +00:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.Anglerfish.WorldObjects;
|
2021-12-23 23:57:41 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Anglerfish.Messages;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// angler state, target transform, and local disturbance pos
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AnglerDataMessage : QSBWorldObjectMessage<QSBAngler, AnglerfishController.AnglerState>
|
2021-12-23 23:57:41 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private uint TargetId;
|
|
|
|
|
private Vector3 LocalDisturbancePos;
|
|
|
|
|
|
2022-03-11 01:57:50 +00:00
|
|
|
|
public AnglerDataMessage(QSBAngler qsbAngler) : base(qsbAngler.AttachedObject._currentState)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
TargetId = TargetToId(qsbAngler.TargetTransform);
|
|
|
|
|
LocalDisturbancePos = qsbAngler.AttachedObject._localDisturbancePos;
|
|
|
|
|
}
|
2021-12-23 23:57:41 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(TargetId);
|
|
|
|
|
writer.Write(LocalDisturbancePos);
|
|
|
|
|
}
|
2021-12-23 23:57:41 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
TargetId = reader.Read<uint>();
|
|
|
|
|
LocalDisturbancePos = reader.ReadVector3();
|
|
|
|
|
}
|
2021-12-23 23:57:41 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
WorldObject.TargetTransform = IdToTarget(TargetId);
|
|
|
|
|
WorldObject.AttachedObject._localDisturbancePos = LocalDisturbancePos;
|
|
|
|
|
WorldObject.AttachedObject.ChangeState(Data);
|
|
|
|
|
}
|
2021-12-23 23:57:41 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private static uint TargetToId(Transform transform)
|
|
|
|
|
{
|
|
|
|
|
if (transform == null)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return uint.MaxValue;
|
2021-12-23 23:57:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (transform == Locator.GetShipTransform())
|
2021-12-23 23:57:41 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return uint.MaxValue - 1;
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return QSBPlayerManager.LocalPlayerId;
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private static Transform IdToTarget(uint id)
|
|
|
|
|
{
|
|
|
|
|
if (id == uint.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
2021-12-23 23:57:41 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (id == uint.MaxValue - 1)
|
2022-02-27 12:40:44 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return Locator.GetShipTransform();
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
return QSBPlayerManager.GetPlayer(id).Body.transform;
|
2021-12-23 23:57:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|