269 lines
7.5 KiB
C#
Raw Normal View History

using OWML.Common;
2022-10-10 22:23:44 -07:00
using QSB.EchoesOfTheEye.DreamLantern;
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
using QSB.ItemSync.WorldObjects.Items;
using QSB.Messaging;
using QSB.Player;
2022-08-27 17:57:27 +01:00
using QSB.QuantumSync.WorldObjects;
2022-01-26 17:14:26 -08:00
using QSB.RespawnSync;
using QSB.ShipSync;
using QSB.Utility.Messages;
using QSB.WorldSync;
using System;
2023-06-11 01:00:27 +01:00
using System.Collections;
2021-12-23 17:07:29 -08:00
using System.Linq;
2023-09-17 22:14:21 +01:00
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
2020-12-08 09:31:29 +00:00
using UnityEngine;
using UnityEngine.InputSystem;
2022-03-02 19:46:33 -08:00
namespace QSB.Utility;
public class DebugActions : MonoBehaviour, IAddComponentOnStart
{
2023-09-17 22:14:21 +01:00
public static Type WorldObjectSelection = typeof(QSBRaft);
private static void GoToVessel()
{
2022-03-02 19:46:33 -08:00
var spawnPoint = GameObject.Find("Spawn_Vessel").GetComponent<SpawnPoint>();
var playerBody = Locator.GetPlayerBody();
playerBody.WarpToPositionRotation(spawnPoint.transform.position, spawnPoint.transform.rotation);
playerBody.SetVelocity(spawnPoint.GetPointVelocity());
var bridgeVolume = FindObjectOfType<VesselWarpController>()._bridgeVolume;
bridgeVolume.AddObjectToVolume(Locator.GetPlayerDetector());
bridgeVolume.AddObjectToVolume(Locator.GetPlayerCameraDetector());
}
private static void InsertWarpCore()
2022-03-02 19:46:33 -08:00
{
var warpCore = GameObject.Find("Prefab_NOM_WarpCoreVessel").GetComponent<WarpCoreItem>();
var socket = GameObject.Find("Interactibles_VesselBridge").GetComponentInChildren<WarpCoreSocket>();
socket.PlaceIntoSocket(warpCore);
}
2021-12-21 21:24:31 +00:00
private static void DamageShipElectricalSystem() =>
ShipManager.Instance.ShipElectricalComponent.SetDamaged(true);
2021-12-21 21:24:31 +00:00
2022-03-02 19:46:33 -08:00
private void Awake() => enabled = QSBCore.DebugSettings.DebugMode;
2021-12-27 21:05:11 +00:00
2022-03-02 19:46:33 -08:00
private int _otherPlayerToTeleportTo;
private int _backTimer;
private int _forwardTimer;
private const int UpdatesUntilScroll = 30;
private const int UpdatesBetweenScroll = 5;
2022-07-24 10:20:22 -07:00
private static void GoForwardOneObject()
{
var allWorldObjects = typeof(IWorldObject).GetDerivedTypes().ToArray();
if (WorldObjectSelection == null)
{
WorldObjectSelection = allWorldObjects.First();
return;
}
var index = Array.IndexOf(allWorldObjects, WorldObjectSelection) + 1;
if (index == allWorldObjects.Length)
{
index = 0;
}
WorldObjectSelection = allWorldObjects[index];
}
2022-07-24 10:20:22 -07:00
private static void GoBackOneObject()
{
var allWorldObjects = typeof(IWorldObject).GetDerivedTypes().ToArray();
if (WorldObjectSelection == null)
{
WorldObjectSelection = allWorldObjects.Last();
return;
}
var index = Array.IndexOf(allWorldObjects, WorldObjectSelection) - 1;
if (index < 0)
{
index = allWorldObjects.Length - 1;
}
WorldObjectSelection = allWorldObjects[index];
}
2021-08-08 19:48:48 +01:00
2022-03-02 19:46:33 -08:00
public void Update()
{
if (!Keyboard.current[Key.Q].isPressed)
{
2022-03-02 19:46:33 -08:00
return;
}
if (Keyboard.current[Key.Comma].isPressed && Keyboard.current[Key.Period].isPressed)
{
WorldObjectSelection = null;
}
else if (Keyboard.current[Key.Comma].wasPressedThisFrame)
{
GoBackOneObject();
}
else if (Keyboard.current[Key.Period].wasPressedThisFrame)
{
GoForwardOneObject();
}
else
{
if (Keyboard.current[Key.Comma].isPressed)
{
_backTimer++;
if (_backTimer >= UpdatesUntilScroll)
{
if (_backTimer == UpdatesUntilScroll + UpdatesBetweenScroll)
{
_backTimer = UpdatesUntilScroll;
GoBackOneObject();
}
}
}
2022-07-24 10:20:22 -07:00
else
{
_backTimer = 0;
}
if (Keyboard.current[Key.Period].isPressed)
{
_forwardTimer++;
if (_forwardTimer >= UpdatesUntilScroll)
{
if (_forwardTimer == UpdatesUntilScroll + UpdatesBetweenScroll)
{
_forwardTimer = UpdatesUntilScroll;
GoForwardOneObject();
}
}
}
2022-07-24 10:20:22 -07:00
else
{
_forwardTimer = 0;
}
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad1].wasPressedThisFrame)
{
var otherPlayers = QSBPlayerManager.PlayerList.Where(x => !x.IsLocalPlayer).ToList();
_otherPlayerToTeleportTo = (_otherPlayerToTeleportTo + 1) % otherPlayers.Count;
var otherPlayer = otherPlayers[_otherPlayerToTeleportTo];
new DebugRequestTeleportInfoMessage(otherPlayer.PlayerId).Send();
}
2022-01-12 10:52:11 +00:00
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad2].wasPressedThisFrame)
{
if (!QSBPlayerManager.LocalPlayer.InDreamWorld)
{
2022-06-16 15:08:19 -07:00
// modified from DayDream debug thing
var relativeLocation = new RelativeLocationData(Vector3.up * 2 + Vector3.forward * 2, Quaternion.identity, Vector3.zero);
var location = Keyboard.current[Key.LeftShift].isPressed ? DreamArrivalPoint.Location.Zone4 : DreamArrivalPoint.Location.Zone3;
var arrivalPoint = Locator.GetDreamArrivalPoint(location);
var dreamCampfire = Locator.GetDreamCampfire(location);
if (Locator.GetToolModeSwapper().GetItemCarryTool().GetHeldItemType() != ItemType.DreamLantern)
{
var dreamLanternItem = QSBWorldSync.GetWorldObjects<QSBDreamLanternItem>().First(x =>
x.AttachedObject._lanternType == DreamLanternType.Functioning &&
QSBPlayerManager.PlayerList.All(y => y.HeldItem != x) &&
2023-09-02 23:04:46 -07:00
!x.AttachedObject.GetLanternController().IsLit() // lit = someone else is holding. backup in case held item isnt initial state synced
).AttachedObject;
Locator.GetToolModeSwapper().GetItemCarryTool().PickUpItemInstantly(dreamLanternItem);
}
Locator.GetDreamWorldController().EnterDreamWorld(dreamCampfire, arrivalPoint, relativeLocation);
}
else
{
if (Locator.GetToolModeSwapper().GetItemCarryTool().GetHeldItemType() != ItemType.DreamLantern)
{
var dreamLanternItem = QSBPlayerManager.LocalPlayer.AssignedSimulationLantern.AttachedObject;
Locator.GetToolModeSwapper().GetItemCarryTool().PickUpItemInstantly(dreamLanternItem);
}
}
2022-03-02 19:46:33 -08:00
}
2021-06-18 22:38:32 +01:00
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad3].wasPressedThisFrame)
{
2022-05-03 08:48:24 +01:00
var sarcoController = QSBWorldSync.GetUnityObject<SarcophagusController>();
sarcoController.firstSealProjector.SetLit(false);
sarcoController.secondSealProjector.SetLit(false);
sarcoController.thirdSealProjector.SetLit(false);
2022-08-20 18:02:05 -07:00
sarcoController.OnPressInteract();
2022-03-02 19:46:33 -08:00
}
2021-06-18 22:38:32 +01:00
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad4].wasPressedThisFrame)
{
2023-06-11 01:00:27 +01:00
if (QSBCore.IsHost)
{
StartCoroutine(SendPacketLossTest());
}
2022-03-02 19:46:33 -08:00
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad5].wasPressedThisFrame)
{
new DebugTriggerSupernovaMessage().Send();
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad6].wasPressedThisFrame)
{
PlayerData.SetPersistentCondition("MET_SOLANUM", true);
PlayerData.SetPersistentCondition("MET_PRISONER", true);
DialogueConditionManager.SharedInstance.SetConditionState("MET_SOLANUM", true);
DialogueConditionManager.SharedInstance.SetConditionState("MET_PRISONER", true);
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad7].wasPressedThisFrame)
{
GoToVessel();
InsertWarpCore();
2022-03-02 19:46:33 -08:00
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad8].wasPressedThisFrame)
{
var player = new PlayerInfo(QSBPlayerManager.LocalPlayer.TransformSync);
QSBPlayerManager.PlayerList.SafeAdd(player);
2023-03-05 20:48:08 +00:00
QSBPlayerManager.OnAddPlayer?.SafeInvoke(player);
2022-08-24 09:32:31 +01:00
DebugLog.DebugWrite($"CREATING FAKE PLAYER : {player}", MessageType.Info);
JoinLeaveSingularity.Create(player, true);
2022-03-02 19:46:33 -08:00
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad9].wasPressedThisFrame)
{
new DebugChangeSceneMessage(Keyboard.current[Key.LeftShift].isPressed).Send();
}
2022-03-02 19:46:33 -08:00
if (Keyboard.current[Key.Numpad0].wasPressedThisFrame)
{
RespawnManager.Instance.RespawnSomePlayer();
}
2020-12-02 21:23:01 +00:00
}
2023-06-11 01:00:27 +01:00
2023-06-11 01:15:58 +01:00
const int MAX_MESSAGES = 200;
2023-06-11 01:00:27 +01:00
int currentMessage = 1;
public static int TotalMessages;
IEnumerator SendPacketLossTest()
{
2023-06-11 01:15:58 +01:00
currentMessage = 1;
2023-06-11 01:00:27 +01:00
DebugLog.DebugWrite($"STARTING DROPPED MESSAGE TEST...");
while (currentMessage <= MAX_MESSAGES)
{
new PacketLossTestMessage().Send();
currentMessage++;
2023-06-11 01:15:58 +01:00
yield return new WaitForSeconds(0.1f);
2023-06-11 01:00:27 +01:00
}
}
}