|
|
@@ -6,18 +6,20 @@ using RobocraftX.Character.Movement; |
|
|
|
using RobocraftX.Common.Players; |
|
|
|
using RobocraftX.Common.Input; |
|
|
|
using RobocraftX.Physics; |
|
|
|
using RobocraftX.Blocks.Ghost; |
|
|
|
using RobocraftX.Character.Camera; |
|
|
|
using RobocraftX.Character.Factories; |
|
|
|
using Gamecraft.CharacterVulnerability; |
|
|
|
using Gamecraft.CharacterVulnerability.Entities; |
|
|
|
using Svelto.ECS; |
|
|
|
using Unity.Mathematics; |
|
|
|
using Unity.Physics; |
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines; |
|
|
|
using RobocraftX.Blocks.Ghost; |
|
|
|
using RobocraftX.Character.Camera; |
|
|
|
using RobocraftX.Character.Factories; |
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Players |
|
|
|
{ |
|
|
|
internal class PlayerEngine : IApiEngine |
|
|
|
internal class PlayerEngine : IApiEngine, IFactoryEngine |
|
|
|
{ |
|
|
|
public string Name { get; } = "GamecraftModdingAPIPlayerGameEngine"; |
|
|
|
|
|
|
@@ -25,6 +27,8 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public bool isRemovable => false; |
|
|
|
|
|
|
|
public IEntityFactory Factory { set; private get; } |
|
|
|
|
|
|
|
private bool isReady = false; |
|
|
|
|
|
|
|
public void Dispose() |
|
|
@@ -188,7 +192,7 @@ namespace GamecraftModdingAPI.Players |
|
|
|
|
|
|
|
public float? GetLastPingTime(uint playerId, PlayerType type) |
|
|
|
{ |
|
|
|
EGID egid = new EGID(playerId, GroupFromEnum(type)); |
|
|
|
EGID egid = new EGID(playerId, PlayerGroupFromEnum(type)); |
|
|
|
if (entitiesDB.Exists<PlayerNetworkStatsEntityStruct>(egid)) |
|
|
|
{ |
|
|
|
return entitiesDB.QueryEntity<PlayerNetworkStatsEntityStruct>(egid).lastPingTimeSinceLevelLoad; |
|
|
@@ -196,10 +200,150 @@ namespace GamecraftModdingAPI.Players |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public float GetInitialHealth(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
{ |
|
|
|
return c.initialHealth; |
|
|
|
} |
|
|
|
return -1f; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetInitialHealth(uint playerId, float val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
{ |
|
|
|
c.initialHealth = val; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public float GetCurrentHealth(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
{ |
|
|
|
return c.currentHealth; |
|
|
|
} |
|
|
|
return -1f; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetCurrentHealth(uint playerId, float val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
{ |
|
|
|
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) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct c)) |
|
|
|
{ |
|
|
|
return c.canTakeDamageStat; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetDamageable(uint playerId, bool val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterHealthEntityStruct>(playerId, out CharacterHealthEntityStruct ches)) |
|
|
|
{ |
|
|
|
ches.canTakeDamage = val; |
|
|
|
ches.canTakeDamage = val; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public uint GetInitialLives(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
{ |
|
|
|
return c.initialLives; |
|
|
|
} |
|
|
|
return uint.MaxValue; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetInitialLives(uint playerId, uint val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
{ |
|
|
|
c.initialLives = val; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public uint GetCurrentLives(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
{ |
|
|
|
return c.currentLives; |
|
|
|
} |
|
|
|
return uint.MaxValue; |
|
|
|
} |
|
|
|
|
|
|
|
public bool SetCurrentLives(uint playerId, uint val) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
{ |
|
|
|
c.currentLives = val; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public bool GetGameOverScreen(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<CharacterLivesEntityComponent>(playerId, out CharacterLivesEntityComponent c)) |
|
|
|
{ |
|
|
|
return c.gameOverScreen; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public bool IsDead(uint playerId) |
|
|
|
{ |
|
|
|
return entitiesDB.Exists<RigidBodyEntityStruct>(playerId, CharacterExclusiveGroups.DeadGroup); |
|
|
|
} |
|
|
|
|
|
|
|
public int GetSelectedBlock(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<EquippedPartStruct>(playerId, out EquippedPartStruct c)) |
|
|
|
{ |
|
|
|
return c.SelectedDBPartID; |
|
|
|
} |
|
|
|
return ushort.MaxValue; |
|
|
|
} |
|
|
|
|
|
|
|
public byte GetSelectedColor(uint playerId) |
|
|
|
{ |
|
|
|
if (GetCharacterStruct<EquippedColourStruct>(playerId, out EquippedColourStruct c)) |
|
|
|
{ |
|
|
|
return c.indexInPalette; |
|
|
|
} |
|
|
|
return 255; |
|
|
|
} |
|
|
|
|
|
|
|
// reusable methods |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
private ExclusiveGroup GroupFromEnum(PlayerType type) |
|
|
|
private ExclusiveGroup PlayerGroupFromEnum(PlayerType type) |
|
|
|
{ |
|
|
|
return type == PlayerType.Local ? PlayersExclusiveGroups.LocalPlayers : PlayersExclusiveGroups.RemotePlayers; |
|
|
|
} |
|
|
|