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

МЕХИ!!!! #347

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions 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; // Goobstation
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
Expand Down Expand Up @@ -147,6 +148,9 @@ public override void Update(float frameTime)

var entity = entityNull.Value;

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

if (!TryGetGun(entity, out var gunUid, out var gun))
{
return;
Expand Down
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);
}
}
29 changes: 29 additions & 0 deletions Content.Shared/Interaction/ActivateInWorldEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,32 @@ public ActivateInWorldEvent(EntityUid user, EntityUid target)
Target = target;
}
}

/// <summary>
/// Event raised on the user when it activates something in the world
/// </summary>
[PublicAPI]
public sealed class UserActivateInWorldEvent : HandledEntityEventArgs, ITargetedInteractEventArgs
{
/// <summary>
/// Entity that activated the target world entity.
/// </summary>
public EntityUid User { get; }

/// <summary>
/// Entity that was activated in the world.
/// </summary>
public EntityUid Target { get; }

/// <summary>
/// Whether or not <see cref="User"/> can perform complex interactions or only basic ones.
/// </summary>
public bool Complex;

public UserActivateInWorldEvent(EntityUid user, EntityUid target, bool complex)
{
User = user;
Target = target;
Complex = complex;
}
}
10 changes: 10 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>
/// Goobstation: 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 Expand Up @@ -141,6 +148,8 @@ public sealed partial class MechComponent : Component
[DataField]
public EntProtoId MechCycleAction = "ActionMechCycleEquipment";
[DataField]
public EntProtoId ToggleAction = "ActionToggleLight"; //Goobstation Mech Lights toggle action
[DataField]
public EntProtoId MechUiAction = "ActionMechOpenUI";
[DataField]
public EntProtoId MechEjectAction = "ActionMechEject";
Expand All @@ -158,4 +167,5 @@ public sealed partial class MechComponent : Component
[DataField] public EntityUid? MechCycleActionEntity;
[DataField] public EntityUid? MechUiActionEntity;
[DataField] public EntityUid? MechEjectActionEntity;
[DataField, AutoNetworkedField] public EntityUid? ToggleActionEntity; //Goobstation Mech Lights toggle action
}
32 changes: 23 additions & 9 deletions Content.Shared/Mech/EntitySystems/SharedMechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;

// Goobstation Change
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Weapons.Ranged.Events;

namespace Content.Shared.Mech.EntitySystems;

/// <summary>
Expand All @@ -37,18 +43,20 @@ public abstract class SharedMechSystem : EntitySystem
[Dependency] private readonly SharedMoverController _mover = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MechComponent, MechToggleEquipmentEvent>(OnToggleEquipmentAction);
SubscribeLocalEvent<MechComponent, MechEjectPilotEvent>(OnEjectPilotEvent);
SubscribeLocalEvent<MechComponent, InteractNoHandEvent>(RelayInteractionEvent);
SubscribeLocalEvent<MechComponent, UserActivateInWorldEvent>(RelayInteractionEvent);
SubscribeLocalEvent<MechComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<MechComponent, DestructionEventArgs>(OnDestruction);
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 All @@ -71,7 +79,7 @@ private void OnEjectPilotEvent(EntityUid uid, MechComponent component, MechEject
TryEject(uid, component);
}

private void RelayInteractionEvent(EntityUid uid, MechComponent component, InteractNoHandEvent args)
private void RelayInteractionEvent(EntityUid uid, MechComponent component, UserActivateInWorldEvent args)
{
var pilot = component.PilotSlot.ContainedEntity;
if (pilot == null)
Expand Down Expand Up @@ -130,6 +138,7 @@ private void SetupUser(EntityUid mech, EntityUid pilot, MechComponent? component
_actions.AddAction(pilot, ref component.MechCycleActionEntity, component.MechCycleAction, mech);
_actions.AddAction(pilot, ref component.MechUiActionEntity, component.MechUiAction, mech);
_actions.AddAction(pilot, ref component.MechEjectActionEntity, component.MechEjectAction, mech);
_actions.AddAction(pilot, ref component.ToggleActionEntity, component.ToggleAction, mech); //Goobstation Mech Lights toggle action
}

private void RemoveUser(EntityUid mech, EntityUid pilot)
Expand Down Expand Up @@ -194,7 +203,7 @@ public void CycleEquipment(EntityUid uid, MechComponent? component = null)
if (_net.IsServer)
_popup.PopupEntity(popupString, uid);

Dirty(component);
Dirty(uid, component);
}

