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

вывод аврита из маппула, ввод дельты взамен #635

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 27 additions & 1 deletion Content.Client/Mech/MechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
using Content.Shared.Mech.EntitySystems;
using Robust.Client.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
using Robust.Shared.Audio.Systems;
using Robust.Client.Player;

namespace Content.Client.Mech;

/// <inheritdoc/>
public sealed class MechSystem : SharedMechSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;

[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MechComponent, AppearanceChangeEvent>(OnAppearanceChanged);
SubscribeLocalEvent<MechComponent, MechEntryEvent>(OnMechEntry);
SubscribeLocalEvent<MechComponent, MechEquipmentDestroyedEvent>(OnEquipmentDestroyed);
}

private void OnAppearanceChanged(EntityUid uid, MechComponent component, ref AppearanceChangeEvent args)
Expand All @@ -43,4 +49,24 @@ private void OnAppearanceChanged(EntityUid uid, MechComponent component, ref App
layer.SetState(state);
args.Sprite.DrawDepth = (int) drawDepth;
}
private void OnMechEntry(EntityUid uid, MechComponent component, MechEntryEvent args)
{
var player = _playerManager.LocalPlayer;
var playerEntity = player?.ControlledEntity;
if (playerEntity == null)
{
return;
}
_audio.PlayPredicted(component.MechEntrySound, uid, playerEntity);
}
private void OnEquipmentDestroyed(EntityUid uid, MechComponent component, MechEquipmentDestroyedEvent args)
{
var player = _playerManager.LocalPlayer;
var playerEntity = player?.ControlledEntity;
if (playerEntity == null)
{
return;
}
_audio.PlayPredicted(component.MechEntrySound, uid, playerEntity);
}
}
17 changes: 17 additions & 0 deletions Content.Server/Mech/Equipment/Components/MechArmorComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Damage;

namespace Content.Server.Mech.Equipment.Components;

/// <summary>
/// A piece of mech equipment that grabs entities and stores them
/// inside of a container so large objects can be moved.
/// </summary>
[RegisterComponent]
public sealed partial class MechArmorComponent : Component
{
/// <summary>
/// damage modifiers to add
/// </summary>
[DataField(required: true)]
public DamageModifierSet Modifiers = default!;
}
14 changes: 13 additions & 1 deletion Content.Server/Mech/Equipment/Components/MechGrabberComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Numerics;
using System.Numerics;
using System.Threading;
using Content.Shared.DoAfter;
using Robust.Shared.Audio;
Expand Down Expand Up @@ -38,6 +38,18 @@ public sealed partial class MechGrabberComponent : Component
[DataField("maxContents")]
public int MaxContents = 10;

/// <summary>
/// is it possible to grab a mob?
/// </summary>
[DataField("grabmobs")]
public bool GrabMobs = false;

/// <summary>
/// is it slow mob's metabolism?
/// </summary>
[DataField("creo")]
public bool SlowMetabolism = false;

/// <summary>
/// The sound played when a mech is grabbing something
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Content.Server/Mech/Equipment/Components/MechGunComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Content.Shared.Mech.Equipment.Components;

/// <summary>
/// A piece of mech equipment that grabs entities and stores them
/// inside of a container so large objects can be moved.
/// </summary>
[RegisterComponent]
public sealed partial class MechGunComponent : Component
{
}
public sealed class MechShootEvent : CancellableEntityEventArgs
{
public EntityUid User;

public MechShootEvent(EntityUid user)
{
User = user;
}
}

78 changes: 78 additions & 0 deletions Content.Server/Mech/Equipment/EntitySystems/MechArmorSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Linq;
using Content.Server.Interaction;
using Content.Server.Mech.Equipment.Components;
using Content.Server.Mech.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Mech;
using Content.Shared.Mech.Components;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Wall;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Content.Shared.Damage;

namespace Content.Server.Mech.Equipment.EntitySystems;

public sealed class MechArmorSystem : EntitySystem
{
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MechArmorComponent, MechEquipmentInsertedEvent>(OnEquipmentInstalled);
SubscribeLocalEvent<MechArmorComponent, MechEquipmentRemovedEvent>(OnEquipmentRemoved);
}

private void OnEquipmentInstalled(EntityUid uid, MechArmorComponent component, ref MechEquipmentInsertedEvent args)
{
if (!TryComp<MechComponent>(args.Mech, out var mech))
return;
mech.Modifiers = SumModifierSets(mech.Modifiers, component.Modifiers);
}

private void OnEquipmentRemoved(EntityUid uid, MechArmorComponent component, ref MechEquipmentRemovedEvent args)
{
if (!TryComp<MechComponent>(args.Mech, out var mech))
return;
mech.Modifiers = MinodifierSets(mech.Modifiers, component.Modifiers);
}

