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
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.MeteorSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBFragment : WorldObject<FragmentIntegrity>
|
2021-11-13 16:57:06 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
2021-11-13 16:57:06 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
|
|
|
|
LeashLength = Random.Range(MeteorManager.WhiteHoleVolume._debrisDistMin, MeteorManager.WhiteHoleVolume._debrisDistMax);
|
2022-03-10 21:27:29 -08:00
|
|
|
|
// SetIntegrity(0);
|
2021-11-13 16:57:06 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-11-13 20:41:46 -08:00
|
|
|
|
|
2022-03-10 20:20:37 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
|
|
|
|
this.SendMessage(new FragmentInitialStateMessage(AttachedObject._origIntegrity, (float)LeashLength) { To = to });
|
2022-03-29 13:49:02 -07:00
|
|
|
|
this.SendMessage(new FragmentIntegrityMessage(AttachedObject._integrity) { To = to });
|
2022-03-10 20:20:37 -08:00
|
|
|
|
}
|
2022-01-21 15:13:16 -08:00
|
|
|
|
|
2022-03-10 19:47:09 -08:00
|
|
|
|
public void SetIntegrity(float integrity)
|
|
|
|
|
{
|
|
|
|
|
if (OWMath.ApproxEquals(AttachedObject._integrity, integrity))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AttachedObject._integrity = integrity;
|
|
|
|
|
AttachedObject.CallOnTakeDamage();
|
|
|
|
|
}
|
2022-03-10 20:01:44 -08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// what the leash length will be when we eventually detach and fall thru white hole.
|
|
|
|
|
/// <para/>
|
|
|
|
|
/// generated by the server and sent to clients in the initial state message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float? LeashLength;
|
2022-03-10 19:47:09 -08:00
|
|
|
|
}
|