Thermal Performance Threshold & Thermal Override
Items will switch themselves off below a customizable threshold to avoid damage Player can toggle thermal override to disable safety shutdown Selecting an item allows player to select whether the item will override Clicking on the background of an inventory panel will display general ship settings (including thermal shutdown threshold) Performance Stat evaluation has been moved to EquippedItem, slight performance improvement Item online and active status are now reactive properties Created player settings file to store e.g. shutdown threshold Fixed crash when entering wormhole while enemies are visible
This commit is contained in:
parent
2f088b5590
commit
1092159063
66 changed files with 756 additions and 206 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
|
@ -18,8 +19,7 @@ public class CombatState : BaseState
|
|||
SampleDps();
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
weapon.Item.OnOffline += SampleDps;
|
||||
weapon.Item.OnOnline += SampleDps;
|
||||
weapon.Item.Online.Subscribe(b => SampleDps());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ public class CombatState : BaseState
|
|||
var group = _agent.Ship.TriggerGroups[i];
|
||||
var dps = 0f;
|
||||
foreach (var weapon in group.weapons)
|
||||
if (weapon.Item.Online &&
|
||||
if (weapon.Item.Online.Value &&
|
||||
weapon.MinRange < targetDistance &&
|
||||
targetDistance < weapon.Range &&
|
||||
(weapon is ConstantWeapon ||
|
||||
|
|
@ -134,7 +134,7 @@ public class CombatState : BaseState
|
|||
float dps = 0;
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
if (weapon.Item.Online && weapon.MinRange < range && range < weapon.Range)
|
||||
if (weapon.Item.Online.Value && weapon.MinRange < range && range < weapon.Range)
|
||||
dps += weapon.RangeDamagePerSecond(range);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class Capacitor : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Capacity = Context.Evaluate(_data.Capacity, Item);
|
||||
Efficiency = Context.Evaluate(_data.Efficiency, Item);
|
||||
Capacity = Item.Evaluate(_data.Capacity);
|
||||
Efficiency = Item.Evaluate(_data.Efficiency);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,9 +100,9 @@ public class ChargedWeapon : InstantWeapon
|
|||
protected override void UpdateStats()
|
||||
{
|
||||
base.UpdateStats();
|
||||
ChargeTime = Context.Evaluate(_data.ChargeTime, Item);
|
||||
ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item);
|
||||
ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item);
|
||||
ChargeTime = Item.Evaluate(_data.ChargeTime);
|
||||
ChargeEnergy = Item.Evaluate(_data.ChargeEnergy);
|
||||
ChargeHeat = Item.Evaluate(_data.ChargeHeat);
|
||||
Damage *= lerp(1, _data.ChargeFiringDamageMultiplier, saturate(_charge));
|
||||
Heat *= lerp(1, _data.ChargeFiringHeatMultiplier, saturate(_charge));
|
||||
Spread *= lerp(1, _data.ChargeFiringSpreadMultiplier, saturate(_charge));
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior
|
|||
base.Execute(delta);
|
||||
if (_firing)
|
||||
{
|
||||
if (!Entity.TryConsumeEnergy(Context.Evaluate(_data.Energy, Item) * delta))
|
||||
if (!Entity.TryConsumeEnergy(Item.Evaluate(_data.Energy) * delta))
|
||||
{
|
||||
_firing = false;
|
||||
OnStopFiring?.Invoke();
|
||||
|
|
@ -115,9 +115,9 @@ public class ConstantWeapon : Weapon, IProgressBehavior
|
|||
}
|
||||
}
|
||||
|
||||
Item.EquippableItem.Durability -= Wear * delta;
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item) * delta);
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item);
|
||||
Item.EquippableItem.Durability -= Item.Wear * delta;
|
||||
Item.AddHeat(Item.Evaluate(_data.Heat) * delta);
|
||||
Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,6 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item);
|
||||
_cooldown -= delta / Item.Evaluate(_data.Cooldown);
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,6 @@ public class EnergyDraw : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return Entity.TryConsumeEnergy(Context.Evaluate(_data.EnergyDraw, Item) * (_data.PerSecond ? delta : 1));
|
||||
return Entity.TryConsumeEnergy(Item.Evaluate(_data.EnergyDraw) * (_data.PerSecond ? delta : 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ public class Heat : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item) * (_data.PerSecond ? delta : 1));
|
||||
Item.AddHeat(Item.Evaluate(_data.Heat) * (_data.PerSecond ? delta : 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,9 +92,9 @@ public class InstantWeapon : Weapon, IProgressBehavior
|
|||
protected override void UpdateStats()
|
||||
{
|
||||
base.UpdateStats();
|
||||
BurstCount = Context.Evaluate(_data.Count, Item);
|
||||
BurstTime = Context.Evaluate(_data.BurstTime, Item);
|
||||
Cooldown = Context.Evaluate(_data.Cooldown, Item);
|
||||
BurstCount = Item.Evaluate(_data.Count);
|
||||
BurstTime = Item.Evaluate(_data.BurstTime);
|
||||
Cooldown = Item.Evaluate(_data.Cooldown);
|
||||
|
||||
Damage /= (int) BurstCount;
|
||||
Heat /= (int) BurstCount;
|
||||
|
|
@ -165,7 +165,7 @@ public class InstantWeapon : Weapon, IProgressBehavior
|
|||
_burstRemaining--;
|
||||
_burstTimer -= _burstInterval;
|
||||
OnFire?.Invoke();
|
||||
Item.EquippableItem.Durability -= Wear;
|
||||
Item.EquippableItem.Durability -= Item.Wear;
|
||||
Item.AddHeat(Heat);
|
||||
Entity.VisibilitySources[this] = Visibility;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,11 +71,11 @@ public class LockWeapon : InstantWeapon
|
|||
|
||||
if (Entity.Target.Value != null)
|
||||
{
|
||||
LockSpeed = Context.Evaluate(_data.LockSpeed, Item);
|
||||
SensorImpact = Context.Evaluate(_data.SensorImpact, Item);
|
||||
LockAngle = Context.Evaluate(_data.LockAngle, Item);
|
||||
DirectionImpact = Context.Evaluate(_data.DirectionImpact, Item);
|
||||
Decay = Context.Evaluate(_data.Decay, Item);
|
||||
LockSpeed = Item.Evaluate(_data.LockSpeed);
|
||||
SensorImpact = Item.Evaluate(_data.SensorImpact);
|
||||
LockAngle = Item.Evaluate(_data.LockAngle);
|
||||
DirectionImpact = Item.Evaluate(_data.DirectionImpact);
|
||||
Decay = Item.Evaluate(_data.Decay);
|
||||
|
||||
var degrees = acos(dot(normalize(Entity.Target.Value.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f;
|
||||
if (degrees < LockAngle)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class MiningTool : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item);
|
||||
Range = Item.Evaluate(_data.Range);
|
||||
var belt = Entity.Zone.AsteroidBelts[AsteroidBelt];
|
||||
if (AsteroidBelt != Guid.Empty &&
|
||||
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
|
|
@ -64,9 +64,9 @@ public class MiningTool : IBehavior
|
|||
Entity,
|
||||
AsteroidBelt,
|
||||
Asteroid,
|
||||
Context.Evaluate(_data.DamagePerSecond, Item) * delta,
|
||||
Context.Evaluate(_data.Efficiency, Item),
|
||||
Context.Evaluate(_data.Penetration, Item));
|
||||
Item.Evaluate(_data.DamagePerSecond) * delta,
|
||||
Item.Evaluate(_data.Efficiency),
|
||||
Item.Evaluate(_data.Penetration));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item);
|
||||
WasteHeat = Context.Evaluate(_data.WasteHeat, Item);
|
||||
EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item);
|
||||
PumpedHeat = Item.Evaluate(_data.PumpedHeat);
|
||||
WasteHeat = Item.Evaluate(_data.WasteHeat);
|
||||
EnergyUsage = Item.Evaluate(_data.EnergyUsage);
|
||||
|
||||
var itemTemperature = Item.Temperature;
|
||||
var tempRatio = max(Temperature / itemTemperature, 1);
|
||||
|
|
@ -84,7 +84,7 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item);
|
||||
Emissivity = Item.Evaluate(_data.Emissivity);
|
||||
var rad = pow(Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
Temperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var charge = Context.Evaluate(_data.Charge, Item) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item);
|
||||
var charge = Item.Evaluate(_data.Charge) * delta;
|
||||
var efficiency = Item.Evaluate(_data.Efficiency);
|
||||
|
||||
// This behavior executes last, so any components drawing power have already done so
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
// We have an energy deficit, have to overload the reactor
|
||||
if (Draw > .01f)
|
||||
{
|
||||
var overloadEfficiency = Context.Evaluate(_data.OverloadEfficiency, Item);
|
||||
var overloadEfficiency = Item.Evaluate(_data.OverloadEfficiency);
|
||||
|
||||
// Generate heat using overload efficiency, usually much less efficient!
|
||||
heat += Draw / overloadEfficiency;
|
||||
|
|
@ -120,7 +120,7 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
// We still have an energy surplus, try to throttle the reactor to reduce heat generation
|
||||
if (Draw < -.01f)
|
||||
{
|
||||
heat -= Draw / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item));
|
||||
heat -= Draw / efficiency * (1 - 1 / Item.Evaluate(_data.ThrottlingFactor));
|
||||
Draw = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item);
|
||||
MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item);
|
||||
ScanDuration = Context.Evaluate(_data.ScanDuration, Item);
|
||||
Range = Item.Evaluate(_data.Range);
|
||||
MinimumDensity = Item.Evaluate(_data.MinimumDensity);
|
||||
ScanDuration = Item.Evaluate(_data.ScanDuration);
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ public class Sensor : IBehavior
|
|||
var next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Context.Evaluate(_data.Sensitivity, Item) *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
next *= 1 - Context.GameplaySettings.TargetInfoDecay * delta;
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ public class Shield : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Efficiency = Context.Evaluate(_data.Efficiency, Item);
|
||||
EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item);
|
||||
Efficiency = Item.Evaluate(_data.Efficiency);
|
||||
EnergyUsage = Item.Evaluate(_data.EnergyUsage);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
foreach (var stat in _stats)
|
||||
(_data.Type == StatModifierType.Constant
|
||||
? stat.GetConstantModifiers(Entity)
|
||||
: stat.GetScaleModifiers(Entity))[this] = Context.Evaluate(_data.Modifier, Item);
|
||||
: stat.GetScaleModifiers(Entity))[this] = Item.Evaluate(_data.Modifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,16 +61,16 @@ public class Thruster : IAnalogBehavior
|
|||
var itemCenter = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
|
||||
var toCenter = hullCenter - itemCenter;
|
||||
Torque = -dot(normalize(toCenter), float2(1, 0).Rotate(item.EquippableItem.Rotation));
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item);
|
||||
Thrust = Item.Evaluate(_data.Thrust);
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item);
|
||||
Thrust = Item.Evaluate(_data.Thrust);
|
||||
Entity.Velocity -= Entity.Direction.Rotate(Item.EquippableItem.Rotation) * _input * Thrust / Entity.Mass * delta;
|
||||
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque * Thrust * Context.GameplaySettings.TorqueMultiplier / Entity.Mass * delta));
|
||||
Item.AddHeat(_input * Context.Evaluate(_data.Heat, Item) * delta);
|
||||
var vis = _input * Context.Evaluate(_data.Visibility, Item);
|
||||
Item.AddHeat(_input * Item.Evaluate(_data.Heat) * delta);
|
||||
var vis = _input * Item.Evaluate(_data.Visibility);
|
||||
if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
return _input > .01f;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class TurretController : IBehavior
|
|||
if (b is Weapon weapon)
|
||||
{
|
||||
_weapons.Add(weapon);
|
||||
var vel = Context.Evaluate(weapon.WeaponData.Velocity, item);
|
||||
var vel = weapon.Item.Evaluate(weapon.WeaponData.Velocity);
|
||||
if (vel > .1f)
|
||||
{
|
||||
_predictShots = true;
|
||||
|
|
@ -95,7 +95,7 @@ public class TurretController : IBehavior
|
|||
var fire = dot(
|
||||
EquippedEntity.HardpointTransforms[EquippedEntity.Hardpoints[x.Item.Position.x, x.Item.Position.y]].direction,
|
||||
EquippedEntity.LookDirection) > .99f;
|
||||
if (Context.Evaluate(data.Range, x.Item) > dist && fire)
|
||||
if (x.Item.Evaluate(data.Range) > dist && fire)
|
||||
{
|
||||
x.Activate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class VelocityLimit : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Limit = Context.Evaluate(_data.TopSpeed, Item);
|
||||
Limit = Item.Evaluate(_data.TopSpeed);
|
||||
if (length(Entity.Velocity) > Limit)
|
||||
Entity.Velocity = normalize(Entity.Velocity) * Limit;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item);
|
||||
Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
|||
// TODO: Time independent decay?
|
||||
if(Entity.VisibilitySources.ContainsKey(this))
|
||||
{
|
||||
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item);
|
||||
Entity.VisibilitySources[this] *= Item.Evaluate(_data.VisibilityDecay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +91,6 @@ public abstract class Weapon : IActivatedBehavior
|
|||
public float Visibility { get; protected set; }
|
||||
public float Spread { get; protected set; }
|
||||
public float Velocity { get; protected set; }
|
||||
public float Wear { get; protected set; }
|
||||
|
||||
protected bool _firing;
|
||||
|
||||
|
|
@ -114,20 +113,16 @@ public abstract class Weapon : IActivatedBehavior
|
|||
|
||||
protected virtual void UpdateStats()
|
||||
{
|
||||
Damage = Context.Evaluate(_data.Damage, Item);
|
||||
Penetration = Context.Evaluate(_data.Penetration, Item);
|
||||
DamageSpread = Context.Evaluate(_data.DamageSpread, Item);
|
||||
MinRange = Context.Evaluate(_data.MinRange, Item);
|
||||
Range = Context.Evaluate(_data.Range, Item);
|
||||
Energy = Context.Evaluate(_data.Energy, Item);
|
||||
Heat = Context.Evaluate(_data.Heat, Item);
|
||||
Visibility = Context.Evaluate(_data.Visibility, Item);
|
||||
Spread = Context.Evaluate(_data.Spread, Item);
|
||||
Velocity = Context.Evaluate(_data.Velocity, Item);
|
||||
Wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability;
|
||||
Damage = Item.Evaluate(_data.Damage);
|
||||
Penetration = Item.Evaluate(_data.Penetration);
|
||||
DamageSpread = Item.Evaluate(_data.DamageSpread);
|
||||
MinRange = Item.Evaluate(_data.MinRange);
|
||||
Range = Item.Evaluate(_data.Range);
|
||||
Energy = Item.Evaluate(_data.Energy);
|
||||
Heat = Item.Evaluate(_data.Heat);
|
||||
Visibility = Item.Evaluate(_data.Visibility);
|
||||
Spread = Item.Evaluate(_data.Spread);
|
||||
Velocity = Item.Evaluate(_data.Velocity);
|
||||
}
|
||||
|
||||
public virtual bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -42,12 +42,9 @@ public class Wear : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability / _itemData.ThermalResilience;
|
||||
if (_data.PerSecond) wear *= delta;
|
||||
Item.EquippableItem.Durability -= wear;
|
||||
if (_data.PerSecond)
|
||||
Item.EquippableItem.Durability -= Item.Wear * delta;
|
||||
else Item.EquippableItem.Durability -= Item.Wear;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ public class DatabaseCache
|
|||
public void Load(string path)
|
||||
{
|
||||
RegisterResolver.Register();
|
||||
var bytes = File.ReadAllBytes(Path.Combine(path, "AetherDB.msgpack"));
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
var entries = MessagePackSerializer.Deserialize<DatabaseEntry[]>(bytes);
|
||||
AddAll(entries);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public abstract class Entity
|
|||
{
|
||||
public Zone Zone;
|
||||
public MegaCorporation Faction;
|
||||
public PlayerSettings PlayerSettings;
|
||||
public EquippableItem Hull;
|
||||
|
||||
public float3 Position;
|
||||
|
|
@ -82,10 +83,12 @@ public abstract class Entity
|
|||
if (value == _heatsinksEnabled) return;
|
||||
_heatsinksEnabled = value;
|
||||
foreach (var heatsink in _heatsinks)
|
||||
heatsink.Item.Enabled = value;
|
||||
heatsink.Item.Enabled.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideShutdown { get; set; }
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
|
|
@ -110,8 +113,8 @@ public abstract class Entity
|
|||
|
||||
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
|
||||
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
|
||||
public Subject<EquippedItem> ItemOffline = new Subject<EquippedItem>();
|
||||
public Subject<EquippedItem> ItemOnline = new Subject<EquippedItem>();
|
||||
// public Subject<EquippedItem> ItemOffline = new Subject<EquippedItem>();
|
||||
// public Subject<EquippedItem> ItemOnline = new Subject<EquippedItem>();
|
||||
public Subject<float> HullDamage = new Subject<float>();
|
||||
public Subject<Entity> Docked = new Subject<Entity>();
|
||||
public Subject<Unit> HeatstrokeRisk = new Subject<Unit>();
|
||||
|
|
@ -543,8 +546,8 @@ public abstract class Entity
|
|||
Cockpit = cockpit;
|
||||
}
|
||||
|
||||
equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem);
|
||||
equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem);
|
||||
// equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem);
|
||||
// equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem);
|
||||
|
||||
foreach (var i in itemData.Shape.Coordinates)
|
||||
{
|
||||
|
|
@ -597,7 +600,7 @@ public abstract class Entity
|
|||
public bool CanConsumeEnergy(float energy)
|
||||
{
|
||||
var capEnergy = _capacitors.Sum(cap => cap.Charge);
|
||||
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online);
|
||||
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online.Value);
|
||||
return capEnergy > energy || onlineReactors > 0;
|
||||
}
|
||||
|
||||
|
|
@ -622,10 +625,10 @@ public abstract class Entity
|
|||
|
||||
if (energy < .01f) return true;
|
||||
|
||||
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online);
|
||||
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online.Value);
|
||||
foreach (var reactor in _reactors)
|
||||
{
|
||||
if (reactor.Item.Online)
|
||||
if (reactor.Item.Online.Value)
|
||||
{
|
||||
reactor.ConsumeEnergy(energy / onlineReactors);
|
||||
}
|
||||
|
|
@ -877,67 +880,66 @@ public abstract class Entity
|
|||
|
||||
public class EquippedItem
|
||||
{
|
||||
public int SortPosition;
|
||||
public EquippableItem EquippableItem;
|
||||
|
||||
public int2 Position;
|
||||
|
||||
public IBehavior[] Behaviors;
|
||||
|
||||
public Dictionary<int, BehaviorGroup> BehaviorGroups;
|
||||
|
||||
public bool Enabled = true;
|
||||
|
||||
public event Action OnOffline;
|
||||
public event Action OnOnline;
|
||||
private bool _thermalOnline;
|
||||
private bool _durabilityOnline;
|
||||
|
||||
public IBehavior[] Behaviors { get; }
|
||||
public float Conductivity { get; }
|
||||
|
||||
public float ThermalPerformance { get; private set; }
|
||||
public float ThermalExponent { get; }
|
||||
public float DurabilityPerformance { get; private set; }
|
||||
public float DurabilityExponent { get; }
|
||||
public float Wear { get; private set; }
|
||||
public Shape InsetShape { get; }
|
||||
public Entity Entity { get; }
|
||||
public EquippableItemData Data { get; }
|
||||
|
||||
public int SortPosition;
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _online && Enabled;
|
||||
}
|
||||
public ReactiveProperty<bool> ThermalOnline { get; } = new ReactiveProperty<bool>(false);
|
||||
public ReactiveProperty<bool> DurabilityOnline { get; } = new ReactiveProperty<bool>(false);
|
||||
public ReadOnlyReactiveProperty<bool> Online { get; }
|
||||
public ReactiveProperty<bool> Enabled { get; } = new ReactiveProperty<bool>(true);
|
||||
public ReadOnlyReactiveProperty<bool> Active { get; }
|
||||
|
||||
public bool Online
|
||||
{
|
||||
get => _online;
|
||||
}
|
||||
|
||||
public float Temperature
|
||||
{
|
||||
get
|
||||
{
|
||||
float sum = 0;
|
||||
foreach (var x in InsetShape.Coordinates) sum += _entity.Temperature[x.x, x.y];
|
||||
foreach (var x in InsetShape.Coordinates) sum += Entity.Temperature[x.x, x.y];
|
||||
return sum/InsetShape.Coordinates.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public Entity Entity
|
||||
{
|
||||
get => _entity;
|
||||
}
|
||||
|
||||
protected readonly ItemManager _itemManager;
|
||||
private readonly EquippableItemData _data;
|
||||
private Entity _entity;
|
||||
private bool _online;
|
||||
//private bool _online;
|
||||
|
||||
public EquippedItem(ItemManager itemManager, EquippableItem item, int2 position, Entity entity)
|
||||
{
|
||||
_itemManager = itemManager;
|
||||
_data = _itemManager.GetData(item);
|
||||
_entity = entity;
|
||||
Data = _itemManager.GetData(item);
|
||||
Entity = entity;
|
||||
EquippableItem = item;
|
||||
Position = position;
|
||||
Conductivity = _data.Conductivity;
|
||||
Conductivity = Data.Conductivity;
|
||||
ThermalExponent = _itemManager.Evaluate(Data.HeatExponent, EquippableItem);
|
||||
DurabilityExponent = _itemManager.Evaluate(Data.DurabilityExponent, EquippableItem);
|
||||
var hullData = itemManager.GetData(entity.Hull);
|
||||
InsetShape = hullData.Shape.Inset(_data.Shape, position, item.Rotation);
|
||||
InsetShape = hullData.Shape.Inset(Data.Shape, position, item.Rotation);
|
||||
|
||||
Behaviors = _data.Behaviors
|
||||
Online = new ReadOnlyReactiveProperty<bool>(ThermalOnline
|
||||
.CombineLatest(DurabilityOnline, (thermal, durability) => thermal && durability).DistinctUntilChanged());
|
||||
Active = new ReadOnlyReactiveProperty<bool>(Enabled
|
||||
.CombineLatest(Online, (enabled, online) => enabled && online).DistinctUntilChanged());
|
||||
|
||||
|
||||
Behaviors = Data.Behaviors
|
||||
.Select(bd => bd.CreateInstance(itemManager, entity, this))
|
||||
.ToArray();
|
||||
|
||||
|
|
@ -946,9 +948,7 @@ public class EquippedItem
|
|||
.OrderBy(g => g.Key)
|
||||
.ToDictionary(g => g.Key, g => new BehaviorGroup
|
||||
{
|
||||
Behaviors = g.ToArray(),
|
||||
// Switch = (Switch) g.FirstOrDefault(b => b is Switch),
|
||||
// Trigger = (Trigger) g.FirstOrDefault(b => b is Trigger)
|
||||
Behaviors = g.ToArray()
|
||||
});
|
||||
|
||||
foreach (var behavior in Behaviors)
|
||||
|
|
@ -960,10 +960,32 @@ public class EquippedItem
|
|||
}
|
||||
}
|
||||
|
||||
public float Evaluate(PerformanceStat stat)
|
||||
{
|
||||
var heat = 1f;
|
||||
if(stat.HeatDependent)
|
||||
heat = pow(ThermalPerformance, ThermalExponent * stat.HeatExponentMultiplier);
|
||||
var durability = 1f;
|
||||
if(stat.DurabilityDependent)
|
||||
durability = pow(DurabilityPerformance, DurabilityExponent);
|
||||
var quality = pow(_itemManager.Quality(stat, EquippableItem), stat.QualityExponent);
|
||||
|
||||
var scaleModifier = 1.0f;
|
||||
foreach (var value in stat.GetScaleModifiers(Entity).Values) scaleModifier = scaleModifier * value;
|
||||
|
||||
float constantModifier = 0;
|
||||
foreach (var value in stat.GetConstantModifiers(Entity).Values) constantModifier += value;
|
||||
|
||||
var result = lerp(stat.Min, stat.Max, durability * quality * heat) * scaleModifier + constantModifier;
|
||||
if (float.IsNaN(result))
|
||||
return stat.Min;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void AddHeat(float heat, bool ignoreThermalMass = false)
|
||||
{
|
||||
foreach(var hullCoord in InsetShape.Coordinates)
|
||||
_entity.AddHeat(hullCoord, heat / InsetShape.Coordinates.Length, ignoreThermalMass);
|
||||
Entity.AddHeat(hullCoord, heat / InsetShape.Coordinates.Length, ignoreThermalMass);
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
|
|
@ -971,13 +993,18 @@ public class EquippedItem
|
|||
foreach (var behavior in Behaviors)
|
||||
if(behavior is IAlwaysUpdatedBehavior alwaysUpdatedBehavior) alwaysUpdatedBehavior.Update(delta);
|
||||
|
||||
var previouslyOnline = _online;
|
||||
_online = EquippableItem.Durability > .01f && Temperature > _data.MinimumTemperature && Temperature < _data.MaximumTemperature;
|
||||
var temp = Temperature;
|
||||
ThermalPerformance = Data.Performance(temp);
|
||||
DurabilityPerformance = EquippableItem.Durability / Data.Durability;
|
||||
var performanceThreshold = Entity.PlayerSettings?.ShutdownPerformance ?? _itemManager.GameplaySettings.DefaultShutdownPerformance;
|
||||
Wear = (1 - pow(Data.Performance(temp),
|
||||
(1 - pow(_itemManager.CompoundQuality(EquippableItem), _itemManager.GameplaySettings.QualityWearExponent)) *
|
||||
_itemManager.GameplaySettings.ThermalWearExponent)
|
||||
) * Data.Durability / Data.ThermalResilience;
|
||||
ThermalOnline.Value = ThermalPerformance > performanceThreshold || Entity.OverrideShutdown && EquippableItem.OverrideShutdown;
|
||||
DurabilityOnline.Value = EquippableItem.Durability > .01f;
|
||||
|
||||
if (!previouslyOnline && _online) OnOnline?.Invoke();
|
||||
if (previouslyOnline && !_online) OnOffline?.Invoke();
|
||||
|
||||
if (Active)
|
||||
if (Active.Value)
|
||||
{
|
||||
foreach (var group in BehaviorGroups.Values)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,5 +55,6 @@ public class SimpleCommodity : ItemInstance
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class EquippableItem : CraftedItemInstance
|
||||
{
|
||||
[JsonProperty("durability"), Key(7)] public float Durability;
|
||||
[JsonProperty("durability"), Key(7)] public float Durability;
|
||||
[JsonProperty("override"), Key(8)] public bool OverrideShutdown;
|
||||
}
|
||||
|
|
@ -272,27 +272,6 @@ public class ItemManager
|
|||
return result;
|
||||
}
|
||||
|
||||
// Returns stat using ship temperature and modifiers
|
||||
public float Evaluate(PerformanceStat stat, EquippedItem item)
|
||||
{
|
||||
var itemData = GetData(item.EquippableItem);
|
||||
|
||||
var heat = !stat.HeatDependent ? 1 : pow(itemData.Performance(item.Temperature), Evaluate(itemData.HeatExponent, item.EquippableItem) * stat.HeatExponentMultiplier);
|
||||
var durability = !stat.DurabilityDependent ? 1 : pow(item.EquippableItem.Durability / itemData.Durability, Evaluate(itemData.DurabilityExponent,item.EquippableItem));
|
||||
var quality = pow(Quality(stat, item.EquippableItem), stat.QualityExponent);
|
||||
|
||||
var scaleModifier = 1.0f;
|
||||
foreach (var value in stat.GetScaleModifiers(item.Entity).Values) scaleModifier = scaleModifier * value;
|
||||
|
||||
float constantModifier = 0;
|
||||
foreach (var value in stat.GetConstantModifiers(item.Entity).Values) constantModifier += value;
|
||||
|
||||
var result = lerp(stat.Min, stat.Max, durability * quality * heat) * scaleModifier + constantModifier;
|
||||
if (float.IsNaN(result))
|
||||
return stat.Min;
|
||||
return result;
|
||||
}
|
||||
|
||||
// public Entity CreateEntity(Guid zoneID, Guid corporation, Guid loadout)
|
||||
// {
|
||||
// if (!(ItemData.Get(loadout) is LoadoutData loadoutData))
|
||||
|
|
|
|||
12
Assets/Scripts/ServerShared/PlayerSettings.cs
Normal file
12
Assets/Scripts/ServerShared/PlayerSettings.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using MessagePack;
|
||||
|
||||
[MessagePackObject, Serializable]
|
||||
public class PlayerSettings
|
||||
{
|
||||
[Key(0)]
|
||||
public string Name;
|
||||
|
||||
[Key(1)]
|
||||
public float ShutdownPerformance = .25f;
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/PlayerSettings.cs.meta
Normal file
3
Assets/Scripts/ServerShared/PlayerSettings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ae0b9ef04d124cd5b5dbc098681b7fc2
|
||||
timeCreated: 1615064445
|
||||
|
|
@ -88,6 +88,7 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public float DefaultShutdownPerformance = .25f;
|
||||
public float SevereHeatstrokeRiskThreshold = .25f;
|
||||
public float WormholeDepth = 1000;
|
||||
public float WormholeExitVelocity = 20;
|
||||
|
|
|
|||
|
|
@ -94,26 +94,38 @@ public class Ship : Entity
|
|||
_forwardThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Reversed));
|
||||
RecalculateForwardThrust();
|
||||
|
||||
foreach (var thruster in _forwardThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateForwardThrust());
|
||||
|
||||
_reverseThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.None));
|
||||
RecalculateReverseThrust();
|
||||
foreach (var thruster in _reverseThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateReverseThrust());
|
||||
|
||||
_rightThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.CounterClockwise));
|
||||
RecalculateRightStrafeThrust();
|
||||
foreach (var thruster in _rightThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateRightStrafeThrust());
|
||||
|
||||
_leftThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Clockwise));
|
||||
RecalculateLeftStrafeThrust();
|
||||
foreach (var thruster in _leftThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateLeftStrafeThrust());
|
||||
|
||||
_counterClockwiseThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Torque < -ItemManager.GameplaySettings.TorqueFloor));
|
||||
RecalculateCounterClockwiseTorque();
|
||||
foreach (var thruster in _counterClockwiseThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateCounterClockwiseTorque());
|
||||
|
||||
_clockwiseThrusters = new HashSet<Thruster>(_allThrusters
|
||||
.Where(x => x.Torque > ItemManager.GameplaySettings.TorqueFloor));
|
||||
RecalculateClockwiseTorque();
|
||||
foreach (var thruster in _clockwiseThrusters)
|
||||
thruster.Item.Online.Skip(1).Subscribe(b => RecalculateClockwiseTorque());
|
||||
}
|
||||
|
||||
public Ship(ItemManager itemManager, Zone zone, EquippableItem hull) : base(itemManager, zone, hull)
|
||||
|
|
@ -138,8 +150,6 @@ public class Ship : Entity
|
|||
}
|
||||
|
||||
ItemDamage.Select(x => x.item).Subscribe(CheckForThruster);
|
||||
ItemOffline.Subscribe(CheckForThruster);
|
||||
ItemOnline.Subscribe(CheckForThruster);
|
||||
}
|
||||
|
||||
#region ThrustCalculation
|
||||
|
|
@ -149,7 +159,7 @@ public class Ship : Entity
|
|||
ForwardThrust = 0;
|
||||
foreach (var thruster in _forwardThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
ForwardThrust += thruster.Thrust;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +169,7 @@ public class Ship : Entity
|
|||
ReverseThrust = 0;
|
||||
foreach (var thruster in _reverseThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
ReverseThrust += thruster.Thrust;
|
||||
}
|
||||
}
|
||||
|
|
@ -170,7 +180,7 @@ public class Ship : Entity
|
|||
LeftStrafeTotalTorque = 0;
|
||||
foreach (var thruster in _leftThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
{
|
||||
LeftStrafeThrust += thruster.Thrust;
|
||||
LeftStrafeTotalTorque += thruster.Torque * thruster.Thrust;
|
||||
|
|
@ -187,7 +197,7 @@ public class Ship : Entity
|
|||
RightStrafeTotalTorque = 0;
|
||||
foreach (var thruster in _rightThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
{
|
||||
RightStrafeThrust += thruster.Thrust;
|
||||
RightStrafeTotalTorque += thruster.Torque * thruster.Thrust;
|
||||
|
|
@ -203,7 +213,7 @@ public class Ship : Entity
|
|||
ClockwiseTorque = 0;
|
||||
foreach (var thruster in _clockwiseThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
ClockwiseTorque += thruster.Torque;
|
||||
}
|
||||
}
|
||||
|
|
@ -213,7 +223,7 @@ public class Ship : Entity
|
|||
CounterClockwiseTorque = 0;
|
||||
foreach (var thruster in _counterClockwiseThrusters)
|
||||
{
|
||||
if(thruster.Item.Online)
|
||||
if(thruster.Item.Active.Value)
|
||||
CounterClockwiseTorque -= thruster.Torque;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue