Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Isn't worked
Browse files Browse the repository at this point in the history
  • Loading branch information
NULL882 committed Jun 18, 2024
1 parent 8e9cc3b commit 7ad830f
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,13 @@ public override void Update(float frameTime)

var entity = entityNull.Value;

// Corvax-Frontier addition start.
if (TryComp<MechPilotComponent>(entity, out var mechPilot))
{
entity = mechPilot.Mech;
}
// Corvax-Frontier addition end.

if (!TryGetGun(entity, out var gunUid, out var gun))
{
return;
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Atmos/EntitySystems/FlammableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -314,6 +315,11 @@ public void Ignite(EntityUid uid, EntityUid ignitionSource, FlammableComponent?
if (!Resolve(uid, ref flammable))
return;

// Corvax-Frontier addition start.
if (TryComp<MechPilotComponent>(uid, out var mechPilot) && TryComp<MechComponent>(mechPilot.Mech, out var mech) && mech.Airtight)
return;
// Corvax-Frontier addition end.

if (flammable.AlwaysCombustible)
{
flammable.FireStacks = Math.Max(flammable.FirestacksOnIgnite, flammable.FireStacks);
Expand Down
73 changes: 73 additions & 0 deletions Content.Server/Mech/Equipment/EntitySystems/CorvaxMechGunSystem.cs
Original file line number Diff line number Diff line change
@@ -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<MechEquipmentComponent, GunShotEvent>(MechGunShot);
}

private void MechGunShot(EntityUid uid, MechEquipmentComponent component, ref GunShotEvent args)
{
if (!component.EquipmentOwner.HasValue)
return;

if (!TryComp<MechComponent>(component.EquipmentOwner.Value, out var mech))
return;

if (TryComp<BatteryComponent>(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<MechEquipmentComponent>(uid, out var mechEquipment) || !mechEquipment.EquipmentOwner.HasValue)
return;

if (!TryComp<MechComponent>(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);
}
}
1 change: 1 addition & 0 deletions Content.Server/Mech/Systems/MechSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Mech/EntitySystems/SharedMechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 38 additions & 12 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemComponent>(user)) // Delta-V: Felinids in duffelbags can't shoot.
{
if (user == null || !_combatMode.IsInCombatMode(user) || HasComp<ItemComponent>(user)) // Delta-V: Felinids in duffelbags can't shoot.
return;
}

// Corvax-Frontier addition start.
if (TryComp<MechPilotComponent>(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;
Expand All @@ -146,15 +150,21 @@ private void OnStopShootRequest(RequestStopShootEvent ev, EntitySessionEventArgs
{
var gunUid = GetEntity(ev.Gun);

if (args.SenderSession.AttachedEntity == null ||
!TryComp<GunComponent>(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<MechPilotComponent>(user.Value, out var mechPilot))
user = mechPilot.Mech;

if (!TryGetGun(user.Value, out var ent, out var gun))
return;

if (ent != ev.Gun)

Check failure on line 165 in Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Operator '!=' cannot be applied to operands of type 'EntityUid' and 'NetEntity'

Check failure on line 165 in Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

Operator '!=' cannot be applied to operands of type 'EntityUid' and 'NetEntity'
return;
// Corvax-Frontier addition end.

StopShooting(gunUid, gun);
}
Expand All @@ -172,6 +182,17 @@ public bool TryGetGun(EntityUid entity, out EntityUid gunEntity, [NotNullWhen(tr
gunEntity = default;
gunComp = null;

// Corvax-Frontier addition start.
if (TryComp<MechComponent>(entity, out var mech) &&
mech.CurrentSelectedEquipment.HasValue &&
TryComp<GunComponent>(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))
Expand Down Expand Up @@ -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++;
}
Expand All @@ -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);

Expand Down

0 comments on commit 7ad830f

Please sign in to comment.