Port cleanbots from Nyano (#9853)

This commit is contained in:
Rane
2022-07-17 23:48:36 -04:00
committed by GitHub
parent f8b8b83657
commit 1e8efb1dd5
9 changed files with 205 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
using Content.Server.Fluids.Components;
namespace Content.Server.AI.EntitySystems
{
public sealed class GoToPuddleSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
public EntityUid GetNearbyPuddle(EntityUid cleanbot, float range = 10)
{
foreach (var entity in _lookup.GetEntitiesInRange(cleanbot, range))
{
if (HasComp<PuddleComponent>(entity))
return entity;
}
return default;
}
}
}

View File

@@ -0,0 +1,50 @@
using Content.Server.AI.Operators;
using Content.Server.AI.Operators.Generic;
using Content.Server.AI.Operators.Movement;
using Content.Server.AI.WorldState;
using Content.Server.AI.Utility.Considerations.Containers;
using Content.Server.AI.Utility.Considerations;
using Content.Server.AI.Utility.Considerations.ActionBlocker;
using Content.Server.AI.WorldState.States.Movement;
using Content.Server.AI.WorldState.States;
namespace Content.Server.AI.Utility.Actions.Bots
{
public sealed class GoToPuddleAndWait : UtilityAction
{
public EntityUid Target { get; set; } = default!;
public override void SetupOperators(Blackboard context)
{
MoveToEntityOperator moveOperator = new MoveToEntityOperator(Owner, Target, 0, 0);
float waitTime = 3f;
ActionOperators = new Queue<AiOperator>(new AiOperator[]
{
moveOperator,
new WaitOperator(waitTime),
});
}
protected override void UpdateBlackboard(Blackboard context)
{
base.UpdateBlackboard(context);
context.GetState<TargetEntityState>().SetValue(Target);
context.GetState<MoveTargetState>().SetValue(Target);
// Can just set ourselves as entity given unarmed just inherits from meleeweapon
}
protected override IReadOnlyCollection<Func<float>> GetConsiderations(Blackboard context)
{
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<CanMoveCon>()
.BoolCurve(context),
considerationsManager.Get<TargetAccessibleCon>()
.BoolCurve(context),
};
}
}
}

View File

@@ -0,0 +1,40 @@
using Content.Server.AI.Components;
using Content.Server.AI.EntitySystems;
using Content.Server.AI.Utility.Actions;
using Content.Server.AI.Utility.Actions.Bots;
using Content.Server.AI.Utility.Considerations;
using Content.Server.AI.Utility.Considerations.Combat.Melee;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.Utility.Considerations.ActionBlocker;
namespace Content.Server.AI.Utility.ExpandableActions.Bots
{
public sealed class BufferNearbyPuddlesExp : ExpandableUtilityAction
{
public override float Bonus => 30;
protected override IReadOnlyCollection<Func<float>> GetCommonConsiderations(Blackboard context)
{
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<CanMoveCon>()
.BoolCurve(context),
};
}
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out AiControllerComponent? controller))
{
throw new InvalidOperationException();
}
yield return new GoToPuddleAndWait() {Owner = owner, Target = EntitySystem.Get<GoToPuddleSystem>().GetNearbyPuddle(Owner), Bonus = Bonus};
}
}
}