pet dehydrated fish to make him nice to you (#14709)
* petting fish to make him nice to you * fix fishe, refactor a bit * fishe * pro * feedback, for now * refactor * pro --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
17
Content.Server/NPC/Components/FactionExceptionComponent.cs
Normal file
17
Content.Server/NPC/Components/FactionExceptionComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Content.Server.NPC.Systems;
|
||||
|
||||
namespace Content.Server.NPC.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Prevents an NPC from attacking ignored entities from enemy factions.
|
||||
/// Can be added to if pettable, see PettableFriendComponent.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(FactionExceptionSystem))]
|
||||
public sealed class FactionExceptionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// List of entities that this NPC will refuse to attack
|
||||
/// </summary>
|
||||
[DataField("ignored")]
|
||||
public HashSet<EntityUid> Ignored = new();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.NPC.Components;
|
||||
using Content.Server.NPC.Pathfinding;
|
||||
using Content.Server.NPC.Systems;
|
||||
using Content.Shared.Examine;
|
||||
@@ -8,6 +9,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Shared.Map;
|
||||
//using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
|
||||
|
||||
@@ -15,6 +17,7 @@ public abstract class NPCCombatOperator : HTNOperator
|
||||
{
|
||||
[Dependency] protected readonly IEntityManager EntManager = default!;
|
||||
private FactionSystem _factions = default!;
|
||||
private FactionExceptionSystem _factionException = default!;
|
||||
protected InteractionSystem Interaction = default!;
|
||||
private PathfindingSystem _pathfinding = default!;
|
||||
|
||||
@@ -38,6 +41,7 @@ public abstract class NPCCombatOperator : HTNOperator
|
||||
base.Initialize(sysManager);
|
||||
sysManager.GetEntitySystem<ExamineSystemShared>();
|
||||
_factions = sysManager.GetEntitySystem<FactionSystem>();
|
||||
_factionException = sysManager.GetEntitySystem<FactionExceptionSystem>();
|
||||
Interaction = sysManager.GetEntitySystem<InteractionSystem>();
|
||||
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
|
||||
}
|
||||
@@ -85,6 +89,8 @@ public abstract class NPCCombatOperator : HTNOperator
|
||||
paths.Add(UpdateTarget(owner, existingTarget, existingTarget, ownerCoordinates, blackboard, radius, canMove, xformQuery, targets));
|
||||
}
|
||||
|
||||
EntManager.TryGetComponent<FactionExceptionComponent>(owner, out var factionException);
|
||||
|
||||
// TODO: Need a perception system instead
|
||||
// TODO: This will be expensive so will be good to optimise and cut corners.
|
||||
foreach (var target in _factions
|
||||
@@ -93,7 +99,8 @@ public abstract class NPCCombatOperator : HTNOperator
|
||||
if (mobQuery.TryGetComponent(target, out var mobState) &&
|
||||
mobState.CurrentState > MobState.Alive ||
|
||||
target == existingTarget ||
|
||||
target == owner)
|
||||
target == owner ||
|
||||
(factionException != null && _factionException.IsIgnored(factionException, target)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
33
Content.Server/NPC/Systems/FactionExceptionSystem.cs
Normal file
33
Content.Server/NPC/Systems/FactionExceptionSystem.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Server.NPC.Components;
|
||||
|
||||
namespace Content.Server.NPC.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Prevents an NPC from attacking some entities from an enemy faction.
|
||||
/// </summary>
|
||||
public sealed class FactionExceptionSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns whether the entity from an enemy faction won't be attacked
|
||||
/// </summary>
|
||||
public bool IsIgnored(FactionExceptionComponent comp, EntityUid target)
|
||||
{
|
||||
return comp.Ignored.Contains(target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents an entity from an enemy faction from being attacked
|
||||
/// </summary>
|
||||
public void IgnoreEntity(FactionExceptionComponent comp, EntityUid target)
|
||||
{
|
||||
comp.Ignored.Add(target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents a list of entities from an enemy faction from being attacked
|
||||
/// </summary>
|
||||
public void IgnoreEntities(FactionExceptionComponent comp, IEnumerable<EntityUid> ignored)
|
||||
{
|
||||
comp.Ignored.UnionWith(ignored);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user