Merge branch 'master' into buckle-locker-fix-1262
This commit is contained in:
@@ -56,6 +56,11 @@ namespace Content.Server.AI.WorldState
|
||||
}
|
||||
}
|
||||
|
||||
public void GetState(Type type, out IAiState state)
|
||||
{
|
||||
state = _states[type];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the AI state class
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.WorldState
|
||||
{
|
||||
@@ -22,6 +25,11 @@ namespace Content.Server.AI.WorldState
|
||||
void CheckCache();
|
||||
}
|
||||
|
||||
public interface IStoredState
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default class for state values. Also see CachedStateData and PlanningStateData
|
||||
/// </summary>
|
||||
@@ -44,7 +52,7 @@ namespace Content.Server.AI.WorldState
|
||||
/// Useful for group blackboard sharing or to avoid repeating the same action (e.g. bark phrases).
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public abstract class StoredStateData<T> : IAiState
|
||||
public abstract class StoredStateData<T> : IAiState, IStoredState
|
||||
{
|
||||
// Probably not the best class name but couldn't think of anything better
|
||||
public abstract string Name { get; }
|
||||
@@ -108,11 +116,11 @@ namespace Content.Server.AI.WorldState
|
||||
protected IEntity Owner { get; private set; }
|
||||
private bool _cached;
|
||||
protected T Value;
|
||||
private DateTime _lastCache = DateTime.Now;
|
||||
private TimeSpan _lastCache = TimeSpan.Zero;
|
||||
/// <summary>
|
||||
/// How long something stays in the cache before new values are retrieved
|
||||
/// </summary>
|
||||
protected float CacheTime { get; set; } = 2.0f;
|
||||
protected double CacheTime { get; set; } = 2.0f;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
{
|
||||
@@ -121,7 +129,9 @@ namespace Content.Server.AI.WorldState
|
||||
|
||||
public void CheckCache()
|
||||
{
|
||||
if (!_cached || (DateTime.Now - _lastCache).TotalSeconds >= CacheTime)
|
||||
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
|
||||
if (!_cached || (curTime - _lastCache).TotalSeconds >= CacheTime)
|
||||
{
|
||||
_cached = false;
|
||||
return;
|
||||
@@ -142,7 +152,7 @@ namespace Content.Server.AI.WorldState
|
||||
{
|
||||
Value = GetTrueValue();
|
||||
_cached = true;
|
||||
_lastCache = DateTime.Now;
|
||||
_lastCache = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
}
|
||||
|
||||
return Value;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
|
||||
namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
public sealed class ClothingSlotConState : PlanningStateData<EquipmentSlotDefines.Slots>
|
||||
{
|
||||
public override string Name => "ClothingSlotCon";
|
||||
public override void Reset()
|
||||
{
|
||||
Value = EquipmentSlotDefines.Slots.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
|
||||
namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
public sealed class ClothingSlotFlagConState : PlanningStateData<EquipmentSlotDefines.SlotFlags>
|
||||
{
|
||||
public override string Name => "ClothingSlotFlagCon";
|
||||
public override void Reset()
|
||||
{
|
||||
Value = EquipmentSlotDefines.SlotFlags.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,25 +6,19 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
namespace Content.Server.AI.WorldState.States.Inventory
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class InventoryState : StateData<List<IEntity>>
|
||||
public sealed class EnumerableInventoryState : StateData<IEnumerable<IEntity>>
|
||||
{
|
||||
public override string Name => "Inventory";
|
||||
public override string Name => "EnumerableInventory";
|
||||
|
||||
public override List<IEntity> GetValue()
|
||||
public override IEnumerable<IEntity> GetValue()
|
||||
{
|
||||
var inventory = new List<IEntity>();
|
||||
|
||||
if (Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
{
|
||||
foreach (var item in handsComponent.GetAllHeldItems())
|
||||
{
|
||||
inventory.Add(item.Owner);
|
||||
yield return item.Owner;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: InventoryComponent (Pockets were throwing)
|
||||
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Content.Server.AI.WorldState.States.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by the utility AI to calc the adjusted scores
|
||||
/// </summary>
|
||||
public class ConsiderationState : StoredStateData<int>
|
||||
{
|
||||
public override string Name => "Consideration";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Content.Server.AI.WorldState.States.Utility
|
||||
{
|
||||
public sealed class StoredStateIsNullState : PlanningStateData<Type>
|
||||
{
|
||||
public override string Name => "StoredStateIsNull";
|
||||
public override void Reset()
|
||||
{
|
||||
Value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user