Skip to content

Commit

Permalink
Merge pull request #649 from MoonstoneStudios/log-lift-fix
Browse files Browse the repository at this point in the history
Elevator attach positions
  • Loading branch information
misternebula authored Nov 12, 2023
2 parents 43821c6 + 7280e0d commit 366da20
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 15 deletions.
33 changes: 28 additions & 5 deletions QSB/ElevatorSync/WorldObjects/QSBElevator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using QSB.ElevatorSync.Messages;
using QSB.Messaging;
using QSB.Patches;
using QSB.Utility;
using QSB.WorldSync;
using System.Threading;
using UnityEngine;
Expand All @@ -12,15 +13,26 @@ public class QSBElevator : WorldObject<Elevator>
{
private OWTriggerVolume _elevatorTrigger;

// Used to reset attach position. This is in local space.
public Vector3 originalAttachPosition;

public override async UniTask Init(CancellationToken ct)
{
// BUG : This won't work for the log lift! need to make a different trigger for that

var boxShape = AttachedObject.gameObject.GetAddComponent<BoxShape>();
boxShape.center = new Vector3(0, 1.75f, 0.25f);
boxShape.size = new Vector3(3, 3.5f, 3);

if (Name == "LogLift")
{
boxShape.size = new Vector3(4.6f, 3.5f, 12);
boxShape.center = new Vector3(0.1f, 1.75f, 1.3f);
}
else
{
boxShape.size = new Vector3(3, 3.5f, 3);
boxShape.center = new Vector3(0, 1.75f, 0.25f);
}

_elevatorTrigger = AttachedObject.gameObject.GetAddComponent<OWTriggerVolume>();
originalAttachPosition = AttachedObject._attachPoint.transform.localPosition;
}

public override void SendInitialState(uint to) =>
Expand All @@ -36,14 +48,25 @@ public void RemoteCall(bool isGoingUp)
SetDirection(isGoingUp);
if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector()))
{
AttachedObject._attachPoint.AttachPlayer();
var attachPoint = AttachedObject._attachPoint;
attachPoint.transform.position = Locator.GetPlayerTransform().position;

attachPoint.AttachPlayer();
if (Locator.GetPlayerSuit().IsWearingSuit() && Locator.GetPlayerSuit().IsTrainingSuit())
{
Locator.GetPlayerSuit().RemoveSuit();
}
}

AttachedObject.StartLift();

// Runs when the lift/elevator is done moving.
// Reset the position of the attach point.
Delay.RunWhen(() => !AttachedObject.enabled, () =>
{
AttachedObject._attachPoint.transform.localPosition = originalAttachPosition;
});

}

private void SetDirection(bool isGoingUp)
Expand Down
49 changes: 39 additions & 10 deletions QSB/SectorSync/QSBSectorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,9 @@ private static void CreateFakeSectors()
// TH elevators
foreach (var elevator in QSBWorldSync.GetUnityObjects<Elevator>())
{
// just create a sphere at the attach point lol
// since players will be moved there when riding the elevator
FakeSector.Create(elevator._attachPoint.gameObject,
FakeSector.Create(elevator.gameObject,
elevator.GetComponentInParent<Sector>(),
x =>
{
x.gameObject.AddComponent<OWTriggerVolume>();
x.gameObject.AddComponent<SphereShape>();
});
x => x._triggerRoot = elevator.gameObject);
}

// rafts
Expand All @@ -120,10 +114,45 @@ private static void CreateFakeSectors()
x => x._triggerRoot = raft._rideVolume.gameObject);
}

// todo cage elevators
// todo prisoner elevator
// todo black hole forge

// cage elevators
foreach (var cageElevator in QSBWorldSync.GetUnityObjects<CageElevator>())
{
FakeSector.Create(cageElevator._platformBody.gameObject,
cageElevator.gameObject.GetComponentInParent<Sector>(),
x =>
{
x.gameObject.AddComponent<OWTriggerVolume>();
var shape = x.gameObject.AddComponent<BoxShape>();
shape.size = new Vector3(2.5f, 4.25f, 2.5f);
shape.center = new Vector3(0, 2.15f, 0);
// When the cage elevator warps when entering/exiting the underground,
// the player's sector detector is removed from the fake sector.
// So when the elevator is moving and they leave the sector, it means they have warped
// and should be added back in.
x.OnOccupantExitSector.AddListener((e) =>
{
if (cageElevator.isMoving) x.AddOccupant(e);
});
});
}

// prisoner elevator
{
var prisonerElevator = QSBWorldSync.GetUnityObject<PrisonCellElevator>();
FakeSector.Create(prisonerElevator._elevatorBody.gameObject,
prisonerElevator.gameObject.GetComponentInParent<Sector>(),
x =>
{
x.gameObject.AddComponent<OWTriggerVolume>();
var shape = x.gameObject.AddComponent<BoxShape>();
shape.size = new Vector3(4f, 6.75f, 6.7f);
shape.center = new Vector3(0, 3.3f, 3.2f);
});
}

// OPC probe
{
var probe = Locator._orbitalProbeCannon
Expand Down

0 comments on commit 366da20

Please sign in to comment.