Add utility AI (#806)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
metalgearsloth
2020-06-18 22:52:44 +10:00
committed by GitHub
parent 9b8cedf6c6
commit 5391d3c72a
211 changed files with 10335 additions and 527 deletions

View File

@@ -0,0 +1,23 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects.EntitySystems;
namespace Content.Server.AI.Utility.Considerations.ActionBlocker
{
public sealed class CanMoveCon : Consideration
{
public CanMoveCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var self = context.GetState<SelfState>().GetValue();
if (!ActionBlockerSystem.CanMove(self))
{
return 0.0f;
}
return 1.0f;
}
}
}

View File

@@ -0,0 +1,38 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
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)
{
_slot = slotFlags;
}
public override float GetScore(Blackboard context)
{
var inventory = context.GetState<InventoryState>().GetValue();
foreach (var entity in inventory)
{
if (!entity.TryGetComponent(out ClothingComponent clothingComponent))
{
continue;
}
if ((clothingComponent.SlotFlags & _slot) != 0)
{
return 1.0f;
}
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Clothing;
using Content.Shared.GameObjects.Components.Inventory;
namespace Content.Server.AI.Utility.Considerations.Clothing
{
public class ClothingInSlotCon : Consideration
{
private EquipmentSlotDefines.Slots _slot;
public ClothingInSlotCon(EquipmentSlotDefines.Slots slot, IResponseCurve curve) : base(curve)
{
_slot = slot;
}
public override float GetScore(Blackboard context)
{
var inventory = context.GetState<EquippedClothingState>().GetValue();
return inventory.ContainsKey(_slot) ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,25 @@
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;
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)
{
foreach (var item in context.GetState<InventoryState>().GetValue())
{
if (item.HasComponent<MeleeWeaponComponent>())
{
return 1.0f;
}
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,25 @@
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;
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)
{
var target = context.GetState<WeaponEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MeleeWeaponComponent meleeWeaponComponent))
{
return 0.0f;
}
// Just went with max health
return meleeWeaponComponent.Damage / 300.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
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;
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)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null)
{
return 0.0f;
}
return equipped.HasComponent<MeleeWeaponComponent>() ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
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;
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)
{
var target = context.GetState<WeaponEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MeleeWeaponComponent meleeWeaponComponent))
{
return 0.0f;
}
return meleeWeaponComponent.CooldownTime / 10.0f;
}
}
}

View File

