Remove gun .Owners (#14585)

This commit is contained in:
metalgearsloth
2023-03-11 20:08:22 +11:00
committed by GitHub
parent 19f5c403b5
commit 330bb7bb14
18 changed files with 333 additions and 280 deletions

View File

@@ -36,20 +36,24 @@ public sealed class GunSpreadOverlay : Overlay
var player = _player.LocalPlayer?.ControlledEntity;
if (player == null ||
!_entManager.TryGetComponent<TransformComponent>(player, out var xform)) return;
!_entManager.TryGetComponent<TransformComponent>(player, out var xform))
{
return;
}
var mapPos = xform.MapPosition;
if (mapPos.MapId == MapId.Nullspace) return;
if (mapPos.MapId == MapId.Nullspace)
return;
var gun = _guns.GetGun(player.Value);
if (gun == null) return;
if (!_guns.TryGetGun(player.Value, out var gunUid, out var gun))
return;
var mouseScreenPos = _input.MouseScreenPosition;
var mousePos = _eye.ScreenToMap(mouseScreenPos);
if (mapPos.MapId != mousePos.MapId) return;
if (mapPos.MapId != mousePos.MapId)
return;
// (☞゚ヮ゚)☞
var maxSpread = gun.MaxAngle;

View File

@@ -27,7 +27,8 @@ public sealed partial class GunSystem
/// <param name="component"></param>
private void RefreshControl(EntityUid uid, AmmoCounterComponent? component = null)
{
if (!Resolve(uid, ref component, false)) return;
if (!Resolve(uid, ref component, false))
return;
component.Control?.Dispose();
component.Control = null;
@@ -44,7 +45,8 @@ public sealed partial class GunSystem
private void UpdateAmmoCount(EntityUid uid, AmmoCounterComponent component)
{
if (component.Control == null) return;
if (component.Control == null)
return;
var ev = new UpdateAmmoCounterEvent()
{
@@ -59,7 +61,8 @@ public sealed partial class GunSystem
// Don't use resolves because the method is shared and there's no compref and I'm trying to
// share as much code as possible
if (!Timing.IsFirstTimePredicted ||
!TryComp<AmmoCounterComponent>(uid, out var clientComp)) return;
!TryComp<AmmoCounterComponent>(uid, out var clientComp))
return;
UpdateAmmoCount(uid, clientComp);
}

View File

@@ -12,10 +12,8 @@ using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Animations;
using Robust.Shared.Audio;
using Robust.Shared.Input;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem;
@@ -35,7 +33,9 @@ public sealed partial class GunSystem : SharedGunSystem
get => _spreadOverlay;
set
{
if (_spreadOverlay == value) return;
if (_spreadOverlay == value)
return;
_spreadOverlay = value;
var overlayManager = IoCManager.Resolve<IOverlayManager>();
@@ -131,9 +131,8 @@ public sealed partial class GunSystem : SharedGunSystem
}
var entity = entityNull.Value;
var gun = GetGun(entity);
if (gun == null)
if (!TryGetGun(entity, out var gunUid, out var gun))
{
return;
}
@@ -141,7 +140,7 @@ public sealed partial class GunSystem : SharedGunSystem
if (_inputSystem.CmdStates.GetState(EngineKeyFunctions.Use) != BoundKeyState.Down)
{
if (gun.ShotCounter != 0)
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = gun.Owner });
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = gunUid });
return;
}
@@ -153,40 +152,40 @@ public sealed partial class GunSystem : SharedGunSystem
if (mousePos.MapId == MapId.Nullspace)
{
if (gun.ShotCounter != 0)
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = gun.Owner });
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = gunUid });
return;
}
// Define target coordinates relative to gun entity, so that network latency on moving grids doesn't fuck up the target location.
var coordinates = EntityCoordinates.FromMap(entity, mousePos, EntityManager);
var coordinates = EntityCoordinates.FromMap(entity, mousePos, Transform, EntityManager);
Sawmill.Debug($"Sending shoot request tick {Timing.CurTick} / {Timing.CurTime}");
EntityManager.RaisePredictiveEvent(new RequestShootEvent
{
Coordinates = coordinates,
Gun = gun.Owner,
Gun = gunUid,
});
}
public override void Shoot(GunComponent gun, List<IShootable> ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid? user = null)
public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid? Entity, IShootable Shootable)> ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid? user = null)
{
// Rather than splitting client / server for every ammo provider it's easier
// to just delete the spawned entities. This is for programmer sanity despite the wasted perf.
// This also means any ammo specific stuff can be grabbed as necessary.
var direction = fromCoordinates.ToMapPos(EntityManager) - toCoordinates.ToMapPos(EntityManager);
var direction = fromCoordinates.ToMapPos(EntityManager, Transform) - toCoordinates.ToMapPos(EntityManager, Transform);
foreach (var ent in ammo)
foreach (var (ent, shootable) in ammo)
{
switch (ent)
switch (shootable)
{
case CartridgeAmmoComponent cartridge:
if (!cartridge.Spent)
{
SetCartridgeSpent(cartridge, true);
MuzzleFlash(gun.Owner, cartridge, user);
Audio.PlayPredicted(gun.SoundGunshot, gun.Owner, user);
SetCartridgeSpent(ent!.Value, cartridge, true);
MuzzleFlash(gunUid, cartridge, user);
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Recoil(user, direction);
// TODO: Can't predict entity deletions.
//if (cartridge.DeleteOnSpawn)
@@ -194,24 +193,24 @@ public sealed partial class GunSystem : SharedGunSystem
}
else
{
Audio.PlayPredicted(gun.SoundEmpty, gun.Owner, user);
Audio.PlayPredicted(gun.SoundEmpty, gunUid, user);
}
if (cartridge.Owner.IsClientSide())
Del(cartridge.Owner);
if (ent!.Value.IsClientSide())
Del(ent.Value);
break;
case AmmoComponent newAmmo:
MuzzleFlash(gun.Owner, newAmmo, user);
Audio.PlayPredicted(gun.SoundGunshot, gun.Owner, user);
MuzzleFlash(gunUid, newAmmo, user);
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Recoil(user, direction);
if (newAmmo.Owner.IsClientSide())
Del(newAmmo.Owner);
if (ent!.Value.IsClientSide())
Del(ent.Value);
else
RemComp<AmmoComponent>(newAmmo.Owner);
RemComp<AmmoComponent>(ent.Value);
break;
case HitscanPrototype:
Audio.PlayPredicted(gun.SoundGunshot, gun.Owner, user);
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
Recoil(user, direction);
break;
}
@@ -220,13 +219,17 @@ public sealed partial class GunSystem : SharedGunSystem
private void Recoil(EntityUid? user, Vector2 recoil)
{
if (!Timing.IsFirstTimePredicted || user == null || recoil == Vector2.Zero) return;
if (!Timing.IsFirstTimePredicted || user == null || recoil == Vector2.Zero)
return;
_recoil.KickCamera(user.Value, recoil.Normalized * 0.5f);
}
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
{
if (uid == null || user == null || !Timing.IsFirstTimePredicted) return;
if (uid == null || user == null || !Timing.IsFirstTimePredicted)
return;
PopupSystem.PopupEntity(message, uid.Value, user.Value);
}