2021-10-25 10:42:25 +01:00
using OWML.Common ;
using QSB.Animation.Player ;
2021-12-14 22:53:53 +00:00
using QSB.Audio ;
2021-08-08 20:06:38 +01:00
using QSB.ClientServerStateSync ;
2023-02-10 12:01:31 +00:00
using QSB.HUD ;
2021-12-22 17:38:08 -08:00
using QSB.Messaging ;
2022-08-28 01:44:40 -04:00
using QSB.ModelShip ;
2021-12-23 17:07:29 -08:00
using QSB.Player.Messages ;
using QSB.Player.TransformSync ;
using QSB.QuantumSync.WorldObjects ;
2022-04-16 10:08:59 +01:00
using QSB.ShipSync ;
2020-08-22 17:08:56 +01:00
using QSB.Tools ;
2021-07-10 18:59:37 +01:00
using QSB.Utility ;
2020-08-21 14:04:13 +01:00
using System.Linq ;
2023-03-04 13:30:50 +00:00
using UnityEngine ;
2020-07-28 15:59:24 +02:00
2022-03-02 19:46:33 -08:00
namespace QSB.Player ;
2022-03-24 15:02:31 +00:00
public partial class PlayerInfo
2020-07-28 15:59:24 +02:00
{
2022-03-02 19:46:33 -08:00
/// <summary>
/// the player transform sync's net id
/// </summary>
public uint PlayerId { get ; }
public string Name { get ; set ; }
public PlayerHUDMarker HudMarker { get ; set ; }
2022-11-19 17:15:42 -08:00
public PlayerMapMarker MapMarker { get ; set ; }
2023-02-10 12:01:31 +00:00
public PlayerBox HUDBox { get ; set ; }
2023-03-04 13:30:50 +00:00
public Transform MinimapPlayerMarker { get ; set ; }
2022-03-02 19:46:33 -08:00
public PlayerTransformSync TransformSync { get ; }
public ClientState State { get ; set ; }
public EyeState EyeState { get ; set ; }
public bool IsDead { get ; set ; }
public bool IsReady { get ; set ; }
public bool IsInMoon { get ; set ; }
public bool IsInShrine { get ; set ; }
public bool IsInEyeShuttle { get ; set ; }
2023-01-21 10:48:54 +00:00
public bool IsInShip { get ; set ; }
2023-01-22 22:44:59 +00:00
public bool IsInCloak { get ; set ; }
2022-03-02 19:46:33 -08:00
public IQSBQuantumObject EntangledObject { get ; set ; }
public QSBPlayerAudioController AudioController { get ; set ; }
2022-08-24 13:29:03 -07:00
public bool IsLocalPlayer = > TransformSync . isLocalPlayer ; // if TransformSync is ever null, i give permission for nebula to make fun of me about it for the rest of time - johncorby
2022-03-07 13:25:41 -08:00
public ThrusterLightTracker ThrusterLightTracker ;
2022-04-16 10:08:59 +01:00
public bool FlyingShip = > ShipManager . Instance . CurrentFlyer = = PlayerId ;
2022-08-28 01:44:40 -04:00
public bool FlyingModelShip = > ModelShipManager . Instance . CurrentFlyer = = PlayerId ;
2023-03-04 13:30:33 +00:00
public RemotePlayerRulesetDetector RulesetDetector { get ; set ; }
2022-08-24 14:07:22 -07:00
2022-03-02 19:46:33 -08:00
public PlayerInfo ( PlayerTransformSync transformSync )
{
PlayerId = transformSync . netId ;
TransformSync = transformSync ;
AnimationSync = transformSync . GetComponent < AnimationSync > ( ) ;
}
2021-12-10 14:54:51 +00:00
2022-03-28 12:54:20 -07:00
/// <summary>
/// called on player transform sync uninit.
2022-03-28 13:03:21 -07:00
/// (BOTH local and non-local)
2022-03-28 12:54:20 -07:00
/// </summary>
public void Reset ( )
{
2022-08-18 12:20:52 +01:00
if ( AnimationSync ! = null )
{
AnimationSync . Reset ( ) ;
}
2022-03-28 12:56:35 -07:00
EyeState = default ;
2022-03-28 12:54:20 -07:00
IsDead = default ;
IsReady = default ;
IsInMoon = default ;
IsInShrine = default ;
IsInEyeShuttle = default ;
EntangledObject = default ;
2022-05-13 22:38:06 +01:00
CurrentCharacterDialogueTree = default ;
2022-03-28 12:54:20 -07:00
InDreamWorld = default ;
AssignedSimulationLantern = default ;
Campfire = default ;
HeldItem = default ;
FlashlightActive = default ;
SuitedUp = default ;
2022-04-16 10:08:59 +01:00
LocalProbeLauncherEquipped = default ;
2022-03-28 12:54:20 -07:00
SignalscopeEquipped = default ;
TranslatorEquipped = default ;
ProbeActive = default ;
2022-04-16 10:08:59 +01:00
ProbeLauncherEquipped = default ;
2022-07-01 16:20:38 -07:00
IsTranslating = default ;
2022-03-28 12:54:20 -07:00
}
2022-03-02 19:46:33 -08:00
public void UpdateObjectsFromStates ( )
{
2022-05-30 09:24:02 +01:00
FlashLight . UpdateState ( FlashlightActive & & Visible ) ;
2022-03-29 23:20:38 +01:00
Translator . ChangeEquipState ( TranslatorEquipped ) ;
2022-04-16 10:08:59 +01:00
ProbeLauncherTool . ChangeEquipState ( LocalProbeLauncherEquipped ) ;
2022-03-29 23:20:38 +01:00
Signalscope . ChangeEquipState ( SignalscopeEquipped ) ;
2022-03-02 19:46:33 -08:00
AnimationSync . SetSuitState ( SuitedUp ) ;
}
2022-02-24 22:04:54 -08:00
2022-03-02 19:46:33 -08:00
public void UpdateStatesFromObjects ( )
{
if ( Locator . GetFlashlight ( ) = = null | | Locator . GetPlayerBody ( ) = = null )
{
FlashlightActive = false ;
SuitedUp = false ;
}
else
{
FlashlightActive = Locator . GetFlashlight ( ) . _flashlightOn ;
2022-08-18 12:20:52 +01:00
SuitedUp = Locator . GetPlayerBody ( ) . GetComponent < PlayerSpacesuit > ( ) . IsWearingSuit ( )
| | QSBSceneManager . CurrentScene = = OWScene . EyeOfTheUniverse ;
2022-03-02 19:46:33 -08:00
}
2022-01-21 22:21:45 -08:00
2022-03-02 19:46:33 -08:00
new PlayerInformationMessage ( ) . Send ( ) ;
}
2022-02-24 22:04:54 -08:00
2022-03-02 19:46:33 -08: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 ;
}
2022-02-27 04:40:44 -08:00
2022-03-02 19:46:33 -08:00
var tools = CameraBody . GetComponentsInChildren < QSBTool > ( ) ;
if ( tools = = null | | tools . Length = = 0 )
{
DebugLog . ToConsole ( $"Warning - Couldn't find any QSBTools for player {PlayerId}." , MessageType . Warning ) ;
return null ;
2022-02-24 22:04:54 -08:00
}
2022-01-21 22:21:45 -08:00
2022-03-02 19:46:33 -08:00
var tool = tools . FirstOrDefault ( x = > x . Type = = type ) ;
if ( tool = = null )
2022-02-24 22:04:54 -08:00
{
2022-03-02 19:46:33 -08:00
DebugLog . ToConsole ( $"Warning - No tool found on player {PlayerId} matching ToolType {type}." , MessageType . Warning ) ;
}
2022-01-21 22:21:45 -08:00
2022-03-02 19:46:33 -08:00
return tool ;
}
public void SetVisible ( bool visible , float seconds = 0 )
{
if ( IsLocalPlayer )
{
return ;
}
2022-02-27 04:40:44 -08:00
2022-03-02 19:46:33 -08:00
if ( ! _ditheringAnimator )
{
DebugLog . ToConsole ( $"Warning - {PlayerId}.DitheringAnimator is null!" , MessageType . Warning ) ;
return ;
2022-02-27 04:40:44 -08:00
}
2022-03-02 19:46:33 -08:00
_ditheringAnimator . SetVisible ( visible , seconds ) ;
2022-05-30 09:24:02 +01:00
if ( ! visible )
{
FlashLight . UpdateState ( false ) ;
}
else
{
FlashLight . UpdateState ( FlashlightActive ) ;
}
2020-12-02 21:23:01 +00:00
}
2022-03-06 01:01:02 -08:00
2023-02-10 12:01:31 +00:00
public void Die ( )
{
IsDead = true ;
SetVisible ( false , 1 ) ;
HUDBox . OnDeath ( ) ;
}
public void Revive ( )
{
IsDead = false ;
SetVisible ( true , 1 ) ;
HUDBox . OnRespawn ( ) ;
}
2022-03-11 00:58:14 -08:00
public override string ToString ( ) = > $"{PlayerId}:{GetType().Name} ({Name})" ;
2022-08-24 14:07:22 -07:00
}