2020-05-12 00:30:16 +00:00
|
|
|
|
using System;
|
2020-08-13 14:12:36 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
using RobocraftX.Character;
|
|
|
|
|
using RobocraftX.Character.Movement;
|
|
|
|
|
using RobocraftX.Common.Players;
|
|
|
|
|
using RobocraftX.Common.Input;
|
2020-06-07 22:10:10 +00:00
|
|
|
|
using RobocraftX.CR.MachineEditing.BoxSelect;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
using RobocraftX.Physics;
|
2020-05-30 01:30:24 +00:00
|
|
|
|
using RobocraftX.Blocks.Ghost;
|
2020-08-13 14:12:36 +00:00
|
|
|
|
using Gamecraft.GUI.HUDFeedbackBlocks;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
using Svelto.ECS;
|
2021-04-10 00:02:47 +00:00
|
|
|
|
using Techblox.Camera;
|
|
|
|
|
using Techblox.FlyCam;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using Unity.Physics;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
using UnityEngine;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines;
|
2020-08-13 14:12:36 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using Svelto.ECS.DataStructures;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Players
|
|
|
|
|
{
|
2020-05-30 01:30:24 +00:00
|
|
|
|
internal class PlayerEngine : IApiEngine, IFactoryEngine
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIPlayerGameEngine";
|
|
|
|
|
|
|
|
|
|
public EntitiesDB entitiesDB { set; private get; }
|
|
|
|
|
|
|
|
|
|
public bool isRemovable => false;
|
|
|
|
|
|
2020-05-30 01:30:24 +00:00
|
|
|
|
public IEntityFactory Factory { set; private get; }
|
|
|
|
|
|
2020-05-12 00:30:16 +00:00
|
|
|
|
private bool isReady = false;
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
isReady = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
|
{
|
|
|
|
|
isReady = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetLocalPlayer()
|
|
|
|
|
{
|
|
|
|
|
if (!isReady) return uint.MaxValue;
|
2020-11-09 21:18:25 +00:00
|
|
|
|
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers).ToBuffer();
|
2020-06-12 15:27:36 +00:00
|
|
|
|
if (localPlayers.count > 0)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
return localPlayers.buffer[0].ID.entityID;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetRemotePlayer()
|
|
|
|
|
{
|
|
|
|
|
if (!isReady) return uint.MaxValue;
|
2020-11-09 21:18:25 +00:00
|
|
|
|
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers).ToBuffer();
|
2020-06-12 15:27:36 +00:00
|
|
|
|
if (localPlayers.count > 0)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
return localPlayers.buffer[0].ID.entityID;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public long GetAllPlayerCount()
|
2020-06-23 17:49:42 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-07-10 22:30:58 +00:00
|
|
|
|
long count = 0;
|
2020-06-23 17:49:42 +00:00
|
|
|
|
foreach (ExclusiveGroupStruct eg in PlayersExclusiveGroups.AllPlayers)
|
|
|
|
|
{
|
|
|
|
|
count += entitiesDB.Count<PlayerIDStruct>(eg);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public long GetLocalPlayerCount()
|
2020-06-23 17:49:42 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-23 17:49:42 +00:00
|
|
|
|
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public long GetRemotePlayerCount()
|
2020-06-23 17:49:42 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-23 17:49:42 +00:00
|
|
|
|
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 00:30:16 +00:00
|
|
|
|
public bool ExistsById(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
return entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.LocalPlayers)
|
|
|
|
|
|| entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.RemotePlayers);
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float3 GetLocation(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return float3.zero;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return rbes.position;
|
|
|
|
|
}
|
|
|
|
|
return float3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetLocation(uint playerId, float3 location, bool exitSeat = true)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-12 15:27:36 +00:00
|
|
|
|
var characterGroups = CharacterExclusiveGroups.AllCharacters;
|
|
|
|
|
for (int i = 0; i < characterGroups.count; i++)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
EGID egid = new EGID(playerId, characterGroups[i]);
|
|
|
|
|
if (entitiesDB.Exists<RigidBodyEntityStruct>(egid))
|
|
|
|
|
{
|
|
|
|
|
ref RigidBodyEntityStruct rbes = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(egid);
|
|
|
|
|
if (characterGroups[i] == CharacterExclusiveGroups.InPilotSeatGroup && exitSeat)
|
|
|
|
|
{
|
|
|
|
|
entitiesDB.QueryEntity<CharacterPilotSeatEntityStruct>(egid).instantExit = true;
|
|
|
|
|
entitiesDB.PublishEntityChange<CharacterPilotSeatEntityStruct>(egid);
|
|
|
|
|
}
|
|
|
|
|
rbes.position = location;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 22:20:35 +00:00
|
|
|
|
public float3 GetRotation(uint playerId)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return float3.zero;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
|
|
|
|
{
|
|
|
|
|
return ((Quaternion) rbes.rotation).eulerAngles;
|
|
|
|
|
}
|
2020-06-23 17:49:42 +00:00
|
|
|
|
return default(float3);
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 22:20:35 +00:00
|
|
|
|
public bool SetRotation(uint playerId, float3 value)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-06-04 22:20:35 +00:00
|
|
|
|
Quaternion q = rbes.rotation;
|
|
|
|
|
q.eulerAngles = value;
|
|
|
|
|
rbes.rotation = q;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float3 GetLinearVelocity(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return float3.zero;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return rbes.velocity;
|
|
|
|
|
}
|
|
|
|
|
return float3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetLinearVelocity(uint playerId, float3 value)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
rbes.velocity = value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float3 GetAngularVelocity(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return float3.zero;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return rbes.angularVelocity;
|
|
|
|
|
}
|
|
|
|
|
return float3.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetAngularVelocity(uint playerId, float3 value)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
rbes.angularVelocity = value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PhysicsMass GetMass(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return default(PhysicsMass);
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return rbes.physicsMass;
|
|
|
|
|
}
|
2020-06-23 17:49:42 +00:00
|
|
|
|
return default(PhysicsMass);
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetInverseMass(uint playerId, float inverseMass)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
rbes.physicsMass.InverseInertia = inverseMass;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float? GetLastPingTime(uint playerId, PlayerType type)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return null;
|
2020-05-30 01:30:24 +00:00
|
|
|
|
EGID egid = new EGID(playerId, PlayerGroupFromEnum(type));
|
2020-05-12 00:30:16 +00:00
|
|
|
|
if (entitiesDB.Exists<PlayerNetworkStatsEntityStruct>(egid))
|
|
|
|
|
{
|
2021-04-11 00:36:00 +00:00
|
|
|
|
//return entitiesDB.QueryEntity<PlayerNetworkStatsEntityStruct>(egid).lastPingTimeSinceLevelLoad; - TODO
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-30 01:30:24 +00:00
|
|
|
|
public float GetInitialHealth(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.initialHealth;
|
|
|
|
|
}
|
|
|
|
|
return -1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetInitialHealth(uint playerId, float val)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
c.initialHealth = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetCurrentHealth(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.currentHealth;
|
|
|
|
|
}
|
|
|
|
|
return -1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetCurrentHealth(uint playerId, float val)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
c.currentHealth = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DamagePlayer(uint playerId, float amount)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-08-07 17:55:00 +00:00
|
|
|
|
return SetCurrentHealth(playerId, GetCurrentHealth(playerId) - amount);
|
2020-05-30 01:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetDamageable(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.canTakeDamageStat;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetDamageable(uint playerId, bool val)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var ches = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
ches.canTakeDamage = val;
|
|
|
|
|
ches.canTakeDamage = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetInitialLives(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.initialLives;
|
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetInitialLives(uint playerId, uint val)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
c.initialLives = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetCurrentLives(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.currentLives;
|
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetCurrentLives(uint playerId, uint val)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
c.currentLives = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetGameOverScreen(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return false;
|
2020-08-13 14:12:36 +00:00
|
|
|
|
ref HudActivatedBlocksEntityStruct habes = ref entitiesDB.QueryEntity<HudActivatedBlocksEntityStruct>(HUDFeedbackBlocksGUIExclusiveGroups.GameOverHudEgid);
|
|
|
|
|
NativeDynamicArrayCast<EGID> nativeDynamicArrayCast = new NativeDynamicArrayCast<EGID>(habes.activatedBlocksOrdered);
|
|
|
|
|
return nativeDynamicArrayCast.count > 0;
|
2020-05-30 01:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 14:12:36 +00:00
|
|
|
|
public bool IsDead(uint playerId)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return true;
|
2020-06-12 15:27:36 +00:00
|
|
|
|
return entitiesDB.Exists<RigidBodyEntityStruct>(playerId, CharacterExclusiveGroups.DeadCharacters);
|
2020-05-30 01:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetSelectedBlock(uint playerId)
|
2020-06-04 22:20:35 +00:00
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<EquippedPartStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.SelectedDBPartID;
|
|
|
|
|
}
|
|
|
|
|
return ushort.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte GetSelectedColor(uint playerId)
|
|
|
|
|
{
|
2020-07-01 17:43:56 +00:00
|
|
|
|
if (entitiesDB == null) return 0;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
ref var c = ref GetCharacterStruct<EquippedColourStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
2020-05-30 01:30:24 +00:00
|
|
|
|
{
|
|
|
|
|
return c.indexInPalette;
|
|
|
|
|
}
|
|
|
|
|
return 255;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 00:30:16 +00:00
|
|
|
|
// reusable methods
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2020-05-30 01:30:24 +00:00
|
|
|
|
private ExclusiveGroup PlayerGroupFromEnum(PlayerType type)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return type == PlayerType.Local ? PlayersExclusiveGroups.LocalPlayers : PlayersExclusiveGroups.RemotePlayers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2020-06-04 22:20:35 +00:00
|
|
|
|
public ref T GetCharacterStruct<T>(uint playerId, out bool exists) where T : unmanaged, IEntityComponent
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
2020-06-12 15:27:36 +00:00
|
|
|
|
var characterGroups = CharacterExclusiveGroups.AllCharacters;
|
|
|
|
|
for (int i = 0; i < characterGroups.count; i++)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
EGID egid = new EGID(playerId, characterGroups[i]);
|
|
|
|
|
if (entitiesDB.Exists<T>(egid))
|
|
|
|
|
{
|
2020-06-04 22:20:35 +00:00
|
|
|
|
exists = true;
|
|
|
|
|
return ref entitiesDB.QueryEntity<T>(egid);
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-04 22:20:35 +00:00
|
|
|
|
|
|
|
|
|
exists = false;
|
|
|
|
|
T[] arr = new T[1];
|
|
|
|
|
return ref arr[0]; //Return default value
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public bool GetPlayerStruct<T>(uint playerId, out T s) where T : unmanaged, IEntityComponent
|
|
|
|
|
{
|
2020-06-12 15:27:36 +00:00
|
|
|
|
var playerGroups = PlayersExclusiveGroups.AllPlayers;
|
|
|
|
|
for (int i = 0; i < playerGroups.count; i++)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
EGID egid = new EGID(playerId, playerGroups[i]);
|
|
|
|
|
if (entitiesDB.Exists<T>(egid))
|
|
|
|
|
{
|
|
|
|
|
s = entitiesDB.QueryEntity<T>(egid);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-06-12 15:27:36 +00:00
|
|
|
|
|
2020-05-22 22:06:49 +00:00
|
|
|
|
public EGID? GetThingLookedAt(uint playerId, float maxDistance = -1f)
|
2020-05-13 12:02:36 +00:00
|
|
|
|
{
|
|
|
|
|
if (!entitiesDB.TryQueryMappedEntities<CharacterCameraRayCastEntityStruct>(
|
|
|
|
|
CameraExclusiveGroups.CameraGroup, out var mapper))
|
|
|
|
|
return null;
|
|
|
|
|
mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
|
|
|
|
|
float distance = maxDistance < 0
|
2020-06-12 15:27:36 +00:00
|
|
|
|
? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast,
|
|
|
|
|
GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize)
|
2020-05-13 12:02:36 +00:00
|
|
|
|
: maxDistance;
|
|
|
|
|
if (rayCast.hit && rayCast.distance <= distance)
|
2020-05-22 22:06:49 +00:00
|
|
|
|
return rayCast.hitEgid;
|
2020-05-13 12:02:36 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-06-07 22:10:10 +00:00
|
|
|
|
|
|
|
|
|
public unsafe Block[] GetSelectedBlocks(uint playerid)
|
|
|
|
|
{
|
|
|
|
|
if (!entitiesDB.Exists<BoxSelectStateEntityStruct>(playerid,
|
|
|
|
|
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup))
|
|
|
|
|
return new Block[0];
|
|
|
|
|
var state = entitiesDB.QueryEntity<BoxSelectStateEntityStruct>(playerid,
|
|
|
|
|
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
|
|
|
|
|
var blocks = entitiesDB.QueryEntity<SelectedBlocksStruct>(playerid,
|
|
|
|
|
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
|
|
|
|
|
if (!state.active) return new Block[0];
|
|
|
|
|
var pointer = (EGID*) blocks.selectedBlocks.ToPointer();
|
|
|
|
|
var ret = new Block[blocks.count];
|
|
|
|
|
for (int j = 0; j < blocks.count; j++)
|
|
|
|
|
{
|
|
|
|
|
var egid = pointer[j];
|
|
|
|
|
ret[j] = new Block(egid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2020-05-12 00:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|