Files
tbd-station-14/Content.Server/NPC/HTN/Preconditions/GunAmmoPrecondition.cs
metalgearsloth c31c848afd 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
2023-08-01 19:48:56 -05:00

49 lines
1.3 KiB
C#

using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Server.NPC.HTN.Preconditions;
/// <summary>
/// Gets ammo for this NPC's selected gun; either active hand or itself.
/// </summary>
public sealed class GunAmmoPrecondition : HTNPrecondition
{
[Dependency] private readonly IEntityManager _entManager = default!;
[DataField("minPercent")]
public float MinPercent = 0f;
[DataField("maxPercent")]
public float MaxPercent = 1f;
public override bool IsMet(NPCBlackboard blackboard)
{
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
var gunSystem = _entManager.System<GunSystem>();
if (!gunSystem.TryGetGun(owner, out var gunUid, out _))
{
return false;
}
var ammoEv = new GetAmmoCountEvent();
_entManager.EventBus.RaiseLocalEvent(gunUid, ref ammoEv);
float percent;
if (ammoEv.Capacity == 0)
percent = 0f;
else
percent = ammoEv.Count / (float) ammoEv.Capacity;
percent = Math.Clamp(percent, 0f, 1f);
if (MaxPercent < percent)
return false;
if (MinPercent > percent)
return false;
return true;
}
}