Bypass configs for simple behaviors
This commit is contained in:
parent
068bc11622
commit
b97bf31b50
14 changed files with 152 additions and 256 deletions
|
|
@ -95,6 +95,14 @@ public abstract class Behavior
|
|||
return false;
|
||||
}
|
||||
|
||||
protected void RegisterPerformanceStat(string statName, PerformanceStat stat)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(statName) && stat != null)
|
||||
{
|
||||
_performanceStats[statName] = stat;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, PerformanceStat> CapturePerformanceStats(RuntimeBehaviorConfig config)
|
||||
{
|
||||
return config == null
|
||||
|
|
@ -186,6 +194,8 @@ public interface IPopulationAssignment
|
|||
|
||||
public sealed class RuntimeBehaviorDefinition
|
||||
{
|
||||
private readonly IReadOnlyDictionary<int, AetheriaRuntimeBehaviorValue> _fields;
|
||||
|
||||
public string Kind { get; }
|
||||
public int Group { get; }
|
||||
|
||||
|
|
@ -193,6 +203,55 @@ public sealed class RuntimeBehaviorDefinition
|
|||
{
|
||||
Kind = payload?.Kind ?? "";
|
||||
Group = payload?.Group ?? 0;
|
||||
|
||||
var fields = new Dictionary<int, AetheriaRuntimeBehaviorValue>();
|
||||
if (payload != null)
|
||||
{
|
||||
foreach (var field in payload.Fields)
|
||||
{
|
||||
if (!fields.ContainsKey(field.Key))
|
||||
{
|
||||
fields.Add(field.Key, field.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_fields = fields;
|
||||
}
|
||||
|
||||
public bool Bool(int key, bool fallback = false)
|
||||
{
|
||||
return _fields.TryGetValue(key, out var value) ? value.BoolValue : fallback;
|
||||
}
|
||||
|
||||
public string ItemKey(int key, string fallback = "")
|
||||
{
|
||||
return _fields.TryGetValue(key, out var value) &&
|
||||
!string.IsNullOrWhiteSpace(value.ItemKeyValue)
|
||||
? value.ItemKeyValue
|
||||
: fallback;
|
||||
}
|
||||
|
||||
public PerformanceStat PerformanceStat(int key, PerformanceStat fallback)
|
||||
{
|
||||
return _fields.TryGetValue(key, out var value) ? ToPerformanceStat(value) : fallback;
|
||||
}
|
||||
|
||||
private static PerformanceStat ToPerformanceStat(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
return new PerformanceStat
|
||||
{
|
||||
Min = ChildFloat(value, 0),
|
||||
Max = ChildFloat(value, 1),
|
||||
HeatExponentMultiplier = ChildFloat(value, 2),
|
||||
DurabilityExponentMultiplier = ChildFloat(value, 3),
|
||||
QualityExponent = ChildFloat(value, 4)
|
||||
};
|
||||
}
|
||||
|
||||
private static float ChildFloat(AetheriaRuntimeBehaviorValue value, int index)
|
||||
{
|
||||
return value.Children.Count > index ? (float)value.Children[index].NumberValue : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,23 +7,6 @@ using System.Linq;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Inspectable, Order(-10)]
|
||||
public class CooldownConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Cooldown(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Cooldown(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
||||
{
|
||||
private readonly PerformanceStat _cooldownDuration;
|
||||
|
|
@ -32,14 +15,16 @@ public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
|
||||
public float Progress => saturate(_cooldown);
|
||||
|
||||
public Cooldown(CooldownConfig data, EquippedItem item) : base(data, item)
|
||||
public Cooldown(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_cooldownDuration = data.Cooldown;
|
||||
_cooldownDuration = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Cooldown), _cooldownDuration);
|
||||
}
|
||||
|
||||
public Cooldown(CooldownConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
public Cooldown(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_cooldownDuration = data.Cooldown;
|
||||
_cooldownDuration = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Cooldown), _cooldownDuration);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -4,41 +4,23 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
[Inspectable, Order(-20)]
|
||||
public class EnergyDrawConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat EnergyDraw = new PerformanceStat();
|
||||
|
||||
[Inspectable]
|
||||
public bool PerSecond;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new EnergyDraw(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new EnergyDraw(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class EnergyDraw : Behavior
|
||||
{
|
||||
private readonly PerformanceStat _energyDraw;
|
||||
private readonly bool _perSecond;
|
||||
|
||||
public EnergyDraw(EnergyDrawConfig data, EquippedItem item) : base(data, item)
|
||||
public EnergyDraw(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_energyDraw = data.EnergyDraw;
|
||||
_perSecond = data.PerSecond;
|
||||
_energyDraw = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_perSecond = definition.Bool(2);
|
||||
RegisterPerformanceStat(nameof(EnergyDraw), _energyDraw);
|
||||
}
|
||||
|
||||
public EnergyDraw(EnergyDrawConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
public EnergyDraw(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_energyDraw = data.EnergyDraw;
|
||||
_perSecond = data.PerSecond;
|
||||
_energyDraw = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_perSecond = definition.Bool(2);
|
||||
RegisterPerformanceStat(nameof(EnergyDraw), _energyDraw);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -4,40 +4,23 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
[Inspectable, Order(10)]
|
||||
public class HeatConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
[Inspectable]
|
||||
public bool PerSecond;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Heat(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Heat(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Heat : Behavior
|
||||
{
|
||||
private readonly PerformanceStat _heat;
|
||||
private readonly bool _perSecond;
|
||||
|
||||
public Heat(HeatConfig data, EquippedItem item) : base(data, item)
|
||||
public Heat(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_heat = data.Heat;
|
||||
_perSecond = data.PerSecond;
|
||||
_heat = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_perSecond = definition.Bool(2);
|
||||
RegisterPerformanceStat(nameof(Heat), _heat);
|
||||
}
|
||||
public Heat(HeatConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
|
||||
public Heat(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_heat = data.Heat;
|
||||
_perSecond = data.PerSecond;
|
||||
_heat = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_perSecond = definition.Bool(2);
|
||||
RegisterPerformanceStat(nameof(Heat), _heat);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -3,34 +3,18 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Linq;
|
||||
[Inspectable, Order(-5)]
|
||||
public class ItemUsageConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
public string ItemKey;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ItemUsage(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new ItemUsage(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemUsage : Behavior
|
||||
{
|
||||
private readonly string _itemKey;
|
||||
|
||||
public ItemUsage(ItemUsageConfig data, EquippedItem item) : base(data, item)
|
||||
public ItemUsage(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_itemKey = data.ItemKey;
|
||||
_itemKey = definition.ItemKey(1);
|
||||
}
|
||||
|
||||
public ItemUsage(ItemUsageConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
public ItemUsage(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_itemKey = data.ItemKey;
|
||||
_itemKey = definition.ItemKey(1);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -5,38 +5,20 @@
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Inspectable]
|
||||
public class ReflectorConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat CrossSection = new PerformanceStat();
|
||||
|
||||
// [InspectableAnimationCurve]
|
||||
// public float4[] VisibilityCurve;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Reflector(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Reflector(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Reflector : Behavior
|
||||
{
|
||||
private readonly PerformanceStat _crossSection;
|
||||
|
||||
public Reflector(ReflectorConfig data, EquippedItem item) : base(data, item)
|
||||
public Reflector(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_crossSection = data.CrossSection;
|
||||
_crossSection = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("CrossSection", _crossSection);
|
||||
}
|
||||
|
||||
public Reflector(ReflectorConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
public Reflector(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_crossSection = data.CrossSection;
|
||||
_crossSection = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("CrossSection", _crossSection);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -4,32 +4,20 @@
|
|||
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
public class VelocityConversionConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat Lambda = new PerformanceStat();
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new VelocityConversion(this, item);
|
||||
}
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new VelocityConversion(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class VelocityConversion : Behavior
|
||||
{
|
||||
private readonly PerformanceStat _lambda;
|
||||
|
||||
public VelocityConversion(VelocityConversionConfig data, EquippedItem item) : base(data, item)
|
||||
public VelocityConversion(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_lambda = data.Lambda;
|
||||
_lambda = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("Lambda", _lambda);
|
||||
}
|
||||
public VelocityConversion(VelocityConversionConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
|
||||
public VelocityConversion(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_lambda = data.Lambda;
|
||||
_lambda = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("Lambda", _lambda);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -5,22 +5,6 @@
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Inspectable]
|
||||
public class VelocityLimitConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat TopSpeed = new PerformanceStat();
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new VelocityLimit(this, item);
|
||||
}
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new VelocityLimit(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
[Order(100)]
|
||||
public class VelocityLimit : Behavior
|
||||
{
|
||||
|
|
@ -28,15 +12,17 @@ public class VelocityLimit : Behavior
|
|||
|
||||
private readonly PerformanceStat _topSpeed;
|
||||
|
||||
public VelocityLimit(VelocityLimitConfig data, EquippedItem item) : base(data, item)
|
||||
public VelocityLimit(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_topSpeed = data.TopSpeed;
|
||||
_topSpeed = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("TopSpeed", _topSpeed);
|
||||
Limit = Evaluate(_topSpeed);
|
||||
}
|
||||
|
||||
public VelocityLimit(VelocityLimitConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
public VelocityLimit(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_topSpeed = data.TopSpeed;
|
||||
_topSpeed = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat("TopSpeed", _topSpeed);
|
||||
Limit = Evaluate(_topSpeed);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,36 +4,22 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
[Inspectable]
|
||||
public class VisibilityConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[Inspectable]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[Inspectable]
|
||||
public PerformanceStat VisibilityDecay = new PerformanceStat();
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Visibility(this, item);
|
||||
}
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Visibility(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Visibility : Behavior
|
||||
{
|
||||
private readonly PerformanceStat _visibility;
|
||||
|
||||
public Visibility(VisibilityConfig data, EquippedItem item) : base(data, item)
|
||||
public Visibility(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_visibility = data.Visibility;
|
||||
_visibility = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Visibility), _visibility);
|
||||
RegisterPerformanceStat("VisibilityDecay", definition.PerformanceStat(2, new PerformanceStat()));
|
||||
}
|
||||
public Visibility(VisibilityConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
|
||||
public Visibility(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_visibility = data.Visibility;
|
||||
_visibility = definition.PerformanceStat(1, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Visibility), _visibility);
|
||||
RegisterPerformanceStat("VisibilityDecay", definition.PerformanceStat(2, new PerformanceStat()));
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
|
|
@ -6,33 +6,18 @@ using System.Collections.Generic;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Inspectable, Order(1000)]
|
||||
public class WearConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
[InspectableTemperature]
|
||||
public bool PerSecond = true;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Wear(this, item);
|
||||
}
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Wear(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Wear : Behavior
|
||||
{
|
||||
private readonly bool _perSecond;
|
||||
|
||||
public Wear(WearConfig data, EquippedItem item) : base(data, item)
|
||||
public Wear(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
{
|
||||
_perSecond = data.PerSecond;
|
||||
_perSecond = definition.Bool(1, true);
|
||||
}
|
||||
public Wear(WearConfig data, ConsumableItemEffect item) : base(data, item)
|
||||
|
||||
public Wear(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
{
|
||||
_perSecond = data.PerSecond;
|
||||
_perSecond = definition.Bool(1, true);
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue