2022-01-28 20:49:07 -08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using Mirror;
|
2022-01-21 15:13:16 -08:00
|
|
|
|
using QSB.Anglerfish.Messages;
|
2022-01-14 22:54:18 -08:00
|
|
|
|
using QSB.Anglerfish.TransformSync;
|
2022-01-21 15:13:16 -08:00
|
|
|
|
using QSB.Messaging;
|
2022-03-14 01:53:12 -07:00
|
|
|
|
using QSB.Utility.LinkedWorldObject;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
using QSB.WorldSync;
|
2022-01-28 20:49:07 -08:00
|
|
|
|
using System.Threading;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.Anglerfish.WorldObjects;
|
|
|
|
|
|
2022-03-14 01:53:12 -07:00
|
|
|
|
public class QSBAngler : WorldObject<AnglerfishController>, ILinkedWorldObject<AnglerTransformSync>
|
2021-11-09 17:56:45 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override bool ShouldDisplayDebug() => false;
|
2022-01-21 17:56:20 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public Transform TargetTransform;
|
|
|
|
|
public Vector3 TargetVelocity { get; private set; }
|
2021-11-10 09:28:05 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private Vector3 _lastTargetPosition;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
2022-03-14 01:53:12 -07:00
|
|
|
|
public AnglerTransformSync NetworkBehaviour { get; private set; }
|
|
|
|
|
public void LinkTo(NetworkBehaviour networkBehaviour) => NetworkBehaviour = (AnglerTransformSync)networkBehaviour;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2021-11-09 17:56:45 -08:00
|
|
|
|
{
|
2022-03-14 01:53:12 -07:00
|
|
|
|
this.SpawnLinked(QSBNetworkManager.singleton.AnglerPrefab);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await this.WaitForLink(ct);
|
2022-02-27 04:40:44 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2021-11-09 17:56:45 -08:00
|
|
|
|
{
|
2022-03-14 01:53:12 -07:00
|
|
|
|
NetworkServer.Destroy(NetworkBehaviour.gameObject);
|
2021-11-09 18:38:19 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-11-09 18:38:19 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void SendInitialState(uint to) =>
|
|
|
|
|
this.SendMessage(new AnglerDataMessage(this) { To = to });
|
2022-01-21 15:13:16 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void UpdateTargetVelocity()
|
|
|
|
|
{
|
|
|
|
|
if (TargetTransform == null)
|
2021-11-09 20:35:55 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return;
|
2022-02-27 04:40:44 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
TargetVelocity = TargetTransform.position - _lastTargetPosition;
|
|
|
|
|
_lastTargetPosition = TargetTransform.position;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|