Aetheria/Assets/Scripts/ServerShared/Behaviors/Reactor.cs
hyperion51 698263ce63 Entity Properties & Thermal Regulation
Entities such as colonies and ships can now be clicked on to reveal their properties or context menus
Orbital Colony loadout now has a new item (thermostatic heater) which itself has a new behavior type (Thermotoggle) allowing it to regulate its temperature for more agreeable living conditions
Fixed stat modifiers for hull stats (e.g. Hull Expansion)
Widened property label in DB inspector
2020-05-26 01:12:06 +01:00

69 lines
No EOL
2.1 KiB
C#

using MessagePack;
using Newtonsoft.Json;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ReactorData : BehaviorData
{
[InspectableField, JsonProperty("charge"), Key(1)]
public PerformanceStat Charge = new PerformanceStat();
[InspectableField, JsonProperty("capacitance"), Key(2)]
public PerformanceStat Capacitance = new PerformanceStat();
[InspectableField, JsonProperty("efficiency"), Key(3)]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("overload"), Key(4)]
public PerformanceStat OverloadEfficiency = new PerformanceStat();
[InspectableField, JsonProperty("underload"), Key(5)]
public PerformanceStat UnderloadRecovery = new PerformanceStat();
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Reactor(context, this, entity, item);
}
}
public class Reactor : IBehavior
{
private ReactorData _data;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public BehaviorData Data => _data;
public float Capacitance;
public Reactor(GameContext context, ReactorData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public bool Update(float delta)
{
Capacitance = Context.Evaluate(_data.Capacitance, Item, Entity);
var charge = Context.Evaluate(_data.Charge, Item, Entity) * delta;
var efficiency = Context.Evaluate(_data.Efficiency, Item, Entity);
Entity.AddHeat(charge / efficiency);
Entity.Energy += charge;
if (Entity.Energy > Capacitance)
{
Entity.AddHeat(-(Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Entity)));
Entity.Energy = Capacitance;
}
if (Entity.Energy < 0)
{
Entity.AddHeat( -Entity.Energy / Context.Evaluate(_data.OverloadEfficiency, Item, Entity));
Entity.Energy = 0;
}
return true;
}
}