mech bug fixes (#13155)

* mech bug fixes

* struct events

* fug
This commit is contained in:
Nemanja
2022-12-24 16:33:08 -05:00
committed by GitHub
parent 455939afc1
commit 56bdfad912
5 changed files with 46 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ using Content.Server.Mech.Systems;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Mech; using Content.Shared.Mech;
using Content.Shared.Mech.Equipment.Components; using Content.Shared.Mech.Equipment.Components;
using Content.Shared.MobState.Components;
using Content.Shared.Wall; using Content.Shared.Wall;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Map; using Robust.Shared.Map;
@@ -115,17 +116,17 @@ public sealed class MechGrabberSystem : EntitySystem
private void OnInteract(EntityUid uid, MechGrabberComponent component, InteractNoHandEvent args) private void OnInteract(EntityUid uid, MechGrabberComponent component, InteractNoHandEvent args)
{ {
if (args.Handled || args.Target == null) if (args.Handled || args.Target is not {} target)
return; return;
var xform = Transform(args.Target.Value); var xform = Transform(target);
if (xform.Anchored || HasComp<WallMountComponent>(args.Target.Value)) if (xform.Anchored || HasComp<WallMountComponent>(target) || HasComp<MobStateComponent>(target))
return; return;
if (component.ItemContainer.ContainedEntities.Count >= component.MaxContents) if (component.ItemContainer.ContainedEntities.Count >= component.MaxContents)
return; return;
if (!TryComp<MechComponent>(args.User, out var mech)) if (!TryComp<MechComponent>(args.User, out var mech) || mech.PilotSlot.ContainedEntity == target)
return; return;
if (mech.Energy + component.GrabEnergyDelta < 0) if (mech.Energy + component.GrabEnergyDelta < 0)
@@ -134,17 +135,17 @@ public sealed class MechGrabberSystem : EntitySystem
if (component.Token != null) if (component.Token != null)
return; return;
if (!_interaction.InRangeUnobstructed(args.User, args.Target.Value)) if (!_interaction.InRangeUnobstructed(args.User, target))
return; return;
args.Handled = true; args.Handled = true;
component.Token = new(); component.Token = new();
component.AudioStream = _audio.PlayPvs(component.GrabSound, uid); component.AudioStream = _audio.PlayPvs(component.GrabSound, uid);
_doAfter.DoAfter(new DoAfterEventArgs(args.User, component.GrabDelay, component.Token.Token, args.Target, uid) _doAfter.DoAfter(new DoAfterEventArgs(args.User, component.GrabDelay, component.Token.Token, target, uid)
{ {
BreakOnTargetMove = true, BreakOnTargetMove = true,
BreakOnUserMove = true, BreakOnUserMove = true,
UsedFinishedEvent = new MechGrabberGrabFinishedEvent(args.Target.Value), UsedFinishedEvent = new MechGrabberGrabFinishedEvent(target),
UsedCancelledEvent = new MechGrabberGrabCancelledEvent() UsedCancelledEvent = new MechGrabberGrabCancelledEvent()
}); });
} }

View File

@@ -4,6 +4,7 @@ using Content.Server.Atmos.EntitySystems;
using Content.Server.DoAfter; using Content.Server.DoAfter;
using Content.Server.Mech.Components; using Content.Server.Mech.Components;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Tools;
using Content.Server.Wires; using Content.Server.Wires;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
@@ -52,6 +53,7 @@ public sealed class MechSystem : SharedMechSystem
SubscribeLocalEvent<MechComponent, DamageChangedEvent>(OnDamageChanged); SubscribeLocalEvent<MechComponent, DamageChangedEvent>(OnDamageChanged);
SubscribeLocalEvent<MechComponent, MechEquipmentRemoveMessage>(OnRemoveEquipmentMessage); SubscribeLocalEvent<MechComponent, MechEquipmentRemoveMessage>(OnRemoveEquipmentMessage);
SubscribeLocalEvent<MechPilotComponent, ToolUserAttemptUseEvent>(OnToolUseAttempt);
SubscribeLocalEvent<MechPilotComponent, InhaleLocationEvent>(OnInhale); SubscribeLocalEvent<MechPilotComponent, InhaleLocationEvent>(OnInhale);
SubscribeLocalEvent<MechPilotComponent, ExhaleLocationEvent>(OnExhale); SubscribeLocalEvent<MechPilotComponent, ExhaleLocationEvent>(OnExhale);
SubscribeLocalEvent<MechPilotComponent, AtmosExposedGetAirEvent>(OnExpose); SubscribeLocalEvent<MechPilotComponent, AtmosExposedGetAirEvent>(OnExpose);
@@ -137,6 +139,12 @@ public sealed class MechSystem : SharedMechSystem
ToggleMechUi(uid, component); ToggleMechUi(uid, component);
} }
private void OnToolUseAttempt(EntityUid uid, MechPilotComponent component, ref ToolUserAttemptUseEvent args)
{
if (args.Target == component.Mech)
args.Cancelled = true;
}
private void OnAlternativeVerb(EntityUid uid, MechComponent component, GetVerbsEvent<AlternativeVerb> args) private void OnAlternativeVerb(EntityUid uid, MechComponent component, GetVerbsEvent<AlternativeVerb> args)
{ {
if (!args.CanAccess || !args.CanInteract || component.Broken) if (!args.CanAccess || !args.CanInteract || component.Broken)

View File

@@ -119,6 +119,11 @@ namespace Content.Server.Tools
if (!Resolve(tool, ref toolComponent, false)) if (!Resolve(tool, ref toolComponent, false))
return false; return false;
var ev = new ToolUserAttemptUseEvent(user, target);
RaiseLocalEvent(user, ref ev);
if (ev.Cancelled)
return false;
if (!ToolStartUse(tool, user, fuel, toolQualitiesNeeded, toolComponent)) if (!ToolStartUse(tool, user, fuel, toolQualitiesNeeded, toolComponent))
return false; return false;
@@ -173,6 +178,11 @@ namespace Content.Server.Tools
if (!Resolve(tool, ref toolComponent, false)) if (!Resolve(tool, ref toolComponent, false))
return false; return false;
var ev = new ToolUserAttemptUseEvent(user, target);
RaiseLocalEvent(user, ref ev);
if (ev.Cancelled)
return false;
if (!ToolStartUse(tool, user, fuel, toolQualitiesNeeded, toolComponent)) if (!ToolStartUse(tool, user, fuel, toolQualitiesNeeded, toolComponent))
return false; return false;
@@ -306,6 +316,23 @@ namespace Content.Server.Tools
} }
} }
/// <summary>
/// Event raised on the user of a tool to see if they can actually use it.
/// </summary>
[ByRefEvent]
public struct ToolUserAttemptUseEvent
{
public EntityUid User;
public EntityUid? Target;
public bool Cancelled = false;
public ToolUserAttemptUseEvent(EntityUid user, EntityUid? target)
{
User = user;
Target = target;
}
}
/// <summary> /// <summary>
/// Attempt event called *after* any do afters to see if the tool usage should succeed or not. /// Attempt event called *after* any do afters to see if the tool usage should succeed or not.
/// You can use this event to consume any fuel needed. /// You can use this event to consume any fuel needed.

View File

@@ -4,9 +4,9 @@ using Content.Shared.Access.Systems;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes; using Content.Shared.Actions.ActionTypes;
using Content.Shared.Body.Components;
using Content.Shared.Destructible; using Content.Shared.Destructible;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Components; using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
@@ -18,7 +18,6 @@ using Content.Shared.Popups;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -374,7 +373,7 @@ public abstract class SharedMechSystem : EntitySystem
if (!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
return false; return false;
return IsEmpty(component) && _actionBlocker.CanMove(toInsert) && HasComp<BodyComponent>(toInsert); return IsEmpty(component) && _actionBlocker.CanMove(toInsert) && HasComp<SharedHandsComponent>(toInsert);
} }
/// <summary> /// <summary>

View File

@@ -1,5 +1,5 @@
mech-verb-enter = Enter mech-verb-enter = Enter
mech-verb-exit = Exit mech-verb-exit = Remove pilot
mech-equipment-begin-install = Installing the {THE($item)}... mech-equipment-begin-install = Installing the {THE($item)}...
mech-equipment-finish-install = Finished installing the {THE($item)} mech-equipment-finish-install = Finished installing the {THE($item)}