37 lines
1.4 KiB
C#
Raw Normal View History

2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks;
using QSB.Messaging;
2022-01-21 15:13:16 -08:00
using QSB.MeteorSync.Messages;
using QSB.WorldSync;
2022-01-28 20:49:07 -08:00
using System.Threading;
2021-11-15 02:39:06 -08:00
using UnityEngine;
2021-11-13 16:57:06 -08:00
namespace QSB.MeteorSync.WorldObjects;
public class QSBFragment : WorldObject<FragmentIntegrity>
2021-11-13 16:57:06 -08:00
{
public override async UniTask Init(CancellationToken ct)
2021-11-13 16:57:06 -08:00
{
DetachableFragment = AttachedObject.GetComponent<DetachableFragment>();
2021-11-15 02:39:06 -08:00
if (QSBCore.IsHost)
{
LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax);
2021-11-13 16:57:06 -08:00
}
}
2021-11-13 20:41:46 -08:00
public override void SendInitialState(uint to) =>
this.SendMessage(new FragmentInitialStateMessage(this) { To = to });
2022-01-21 15:13:16 -08:00
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;
2021-11-15 00:29:36 -08:00
/// what the leash length will be when we eventually detach and fall thru white hole
public float LeashLength;
2021-11-15 00:29:36 -08:00
public void AddDamage(float damage)
=> AttachedObject.AddDamage(damage);
}