40 lines
1.3 KiB
C#
Raw Normal View History

2022-03-11 05:40:52 -08:00
using QSB.WorldSync;
2022-03-10 19:17:06 -08:00
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-02 19:46:33 -08:00
public override void SendInitialState(uint to)
2021-11-10 21:13:49 -08:00
{
2022-03-11 05:40:52 -08:00
// we don't really need to sync initial state
2022-03-02 19:46:33 -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
public void LaunchMeteor(MeteorController meteor, float launchSpeed)
2022-03-02 19:46:33 -08:00
{
meteor.Initialize(AttachedObject.transform, AttachedObject._detectableField, AttachedObject._detectableFluid);
2022-03-10 19:17:06 -08:00
var linearVelocity = AttachedObject._parentBody.GetPointVelocity(AttachedObject.transform.position) + AttachedObject.transform.TransformDirection(AttachedObject._launchDirection) * launchSpeed;
var angularVelocity = AttachedObject.transform.forward * 2f;
meteor.Launch(null, AttachedObject.transform.position, AttachedObject.transform.rotation, linearVelocity, angularVelocity);
2022-03-10 19:17:06 -08:00
if (AttachedObject._audioSector.ContainsOccupant(DynamicOccupant.Player))
{
AttachedObject._launchSource.pitch = Random.Range(0.4f, 0.6f);
AttachedObject._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch);
}
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
}