|
|
@@ -14,6 +14,7 @@ using Gamecraft.CharacterVulnerability.Entities; |
|
|
|
using Svelto.ECS; |
|
|
|
using Unity.Mathematics; |
|
|
|
using Unity.Physics; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines; |
|
|
|
|
|
|
@@ -65,28 +66,14 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool ExistsById(uint playerId) |
|
|
|
{ |
|
|
|
PlayerIDStruct[] players = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers).ToFastAccess(out uint count); |
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
if (players[i].ID.entityID == playerId) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
players = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers).ToFastAccess(out count); |
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
if (players[i].ID.entityID == playerId) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.LocalPlayers) |
|
|
|
|| entitiesDB.Exists<PlayerIDStruct>(playerId, PlayersExclusiveGroups.RemotePlayers); |
|
|
|
} |
|
|
|
|
|
|
|
public float3 GetLocation(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return rbes.position; |
|
|
|
} |
|
|
@@ -114,20 +101,24 @@ namespace GamecraftModdingAPI.Players |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public quaternion GetRotation(uint playerId) |
|
|
|
public float3 GetRotation(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
{ |
|
|
|
return rbes.rotation; |
|
|
|
} |
|
|
|
return quaternion.identity; |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return ((Quaternion) rbes.rotation).eulerAngles; |
|
|
|
} |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetRotation(uint playerId, quaternion value) |
|
|
|
public bool SetRotation(uint playerId, float3 value) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
rbes.rotation = value; |
|
|
|
Quaternion q = rbes.rotation; |
|
|
|
q.eulerAngles = value; |
|
|
|
rbes.rotation = q; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
@@ -135,7 +126,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public float3 GetLinearVelocity(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return rbes.velocity; |
|
|
|
} |
|
|
@@ -144,7 +136,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetLinearVelocity(uint playerId, float3 value) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
rbes.velocity = value; |
|
|
|
return true; |
|
|
@@ -154,7 +147,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public float3 GetAngularVelocity(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return rbes.angularVelocity; |
|
|
|
} |
|
|
@@ -163,7 +157,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetAngularVelocity(uint playerId, float3 value) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
rbes.angularVelocity = value; |
|
|
|
return true; |
|
|
@@ -173,7 +168,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public PhysicsMass GetMass(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return rbes.physicsMass; |
|
|
|
} |
|
|
@@ -182,7 +178,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetInverseMass(uint playerId, float inverseMass) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<RigidBodyEntityStruct>(playerId, out RigidBodyEntityStruct rbes)) |
|
|
|
ref var rbes = ref GetCharacterStruct<RigidBodyEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
rbes.physicsMass.InverseInertia = inverseMass; |
|
|
|
return true; |
|
|
@@ -202,7 +199,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public float GetInitialHealth(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.initialHealth; |
|
|
|
} |
|
|
@@ -211,7 +209,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetInitialHealth(uint playerId, float val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
c.initialHealth = val; |
|
|
|
return true; |
|
|
@@ -221,7 +220,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public float GetCurrentHealth(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.currentHealth; |
|
|
|
} |
|
|
@@ -230,7 +230,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetCurrentHealth(uint playerId, float val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
c.currentHealth = val; |
|
|
|
return true; |
|
|
@@ -252,7 +253,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool GetDamageable(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.canTakeDamageStat; |
|
|
|
} |
|
|
@@ -261,7 +263,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetDamageable(uint playerId, bool val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct ches)) |
|
|
|
ref var ches = ref GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
ches.canTakeDamage = val; |
|
|
|
ches.canTakeDamage = val; |
|
|
@@ -272,7 +275,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public uint GetInitialLives(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.initialLives; |
|
|
|
} |
|
|
@@ -281,7 +285,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetInitialLives(uint playerId, uint val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
c.initialLives = val; |
|
|
|
return true; |
|
|
@@ -291,7 +296,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public uint GetCurrentLives(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.currentLives; |
|
|
|
} |
|
|
@@ -300,7 +306,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool SetCurrentLives(uint playerId, uint val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
c.currentLives = val; |
|
|
|
return true; |
|
|
@@ -310,7 +317,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool GetGameOverScreen(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
ref var c = ref GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.gameOverScreen; |
|
|
|
} |
|
|
@@ -323,8 +331,9 @@ namespace GamecraftModdingAPI.Players |
|
|
|
} |
|
|
|
|
|
|
|
public int GetSelectedBlock(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<EquippedPartStruct>(playerId, out EquippedPartStruct c)) |
|
|
|
{ |
|
|
|
ref var c = ref GetCharacterStruct<EquippedPartStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.SelectedDBPartID; |
|
|
|
} |
|
|
@@ -333,7 +342,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public byte GetSelectedColor(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<EquippedColourStruct>(playerId, out EquippedColourStruct c)) |
|
|
|
ref var c = ref GetCharacterStruct<EquippedColourStruct>(playerId, out bool exists); |
|
|
|
if (exists) |
|
|
|
{ |
|
|
|
return c.indexInPalette; |
|
|
|
} |
|
|
@@ -349,7 +359,7 @@ namespace GamecraftModdingAPI.Players |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public bool GetCharacterStruct<T>(uint playerId, out T s) where T : unmanaged, IEntityComponent |
|
|
|
public ref T GetCharacterStruct<T>(uint playerId, out bool exists) where T : unmanaged, IEntityComponent |
|
|
|
{ |
|
|
|
ExclusiveGroup[] characterGroups = CharacterExclusiveGroups.AllCharacters; |
|
|
|
for (int i = 0; i < characterGroups.Length; i++) |
|
|
@@ -357,12 +367,14 @@ namespace GamecraftModdingAPI.Players |
|
|
|
EGID egid = new EGID(playerId, characterGroups[i]); |
|
|
|
if (entitiesDB.Exists<T>(egid)) |
|
|
|
{ |
|
|
|
s = entitiesDB.QueryEntity<T>(egid); |
|
|
|
return true; |
|
|
|
exists = true; |
|
|
|
return ref entitiesDB.QueryEntity<T>(egid); |
|
|
|
} |
|
|
|
} |
|
|
|
s = default; |
|
|
|
return false; |
|
|
|
|
|
|
|
exists = false; |
|
|
|
T[] arr = new T[1]; |
|
|
|
return ref arr[0]; //Return default value |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|