@@ -0,0 +1,39 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.GameObjects.Components.Weapon.Ranged.Projectile;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Ballistic
{
public class BallisticAmmoCon : Consideration
{
public BallisticAmmoCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var weapon = context.GetState<WeaponEntityState>().GetValue();
if (weapon == null || !weapon.TryGetComponent(out BallisticMagazineWeaponComponent ballistic))
{
return 0.0f;
}
var contained = ballistic.MagazineSlot.ContainedEntity;
if (contained == null)
{
return 0.0f;
}
var mag = contained.GetComponent<BallisticMagazineComponent>();
if (mag.CountLoaded == 0)
{
// TODO: Do this better
return ballistic.GetChambered(0) != null ? 1.0f : 0.0f;
}
return (float) mag.CountLoaded / mag.Capacity;
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Weapon.Ranged.Projectile;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Ballistic
{
public class BallisticWeaponEquippedCon : Consideration
{
public BallisticWeaponEquippedCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null)
{
return 0.0f;
}
// Maybe change this to BallisticMagazineWeapon
return equipped.HasComponent<BallisticMagazineWeaponComponent>() ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Weapon.Ranged.Projectile;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Ballistic
{
public class EquippedBallisticCon : Consideration
{
public EquippedBallisticCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null || !equipped.HasComponent<BallisticMagazineWeaponComponent>())
{
return 0.0f;
}
return 1.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.Utils;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged
{
public class HasTargetLosCon : Consideration
{
public HasTargetLosCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null)
{
return 0.0f;
}
return Visibility.InLineOfSight(owner, target) ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,29 @@
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;
using Content.Server.GameObjects.Components.Weapon.Ranged;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged
{
public sealed class HeldRangedWeaponsCon : Consideration
{
public HeldRangedWeaponsCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var count = 0;
const int max = 3;
foreach (var item in context.GetState<InventoryState>().GetValue())
{
if (item.HasComponent<RangedWeaponComponent>())
{
count++;
}
}
return (float) count / max;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class EquippedHitscanCon : Consideration
{
public EquippedHitscanCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null || !equipped.HasComponent<HitscanWeaponComponent>())
{
return 0.0f;
}
return 1.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class HitscanChargeCon : Consideration
{
public HitscanChargeCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var weapon = context.GetState<WeaponEntityState>().GetValue();
if (weapon == null || !weapon.TryGetComponent(out HitscanWeaponComponent hitscanWeaponComponent))
{
return 0.0f;
}
return hitscanWeaponComponent.CapacitorComponent.Charge / hitscanWeaponComponent.CapacitorComponent.Capacity;
}
}
}

View File

@@ -0,0 +1,26 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects.Components.Power.Chargers;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class HitscanChargerFullCon : Consideration
{
public HitscanChargerFullCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null ||
!target.TryGetComponent(out WeaponCapacitorChargerComponent chargerComponent) ||
chargerComponent.HeldItem != null)
{
return 1.0f;
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects.Components.Power.Chargers;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class HitscanChargerRateCon : Consideration
{
public HitscanChargerRateCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out WeaponCapacitorChargerComponent weaponCharger))
{
return 0.0f;
}
// AI don't care about efficiency, psfft!
return weaponCharger.TransferRatio;
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class HitscanWeaponDamageCon : Consideration
{
public HitscanWeaponDamageCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var weapon = context.GetState<WeaponEntityState>().GetValue();
if (weapon == null || !weapon.TryGetComponent(out HitscanWeaponComponent hitscanWeaponComponent))
{
return 0.0f;
}
// Just went with max health
return hitscanWeaponComponent.Damage / 300.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged.Hitscan
{
public sealed class HitscanWeaponEquippedCon : Consideration
{
public HitscanWeaponEquippedCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null)
{
return 0.0f;
}
return equipped.HasComponent<HitscanWeaponComponent>() ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Weapon.Ranged;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged
{
public sealed class RangedWeaponEquippedCon : Consideration
{
public RangedWeaponEquippedCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var equipped = context.GetState<EquippedEntityState>().GetValue();
if (equipped == null || !equipped.HasComponent<RangedWeaponComponent>())
{
return 0.0f;
}
return 1.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.GameObjects.Components.Weapon.Ranged;
namespace Content.Server.AI.Utility.Considerations.Combat.Ranged
{
public class RangedWeaponFireRateCon : Consideration
{
public RangedWeaponFireRateCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var weapon = context.GetState<WeaponEntityState>().GetValue();
if (weapon == null || !weapon.TryGetComponent(out RangedWeaponComponent ranged))
{
return 0.0f;
}
return ranged.FireRate / 100.0f;
}
}
}

View File

@@ -0,0 +1,26 @@
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 TargetHealthCon : Consideration
{
public TargetHealthCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out DamageableComponent damageableComponent))
{
return 0.0f;
}
// Just went with max health
return damageableComponent.CurrentDamage[DamageType.Total] / 300.0f;
}
}
}

View File

@@ -0,0 +1,30 @@
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)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out SpeciesComponent speciesComponent))
{
return 0.0f;
}
if (speciesComponent.CurrentDamageState is CriticalState)
{
return 1.0f;
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,29 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects;
namespace Content.Server.AI.Utility.Considerations.Combat
{
public sealed class TargetIsDeadCon : Consideration
{
public TargetIsDeadCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out SpeciesComponent speciesComponent))
{
return 0.0f;
}
if (speciesComponent.CurrentDamageState is DeadState)
{
return 1.0f;
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
namespace Content.Server.AI.Utility.Considerations
{
public abstract class Consideration
{
protected IResponseCurve Curve { get; }
public Consideration(IResponseCurve curve)
{
Curve = curve;
}
public abstract float GetScore(Blackboard context);
public float ComputeResponseCurve(float score)
{
var clampedScore = Math.Clamp(score, 0.0f, 1.0f);
var curvedResponse = Math.Clamp(Curve.GetResponse(clampedScore), 0.0f, 1.0f);
return curvedResponse;
}
}
}

View File

@@ -0,0 +1,39 @@
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 Robust.Shared.Containers;
namespace Content.Server.AI.Utility.Considerations.Containers
{
/// <summary>
/// Returns 1.0f if the item is freely accessible (e.g. in storage we can open, on ground, etc.)
/// </summary>
public sealed class TargetAccessibleCon : Consideration
{
public TargetAccessibleCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null)
{
return 0.0f;
}
if (ContainerHelpers.TryGetContainer(target, out var container))
{
if (container.Owner.TryGetComponent(out EntityStorageComponent storageComponent))
{
if (storageComponent.IsWeldedShut && !storageComponent.Open)
{
return 0.0f;
}
}
}
return 1.0f;
}
}
}

View File

@@ -0,0 +1,12 @@
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;
}
}

