GUNS PELASE WORK.
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
/// </summary>
|
||||
public float Velocity => _velocity;
|
||||
private float _velocity;
|
||||
|
||||
|
||||
private string _muzzleFlashSprite;
|
||||
|
||||
public string SoundCollectionEject => _soundCollectionEject;
|
||||
@@ -104,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity TakeBullet()
|
||||
public IEntity TakeBullet(GridCoordinates spawnAt)
|
||||
{
|
||||
if (_ammoIsProjectile)
|
||||
{
|
||||
@@ -121,12 +121,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
{
|
||||
appearanceComponent.SetData(AmmoVisuals.Spent, true);
|
||||
}
|
||||
|
||||
var entity = Owner.EntityManager.SpawnEntity(_projectileId, Owner.Transform.GridPosition);
|
||||
|
||||
var entity = Owner.EntityManager.SpawnEntity(_projectileId, spawnAt);
|
||||
DebugTools.AssertNotNull(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
public void MuzzleFlash(GridCoordinates grid, Angle angle)
|
||||
{
|
||||
if (_muzzleFlashSprite == null)
|
||||
@@ -138,7 +138,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
var deathTime = time + TimeSpan.FromMilliseconds(200);
|
||||
// Offset the sprite so it actually looks like it's coming from the gun
|
||||
var offset = angle.ToVec().Normalized / 2;
|
||||
|
||||
|
||||
var message = new EffectSystemMessage
|
||||
{
|
||||
EffectSprite = _muzzleFlashSprite,
|
||||
|
||||
@@ -16,6 +16,7 @@ using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
@@ -161,14 +162,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile()
|
||||
public override IEntity TakeProjectile(GridCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
if (_autoCycle)
|
||||
{
|
||||
Cycle();
|
||||
}
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet();
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
|
||||
}
|
||||
|
||||
protected override bool WeaponCanFire()
|
||||
|
||||
@@ -14,6 +14,7 @@ using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
@@ -37,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
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;
|
||||
@@ -47,11 +48,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
private string _fillPrototype;
|
||||
private int _unspawnedCount;
|
||||
|
||||
|
||||
private bool _manualCycle;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
|
||||
|
||||
// Sounds
|
||||
private string _soundCycle;
|
||||
private string _soundInsert;
|
||||
@@ -66,10 +67,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
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)
|
||||
@@ -82,7 +83,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
|
||||
_ammoContainer =
|
||||
ContainerManagerComponent.Ensure<Container>($"{Name}-ammo-container", Owner, out var existing);
|
||||
|
||||
@@ -95,7 +96,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
}
|
||||
|
||||
_chamberContainer =
|
||||
_chamberContainer =
|
||||
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-chamber-container", Owner, out existing);
|
||||
if (existing)
|
||||
{
|
||||
@@ -106,7 +107,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
|
||||
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
UpdateAppearance();
|
||||
}
|
||||
@@ -122,14 +123,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile()
|
||||
public override IEntity TakeProjectile(GridCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
if (!_manualCycle)
|
||||
{
|
||||
Cycle();
|
||||
}
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet();
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
|
||||
}
|
||||
|
||||
private void Cycle(bool manual = false)
|
||||
@@ -141,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var ammoComponent = chamberedEntity.GetComponent<AmmoComponent>();
|
||||
if (!ammoComponent.Caseless)
|
||||
{
|
||||
EjectCasing(chamberedEntity);
|
||||
EjectCasing(chamberedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Dirty();
|
||||
UpdateAppearance();
|
||||
}
|
||||
@@ -195,9 +196,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("No room"));
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -212,4 +213,4 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return TryInsertBullet(eventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
@@ -88,7 +89,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
|
||||
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
}
|
||||
|
||||
@@ -169,16 +170,17 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
/// Takes a projectile out if possible
|
||||
/// IEnumerable just to make supporting shotguns saner
|
||||
/// </summary>
|
||||
/// <param name="spawnAt"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override IEntity TakeProjectile()
|
||||
public override IEntity TakeProjectile(GridCoordinates spawnAt)
|
||||
{
|
||||
var ammo = _ammoSlots[_currentSlot];
|
||||
IEntity bullet = null;
|
||||
if (ammo != null)
|
||||
{
|
||||
var ammoComponent = ammo.GetComponent<AmmoComponent>();
|
||||
bullet = ammoComponent.TakeBullet();
|
||||
bullet = ammoComponent.TakeBullet(spawnAt);
|
||||
if (ammoComponent.Caseless)
|
||||
{
|
||||
_ammoSlots[_currentSlot] = null;
|
||||
|
||||
@@ -14,6 +14,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
@@ -134,7 +135,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return ammo;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile()
|
||||
public override IEntity TakeProjectile(GridCoordinates spawnAt)
|
||||
{
|
||||
var powerCellEntity = _powerCellContainer.ContainedEntity;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -180,7 +181,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return BoltOpen ? null : _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile()
|
||||
public override IEntity TakeProjectile(GridCoordinates spawnAt)
|
||||
{
|
||||
if (BoltOpen)
|
||||
{
|
||||
@@ -189,7 +190,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var entity = _chamberContainer.ContainedEntity;
|
||||
|
||||
Cycle();
|
||||
return entity?.GetComponent<AmmoComponent>().TakeBullet();
|
||||
return entity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
|
||||
}
|
||||
|
||||
private void Cycle(bool manual = false)
|
||||
|
||||
@@ -44,19 +44,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[Dependency] private IGameTiming _gameTiming;
|
||||
[Dependency] private IRobustRandom _robustRandom;
|
||||
#pragma warning restore 649
|
||||
|
||||
|
||||
public override FireRateSelector FireRateSelector => _fireRateSelector;
|
||||
private FireRateSelector _fireRateSelector;
|
||||
public override FireRateSelector AllRateSelectors => _fireRateSelector;
|
||||
private FireRateSelector _allRateSelectors;
|
||||
public override float FireRate => _fireRate;
|
||||
private float _fireRate;
|
||||
|
||||
|
||||
// _lastFire is when we actually fired (so if we hold the button then recoil doesn't build up if we're not firing)
|
||||
private TimeSpan _lastFire;
|
||||
|
||||
|
||||
public abstract IEntity PeekAmmo();
|
||||
public abstract IEntity TakeProjectile();
|
||||
public abstract IEntity TakeProjectile(GridCoordinates spawnAt);
|
||||
|
||||
// Recoil / spray control
|
||||
private Angle _minAngle;
|
||||
@@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
var minAngle = serializer.ReadDataField("minAngle", 0) / 2;
|
||||
_minAngle = Angle.FromDegrees(minAngle);
|
||||
// Random doubles it as it's +/- so uhh we'll just half it here for readability
|
||||
// Random doubles it as it's +/- so uhh we'll just half it here for readability
|
||||
var maxAngle = serializer.ReadDataField("maxAngle", 45) / 2;
|
||||
_maxAngle = Angle.FromDegrees(maxAngle);
|
||||
var angleIncrease = serializer.ReadDataField("angleIncrease", (40 / _fireRate));
|
||||
@@ -106,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var angleDecay = serializer.ReadDataField("angleDecay", (float) 20);
|
||||
_angleDecay = angleDecay * (float) Math.PI / 180;
|
||||
serializer.DataField(ref _spreadRatio, "ammoSpreadRatio", 1.0f);
|
||||
|
||||
|
||||
// FireRate options
|
||||
var allFireRates = serializer.ReadDataField("allSelectors", new List<FireRateSelector>());
|
||||
foreach (var fireRate in allFireRates)
|
||||
@@ -193,7 +193,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
var ammo = PeekAmmo();
|
||||
var projectile = TakeProjectile();
|
||||
var projectile = TakeProjectile(shooter.Transform.GridPosition);
|
||||
if (projectile == null)
|
||||
{
|
||||
soundSystem.PlayAtCoords(_soundEmpty, Owner.Transform.GridPosition);
|
||||
@@ -236,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
// Invalid types
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
|
||||
soundSystem.PlayAtCoords(_soundGunshot, Owner.Transform.GridPosition);
|
||||
_lastFire = _gameTiming.CurTime;
|
||||
|
||||
@@ -253,9 +253,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
/// <param name="prototypeManager"></param>
|
||||
/// <param name="ejectDirections"></param>
|
||||
public static void EjectCasing(
|
||||
IEntity entity,
|
||||
IEntity entity,
|
||||
bool playSound = true,
|
||||
IRobustRandom robustRandom = null,
|
||||
IRobustRandom robustRandom = null,
|
||||
IPrototypeManager prototypeManager = null,
|
||||
Direction[] ejectDirections = null)
|
||||
{
|
||||
@@ -268,7 +268,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
ejectDirections = new[] {Direction.East, Direction.North, Direction.South, Direction.West};
|
||||
}
|
||||
|
||||
|
||||
const float ejectOffset = 0.2f;
|
||||
var ammo = entity.GetComponent<AmmoComponent>();
|
||||
var offsetPos = (robustRandom.NextFloat() * ejectOffset, robustRandom.NextFloat() * ejectOffset);
|
||||
@@ -330,7 +330,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
IEntity projectile;
|
||||
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
projectile = baseProjectile;
|
||||
@@ -355,21 +355,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var physicsComponent = projectile.GetComponent<PhysicsComponent>();
|
||||
physicsComponent.Status = BodyStatus.InAir;
|
||||
projectile.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
|
||||
|
||||
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
|
||||
projectileComponent.IgnoreEntity(shooter);
|
||||
projectile.GetComponent<PhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
|
||||
projectile.Transform.LocalRotation = projectileAngle.Theta;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of numbers that form a set of equal intervals between the start and end value. Used to calculate shotgun spread angles.
|
||||
/// </summary>
|
||||
private List<Angle> Linspace(double start, double end, int intervals)
|
||||
{
|
||||
DebugTools.Assert(intervals > 1);
|
||||
|
||||
|
||||
var linspace = new List<Angle>(intervals);
|
||||
|
||||
for (var i = 0; i <= intervals - 1; i++)
|
||||
@@ -398,11 +398,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
damageable.TakeDamage(
|
||||
hitscan.DamageType,
|
||||
(int)Math.Round(hitscan.Damage, MidpointRounding.AwayFromZero),
|
||||
Owner,
|
||||
hitscan.DamageType,
|
||||
(int)Math.Round(hitscan.Damage, MidpointRounding.AwayFromZero),
|
||||
Owner,
|
||||
shooter);
|
||||
//I used Math.Round over Convert.toInt32, as toInt32 always rounds to
|
||||
//even numbers if halfway between two numbers, rather than rounding to nearest
|
||||
|
||||
Reference in New Issue
Block a user