Exosuit: Ripley (#12668)
* mechs * interaction relay * atmos handling * fuck around with interaction events SPAGHETTI CODE OH MY GOD * more sprites and whatever the hell * more mech shit * more shit for equipment * starting equipment (for nukie mechs and such) * equipment cycling * starting with some of the ui * a fat chunk of ui prototyping * done tinkering with ui * a bunch of ui stuff and what have yous * cleaning up grabber and state handling * make the ui actually functional + watch me port a million icons I swear i'll prune the sprites later blease * start on construction * construction yo mamma * remove some unused files * fix a silly * make the graph sane * make it actually constructible. * print the boards as well, bozo * rebalance part prices * eject action also i appease the russians by remembering to localize * Punch Shit * make mech integrity and repairs work * Make the UI more based STOMP STOMP STOMP STOMP * make equipment even more based * batteries and other such delights * make the ui look pimpin af * make the construction mega based * UI but so epic * equipment * some sweat tweaks * damage rebalancing * restructure tech * fix some shit * mechs inherit access * make icons actually use sprite specifiers * TRAILING COMMAA!!!!! * fix a mild indentation sin * undo this change because it isn't needed * actually fix this * secret webeditting shhhh * place this tech here * comments * foo
This commit is contained in:
167
Content.Server/Mech/Equipment/EntitySystems/MechGrabberSystem.cs
Normal file
167
Content.Server/Mech/Equipment/EntitySystems/MechGrabberSystem.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using System.Linq;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Mech.Components;
|
||||
using Content.Server.Mech.Equipment.Components;
|
||||
using Content.Server.Mech.Systems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Mech;
|
||||
using Content.Shared.Mech.Equipment.Components;
|
||||
using Content.Shared.Wall;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Mech.Equipment.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// Handles <see cref="MechGrabberComponent"/> and all related UI logic
|
||||
/// </summary>
|
||||
public sealed class MechGrabberSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly MechSystem _mech = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly InteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MechGrabberComponent, MechEquipmentUiMessageRelayEvent>(OnGrabberMessage);
|
||||
SubscribeLocalEvent<MechGrabberComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<MechGrabberComponent, MechEquipmentUiStateReadyEvent>(OnUiStateReady);
|
||||
SubscribeLocalEvent<MechGrabberComponent, MechEquipmentRemovedEvent>(OnEquipmentRemoved);
|
||||
SubscribeLocalEvent<MechGrabberComponent, AttemptRemoveMechEquipmentEvent>(OnAttemptRemove);
|
||||
|
||||
SubscribeLocalEvent<MechGrabberComponent, InteractNoHandEvent>(OnInteract);
|
||||
SubscribeLocalEvent<MechGrabberComponent, MechGrabberGrabFinishedEvent>(OnGrabFinished);
|
||||
SubscribeLocalEvent<MechGrabberComponent, MechGrabberGrabCancelledEvent>(OnGrabCancelled);
|
||||
}
|
||||
|
||||
private void OnGrabberMessage(EntityUid uid, MechGrabberComponent component, MechEquipmentUiMessageRelayEvent args)
|
||||
{
|
||||
if (args.Message is not MechGrabberEjectMessage msg)
|
||||
return;
|
||||
|
||||
if (!TryComp<MechEquipmentComponent>(uid, out var equipmentComponent) ||
|
||||
equipmentComponent.EquipmentOwner == null)
|
||||
return;
|
||||
var mech = equipmentComponent.EquipmentOwner.Value;
|
||||
|
||||
var targetCoords = new EntityCoordinates(mech, component.DepositOffset);
|
||||
if (!_interaction.InRangeUnobstructed(mech, targetCoords))
|
||||
return;
|
||||
|
||||
if (!component.ItemContainer.Contains(msg.Item))
|
||||
return;
|
||||
|
||||
RemoveItem(uid, mech, msg.Item, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an item from the grabber's container
|
||||
/// </summary>
|
||||
/// <param name="uid">The mech grabber</param>
|
||||
/// <param name="mech">The mech it belongs to</param>
|
||||
/// <param name="toRemove">The item being removed</param>
|
||||
/// <param name="component"></param>
|
||||
public void RemoveItem(EntityUid uid, EntityUid mech, EntityUid toRemove, MechGrabberComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
component.ItemContainer.Remove(toRemove);
|
||||
var mechxform = Transform(mech);
|
||||
var xform = Transform(toRemove);
|
||||
xform.AttachToGridOrMap();
|
||||
xform.WorldPosition = mechxform.WorldPosition + mechxform.WorldRotation.RotateVec(component.DepositOffset);
|
||||
xform.WorldRotation = Angle.Zero;
|
||||
_mech.UpdateUserInterface(mech);
|
||||
}
|
||||
|
||||
private void OnEquipmentRemoved(EntityUid uid, MechGrabberComponent component, ref MechEquipmentRemovedEvent args)
|
||||
{
|
||||
if (!TryComp<MechEquipmentComponent>(uid, out var equipmentComponent) ||
|
||||
equipmentComponent.EquipmentOwner == null)
|
||||
return;
|
||||
var mech = equipmentComponent.EquipmentOwner.Value;
|
||||
|
||||
var allItems = new List<EntityUid>(component.ItemContainer.ContainedEntities);
|
||||
foreach (var item in allItems)
|
||||
{
|
||||
RemoveItem(uid, mech, item, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAttemptRemove(EntityUid uid, MechGrabberComponent component, ref AttemptRemoveMechEquipmentEvent args)
|
||||
{
|
||||
args.Cancelled = component.ItemContainer.ContainedEntities.Any();
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, MechGrabberComponent component, ComponentStartup args)
|
||||
{
|
||||
component.ItemContainer = _container.EnsureContainer<Container>(uid, "item-container");
|
||||
}
|
||||
|
||||
private void OnUiStateReady(EntityUid uid, MechGrabberComponent component, MechEquipmentUiStateReadyEvent args)
|
||||
{
|
||||
var state = new MechGrabberUiState
|
||||
{
|
||||
Contents = component.ItemContainer.ContainedEntities.ToList(),
|
||||
MaxContents = component.MaxContents
|
||||
};
|
||||
args.States.Add(uid, state);
|
||||
}
|
||||
|
||||
private void OnInteract(EntityUid uid, MechGrabberComponent component, InteractNoHandEvent args)
|
||||
{
|
||||
if (args.Handled || args.Target == null)
|
||||
return;
|
||||
|
||||
var xform = Transform(args.Target.Value);
|
||||
if (xform.Anchored || HasComp<WallMountComponent>(args.Target.Value))
|
||||
return;
|
||||
|
||||
if (component.ItemContainer.ContainedEntities.Count >= component.MaxContents)
|
||||
return;
|
||||
|
||||
if (!TryComp<MechComponent>(args.User, out var mech))
|
||||
return;
|
||||
|
||||
if (mech.Energy + component.GrabEnergyDelta < 0)
|
||||
return;
|
||||
|
||||
if (component.Token != null)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
component.Token = new();
|
||||
component.AudioStream = _audio.PlayPvs(component.GrabSound, uid);
|
||||
_doAfter.DoAfter(new DoAfterEventArgs(args.User, component.GrabDelay, component.Token.Token, args.Target, uid)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
UsedFinishedEvent = new MechGrabberGrabFinishedEvent(args.Target.Value),
|
||||
UserCancelledEvent = new MechGrabberGrabCancelledEvent()
|
||||
});
|
||||
}
|
||||
|
||||
private void OnGrabFinished(EntityUid uid, MechGrabberComponent component, MechGrabberGrabFinishedEvent args)
|
||||
{
|
||||
component.Token = null;
|
||||
|
||||
if (!TryComp<MechEquipmentComponent>(uid, out var equipmentComponent) || equipmentComponent.EquipmentOwner == null)
|
||||
return;
|
||||
if (!_mech.TryChangeEnergy(equipmentComponent.EquipmentOwner.Value, component.GrabEnergyDelta))
|
||||
return;
|
||||
|
||||
component.ItemContainer.Insert(args.Grabbed);
|
||||
_mech.UpdateUserInterface(equipmentComponent.EquipmentOwner.Value);
|
||||
}
|
||||
|
||||
private void OnGrabCancelled(EntityUid uid, MechGrabberComponent component, MechGrabberGrabCancelledEvent args)
|
||||
{
|
||||
component.AudioStream?.Stop();
|
||||
component.Token = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user