Enable nullability in Content.Server (#3685)
This commit is contained in:
@@ -30,11 +30,11 @@ namespace Content.Server.GameObjects.Components.Weapon
|
||||
return new FlashComponentState(_duration, _lastFlash);
|
||||
}
|
||||
|
||||
public static void FlashAreaHelper(IEntity source, float range, float duration, string sound = null)
|
||||
public static void FlashAreaHelper(IEntity source, float range, float duration, string? sound = null)
|
||||
{
|
||||
foreach (var entity in source.EntityManager.GetEntitiesInRange(source.Transform.Coordinates, range))
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlashableComponent flashable) ||
|
||||
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
|
||||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
|
||||
|
||||
flashable.Flash(duration);
|
||||
|
||||
@@ -12,11 +12,9 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
@@ -104,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
if (!entity.Transform.IsMapTransform || entity == eventArgs.User)
|
||||
continue;
|
||||
|
||||
if (entity.TryGetComponent(out IDamageableComponent damageComponent))
|
||||
if (entity.TryGetComponent(out IDamageableComponent? damageComponent))
|
||||
{
|
||||
damageComponent.ChangeDamage(DamageType, Damage, false, Owner);
|
||||
hitEntities.Add(entity);
|
||||
@@ -154,7 +152,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.TryGetComponent(out IDamageableComponent damageComponent))
|
||||
if (target.TryGetComponent(out IDamageableComponent? damageComponent))
|
||||
{
|
||||
damageComponent.ChangeDamage(DamageType, Damage, false, Owner);
|
||||
}
|
||||
@@ -231,7 +229,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
|
||||
|
||||
private void RefreshItemCooldown()
|
||||
{
|
||||
if (Owner.TryGetComponent(out ItemCooldownComponent cooldown))
|
||||
if (Owner.TryGetComponent(out ItemCooldownComponent? cooldown))
|
||||
{
|
||||
cooldown.CooldownStart = _lastAttackTime;
|
||||
cooldown.CooldownEnd = _cooldownEnd;
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
private Stack<IEntity> _spawnedAmmo = new();
|
||||
private Container _ammoContainer;
|
||||
private Container _ammoContainer = default!;
|
||||
private int _unspawnedCount;
|
||||
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype;
|
||||
private string? _fillPrototype;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
appearanceComponent.SetData(AmmoVisuals.AmmoCount, AmmoLeft);
|
||||
@@ -81,9 +81,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity TakeAmmo()
|
||||
public IEntity? TakeAmmo()
|
||||
{
|
||||
if (_spawnedAmmo.TryPop(out IEntity ammo))
|
||||
if (_spawnedAmmo.TryPop(out var ammo))
|
||||
{
|
||||
_ammoContainer.Remove(ammo);
|
||||
return ammo;
|
||||
@@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!entity.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -130,12 +130,17 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
return TryInsertAmmo(eventArgs.User, eventArgs.Using);
|
||||
}
|
||||
|
||||
if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent rangedMagazine))
|
||||
if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent? rangedMagazine))
|
||||
{
|
||||
for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++)
|
||||
{
|
||||
var ammo = rangedMagazine.TakeAmmo();
|
||||
|
||||
if (ammo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryInsertAmmo(eventArgs.User, ammo))
|
||||
{
|
||||
rangedMagazine.TryInsertAmmo(eventArgs.User, ammo);
|
||||
@@ -151,21 +156,29 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
private bool TryUse(IEntity user)
|
||||
{
|
||||
if (!user.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!user.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var ammo = TakeAmmo();
|
||||
var itemComponent = ammo.GetComponent<ItemComponent>();
|
||||
|
||||
if (!handsComponent.CanPutInHand(itemComponent))
|
||||
if (ammo == null)
|
||||
{
|
||||
TryInsertAmmo(user, ammo);
|
||||
return false;
|
||||
}
|
||||
|
||||
handsComponent.PutInHand(itemComponent);
|
||||
if (ammo.TryGetComponent(out ItemComponent? item))
|
||||
{
|
||||
if (!handsComponent.CanPutInHand(item))
|
||||
{
|
||||
TryInsertAmmo(user, ammo);
|
||||
return false;
|
||||
}
|
||||
|
||||
handsComponent.PutInHand(item);
|
||||
}
|
||||
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
public int ProjectilesFired { get; } = 1;
|
||||
|
||||
[DataField("projectile")]
|
||||
private string _projectileId;
|
||||
private string? _projectileId;
|
||||
|
||||
// How far apart each entity is if multiple are shot
|
||||
[field: DataField("ammoSpread")]
|
||||
@@ -82,7 +82,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
private string _muzzleFlashSprite = "Objects/Weapons/Guns/Projectiles/bullet_muzzle.png";
|
||||
|
||||
[field: DataField("soundCollectionEject")]
|
||||
public string SoundCollectionEject { get; } = "CasingEject";
|
||||
public string? SoundCollectionEject { get; } = "CasingEject";
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
@@ -101,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity TakeBullet(EntityCoordinates spawnAt)
|
||||
public IEntity? TakeBullet(EntityCoordinates spawnAt)
|
||||
{
|
||||
if (_ammoIsProjectile)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
|
||||
_spent = true;
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
appearanceComponent.SetData(AmmoVisuals.Spent, true);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
@@ -17,7 +15,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
[DataField("fractionTransfered")]
|
||||
private float _fractionTransfered = 1;
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
|
||||
@@ -12,8 +12,6 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -25,7 +23,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
public override string Name => "RangedMagazine";
|
||||
|
||||
private readonly Stack<IEntity> _spawnedAmmo = new();
|
||||
private Container _ammoContainer;
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
public int ShotsLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
public int Capacity => _capacity;
|
||||
@@ -39,11 +37,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
[DataField("caliber")]
|
||||
private BallisticCaliber _caliber = BallisticCaliber.Unspecified;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
private AppearanceComponent? _appearanceComponent;
|
||||
|
||||
// If there's anything already in the magazine
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype;
|
||||
private string? _fillPrototype;
|
||||
|
||||
// By default the magazine won't spawn the entity until needed so we need to keep track of how many left we can spawn
|
||||
// Generally you probablt don't want to use this
|
||||
private int _unspawnedCount;
|
||||
@@ -76,7 +75,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -92,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity ammo)
|
||||
{
|
||||
if (!ammo.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!ammo.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -115,9 +114,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEntity TakeAmmo()
|
||||
public IEntity? TakeAmmo()
|
||||
{
|
||||
IEntity ammo = null;
|
||||
IEntity? ammo = null;
|
||||
// If anything's spawned use that first, otherwise use the fill prototype as a fallback (if we have spawn count left)
|
||||
if (_spawnedAmmo.TryPop(out var entity))
|
||||
{
|
||||
@@ -141,7 +140,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!eventArgs.User.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
@@ -29,14 +27,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
public int Capacity => _capacity;
|
||||
[DataField("capacity")]
|
||||
private int _capacity = 6;
|
||||
private Container _ammoContainer;
|
||||
private Container _ammoContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = new();
|
||||
private int _unspawnedCount;
|
||||
|
||||
public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype = default;
|
||||
private string? _fillPrototype = default;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -61,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
appearanceComponent?.SetData(AmmoVisuals.AmmoCount, AmmoLeft);
|
||||
@@ -71,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!entity.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -97,7 +95,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
|
||||
private bool UseEntity(IEntity user)
|
||||
{
|
||||
if (!user.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (!user.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -122,7 +120,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEntity TakeAmmo()
|
||||
private IEntity? TakeAmmo()
|
||||
{
|
||||
if (_spawnedAmmo.TryPop(out var entity))
|
||||
{
|
||||
@@ -147,9 +145,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
}
|
||||
|
||||
// This area is dirty but not sure of an easier way to do it besides add an interface or somethin
|
||||
bool changed = false;
|
||||
var changed = false;
|
||||
|
||||
if (eventArgs.Target.TryGetComponent(out RevolverBarrelComponent revolverBarrel))
|
||||
if (eventArgs.Target.TryGetComponent(out RevolverBarrelComponent? revolverBarrel))
|
||||
{
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
@@ -169,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||
TryInsertAmmo(eventArgs.User, ammo);
|
||||
break;
|
||||
}
|
||||
} else if (eventArgs.Target.TryGetComponent(out BoltActionBarrelComponent boltActionBarrel))
|
||||
} else if (eventArgs.Target.TryGetComponent(out BoltActionBarrelComponent? boltActionBarrel))
|
||||
{
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
|
||||
@@ -45,9 +45,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[DataField("capacity")]
|
||||
private int _capacity = 6;
|
||||
|
||||
private ContainerSlot _chamberContainer;
|
||||
private Stack<IEntity> _spawnedAmmo;
|
||||
private Container _ammoContainer;
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = default!;
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("caliber")]
|
||||
@@ -55,7 +55,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype;
|
||||
private string? _fillPrototype;
|
||||
[ViewVariables]
|
||||
private int _unspawnedCount;
|
||||
|
||||
@@ -97,7 +97,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[DataField("autoCycle")]
|
||||
private bool _autoCycle;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
private AppearanceComponent? _appearanceComponent;
|
||||
|
||||
// Sounds
|
||||
[DataField("soundCycle")]
|
||||
private string _soundCycle = "/Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg";
|
||||
@@ -129,7 +130,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var chamberedExists = _chamberContainer.ContainedEntity != null;
|
||||
// (Is one chambered?, is the bullet spend)
|
||||
var chamber = (chamberedExists, false);
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
|
||||
DebugTools.AssertNotNull(_chamberContainer.ContainedEntity);
|
||||
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity!.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
{
|
||||
chamber.Item2 = ammo.Spent;
|
||||
}
|
||||
@@ -159,7 +163,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
_chamberContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-chamber-container");
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -176,12 +180,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
public override IEntity? PeekAmmo()
|
||||
{
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
if (_autoCycle)
|
||||
@@ -193,7 +197,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
Dirty();
|
||||
}
|
||||
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
|
||||
return chamberEntity?.GetComponentOrNull<AmmoComponent>()?.TakeBullet(spawnAt);
|
||||
}
|
||||
|
||||
protected override bool WeaponCanFire()
|
||||
@@ -222,7 +226,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_soundCycle != null)
|
||||
if (!string.IsNullOrEmpty(_soundCycle))
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
@@ -234,7 +238,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
public bool TryInsertBullet(IEntity user, IEntity ammo)
|
||||
{
|
||||
if (!ammo.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!ammo.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override int Capacity { get; } = DefaultCapacity;
|
||||
|
||||
// Even a point having a chamber? I guess it makes some of the below code cleaner
|
||||
private ContainerSlot _chamberContainer;
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = new (DefaultCapacity-1);
|
||||
private Container _ammoContainer;
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("caliber")]
|
||||
@@ -52,14 +52,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype;
|
||||
private string? _fillPrototype;
|
||||
[ViewVariables]
|
||||
private int _unspawnedCount;
|
||||
|
||||
[DataField("manualCycle")]
|
||||
private bool _manualCycle = true;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
private AppearanceComponent? _appearanceComponent;
|
||||
|
||||
// Sounds
|
||||
[DataField("soundCycle")]
|
||||
@@ -83,7 +83,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var chamberedExists = _chamberContainer.ContainedEntity != null;
|
||||
// (Is one chambered?, is the bullet spend)
|
||||
var chamber = (chamberedExists, false);
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
|
||||
DebugTools.AssertNotNull(_chamberContainer.ContainedEntity);
|
||||
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity!.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
{
|
||||
chamber.Item2 = ammo.Spent;
|
||||
}
|
||||
@@ -122,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
_unspawnedCount--;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -138,12 +141,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
public override IEntity? PeekAmmo()
|
||||
{
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
if (!_manualCycle)
|
||||
@@ -155,7 +158,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
Dirty();
|
||||
}
|
||||
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
|
||||
return chamberEntity?.GetComponentOrNull<AmmoComponent>()?.TakeBullet(spawnAt);
|
||||
}
|
||||
|
||||
private void Cycle(bool manual = false)
|
||||
@@ -186,7 +189,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
if (manual)
|
||||
{
|
||||
if (_soundCycle != null)
|
||||
if (!string.IsNullOrEmpty(_soundCycle))
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
@@ -198,7 +201,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
public bool TryInsertBullet(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Using.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!eventArgs.Using.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
||||
using Content.Shared.GameObjects;
|
||||
@@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[DataField("caliber")]
|
||||
private BallisticCaliber _caliber = BallisticCaliber.Unspecified;
|
||||
|
||||
private Container _ammoContainer;
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private int _currentSlot;
|
||||
@@ -45,13 +45,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
private int _serializedCapacity = 6;
|
||||
|
||||
[DataField("ammoSlots", readOnly: true)]
|
||||
private IEntity[] _ammoSlots = Array.Empty<IEntity>();
|
||||
private IEntity?[] _ammoSlots = Array.Empty<IEntity?>();
|
||||
|
||||
public override int ShotsLeft => _ammoContainer.ContainedEntities.Count;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("fillPrototype")]
|
||||
private string _fillPrototype;
|
||||
private string? _fillPrototype;
|
||||
|
||||
[ViewVariables]
|
||||
private int _unspawnedCount;
|
||||
@@ -82,7 +82,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
slotsSpent[i] = null;
|
||||
if (_ammoSlots[i] != null && _ammoSlots[i].TryGetComponent(out AmmoComponent ammo))
|
||||
var ammoEntity = _ammoSlots[i];
|
||||
if (ammoEntity != null && ammoEntity.TryGetComponent(out AmmoComponent? ammo))
|
||||
{
|
||||
slotsSpent[i] = ammo.Spent;
|
||||
}
|
||||
@@ -126,7 +127,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
if (!Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +140,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
public bool TryInsertBullet(IEntity user, IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (!entity.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -191,14 +192,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
var random = _random.Next(_ammoSlots.Length - 1);
|
||||
_currentSlot = random;
|
||||
if (_soundSpin != null)
|
||||
if (!string.IsNullOrEmpty(_soundSpin))
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundSpin, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
public override IEntity? PeekAmmo()
|
||||
{
|
||||
return _ammoSlots[_currentSlot];
|
||||
}
|
||||
@@ -209,10 +210,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override IEntity TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var ammo = _ammoSlots[_currentSlot];
|
||||
IEntity bullet = null;
|
||||
IEntity? bullet = null;
|
||||
if (ammo != null)
|
||||
{
|
||||
var ammoComponent = ammo.GetComponent<AmmoComponent>();
|
||||
|
||||
@@ -36,14 +36,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[ViewVariables] private int _baseFireCost = 300;
|
||||
// What gets fired
|
||||
[DataField("ammoPrototype")]
|
||||
[ViewVariables] private string _ammoPrototype;
|
||||
[ViewVariables] private string? _ammoPrototype;
|
||||
|
||||
[ViewVariables] public IEntity PowerCellEntity => _powerCellContainer.ContainedEntity;
|
||||
public BatteryComponent PowerCell => _powerCellContainer.ContainedEntity?.GetComponent<BatteryComponent>();
|
||||
private ContainerSlot _powerCellContainer;
|
||||
private ContainerSlot _ammoContainer;
|
||||
[ViewVariables] public IEntity? PowerCellEntity => _powerCellContainer.ContainedEntity;
|
||||
public BatteryComponent? PowerCell => _powerCellContainer.ContainedEntity?.GetComponentOrNull<BatteryComponent>();
|
||||
private ContainerSlot _powerCellContainer = default!;
|
||||
private ContainerSlot _ammoContainer = default!;
|
||||
[DataField("powerCellPrototype")]
|
||||
private string _powerCellPrototype = default;
|
||||
private string? _powerCellPrototype = default;
|
||||
[DataField("powerCellRemovable")]
|
||||
[ViewVariables] private bool _powerCellRemovable = default;
|
||||
|
||||
@@ -77,13 +77,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
}
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
private AppearanceComponent? _appearanceComponent;
|
||||
|
||||
// Sounds
|
||||
[DataField("soundPowerCellInsert")]
|
||||
private string _soundPowerCellInsert = default;
|
||||
private string? _soundPowerCellInsert = default;
|
||||
[DataField("soundPowerCellEject")]
|
||||
private string _soundPowerCellEject = default;
|
||||
private string? _soundPowerCellEject = default;
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
_ammoContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-ammo-container");
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return ammo;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var powerCellEntity = _powerCellContainer.ContainedEntity;
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
entity = Owner.EntityManager.SpawnEntity(_ammoPrototype, spawnAt);
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out ProjectileComponent projectileComponent))
|
||||
if (entity.TryGetComponent(out ProjectileComponent? projectileComponent))
|
||||
{
|
||||
if (energyRatio < 1.0)
|
||||
{
|
||||
@@ -192,7 +192,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
projectileComponent.Damages = newDamages;
|
||||
}
|
||||
} else if (entity.TryGetComponent(out HitscanComponent hitscanComponent))
|
||||
} else if (entity.TryGetComponent(out HitscanComponent? hitscanComponent))
|
||||
{
|
||||
hitscanComponent.Damage *= energyRatio;
|
||||
hitscanComponent.ColorModifier = energyRatio;
|
||||
@@ -253,7 +253,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent hands))
|
||||
if (!user.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override uint? NetID => ContentNetIDs.MAGAZINE_BARREL;
|
||||
|
||||
[ViewVariables]
|
||||
private ContainerSlot _chamberContainer;
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
[ViewVariables] public bool HasMagazine => _magazineContainer.ContainedEntity != null;
|
||||
private ContainerSlot _magazineContainer;
|
||||
private ContainerSlot _magazineContainer = default!;
|
||||
|
||||
[ViewVariables] public MagazineType MagazineTypes => _magazineTypes;
|
||||
[DataField("magazineTypes")]
|
||||
@@ -80,7 +80,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
[DataField("magFillPrototype")]
|
||||
private string _magFillPrototype;
|
||||
private string? _magFillPrototype;
|
||||
|
||||
public bool BoltOpen
|
||||
{
|
||||
@@ -125,19 +125,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
[DataField("magNeedsOpenBolt")]
|
||||
private bool _magNeedsOpenBolt = default;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
private AppearanceComponent? _appearanceComponent;
|
||||
|
||||
// Sounds
|
||||
[DataField("soundBoltOpen")]
|
||||
private string _soundBoltOpen = default;
|
||||
private string? _soundBoltOpen = default;
|
||||
[DataField("soundBoltClosed")]
|
||||
private string _soundBoltClosed = default;
|
||||
private string? _soundBoltClosed = default;
|
||||
[DataField("soundRack")]
|
||||
private string _soundRack = default;
|
||||
private string? _soundRack = default;
|
||||
[DataField("soundMagInsert")]
|
||||
private string _soundMagInsert = default;
|
||||
private string? _soundMagInsert = default;
|
||||
[DataField("soundMagEject")]
|
||||
private string _soundMagEject = default;
|
||||
private string? _soundMagEject = default;
|
||||
[DataField("soundAutoEject")]
|
||||
private string _soundAutoEject = "/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg";
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
(int, int)? count = null;
|
||||
var magazine = _magazineContainer.ContainedEntity;
|
||||
if (magazine != null && magazine.TryGetComponent(out RangedMagazineComponent rangedMagazineComponent))
|
||||
if (magazine != null && magazine.TryGetComponent(out RangedMagazineComponent? rangedMagazineComponent))
|
||||
{
|
||||
count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity);
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -197,12 +197,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
public override IEntity? PeekAmmo()
|
||||
{
|
||||
return BoltOpen ? null : _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
if (BoltOpen)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundMagEject, Owner.Transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent handsComponent))
|
||||
if (user.TryGetComponent(out HandsComponent? handsComponent))
|
||||
{
|
||||
handsComponent.PutInHandOrDrop(mag.GetComponent<ItemComponent>());
|
||||
}
|
||||
@@ -371,7 +371,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
// Insert magazine
|
||||
if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent magazineComponent))
|
||||
if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent? magazineComponent))
|
||||
{
|
||||
if ((MagazineTypes & magazineComponent.MagazineType) == 0)
|
||||
{
|
||||
@@ -409,7 +409,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
// Insert 1 ammo
|
||||
if (eventArgs.Using.TryGetComponent(out AmmoComponent ammoComponent))
|
||||
if (eventArgs.Using.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
if (!BoltOpen)
|
||||
{
|
||||
|
||||
@@ -10,9 +10,6 @@ using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -21,8 +18,8 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -59,8 +56,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
// _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(EntityCoordinates spawnAt);
|
||||
public abstract IEntity? PeekAmmo();
|
||||
public abstract IEntity? TakeProjectile(EntityCoordinates spawnAt);
|
||||
|
||||
// Recoil / spray control
|
||||
[DataField("minAngle")]
|
||||
@@ -100,7 +97,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
// Sounds
|
||||
[field: DataField("soundGunshot")]
|
||||
public string SoundGunshot { get; set; }
|
||||
public string? SoundGunshot { get; set; }
|
||||
|
||||
[field: DataField("soundEmpty")]
|
||||
public string SoundEmpty { get; } = "/Audio/Weapons/Guns/Empty/empty.ogg";
|
||||
@@ -149,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
if (Owner.TryGetComponent(out ServerRangedWeaponComponent rangedWeaponComponent))
|
||||
if (Owner.TryGetComponent(out ServerRangedWeaponComponent? rangedWeaponComponent))
|
||||
{
|
||||
rangedWeaponComponent.Barrel = null;
|
||||
rangedWeaponComponent.FireHandler -= Fire;
|
||||
@@ -218,21 +215,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var direction = (targetPos - shooter.Transform.WorldPosition).ToAngle();
|
||||
var angle = GetRecoilAngle(direction);
|
||||
// This should really be client-side but for now we'll just leave it here
|
||||
if (shooter.TryGetComponent(out CameraRecoilComponent recoilComponent))
|
||||
if (shooter.TryGetComponent(out CameraRecoilComponent? recoilComponent))
|
||||
{
|
||||
recoilComponent.Kick(-angle.ToVec() * 0.15f);
|
||||
}
|
||||
|
||||
|
||||
// This section probably needs tweaking so there can be caseless hitscan etc.
|
||||
if (projectile.TryGetComponent(out HitscanComponent hitscan))
|
||||
if (projectile.TryGetComponent(out HitscanComponent? hitscan))
|
||||
{
|
||||
FireHitscan(shooter, hitscan, angle);
|
||||
}
|
||||
else if (projectile.HasComponent<ProjectileComponent>())
|
||||
else if (projectile.HasComponent<ProjectileComponent>() &&
|
||||
ammo != null &&
|
||||
ammo.TryGetComponent(out AmmoComponent? ammoComponent))
|
||||
{
|
||||
var ammoComponent = ammo.GetComponent<AmmoComponent>();
|
||||
|
||||
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo);
|
||||
|
||||
if (CanMuzzleFlash)
|
||||
@@ -251,10 +248,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
SoundSystem.Play(Filter.Broadcast(), SoundGunshot, Owner.Transform.Coordinates);
|
||||
_lastFire = _gameTiming.CurTime;
|
||||
if (!string.IsNullOrEmpty(SoundGunshot))
|
||||
{
|
||||
SoundSystem.Play(Filter.Broadcast(), SoundGunshot, Owner.Transform.Coordinates);
|
||||
}
|
||||
|
||||
return;
|
||||
_lastFire = _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -269,19 +268,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public static void EjectCasing(
|
||||
IEntity entity,
|
||||
bool playSound = true,
|
||||
IRobustRandom robustRandom = null,
|
||||
IPrototypeManager prototypeManager = null,
|
||||
Direction[] ejectDirections = null)
|
||||
IRobustRandom? robustRandom = null,
|
||||
IPrototypeManager? prototypeManager = null,
|
||||
Direction[]? ejectDirections = null)
|
||||
{
|
||||
if (robustRandom == null)
|
||||
{
|
||||
robustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
}
|
||||
|
||||
if (ejectDirections == null)
|
||||
{
|
||||
ejectDirections = new[] {Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
|
||||
}
|
||||
robustRandom ??= IoCManager.Resolve<IRobustRandom>();
|
||||
ejectDirections ??= new[]
|
||||
{Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
|
||||
|
||||
const float ejectOffset = 1.8f;
|
||||
var ammo = entity.GetComponent<AmmoComponent>();
|
||||
@@ -294,10 +287,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
return;
|
||||
}
|
||||
|
||||
if (prototypeManager == null)
|
||||
{
|
||||
prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
}
|
||||
prototypeManager ??= IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
var soundCollection = prototypeManager.Index<SoundCollectionPrototype>(ammo.SoundCollectionEject);
|
||||
var randomFile = robustRandom.Pick(soundCollection.PickFiles);
|
||||
@@ -334,7 +324,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
/// </summary>
|
||||
private void FireProjectiles(IEntity shooter, IEntity baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, IEntity ammo)
|
||||
{
|
||||
List<Angle> sprayAngleChange = null;
|
||||
List<Angle>? sprayAngleChange = null;
|
||||
if (count > 1)
|
||||
{
|
||||
evenSpreadAngle *= SpreadRatio;
|
||||
@@ -353,7 +343,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
else
|
||||
{
|
||||
projectile =
|
||||
Owner.EntityManager.SpawnEntity(baseProjectile.Prototype.ID, baseProjectile.Transform.Coordinates);
|
||||
Owner.EntityManager.SpawnEntity(baseProjectile.Prototype?.ID, baseProjectile.Transform.Coordinates);
|
||||
}
|
||||
firedProjectiles.Add(projectile);
|
||||
|
||||
@@ -414,7 +404,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
var distance = result.Distance;
|
||||
hitscan.FireEffects(shooter, distance, angle, result.HitEntity);
|
||||
|
||||
if (!result.HitEntity.TryGetComponent(out IDamageableComponent damageable))
|
||||
if (!result.HitEntity.TryGetComponent(out IDamageableComponent? damageable))
|
||||
return;
|
||||
|
||||
damageable.ChangeDamage(hitscan.DamageType, (int)Math.Round(hitscan.Damage, MidpointRounding.AwayFromZero), false, Owner);
|
||||
|
||||
@@ -18,8 +18,8 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
@@ -40,11 +40,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
[DataField("clumsyExplodeChance")]
|
||||
public float ClumsyExplodeChance { get; set; } = 0.5f;
|
||||
|
||||
public Func<bool> WeaponCanFireHandler;
|
||||
public Func<IEntity, bool> UserCanFireHandler;
|
||||
public Action<IEntity, Vector2> FireHandler;
|
||||
public Func<bool>? WeaponCanFireHandler;
|
||||
public Func<IEntity, bool>? UserCanFireHandler;
|
||||
public Action<IEntity, Vector2>? FireHandler;
|
||||
|
||||
public ServerRangedBarrelComponent Barrel
|
||||
public ServerRangedBarrelComponent? Barrel
|
||||
{
|
||||
get => _barrel;
|
||||
set
|
||||
@@ -59,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
private ServerRangedBarrelComponent _barrel;
|
||||
private ServerRangedBarrelComponent? _barrel;
|
||||
|
||||
private FireRateSelector FireRateSelector => _barrel?.FireRateSelector ?? FireRateSelector.Safety;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
@@ -126,12 +126,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
/// <param name="targetPos">Target position on the map to shoot at.</param>
|
||||
private void TryFire(IEntity user, Vector2 targetPos)
|
||||
{
|
||||
if (!user.TryGetComponent(out HandsComponent hands) || hands.GetActiveHand?.Owner != Owner)
|
||||
if (!user.TryGetComponent(out HandsComponent? hands) || hands.GetActiveHand?.Owner != Owner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!user.TryGetComponent(out CombatModeComponent combat) || !combat.IsInCombatMode) {
|
||||
if(!user.TryGetComponent(out CombatModeComponent? combat) || !combat.IsInCombatMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
|
||||
var curTime = _gameTiming.CurTime;
|
||||
var span = curTime - _lastFireTime;
|
||||
if (span.TotalSeconds < 1 / _barrel.FireRate)
|
||||
if (span.TotalSeconds < 1 / _barrel?.FireRate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -158,13 +158,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
soundSystem.PlayAtCoords("/Audio/Weapons/Guns/Gunshots/bang.ogg",
|
||||
Owner.Transform.Coordinates, AudioParams.Default, 5);
|
||||
|
||||
if (user.TryGetComponent(out IDamageableComponent health))
|
||||
if (user.TryGetComponent(out IDamageableComponent? health))
|
||||
{
|
||||
health.ChangeDamage(DamageType.Blunt, 10, false, user);
|
||||
health.ChangeDamage(DamageType.Heat, 5, false, user);
|
||||
}
|
||||
|
||||
if (user.TryGetComponent(out StunnableComponent stun))
|
||||
if (user.TryGetComponent(out StunnableComponent? stun))
|
||||
{
|
||||
stun.Paralyze(3f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user