91 lines
2.4 KiB
C#
Raw Normal View History

2022-01-22 17:30:08 -08:00
using QSB.ElevatorSync.Messages;
using QSB.Messaging;
using QSB.WorldSync;
2020-08-12 21:58:29 +02:00
using UnityEngine;
namespace QSB.ElevatorSync.WorldObjects
2020-08-12 21:58:29 +02:00
{
2020-12-23 22:43:05 +00:00
public class QSBElevator : WorldObject<Elevator>
2020-12-02 21:23:01 +00:00
{
2021-11-25 18:55:22 +00:00
private OWTriggerVolume _elevatorTrigger;
2020-08-12 21:58:29 +02:00
public override void Init()
2020-12-02 21:23:01 +00:00
{
StartDelayedReady();
2022-01-23 00:19:43 -08:00
QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume, () =>
{
FinishDelayedReady();
2021-11-25 18:55:22 +00:00
2022-01-23 00:19:43 -08:00
// BUG : This won't work for the log lift! need to make a different trigger for that
2022-01-23 00:19:43 -08:00
var boxShape = AttachedObject.gameObject.GetAddComponent<BoxShape>();
boxShape.center = new Vector3(0, 1.75f, 0.25f);
boxShape.size = new Vector3(3, 3.5f, 3);
2021-11-25 18:55:22 +00:00
2022-01-23 00:19:43 -08:00
_elevatorTrigger = AttachedObject.gameObject.GetAddComponent<OWTriggerVolume>();
});
2020-12-02 21:23:01 +00:00
}
2020-08-12 21:58:29 +02:00
public override void SendInitialState(uint to)
2022-01-22 17:30:08 -08:00
{
if (QSBCore.IsHost)
{
this.SendMessage(new ElevatorMessage(AttachedObject._goingToTheEnd));
}
}
2020-12-02 21:23:01 +00:00
public void RemoteCall(bool isGoingUp)
{
2022-01-24 11:46:16 -08:00
if (AttachedObject._goingToTheEnd == isGoingUp)
{
return;
}
2021-11-25 18:55:22 +00:00
if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()))
{
SetDirection(isGoingUp);
2021-12-07 15:56:08 +00:00
2021-11-25 18:55:22 +00:00
AttachedObject._attachPoint.AttachPlayer();
2021-12-26 21:08:36 -08:00
if (Locator.GetPlayerSuit().IsWearingSuit() && Locator.GetPlayerSuit().IsTrainingSuit())
2021-11-25 18:55:22 +00:00
{
2021-12-26 21:08:36 -08:00
Locator.GetPlayerSuit().RemoveSuit();
2021-11-25 18:55:22 +00:00
}
2022-01-24 11:46:16 -08:00
RemoteStartLift();
2021-11-25 18:55:22 +00:00
}
else
{
SetDirection(isGoingUp);
2022-01-24 11:46:16 -08:00
RemoteStartLift();
2021-11-25 18:55:22 +00:00
}
2020-12-02 21:23:01 +00:00
}
2020-08-12 21:58:29 +02:00
2020-12-02 21:23:01 +00:00
private void SetDirection(bool isGoingUp)
{
2022-01-23 00:19:43 -08:00
AttachedObject._interactVolume.transform.Rotate(0f, 180f, 0f);
2021-11-25 18:55:22 +00:00
AttachedObject._goingToTheEnd = isGoingUp;
2022-01-23 00:19:43 -08:00
AttachedObject._targetLocalPos = isGoingUp ? AttachedObject._endLocalPos : AttachedObject._startLocalPos;
2020-12-02 21:23:01 +00:00
}
2022-01-24 11:46:16 -08:00
private void RemoteStartLift()
{
AttachedObject.enabled = true;
AttachedObject._initLocalPos = AttachedObject.transform.localPosition;
AttachedObject._initLiftTime = Time.time;
AttachedObject._owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate);
AttachedObject._owAudioSourceLP.FadeIn(0.5f);
AttachedObject._interactVolume.DisableInteraction();
}
public override void DisplayLines()
{
2022-01-06 18:22:34 -08:00
var boxShape = (BoxShape)_elevatorTrigger._shape;
Popcron.Gizmos.Cube(
ShapeUtil.Box.CalcWorldSpaceCenter(boxShape),
boxShape.transform.rotation,
ShapeUtil.Box.CalcWorldSpaceSize(boxShape),
_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()) ? Color.green : Color.white
);
}
2020-12-02 21:23:01 +00:00
}
2020-12-03 08:28:05 +00:00
}