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-05-06 04:56:36 +01:00
|
|
|
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear 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-03-22 19:05:26 +00:00
|
|
|
public Gear Item { get; }
|
|
|
|
|
public GameContext Context { get; }
|
|
|
|
|
|
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-04-09 10:33:16 +01:00
|
|
|
public Reactor(GameContext context, ReactorData data, Entity entity, Gear 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-05-26 01:12:06 +01:00
|
|
|
Capacitance = Context.Evaluate(_data.Capacitance, Item, Entity);
|
2020-04-09 10:33:16 +01:00
|
|
|
var charge = Context.Evaluate(_data.Charge, Item, Entity) * delta;
|
|
|
|
|
var efficiency = Context.Evaluate(_data.Efficiency, Item, Entity);
|
2020-03-22 19:05:26 +00:00
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
Entity.AddHeat(charge / efficiency);
|
|
|
|
|
Entity.Energy += charge;
|
|
|
|
|
|
2020-05-26 01:12:06 +01:00
|
|
|
if (Entity.Energy > Capacitance)
|
2020-03-22 19:05:26 +00:00
|
|
|
{
|
2020-05-31 03:10:11 +01:00
|
|
|
Entity.AddHeat(-(Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item, Entity)));
|
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-04-09 10:33:16 +01:00
|
|
|
Entity.AddHeat( -Entity.Energy / Context.Evaluate(_data.OverloadEfficiency, Item, Entity));
|
|
|
|
|
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
|
|
|
}
|