diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs index 5aba04bdf8a..29e17bc35ce 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs @@ -4,6 +4,7 @@ using Content.Client.Weapons.Ranged.Components; using Content.Shared.Camera; using Content.Shared.CombatMode; +using Content.Shared.Mech.Components; // Corvax-Frontier using Content.Shared.Weapons.Ranged; using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Events; @@ -144,6 +145,13 @@ public override void Update(float frameTime) var entity = entityNull.Value; + // Corvax-Frontier addition start. + if (TryComp(entity, out var mechPilot)) + { + entity = mechPilot.Mech; + } + // Corvax-Frontier addition end. + if (!TryGetGun(entity, out var gunUid, out var gun)) { return; diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index c569997ffed..dc81e700635 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -12,6 +12,7 @@ using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.Interaction; +using Content.Shared.Mech.Components; // Corvax-Frontier using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Projectiles; @@ -314,6 +315,11 @@ public void Ignite(EntityUid uid, EntityUid ignitionSource, FlammableComponent? if (!Resolve(uid, ref flammable)) return; + // Corvax-Frontier addition start. + if (TryComp(uid, out var mechPilot) && TryComp(mechPilot.Mech, out var mech) && mech.Airtight) + return; + // Corvax-Frontier addition end. + if (flammable.AlwaysCombustible) { flammable.FireStacks = Math.Max(flammable.FirestacksOnIgnite, flammable.FireStacks); diff --git a/Content.Server/Mech/Equipment/EntitySystems/CorvaxMechGunSystem.cs b/Content.Server/Mech/Equipment/EntitySystems/CorvaxMechGunSystem.cs new file mode 100644 index 00000000000..56d671a9a0e --- /dev/null +++ b/Content.Server/Mech/Equipment/EntitySystems/CorvaxMechGunSystem.cs @@ -0,0 +1,73 @@ +/* +This code under CC-BY-SA 3.0, and taken from https://github.com/space-wizards/space-station-14/pull/19263/files#diff-b878680d623afff2ab173822240fcb66e3c989d11e9786490e6b91947383c198. +*/ + +using Content.Server.Mech.Systems; +using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; +using Content.Shared.Mech.Components; +using Content.Shared.Mech.Equipment.Components; +using Content.Shared.Throwing; +using Content.Shared.Weapons.Ranged.Systems; +using Robust.Shared.Random; + +namespace Content.Server.Mech.Equipment.EntitySystems; +public sealed class CorvaxMechGunSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly ThrowingSystem _throwing = default!; + [Dependency] private readonly MechSystem _mech = default!; + [Dependency] private readonly BatterySystem _battery = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(MechGunShot); + } + + private void MechGunShot(EntityUid uid, MechEquipmentComponent component, ref GunShotEvent args) + { + if (!component.EquipmentOwner.HasValue) + return; + + if (!TryComp(component.EquipmentOwner.Value, out var mech)) + return; + + if (TryComp(uid, out var battery)) + { + ChargeGunBattery(uid, battery); + return; + } + + foreach (var (ent, _) in args.Ammo) + { + if (ent.HasValue && mech.EquipmentContainer.Contains(ent.Value)) + { + mech.EquipmentContainer.Remove(ent.Value); + _throwing.TryThrow(ent.Value, _random.NextVector2(), _random.Next(5)); + } + } + } + + private void ChargeGunBattery(EntityUid uid, BatteryComponent component) + { + if (!TryComp(uid, out var mechEquipment) || !mechEquipment.EquipmentOwner.HasValue) + return; + + if (!TryComp(mechEquipment.EquipmentOwner.Value, out var mech)) + return; + + var maxCharge = component.MaxCharge; + var currentCharge = component.CurrentCharge; + + var chargeDelta = maxCharge - currentCharge; + + if (chargeDelta <= 0 || mech.Energy - chargeDelta < 0) + return; + + if (!_mech.TryChangeEnergy(mechEquipment.EquipmentOwner.Value, -chargeDelta, mech)) + return; + + _battery.SetCharge(uid, component.MaxCharge, component); + } +} \ No newline at end of file diff --git a/Content.Server/Mech/Systems/MechSystem.cs b/Content.Server/Mech/Systems/MechSystem.cs index 02dcd6ad19f..1be7534102c 100644 --- a/Content.Server/Mech/Systems/MechSystem.cs +++ b/Content.Server/Mech/Systems/MechSystem.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Server.Atmos.Components; // Corvax-Frontier using Content.Server.Atmos.EntitySystems; using Content.Server.Mech.Components; using Content.Server.Power.Components; diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 66a808bf1fc..3fed30cea8b 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -2,6 +2,7 @@ using System.Numerics; using Content.Server.Cargo.Systems; using Content.Server.Interaction; +using Content.Server.Mech.Equipment.Components; // Corvax-Frontier using Content.Server.Power.EntitySystems; using Content.Server.Projectiles; using Content.Server.Stunnable; @@ -11,6 +12,7 @@ using Content.Shared.Database; using Content.Shared.Effects; using Content.Shared.Interaction.Components; +using Content.Shared.Mech.Equipment.Components; // Corvax-Frontier using Content.Shared.Projectiles; using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Ranged; @@ -130,6 +132,7 @@ protected override bool ShootDirect(EntityUid gunUid, GunComponent gun, EntityUi result = true; Dirty(ent!.Value, cartridge); + break; // Ammo shoots itself case AmmoComponent newAmmo: diff --git a/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs b/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs index 3e759945ce6..f89dcea5bcc 100644 --- a/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs +++ b/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs @@ -15,6 +15,7 @@ using Content.Shared.Movement.Systems; using Content.Shared.Popups; using Content.Shared.Weapons.Melee; +using Content.Shared.Weapons.Ranged.Events; using Robust.Shared.Containers; using Robust.Shared.Network; using Robust.Shared.Serialization; diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 57564f7a480..4d2641c63a0 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -11,6 +11,7 @@ using Content.Shared.Gravity; using Content.Shared.Hands; using Content.Shared.Hands.Components; +using Content.Shared.Mech.Components; // Corvax-Frontier using Content.Shared.Item; // Delta-V: Felinids in duffelbags can't shoot. using Content.Shared.Popups; using Content.Shared.Projectiles; @@ -127,13 +128,16 @@ private void OnShootRequest(RequestShootEvent msg, EntitySessionEventArgs args) { var user = args.SenderSession.AttachedEntity; - if (user == null || - !_combatMode.IsInCombatMode(user) || - !TryGetGun(user.Value, out var ent, out var gun) || - HasComp(user)) // Delta-V: Felinids in duffelbags can't shoot. - { + if (user == null || !_combatMode.IsInCombatMode(user) || HasComp(user)) // Delta-V: Felinids in duffelbags can't shoot. return; - } + + // Corvax-Frontier addition start. + if (TryComp(user.Value, out var mechPilot)) + user = mechPilot.Mech; + + if (!TryGetGun(user.Value, out var ent, out var gun)) + return; + // Corvax-Frontier addition end. if (ent != GetEntity(msg.Gun)) return; @@ -146,15 +150,21 @@ private void OnStopShootRequest(RequestStopShootEvent ev, EntitySessionEventArgs { var gunUid = GetEntity(ev.Gun); - if (args.SenderSession.AttachedEntity == null || - !TryComp(gunUid, out var gun) || - !TryGetGun(args.SenderSession.AttachedEntity.Value, out _, out var userGun)) - { + // Corvax-Frontier addition start. + var user = args.SenderSession.AttachedEntity; + + if (user == null) return; - } - if (userGun != gun) + if (TryComp(user.Value, out var mechPilot)) + user = mechPilot.Mech; + + if (!TryGetGun(user.Value, out var ent, out var gun)) + return; + + if (ent != ev.Gun) return; + // Corvax-Frontier addition end. StopShooting(gunUid, gun); } @@ -172,6 +182,17 @@ public bool TryGetGun(EntityUid entity, out EntityUid gunEntity, [NotNullWhen(tr gunEntity = default; gunComp = null; + // Corvax-Frontier addition start. + if (TryComp(entity, out var mech) && + mech.CurrentSelectedEquipment.HasValue && + TryComp(mech.CurrentSelectedEquipment.Value, out var mechGun)) + { + gunEntity = mech.CurrentSelectedEquipment.Value; + gunComp = mechGun; + return true; + } + // Corvax-Frontier addition end. + if (EntityManager.TryGetComponent(entity, out HandsComponent? hands) && hands.ActiveHandEntity is { } held && TryComp(held, out GunComponent? gun)) @@ -331,8 +352,11 @@ private bool TryTakeAmmo( var shots = 0; var lastFire = gun.NextFire; + Log.Debug($"Nextfire={gun.NextFire} curTime={curTime}"); // Corvax-Frontier addition. + while (gun.NextFire <= curTime) { + Log.Debug("Shots++"); // Corvax-Frontier addition. gun.NextFire += fireRate; shots++; } @@ -356,6 +380,8 @@ private bool TryTakeAmmo( throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!"); } + Log.Debug($"Shots fired: {shots}"); // Corvax-Frontier addition. + var attemptEv = new AttemptShootEvent(user, null); RaiseLocalEvent(gunUid, ref attemptEv);