GunSystem.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Numerics;
  2. using Content.Server.Cargo.Systems;
  3. using Content.Server.Interaction;
  4. using Content.Server.Power.EntitySystems;
  5. using Content.Server.Stunnable;
  6. using Content.Shared.Damage.Systems;
  7. using Content.Shared.Effects;
  8. using Content.Shared.Weapons.Ranged;
  9. using Content.Shared.Weapons.Ranged.Components;
  10. using Content.Shared.Weapons.Ranged.Events;
  11. using Content.Shared.Weapons.Ranged.Systems;
  12. using Robust.Shared.Containers;
  13. using Robust.Shared.Map;
  14. using Robust.Shared.Player;
  15. using Robust.Shared.Prototypes;
  16. using Robust.Shared.Utility;
  17. namespace Content.Server.Weapons.Ranged.Systems;
  18. public sealed partial class GunSystem : SharedGunSystem
  19. {
  20. [Dependency] private readonly IComponentFactory _factory = default!;
  21. [Dependency] private readonly BatterySystem _battery = default!;
  22. [Dependency] private readonly DamageExamineSystem _damageExamine = default!;
  23. [Dependency] private readonly PricingSystem _pricing = default!;
  24. public override void Initialize()
  25. {
  26. base.Initialize();
  27. SubscribeLocalEvent<BallisticAmmoProviderComponent, PriceCalculationEvent>(OnBallisticPrice);
  28. }
  29. private void OnBallisticPrice(EntityUid uid, BallisticAmmoProviderComponent component, ref PriceCalculationEvent args)
  30. {
  31. if (string.IsNullOrEmpty(component.Proto) || component.UnspawnedCount == 0)
  32. return;
  33. if (!ProtoManager.TryIndex<EntityPrototype>(component.Proto, out var proto))
  34. {
  35. Log.Error($"Unable to find fill prototype for price on {component.Proto} on {ToPrettyString(uid)}");
  36. return;
  37. }
  38. // Probably good enough for most.
  39. var price = _pricing.GetEstimatedPrice(proto);
  40. args.Price += price * component.UnspawnedCount;
  41. }
  42. protected override void Popup(string message, EntityUid? uid, EntityUid? user) { }
  43. protected override void CreateEffect(EntityUid gunUid, MuzzleFlashEvent message, EntityUid? user = null, EntityUid? player = null)
  44. {
  45. var filter = Filter.Pvs(gunUid, entityManager: EntityManager);
  46. if (TryComp<ActorComponent>(user, out var actor))
  47. filter.RemovePlayer(actor.PlayerSession);
  48. if (GunPrediction && TryComp(player, out actor))
  49. filter.RemovePlayer(actor.PlayerSession);
  50. RaiseNetworkEvent(message, filter);
  51. }
  52. // TODO: Pseudo RNG so the client can predict these.
  53. }