2020-05-12 00:30:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
|
|
|
|
using RobocraftX.Character.Camera;
|
|
|
|
|
using RobocraftX.Character.Factories;
|
|
|
|
|
using Gamecraft.CharacterVulnerability;
|
|
|
|
|
using Gamecraft.CharacterVulnerability.Entities;
|
2020-05-12 00:30:16 +00:00
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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-06-12 15:27:36 +00:00
|
|
|
|
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers);
|
|
|
|
|
if (localPlayers.count > 0)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return localPlayers[0].ID.entityID;
|
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint GetRemotePlayer()
|
|
|
|
|
{
|
|
|
|
|
if (!isReady) return uint.MaxValue;
|
2020-06-12 15:27:36 +00:00
|
|
|
|
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers);
|
|
|
|
|
if (localPlayers.count > 0)
|
2020-05-12 00:30:16 +00:00
|
|
|
|
{
|
|
|
|
|
return localPlayers[0].ID.entityID;
|
|
|
|
|
}
|
|
|
|
|
return uint.MaxValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsById(uint playerId)
|
|
|
|
|
{
|
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-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-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-06-04 22:20:35 +00:00
|
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists);
|
|
|
|
|
if (exists)
|
|
|
|
|
{
|
|
|
|
|
return ((Quaternion) rbes.rotation).eulerAngles;
|
|
|
|
|
}
|
|
|
|
|
return default;
|
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-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-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-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-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-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-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;
|
|
|
|
|
}
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetInverseMass(uint playerId, float inverseMass)
|
|
|
|
|
{
|
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-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))
|
|
|
|
|
{
|
|
|
|
|
return entitiesDB.QueryEntity<PlayerNetworkStatsEntityStruct>(egid).lastPingTimeSinceLevelLoad;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-30 01:30:24 +00:00
|
|
|
|
public float GetInitialHealth(uint playerId)
|
|
|
|
|
{
|
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-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-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-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)
|
|
|
|
|
{
|
|
|
|
|
Factory.BuildEntity<DamageEntityDescriptor>(
|
|
|
|
|
new EGID(CharacterVulnerabilityExclusiveGroups.NextDamageEntityId, CharacterVulnerabilityExclusiveGroups.CharacterDamageExclusiveGroup)
|
|
|
|
|
).Init(new DamageEntityStruct
|
|
|
|
|
{
|
|
|
|
|
damage = amount,
|
|
|
|
|
targetPlayerEntityId = playerId,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetDamageable(uint playerId)
|
|
|
|
|
{
|
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-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-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-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-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-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-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.gameOverScreen;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDead(uint playerId)
|
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
|
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-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
|
|
|
|
}
|
|
|
|
|
}
|