Heat Performance Curves + Wear & Tear
Added heat variation option for Performance Stats Ability to toggle radiators on/off using H key Item durability loss (Wear) is now heat dependent and incurred only when used Restricted equip/unequip to docked (inactive) entities Fixed race condition causing exceptions in database sync code
This commit is contained in:
parent
1bb058a8dc
commit
4b10923448
44 changed files with 437 additions and 184 deletions
|
|
@ -18,8 +18,8 @@ public class CombatState : BaseState
|
|||
SampleDps();
|
||||
foreach (var weapon in _agent.Ship.Weapons)
|
||||
{
|
||||
weapon.Item.OnDisable += SampleDps;
|
||||
weapon.Item.OnEnable += SampleDps;
|
||||
weapon.Item.OnOffline += SampleDps;
|
||||
weapon.Item.OnOnline += SampleDps;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class Capacitor : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Capacity = Context.Evaluate(_data.Capacity, Item.EquippableItem, Entity);
|
||||
Efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity);
|
||||
Capacity = Context.Evaluate(_data.Capacity, Item);
|
||||
Efficiency = Context.Evaluate(_data.Efficiency, Item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,9 +100,9 @@ public class ChargedWeapon : InstantWeapon
|
|||
protected override void UpdateStats()
|
||||
{
|
||||
base.UpdateStats();
|
||||
ChargeTime = Context.Evaluate(_data.ChargeTime, Item.EquippableItem, Entity);
|
||||
ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item.EquippableItem, Entity);
|
||||
ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item.EquippableItem, Entity);
|
||||
ChargeTime = Context.Evaluate(_data.ChargeTime, Item);
|
||||
ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item);
|
||||
ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item);
|
||||
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.EquippableItem, Entity) * delta))
|
||||
if (!Entity.TryConsumeEnergy(Context.Evaluate(_data.Energy, Item) * delta))
|
||||
{
|
||||
_firing = false;
|
||||
OnStopFiring?.Invoke();
|
||||
|
|
@ -114,9 +114,10 @@ public class ConstantWeapon : Weapon, IProgressBehavior
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
|
||||
Item.EquippableItem.Durability -= Wear * delta;
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item) * delta);
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,6 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity);
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(12), RuntimeInspectable]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable]
|
||||
public class EnergyDrawData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("draw"), Key(1), RuntimeInspectable]
|
||||
|
|
@ -42,6 +42,6 @@ public class EnergyDraw : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return Entity.TryConsumeEnergy(Context.Evaluate(_data.EnergyDraw, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1));
|
||||
return Entity.TryConsumeEnergy(Context.Evaluate(_data.EnergyDraw, Item) * (_data.PerSecond ? delta : 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ public class Heat : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1));
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item) * (_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.EquippableItem, Entity);
|
||||
BurstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity);
|
||||
Cooldown = Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity);
|
||||
BurstCount = Context.Evaluate(_data.Count, Item);
|
||||
BurstTime = Context.Evaluate(_data.BurstTime, Item);
|
||||
Cooldown = Context.Evaluate(_data.Cooldown, Item);
|
||||
|
||||
Damage /= (int) BurstCount;
|
||||
Heat /= (int) BurstCount;
|
||||
|
|
@ -165,6 +165,7 @@ public class InstantWeapon : Weapon, IProgressBehavior
|
|||
_burstRemaining--;
|
||||
_burstTimer -= _burstInterval;
|
||||
OnFire?.Invoke();
|
||||
Item.EquippableItem.Durability -= 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.EquippableItem, Entity);
|
||||
SensorImpact = Context.Evaluate(_data.SensorImpact, Item.EquippableItem, Entity);
|
||||
LockAngle = Context.Evaluate(_data.LockAngle, Item.EquippableItem, Entity);
|
||||
DirectionImpact = Context.Evaluate(_data.DirectionImpact, Item.EquippableItem, Entity);
|
||||
Decay = Context.Evaluate(_data.Decay, Item.EquippableItem, Entity);
|
||||
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);
|
||||
|
||||
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.EquippableItem, Entity);
|
||||
Range = Context.Evaluate(_data.Range, Item);
|
||||
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.EquippableItem, Entity) * delta,
|
||||
Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity),
|
||||
Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity));
|
||||
Context.Evaluate(_data.DamagePerSecond, Item) * delta,
|
||||
Context.Evaluate(_data.Efficiency, Item),
|
||||
Context.Evaluate(_data.Penetration, Item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item.EquippableItem, Entity);
|
||||
WasteHeat = Context.Evaluate(_data.WasteHeat, Item.EquippableItem, Entity);
|
||||
EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item.EquippableItem, Entity);
|
||||
PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item);
|
||||
WasteHeat = Context.Evaluate(_data.WasteHeat, Item);
|
||||
EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item);
|
||||
|
||||
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.EquippableItem, Entity);
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item);
|
||||
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.EquippableItem, Entity) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity);
|
||||
var charge = Context.Evaluate(_data.Charge, Item) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item);
|
||||
|
||||
// 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.EquippableItem, Entity);
|
||||
var overloadEfficiency = Context.Evaluate(_data.OverloadEfficiency, Item);
|
||||
|
||||
// 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.EquippableItem, Entity));
|
||||
heat -= Draw / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item));
|
||||
Draw = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item.EquippableItem, Entity);
|
||||
ScanDuration = Context.Evaluate(_data.ScanDuration, Item.EquippableItem, Entity);
|
||||
Range = Context.Evaluate(_data.Range, Item);
|
||||
MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item);
|
||||
ScanDuration = Context.Evaluate(_data.ScanDuration, Item);
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ public class Sensor : IBehavior
|
|||
var next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Context.Evaluate(_data.Sensitivity, Item.EquippableItem, Entity) *
|
||||
Context.Evaluate(_data.Sensitivity, Item) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
next *= 1 - Context.GameplaySettings.TargetInfoDecay * delta;
|
||||
|
|
|
|||
|
|
@ -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.EquippableItem, Entity);
|
||||
: stat.GetScaleModifiers(Entity))[this] = Context.Evaluate(_data.Modifier, Item);
|
||||
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.EquippableItem, Entity);
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item);
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item.EquippableItem, Entity);
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item);
|
||||
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.EquippableItem, Entity) * delta);
|
||||
var vis = _input * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
Item.AddHeat(_input * Context.Evaluate(_data.Heat, Item) * delta);
|
||||
var vis = _input * Context.Evaluate(_data.Visibility, Item);
|
||||
if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class TurretController : IBehavior
|
|||
if (b is Weapon weapon)
|
||||
{
|
||||
_weapons.Add(weapon);
|
||||
var vel = Context.Evaluate(weapon.WeaponData.Velocity, item.EquippableItem, EquippedEntity);
|
||||
var vel = Context.Evaluate(weapon.WeaponData.Velocity, item);
|
||||
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.EquippableItem, EquippedEntity) > dist && fire)
|
||||
if (Context.Evaluate(data.Range, x.Item) > dist && fire)
|
||||
{
|
||||
x.Activate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class VelocityLimit : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Limit = Context.Evaluate(_data.TopSpeed, Item.EquippableItem, Entity);
|
||||
Limit = Context.Evaluate(_data.TopSpeed, Item);
|
||||
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.EquippableItem, Entity);
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item);
|
||||
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.EquippableItem, Entity);
|
||||
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,7 @@ public abstract class WeaponData : BehaviorData
|
|||
public abstract class Weapon : IActivatedBehavior
|
||||
{
|
||||
private WeaponData _data;
|
||||
private EquippableItemData _itemData;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
|
|
@ -89,6 +90,7 @@ 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;
|
||||
|
||||
|
|
@ -104,22 +106,24 @@ public abstract class Weapon : IActivatedBehavior
|
|||
Entity = entity;
|
||||
Item = item;
|
||||
_data = data;
|
||||
_itemData = context.GetData(item.EquippableItem);
|
||||
}
|
||||
|
||||
public virtual void ResetEvents(){}
|
||||
|
||||
protected virtual void UpdateStats()
|
||||
{
|
||||
Damage = Context.Evaluate(_data.Damage, Item.EquippableItem, Entity);
|
||||
Penetration = Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity);
|
||||
DamageSpread = Context.Evaluate(_data.DamageSpread, Item.EquippableItem, Entity);
|
||||
MinRange = Context.Evaluate(_data.MinRange, Item.EquippableItem, Entity);
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
Energy = Context.Evaluate(_data.Energy, Item.EquippableItem, Entity);
|
||||
Heat = Context.Evaluate(_data.Heat, Item.EquippableItem, Entity);
|
||||
Visibility = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
Spread = Context.Evaluate(_data.Spread, Item.EquippableItem, Entity);
|
||||
Velocity = Context.Evaluate(_data.Velocity, Item.EquippableItem, Entity);
|
||||
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 = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
}
|
||||
|
||||
public virtual bool Execute(float delta)
|
||||
|
|
|
|||
50
Assets/Scripts/ServerShared/Behaviors/Wear.cs
Normal file
50
Assets/Scripts/ServerShared/Behaviors/Wear.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(1000), RuntimeInspectable]
|
||||
public class WearData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("perSecond"), Key(1)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Wear(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Wear : IBehavior
|
||||
{
|
||||
private WearData _data;
|
||||
private EquippableItemData _itemData;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Wear(ItemManager context, WearData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_itemData = context.GetData(item.EquippableItem);
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var wear = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
if (_data.PerSecond) wear *= delta;
|
||||
Item.EquippableItem.Durability -= wear;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: efacda60d2c34447a59c16bdb100ad80
|
||||
timeCreated: 1614819389
|
||||
|
|
@ -18,6 +18,8 @@ public class DatabaseCache
|
|||
public event Action<DatabaseEntry> OnDataUpdateRemote;
|
||||
public event Action<DatabaseEntry> OnDataDeleteRemote;
|
||||
|
||||
private readonly object addLock = new object();
|
||||
|
||||
public Action<string> Logger = Console.WriteLine;
|
||||
|
||||
private readonly Dictionary<Guid, DatabaseEntry> _entries = new Dictionary<Guid, DatabaseEntry>();
|
||||
|
|
@ -28,32 +30,35 @@ public class DatabaseCache
|
|||
|
||||
public void Add(DatabaseEntry entry, bool remote = false)
|
||||
{
|
||||
if (entry != null)
|
||||
lock(addLock)
|
||||
{
|
||||
var exists = _entries.ContainsKey(entry.ID);
|
||||
_entries[entry.ID] = entry;
|
||||
var type = entry.GetType();
|
||||
var types = type.GetParentTypes();
|
||||
foreach (var t in types)
|
||||
if (entry != null)
|
||||
{
|
||||
if(!_types.ContainsKey(t))
|
||||
_types[t] = new Dictionary<Guid, DatabaseEntry>();
|
||||
_types[t][entry.ID] = entry;
|
||||
}
|
||||
var exists = _entries.ContainsKey(entry.ID);
|
||||
_entries[entry.ID] = entry;
|
||||
var type = entry.GetType();
|
||||
var types = type.GetParentTypes();
|
||||
foreach (var t in types)
|
||||
{
|
||||
if (!_types.ContainsKey(t))
|
||||
_types[t] = new Dictionary<Guid, DatabaseEntry>();
|
||||
_types[t][entry.ID] = entry;
|
||||
}
|
||||
|
||||
if (remote)
|
||||
{
|
||||
if (exists)
|
||||
OnDataUpdateRemote?.Invoke(entry);
|
||||
if (remote)
|
||||
{
|
||||
if (exists)
|
||||
OnDataUpdateRemote?.Invoke(entry);
|
||||
else
|
||||
OnDataInsertRemote?.Invoke(entry);
|
||||
}
|
||||
else
|
||||
OnDataInsertRemote?.Invoke(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (exists)
|
||||
OnDataUpdateLocal?.Invoke(entry);
|
||||
else
|
||||
OnDataInsertLocal?.Invoke(entry);
|
||||
{
|
||||
if (exists)
|
||||
OnDataUpdateLocal?.Invoke(entry);
|
||||
else
|
||||
OnDataInsertLocal?.Invoke(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,27 @@ public abstract class Entity
|
|||
private List<Weapon> _weapons = new List<Weapon>();
|
||||
private List<Capacitor> _capacitors = new List<Capacitor>();
|
||||
private List<Reactor> _reactors = new List<Reactor>();
|
||||
private List<Radiator> _heatsinks = new List<Radiator>();
|
||||
protected bool _active;
|
||||
|
||||
private bool _heatsinksEnabled = true;
|
||||
|
||||
public bool HeatsinksEnabled
|
||||
{
|
||||
get => _heatsinksEnabled;
|
||||
set
|
||||
{
|
||||
if (value == _heatsinksEnabled) return;
|
||||
_heatsinksEnabled = value;
|
||||
foreach (var heatsink in _heatsinks)
|
||||
heatsink.Item.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
}
|
||||
|
||||
public IEnumerable<Weapon> Weapons
|
||||
{
|
||||
|
|
@ -291,8 +311,11 @@ public abstract class Entity
|
|||
return quantityTransferred;
|
||||
}
|
||||
|
||||
public EquippableItem Unequip(EquippedItem item)
|
||||
public EquippableItem TryUnequip(EquippedItem item)
|
||||
{
|
||||
// Don't allow unequipping when the entity is active
|
||||
if (_active) return null;
|
||||
|
||||
if (item.EquippableItem == null)
|
||||
{
|
||||
ItemManager.Log("Attempted to remove equipped item with no equippable item on it! This should be impossible!");
|
||||
|
|
@ -330,6 +353,8 @@ public abstract class Entity
|
|||
_capacitors.Remove(capacitor);
|
||||
if(b is Reactor reactor)
|
||||
_reactors.Remove(reactor);
|
||||
if(b is Radiator heatsink)
|
||||
_heatsinks.Remove(heatsink);
|
||||
}
|
||||
|
||||
return item.EquippableItem;
|
||||
|
|
@ -396,6 +421,9 @@ public abstract class Entity
|
|||
// Check whether the given item will fit when its origin is placed at the given coordinate on the hull
|
||||
public bool ItemFits(EquippableItem item, int2 hullCoord)
|
||||
{
|
||||
// Don't allow equipping while deployed
|
||||
if (_active) return false;
|
||||
|
||||
var itemData = ItemManager.GetData(item);
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
return ItemFits(itemData, hullData, item, hullCoord);
|
||||
|
|
@ -403,6 +431,12 @@ public abstract class Entity
|
|||
|
||||
public bool TryFindSpace(EquippableItem item, out int2 hullCoord)
|
||||
{
|
||||
// Don't allow equipping while deployed
|
||||
if (_active)
|
||||
{
|
||||
hullCoord = int2.zero;
|
||||
return false;
|
||||
}
|
||||
var itemData = ItemManager.GetData(item);
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
|
||||
|
|
@ -451,6 +485,9 @@ public abstract class Entity
|
|||
// Try to equip the given item to the given location
|
||||
public bool TryEquip(EquippableItem item, int2 hullCoord)
|
||||
{
|
||||
// Don't allow equipping while deployed
|
||||
if (_active) return false;
|
||||
|
||||
var itemData = ItemManager.GetData(item);
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
|
||||
|
|
@ -492,10 +529,12 @@ public abstract class Entity
|
|||
_capacitors.Add(capacitor);
|
||||
if(b is Reactor reactor)
|
||||
_reactors.Add(reactor);
|
||||
if(b is Radiator heatsink)
|
||||
_heatsinks.Add(heatsink);
|
||||
}
|
||||
|
||||
equippedItem.OnEnable += () => ItemOnline.OnNext(equippedItem);
|
||||
equippedItem.OnDisable += () => ItemOffline.OnNext(equippedItem);
|
||||
equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem);
|
||||
equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem);
|
||||
|
||||
foreach (var i in itemData.Shape.Coordinates)
|
||||
{
|
||||
|
|
@ -811,8 +850,10 @@ public class EquippedItem
|
|||
|
||||
public Dictionary<int, BehaviorGroup> BehaviorGroups;
|
||||
|
||||
public event Action OnDisable;
|
||||
public event Action OnEnable;
|
||||
public bool Enabled = true;
|
||||
|
||||
public event Action OnOffline;
|
||||
public event Action OnOnline;
|
||||
|
||||
public float Conductivity { get; }
|
||||
|
||||
|
|
@ -834,6 +875,11 @@ public class EquippedItem
|
|||
return sum/InsetShape.Coordinates.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public Entity Entity
|
||||
{
|
||||
get => _entity;
|
||||
}
|
||||
|
||||
protected readonly ItemManager _itemManager;
|
||||
private readonly EquippableItemData _data;
|
||||
|
|
@ -882,22 +928,16 @@ public class EquippedItem
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
if (Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature)
|
||||
{
|
||||
_entity.ItemDamage.OnNext((this, delta));
|
||||
EquippableItem.Durability -= delta;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (!previouslyOnline && _online) OnEnable?.Invoke();
|
||||
if (previouslyOnline && !_online) OnDisable?.Invoke();
|
||||
if (!previouslyOnline && _online) OnOnline?.Invoke();
|
||||
if (previouslyOnline && !_online) OnOffline?.Invoke();
|
||||
|
||||
if (_online)
|
||||
if (Enabled && _online)
|
||||
{
|
||||
foreach (var group in BehaviorGroups.Values)
|
||||
{
|
||||
|
|
@ -958,6 +998,15 @@ public class EquippedCargoBay : EquippedItem
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryFindSpace(ItemInstance item)
|
||||
{
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
return TryFindSpace(simpleCommodity, out _);
|
||||
if (item is CraftedItemInstance craftedItem)
|
||||
return TryFindSpace(craftedItem, out _);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tries to find a place to put the given items in the inventory
|
||||
// Will attempt to fill existing item stacks first
|
||||
|
|
@ -996,6 +1045,23 @@ public class EquippedCargoBay : EquippedItem
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Searches the cargo bay for a position where the item will fit, returns true when found
|
||||
public bool TryFindSpace(CraftedItemInstance item, out int2 position)
|
||||
{
|
||||
// Search all the space in the cargo bay for an empty space where the item fits
|
||||
foreach (var cargoCoord in Data.InteriorShape.Coordinates)
|
||||
{
|
||||
if (ItemFits(item, cargoCoord))
|
||||
{
|
||||
position = cargoCoord;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
position = int2.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryStore(ItemInstance item)
|
||||
{
|
||||
|
|
@ -1072,23 +1138,6 @@ public class EquippedCargoBay : EquippedItem
|
|||
return true;
|
||||
}
|
||||
|
||||
// Searches the cargo bay for a position where the item will fit, returns true when found
|
||||
public bool TryFindSpace(CraftedItemInstance item, out int2 position)
|
||||
{
|
||||
// Search all the space in the cargo bay for an empty space where the item fits
|
||||
foreach (var cargoCoord in Data.InteriorShape.Coordinates)
|
||||
{
|
||||
if (ItemFits(item, cargoCoord))
|
||||
{
|
||||
position = cargoCoord;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
position = int2.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to store the given item anywhere it will fit, returns true when the item was successfully stored
|
||||
public bool TryStore(CraftedItemInstance item) => TryFindSpace(item, out var position) && TryStore(item, position);
|
||||
|
||||
|
|
|
|||
|
|
@ -290,6 +290,15 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
|
||||
[InspectableField, JsonProperty("durabilityExponent"), Key(15), SimplePerformanceStat]
|
||||
public PerformanceStat DurabilityExponent = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heatExponent"), Key(16), SimplePerformanceStat]
|
||||
public PerformanceStat HeatExponent = new PerformanceStat();
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(17)]
|
||||
public float4[] HeatPerformanceCurve;
|
||||
|
||||
[InspectableField, JsonProperty("wearDamage"), Key(18)]
|
||||
public PerformanceStat WearDamage = new PerformanceStat();
|
||||
|
||||
[IgnoreMember]
|
||||
public abstract HardpointType HardpointType { get; }
|
||||
|
|
@ -297,12 +306,42 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
[IgnoreMember] private const int STEPS = 64;
|
||||
|
||||
[IgnoreMember] private float? _optimum;
|
||||
|
||||
[IgnoreMember]
|
||||
public float OptimalTemperature
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_optimum==null)
|
||||
{
|
||||
var samples = Enumerable.Range(0, STEPS).Select(i => (float) i / STEPS).ToArray();
|
||||
float max = 0;
|
||||
_optimum = 0;
|
||||
foreach (var f in samples)
|
||||
{
|
||||
var p = HeatPerformanceCurve?.Evaluate(f)??0;
|
||||
if (p > max)
|
||||
{
|
||||
max = p;
|
||||
_optimum = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (float) (MinimumTemperature + _optimum * (MaximumTemperature - MinimumTemperature));
|
||||
}
|
||||
}
|
||||
|
||||
public float Performance(float temperature)
|
||||
{
|
||||
return saturate(HeatPerformanceCurve.Evaluate(unlerp(MinimumTemperature, MaximumTemperature, temperature)));
|
||||
}
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GearData : EquippableItemData
|
||||
{
|
||||
[InspectableField, JsonProperty("hardpointType"), Key(16)]
|
||||
[InspectableField, JsonProperty("hardpointType"), Key(19)]
|
||||
public HardpointType Hardpoint;
|
||||
|
||||
[IgnoreMember] public override HardpointType HardpointType => Hardpoint;
|
||||
|
|
@ -311,7 +350,7 @@ public class GearData : EquippableItemData
|
|||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class CargoBayData : EquippableItemData
|
||||
{
|
||||
[InspectableField, JsonProperty("interiorShape"), Key(16)]
|
||||
[InspectableField, JsonProperty("interiorShape"), Key(19)]
|
||||
public Shape InteriorShape;
|
||||
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool;
|
||||
}
|
||||
|
|
@ -319,7 +358,7 @@ public class CargoBayData : EquippableItemData
|
|||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class DockingBayData : CargoBayData
|
||||
{
|
||||
[InspectableField, JsonProperty("maxSize"), Key(17)]
|
||||
[InspectableField, JsonProperty("maxSize"), Key(20)]
|
||||
public int2 MaxSize;
|
||||
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool;
|
||||
}
|
||||
|
|
@ -327,19 +366,19 @@ public class DockingBayData : CargoBayData
|
|||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class HullData : EquippableItemData
|
||||
{
|
||||
[InspectableField, JsonProperty("hardpoints"), Key(16)]
|
||||
[InspectableField, JsonProperty("hardpoints"), Key(19)]
|
||||
public List<HardpointData> Hardpoints = new List<HardpointData>();
|
||||
|
||||
[InspectablePrefab, JsonProperty("prefab"), Key(17)]
|
||||
[InspectablePrefab, JsonProperty("prefab"), Key(20)]
|
||||
public string Prefab;
|
||||
|
||||
[InspectableField, JsonProperty("hullType"), Key(18)]
|
||||
[InspectableField, JsonProperty("hullType"), Key(21)]
|
||||
public HullType HullType;
|
||||
|
||||
[InspectableField, JsonProperty("gridOffset"), Key(19)]
|
||||
[InspectableField, JsonProperty("gridOffset"), Key(22)]
|
||||
public float GridOffset;
|
||||
|
||||
[InspectableField, JsonProperty("armor"), Key(20)]
|
||||
[InspectableField, JsonProperty("armor"), Key(23)]
|
||||
public float Armor;
|
||||
|
||||
[IgnoreMember]
|
||||
|
|
@ -410,11 +449,14 @@ public class PerformanceStat
|
|||
[JsonProperty("durabilityDependent"), Key(2)]
|
||||
public bool DurabilityDependent;
|
||||
|
||||
// [JsonProperty("heatDependent"), Key(3)]
|
||||
// public bool HeatDependent;
|
||||
|
||||
[JsonProperty("qualityExponent"), Key(3)]
|
||||
public float QualityExponent;
|
||||
|
||||
[JsonProperty("heatDependent"), Key(4)]
|
||||
public bool HeatDependent;
|
||||
|
||||
[JsonProperty("heatExponentMultiplier"), Key(5)]
|
||||
public float HeatExponentMultiplier = 1;
|
||||
|
||||
//[JsonProperty("id"), Key(5)] public Guid ID = Guid.NewGuid();
|
||||
|
||||
|
|
|
|||
|
|
@ -273,21 +273,21 @@ public class ItemManager
|
|||
}
|
||||
|
||||
// Returns stat using ship temperature and modifiers
|
||||
public float Evaluate(PerformanceStat stat, EquippableItem item, Entity entity)
|
||||
public float Evaluate(PerformanceStat stat, EquippedItem item)
|
||||
{
|
||||
var itemData = GetData(item);
|
||||
var itemData = GetData(item.EquippableItem);
|
||||
|
||||
//var heat = !stat.HeatDependent ? 1 : pow(itemData.Performance(entity.Temperature), Evaluate(itemData.HeatExponent,item));
|
||||
var durability = !stat.DurabilityDependent ? 1 : pow(item.Durability / itemData.Durability, Evaluate(itemData.DurabilityExponent,item));
|
||||
var quality = pow(Quality(stat, item), stat.QualityExponent);
|
||||
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(entity).Values) scaleModifier = scaleModifier * value;
|
||||
foreach (var value in stat.GetScaleModifiers(item.Entity).Values) scaleModifier = scaleModifier * value;
|
||||
|
||||
float constantModifier = 0;
|
||||
foreach (var value in stat.GetConstantModifiers(entity).Values) constantModifier += value;
|
||||
foreach (var value in stat.GetConstantModifiers(item.Entity).Values) constantModifier += value;
|
||||
|
||||
var result = lerp(stat.Min, stat.Max, durability * quality) * scaleModifier + constantModifier;
|
||||
var result = lerp(stat.Min, stat.Max, durability * quality * heat) * scaleModifier + constantModifier;
|
||||
if (float.IsNaN(result))
|
||||
return stat.Min;
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Reference in a new issue