231 lines
6.6 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-03-31 10:30:51 +01:00
using QSB.CampfireSync.WorldObjects;
2021-08-08 20:06:38 +01:00
using QSB.ClientServerStateSync;
2021-11-21 13:52:29 +00:00
using QSB.Events;
2021-11-01 15:49:00 +00:00
using QSB.ItemSync.WorldObjects.Items;
2021-04-21 11:02:17 +01:00
using QSB.Player.TransformSync;
2021-02-21 18:25:25 +00:00
using QSB.QuantumSync;
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
2020-11-03 21:33:48 +00:00
namespace QSB.Player
2020-07-28 15:59:24 +02:00
{
2020-12-02 21:23:01 +00:00
public class PlayerInfo
{
public uint PlayerId { get; }
public string Name { get; set; }
public PlayerHUDMarker HudMarker { get; set; }
2021-04-21 11:02:17 +01:00
public PlayerTransformSync TransformSync { get; set; }
2020-11-01 12:26:09 +00:00
2020-12-02 21:23:01 +00:00
// Body Objects
2021-10-25 10:42:25 +01:00
public OWCamera Camera
{
get
{
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;
}
}
private OWCamera _camera;
2020-12-22 09:13:08 +00:00
public GameObject CameraBody { get; set; }
2021-10-25 10:42:25 +01:00
public GameObject Body
{
get
{
if (_body == null && IsReady)
2021-10-25 10:42:25 +01:00
{
DebugLog.ToConsole($"Warning - {PlayerId}.Body is null!", MessageType.Warning);
}
2021-11-20 19:49:50 +00:00
2021-10-25 10:42:25 +01:00
return _body;
}
set
{
if (value == null)
{
DebugLog.ToConsole($"Warning - Setting {PlayerId}.Body to null.", MessageType.Warning);
}
2021-11-20 19:49:50 +00:00
2021-10-25 10:42:25 +01:00
_body = value;
}
}
private GameObject _body;
2021-03-30 17:28:05 +01:00
public GameObject RoastingStick { get; set; }
2021-06-23 21:44:18 +01:00
public bool Visible { get; set; } = true;
2020-09-22 21:11:29 +01:00
2020-12-02 21:23:01 +00:00
// Tools
public GameObject ProbeBody { get; set; }
public QSBProbe Probe { get; set; }
2021-11-21 13:52:29 +00:00
public QSBFlashlight FlashLight
{
get
{
if (CameraBody == null)
{
return null;
}
return CameraBody.GetComponentInChildren<QSBFlashlight>();
}
}
2020-12-02 21:23:01 +00:00
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
public QSBTool Translator => GetToolByType(ToolType.Translator);
2021-07-26 22:55:09 +01:00
public QSBProbeLauncherTool ProbeLauncher => (QSBProbeLauncherTool)GetToolByType(ToolType.ProbeLauncher);
2021-07-19 14:58:28 +01:00
public Transform ItemSocket => CameraBody.transform.Find("REMOTE_ItemSocket");
public Transform ScrollSocket => CameraBody.transform.Find("REMOTE_ScrollSocket");
public Transform SharedStoneSocket => CameraBody.transform.Find("REMOTE_SharedStoneSocket");
public Transform WarpCoreSocket => CameraBody.transform.Find("REMOTE_WarpCoreSocket");
public Transform VesselCoreSocket => CameraBody.transform.Find("REMOTE_VesselCoreSocket");
2021-11-01 15:49:00 +00:00
public Transform SimpleLanternSocket => CameraBody.transform.Find("REMOTE_SimpleLanternSocket");
public Transform DreamLanternSocket => CameraBody.transform.Find("REMOTE_DreamLanternSocket");
public Transform SlideReelSocket => CameraBody.transform.Find("REMOTE_SlideReelSocket");
public Transform VisionTorchSocket => CameraBody.transform.Find("REMOTE_VisionTorchSocket");
2021-03-30 17:28:05 +01:00
public QSBMarshmallow Marshmallow { get; set; }
2021-03-31 10:30:51 +01:00
public QSBCampfire Campfire { get; set; }
2021-10-30 16:14:38 +01:00
public IQSBOWItem HeldItem { get; set; }
2020-09-22 21:11:29 +01:00
2020-12-02 21:23:01 +00:00
// Conversation
2021-04-29 18:30:45 +01:00
public int CurrentCharacterDialogueTreeId { get; set; }
2020-12-02 21:23:01 +00:00
public GameObject CurrentDialogueBox { get; set; }
2020-11-01 12:26:09 +00:00
2020-12-02 21:23:01 +00:00
// Animation
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
2021-11-20 19:49:50 +00:00
public bool PlayingInstrument => AnimationSync.CurrentType is not AnimationType.PlayerSuited
and not AnimationType.PlayerUnsuited;
2021-05-07 14:58:37 +01:00
public JetpackAccelerationSync JetpackAcceleration { get; set; }
2021-01-18 12:33:07 +00:00
// Misc
public bool IsReady { get; set; }
2021-08-22 16:40:50 +01:00
public bool IsInMoon; // MOVE : move into PlayerStates?
public bool IsInShrine; // MOVE : move into PlayerStates?
2021-02-21 18:25:25 +00:00
public IQSBQuantumObject EntangledObject;
2021-06-25 13:17:10 +01:00
public bool IsDead { get; set; }
2021-08-08 19:57:58 +01:00
public ClientState State { 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; }
2021-01-18 12:33:07 +00:00
2021-07-10 18:59:37 +01:00
// Local only
public PlayerProbeLauncher LocalProbeLauncher
{
get
{
if (QSBPlayerManager.LocalPlayer != this)
{
2021-10-25 10:42:25 +01:00
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalProbeLauncher in PlayerInfo for non local player!", MessageType.Warning);
2021-07-10 18:59:37 +01:00
return null;
}
return CameraBody.transform.Find("ProbeLauncher").GetComponent<PlayerProbeLauncher>();
}
}
2021-08-22 16:54:48 +01:00
public Flashlight LocalFlashlight
2021-07-10 18:59:37 +01:00
{
get
{
if (QSBPlayerManager.LocalPlayer != this)
{
2021-10-25 10:42:25 +01:00
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalFlashlight in PlayerInfo for non local player!", MessageType.Warning);
2021-07-10 18:59:37 +01:00
return null;
}
return Locator.GetFlashlight();
}
}
public Signalscope LocalSignalscope
{
get
{
if (QSBPlayerManager.LocalPlayer != this)
{
2021-10-25 10:42:25 +01:00
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalSignalscope in PlayerInfo for non local player!", MessageType.Warning);
2021-07-10 18:59:37 +01:00
return null;
}
return CameraBody.transform.Find("Signalscope").GetComponent<Signalscope>();
}
}
public NomaiTranslator LocalTranslator
{
get
{
if (QSBPlayerManager.LocalPlayer != this)
{
2021-10-25 10:42:25 +01:00
DebugLog.ToConsole($"Warning - Tried to access local-only property LocalTranslator in PlayerInfo for non local player!", MessageType.Warning);
2021-07-10 18:59:37 +01:00
return null;
}
return CameraBody.transform.Find("NomaiTranslatorProp").GetComponent<NomaiTranslator>();
}
}
2020-12-02 21:23:01 +00:00
public PlayerInfo(uint id)
{
PlayerId = id;
2021-04-29 18:30:45 +01:00
CurrentCharacterDialogueTreeId = -1;
2020-12-02 21:23:01 +00:00
}
2021-11-21 13:52:29 +00:00
public void UpdateObjectsFromStates()
2020-12-02 21:23:01 +00:00
{
if (OWInput.GetInputMode() == InputMode.None)
{
return;
}
2021-06-18 22:38:32 +01:00
FlashLight?.UpdateState(FlashlightActive);
Translator?.ChangeEquipState(TranslatorEquipped);
ProbeLauncher?.ChangeEquipState(ProbeLauncherEquipped);
Signalscope?.ChangeEquipState(SignalscopeEquipped);
2021-03-13 10:17:52 +00:00
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId) != null,
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(SuitedUp));
2020-12-02 21:23:01 +00:00
}
2020-08-09 21:46:51 +01:00
2021-11-21 13:52:29 +00:00
public void UpdateStatesFromObjects()
{
if (Locator.GetFlashlight() == null || Locator.GetPlayerBody() == null)
{
FlashlightActive = false;
SuitedUp = false;
}
else
{
FlashlightActive = Locator.GetFlashlight()._flashlightOn;
SuitedUp = Locator.GetPlayerBody().GetComponent<PlayerSpacesuit>().IsWearingSuit(true);
}
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
}
2021-07-12 22:02:50 +01:00
private QSBTool GetToolByType(ToolType type) => CameraBody?.GetComponentsInChildren<QSBTool>()
2020-12-02 21:23:01 +00:00
.FirstOrDefault(x => x.Type == type);
}
2020-07-28 15:59:24 +02:00
}