diff --git a/Content.Server/NPC/Components/NPCRangedCombatComponent.cs b/Content.Server/NPC/Components/NPCRangedCombatComponent.cs index 2e4fcf5298b4a1..a262d8567ef6ca 100644 --- a/Content.Server/NPC/Components/NPCRangedCombatComponent.cs +++ b/Content.Server/NPC/Components/NPCRangedCombatComponent.cs @@ -1,4 +1,5 @@ using Content.Server.NPC.Systems; +using Content.Shared.Physics; using Robust.Shared.Audio; namespace Content.Server.NPC.Components; @@ -54,4 +55,9 @@ public sealed partial class NPCRangedCombatComponent : Component /// [ViewVariables(VVAccess.ReadWrite)] public SoundSpecifier? SoundTargetInLOS; + + //SS220 Change laser turrets AI begin + [ViewVariables(VVAccess.ReadWrite)] + public CollisionGroup? CollisionGroup; + //SS220 Change laser turrets AI end } diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Combat/Ranged/GunOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Combat/Ranged/GunOperator.cs index 53c5ed19522b3a..798f9055bc7bb8 100644 --- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Combat/Ranged/GunOperator.cs +++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Combat/Ranged/GunOperator.cs @@ -4,6 +4,8 @@ using Content.Shared.CombatMode; using Content.Shared.Mobs; using Content.Shared.Mobs.Components; +using Content.Shared.Physics; +using Content.Shared.Weapons.Ranged.Components; using Robust.Shared.Audio; namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Combat.Ranged; @@ -68,6 +70,14 @@ public override void Startup(NPCBlackboard blackboard) { ranged.SoundTargetInLOS = losSound; } + + //SS220 Change laser turrets AI begin + var owner = blackboard.GetValue(NPCBlackboard.Owner); + if (_entManager.HasComponent(owner)) + { + ranged.CollisionGroup = CollisionGroup.Opaque; + } + //SS220 Change laser turrets AI end } public void ConditionalShutdown(NPCBlackboard blackboard) diff --git a/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs b/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs index d7196ea73c71dc..12ec884e7c2080 100644 --- a/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs +++ b/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs @@ -133,7 +133,14 @@ private void UpdateRanged(float frameTime) { comp.LOSAccumulator += UnoccludedCooldown; // For consistency with NPC steering. - comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f); + + //SS220 Change laser turrets AI begin + //comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f); + if (comp.CollisionGroup is { } collisionMask) + comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f, collisionMask); + else + comp.TargetInLOS = _interaction.InRangeUnobstructed(uid, comp.Target, distance + 0.1f); + //SS220 Change laser turrets AI end } if (!comp.TargetInLOS) diff --git a/Content.Server/SS220/NPC/TargetInLOSIgnoreWindowsPrecondition.cs b/Content.Server/SS220/NPC/TargetInLOSIgnoreWindowsPrecondition.cs new file mode 100644 index 00000000000000..9000318764b04a --- /dev/null +++ b/Content.Server/SS220/NPC/TargetInLOSIgnoreWindowsPrecondition.cs @@ -0,0 +1,37 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt +using Content.Server.Interaction; +using Content.Server.NPC; +using Content.Server.NPC.HTN.Preconditions; +using Content.Shared.Physics; + +namespace Content.Server.SS220.NPC; + +public sealed partial class TargetInLOSOpaqueCollisionPrecondition : HTNPrecondition +{ + [Dependency] private readonly IEntityManager _entManager = default!; + private InteractionSystem _interaction = default!; + + [DataField("targetKey")] + public string TargetKey = "Target"; + + [DataField("rangeKey")] + public string RangeKey = "RangeKey"; + + public override void Initialize(IEntitySystemManager sysManager) + { + base.Initialize(sysManager); + _interaction = sysManager.GetEntitySystem(); + } + + public override bool IsMet(NPCBlackboard blackboard) + { + var owner = blackboard.GetValue(NPCBlackboard.Owner); + + if (!blackboard.TryGetValue(TargetKey, out var target, _entManager)) + return false; + + var range = blackboard.GetValueOrDefault(RangeKey, _entManager); + + return _interaction.InRangeUnobstructed(owner, target, range, CollisionGroup.Opaque); + } +} diff --git a/Resources/Prototypes/SS220/Entities/Objects/Weapons/Guns/turrets.yml b/Resources/Prototypes/SS220/Entities/Objects/Weapons/Guns/turrets.yml index fbe90905c4bb78..1ea58d9ebdd544 100644 --- a/Resources/Prototypes/SS220/Entities/Objects/Weapons/Guns/turrets.yml +++ b/Resources/Prototypes/SS220/Entities/Objects/Weapons/Guns/turrets.yml @@ -75,7 +75,7 @@ startingCharge: 500 - type: HTN rootTask: - task: TurretCompound + task: LaserTurretCompound blackboard: RotateSpeed: !type:Single 5 diff --git a/Resources/Prototypes/SS220/NPCs/turrets.yml b/Resources/Prototypes/SS220/NPCs/turrets.yml new file mode 100644 index 00000000000000..b164acdb578a86 --- /dev/null +++ b/Resources/Prototypes/SS220/NPCs/turrets.yml @@ -0,0 +1,31 @@ +- type: htnCompound + id: LaserTurretCompound + branches: + - tasks: + - !type:HTNPrimitiveTask + operator: !type:UtilityOperator + proto: NearbyGunTargets + + - !type:HTNPrimitiveTask + preconditions: + - !type:KeyExistsPrecondition + key: Target + - !type:TargetInRangePrecondition + targetKey: Target + # TODO: Non-scuffed + rangeKey: RangedRange + - !type:TargetInLOSOpaqueCollisionPrecondition + targetKey: Target + rangeKey: RangedRange + operator: !type:GunOperator + targetKey: Target + requireLOS: true + services: + - !type:UtilityService + id: RangedService + proto: NearbyGunTargets + key: Target + + - tasks: + - !type:HTNCompoundTask + task: IdleSpinCompound