quantum-space-buddies/QSB/PlayerInfo.cs
Mister_Nebula 99064c4572 cleanup
2020-08-09 21:58:03 +01:00

70 lines
2.2 KiB
C#

using System.Linq;
using QSB.Tools;
using QSB.Utility;
using UnityEngine;
namespace QSB
{
public class PlayerInfo
{
public uint NetId { get; }
public GameObject Body { get; set; }
public GameObject Camera { get; set; }
public GameObject ProbeBody { get; set; }
public QSBProbe Probe { get; set; }
public QSBFlashlight FlashLight => Camera.GetComponentInChildren<QSBFlashlight>();
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
public QSBTool Translator => GetToolByType(ToolType.Translator);
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
public string Name { get; set; }
public bool IsReady { get; set; }
public State State { get; private set; }
public PlayerInfo(uint id)
{
NetId = id;
}
public void UpdateState(State state, bool value)
{
var states = State;
if (value)
{
FlagsHelper.Set(ref states, state);
}
else
{
FlagsHelper.Unset(ref states, state);
}
State = states;
}
public void UpdateStates(State newState)
{
State = newState;
FlashLight.UpdateState(FlagsHelper.IsSet(State, State.Flashlight));
Translator.ChangeEquipState(FlagsHelper.IsSet(State, State.Translator));
ProbeLauncher.ChangeEquipState(FlagsHelper.IsSet(State, State.ProbeLauncher));
Signalscope.ChangeEquipState(FlagsHelper.IsSet(State, State.Signalscope));
if (FlagsHelper.IsSet(State, State.Suit))
{
PlayerRegistry.GetAnimationSync(NetId).SuitUp();
}
else
{
PlayerRegistry.GetAnimationSync(NetId).SuitDown();
}
}
public bool GetState(State state)
{
return FlagsHelper.IsSet(State, state);
}
private QSBTool GetToolByType(ToolType type)
{
return Camera.GetComponentsInChildren<QSBTool>().First(x => x.Type == type);
}
}
}