hands ECS (#7081)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.AI.Operators.Nutrition
|
||||
@@ -30,35 +28,23 @@ 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;
|
||||
}
|
||||
|
||||
DrinkComponent? drinkComponent = null;
|
||||
|
||||
foreach (var slot in handsComponent.ActivePriorityEnumerable())
|
||||
{
|
||||
if (handsComponent.GetItem(slot) != itemComponent) continue;
|
||||
handsComponent.ActiveHand = slot;
|
||||
if (!entities.TryGetComponent(_target, out drinkComponent))
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
// This should also implicitly open it.
|
||||
handsComponent.ActivateItem();
|
||||
_interactionCooldown = IoCManager.Resolve<IRobustRandom>().NextFloat() + 0.5f;
|
||||
}
|
||||
|
||||
if (drinkComponent == null)
|
||||
{
|
||||
if (!handsSys.TrySelect<DrinkComponent>(_owner, out var drinkComponent, handsComponent))
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
if (!handsSys.TryUseItemInHand(_owner, false, handsComponent))
|
||||
return Outcome.Failed;
|
||||
|
||||
_interactionCooldown = IoCManager.Resolve<IRobustRandom>().NextFloat() + 0.5f;
|
||||
|
||||
if (drinkComponent.Deleted || EntitySystem.Get<DrinkSystem>().IsEmpty(drinkComponent.Owner, drinkComponent)
|
||||
|| entities.TryGetComponent(_owner, out ThirstComponent? thirstComponent) &&
|
||||
@@ -67,6 +53,7 @@ namespace Content.Server.AI.Operators.Nutrition
|
||||
return Outcome.Success;
|
||||
}
|
||||
|
||||
/// uuhhh do afters for drinks might mess this up?
|
||||
return Outcome.Continuing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user