68 lines
1.5 KiB
C#
Raw Normal View History

2021-11-10 09:18:57 +00:00
using QSB.Anglerfish.TransformSync;
2021-11-09 17:56:45 -08:00
using QSB.Utility;
using QSB.WorldSync;
using QuantumUNET;
2021-11-10 09:18:57 +00:00
using System.Linq;
2021-11-09 17:56:45 -08:00
using UnityEngine;
2021-11-09 20:35:55 -08:00
using Object = UnityEngine.Object;
2021-11-09 17:56:45 -08:00
namespace QSB.Anglerfish.WorldObjects
{
public class QSBAngler : WorldObject<AnglerfishController>
{
public AnglerTransformSync transformSync;
public override void Init(AnglerfishController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
if (QSBCore.IsHost)
{
Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab).SpawnWithServerAuthority();
}
}
public override void OnRemoval()
{
if (QSBCore.IsHost)
{
QNetworkServer.Destroy(transformSync.gameObject);
}
2021-11-09 18:38:19 -08:00
}
public void TransferAuthority(uint id)
{
var conn = QNetworkServer.connections.First(x => x.GetPlayerId() == id);
var identity = transformSync.NetIdentity;
if (identity.ClientAuthorityOwner == conn)
{
return;
}
if (identity.ClientAuthorityOwner != null)
{
identity.RemoveClientAuthority(identity.ClientAuthorityOwner);
}
identity.AssignClientAuthority(conn);
DebugLog.DebugWrite($"angler {ObjectId} - transferred authority to {id}");
2021-11-09 17:56:45 -08:00
}
2021-11-09 20:35:55 -08:00
public Transform targetTransform;
public Vector3 TargetVelocity { get; private set; }
private Vector3 _lastTargetPosition;
public void FixedUpdate()
2021-11-09 20:35:55 -08:00
{
if (targetTransform == null)
{
return;
}
TargetVelocity = targetTransform.position - _lastTargetPosition;
_lastTargetPosition = targetTransform.position;
2021-11-09 20:35:55 -08:00
}
2021-11-09 17:56:45 -08:00
}
}