Shooting NPCs and more (#18042)

* Add pirate shooting

* Shooting working

* Basics working

* Refactor time

* More conversion

* Update primitives

* Update yml

* weh

* Building again

* Draft

* weh

* b

* Start shutdown

* Starting to take form

* Code side done

* is it worky

* Fix prototypes

* stuff

* Shitty working

* Juke events working

* Even more cleanup

* RTX

* Fix interaction combat mode and compquery

* GetAmmoCount relays

* Fix rotation speed

* Juke fixes

* fixes

* weh

* The collision avoidance never ends

* Fixes

* Pause support

* framework

* lazy

* Fix idling

* Fix drip

* goobed

* Fix takeover shutdown bug

* Merge fixes

* shitter

* Fix carpos
This commit is contained in:
metalgearsloth
2023-08-02 10:48:56 +10:00
committed by GitHub
parent 018e465fad
commit c31c848afd
103 changed files with 2089 additions and 810 deletions

View File

@@ -1,7 +1,8 @@
using System.Numerics;
using Content.Server.NPC.Components;
using Content.Shared.CombatMode;
using Content.Shared.Interaction;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
@@ -12,6 +13,12 @@ public sealed partial class NPCCombatSystem
[Dependency] private readonly SharedCombatModeSystem _combat = default!;
[Dependency] private readonly RotateToFaceSystem _rotate = default!;
private EntityQuery<CombatModeComponent> _combatQuery;
private EntityQuery<NPCSteeringComponent> _steeringQuery;
private EntityQuery<RechargeBasicEntityAmmoComponent> _rechargeQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private EntityQuery<TransformComponent> _xformQuery;
// TODO: Don't predict for hitscan
private const float ShootSpeed = 20f;
@@ -22,6 +29,12 @@ public sealed partial class NPCCombatSystem
private void InitializeRanged()
{
_combatQuery = GetEntityQuery<CombatModeComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
_rechargeQuery = GetEntityQuery<RechargeBasicEntityAmmoComponent>();
_steeringQuery = GetEntityQuery<NPCSteeringComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
SubscribeLocalEvent<NPCRangedCombatComponent, ComponentStartup>(OnRangedStartup);
SubscribeLocalEvent<NPCRangedCombatComponent, ComponentShutdown>(OnRangedShutdown);
}
@@ -48,9 +61,6 @@ public sealed partial class NPCCombatSystem
private void UpdateRanged(float frameTime)
{
var bodyQuery = GetEntityQuery<PhysicsComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
var combatQuery = GetEntityQuery<CombatModeComponent>();
var query = EntityQueryEnumerator<NPCRangedCombatComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var comp, out var xform))
@@ -58,8 +68,15 @@ public sealed partial class NPCCombatSystem
if (comp.Status == CombatStatus.Unspecified)
continue;
if (!xformQuery.TryGetComponent(comp.Target, out var targetXform) ||
!bodyQuery.TryGetComponent(comp.Target, out var targetBody))
if (_steeringQuery.TryGetComponent(uid, out var steering) && steering.Status == SteeringStatus.NoPath)
{
comp.Status = CombatStatus.TargetUnreachable;
comp.ShootAccumulator = 0f;
continue;
}
if (!_xformQuery.TryGetComponent(comp.Target, out var targetXform) ||
!_physicsQuery.TryGetComponent(comp.Target, out var targetBody))
{
comp.Status = CombatStatus.TargetUnreachable;
comp.ShootAccumulator = 0f;
@@ -73,7 +90,7 @@ public sealed partial class NPCCombatSystem
continue;
}
if (combatQuery.TryGetComponent(uid, out var combatMode))
if (_combatQuery.TryGetComponent(uid, out var combatMode))
{
_combat.SetInCombatMode(uid, true, combatMode);
}
@@ -85,10 +102,26 @@ public sealed partial class NPCCombatSystem
continue;
}
var ammoEv = new GetAmmoCountEvent();
RaiseLocalEvent(gunUid, ref ammoEv);
if (ammoEv.Count == 0)
{
// Recharging then?
if (_rechargeQuery.HasComponent(gunUid))
{
continue;
}
comp.Status = CombatStatus.Unspecified;
comp.ShootAccumulator = 0f;
continue;
}
comp.LOSAccumulator -= frameTime;
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(xform, xformQuery);
var (targetPos, targetRot) = _transform.GetWorldPositionRotation(targetXform, xformQuery);
var worldPos = _transform.GetWorldPosition(xform);
var targetPos = _transform.GetWorldPosition(targetXform);
// We'll work out the projected spot of the target and shoot there instead of where they are.
var distance = (targetPos - worldPos).Length();
@@ -105,7 +138,7 @@ public sealed partial class NPCCombatSystem
if (!comp.TargetInLOS)
{
comp.ShootAccumulator = 0f;
comp.Status = CombatStatus.TargetUnreachable;
comp.Status = CombatStatus.NotInSight;
continue;
}
@@ -156,6 +189,7 @@ public sealed partial class NPCCombatSystem
}
_gun.AttemptShoot(uid, gunUid, gun, targetCordinates);
comp.Status = CombatStatus.Normal;
}
}
}