Hide behavior config runtime authority
This commit is contained in:
parent
3e56eadeba
commit
977fa52b18
6 changed files with 34 additions and 29 deletions
|
|
@ -12,7 +12,7 @@ using static Unity.Mathematics.noise;
|
|||
|
||||
public abstract class Behavior
|
||||
{
|
||||
public RuntimeBehaviorConfig Config { get; }
|
||||
private readonly RuntimeBehaviorConfig _config;
|
||||
public string Kind { get; }
|
||||
public int Group { get; }
|
||||
public EquippedItem Item { get; }
|
||||
|
|
@ -46,7 +46,7 @@ public abstract class Behavior
|
|||
|
||||
protected Behavior(RuntimeBehaviorConfig config, EquippedItem item)
|
||||
{
|
||||
Config = config;
|
||||
_config = config;
|
||||
Kind = config?.Kind ?? "";
|
||||
Group = config?.Group ?? 0;
|
||||
Item = item;
|
||||
|
|
@ -55,7 +55,7 @@ public abstract class Behavior
|
|||
|
||||
protected Behavior(RuntimeBehaviorConfig config, ConsumableItemEffect consumable)
|
||||
{
|
||||
Config = config;
|
||||
_config = config;
|
||||
Kind = config?.Kind ?? "";
|
||||
Group = config?.Group ?? 0;
|
||||
Consumable = consumable;
|
||||
|
|
@ -63,6 +63,23 @@ public abstract class Behavior
|
|||
}
|
||||
|
||||
public float Evaluate(PerformanceStat stat) => Item?.Evaluate(stat) ?? Consumable.Evaluate(stat);
|
||||
|
||||
public bool TryGetPerformanceStat(string statName, out PerformanceStat stat)
|
||||
{
|
||||
stat = null;
|
||||
if (_config == null || string.IsNullOrWhiteSpace(statName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var statField = _config
|
||||
.GetType()
|
||||
.GetFields()
|
||||
.FirstOrDefault(field => field.FieldType == typeof(PerformanceStat) && field.Name == statName);
|
||||
stat = statField?.GetValue(_config) as PerformanceStat;
|
||||
return stat != null;
|
||||
}
|
||||
|
||||
protected void AddHeat(float heat) => Item?.AddHeat(heat); // TODO: Heat for Consumables
|
||||
|
||||
protected void CauseDamage(float damage)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ public class StatModifierConfig : RuntimeBehaviorConfig
|
|||
[Inspectable]
|
||||
public StatModifierType Type;
|
||||
|
||||
[InspectableType(typeof(RuntimeBehaviorConfig))]
|
||||
public string RequireBehavior;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
|
|
@ -69,14 +68,7 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwa
|
|||
|
||||
private PerformanceStat FindTargetStat(Behavior behavior)
|
||||
{
|
||||
var data = behavior.Config;
|
||||
var statField = data
|
||||
.GetType()
|
||||
.GetFields()
|
||||
.Where(f => f.FieldType == typeof(PerformanceStat))
|
||||
.FirstOrDefault(f => f.Name == _data.Stat.Stat);
|
||||
|
||||
return statField?.GetValue(data) as PerformanceStat;
|
||||
return behavior.TryGetPerformanceStat(_data.Stat.Stat, out var stat) ? stat : null;
|
||||
}
|
||||
|
||||
private static bool BehaviorKindMatches(string runtimeKind, string expectedKind)
|
||||
|
|
@ -153,7 +145,6 @@ public enum StatModifierType
|
|||
[Inspectable]
|
||||
public class StatReference
|
||||
{
|
||||
[InspectableType(typeof(RuntimeBehaviorConfig))]
|
||||
public string Target;
|
||||
|
||||
[Inspectable]
|
||||
|
|
|
|||
|
|
@ -49,16 +49,6 @@ public class InspectableRangedIntAttribute : PreferredInspectorAttribute
|
|||
}
|
||||
}
|
||||
|
||||
public class InspectableTypeAttribute : PreferredInspectorAttribute
|
||||
{
|
||||
public readonly Type Type;
|
||||
|
||||
public InspectableTypeAttribute(Type type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public class OrderAttribute : Attribute
|
||||
{
|
||||
public int Order;
|
||||
|
|
|
|||
Loading…
Reference in a new issue