2020-05-11 20:30:16 -04:00
|
|
|
|
using System;
|
2021-05-28 02:12:54 +02:00
|
|
|
|
using RobocraftX.Character;
|
2021-05-28 02:52:42 +02:00
|
|
|
|
using RobocraftX.Character.Movement;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
using Unity.Mathematics;
|
2020-05-23 00:06:49 +02:00
|
|
|
|
using RobocraftX.Common;
|
2020-06-05 00:20:35 +02:00
|
|
|
|
using RobocraftX.Common.Players;
|
2021-05-28 02:12:54 +02:00
|
|
|
|
using RobocraftX.Physics;
|
2020-06-05 00:20:35 +02:00
|
|
|
|
using Svelto.ECS;
|
2021-06-09 20:11:31 +02:00
|
|
|
|
using Techblox.BuildingDrone;
|
2021-05-28 02:12:54 +02:00
|
|
|
|
using Techblox.Camera;
|
2021-05-02 01:08:25 +02:00
|
|
|
|
using TechbloxModdingAPI.Blocks;
|
|
|
|
|
using TechbloxModdingAPI.Players;
|
2021-05-28 02:12:54 +02:00
|
|
|
|
using TechbloxModdingAPI.Utility;
|
|
|
|
|
using UnityEngine;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2021-05-02 01:08:25 +02:00
|
|
|
|
namespace TechbloxModdingAPI
|
2020-05-11 20:30:16 -04:00
|
|
|
|
{
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An in-game player character. Any Leo you see is a player.
|
|
|
|
|
/// </summary>
|
2021-05-28 02:52:42 +02:00
|
|
|
|
public class Player : IEquatable<Player>, IEquatable<EGID>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
{
|
|
|
|
|
// static functionality
|
|
|
|
|
private static PlayerEngine playerEngine = new PlayerEngine();
|
2020-09-30 23:52:17 +02:00
|
|
|
|
private static Player localPlayer;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the specified player exists.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Whether the player exists.</returns>
|
|
|
|
|
/// <param name="player">Player type.</param>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public static bool Exists(PlayerType player)
|
|
|
|
|
{
|
|
|
|
|
switch (player)
|
|
|
|
|
{
|
|
|
|
|
case PlayerType.Remote:
|
|
|
|
|
return playerEngine.GetRemotePlayer() != uint.MaxValue;
|
|
|
|
|
case PlayerType.Local:
|
|
|
|
|
return playerEngine.GetLocalPlayer() != uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the specified player exists.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Whether the player exists.</returns>
|
|
|
|
|
/// <param name="player">The player's unique identifier.</param>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public static bool Exists(uint player)
|
|
|
|
|
{
|
|
|
|
|
return playerEngine.ExistsById(player);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
2020-06-23 13:49:42 -04:00
|
|
|
|
/// The amount of Players in the current game.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The count.</returns>
|
|
|
|
|
public static uint Count()
|
|
|
|
|
{
|
2020-07-11 00:30:58 +02:00
|
|
|
|
return (uint) playerEngine.GetAllPlayerCount();
|
2020-06-23 13:49:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 23:52:17 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the current player belonging to this client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Player LocalPlayer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (localPlayer == null || localPlayer.Id != playerEngine.GetLocalPlayer())
|
|
|
|
|
localPlayer = new Player(PlayerType.Local);
|
|
|
|
|
return localPlayer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 13:49:42 -04:00
|
|
|
|
/// <summary>
|
2021-05-02 01:08:25 +02:00
|
|
|
|
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Player"/> class.
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The player's unique identifier.</param>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public Player(uint id)
|
|
|
|
|
{
|
|
|
|
|
this.Id = id;
|
|
|
|
|
if (!Exists(id))
|
|
|
|
|
{
|
2020-05-13 16:52:06 -04:00
|
|
|
|
throw new PlayerNotFoundException($"No player with id {id} exists");
|
2020-05-11 20:30:16 -04:00
|
|
|
|
}
|
|
|
|
|
this.Type = playerEngine.GetLocalPlayer() == id ? PlayerType.Local : PlayerType.Remote;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
2021-05-02 01:08:25 +02:00
|
|
|
|
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Player"/> class.
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player">The player type. Chooses the first available player matching the criteria.</param>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public Player(PlayerType player)
|
|
|
|
|
{
|
|
|
|
|
switch (player)
|
|
|
|
|
{
|
|
|
|
|
case PlayerType.Local:
|
|
|
|
|
this.Id = playerEngine.GetLocalPlayer();
|
|
|
|
|
break;
|
|
|
|
|
case PlayerType.Remote:
|
|
|
|
|
this.Id = playerEngine.GetRemotePlayer();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (this.Id == uint.MaxValue)
|
|
|
|
|
{
|
2020-05-13 16:52:06 -04:00
|
|
|
|
throw new PlayerNotFoundException($"No player of {player} type exists");
|
2020-05-11 20:30:16 -04:00
|
|
|
|
}
|
|
|
|
|
this.Type = player;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// object fields & properties
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's type.
|
|
|
|
|
/// The player type is always relative to the current client, not the game host.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The enumerated player type.</value>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public PlayerType Type { get; }
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's unique identifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The identifier.</value>
|
2020-06-05 00:20:35 +02:00
|
|
|
|
public uint Id { get; }
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current position.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The position.</value>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public float3 Position
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get => playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().position;
|
|
|
|
|
set => playerEngine.SetLocation(Id, value, false);
|
|
|
|
|
}
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current rotation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The rotation.</value>
|
2020-06-05 00:20:35 +02:00
|
|
|
|
public float3 Rotation
|
2021-05-28 02:12:54 +02:00
|
|
|
|
{
|
|
|
|
|
get => ((Quaternion) (GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCameraStruct<CameraEntityStruct>(Id).Get().rotation
|
2021-05-28 02:12:54 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().rotation)).eulerAngles;
|
|
|
|
|
set => _ = GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCameraStruct<CameraEntityStruct>(Id).Get().rotation = quaternion.Euler(value)
|
2021-05-28 02:12:54 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().rotation = quaternion.Euler(value);
|
|
|
|
|
}
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current velocity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The velocity.</value>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public float3 Velocity
|
2021-05-28 02:12:54 +02:00
|
|
|
|
{
|
|
|
|
|
get => playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().velocity;
|
|
|
|
|
set => playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().velocity = value;
|
|
|
|
|
}
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current angular velocity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The angular velocity.</value>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public float3 AngularVelocity
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get => playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().angularVelocity;
|
|
|
|
|
set => playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's mass.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The mass.</value>
|
2021-05-28 02:12:54 +02:00
|
|
|
|
public float Mass =>
|
|
|
|
|
1f / playerEngine.GetCharacterStruct<RigidBodyEntityStruct>(Id).Get().physicsMass.InverseMass;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
private float _ping = -1f;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's latest network ping time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The ping (s).</value>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public float Ping
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
var opt = playerEngine.GetPlayerStruct<PlayerNetworkStatsEntityStruct>(Id, Type);
|
|
|
|
|
if (opt)
|
2020-05-11 20:30:16 -04:00
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
_ping = opt.Get().lastPingTimeSinceLevelLoad ?? _ping;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
}
|
|
|
|
|
return _ping;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 21:30:24 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's initial health when entering Simulation (aka Time Running) mode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The initial health.</value>
|
|
|
|
|
public float InitialHealth
|
2021-05-28 02:12:54 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var opt = playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id);
|
|
|
|
|
return opt ? opt.Get().initialHealth : -1f;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
set => playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id).Get().initialHealth = value;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current health in Simulation (aka Time Running) mode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The current health.</value>
|
|
|
|
|
public float CurrentHealth
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var opt = playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id);
|
|
|
|
|
return opt ? opt.Get().currentHealth : -1f;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
set => playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id).Get().currentHealth = value;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-05-02 01:08:25 +02:00
|
|
|
|
/// Whether this <see cref="T:TechbloxModdingAPI.Player"/> is damageable.
|
2020-05-29 21:30:24 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if damageable; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool Damageable
|
2021-05-28 02:12:54 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var opt = playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id);
|
|
|
|
|
return opt.Get().canTakeDamageStat;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref var healthStruct = ref playerEngine.GetCharacterStruct<CharacterHealthEntityStruct>(Id).Get();
|
|
|
|
|
healthStruct.canTakeDamage = value;
|
|
|
|
|
healthStruct.canTakeDamageStat = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's lives when initially entering Simulation (aka Time Running) mode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The initial lives.</value>
|
|
|
|
|
public uint InitialLives
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var opt = playerEngine.GetCharacterStruct<CharacterLivesEntityComponent>(Id);
|
|
|
|
|
return opt ? opt.Get().initialLives : uint.MaxValue;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
set => playerEngine.GetCharacterStruct<CharacterLivesEntityComponent>(Id).Get().initialLives = value;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's current lives in Simulation (aka Time Running) mode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The current lives.</value>
|
|
|
|
|
public uint CurrentLives
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var opt = playerEngine.GetCharacterStruct<CharacterLivesEntityComponent>(Id);
|
|
|
|
|
return opt ? opt.Get().currentLives : uint.MaxValue;
|
|
|
|
|
}
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
set => playerEngine.GetCharacterStruct<CharacterLivesEntityComponent>(Id).Get().currentLives = value;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 02:12:54 +02:00
|
|
|
|
/*/// <summary>
|
2020-05-29 21:30:24 -04:00
|
|
|
|
/// Whether the Game Over screen is displayed for the player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if game over; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool GameOver
|
|
|
|
|
{
|
|
|
|
|
get => playerEngine.GetGameOverScreen(Id);
|
2021-05-28 02:12:54 +02:00
|
|
|
|
}*/
|
2020-05-29 21:30:24 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the player is dead.
|
|
|
|
|
/// If <c>true</c>, hopefully it was quick.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if dead; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool Dead
|
|
|
|
|
{
|
|
|
|
|
get => playerEngine.IsDead(Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's selected block ID in their hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The selected block.</value>
|
|
|
|
|
public BlockIDs SelectedBlock
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
var optstruct = playerEngine.GetCharacterStruct<EquippedPartStruct>(Id);
|
|
|
|
|
return optstruct ? (BlockIDs) optstruct.Get().SelectedDBPartID : BlockIDs.Invalid;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's selected block color in their hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The selected block's color.</value>
|
2020-06-05 00:20:35 +02:00
|
|
|
|
public BlockColor SelectedColor
|
2020-05-29 21:30:24 -04:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
var optstruct = playerEngine.GetCharacterStruct<EquippedColourStruct>(Id);
|
|
|
|
|
return optstruct ? new BlockColor(optstruct.Get().indexInPalette) : BlockColors.Default;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's selected block colour in their hand.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The selected block's colour.</value>
|
2020-06-05 00:20:35 +02:00
|
|
|
|
public BlockColor SelectedColour
|
2020-05-29 21:30:24 -04:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
var optstruct = playerEngine.GetCharacterStruct<EquippedColourStruct>(Id);
|
|
|
|
|
return optstruct ? new BlockColor(optstruct.Get().indexInPalette) : BlockColors.Default;
|
2020-05-29 21:30:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 02:39:58 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's selected blueprint in their hand. Set to null to clear. Dispose after usage.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Blueprint SelectedBlueprint
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var lbiso = playerEngine.GetPlayerStruct<LocalBlueprintInputStruct>(Id, Type);
|
|
|
|
|
return lbiso ? new Blueprint(lbiso.Get().selectedBlueprintId) : null;
|
|
|
|
|
}
|
2020-11-12 02:39:58 +01:00
|
|
|
|
set => BlockGroup._engine.SelectBlueprint(value?.Id ?? uint.MaxValue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 02:52:16 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player's mode in time stopped mode, determining what they place.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PlayerBuildingMode BuildingMode => (PlayerBuildingMode) playerEngine
|
2021-06-09 20:11:31 +02:00
|
|
|
|
.GetCharacterStruct<TimeStoppedModeComponent>(Id).Get().timeStoppedContext;
|
2020-11-14 02:52:16 +01:00
|
|
|
|
|
2021-05-28 02:52:42 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the player is sprinting.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Sprinting
|
|
|
|
|
{
|
|
|
|
|
get => GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementComponent>(Id).Get().sprinting
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementEntityStruct>(Id).Get().isSprinting;
|
|
|
|
|
set => _ = GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementComponent>(Id).Get().sprinting = value
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementEntityStruct>(Id).Get().isSprinting = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Movement speed setting. Build mode (camera) and simulation mode settings are separate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float SpeedSetting
|
|
|
|
|
{
|
|
|
|
|
get => GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().speed
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().moveSpeed;
|
|
|
|
|
set => _ = GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().speed = value
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().moveSpeed = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The multiplier setting to use when sprinting. Build mode (camera) and simulation mode settings are separate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float SpeedSprintMultiplierSetting
|
|
|
|
|
{
|
|
|
|
|
get => GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().speedSprintMultiplier
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().sprintSpeedMultiplier;
|
|
|
|
|
set => _ = GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().speedSprintMultiplier = value
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().sprintSpeedMultiplier = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The acceleration setting of the player. Build mode (camera) and simulation mode settings are separate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float AccelerationSetting
|
|
|
|
|
{
|
|
|
|
|
get => GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().acceleration
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().acceleration;
|
|
|
|
|
set => _ = GameState.IsBuildMode()
|
2021-06-09 20:11:31 +02:00
|
|
|
|
? playerEngine.GetCharacterStruct<BuildingDroneMovementSettingsComponent>(Id).Get().acceleration = value
|
2021-05-28 02:52:42 +02:00
|
|
|
|
: playerEngine.GetCharacterStruct<CharacterMovementSettingsEntityStruct>(Id).Get().acceleration = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 02:52:16 +01:00
|
|
|
|
// object methods
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-05-12 17:08:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Teleport the player to the specified coordinates.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">The x coordinate.</param>
|
|
|
|
|
/// <param name="y">The y coordinate.</param>
|
|
|
|
|
/// <param name="z">The z coordinate.</param>
|
|
|
|
|
/// <param name="relative">If set to <c>true</c> teleport relative to the player's current position.</param>
|
|
|
|
|
/// <param name="exitSeat">If set to <c>true</c> exit any seat the player is in.</param>
|
2020-05-11 20:30:16 -04:00
|
|
|
|
public void Teleport(float x, float y, float z, bool relative = true, bool exitSeat = true)
|
|
|
|
|
{
|
|
|
|
|
float3 location = new float3(x, y, z);
|
|
|
|
|
if (relative)
|
|
|
|
|
{
|
2021-05-28 02:12:54 +02:00
|
|
|
|
location += Position;
|
2020-05-11 20:30:16 -04:00
|
|
|
|
}
|
|
|
|
|
playerEngine.SetLocation(Id, location, exitSeat: exitSeat);
|
|
|
|
|
}
|
2020-05-13 14:02:36 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-06-04 01:42:13 +02:00
|
|
|
|
/// Returns the block the player is currently looking at in build mode.
|
2020-05-13 14:02:36 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
|
2020-05-23 00:06:49 +02:00
|
|
|
|
/// <returns>The block or null if not found</returns>
|
2020-05-13 14:02:36 +02:00
|
|
|
|
public Block GetBlockLookedAt(float maxDistance = -1f)
|
|
|
|
|
{
|
2020-05-23 00:06:49 +02:00
|
|
|
|
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
|
2021-05-03 01:25:26 +02:00
|
|
|
|
return egid != EGID.Empty && egid.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP
|
2021-05-19 01:40:15 +02:00
|
|
|
|
? Block.New(egid)
|
2020-05-23 00:06:49 +02:00
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the rigid body the player is currently looking at during simulation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
|
2021-05-28 02:12:54 +02:00
|
|
|
|
/// <returns>The body or null if not found</returns>
|
2020-05-23 00:06:49 +02:00
|
|
|
|
public SimBody GetSimBodyLookedAt(float maxDistance = -1f)
|
|
|
|
|
{
|
|
|
|
|
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
|
2021-05-03 01:25:26 +02:00
|
|
|
|
return egid != EGID.Empty && egid.groupID == CommonExclusiveGroups.SIMULATION_BODIES_GROUP
|
|
|
|
|
? new SimBody(egid)
|
2020-05-23 00:06:49 +02:00
|
|
|
|
: null;
|
2020-05-13 14:02:36 +02:00
|
|
|
|
}
|
2020-05-11 20:30:16 -04:00
|
|
|
|
|
2020-06-08 00:10:10 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the blocks that are in the player's current selection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An array of blocks or an empty array</returns>
|
|
|
|
|
public Block[] GetSelectedBlocks()
|
|
|
|
|
{
|
|
|
|
|
return playerEngine.GetSelectedBlocks(Id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 00:20:35 +02:00
|
|
|
|
public bool Equals(Player other)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(null, other)) return false;
|
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
|
return Id == other.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Equals(EGID other)
|
|
|
|
|
{
|
|
|
|
|
return Id == other.entityID && other.groupID == (Type == PlayerType.Local
|
|
|
|
|
? PlayersExclusiveGroups.LocalPlayers
|
|
|
|
|
: PlayersExclusiveGroups.RemotePlayers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
|
|
|
if (obj.GetType() != this.GetType()) return false;
|
|
|
|
|
return Equals((Player) obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return (int) Id;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 20:30:16 -04:00
|
|
|
|
// internal methods
|
|
|
|
|
|
2020-07-01 13:43:56 -04:00
|
|
|
|
internal static void Init()
|
2020-05-11 20:30:16 -04:00
|
|
|
|
{
|
|
|
|
|
Utility.GameEngineManager.AddGameEngine(playerEngine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|