* Start adding flashy flash * Change slop Might give a smoother decline * flashy flash * Add flashbang and flash projectiles Bang bang bang pull my flash trigger * Add collision check to area flash * Flash cleanupo * flash.ogg mixed to mono * Adjusted flash curve again * Enhancing flashes with unshaded and lights and shit Still a WIP * Add the other ballistic gun types Re-organised some of the gun stuff so the powercell guns share the shooting code with the ballistic guns. * Re-merging branch with master Also fixed some visualizer bugs * Last cleanup Fixed some crashes Fixed Deckard sprite Fixed Hitscan effects Re-applied master changes Re-factor to using soundsystem Add some more audio effects * Cleanup flashes for merge Can put flashbangs in lockers so you don't get blinded Fix some bugs * Fix shotties Also removed some redundant code * Bulldoze some legacycode brrrrrrrrt * Fix clientignore warnings * Add the other Stunnable types to StunnableProjectile * Some gun refactoring * Removed extra visualizers * All casing ejections use the same code * Speed loaders can have their ammo pulled out * Bolt sound less loud * Stop ThrowController from throwing * Fix speed loader visuals * Update hitscan collision mask and fix typo * Cleanup * Fit hitscan and flashbang collisions * Use the new flags support * Update taser placeholder description * Update protonames per style guide * Add yaml flag support for gun firerates * Cleanup crew * Fix Audio up (components, audio file, + remove global sounds) * Add server-side recoil back-in (forgot that I was testing this client-side) * Add Flag support for fire-rate selectors * Wrong int you dolt * Fix AI conflicts Haha ranged bulldozer go BRR (I'll rewrite it after the other AI systems are done). * Mix bang.ogg from stereo to mono * Make sure serializer's reading for guns Fixes integration test * Change EntitySystem calls to use the static function Also removed the Pumpbarrel commented-out code * Change StunnableProjectile defaults to 0 * Fix taser paralyse Apparently removing defaults means you have to specify the values, whodathunkit * Add slowdown to stunnableprojectiles and fix tasers * Remove FlagsFor from gun components Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com> Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
215 lines
7.0 KiB
C#
215 lines
7.0 KiB
C#
using System.Collections.Generic;
|
|
using Content.Server.GameObjects.Components.Sound;
|
|
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
|
using Content.Server.GameObjects.EntitySystems;
|
|
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
|
|
using Content.Shared.Interfaces;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Server.GameObjects.Components.Container;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|
{
|
|
/// <summary>
|
|
/// Bolt-action rifles
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit
|
|
{
|
|
public override string Name => "PumpBarrel";
|
|
|
|
public override int ShotsLeft
|
|
{
|
|
get
|
|
{
|
|
var chamberCount = _chamberContainer.ContainedEntity != null ? 1 : 0;
|
|
return chamberCount + _spawnedAmmo.Count + _unspawnedCount;
|
|
}
|
|
}
|
|
|
|
public override int Capacity => _capacity;
|
|
private int _capacity;
|
|
|
|
// Even a point having a chamber? I guess it makes some of the below code cleaner
|
|
private ContainerSlot _chamberContainer;
|
|
private Stack<IEntity> _spawnedAmmo;
|
|
private Container _ammoContainer;
|
|
|
|
private BallisticCaliber _caliber;
|
|
|
|
private string _fillPrototype;
|
|
private int _unspawnedCount;
|
|
|
|
private bool _manualCycle;
|
|
|
|
private AppearanceComponent _appearanceComponent;
|
|
|
|
// Sounds
|
|
private string _soundCycle;
|
|
private string _soundInsert;
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
|
|
serializer.DataField(ref _capacity, "capacity", 6);
|
|
serializer.DataField(ref _fillPrototype, "fillPrototype", null);
|
|
serializer.DataField(ref _manualCycle, "manualCycle", true);
|
|
|
|
serializer.DataField(ref _soundCycle, "soundCycle", "/Audio/Guns/Cock/sf_rifle_cock.ogg");
|
|
serializer.DataField(ref _soundInsert, "soundInsert", "/Audio/Guns/MagIn/bullet_insert.ogg");
|
|
|
|
_spawnedAmmo = new Stack<IEntity>(_capacity - 1);
|
|
}
|
|
|
|
void IMapInit.MapInit()
|
|
{
|
|
if (_fillPrototype != null)
|
|
{
|
|
_unspawnedCount += Capacity - 1;
|
|
}
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_ammoContainer =
|
|
ContainerManagerComponent.Ensure<Container>($"{Name}-ammo-container", Owner, out var existing);
|
|
|
|
if (existing)
|
|
{
|
|
foreach (var entity in _ammoContainer.ContainedEntities)
|
|
{
|
|
_spawnedAmmo.Push(entity);
|
|
_unspawnedCount--;
|
|
}
|
|
}
|
|
|
|
_chamberContainer =
|
|
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-chamber-container", Owner, out existing);
|
|
if (existing)
|
|
{
|
|
_unspawnedCount--;
|
|
}
|
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
|
{
|
|
_appearanceComponent = appearanceComponent;
|
|
}
|
|
|
|
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
|
UpdateAppearance();
|
|
}
|
|
|
|
private void UpdateAppearance()
|
|
{
|
|
_appearanceComponent?.SetData(AmmoVisuals.AmmoCount, ShotsLeft);
|
|
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
|
}
|
|
|
|
public override IEntity PeekAmmo()
|
|
{
|
|
return _chamberContainer.ContainedEntity;
|
|
}
|
|
|
|
public override IEntity TakeProjectile()
|
|
{
|
|
var chamberEntity = _chamberContainer.ContainedEntity;
|
|
if (!_manualCycle)
|
|
{
|
|
Cycle();
|
|
}
|
|
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet();
|
|
}
|
|
|
|
private void Cycle(bool manual = false)
|
|
{
|
|
var chamberedEntity = _chamberContainer.ContainedEntity;
|
|
if (chamberedEntity != null)
|
|
{
|
|
_chamberContainer.Remove(chamberedEntity);
|
|
var ammoComponent = chamberedEntity.GetComponent<AmmoComponent>();
|
|
if (!ammoComponent.Caseless)
|
|
{
|
|
EjectCasing(chamberedEntity);
|
|
}
|
|
}
|
|
|
|
if (_spawnedAmmo.TryPop(out var next))
|
|
{
|
|
_ammoContainer.Remove(next);
|
|
_chamberContainer.Insert(next);
|
|
}
|
|
|
|
if (_unspawnedCount > 0)
|
|
{
|
|
_unspawnedCount--;
|
|
var ammoEntity = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.GridPosition);
|
|
_chamberContainer.Insert(ammoEntity);
|
|
}
|
|
|
|
if (manual)
|
|
{
|
|
if (_soundCycle != null)
|
|
{
|
|
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
|
}
|
|
}
|
|
|
|
// Dirty();
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public bool TryInsertBullet(InteractUsingEventArgs eventArgs)
|
|
{
|
|
if (!eventArgs.Using.TryGetComponent(out AmmoComponent ammoComponent))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (ammoComponent.Caliber != _caliber)
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("Wrong caliber"));
|
|
return false;
|
|
}
|
|
|
|
if (_ammoContainer.ContainedEntities.Count < Capacity - 1)
|
|
{
|
|
_ammoContainer.Insert(eventArgs.Using);
|
|
_spawnedAmmo.Push(eventArgs.Using);
|
|
// Dirty();
|
|
UpdateAppearance();
|
|
if (_soundInsert != null)
|
|
{
|
|
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("No room"));
|
|
|
|
return false;
|
|
}
|
|
|
|
public override bool UseEntity(UseEntityEventArgs eventArgs)
|
|
{
|
|
Cycle(true);
|
|
return true;
|
|
}
|
|
|
|
public override bool InteractUsing(InteractUsingEventArgs eventArgs)
|
|
{
|
|
return TryInsertBullet(eventArgs);
|
|
}
|
|
}
|
|
} |