TechbloxModdingAPI/TechbloxModdingAPI/Cluster.cs

77 lines
2.4 KiB
C#

using Gamecraft.Damage;
using RobocraftX.Common;
using Svelto.ECS;
using Techblox.Physics;
namespace TechbloxModdingAPI
{
/// <summary>
/// Represnts a cluster of blocks in time running mode, meaning blocks that are connected either directly or via joints.
/// Only exists if a cluster destruction manager is present. Static blocks like grass and dirt aren't part of a cluster.
/// </summary>
public class Cluster : EcsObjectBase
{
public Cluster(EGID id) : base(id)
{
}
public Cluster(uint id) : this(new EGID(id, CommonExclusiveGroups.SIMULATION_CLUSTERS_GROUP))
{
}
public float InitialHealth
{
get => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).initialHealth;
set => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).initialHealth = value;
}
public float CurrentHealth
{
get => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).currentHealth;
set => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).currentHealth = value;
}
public float HealthMultiplier
{
get => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).healthMultiplier;
set => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).healthMultiplier = value;
}
/// <summary>
/// The mass of the cluster.
/// </summary>
public float Mass => Block.BlockEngine.GetBlockInfo<ClusterMassComponent>(this).mass;
/// <summary>
/// Returns the simulation-time rigid bodies for the chunks in this cluster.
/// </summary>
/// <returns>An array of sim-bodies</returns>
public SimBody[] GetSimBodies()
{
return Block.BlockEngine.GetClusterBodies(Id.entityID);
}
public override string ToString()
{
return $"{nameof(Id)}: {Id}";
}
protected bool Equals(Cluster other)
{
return Id.Equals(other.Id);
}
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((Cluster) obj);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}