Merge branch 'master' into buckle-locker-fix-1262
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
@@ -9,9 +8,7 @@ namespace Content.Server.AI.Utility.Considerations.ActionBlocker
|
||||
{
|
||||
public sealed class CanMoveCon : Consideration
|
||||
{
|
||||
public CanMoveCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var self = context.GetState<SelfState>().GetValue();
|
||||
if (!ActionBlockerSystem.CanMove(self))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -8,25 +8,27 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
|
||||
{
|
||||
public sealed class ClothingInInventoryCon : Consideration
|
||||
{
|
||||
private readonly EquipmentSlotDefines.SlotFlags _slot;
|
||||
|
||||
public ClothingInInventoryCon(EquipmentSlotDefines.SlotFlags slotFlags, IResponseCurve curve) : base(curve)
|
||||
public ClothingInInventoryCon Slot(EquipmentSlotDefines.SlotFlags slotFlags, Blackboard context)
|
||||
{
|
||||
_slot = slotFlags;
|
||||
// Ideally we'd just use a variable but then if we were iterating through multiple AI at once it'd be
|
||||
// Stuffed so we need to store it on the AI's context.
|
||||
context.GetState<ClothingSlotFlagConState>().SetValue(slotFlags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var inventory = context.GetState<InventoryState>().GetValue();
|
||||
var slots = context.GetState<ClothingSlotConState>().GetValue();
|
||||
var slotFlags = EquipmentSlotDefines.SlotMasks[slots];
|
||||
|
||||
foreach (var entity in inventory)
|
||||
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
|
||||
{
|
||||
if (!entity.TryGetComponent(out ClothingComponent clothingComponent))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((clothingComponent.SlotFlags & _slot) != 0)
|
||||
if ((clothingComponent.SlotFlags & slotFlags) != 0)
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -7,18 +6,18 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
|
||||
{
|
||||
public class ClothingInSlotCon : Consideration
|
||||
{
|
||||
private EquipmentSlotDefines.Slots _slot;
|
||||
|
||||
public ClothingInSlotCon(EquipmentSlotDefines.Slots slot, IResponseCurve curve) : base(curve)
|
||||
public ClothingInSlotCon Slot(EquipmentSlotDefines.Slots slot, Blackboard context)
|
||||
{
|
||||
_slot = slot;
|
||||
context.GetState<ClothingSlotConState>().SetValue(slot);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var slot = context.GetState<ClothingSlotConState>().GetValue();
|
||||
var inventory = context.GetState<EquippedClothingState>().GetValue();
|
||||
|
||||
return inventory.ContainsKey(_slot) ? 1.0f : 0.0f;
|
||||
return inventory.ContainsKey(slot) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class CanUnarmedCombatCon : Consideration
|
||||
{
|
||||
public CanUnarmedCombatCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
return context.GetState<SelfState>().GetValue().HasComponent<UnarmedCombatComponent>() ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
@@ -7,11 +6,9 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class HasMeleeWeaponCon : Consideration
|
||||
{
|
||||
public HasMeleeWeaponCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
foreach (var item in context.GetState<InventoryState>().GetValue())
|
||||
foreach (var item in context.GetState<EnumerableInventoryState>().GetValue())
|
||||
{
|
||||
if (item.HasComponent<MeleeWeaponComponent>())
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Combat;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class MeleeWeaponDamageCon : Consideration
|
||||
{
|
||||
public MeleeWeaponDamageCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<WeaponEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class MeleeWeaponEquippedCon : Consideration
|
||||
{
|
||||
public MeleeWeaponEquippedCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var equipped = context.GetState<EquippedEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Combat;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class MeleeWeaponSpeedCon : Consideration
|
||||
{
|
||||
public MeleeWeaponSpeedCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<WeaponEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
@@ -8,9 +7,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
|
||||
{
|
||||
public sealed class TargetHealthCon : Consideration
|
||||
{
|
||||
public TargetHealthCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Combat
|
||||
{
|
||||
public sealed class TargetIsCritCon : Consideration
|
||||
{
|
||||
public TargetIsCritCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
|
||||
{
|
||||
public sealed class TargetIsDeadCon : Consideration
|
||||
{
|
||||
public TargetIsDeadCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,25 +1,67 @@
|
||||
using System;
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Utility;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations
|
||||
{
|
||||
public abstract class Consideration
|
||||
{
|
||||
protected IResponseCurve Curve { get; }
|
||||
protected abstract float GetScore(Blackboard context);
|
||||
|
||||
public Consideration(IResponseCurve curve)
|
||||
private float GetAdjustedScore(Blackboard context)
|
||||
{
|
||||
Curve = curve;
|
||||
var score = GetScore(context);
|
||||
var considerationsCount = context.GetState<ConsiderationState>().GetValue();
|
||||
var modificationFactor = 1.0f - 1.0f / considerationsCount;
|
||||
var makeUpValue = (1.0f - score) * modificationFactor;
|
||||
var adjustedScore = score + makeUpValue * score;
|
||||
return Math.Clamp(adjustedScore, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
public abstract float GetScore(Blackboard context);
|
||||
|
||||
public float ComputeResponseCurve(float score)
|
||||
public Func<float> BoolCurve(Blackboard context)
|
||||
{
|
||||
var clampedScore = Math.Clamp(score, 0.0f, 1.0f);
|
||||
var curvedResponse = Math.Clamp(Curve.GetResponse(clampedScore), 0.0f, 1.0f);
|
||||
return curvedResponse;
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return adjustedScore == 1.0f ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public Func<float> InverseBoolCurve(Blackboard context)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return adjustedScore == 1.0f ? 0.0f : 1.0f;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public Func<float> LogisticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
return Math.Clamp(exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * adjustedScore + xOffset))) + yOffset, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public Func<float> QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
return Math.Clamp(slope * (float) Math.Pow(adjustedScore - xOffset, exponent) + yOffset, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations
|
||||
{
|
||||
public class ConsiderationsManager
|
||||
{
|
||||
private Dictionary<Type, Consideration> _considerations = new Dictionary<Type, Consideration>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
||||
|
||||
foreach (var conType in reflectionManager.GetAllChildren(typeof(Consideration)))
|
||||
{
|
||||
var con = (Consideration) typeFactory.CreateInstance(conType);
|
||||
_considerations.Add(conType, con);
|
||||
}
|
||||
}
|
||||
|
||||
public T Get<T>() where T : Consideration
|
||||
{
|
||||
return (T) _considerations[typeof(T)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -13,9 +11,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers
|
||||
/// </summary>
|
||||
public sealed class TargetAccessibleCon : Consideration
|
||||
{
|
||||
public TargetAccessibleCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
if (target == null)
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations
|
||||
{
|
||||
public class DummyCon : Consideration
|
||||
{
|
||||
public DummyCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context) => 1.0f;
|
||||
protected override float GetScore(Blackboard context) => 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Hands
|
||||
{
|
||||
public class FreeHandCon : Consideration
|
||||
{
|
||||
public FreeHandCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
@@ -11,9 +10,7 @@ namespace Content.Server.AI.Utility.Considerations.Hands
|
||||
/// </summary>
|
||||
public sealed class TargetInOurHandsCon : Consideration
|
||||
{
|
||||
public TargetInOurHandsCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Hands;
|
||||
@@ -9,9 +8,7 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
{
|
||||
public class CanPutTargetInHandsCon : Consideration
|
||||
{
|
||||
public CanPutTargetInHandsCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
// First check if target in inventory already
|
||||
// If not then check if we have a free hand
|
||||
@@ -22,9 +19,7 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
var inventory = context.GetState<InventoryState>().GetValue();
|
||||
|
||||
foreach (var item in inventory)
|
||||
foreach (var item in context.GetState<EnumerableInventoryState>().GetValue())
|
||||
{
|
||||
if (item == target)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
@@ -8,11 +7,8 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
{
|
||||
public class TargetInOurInventoryCon : Consideration
|
||||
{
|
||||
public TargetInOurInventoryCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var inventory = context.GetState<InventoryState>().GetValue();
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
if (target == null || !target.HasComponent<ItemComponent>())
|
||||
@@ -20,7 +16,7 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
foreach (var item in inventory)
|
||||
foreach (var item in context.GetState<EnumerableInventoryState>().GetValue())
|
||||
{
|
||||
if (item == target)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
|
||||
@@ -6,9 +5,7 @@ namespace Content.Server.AI.Utility.Considerations.Movement
|
||||
{
|
||||
public sealed class DistanceCon : Consideration
|
||||
{
|
||||
public DistanceCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var self = context.GetState<SelfState>().GetValue();
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
@@ -7,9 +6,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
|
||||
{
|
||||
public sealed class DrinkValueCon : Consideration
|
||||
{
|
||||
public DrinkValueCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
@@ -8,9 +7,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
|
||||
{
|
||||
public class ThirstCon : Consideration
|
||||
{
|
||||
public ThirstCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Nutrition
|
||||
namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
|
||||
{
|
||||
public sealed class FoodValueCon : Consideration
|
||||
{
|
||||
public FoodValueCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Shared.GameObjects.Components.Nutrition;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Nutrition
|
||||
namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
|
||||
{
|
||||
|
||||
public sealed class HungerCon : Consideration
|
||||
{
|
||||
public HungerCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Utility;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple NullCheck on a StoredState
|
||||
/// </summary>
|
||||
public sealed class StoredStateEntityIsNullCon : Consideration
|
||||
{
|
||||
public StoredStateEntityIsNullCon Set(Type type, Blackboard context)
|
||||
{
|
||||
// Ideally we'd just use a variable but then if we were iterating through multiple AI at once it'd be
|
||||
// Stuffed so we need to store it on the AI's context.
|
||||
context.GetState<StoredStateIsNullState>().SetValue(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var stateData = context.GetState<StoredStateIsNullState>().GetValue();
|
||||
return stateData == null ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple NullCheck on a StoredState
|
||||
/// </summary>
|
||||
public sealed class StoredStateIsNullCon<T, U> : Consideration where T : StoredStateData<U>
|
||||
{
|
||||
public StoredStateIsNullCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
{
|
||||
var state = context.GetState<T>();
|
||||
if (state.GetValue() == null)
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user