quantum-space-buddies/QSB/MeteorSync/WorldObjects/QSBFragment.cs
JohnCorby 9e5e7bb6a1 initial state:
- always send from the host
- QSBNetworkBehaviour will store last known data in an array and send that, since real data will be wrong if no authority
2022-02-16 19:22:21 -08:00

39 lines
1.4 KiB
C#

using Cysharp.Threading.Tasks;
using QSB.Messaging;
using QSB.MeteorSync.Messages;
using QSB.WorldSync;
using System.Threading;
using UnityEngine;
namespace QSB.MeteorSync.WorldObjects
{
public class QSBFragment : WorldObject<FragmentIntegrity>
{
public override async UniTask Init(CancellationToken ct)
{
DetachableFragment = AttachedObject.GetComponent<DetachableFragment>();
if (QSBCore.IsHost)
{
LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax);
}
}
public override void SendInitialState(uint to) =>
this.SendMessage(new FragmentInitialStateMessage(this) { To = to });
public DetachableFragment DetachableFragment;
public bool IsDetached => DetachableFragment != null && DetachableFragment._isDetached;
public bool IsThruWhiteHole => IsDetached && DetachableFragment._sector != null &&
DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody;
public OWRigidbody Body => IsDetached ? AttachedObject.transform.parent.parent.GetAttachedOWRigidbody() : null;
/// what the leash length will be when we eventually detach and fall thru white hole
public float LeashLength;
public void AddDamage(float damage)
=> AttachedObject.AddDamage(damage);
}
}