This commit is contained in:
Leon Friedrich
2022-03-17 20:13:31 +13:00
committed by GitHub
parent 7b84362901
commit bfd95c493b
94 changed files with 1454 additions and 2185 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.Hands.Components;
using Content.Server.Nutrition.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Nutrition.Components;
using Robust.Shared.GameObjects;
@@ -29,35 +30,21 @@ namespace Content.Server.AI.Operators.Nutrition
}
var entities = IoCManager.Resolve<IEntityManager>();
var sysMan = IoCManager.Resolve<IEntitySystemManager>();
var handsSys = sysMan.GetEntitySystem<SharedHandsSystem>();
// TODO: Also have this check storage a la backpack etc.
if (entities.Deleted(_target) ||
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent) ||
!entities.TryGetComponent(_target, out SharedItemComponent? itemComponent))
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent))
{
return Outcome.Failed;
}
FoodComponent? foodComponent = null;
foreach (var slot in handsComponent.ActivePriorityEnumerable())
{
if (handsComponent.GetItem(slot) != itemComponent) continue;
handsComponent.ActiveHand = slot;
if (!entities.TryGetComponent(_target, out foodComponent))
{
return Outcome.Failed;
}
// This should also implicitly open it.
handsComponent.ActivateItem();
_interactionCooldown = IoCManager.Resolve<IRobustRandom>().NextFloat() + 0.5f;
}
if (foodComponent == null)
{
if (!handsSys.TrySelect<FoodComponent>(_owner, out var foodComponent, handsComponent))
return Outcome.Failed;
if (!handsSys.TryUseItemInHand(_owner, false, handsComponent))
return Outcome.Failed;
}
if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
foodComponent.UsesRemaining == 0 ||
@@ -67,6 +54,7 @@ namespace Content.Server.AI.Operators.Nutrition
return Outcome.Success;
}
/// do afters for food might mess this up?
return Outcome.Continuing;
}
}