Aetheria/Assets/Scripts/ServerShared/Behaviors/Turning.cs
hyperion51 43f33546a3 Inventory Refactoring
Massively refactored everything related to entity inventory management
We are no longer recalculating mass by iterating over the entire inventory any time anything changes, for example
Gear is explicitly associated with hardpoints in the entity code
This did introduce some bugs, will clean those up tomorrow
2020-06-05 04:16:33 +01:00

68 lines
No EOL
1.9 KiB
C#

using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class TurningData : BehaviorData
{
[InspectableField, JsonProperty("torque"), Key(1), RuntimeInspectable]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(2)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(3)]
public PerformanceStat Heat = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Turning(context, this, entity, item);
}
}
public class Turning : IAnalogBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public float Torque { get; private set; }
public float Axis
{
get => _input;
set => _input = clamp(value, -1, 1);
}
public BehaviorData Data => _data;
private TurningData _data;
private float _input;
public Turning(GameContext context, TurningData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public bool Update(float delta)
{
Torque = Context.Evaluate(_data.Torque, Item, Entity);
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque / Entity.Mass * delta));
Entity.AddHeat(abs(_input) * Context.Evaluate(_data.Heat, Item, Entity) * delta);
Entity.VisibilitySources[this] = abs(_input) * Context.Evaluate(_data.Visibility, Item, Entity);
return true;
}
public void Remove()
{
}
}