private DamageModifierSet SumModifierSets(DamageModifierSet modifier1, DamageModifierSet modifier2)
{
var modifier3 = modifier2;

foreach (var item in modifier1.FlatReduction) {
if (modifier3.FlatReduction.TryGetValue(item.Key, out _) && modifier3.Coefficients[item.Key] <= item.Value){
modifier3.FlatReduction[item.Key] += item.Value;
}
}
foreach (var item in modifier1.Coefficients) {
if (modifier3.Coefficients.TryGetValue(item.Key, out _) && modifier3.Coefficients[item.Key] <= item.Value){
modifier3.Coefficients[item.Key] += item.Value;
}
}
return modifier3;
}
private DamageModifierSet MinodifierSets(DamageModifierSet modifier1, DamageModifierSet modifier2)
{
var modifier3 = modifier2;

foreach (var item in modifier1.FlatReduction) {
if (modifier3.FlatReduction.TryGetValue(item.Key, out _)){
modifier3.FlatReduction[item.Key] -= item.Value;
}
}
foreach (var item in modifier1.Coefficients) {
if (modifier3.Coefficients.TryGetValue(item.Key, out _)){
modifier3.Coefficients[item.Key] -= item.Value;
}
}
return modifier3;
}
}
39 changes: 35 additions & 4 deletions Content.Server/Mech/Equipment/EntitySystems/MechGrabberSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Content.Shared.Mobs.Systems;
using Content.Server.Actions;
using Content.Server.Bed.Components;
using Content.Server.Bed.Sleep;
using Content.Server.Body.Systems;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Bed;
using Content.Shared.Bed.Sleep;
using Content.Shared.Body.Components;
using Content.Shared.Buckle.Components;
using Content.Shared.Damage;
using Content.Shared.Emag.Systems;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Timing;
using Content.Shared.SimpleStation14.Silicon.Components;

namespace Content.Server.Mech.Equipment.EntitySystems;

Expand Down Expand Up @@ -83,7 +99,12 @@ public void RemoveItem(EntityUid uid, EntityUid mech, EntityUid toRemove, MechGr
var xform = Transform(toRemove);
_transform.AttachToGridOrMap(toRemove, xform);
var (mechPos, mechRot) = _transform.GetWorldPositionRotation(mechxform);

if (component.SlowMetabolism)
{
var metabolicEvent = new ApplyMetabolicMultiplierEvent
{Uid = toRemove, Multiplier = 1f};
RaiseLocalEvent(toRemove, metabolicEvent);
}
var offset = mechPos + mechRot.RotateVec(component.DepositOffset);
_transform.SetWorldPositionRotation(xform, offset, Angle.Zero);
_mech.UpdateUserInterface(mech);
Expand Down Expand Up @@ -131,13 +152,17 @@ private void OnInteract(EntityUid uid, MechGrabberComponent component, InteractN
if (args.Target == args.User || component.DoAfter != null)
return;

if (TryComp<PhysicsComponent>(target, out var physics) && physics.BodyType == BodyType.Static ||
if (!component.GrabMobs &&
TryComp<PhysicsComponent>(target, out var physics) && physics.BodyType == BodyType.Static ||
HasComp<WallMountComponent>(target) ||
HasComp<MobStateComponent>(target))
{
return;
if (component.GrabMobs &&
!HasComp<MobStateComponent>(target))
{
return;
}
}

if (Transform(target).Anchored)
return;

Expand Down Expand Up @@ -183,6 +208,12 @@ private void OnMechGrab(EntityUid uid, MechGrabberComponent component, DoAfterEv
return;

_container.Insert(args.Args.Target.Value, component.ItemContainer);
if (component.SlowMetabolism)
{
var metabolicEvent = new ApplyMetabolicMultiplierEvent
{Uid = args.Args.Target.Value, Multiplier = 0.4f};
RaiseLocalEvent(args.Args.Target.Value, metabolicEvent);
}
_mech.UpdateUserInterface(equipmentComponent.EquipmentOwner.Value);

args.Handled = true;
Expand Down
80 changes: 80 additions & 0 deletions Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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;
using Content.Shared.Stunnable;

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!;
[Dependency] private readonly SharedGunSystem _guns = default!;
[Dependency] private readonly SharedStunSystem _stun = 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)
{
_stun.TryParalyze(args.User, TimeSpan.FromSeconds(10), true);
_throwing.TryThrow(args.User, _random.NextVector2(), _random.Next(50));
return;
}
if (!TryComp<MechComponent>(component.EquipmentOwner.Value, out var mech))
{
return;
}
if (TryComp<BatteryComponent>(uid, out var battery))
{
ChargeGunBattery(uid, battery);
return;
}
// In most guns the ammo itself isn't shot but turned into cassings
// and a new projectile is spawned instead, meaning that args.Ammo
// is most likely inside the equipment container (for some odd reason)

// I'm not even sure why this is needed since GunSystem.Shoot() has a
// container check before ejecting, but yet it still puts the spent ammo inside the mech
foreach (var (ent, _) in args.Ammo)
{
if (ent.HasValue && mech.EquipmentContainer.Contains(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);
}
}
Loading
Loading