/// <summary>
Expand All @@ -216,9 +225,6 @@ public void InsertEquipment(EntityUid uid, EntityUid toInsert, MechComponent? co
if (component.EquipmentContainer.ContainedEntities.Count >= component.MaxEquipmentAmount)
return;

if (component.EquipmentWhitelist != null && !component.EquipmentWhitelist.IsValid(toInsert))
return;

equipmentComponent.EquipmentOwner = uid;
_container.Insert(toInsert, component.EquipmentContainer);
var ev = new MechEquipmentInsertedEvent(uid);
Expand Down Expand Up @@ -278,7 +284,7 @@ public virtual bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, MechCompon
return false;

component.Energy = FixedPoint2.Clamp(component.Energy + delta, 0, component.MaxEnergy);
Dirty(component);
Dirty(uid, component);
UpdateUserInterface(uid, component);
return true;
}
Expand Down Expand Up @@ -306,7 +312,7 @@ public void SetIntegrity(EntityUid uid, FixedPoint2 value, MechComponent? compon
UpdateAppearance(uid, component);
}

Dirty(component);
Dirty(uid, component);
UpdateUserInterface(uid, component);
}

Expand Down Expand Up @@ -434,7 +440,7 @@ private void OnDragDrop(EntityUid uid, MechComponent component, ref DragDropTarg

var doAfterEventArgs = new DoAfterArgs(EntityManager, args.Dragged, component.EntryDelay, new MechEntryEvent(), uid, target: uid)
{
BreakOnUserMove = true,
BreakOnMove = true,
};

_doAfter.TryStartDoAfter(doAfterEventArgs);
Expand All @@ -447,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) // Goobstation
{
if (!component.BreakOnEmag)
return;
args.Handled = true;
component.EquipmentWhitelist = null;
Dirty(uid, component);
}
}

/// <summary>
Expand Down
41 changes: 30 additions & 11 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Item; // Delta-V: Felinids in duffelbags can't shoot.
using Content.Shared.Mech.Components; // Goobstation
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Tag;
Expand All @@ -22,6 +23,7 @@
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
Expand Down Expand Up @@ -64,6 +66,7 @@ public abstract partial class SharedGunSystem : EntitySystem
[Dependency] protected readonly TagSystem TagSystem = default!;
[Dependency] protected readonly ThrowingSystem ThrowingSystem = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;

private const float InteractNextFire = 0.3f;
private const double SafetyNextFire = 0.5;
Expand Down Expand Up @@ -127,12 +130,15 @@ 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.
{
!_combatMode.IsInCombatMode(user))
return;

if (TryComp<MechPilotComponent>(user.Value, out var mechPilot))
user = mechPilot.Mech;

if (!TryGetGun(user.Value, out var ent, out var gun) ||
HasComp<ItemComponent>(user))
return;
}

if (ent != GetEntity(msg.Gun))
return;
Expand All @@ -146,14 +152,18 @@ 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))
{
var user = args.SenderSession.AttachedEntity;

if (user == null)
return;

if (TryComp<MechPilotComponent>(user.Value, out var mechPilot))
user = mechPilot.Mech;

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

if (userGun != gun)
if (ent != gunUid)
return;

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

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;
}

if (EntityManager.TryGetComponent(entity, out HandsComponent? hands) &&
hands.ActiveHandEntity is { } held &&
TryComp(held, out GunComponent? gun))
Expand Down
Loading
Loading