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

AddMechToClothing #2265

Merged
merged 14 commits into from
Nov 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ private void OnInteract(EntityUid uid, MechGrabberComponent component, UserActiv

if (TryComp<PhysicsComponent>(target, out var physics) && physics.BodyType == BodyType.Static ||
HasComp<WallMountComponent>(target) ||
HasComp<MobStateComponent>(target))
HasComp<MobStateComponent>(target) ||
HasComp<MechComponent>(target)) //SS220 Ripley in ripley fix (AddMechToClothing)
{
return;
}
Expand Down
7 changes: 5 additions & 2 deletions Content.Server/Mech/Systems/MechEquipmentSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ private void OnUsed(EntityUid uid, MechEquipmentComponent component, AfterIntera
if (mechComp.Broken)
return;

if (args.User == mechComp.PilotSlot.ContainedEntity)
return;
//SS220-AddMechToClothing-start
//Why does this check exist if it cannot be called?
// if (args.User == mechComp.PilotSlot.ContainedEntity)
// return;
//SS220-AddMechToClothing-end

if (mechComp.EquipmentContainer.ContainedEntities.Count >= mechComp.MaxEquipmentAmount)
return;
Expand Down
41 changes: 40 additions & 1 deletion Content.Server/Mech/Systems/MechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Content.Shared.Whitelist;
using Content.Shared.SS220.MechRobot; //SS220-AddMechToClothing

namespace Content.Server.Mech.Systems;

Expand Down Expand Up @@ -50,6 +51,7 @@ public override void Initialize()
SubscribeLocalEvent<MechComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<MechComponent, GetVerbsEvent<AlternativeVerb>>(OnAlternativeVerb);
SubscribeLocalEvent<MechComponent, MechOpenUiEvent>(OnOpenUi);
SubscribeLocalEvent<MechComponent, MechClothingOpenUiEvent>(OnOpenClothingUi); //SS220-AddMechToClothing
SubscribeLocalEvent<MechComponent, RemoveBatteryEvent>(OnRemoveBattery);
SubscribeLocalEvent<MechComponent, MechEntryEvent>(OnMechEntry);
SubscribeLocalEvent<MechComponent, MechExitEvent>(OnMechExit);
Expand Down Expand Up @@ -163,6 +165,14 @@ private void OnOpenUi(EntityUid uid, MechComponent component, MechOpenUiEvent ar
ToggleMechUi(uid, component);
}

//SS220-AddMechToClothing-start
private void OnOpenClothingUi(Entity<MechComponent> ent, ref MechClothingOpenUiEvent args)
{
args.Handled = true;
ToggleMechClothingUi(ent.Owner, args.Performer, ent.Comp);
}
//SS220-AddMechToClothing-end

private void OnToolUseAttempt(EntityUid uid, MechPilotComponent component, ref ToolUserAttemptUseEvent args)
{
if (args.Target == component.Mech)
Expand All @@ -174,6 +184,11 @@ private void OnAlternativeVerb(EntityUid uid, MechComponent component, GetVerbsE
if (!args.CanAccess || !args.CanInteract || component.Broken)
return;

//SS220-AddMechToClothing-start
if (!TryComp<MechRobotComponent>(uid, out var _))
return;
//SS220-AddMechToClothing-end

if (CanInsert(uid, args.User, component))
{
var enterVerb = new AlternativeVerb
Expand All @@ -197,8 +212,13 @@ private void OnAlternativeVerb(EntityUid uid, MechComponent component, GetVerbsE
args.Verbs.Add(enterVerb);
args.Verbs.Add(openUiVerb);
}
else if (!IsEmpty(component))
else if (!IsEmpty(component, uid)) //SS220-AddMechToClothing
{
//SS220-AddMechToClothing-start
if (!TryComp<MechRobotComponent>(uid, out var _))
return;
//SS220-AddMechToClothing-end

var ejectVerb = new AlternativeVerb
{
Text = Loc.GetString("mech-verb-exit"),
Expand Down Expand Up @@ -229,6 +249,11 @@ private void OnMechEntry(EntityUid uid, MechComponent component, MechEntryEvent
if (args.Cancelled || args.Handled)
return;

//SS220-AddMechToClothing-start
if (!TryComp<MechRobotComponent>(uid, out var _))
return;
//SS220-AddMechToClothing-end

if (_whitelistSystem.IsWhitelistFail(component.PilotWhitelist, args.User))
{
_popup.PopupEntity(Loc.GetString("mech-no-enter", ("item", uid)), args.User);
Expand Down Expand Up @@ -280,6 +305,20 @@ private void ToggleMechUi(EntityUid uid, MechComponent? component = null, Entity
UpdateUserInterface(uid, component);
}

//SS220-AddMechToClothing-start
private void ToggleMechClothingUi(EntityUid entOwner, EntityUid argsPerformer, MechComponent? entComp = null)
{
if (!Resolve(entOwner, ref entComp))
return;

if (!TryComp<ActorComponent>(argsPerformer, out var actor))
return;

_ui.TryToggleUi(entOwner, MechUiKey.Key, actor.PlayerSession);
UpdateUserInterface(entOwner, entComp);
}
//SS220-AddMechToClothing-end

private void ReceiveEquipmentUiMesssages<T>(EntityUid uid, MechComponent component, T args) where T : MechEquipmentUiMessage
{
var ev = new MechEquipmentUiMessageRelayEvent(args);
Expand Down
127 changes: 127 additions & 0 deletions Content.Server/SS220/MechClothing/MechClothingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Server.Interaction;
using Content.Server.Mech.Equipment.Components;
using Content.Server.Mech.Systems;
using Content.Server.Popups;
using Content.Shared.DoAfter;
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.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Content.Shared.SS220.MechClothing;

namespace Content.Server.SS220.MechClothing;

/// <summary>
/// This handles placing containers in claw when the player uses an action, copies part of the logic MechGrabberSystem
/// </summary>
public sealed class MechClothingSystem : EntitySystem
{
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly MechSystem _mech = default!;
[Dependency] private readonly PopupSystem _popup = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MechClothingComponent, MechClothingGrabEvent>(OnInteract);
SubscribeLocalEvent<MechClothingComponent, ComponentStartup>(OnStartUp);
SubscribeLocalEvent<MechClothingComponent, GrabberDoAfterEvent>(OnMechGrab);
}

private void OnStartUp(Entity<MechClothingComponent> ent, ref ComponentStartup args)
{
ent.Comp.ItemContainer = _container.EnsureContainer<Container>(ent.Owner, "item-container");
}

private void OnInteract(Entity<MechClothingComponent> ent, ref MechClothingGrabEvent args)
{
if (!ent.Comp.CurrentEquipmentUid.HasValue)
{
_popup.PopupEntity(Loc.GetString("mech-no-equipment-selected"),ent.Owner,ent.Owner);
return;
}

if (args.Handled)
return;

if (args.Target == args.Performer || ent.Comp.DoAfter != null)
return;

if (TryComp<PhysicsComponent>(args.Target, out var physics) && physics.BodyType == BodyType.Static ||
HasComp<WallMountComponent>(args.Target) ||
HasComp<MobStateComponent>(args.Target) ||
HasComp<MechComponent>(args.Target))
return;

if (Transform(args.Target).Anchored)
return;

if (ent.Comp.ItemContainer.ContainedEntities.Count >= ent.Comp.MaxContents)
return;

if (!TryComp<MechComponent>(ent.Comp.MechUid, out var mech))
return;

if (mech.Energy + ent.Comp.GrabEnergyDelta < 0)
{
_popup.PopupEntity(Loc.GetString("mech-not-enough-energy"), ent.Owner, ent.Owner);
return;
}

if (!_interaction.InRangeUnobstructed(args.Performer, args.Target))
return;

args.Handled = true;
ent.Comp.AudioStream = _audio.PlayPvs(ent.Comp.GrabSound, ent.Owner)?.Entity;
var doAfterArgs = new DoAfterArgs(
EntityManager,
args.Performer,
ent.Comp.GrabDelay,
new GrabberDoAfterEvent(),
ent.Owner,
target: args.Target,
used: ent.Owner)
{
BreakOnMove = true
};

_doAfter.TryStartDoAfter(doAfterArgs, out ent.Comp.DoAfter);
}

private void OnMechGrab(Entity<MechClothingComponent> ent, ref GrabberDoAfterEvent args)
{
if (!TryComp<MechEquipmentComponent>(ent.Comp.CurrentEquipmentUid, out var equipmentComponent) ||
equipmentComponent.EquipmentOwner == null)
return;

ent.Comp.DoAfter = null;

if (args.Cancelled)
{
ent.Comp.AudioStream = _audio.Stop(ent.Comp.AudioStream);
return;
}

if (args.Handled || args.Args.Target == null)
return;

if (!_mech.TryChangeEnergy(equipmentComponent.EquipmentOwner.Value, ent.Comp.GrabEnergyDelta))
return;

if(!TryComp<MechGrabberComponent>(ent.Comp.CurrentEquipmentUid, out var mechGrabberComp))
return;

_container.Insert(args.Args.Target.Value, mechGrabberComp.ItemContainer);
_mech.UpdateUserInterface(equipmentComponent.EquipmentOwner.Value);

args.Handled = true;
}
}
7 changes: 7 additions & 0 deletions Content.Shared/Mech/Components/MechComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public sealed partial class MechComponent : Component
public EntProtoId MechUiAction = "ActionMechOpenUI";
[DataField]
public EntProtoId MechEjectAction = "ActionMechEject";
[DataField]
public EntProtoId MechClothingUiAction= "ActionMechClothingOpenUI"; //SS220-AddMechToClothing
[DataField]
public EntProtoId MechClothingGrabAction= "ActionMechClothingGrab"; //SS220-AddMechToClothing
#endregion

#region Visualizer States
Expand All @@ -158,4 +162,7 @@ public sealed partial class MechComponent : Component
[DataField] public EntityUid? MechCycleActionEntity;
[DataField] public EntityUid? MechUiActionEntity;
[DataField] public EntityUid? MechEjectActionEntity;
[DataField] public EntityUid? MechClothingUiActionEntity; //SS220-AddMechToClothing
[DataField] public EntityUid? MechClothingGrabActionEntity; //SS220-AddMechToClothing

}
Loading
Loading