2022-03-10 19:17:06 -08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.WorldSync;
|
2022-03-10 20:32:33 -08:00
|
|
|
|
using System.Collections.Generic;
|
2022-03-10 19:17:06 -08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using UnityEngine;
|
2021-11-10 21:13:49 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.MeteorSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBMeteorLauncher : WorldObject<MeteorLauncher>
|
2021-11-10 21:13:49 -08:00
|
|
|
|
{
|
2022-03-10 19:17:06 -08:00
|
|
|
|
private QSBMeteor[] _qsbMeteors;
|
|
|
|
|
|
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
2022-03-10 20:32:33 -08:00
|
|
|
|
var meteors = (AttachedObject._meteorPool ?? new List<MeteorController>())
|
|
|
|
|
.Concat(AttachedObject._dynamicMeteorPool ?? new List<MeteorController>());
|
2022-03-10 19:17:06 -08:00
|
|
|
|
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
|
|
|
|
|
_qsbMeteors = meteors.Select(x => x.GetWorldObject<QSBMeteor>()).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
2021-11-10 21:13:49 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
// todo SendInitialState
|
|
|
|
|
}
|
2022-01-25 21:08:04 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void PreLaunchMeteor()
|
|
|
|
|
{
|
2022-03-10 19:17:06 -08:00
|
|
|
|
foreach (var launchParticle in AttachedObject._launchParticles)
|
2021-11-10 21:13:49 -08:00
|
|
|
|
{
|
2022-03-10 19:17:06 -08:00
|
|
|
|
launchParticle.Play();
|
2021-11-11 02:08:03 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-11-11 02:08:03 -08:00
|
|
|
|
|
2022-03-10 19:17:06 -08:00
|
|
|
|
public void LaunchMeteor(MeteorController meteorController, float launchSpeed)
|
2022-03-02 19:46:33 -08:00
|
|
|
|
{
|
2022-03-10 19:17:06 -08:00
|
|
|
|
meteorController.Initialize(AttachedObject.transform, AttachedObject._detectableField, AttachedObject._detectableFluid);
|
|
|
|
|
|
|
|
|
|
var linearVelocity = AttachedObject._parentBody.GetPointVelocity(AttachedObject.transform.position) + AttachedObject.transform.TransformDirection(AttachedObject._launchDirection) * launchSpeed;
|
|
|
|
|
var angularVelocity = AttachedObject.transform.forward * 2f;
|
|
|
|
|
meteorController.Launch(null, AttachedObject.transform.position, AttachedObject.transform.rotation, linearVelocity, angularVelocity);
|
|
|
|
|
if (AttachedObject._audioSector.ContainsOccupant(DynamicOccupant.Player))
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._launchSource.pitch = Random.Range(0.4f, 0.6f);
|
|
|
|
|
AttachedObject._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch);
|
|
|
|
|
}
|
2022-02-27 04:40:44 -08:00
|
|
|
|
|
2022-03-10 19:17:06 -08:00
|
|
|
|
foreach (var launchParticle in AttachedObject._launchParticles)
|
2022-03-02 19:46:33 -08:00
|
|
|
|
{
|
2022-03-10 19:17:06 -08:00
|
|
|
|
launchParticle.Stop();
|
2021-11-10 21:13:49 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-10 19:17:06 -08:00
|
|
|
|
}
|