quantum-space-buddies/QSB/Player/PlayerInfo.cs
2021-04-18 18:46:55 +01:00

81 lines
2.8 KiB
C#

using QSB.Animation;
using QSB.CampfireSync.WorldObjects;
using QSB.ProbeSync;
using QSB.QuantumSync;
using QSB.RoastingSync;
using QSB.Tools;
using QSB.Utility;
using System.Linq;
using UnityEngine;
namespace QSB.Player
{
public class PlayerInfo
{
public uint PlayerId { get; }
public string Name { get; set; }
public PlayerHUDMarker HudMarker { get; set; }
public PlayerState PlayerStates { get; set; }
// Body Objects
public OWCamera Camera { get; set; }
public GameObject CameraBody { get; set; }
public GameObject Body { get; set; }
public GameObject RoastingStick { get; set; }
// Tools
public GameObject ProbeBody { get; set; }
public QSBProbe Probe { get; set; }
public QSBFlashlight FlashLight => CameraBody?.GetComponentInChildren<QSBFlashlight>();
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
public QSBTool Translator => GetToolByType(ToolType.Translator);
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
public Transform ItemSocket => CameraBody.transform.Find("ItemSocket");
public Transform ScrollSocket => CameraBody.transform.Find("ScrollSocket");
public Transform SharedStoneSocket => CameraBody.transform.Find("SharedStoneSocket");
public Transform WarpCoreSocket => CameraBody.transform.Find("WarpCoreSocket");
public Transform VesselCoreSocket => CameraBody.transform.Find("VesselCoreSocket");
public QSBMarshmallow Marshmallow { get; set; }
public QSBCampfire Campfire { get; set; }
// Conversation
public int CurrentDialogueID { get; set; }
public GameObject CurrentDialogueBox { get; set; }
// Animation
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited
&& AnimationSync.CurrentType != AnimationType.PlayerUnsuited;
// Misc
public bool IsInMoon; // TODO : move into PlayerStates?
public bool IsInShrine; // TODO : move into PlayerStates?
public IQSBQuantumObject EntangledObject;
public PlayerInfo(uint id)
{
PlayerId = id;
CurrentDialogueID = -1;
}
public void UpdateStateObjects()
{
if (OWInput.GetInputMode() == InputMode.None)
{
return;
}
FlashLight?.UpdateState(PlayerStates.FlashlightActive);
Translator?.ChangeEquipState(PlayerStates.TranslatorEquipped);
ProbeLauncher?.ChangeEquipState(PlayerStates.ProbeLauncherEquipped);
Signalscope?.ChangeEquipState(PlayerStates.SignalscopeEquipped);
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId) != null,
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(PlayerStates.SuitedUp));
}
private QSBTool GetToolByType(ToolType type)
{
return CameraBody?.GetComponentsInChildren<QSBTool>()
.FirstOrDefault(x => x.Type == type);
}
}
}