2020-03-22 19:05:26 +00:00
|
|
|
using MessagePack;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public class ReactorData : BehaviorData
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("charge"), Key(1), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Charge = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("capacitance"), Key(2), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Capacitance = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("efficiency"), Key(3), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Efficiency = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("overload"), Key(4), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat OverloadEfficiency = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
[InspectableField, JsonProperty("underload"), Key(5), RuntimeInspectable]
|
|
|
|
|
public PerformanceStat ThrottlingFactor = new PerformanceStat();
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-04-09 10:33:16 +01:00
|
|
|
return new Reactor(context, this, entity, item);
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
public class Reactor : IBehavior
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-04-09 10:33:16 +01:00
|
|
|
private ReactorData _data;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
public Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
public EquippedItem Item { get; }
|
|
|
|
|
public ItemManager Context { get; }
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-05-06 04:56:36 +01:00
|
|
|
public BehaviorData Data => _data;
|
2020-05-26 01:12:06 +01:00
|
|
|
public float Capacitance;
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public Reactor(ItemManager context, ReactorData data, Entity entity, EquippedItem item)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
|
|
|
|
Context = context;
|
|
|
|
|
_data = data;
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity = entity;
|
2020-03-22 19:05:26 +00:00
|
|
|
Item = item;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
public bool Update(float delta)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
Capacitance = Context.Evaluate(_data.Capacitance, Item.EquippableItem, Entity);
|
|
|
|
|
var charge = Context.Evaluate(_data.Charge, Item.EquippableItem, Entity) * delta;
|
|
|
|
|
var efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
Item.Temperature += (charge / efficiency) / Context.GetThermalMass(Item.EquippableItem);
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity.Energy += charge;
|
|
|
|
|
|
2020-05-26 01:12:06 +01:00
|
|
|
if (Entity.Energy > Capacitance)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
Item.Temperature -= (Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item.EquippableItem, Entity)) / Context.GetThermalMass(Item.EquippableItem);
|
2020-05-26 01:12:06 +01:00
|
|
|
Entity.Energy = Capacitance;
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
if (Entity.Energy < 0)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
Item.Temperature += -Entity.Energy / Context.Evaluate(_data.OverloadEfficiency, Item.EquippableItem, Entity) / Context.GetThermalMass(Item.EquippableItem);
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity.Energy = 0;
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-03-22 19:05:26 +00:00
|
|
|
}
|