305 lines
8.1 KiB
C#
Raw Normal View History

2021-10-25 10:42:25 +01:00
using OWML.Common;
using QSB.Animation.Player;
2021-05-07 14:58:37 +01:00
using QSB.Animation.Player.Thrusters;
2021-12-14 22:53:53 +00:00
using QSB.Audio;
2021-03-31 10:30:51 +01:00
using QSB.CampfireSync.WorldObjects;
2021-08-08 20:06:38 +01:00
using QSB.ClientServerStateSync;
2021-11-01 15:49:00 +00:00
using QSB.ItemSync.WorldObjects.Items;
2021-12-22 17:38:08 -08:00
using QSB.Messaging;
2021-12-23 17:07:29 -08:00
using QSB.Player.Messages;
using QSB.Player.TransformSync;
2022-02-18 05:33:48 -08:00
using QSB.PlayerBodySetup.Remote;
2021-12-23 17:07:29 -08:00
using QSB.QuantumSync.WorldObjects;
2021-03-30 17:28:05 +01:00
using QSB.RoastingSync;
2020-08-22 17:08:56 +01:00
using QSB.Tools;
using QSB.Tools.FlashlightTool;
2021-07-26 22:55:09 +01:00
using QSB.Tools.ProbeLauncherTool;
using QSB.Tools.ProbeTool;
2021-07-10 18:59:37 +01:00
using QSB.Utility;
2020-08-21 14:04:13 +01:00
using System.Linq;
using UnityEngine;
2020-07-28 15:59:24 +02:00
namespace QSB.Player;
public class PlayerInfo
2020-07-28 15:59:24 +02:00
{
/// <summary>
/// the player transform sync's net id
/// </summary>
public uint PlayerId { get; }
public string Name { get; set; }
public PlayerHUDMarker HudMarker { get; set; }
public PlayerTransformSync TransformSync { get; }
public AnimationSync AnimationSync { get; }
public ClientState State { get; set; }
public EyeState EyeState { get; set; }
public bool IsDead { get; set; }
2022-02-24 23:13:31 -08:00
public bool Visible => IsLocalPlayer || _ditheringAnimator == null || _ditheringAnimator.FullyVisible;
public bool IsReady { get; set; }
public bool IsInMoon { get; set; }
public bool IsInShrine { get; set; }
public bool IsInEyeShuttle { get; set; }
public IQSBQuantumObject EntangledObject { get; set; }
public QSBPlayerAudioController AudioController { get; set; }
internal QSBDitheringAnimator _ditheringAnimator;
public bool IsLocalPlayer => TransformSync.isLocalPlayer;
// Body Objects
public OWCamera Camera
2020-12-02 21:23:01 +00:00
{
get
2021-10-25 10:42:25 +01:00
{
if (_camera == null && IsReady)
2021-10-25 10:42:25 +01:00
{
DebugLog.ToConsole($"Warning - {PlayerId}.Camera is null!", MessageType.Warning);
2021-10-25 10:42:25 +01:00
}
return _camera;
}
set
{
if (value == null)
{
DebugLog.ToConsole($"Warning - Setting {PlayerId}.Camera to null.", MessageType.Warning);
2021-10-25 10:42:25 +01:00
}
_camera = value;
2021-10-25 10:42:25 +01:00
}
}
2022-02-24 23:13:31 -08:00
private OWCamera _camera;
2021-10-25 10:42:25 +01:00
public GameObject CameraBody { get; set; }
2021-12-29 11:30:54 +00:00
public GameObject Body
{
get
2021-10-25 10:42:25 +01:00
{
if (_body == null && IsReady)
2021-10-25 10:42:25 +01:00
{
DebugLog.ToConsole($"Warning - {PlayerId}.Body is null!", MessageType.Warning);
2021-10-25 10:42:25 +01:00
}
2021-11-20 19:49:50 +00:00
return _body;
2021-10-25 10:42:25 +01:00
}
set
2022-01-26 13:12:22 +00:00
{
if (value == null)
2022-01-26 13:12:22 +00:00
{
DebugLog.ToConsole($"Warning - Setting {PlayerId}.Body to null.", MessageType.Warning);
2022-01-26 13:12:22 +00:00
}
_body = value;
2022-01-26 13:12:22 +00:00
}
}
2022-02-24 23:13:31 -08:00
private GameObject _body;
public GameObject RoastingStick { get; set; }
// Tools
public GameObject ProbeBody { get; set; }
public QSBProbe Probe { get; set; }
public QSBFlashlight FlashLight => CameraBody == null ? null : CameraBody.GetComponentInChildren<QSBFlashlight>();
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
public QSBTool Translator => GetToolByType(ToolType.Translator);
public QSBProbeLauncherTool ProbeLauncher => (QSBProbeLauncherTool)GetToolByType(ToolType.ProbeLauncher);
private Transform _handPivot;
2022-02-24 23:13:31 -08:00
public Transform HandPivot
{
get
2021-07-10 18:59:37 +01:00
{
if (_handPivot == null)
2021-07-10 18:59:37 +01:00
{
_handPivot = Body.transform.Find(
// TODO : kill me for my sins
"REMOTE_Traveller_HEA_Player_v2/" +
"Traveller_Rig_v01:Traveller_Trajectory_Jnt/" +
"Traveller_Rig_v01:Traveller_ROOT_Jnt/" +
"Traveller_Rig_v01:Traveller_Spine_01_Jnt/" +
"Traveller_Rig_v01:Traveller_Spine_02_Jnt/" +
"Traveller_Rig_v01:Traveller_Spine_Top_Jnt/" +
"Traveller_Rig_v01:Traveller_RT_Arm_Clavicle_Jnt/" +
"Traveller_Rig_v01:Traveller_RT_Arm_Shoulder_Jnt/" +
"Traveller_Rig_v01:Traveller_RT_Arm_Elbow_Jnt/" +
"Traveller_Rig_v01:Traveller_RT_Arm_Wrist_Jnt/" +
"REMOTE_ItemCarryTool/" +
"HandPivot"
);
2021-07-10 18:59:37 +01:00
}
return _handPivot;
}
}
2022-02-24 23:13:31 -08:00
public Transform ItemSocket => HandPivot.Find("REMOTE_ItemSocket");
public Transform ScrollSocket => HandPivot.Find("REMOTE_ScrollSocket");
public Transform SharedStoneSocket => HandPivot.Find("REMOTE_SharedStoneSocket");
public Transform WarpCoreSocket => HandPivot.Find("REMOTE_WarpCoreSocket");
public Transform VesselCoreSocket => HandPivot.Find("REMOTE_VesselCoreSocket");
public Transform SimpleLanternSocket => HandPivot.Find("REMOTE_SimpleLanternSocket");
public Transform DreamLanternSocket => HandPivot.Find("REMOTE_DreamLanternSocket");
public Transform SlideReelSocket => HandPivot.Find("REMOTE_SlideReelSocket");
public Transform VisionTorchSocket => HandPivot.Find("REMOTE_VisionTorchSocket");
public QSBMarshmallow Marshmallow { get; set; }
public QSBCampfire Campfire { get; set; }
public IQSBItem HeldItem { get; set; }
public bool FlashlightActive { get; set; }
public bool SuitedUp { get; set; }
public bool ProbeLauncherEquipped { get; set; }
public bool SignalscopeEquipped { get; set; }
public bool TranslatorEquipped { get; set; }
public bool ProbeActive { get; set; }
// Conversation
public int CurrentCharacterDialogueTreeId { get; set; } = -1;
public GameObject CurrentDialogueBox { get; set; }
// Animation
public JetpackAccelerationSync JetpackAcceleration { get; set; }
// Local only
public PlayerProbeLauncher LocalProbeLauncher
{
get
2021-07-10 18:59:37 +01:00
{
if (!IsLocalPlayer)
2021-07-10 18:59:37 +01:00
{
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalProbeLauncher in PlayerInfo for non local player!", MessageType.Warning);
return null;
2021-07-10 18:59:37 +01:00
}
return CameraBody?.transform.Find("ProbeLauncher").GetComponent<PlayerProbeLauncher>();
2021-07-10 18:59:37 +01:00
}
}
2021-07-10 18:59:37 +01:00
public Flashlight LocalFlashlight
{
get
2021-07-10 18:59:37 +01:00
{
if (!IsLocalPlayer)
2021-07-10 18:59:37 +01:00
{
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalFlashlight in PlayerInfo for non local player!", MessageType.Warning);
return null;
2021-07-10 18:59:37 +01:00
}
return Locator.GetFlashlight();
2021-07-10 18:59:37 +01:00
}
}
2021-07-10 18:59:37 +01:00
public Signalscope LocalSignalscope
{
get
2021-07-10 18:59:37 +01:00
{
if (!IsLocalPlayer)
2021-07-10 18:59:37 +01:00
{
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalSignalscope in PlayerInfo for non local player!", MessageType.Warning);
return null;
2021-07-10 18:59:37 +01:00
}
return CameraBody?.transform.Find("Signalscope").GetComponent<Signalscope>();
2020-12-02 21:23:01 +00:00
}
}
public NomaiTranslator LocalTranslator
{
get
2020-12-02 21:23:01 +00:00
{
if (!IsLocalPlayer)
2020-12-02 21:23:01 +00:00
{
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalTranslator in PlayerInfo for non local player!", MessageType.Warning);
return null;
2020-12-02 21:23:01 +00:00
}
2021-06-18 22:38:32 +01:00
return CameraBody?.transform.Find("NomaiTranslatorProp").GetComponent<NomaiTranslator>();
2020-12-02 21:23:01 +00:00
}
}
2020-08-09 21:46:51 +01:00
public PlayerInfo(PlayerTransformSync transformSync)
{
PlayerId = transformSync.netId;
TransformSync = transformSync;
AnimationSync = transformSync.GetComponent<AnimationSync>();
}
public void UpdateObjectsFromStates()
{
if (OWInput.GetInputMode() == InputMode.None)
2021-11-21 13:52:29 +00:00
{
// ? why is this here lmao
return;
}
2021-11-21 13:52:29 +00:00
if (CameraBody == null)
{
return;
2021-11-21 13:52:29 +00:00
}
FlashLight?.UpdateState(FlashlightActive);
Translator?.ChangeEquipState(TranslatorEquipped);
ProbeLauncher?.ChangeEquipState(ProbeLauncherEquipped);
Signalscope?.ChangeEquipState(SignalscopeEquipped);
AnimationSync.SetSuitState(SuitedUp);
}
public void UpdateStatesFromObjects()
{
if (Locator.GetFlashlight() == null || Locator.GetPlayerBody() == null)
2021-12-10 14:54:51 +00:00
{
FlashlightActive = false;
SuitedUp = false;
}
else
{
FlashlightActive = Locator.GetFlashlight()._flashlightOn;
SuitedUp = Locator.GetPlayerBody().GetComponent<PlayerSpacesuit>().IsWearingSuit();
}
2021-12-10 14:54:51 +00:00
new PlayerInformationMessage().Send();
}
2021-12-10 14:54:51 +00:00
private QSBTool GetToolByType(ToolType type)
{
if (CameraBody == null)
{
DebugLog.ToConsole($"Warning - Tried to GetToolByType({type}) on player {PlayerId}, but CameraBody was null.", MessageType.Warning);
return null;
}
2021-12-10 14:54:51 +00:00
var tools = CameraBody.GetComponentsInChildren<QSBTool>();
2021-12-10 14:54:51 +00:00
if (tools == null || tools.Length == 0)
{
DebugLog.ToConsole($"Warning - Couldn't find any QSBTools for player {PlayerId}.", MessageType.Warning);
return null;
}
2021-12-10 14:54:51 +00:00
var tool = tools.FirstOrDefault(x => x.Type == type);
if (tool == null)
{
DebugLog.ToConsole($"Warning - No tool found on player {PlayerId} matching ToolType {type}.", MessageType.Warning);
2021-12-10 14:54:51 +00:00
}
2022-01-21 22:21:45 -08:00
return tool;
}
public void SetVisible(bool visible, float seconds = 0)
{
if (IsLocalPlayer)
2022-01-21 22:21:45 -08:00
{
return;
}
2022-01-21 22:21:45 -08:00
if (!_ditheringAnimator)
{
DebugLog.ToConsole($"Warning - {PlayerId}.DitheringAnimator is null!", MessageType.Warning);
return;
}
2022-01-21 22:21:45 -08:00
2022-02-24 23:13:31 -08:00
_ditheringAnimator.SetVisible(visible, seconds);
2020-12-02 21:23:01 +00:00
}
2022-02-24 23:13:31 -08:00
}