Add xenos (#1204)
* Add xenos for stress test Pretty hacky and not how I'd do it long-term * Remove claws * Add in unarmed combat behaviors * Cleanuppppp Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Operators.Combat
|
||||
namespace Content.Server.AI.Operators.Combat.Melee
|
||||
{
|
||||
public class SwingMeleeWeaponOperator : AiOperator
|
||||
{
|
||||
@@ -41,6 +41,15 @@ namespace Content.Server.AI.Operators.Combat
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Shutdown(Outcome outcome)
|
||||
{
|
||||
base.Shutdown(outcome);
|
||||
if (_owner.TryGetComponent(out CombatModeComponent combatModeComponent))
|
||||
{
|
||||
combatModeComponent.IsInCombatMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override Outcome Execute(float frameTime)
|
||||
{
|
||||
@@ -70,5 +79,4 @@ namespace Content.Server.AI.Operators.Combat
|
||||
return Outcome.Continuing;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Operators.Combat.Melee
|
||||
{
|
||||
public sealed class UnarmedCombatOperator : AiOperator
|
||||
{
|
||||
private float _burstTime;
|
||||
private float _elapsedTime;
|
||||
|
||||
private readonly IEntity _owner;
|
||||
private readonly IEntity _target;
|
||||
private UnarmedCombatComponent _unarmedCombat;
|
||||
|
||||
public UnarmedCombatOperator(IEntity owner, IEntity target, float burstTime = 1.0f)
|
||||
{
|
||||
_owner = owner;
|
||||
_target = target;
|
||||
_burstTime = burstTime;
|
||||
}
|
||||
|
||||
public override bool TryStartup()
|
||||
{
|
||||
if (!base.TryStartup())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_owner.TryGetComponent(out CombatModeComponent combatModeComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!combatModeComponent.IsInCombatMode)
|
||||
{
|
||||
combatModeComponent.IsInCombatMode = true;
|
||||
}
|
||||
|
||||
if (_owner.TryGetComponent(out UnarmedCombatComponent unarmedCombatComponent))
|
||||
{
|
||||
_unarmedCombat = unarmedCombatComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Shutdown(Outcome outcome)
|
||||
{
|
||||
base.Shutdown(outcome);
|
||||
if (_owner.TryGetComponent(out CombatModeComponent combatModeComponent))
|
||||
{
|
||||
combatModeComponent.IsInCombatMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override Outcome Execute(float frameTime)
|
||||
{
|
||||
if (_burstTime <= _elapsedTime)
|
||||
{
|
||||
return Outcome.Success;
|
||||
}
|
||||
|
||||
if (_unarmedCombat.Deleted)
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
if ((_target.Transform.GridPosition.Position - _owner.Transform.GridPosition.Position).Length >
|
||||
_unarmedCombat.Range)
|
||||
{
|
||||
return Outcome.Failed;
|
||||
}
|
||||
|
||||
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
|
||||
interactionSystem.UseItemInHand(_owner, _target.Transform.GridPosition, _target.Uid);
|
||||
_elapsedTime += frameTime;
|
||||
return Outcome.Continuing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Combat;
|
||||
using Content.Server.AI.Operators.Combat.Melee;
|
||||
using Content.Server.AI.Operators.Movement;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat;
|
||||
@@ -17,11 +18,11 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class MeleeAttackEntity : UtilityAction
|
||||
public sealed class MeleeWeaponAttackEntity : UtilityAction
|
||||
{
|
||||
private IEntity _entity;
|
||||
|
||||
public MeleeAttackEntity(IEntity owner, IEntity entity, float weight) : base(owner)
|
||||
public MeleeWeaponAttackEntity(IEntity owner, IEntity entity, float weight) : base(owner)
|
||||
{
|
||||
_entity = entity;
|
||||
Bonus = weight;
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Combat.Melee;
|
||||
using Content.Server.AI.Operators.Movement;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Combat;
|
||||
using Content.Server.AI.WorldState.States.Movement;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
{
|
||||
public sealed class UnarmedAttackEntity : UtilityAction
|
||||
{
|
||||
private IEntity _entity;
|
||||
|
||||
public UnarmedAttackEntity(IEntity owner, IEntity entity, float weight) : base(owner)
|
||||
{
|
||||
_entity = entity;
|
||||
Bonus = weight;
|
||||
}
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
MoveToEntityOperator moveOperator;
|
||||
if (Owner.TryGetComponent(out UnarmedCombatComponent unarmedCombatComponent))
|
||||
{
|
||||
moveOperator = new MoveToEntityOperator(Owner, _entity, unarmedCombatComponent.Range - 0.01f);
|
||||
}
|
||||
// I think it's possible for this to happen given planning is time-sliced?
|
||||
// TODO: At this point we should abort
|
||||
else
|
||||
{
|
||||
moveOperator = new MoveToEntityOperator(Owner, _entity);
|
||||
}
|
||||
|
||||
ActionOperators = new Queue<AiOperator>(new AiOperator[]
|
||||
{
|
||||
moveOperator,
|
||||
new UnarmedCombatOperator(Owner, _entity),
|
||||
});
|
||||
}
|
||||
|
||||
protected override void UpdateBlackboard(Blackboard context)
|
||||
{
|
||||
base.UpdateBlackboard(context);
|
||||
context.GetState<TargetEntityState>().SetValue(_entity);
|
||||
context.GetState<MoveTargetState>().SetValue(_entity);
|
||||
// Can just set ourselves as entity given unarmed just inherits from meleeweapon
|
||||
context.GetState<WeaponEntityState>().SetValue(Owner);
|
||||
}
|
||||
|
||||
protected override Consideration[] Considerations { get; } = {
|
||||
new CanUnarmedCombatCon(
|
||||
new BoolCurve()),
|
||||
// Don't attack a dead target
|
||||
new TargetIsDeadCon(
|
||||
new InverseBoolCurve()),
|
||||
// Deprioritise a target in crit
|
||||
new TargetIsCritCon(
|
||||
new QuadraticCurve(-0.8f, 1.0f, 1.0f, 0.0f)),
|
||||
// Somewhat prioritise distance
|
||||
new DistanceCon(
|
||||
new QuadraticCurve(-1.0f, 1.0f, 1.02f, 0.0f)),
|
||||
// Prefer weaker targets
|
||||
new TargetHealthCon(
|
||||
new QuadraticCurve(1.0f, 0.4f, 0.0f, -0.02f)),
|
||||
// TODO: Consider our Speed and Damage to compare this to using a weapon
|
||||
// Also need to unequip our weapon if we have one (xenos can't hold one so no issue for now)
|
||||
};
|
||||
}
|
||||
}
|
||||
18
Content.Server/AI/Utility/AiLogic/Mimic.cs
Normal file
18
Content.Server/AI/Utility/AiLogic/Mimic.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Content.Server.AI.Utility.BehaviorSets;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.AI;
|
||||
|
||||
namespace Content.Server.AI.Utility.AiLogic
|
||||
{
|
||||
[AiLogicProcessor("Mimic")]
|
||||
[UsedImplicitly]
|
||||
public sealed class Mimic : UtilityAi
|
||||
{
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
AddBehaviorSet(new UnarmedAttackPlayersBehaviorSet(SelfEntity), false);
|
||||
SortActions();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Content.Server/AI/Utility/AiLogic/Xeno.cs
Normal file
19
Content.Server/AI/Utility/AiLogic/Xeno.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Content.Server.AI.Utility.BehaviorSets;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.AI;
|
||||
|
||||
namespace Content.Server.AI.Utility.AiLogic
|
||||
{
|
||||
[AiLogicProcessor("Xeno")]
|
||||
[UsedImplicitly]
|
||||
public sealed class Xeno : UtilityAi
|
||||
{
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
AddBehaviorSet(new IdleBehaviorSet(SelfEntity), false);
|
||||
AddBehaviorSet(new UnarmedAttackPlayersBehaviorSet(SelfEntity), false);
|
||||
SortActions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.ExpandableActions.Combat.Melee;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.AI.Utility.BehaviorSets
|
||||
{
|
||||
public sealed class UnarmedAttackPlayersBehaviorSet : BehaviorSet
|
||||
{
|
||||
public UnarmedAttackPlayersBehaviorSet(IEntity owner) : base(owner)
|
||||
{
|
||||
Actions = new IAiUtility[]
|
||||
{
|
||||
new UnarmedAttackNearbyPlayerExp(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Combat.Melee
|
||||
{
|
||||
public sealed class CanUnarmedCombatCon : Consideration
|
||||
{
|
||||
public CanUnarmedCombatCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
{
|
||||
return context.GetState<SelfState>().GetValue().HasComponent<UnarmedCombatComponent>() ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
if (entity.HasComponent<BasicActorComponent>() && entity != owner)
|
||||
{
|
||||
yield return new MeleeAttackEntity(owner, entity, Bonus);
|
||||
yield return new MeleeWeaponAttackEntity(owner, entity, Bonus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
foreach (var entity in context.GetState<NearbySpeciesState>().GetValue())
|
||||
{
|
||||
yield return new MeleeAttackEntity(owner, entity, Bonus);
|
||||
yield return new MeleeWeaponAttackEntity(owner, entity, Bonus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.Utils;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
public sealed class UnarmedAttackNearbyPlayerExp : ExpandableUtilityAction
|
||||
{
|
||||
public override float Bonus => UtilityAction.CombatBonus;
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
if (!owner.TryGetComponent(out AiControllerComponent controller))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
foreach (var entity in Visibility.GetEntitiesInRange(owner.Transform.GridPosition, typeof(SpeciesComponent),
|
||||
controller.VisionRadius))
|
||||
{
|
||||
if (entity.HasComponent<BasicActorComponent>() && entity != owner)
|
||||
{
|
||||
yield return new UnarmedAttackEntity(owner, entity, Bonus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user