Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Код для мехов #14

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Camera;
using Content.Shared.CombatMode;
using Content.Shared.Mech.Components;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
Expand Down Expand Up @@ -150,14 +151,19 @@ public override void Update(float frameTime)

var entity = entityNull.Value;

if (TryComp<MechPilotComponent>(entity, out var mechPilot))
{
entity = mechPilot.Mech;
}

if (!TryGetGun(entity, out var gunUid, out var gun))
{
return;
}

var useKey = gun.UseKey ? EngineKeyFunctions.Use : EngineKeyFunctions.UseSecondary;

if (_inputSystem.CmdStates.GetState(useKey) != BoundKeyState.Down && !gun.BurstActivated)
if (_inputSystem.CmdStates.GetState(useKey) != BoundKeyState.Down)
{
if (gun.ShotCounter != 0)
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = GetNetEntity(gunUid) });
Expand Down
61 changes: 61 additions & 0 deletions Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 MechGunSystem : 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;
}
}

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;

// TODO: The battery charge of the mech would be spent directly when fired.
if (chargeDelta <= 0 || mech.Energy - chargeDelta < 0)
return;

if (!_mech.TryChangeEnergy(mechEquipment.EquipmentOwner.Value, -chargeDelta, mech))
return;

_battery.SetCharge(uid, component.MaxCharge, component);
}
}
11 changes: 11 additions & 0 deletions Content.Server/Mech/Systems/MechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Content.Shared.Wires;
using Content.Server.Body.Systems;
using Content.Shared.Tools.Systems;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
Expand All @@ -39,6 +41,7 @@ public sealed partial class MechSystem : SharedMechSystem
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;

/// <inheritdoc/>
public override void Initialize()
Expand Down Expand Up @@ -234,6 +237,14 @@ private void OnMechEntry(EntityUid uid, MechComponent component, MechEntryEvent
_popup.PopupEntity(Loc.GetString("mech-no-enter", ("item", uid)), args.User);
return;
}

if (!TryComp<HandsComponent>(args.Args.User, out var handsComponent))
return;

foreach (var hand in _hands.EnumerateHands(args.Args.User, handsComponent))
{
_hands.DoDrop(args.Args.User, hand, true, handsComponent);
}

TryInsert(uid, args.Args.User, component);
_actionBlocker.UpdateCanMove(uid);
Expand Down
32 changes: 26 additions & 6 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.Linq;
using System.Numerics;
using Content.Server.Cargo.Systems;
using Content.Server.Interaction;
using Content.Server.Mech.Equipment.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Stunnable;
using Content.Server.Weapons.Ranged.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Interaction.Components;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged;
Expand All @@ -30,13 +35,16 @@
[Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly PricingSystem _pricing = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;
[Dependency] private readonly StunSystem _stun = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;

private const float DamagePitchVariation = 0.05f;
public const float GunClumsyChance = 0.5f;

public override void Initialize()
{
Expand Down Expand Up @@ -65,14 +73,26 @@
{
userImpulse = true;

if (user != null)
// Try a clumsy roll
// TODO: Who put this here
if (TryComp<ClumsyComponent>(user, out var clumsy) && gun.ClumsyProof == false)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 78 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'ClumsyComponent' could not be found (are you missing a using directive or an assembly reference?)
{
var selfEvent = new SelfBeforeGunShotEvent(user.Value, (gunUid, gun), ammo);
RaiseLocalEvent(user.Value, selfEvent);
if (selfEvent.Cancelled)
for (var i = 0; i < ammo.Count; i++)
{
userImpulse = false;
return;
if (_interaction.TryRollClumsy(user.Value, GunClumsyChance, clumsy))

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 82 in Content.Server/Weapons/Ranged/Systems/GunSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'InteractionSystem' does not contain a definition for 'TryRollClumsy' and no accessible extension method 'TryRollClumsy' accepting a first argument of type 'InteractionSystem' could be found (are you missing a using directive or an assembly reference?)
{
// Wound them
Damageable.TryChangeDamage(user, clumsy.ClumsyDamage, origin: user);
_stun.TryParalyze(user.Value, TimeSpan.FromSeconds(3f), true);

// Apply salt to the wound ("Honk!")
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/bang.ogg"), gunUid);
Audio.PlayPvs(clumsy.ClumsySound, gunUid);

PopupSystem.PopupEntity(Loc.GetString("gun-clumsy"), user.Value);
userImpulse = false;
return;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Mech/Components/MechComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace Content.Shared.Mech.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class MechComponent : Component
{
/// <summary>
/// Whether or not an emag disables it.
/// </summary>
[DataField("breakOnEmag")]
[AutoNetworkedField]
public bool BreakOnEmag = true;

/// <summary>
/// How much "health" the mech has left.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
Expand All @@ -15,6 +17,7 @@
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.Network;
Expand Down Expand Up @@ -51,6 +54,7 @@ public override void Initialize()
SubscribeLocalEvent<MechComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
SubscribeLocalEvent<MechComponent, DragDropTargetEvent>(OnDragDrop);
SubscribeLocalEvent<MechComponent, CanDropTargetEvent>(OnCanDragDrop);
SubscribeLocalEvent<MechComponent, GotEmaggedEvent>(OnEmagged);

SubscribeLocalEvent<MechPilotComponent, GetMeleeWeaponEvent>(OnGetMeleeWeapon);
SubscribeLocalEvent<MechPilotComponent, CanAttackFromContainerEvent>(OnCanAttackFromContainer);
Expand Down Expand Up @@ -449,6 +453,14 @@ private void OnCanDragDrop(EntityUid uid, MechComponent component, ref CanDropTa
args.CanDrop |= !component.Broken && CanInsert(uid, args.Dragged, component);
}

private void OnEmagged(EntityUid uid, MechComponent component, ref GotEmaggedEvent args)
{
if (!component.BreakOnEmag)
return;
args.Handled = true;
component.EquipmentWhitelist = null;
Dirty(uid, component);
}
}

/// <summary>
Expand Down
Loading
Loading