Fix 3000 errors
This commit is contained in:
@@ -8,7 +8,6 @@ using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Cooldown;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Hands;
|
||||
@@ -70,7 +69,7 @@ namespace Content.Server.Weapon.Melee
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
private void OnClickAttack(EntityUid uid, MeleeWeaponComponent comp, ClickAttackEvent args)
|
||||
private void OnClickAttack(EntityUid owner, MeleeWeaponComponent comp, ClickAttackEvent args)
|
||||
{
|
||||
args.Handled = true;
|
||||
var curTime = _gameTiming.CurTime;
|
||||
@@ -78,18 +77,15 @@ namespace Content.Server.Weapon.Melee
|
||||
if (curTime < comp.CooldownEnd || !args.Target.IsValid())
|
||||
return;
|
||||
|
||||
var owner = EntityManager.GetEntity(uid);
|
||||
var target = args.TargetEntity;
|
||||
|
||||
var location = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).Coordinates;
|
||||
var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve<IEntityManager>()) - location.ToMapPos(IoCManager.Resolve<IEntityManager>());
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
|
||||
if (target != null)
|
||||
if (args.Target is {Valid: true} target)
|
||||
{
|
||||
// Raise event before doing damage so we can cancel damage if the event is handled
|
||||
var hitEvent = new MeleeHitEvent(new List<IEntity>() { target }, args.User);
|
||||
RaiseLocalEvent(uid, hitEvent, false);
|
||||
var hitEvent = new MeleeHitEvent(new List<EntityUid>() { target }, args.User);
|
||||
RaiseLocalEvent(owner, hitEvent, false);
|
||||
|
||||
if (!hitEvent.Handled)
|
||||
{
|
||||
@@ -123,10 +119,10 @@ namespace Content.Server.Weapon.Melee
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime);
|
||||
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
private void OnWideAttack(EntityUid uid, MeleeWeaponComponent comp, WideAttackEvent args)
|
||||
private void OnWideAttack(EntityUid owner, MeleeWeaponComponent comp, WideAttackEvent args)
|
||||
{
|
||||
args.Handled = true;
|
||||
var curTime = _gameTiming.CurTime;
|
||||
@@ -136,8 +132,6 @@ namespace Content.Server.Weapon.Melee
|
||||
return;
|
||||
}
|
||||
|
||||
var owner = EntityManager.GetEntity(uid);
|
||||
|
||||
var location = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).Coordinates;
|
||||
var diff = args.ClickLocation.ToMapPos(IoCManager.Resolve<IEntityManager>()) - location.ToMapPos(IoCManager.Resolve<IEntityManager>());
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
@@ -145,7 +139,7 @@ namespace Content.Server.Weapon.Melee
|
||||
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
|
||||
var entities = ArcRayCast(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).WorldPosition, angle, comp.ArcWidth, comp.Range, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(owner).MapID, args.User);
|
||||
|
||||
var hitEntities = new List<IEntity>();
|
||||
var hitEntities = new List<EntityUid>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.IsInContainer() || entity == args.User)
|
||||
@@ -159,7 +153,7 @@ namespace Content.Server.Weapon.Melee
|
||||
|
||||
// Raise event before doing damage so we can cancel damage if handled
|
||||
var hitEvent = new MeleeHitEvent(hitEntities, args.User);
|
||||
RaiseLocalEvent(uid, hitEvent, false);
|
||||
RaiseLocalEvent(owner, hitEvent, false);
|
||||
SendAnimation(comp.Arc, angle, args.User, owner, hitEntities);
|
||||
|
||||
if (!hitEvent.Handled)
|
||||
@@ -195,14 +189,14 @@ namespace Content.Server.Weapon.Melee
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.ArcCooldownTime);
|
||||
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used for melee weapons that want some behavior on AfterInteract,
|
||||
/// but also want the cooldown (stun batons, flashes)
|
||||
/// </summary>
|
||||
private void OnAfterInteract(EntityUid uid, MeleeWeaponComponent comp, AfterInteractEvent args)
|
||||
private void OnAfterInteract(EntityUid owner, MeleeWeaponComponent comp, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach)
|
||||
return;
|
||||
@@ -214,9 +208,7 @@ namespace Content.Server.Weapon.Melee
|
||||
return;
|
||||
}
|
||||
|
||||
var owner = EntityManager.GetEntity(uid);
|
||||
|
||||
if (args.Target == null)
|
||||
if (!args.Target.Valid)
|
||||
return;
|
||||
|
||||
var location = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).Coordinates;
|
||||
@@ -224,25 +216,25 @@ namespace Content.Server.Weapon.Melee
|
||||
var angle = Angle.FromWorldVec(diff);
|
||||
|
||||
var hitEvent = new MeleeInteractEvent(args.Target, args.User);
|
||||
RaiseLocalEvent(uid, hitEvent, false);
|
||||
RaiseLocalEvent(owner, hitEvent, false);
|
||||
|
||||
if (!hitEvent.CanInteract) return;
|
||||
SendAnimation(comp.ClickArc, angle, args.User, owner, new List<IEntity>() { args.Target }, comp.ClickAttackEffect, false);
|
||||
SendAnimation(comp.ClickArc, angle, args.User, owner, new List<EntityUid>() { args.Target }, comp.ClickAttackEffect, false);
|
||||
|
||||
comp.LastAttackTime = curTime;
|
||||
comp.CooldownEnd = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime);
|
||||
|
||||
RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
RaiseLocalEvent(owner, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
|
||||
}
|
||||
|
||||
private HashSet<IEntity> ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, IEntity ignore)
|
||||
private HashSet<EntityUid> ArcRayCast(Vector2 position, Angle angle, float arcWidth, float range, MapId mapId, EntityUid ignore)
|
||||
{
|
||||
var widthRad = Angle.FromDegrees(arcWidth);
|
||||
var increments = 1 + 35 * (int) Math.Ceiling(widthRad / (2 * Math.PI));
|
||||
var increment = widthRad / increments;
|
||||
var baseAngle = angle - widthRad / 2;
|
||||
|
||||
var resSet = new HashSet<IEntity>();
|
||||
var resSet = new HashSet<EntityUid>();
|
||||
|
||||
for (var i = 0; i < increments; i++)
|
||||
{
|
||||
@@ -260,9 +252,8 @@ namespace Content.Server.Weapon.Melee
|
||||
return resSet;
|
||||
}
|
||||
|
||||
private void OnChemicalInjectorHit(EntityUid uid, MeleeChemicalInjectorComponent comp, MeleeHitEvent args)
|
||||
private void OnChemicalInjectorHit(EntityUid owner, MeleeChemicalInjectorComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
IEntity owner = EntityManager.GetEntity(uid);
|
||||
if (!_solutionsSystem.TryGetInjectableSolution(owner, out var solutionContainer))
|
||||
return;
|
||||
|
||||
@@ -291,13 +282,13 @@ namespace Content.Server.Weapon.Melee
|
||||
}
|
||||
}
|
||||
|
||||
public void SendAnimation(string arc, Angle angle, IEntity attacker, IEntity source, IEnumerable<IEntity> hits, bool textureEffect = false, bool arcFollowAttacker = true)
|
||||
public void SendAnimation(string arc, Angle angle, EntityUid attacker, EntityUid source, IEnumerable<EntityUid> hits, bool textureEffect = false, bool arcFollowAttacker = true)
|
||||
{
|
||||
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayMeleeWeaponAnimationMessage(arc, angle, attacker, source,
|
||||
hits.Select(e => (EntityUid) e).ToList(), textureEffect, arcFollowAttacker), Filter.Pvs(source, 1f));
|
||||
hits.Select(e => e).ToList(), textureEffect, arcFollowAttacker), Filter.Pvs(source, 1f));
|
||||
}
|
||||
|
||||
public void SendLunge(Angle angle, IEntity source)
|
||||
public void SendLunge(Angle angle, EntityUid source)
|
||||
{
|
||||
RaiseNetworkEvent(new MeleeWeaponSystemMessages.PlayLungeAnimationMessage(angle, source), Filter.Pvs(source, 1f));
|
||||
}
|
||||
@@ -323,14 +314,14 @@ namespace Content.Server.Weapon.Melee
|
||||
/// <summary>
|
||||
/// A list containing every hit entity. Can be zero.
|
||||
/// </summary>
|
||||
public IEnumerable<IEntity> HitEntities { get; }
|
||||
public IEnumerable<EntityUid> HitEntities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user who attacked with the melee wepaon.
|
||||
/// </summary>
|
||||
public IEntity User { get; }
|
||||
public EntityUid User { get; }
|
||||
|
||||
public MeleeHitEvent(List<IEntity> hitEntities, IEntity user)
|
||||
public MeleeHitEvent(List<EntityUid> hitEntities, EntityUid user)
|
||||
{
|
||||
HitEntities = hitEntities;
|
||||
User = user;
|
||||
@@ -346,12 +337,12 @@ namespace Content.Server.Weapon.Melee
|
||||
/// <summary>
|
||||
/// The entity interacted with.
|
||||
/// </summary>
|
||||
public IEntity Entity { get; }
|
||||
public EntityUid Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user who interacted using the melee weapon.
|
||||
/// </summary>
|
||||
public IEntity User { get; }
|
||||
public EntityUid User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Modified by the event handler to specify whether they could successfully interact with the entity.
|
||||
@@ -359,7 +350,7 @@ namespace Content.Server.Weapon.Melee
|
||||
/// </summary>
|
||||
public bool CanInteract { get; set; } = false;
|
||||
|
||||
public MeleeInteractEvent(IEntity entity, IEntity user)
|
||||
public MeleeInteractEvent(EntityUid entity, EntityUid user)
|
||||
{
|
||||
Entity = entity;
|
||||
User = user;
|
||||
|
||||
@@ -34,14 +34,14 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
set
|
||||
{
|
||||
_capacity = value;
|
||||
_spawnedAmmo = new Stack<IEntity>(value);
|
||||
_spawnedAmmo = new Stack<EntityUid>(value);
|
||||
}
|
||||
}
|
||||
|
||||
private int _capacity = 30;
|
||||
|
||||
public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
private Stack<IEntity> _spawnedAmmo = new();
|
||||
private Stack<EntityUid> _spawnedAmmo = new();
|
||||
private Container _ammoContainer = default!;
|
||||
private int _unspawnedCount;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity? TakeAmmo()
|
||||
public EntityUid TakeAmmo()
|
||||
{
|
||||
if (_spawnedAmmo.TryPop(out var ammo))
|
||||
{
|
||||
@@ -102,7 +102,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return ammo;
|
||||
}
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity entity)
|
||||
public bool TryInsertAmmo(EntityUid user, EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
@@ -140,7 +140,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
{
|
||||
var ammo = rangedMagazine.TakeAmmo();
|
||||
|
||||
if (ammo == null)
|
||||
if (!ammo.Valid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryUse(IEntity user)
|
||||
private bool TryUse(EntityUiduser)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? handsComponent))
|
||||
{
|
||||
@@ -190,7 +190,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
public void EjectContents(int count)
|
||||
{
|
||||
var ejectCount = Math.Min(count, Capacity);
|
||||
var ejectAmmo = new List<IEntity>(ejectCount);
|
||||
var ejectAmmo = new List<EntityUid>(ejectCount);
|
||||
|
||||
for (var i = 0; i < Math.Min(count, Capacity); i++)
|
||||
{
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity? TakeBullet(EntityCoordinates spawnAt)
|
||||
public EntityUid TakeBullet(EntityCoordinates spawnAt)
|
||||
{
|
||||
if (_ammoIsProjectile)
|
||||
{
|
||||
@@ -127,7 +127,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void MuzzleFlash(IEntity entity, Angle angle)
|
||||
public void MuzzleFlash(EntityUid entity, Angle angle)
|
||||
{
|
||||
if (_muzzleFlashSprite == null)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
{
|
||||
public override string Name => "RangedMagazine";
|
||||
|
||||
private readonly Stack<IEntity> _spawnedAmmo = new();
|
||||
private readonly Stack<EntityUid> _spawnedAmmo = new();
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
public int ShotsLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
@@ -91,7 +91,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity ammo)
|
||||
public bool TryInsertAmmo(EntityUid user, EntityUid ammo)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
@@ -116,9 +116,9 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEntity? TakeAmmo()
|
||||
public EntityUid TakeAmmo()
|
||||
{
|
||||
IEntity? ammo = null;
|
||||
EntityUid ammo = default;
|
||||
// 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))
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
[DataField("capacity")]
|
||||
private int _capacity = 6;
|
||||
private Container _ammoContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = new();
|
||||
private Stack<EntityUid> _spawnedAmmo = new();
|
||||
private int _unspawnedCount;
|
||||
|
||||
public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount;
|
||||
@@ -67,7 +67,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryInsertAmmo(IEntity user, IEntity entity)
|
||||
public bool TryInsertAmmo(EntityUid user, EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
|
||||
}
|
||||
|
||||
private bool UseEntity(IEntity user)
|
||||
private bool UseEntity(EntityUid user)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? handsComponent))
|
||||
{
|
||||
@@ -101,7 +101,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
}
|
||||
|
||||
var ammo = TakeAmmo();
|
||||
if (ammo == null)
|
||||
if (ammo == default)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEntity? TakeAmmo()
|
||||
private EntityUid TakeAmmo()
|
||||
{
|
||||
if (_spawnedAmmo.TryPop(out var entity))
|
||||
{
|
||||
@@ -147,12 +147,13 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
// This area is dirty but not sure of an easier way to do it besides add an interface or somethin
|
||||
var changed = false;
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target, out RevolverBarrelComponent? revolverBarrel))
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (entities.TryGetComponent(eventArgs.Target.Value, out RevolverBarrelComponent? revolverBarrel))
|
||||
{
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
var ammo = TakeAmmo();
|
||||
if (ammo == null)
|
||||
if (ammo == default)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -167,12 +168,13 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
TryInsertAmmo(eventArgs.User, ammo);
|
||||
break;
|
||||
}
|
||||
} else if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target, out BoltActionBarrelComponent? boltActionBarrel))
|
||||
}
|
||||
else if (IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Target.Value, out BoltActionBarrelComponent? boltActionBarrel))
|
||||
{
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
var ammo = TakeAmmo();
|
||||
if (ammo == null)
|
||||
if (ammo == default)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -74,10 +74,12 @@ namespace Content.Server.Weapon.Ranged.Barrels
|
||||
!_actionBlockerSystem.CanPickup(args.User))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.PowerCell.Owner).EntityName;
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Act = () => component.TryEjectCell(args.User);
|
||||
Verb verb = new()
|
||||
{
|
||||
Text = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(component.PowerCell.Owner).EntityName,
|
||||
Category = VerbCategory.Eject,
|
||||
Act = () => component.TryEjectCell(args.User)
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -48,7 +47,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
private int _capacity = 6;
|
||||
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = default!;
|
||||
private Stack<EntityUid> _spawnedAmmo = default!;
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
@@ -141,7 +140,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
// TODO: Add existing ammo support on revolvers
|
||||
base.Initialize();
|
||||
_spawnedAmmo = new Stack<IEntity>(_capacity - 1);
|
||||
_spawnedAmmo = new Stack<EntityUid>(_capacity - 1);
|
||||
_ammoContainer = ContainerHelpers.EnsureContainer<Container>(Owner, $"{Name}-ammo-container", out var existing);
|
||||
|
||||
if (existing)
|
||||
@@ -172,12 +171,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public override IEntity? PeekAmmo()
|
||||
public override EntityUid PeekAmmo()
|
||||
{
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
if (_autoCycle)
|
||||
@@ -228,7 +227,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public bool TryInsertBullet(IEntity user, IEntity ammo)
|
||||
public bool TryInsertBullet(EntityUid user, EntityUid ammo)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
|
||||
@@ -13,7 +13,6 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -45,7 +44,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
// Even a point having a chamber? I guess it makes some of the below code cleaner
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
private Stack<IEntity> _spawnedAmmo = new(DefaultCapacity - 1);
|
||||
private Stack<EntityUid> _spawnedAmmo = new(DefaultCapacity - 1);
|
||||
private Container _ammoContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
@@ -99,7 +98,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
_spawnedAmmo = new Stack<IEntity>(Capacity - 1);
|
||||
_spawnedAmmo = new Stack<EntityUid>(Capacity - 1);
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
@@ -141,12 +140,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public override IEntity? PeekAmmo()
|
||||
public override EntityUid PeekAmmo()
|
||||
{
|
||||
return _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var chamberEntity = _chamberContainer.ContainedEntity;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -44,7 +43,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
private int _serializedCapacity = 6;
|
||||
|
||||
[DataField("ammoSlots", readOnly: true)]
|
||||
private IEntity?[] _ammoSlots = Array.Empty<IEntity?>();
|
||||
private EntityUid[] _ammoSlots = Array.Empty<EntityUid>();
|
||||
|
||||
public override int ShotsLeft => _ammoContainer.ContainedEntities.Count;
|
||||
|
||||
@@ -137,7 +136,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
appearance.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
|
||||
public bool TryInsertBullet(IEntity user, IEntity entity)
|
||||
public bool TryInsertBullet(EntityUid user, EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
@@ -192,7 +191,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override IEntity? PeekAmmo()
|
||||
public override EntityUid PeekAmmo()
|
||||
{
|
||||
return _ammoSlots[_currentSlot];
|
||||
}
|
||||
@@ -203,10 +202,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var ammo = _ammoSlots[_currentSlot];
|
||||
IEntity? bullet = null;
|
||||
EntityUid bullet = null;
|
||||
if (ammo != null)
|
||||
{
|
||||
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(ammo);
|
||||
|
||||
@@ -14,7 +14,6 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -24,6 +23,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
[NetworkedComponent()]
|
||||
public sealed class ServerBatteryBarrelComponent : ServerRangedBarrelComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override string Name => "BatteryBarrel";
|
||||
|
||||
// The minimum change we need before we can fire
|
||||
@@ -35,37 +36,28 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
[DataField("ammoPrototype")]
|
||||
[ViewVariables] private string? _ammoPrototype;
|
||||
|
||||
[ViewVariables] public IEntity? PowerCellEntity => _powerCellContainer.ContainedEntity;
|
||||
public BatteryComponent? PowerCell
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_powerCellContainer.ContainedEntity == null)
|
||||
return null;
|
||||
|
||||
return _powerCellContainer.ContainedEntity.GetComponentOrNull<BatteryComponent>();
|
||||
}
|
||||
}
|
||||
[ViewVariables] public EntityUid? PowerCellEntity => _powerCellContainer.ContainedEntity;
|
||||
public BatteryComponent? PowerCell => _powerCellContainer.ContainedEntity == null
|
||||
? null
|
||||
: _entities.GetComponentOrNull<BatteryComponent>(_powerCellContainer.ContainedEntity.Value);
|
||||
|
||||
private ContainerSlot _powerCellContainer = default!;
|
||||
private ContainerSlot _ammoContainer = default!;
|
||||
[DataField("powerCellPrototype")]
|
||||
private string? _powerCellPrototype = default;
|
||||
private string? _powerCellPrototype;
|
||||
[DataField("powerCellRemovable")]
|
||||
[ViewVariables] public bool PowerCellRemovable = default;
|
||||
[ViewVariables] public bool PowerCellRemovable;
|
||||
|
||||
public override int ShotsLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
var powerCell = _powerCellContainer.ContainedEntity;
|
||||
|
||||
if (powerCell == null)
|
||||
if (_powerCellContainer.ContainedEntity is not {Valid: true} powerCell)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.Ceiling(IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCell).CurrentCharge / _baseFireCost);
|
||||
return (int) Math.Ceiling(_entities.GetComponent<BatteryComponent>(powerCell).CurrentCharge / _baseFireCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,14 +65,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
var powerCell = _powerCellContainer.ContainedEntity;
|
||||
|
||||
if (powerCell == null)
|
||||
if (_powerCellContainer.ContainedEntity is not {Valid: true} powerCell)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.Ceiling((float) (IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCell).MaxCharge / _baseFireCost));
|
||||
return (int) Math.Ceiling(_entities.GetComponent<BatteryComponent>(powerCell).MaxCharge / _baseFireCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,19 +94,19 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_powerCellContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-powercell-container", out var existing);
|
||||
_powerCellContainer = Owner.EnsureContainer<ContainerSlot>($"{Name}-powercell-container", out var existing);
|
||||
if (!existing && _powerCellPrototype != null)
|
||||
{
|
||||
var powerCellEntity = IoCManager.Resolve<IEntityManager>().SpawnEntity(_powerCellPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var powerCellEntity = _entities.SpawnEntity(_powerCellPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
_powerCellContainer.Insert(powerCellEntity);
|
||||
}
|
||||
|
||||
if (_ammoPrototype != null)
|
||||
{
|
||||
_ammoContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-ammo-container");
|
||||
_ammoContainer = Owner.EnsureContainer<ContainerSlot>($"{Name}-ammo-container");
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
@@ -137,64 +127,64 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
public override EntityUid PeekAmmo()
|
||||
{
|
||||
// Spawn a dummy entity because it's easier to work with I guess
|
||||
// This will get re-used for the projectile
|
||||
var ammo = _ammoContainer.ContainedEntity;
|
||||
if (ammo == null)
|
||||
{
|
||||
ammo = IoCManager.Resolve<IEntityManager>().SpawnEntity(_ammoPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
_ammoContainer.Insert(ammo);
|
||||
ammo = _entities.SpawnEntity(_ammoPrototype, _entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
_ammoContainer.Insert(ammo.Value);
|
||||
}
|
||||
|
||||
return ammo;
|
||||
return ammo.Value;
|
||||
}
|
||||
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
var powerCellEntity = _powerCellContainer.ContainedEntity;
|
||||
|
||||
if (powerCellEntity == null)
|
||||
{
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
|
||||
var capacitor = IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCellEntity);
|
||||
var capacitor = _entities.GetComponent<BatteryComponent>(powerCellEntity.Value);
|
||||
if (capacitor.CurrentCharge < _lowerChargeLimit)
|
||||
{
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
|
||||
// Can fire confirmed
|
||||
// Multiply the entity's damage / whatever by the percentage of charge the shot has.
|
||||
IEntity entity;
|
||||
EntityUid? entity;
|
||||
var chargeChange = Math.Min(capacitor.CurrentCharge, _baseFireCost);
|
||||
if (capacitor.UseCharge(chargeChange) < _lowerChargeLimit)
|
||||
{
|
||||
// Handling of funny exploding cells.
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
var energyRatio = chargeChange / _baseFireCost;
|
||||
|
||||
if (_ammoContainer.ContainedEntity != null)
|
||||
{
|
||||
entity = _ammoContainer.ContainedEntity;
|
||||
_ammoContainer.Remove(entity);
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates = spawnAt;
|
||||
_ammoContainer.Remove(entity.Value);
|
||||
_entities.GetComponent<TransformComponent>(entity.Value).Coordinates = spawnAt;
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = IoCManager.Resolve<IEntityManager>().SpawnEntity(_ammoPrototype, spawnAt);
|
||||
entity = _entities.SpawnEntity(_ammoPrototype, spawnAt);
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ProjectileComponent? projectileComponent))
|
||||
if (_entities.TryGetComponent(entity.Value, out ProjectileComponent? projectileComponent))
|
||||
{
|
||||
if (energyRatio < 1.0)
|
||||
{
|
||||
projectileComponent.Damage *= energyRatio;
|
||||
}
|
||||
} else if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out HitscanComponent? hitscanComponent))
|
||||
} else if (_entities.TryGetComponent(entity.Value, out HitscanComponent? hitscanComponent))
|
||||
{
|
||||
hitscanComponent.Damage *= energyRatio;
|
||||
hitscanComponent.ColorModifier = energyRatio;
|
||||
@@ -206,17 +196,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return entity;
|
||||
return entity.Value;
|
||||
}
|
||||
|
||||
public bool TryInsertPowerCell(IEntity entity)
|
||||
public bool TryInsertPowerCell(EntityUid entity)
|
||||
{
|
||||
if (_powerCellContainer.ContainedEntity != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().HasComponent<BatteryComponent>(entity))
|
||||
if (!_entities.HasComponent<BatteryComponent>(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -237,22 +227,17 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PowerCellEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryEjectCell(eventArgs.User);
|
||||
return PowerCellEntity != default && TryEjectCell(eventArgs.User);
|
||||
}
|
||||
|
||||
public bool TryEjectCell(IEntity user)
|
||||
public bool TryEjectCell(EntityUid user)
|
||||
{
|
||||
if (PowerCell == null || !PowerCellRemovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? hands))
|
||||
if (!_entities.TryGetComponent(user, out HandsComponent? hands))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -266,9 +251,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
|
||||
if (!hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(cell.Owner)))
|
||||
if (!hands.PutInHand(_entities.GetComponent<ItemComponent>(cell.Owner)))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(cell.Owner).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).Coordinates;
|
||||
_entities.GetComponent<TransformComponent>(cell.Owner).Coordinates = _entities.GetComponent<TransformComponent>(user).Coordinates;
|
||||
}
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundPowerCellEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
@@ -277,7 +262,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().HasComponent<BatteryComponent>(eventArgs.Using))
|
||||
if (!_entities.HasComponent<BatteryComponent>(eventArgs.Using))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -31,6 +30,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
public sealed class ServerMagazineBarrelComponent : ServerRangedBarrelComponent, IExamine
|
||||
#pragma warning restore 618
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override string Name => "MagazineBarrel";
|
||||
|
||||
[ViewVariables]
|
||||
@@ -55,8 +56,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
count++;
|
||||
}
|
||||
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null)
|
||||
if (MagazineContainer.ContainedEntity is {Valid: true} magazine)
|
||||
{
|
||||
count += IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine).ShotsLeft;
|
||||
}
|
||||
@@ -71,8 +71,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
// Chamber
|
||||
var count = 1;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null)
|
||||
if (MagazineContainer.ContainedEntity is {Valid: true} magazine)
|
||||
{
|
||||
count += IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine).Capacity;
|
||||
}
|
||||
@@ -153,8 +152,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
(int, int)? count = null;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent))
|
||||
if (MagazineContainer.ContainedEntity is {Valid: true} magazine &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(magazine, out RangedMagazineComponent? rangedMagazineComponent))
|
||||
{
|
||||
count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity);
|
||||
}
|
||||
@@ -170,13 +169,13 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
_appearanceComponent = appearanceComponent;
|
||||
}
|
||||
|
||||
_chamberContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-chamber");
|
||||
MagazineContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-magazine", out var existing);
|
||||
_chamberContainer = Owner.EnsureContainer<ContainerSlot>($"{Name}-chamber");
|
||||
MagazineContainer = Owner.EnsureContainer<ContainerSlot>($"{Name}-magazine", out var existing);
|
||||
|
||||
if (!existing && _magFillPrototype != null)
|
||||
{
|
||||
@@ -192,16 +191,16 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override IEntity? PeekAmmo()
|
||||
public override EntityUid PeekAmmo()
|
||||
{
|
||||
return BoltOpen ? null : _chamberContainer.ContainedEntity;
|
||||
return BoltOpen ? default : _chamberContainer.ContainedEntity;
|
||||
}
|
||||
|
||||
public override IEntity? TakeProjectile(EntityCoordinates spawnAt)
|
||||
public override EntityUid TakeProjectile(EntityCoordinates spawnAt)
|
||||
{
|
||||
if (BoltOpen)
|
||||
{
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
var entity = _chamberContainer.ContainedEntity;
|
||||
|
||||
@@ -320,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveMagazine(IEntity user)
|
||||
public void RemoveMagazine(EntityUiduser)
|
||||
{
|
||||
var mag = MagazineContainer.ContainedEntity;
|
||||
|
||||
@@ -347,7 +346,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public bool CanInsertMagazine(IEntity user, IEntity magazine, bool quiet = true)
|
||||
public bool CanInsertMagazine(EntityUid user, EntityUid magazine, bool quiet = true)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(magazine, out RangedMagazineComponent? magazineComponent))
|
||||
{
|
||||
@@ -385,7 +384,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public void InsertMagazine(IEntity user, IEntity magazine)
|
||||
public void InsertMagazine(EntityUid user, EntityUidmagazine)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundMagInsert.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-success"));
|
||||
|
||||
@@ -6,8 +6,6 @@ using Content.Server.Administration.Logs;
|
||||
using Content.Server.Camera;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
@@ -22,7 +20,6 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -45,6 +42,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
// it's just when I re-organised it changed me as the contributor
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override FireRateSelector FireRateSelector => _fireRateSelector;
|
||||
|
||||
@@ -59,8 +57,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
// _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 EntityUid PeekAmmo();
|
||||
public abstract EntityUid TakeProjectile(EntityCoordinates spawnAt);
|
||||
|
||||
// Recoil / spray control
|
||||
[DataField("minAngle")]
|
||||
@@ -149,7 +147,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
protected override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ServerRangedWeaponComponent? rangedWeaponComponent))
|
||||
if (_entities.TryGetComponent(Owner, out ServerRangedWeaponComponent? rangedWeaponComponent))
|
||||
{
|
||||
rangedWeaponComponent.Barrel = null;
|
||||
rangedWeaponComponent.FireHandler -= Fire;
|
||||
@@ -195,7 +193,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// </summary>
|
||||
/// <param name="shooter">Entity that is operating the weapon, usually the player.</param>
|
||||
/// <param name="targetPos">Target position on the map to shoot at.</param>
|
||||
private void Fire(IEntity shooter, Vector2 targetPos)
|
||||
private void Fire(EntityUid shooter, Vector2 targetPos)
|
||||
{
|
||||
if (ShotsLeft == 0)
|
||||
{
|
||||
@@ -204,30 +202,30 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
}
|
||||
|
||||
var ammo = PeekAmmo();
|
||||
var projectile = TakeProjectile(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(shooter).Coordinates);
|
||||
if (projectile == null)
|
||||
var projectile = TakeProjectile(_entities.GetComponent<TransformComponent>(shooter).Coordinates);
|
||||
if (projectile == default)
|
||||
{
|
||||
SoundSystem.Play(Filter.Broadcast(), SoundEmpty.GetSound(), Owner);
|
||||
return;
|
||||
}
|
||||
|
||||
// At this point firing is confirmed
|
||||
var direction = (targetPos - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(shooter).WorldPosition).ToAngle();
|
||||
var direction = (targetPos - _entities.GetComponent<TransformComponent>(shooter).WorldPosition).ToAngle();
|
||||
var angle = GetRecoilAngle(direction);
|
||||
// This should really be client-side but for now we'll just leave it here
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(shooter, out CameraRecoilComponent? recoilComponent))
|
||||
if (_entities.TryGetComponent(shooter, out CameraRecoilComponent? recoilComponent))
|
||||
{
|
||||
recoilComponent.Kick(-angle.ToVec() * 0.15f);
|
||||
}
|
||||
|
||||
// This section probably needs tweaking so there can be caseless hitscan etc.
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(projectile, out HitscanComponent? hitscan))
|
||||
if (_entities.TryGetComponent(projectile, out HitscanComponent? hitscan))
|
||||
{
|
||||
FireHitscan(shooter, hitscan, angle);
|
||||
}
|
||||
else if (IoCManager.Resolve<IEntityManager>().HasComponent<ProjectileComponent>(projectile) &&
|
||||
ammo != null &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(ammo, out AmmoComponent? ammoComponent))
|
||||
else if (_entities.HasComponent<ProjectileComponent>(projectile) &&
|
||||
ammo != default &&
|
||||
_entities.TryGetComponent(ammo, out AmmoComponent? ammoComponent))
|
||||
{
|
||||
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo);
|
||||
|
||||
@@ -238,7 +236,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
if (ammoComponent.Caseless)
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) ammo);
|
||||
_entities.DeleteEntity(ammo);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -261,8 +259,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// <param name="robustRandom"></param>
|
||||
/// <param name="prototypeManager"></param>
|
||||
/// <param name="ejectDirections"></param>
|
||||
public static void EjectCasing(
|
||||
IEntity entity,
|
||||
public void EjectCasing(
|
||||
EntityUid entity,
|
||||
bool playSound = true,
|
||||
IRobustRandom? robustRandom = null,
|
||||
IPrototypeManager? prototypeManager = null,
|
||||
@@ -273,12 +271,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
|
||||
|
||||
const float ejectOffset = 1.8f;
|
||||
var ammo = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(entity);
|
||||
var ammo = _entities.GetComponent<AmmoComponent>(entity);
|
||||
var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset);
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
|
||||
_entities.GetComponent<TransformComponent>(entity).Coordinates = _entities.GetComponent<TransformComponent>(entity).Coordinates.Offset(offsetPos);
|
||||
_entities.GetComponent<TransformComponent>(entity).LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
|
||||
|
||||
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Coordinates, AudioParams.Default.WithVolume(-1));
|
||||
SoundSystem.Play(Filter.Broadcast(), ammo.SoundCollectionEject.GetSound(), _entities.GetComponent<TransformComponent>(entity).Coordinates, AudioParams.Default.WithVolume(-1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -286,7 +284,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// Wraps EjectCasing to make it less toxic for bulk ejections
|
||||
/// </summary>
|
||||
/// <param name="entities"></param>
|
||||
public static void EjectCasings(IEnumerable<IEntity> entities)
|
||||
public void EjectCasings(IEnumerable<EntityUid> entities)
|
||||
{
|
||||
var robustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
@@ -309,7 +307,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// <summary>
|
||||
/// Handles firing one or many projectiles
|
||||
/// </summary>
|
||||
private void FireProjectiles(IEntity shooter, IEntity baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, IEntity ammo)
|
||||
private void FireProjectiles(EntityUid shooter, EntityUid baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, EntityUid ammo)
|
||||
{
|
||||
List<Angle>? sprayAngleChange = null;
|
||||
if (count > 1)
|
||||
@@ -321,7 +319,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
var firedProjectiles = new EntityUid[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
IEntity projectile;
|
||||
EntityUid projectile;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
@@ -329,8 +327,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
projectile =
|
||||
IoCManager.Resolve<IEntityManager>().SpawnEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(baseProjectile).EntityPrototype?.ID, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(baseProjectile).Coordinates);
|
||||
projectile = _entities.SpawnEntity(
|
||||
_entities.GetComponent<MetaDataComponent>(baseProjectile).EntityPrototype?.ID,
|
||||
_entities.GetComponent<TransformComponent>(baseProjectile).Coordinates);
|
||||
}
|
||||
|
||||
firedProjectiles[i] = projectile;
|
||||
@@ -346,10 +345,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
projectileAngle = angle;
|
||||
}
|
||||
|
||||
var physics = IoCManager.Resolve<IEntityManager>().GetComponent<IPhysBody>(projectile);
|
||||
var physics = _entities.GetComponent<IPhysBody>(projectile);
|
||||
physics.BodyStatus = BodyStatus.InAir;
|
||||
|
||||
var projectileComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ProjectileComponent>(projectile);
|
||||
var projectileComponent = _entities.GetComponent<ProjectileComponent>(projectile);
|
||||
projectileComponent.IgnoreEntity(shooter);
|
||||
|
||||
// FIXME: Work around issue where inserting and removing an entity from a container,
|
||||
@@ -357,16 +356,16 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
// See SharedBroadphaseSystem.HandleContainerInsert()... It sets Awake to false, which causes this.
|
||||
projectile.SpawnTimer(TimeSpan.FromMilliseconds(25), () =>
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<IPhysBody>(projectile)
|
||||
_entities.GetComponent<IPhysBody>(projectile)
|
||||
.LinearVelocity = projectileAngle.ToVec() * velocity;
|
||||
});
|
||||
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(projectile).WorldRotation = projectileAngle + MathHelper.PiOver2;
|
||||
_entities.GetComponent<TransformComponent>(projectile).WorldRotation = projectileAngle + MathHelper.PiOver2;
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(((IComponent) this).Owner, new GunShotEvent(firedProjectiles));
|
||||
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(ammo, new AmmoShotEvent(firedProjectiles));
|
||||
_entities.EventBus.RaiseLocalEvent(((IComponent) this).Owner, new GunShotEvent(firedProjectiles));
|
||||
_entities.EventBus.RaiseLocalEvent(ammo, new AmmoShotEvent(firedProjectiles));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -388,11 +387,11 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
/// <summary>
|
||||
/// Fires hitscan entities and then displays their effects
|
||||
/// </summary>
|
||||
private void FireHitscan(IEntity shooter, HitscanComponent hitscan, Angle angle)
|
||||
private void FireHitscan(EntityUid shooter, HitscanComponent hitscan, Angle angle)
|
||||
{
|
||||
var ray = new CollisionRay(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates.ToMapPos(IoCManager.Resolve<IEntityManager>()), angle.ToVec(), (int) hitscan.CollisionMask);
|
||||
var ray = new CollisionRay(_entities.GetComponent<TransformComponent>(Owner).Coordinates.ToMapPos(_entities), angle.ToVec(), (int) hitscan.CollisionMask);
|
||||
var physicsManager = EntitySystem.Get<SharedPhysicsSystem>();
|
||||
var rayCastResults = physicsManager.IntersectRay(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).MapID, ray, hitscan.MaxLength, shooter, false).ToList();
|
||||
var rayCastResults = physicsManager.IntersectRay(_entities.GetComponent<TransformComponent>(Owner).MapID, ray, hitscan.MaxLength, shooter, false).ToList();
|
||||
|
||||
if (rayCastResults.Count >= 1)
|
||||
{
|
||||
|
||||
@@ -4,14 +4,12 @@ using Content.Server.CombatMode;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Ranged.Barrels.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -60,8 +58,8 @@ namespace Content.Server.Weapon.Ranged
|
||||
public DamageSpecifier? ClumsyDamage;
|
||||
|
||||
public Func<bool>? WeaponCanFireHandler;
|
||||
public Func<IEntity, bool>? UserCanFireHandler;
|
||||
public Action<IEntity, Vector2>? FireHandler;
|
||||
public Func<EntityUid, bool>? UserCanFireHandler;
|
||||
public Action<EntityUid, Vector2>? FireHandler;
|
||||
|
||||
public ServerRangedBarrelComponent? Barrel
|
||||
{
|
||||
@@ -87,7 +85,7 @@ namespace Content.Server.Weapon.Ranged
|
||||
return WeaponCanFireHandler == null || WeaponCanFireHandler();
|
||||
}
|
||||
|
||||
private bool UserCanFire(IEntity user)
|
||||
private bool UserCanFire(EntityUid user)
|
||||
{
|
||||
return (UserCanFireHandler == null || UserCanFireHandler(user)) && EntitySystem.Get<ActionBlockerSystem>().CanInteract(user);
|
||||
}
|
||||
@@ -144,7 +142,7 @@ namespace Content.Server.Weapon.Ranged
|
||||
/// </summary>
|
||||
/// <param name="user">Entity that is operating the weapon, usually the player.</param>
|
||||
/// <param name="targetPos">Target position on the map to shoot at.</param>
|
||||
private void TryFire(IEntity user, Vector2 targetPos)
|
||||
private void TryFire(EntityUid user, Vector2 targetPos)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out HandsComponent? hands) || hands.GetActiveHand?.Owner != Owner)
|
||||
{
|
||||
@@ -187,7 +185,7 @@ namespace Content.Server.Weapon.Ranged
|
||||
|
||||
user.PopupMessage(Loc.GetString("server-ranged-weapon-component-try-fire-clumsy"));
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity((EntityUid) Owner);
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(Owner);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace Content.Server.Weapon
|
||||
{
|
||||
public override string Name => "WeaponCapacitorCharger";
|
||||
|
||||
public override bool IsEntityCompatible(IEntity entity)
|
||||
public override bool IsEntityCompatible(EntityUid entity)
|
||||
{
|
||||
return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null ||
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out PowerCellSlotComponent? slot) && slot.HasCell;
|
||||
}
|
||||
|
||||
protected override BatteryComponent? GetBatteryFrom(IEntity entity)
|
||||
protected override BatteryComponent? GetBatteryFrom(EntityUid entity)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out PowerCellSlotComponent? slot))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user