View File

@@ -0,0 +1,36 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects;
namespace Content.Server.AI.Utility.Considerations.Hands
{
public class FreeHandCon : Consideration
{
public FreeHandCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
if (!owner.TryGetComponent(out HandsComponent handsComponent))
{
return 0.0f;
}
var handCount = 0;
var freeCount = 0;
foreach (var hand in handsComponent.ActivePriorityEnumerable())
{
handCount++;
if (handsComponent.GetHand(hand) == null)
{
freeCount += 1;
}
}
return (float) freeCount / handCount;
}
}
}

View File

@@ -0,0 +1,30 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects;
namespace Content.Server.AI.Utility.Considerations.Hands
{
/// <summary>
/// Returns 1 if in our hands else 0
/// </summary>
public sealed class TargetInOurHandsCon : Consideration
{
public TargetInOurHandsCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null ||
!target.HasComponent<ItemComponent>() ||
!owner.TryGetComponent(out HandsComponent handsComponent))
{
return 0.0f;
}
return handsComponent.IsHolding(target) ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,38 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.WorldState.States.Hands;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects;
namespace Content.Server.AI.Utility.Considerations.Inventory
{
public class CanPutTargetInHandsCon : Consideration
{
public CanPutTargetInHandsCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
// First check if target in inventory already
// If not then check if we have a free hand
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.HasComponent<ItemComponent>())
{
return 0.0f;
}
var inventory = context.GetState<InventoryState>().GetValue();
foreach (var item in inventory)
{
if (item == target)
{
return 1.0f;
}
}
return context.GetState<AnyFreeHandState>().GetValue() ? 1.0f : 0.0f;
}
}
}

View File

@@ -0,0 +1,34 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects;
namespace Content.Server.AI.Utility.Considerations.Inventory
{
public class TargetInOurInventoryCon : Consideration
{
public TargetInOurInventoryCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var inventory = context.GetState<InventoryState>().GetValue();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.HasComponent<ItemComponent>())
{
return 0.0f;
}
foreach (var item in inventory)
{
if (item == target)
{
return 1.0f;
}
}
return 0.0f;
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
namespace Content.Server.AI.Utility.Considerations.Movement
{
public sealed class DistanceCon : Consideration
{
public DistanceCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var self = context.GetState<SelfState>().GetValue();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || target.Transform.GridID != self.Transform.GridID)
{
return 0.0f;
}
// TODO: Remove 1 -
// Kind of just pulled a max distance out of nowhere. Add 0.01 just in case it's reaally far and we have no choice so it'll still be considered at least.
return 1 - ((target.Transform.GridPosition.Position - self.Transform.GridPosition.Position).Length / 100 + 0.01f);
}
}
}

View File

@@ -0,0 +1,32 @@
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.Drink
{
public sealed class DrinkValueCon : Consideration
{
public DrinkValueCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (!target.TryGetComponent(out SolutionComponent drink))
{
return 0.0f;
}
var nutritionValue = 0;
foreach (var reagent in drink.ReagentList)
{
// TODO
nutritionValue += (reagent.Quantity * 30).Int();
}
return nutritionValue / 1000.0f;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects.Components.Nutrition;
namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
{
public class ThirstCon : Consideration
{
public ThirstCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
if (!owner.TryGetComponent(out ThirstComponent thirst))
{
return 0.0f;
}
return 1 - (thirst.CurrentThirst / thirst.ThirstThresholds[ThirstThreshold.OverHydrated]);
}
}
}

View File

@@ -0,0 +1,32 @@
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
{
public sealed class FoodValueCon : Consideration
{
public FoodValueCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var target = context.GetState<TargetEntityState>().GetValue();
if (!target.TryGetComponent(out SolutionComponent food))
{
return 0.0f;
}
var nutritionValue = 0;
foreach (var reagent in food.ReagentList)
{
// TODO
nutritionValue += (reagent.Quantity * 30).Int();
}
return nutritionValue / 1000.0f;
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.AI.Utility.Curves;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects.Components.Nutrition;
namespace Content.Server.AI.Utility.Considerations.Nutrition
{
public sealed class HungerCon : Consideration
{
public HungerCon(IResponseCurve curve) : base(curve) {}
public override float GetScore(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
if (!owner.TryGetComponent(out HungerComponent hunger))
{
return 0.0f;
}
return 1 - (hunger.CurrentHunger / hunger.HungerThresholds[HungerThreshold.Overfed]);
}
}
}

View File

@@ -0,0 +1,24 @@
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;
}
}
}