Spray Nozzle & Backpack Water Tank (#16133)

This commit is contained in:
Nemanja
2023-05-05 21:50:09 -04:00
committed by GitHub
parent e80568747d
commit 98481fb9a2
30 changed files with 495 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
using Content.Shared.Inventory;
using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// This is used for relaying ammo events
/// to an entity in the user's clothing slot.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedGunSystem))]
public sealed class ClothingSlotAmmoProviderComponent : AmmoProviderComponent
{
/// <summary>
/// The slot that the ammo provider should be located in.
/// </summary>
[DataField("targetSlot", required: true)]
public SlotFlags TargetSlot;
/// <summary>
/// A whitelist for determining whether or not an ammo provider is valid.
/// </summary>
[DataField("providerWhitelist")]
public EntityWhitelist? ProviderWhitelist;
}

View File

@@ -30,6 +30,13 @@ public partial class GunComponent : Component
// These values are very small for now until we get a debug overlay and fine tune it
/// <summary>
/// A scalar value applied to the vector governing camera recoil.
/// If 0, there will be no camera recoil.
/// </summary>
[DataField("cameraRecoilScalar"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float CameraRecoilScalar = 1f;
/// <summary>
/// Last time the gun fired.
/// Used for recoil purposes.

View File

@@ -0,0 +1,42 @@
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Weapons.Ranged.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedGunSystem))]
public sealed partial class SolutionAmmoProviderComponent : Component
{
/// <summary>
/// The solution where reagents are extracted from for the projectile.
/// </summary>
[DataField("solutionId", required: true), AutoNetworkedField]
public string SolutionId = default!;
/// <summary>
/// How much reagent it costs to fire once.
/// </summary>
[DataField("fireCost"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float FireCost = 10;
/// <summary>
/// The amount of shots currently available.
/// used for network predictions.
/// </summary>
[DataField("shots"), ViewVariables, AutoNetworkedField]
public int Shots;
/// <summary>
/// The max amount of shots the gun can fire.
/// used for network prediction
/// </summary>
[DataField("maxShots"), ViewVariables, AutoNetworkedField]
public int MaxShots;
/// <summary>
/// The prototype that's fired by the gun.
/// </summary>
[DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string Prototype = default!;
}

View File

@@ -0,0 +1,55 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Inventory;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Shared.Weapons.Ranged.Systems;
public partial class SharedGunSystem
{
[Dependency] private readonly InventorySystem _inventory = default!;
private void InitializeClothing()
{
SubscribeLocalEvent<ClothingSlotAmmoProviderComponent, TakeAmmoEvent>(OnClothingTakeAmmo);
SubscribeLocalEvent<ClothingSlotAmmoProviderComponent, GetAmmoCountEvent>(OnClothingAmmoCount);
}
private void OnClothingTakeAmmo(EntityUid uid, ClothingSlotAmmoProviderComponent component, TakeAmmoEvent args)
{
if (!TryGetClothingSlotEntity(uid, component, out var entity))
return;
RaiseLocalEvent(entity.Value, args);
}
private void OnClothingAmmoCount(EntityUid uid, ClothingSlotAmmoProviderComponent component, ref GetAmmoCountEvent args)
{
if (!TryGetClothingSlotEntity(uid, component, out var entity))
return;
RaiseLocalEvent(entity.Value, ref args);
}
private bool TryGetClothingSlotEntity(EntityUid uid, ClothingSlotAmmoProviderComponent component, [NotNullWhen(true)] out EntityUid? slotEntity)
{
slotEntity = null;
if (!_container.TryGetContainingContainer(uid, out var container))
return false;
var user = container.Owner;
if (!TryComp<InventoryComponent>(user, out var inventory))
return false;
var slots = _inventory.GetSlots(user, inventory);
foreach (var slot in slots)
{
if (slot.SlotFlags != component.TargetSlot)
continue;
if (!_inventory.TryGetSlotEntity(user, slot.Name, out var e, inventory))
continue;
if (component.ProviderWhitelist != null && !component.ProviderWhitelist.IsValid(e.Value, EntityManager))
continue;
slotEntity = e;
}
return slotEntity != null;
}
}

View File

@@ -0,0 +1,60 @@
using Content.Shared.Chemistry.Components;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Map;
namespace Content.Shared.Weapons.Ranged.Systems;
public partial class SharedGunSystem
{
protected virtual void InitializeSolution()
{
SubscribeLocalEvent<SolutionAmmoProviderComponent, TakeAmmoEvent>(OnSolutionTakeAmmo);
SubscribeLocalEvent<SolutionAmmoProviderComponent, GetAmmoCountEvent>(OnSolutionAmmoCount);
}
private void OnSolutionTakeAmmo(EntityUid uid, SolutionAmmoProviderComponent component, TakeAmmoEvent args)
{
var shots = Math.Min(args.Shots, component.Shots);
// Don't dirty if it's an empty fire.
if (shots == 0)
return;
for (var i = 0; i < shots; i++)
{
args.Ammo.Add(GetSolutionShot(uid, component, args.Coordinates));
component.Shots--;
}
UpdateSolutionShots(uid, component);
UpdateSolutionAppearance(uid, component);
}
private void OnSolutionAmmoCount(EntityUid uid, SolutionAmmoProviderComponent component, ref GetAmmoCountEvent args)
{
args.Count = component.Shots;
args.Capacity = component.MaxShots;
}
protected virtual void UpdateSolutionShots(EntityUid uid, SolutionAmmoProviderComponent component, Solution? solution = null)
{
}
protected virtual (EntityUid Entity, IShootable) GetSolutionShot(EntityUid uid, SolutionAmmoProviderComponent component, EntityCoordinates position)
{
var ent = Spawn(component.Prototype, position);
return (ent, EnsureComp<AmmoComponent>(ent));
}
protected void UpdateSolutionAppearance(EntityUid uid, SolutionAmmoProviderComponent component)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;
Appearance.SetData(uid, AmmoVisuals.HasAmmo, component.Shots != 0, appearance);
Appearance.SetData(uid, AmmoVisuals.AmmoCount, component.Shots, appearance);
Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.MaxShots, appearance);
}
}

View File

@@ -79,7 +79,9 @@ public abstract partial class SharedGunSystem : EntitySystem
InitializeMagazine();
InitializeRevolver();
InitializeBasicEntity();
InitializeClothing();
InitializeContainer();
InitializeSolution();
// Interactions
SubscribeLocalEvent<GunComponent, GetVerbsEvent<AlternativeVerb>>(OnAltVerb);