2022-01-29 04:49:07 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.ElevatorSync.Messages;
|
2022-01-23 01:30:08 +00:00
|
|
|
|
using QSB.Messaging;
|
2022-03-22 17:56:41 +00:00
|
|
|
|
using QSB.Patches;
|
2023-10-26 03:57:07 +00:00
|
|
|
|
using QSB.Utility;
|
2022-01-23 01:30:08 +00:00
|
|
|
|
using QSB.WorldSync;
|
2022-01-29 04:49:07 +00:00
|
|
|
|
using System.Threading;
|
2020-08-12 19:58:29 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.ElevatorSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBElevator : WorldObject<Elevator>
|
2020-08-12 19:58:29 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private OWTriggerVolume _elevatorTrigger;
|
2023-10-26 03:57:07 +00:00
|
|
|
|
|
2023-10-26 23:48:43 +00:00
|
|
|
|
// Used to reset attach position. This is in local space.
|
2023-10-26 03:57:07 +00:00
|
|
|
|
public Vector3 originalAttachPosition;
|
2022-01-06 16:10:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var boxShape = AttachedObject.gameObject.GetAddComponent<BoxShape>();
|
2023-10-26 23:48:43 +00:00
|
|
|
|
|
|
|
|
|
if (Name == "LogLift")
|
|
|
|
|
{
|
2023-10-29 02:29:35 +00:00
|
|
|
|
boxShape.size = new Vector3(4.6f, 3.5f, 12);
|
|
|
|
|
boxShape.center = new Vector3(0.1f, 1.75f, 1.3f);
|
2023-10-26 23:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
boxShape.size = new Vector3(3, 3.5f, 3);
|
2023-10-29 02:29:35 +00:00
|
|
|
|
boxShape.center = new Vector3(0, 1.75f, 0.25f);
|
2023-10-26 23:48:43 +00:00
|
|
|
|
}
|
2022-01-23 01:30:08 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
_elevatorTrigger = AttachedObject.gameObject.GetAddComponent<OWTriggerVolume>();
|
2023-10-26 03:57:07 +00:00
|
|
|
|
originalAttachPosition = AttachedObject._attachPoint.transform.localPosition;
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2021-12-07 15:56:08 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void SendInitialState(uint to) =>
|
2022-03-29 20:49:02 +00:00
|
|
|
|
this.SendMessage(new ElevatorMessage(AttachedObject._goingToTheEnd) { To = to });
|
2021-11-25 18:55:22 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public void RemoteCall(bool isGoingUp)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._goingToTheEnd == isGoingUp)
|
2022-02-27 12:40:44 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-22 17:56:41 +00:00
|
|
|
|
SetDirection(isGoingUp);
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()))
|
|
|
|
|
{
|
2023-10-26 03:57:07 +00:00
|
|
|
|
var attachPoint = AttachedObject._attachPoint;
|
2023-10-26 23:48:43 +00:00
|
|
|
|
attachPoint.transform.position = Locator.GetPlayerTransform().position;
|
2023-10-26 03:57:07 +00:00
|
|
|
|
|
|
|
|
|
attachPoint.AttachPlayer();
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (Locator.GetPlayerSuit().IsWearingSuit() && Locator.GetPlayerSuit().IsTrainingSuit())
|
2022-02-27 12:40:44 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Locator.GetPlayerSuit().RemoveSuit();
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-22 17:56:41 +00:00
|
|
|
|
|
2022-08-29 05:21:20 +00:00
|
|
|
|
AttachedObject.StartLift();
|
2023-10-26 23:48:43 +00:00
|
|
|
|
|
|
|
|
|
// Runs when the lift/elevator is done moving.
|
|
|
|
|
// Reset the position of the attach point.
|
|
|
|
|
Delay.RunWhen(() => !AttachedObject.enabled, () =>
|
2023-10-26 03:57:07 +00:00
|
|
|
|
{
|
2023-10-26 23:48:43 +00:00
|
|
|
|
AttachedObject._attachPoint.transform.localPosition = originalAttachPosition;
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void SetDirection(bool isGoingUp)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._interactVolume.transform.Rotate(0f, 180f, 0f);
|
|
|
|
|
AttachedObject._goingToTheEnd = isGoingUp;
|
|
|
|
|
AttachedObject._targetLocalPos = isGoingUp ? AttachedObject._endLocalPos : AttachedObject._startLocalPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DisplayLines()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
2022-03-22 17:56:41 +00:00
|
|
|
|
}
|