Enable nullability in Content.Server (#3685)
This commit is contained in:
@@ -32,16 +32,16 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class StateData<T> : IAiState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity Owner { get; private set; }
|
||||
protected IEntity Owner { get; private set; } = default!;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
public abstract T GetValue();
|
||||
public abstract T? GetValue();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// For when we want to set StateData but not reset it when re-planning actions
|
||||
/// Useful for group blackboard sharing or to avoid repeating the same action (e.g. bark phrases).
|
||||
@@ -51,21 +51,21 @@ namespace Content.Server.AI.WorldState
|
||||
{
|
||||
// Probably not the best class name but couldn't think of anything better
|
||||
public abstract string Name { get; }
|
||||
private IEntity Owner { get; set; }
|
||||
private IEntity? Owner { get; set; }
|
||||
|
||||
private T _value;
|
||||
private T? _value;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
public virtual void SetValue(T value)
|
||||
public virtual void SetValue(T? value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public T GetValue()
|
||||
public T? GetValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
@@ -79,8 +79,8 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class PlanningStateData<T> : IAiState, IPlanningState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity Owner { get; private set; }
|
||||
protected T Value;
|
||||
protected IEntity? Owner { get; private set; }
|
||||
protected T? Value;
|
||||
|
||||
public void Setup(IEntity owner)
|
||||
{
|
||||
@@ -89,12 +89,12 @@ namespace Content.Server.AI.WorldState
|
||||
|
||||
public abstract void Reset();
|
||||
|
||||
public T GetValue()
|
||||
public T? GetValue()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public virtual void SetValue(T value)
|
||||
public virtual void SetValue(T? value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
@@ -108,9 +108,9 @@ namespace Content.Server.AI.WorldState
|
||||
public abstract class CachedStateData<T> : IAiState, ICachedState
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
protected IEntity Owner { get; private set; }
|
||||
protected IEntity Owner { get; private set; } = default!;
|
||||
private bool _cached;
|
||||
protected T Value;
|
||||
protected T Value = default!;
|
||||
private TimeSpan _lastCache = TimeSpan.Zero;
|
||||
/// <summary>
|
||||
/// How long something stays in the cache before new values are retrieved
|
||||
@@ -125,7 +125,7 @@ namespace Content.Server.AI.WorldState
|
||||
public void CheckCache()
|
||||
{
|
||||
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
|
||||
|
||||
if (!_cached || (curTime - _lastCache).TotalSeconds >= CacheTime)
|
||||
{
|
||||
_cached = false;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
var result = new Dictionary<EquipmentSlotDefines.Slots, IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out InventoryComponent inventoryComponent))
|
||||
if (!Owner.TryGetComponent(out InventoryComponent? inventoryComponent))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Content.Server.AI.WorldState.States.Clothing
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.AI.WorldState.States.Combat.Nearby
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Content.Server.AI.WorldState.States.Hands
|
||||
public override string Name => "AnyFreeHand";
|
||||
public override bool GetValue()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!Owner.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Server.AI.WorldState.States.Hands
|
||||
{
|
||||
var result = new List<string>();
|
||||
|
||||
if (!Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!Owner.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Server.AI.WorldState.States.Hands
|
||||
public override List<IEntity> GetValue()
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
if (!Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!Owner.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
{
|
||||
public override string Name => "EquippedEntity";
|
||||
|
||||
public override IEntity GetValue()
|
||||
public override IEntity? GetValue()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!Owner.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
|
||||
public override IEnumerable<IEntity> GetValue()
|
||||
{
|
||||
if (Owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (Owner.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
foreach (var item in handsComponent.GetAllHeldItems())
|
||||
{
|
||||
if (item.Owner.Deleted)
|
||||
continue;
|
||||
|
||||
|
||||
yield return item.Owner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
// Fine for now I guess
|
||||
public override string Name => "LastOpenedStorage";
|
||||
|
||||
public override void SetValue(IEntity value)
|
||||
public override void SetValue(IEntity? value)
|
||||
{
|
||||
base.SetValue(value);
|
||||
if (value != null && !value.HasComponent<EntityStorageComponent>())
|
||||
@@ -23,4 +23,4 @@ namespace Content.Server.AI.WorldState.States.Inventory
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.AI.WorldState.States.Mobs
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Content.Server.AI.WorldState.States.Mobs
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -27,6 +27,11 @@ namespace Content.Server.AI.WorldState.States.Mobs
|
||||
|
||||
foreach (var player in nearbyPlayers)
|
||||
{
|
||||
if (player.AttachedEntity == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.AttachedEntity != Owner && player.AttachedEntity.HasComponent<IDamageableComponent>())
|
||||
{
|
||||
result.Add(player.AttachedEntity);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
|
||||
public override bool GetValue()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out HungerComponent hungerComponent))
|
||||
if (!Owner.TryGetComponent(out HungerComponent? hungerComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
{
|
||||
var result = new List<IEntity>();
|
||||
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
||||
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Content.Server.AI.WorldState.States.Nutrition
|
||||
|
||||
public override bool GetValue()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out ThirstComponent thirstComponent))
|
||||
if (!Owner.TryGetComponent(out ThirstComponent? thirstComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user