48 lines
1.4 KiB
C#
Raw Normal View History

2022-02-14 15:15:18 -08:00
using OWML.Common;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
2021-11-10 21:13:49 -08:00
namespace QSB.MeteorSync.WorldObjects
{
public class QSBMeteorLauncher : WorldObject<MeteorLauncher>
{
public override void SendInitialState(uint to)
{
2022-01-26 01:01:32 -08:00
// todo SendInitialState
}
2021-11-11 02:08:03 -08:00
public void PreLaunchMeteor()
2021-11-10 21:13:49 -08:00
{
2021-11-11 02:08:03 -08:00
foreach (var particleSystem in AttachedObject._launchParticles)
2021-11-10 21:13:49 -08:00
{
2021-11-11 02:08:03 -08:00
particleSystem.Play();
2021-11-10 21:13:49 -08:00
}
2021-11-11 02:08:03 -08:00
}
2022-02-14 15:15:18 -08:00
public void LaunchMeteor(QSBMeteor qsbMeteor, float launchSpeed)
2021-11-11 02:08:03 -08:00
{
2022-02-14 15:15:18 -08:00
var meteorController = qsbMeteor.AttachedObject;
if (meteorController.hasLaunched)
{
DebugLog.DebugWrite($"{qsbMeteor} of {this} has already launched", MessageType.Warning);
return;
}
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);
}
2021-11-11 02:08:03 -08:00
foreach (var particleSystem in AttachedObject._launchParticles)
{
particleSystem.Stop();
2021-11-10 21:13:49 -08:00
}
}
}
}