mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-25 01:27:06 +03:00
* fix * fix * fix * fix * fix * Fix Bug with Opening Storage Containers (#1292) <!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Fixes the bug with opening storage containers while there's already one opened. --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 - fix: Fixed the bug with opening storage containers while there's already one open. (cherry picked from commit b0407604ced2859ccbdc417345dadc29656f71f0) * Automatic Changelog Update (#1292) (cherry picked from commit 9a40c3783eb0d0e622badc2febcaf0794f6f8ddd) * possible test fix * possible test fix * fix --------- Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Co-authored-by: SimpleStation Changelogs <simplestation14@users.noreply.github.com>
125 lines
5.2 KiB
C#
125 lines
5.2 KiB
C#
using Content.Server.Atmos.Components;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.FootPrint;
|
|
using Content.Shared.Standing;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Fluids.Components;
|
|
using Content.Shared.Maps;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.FootPrint;
|
|
|
|
public sealed class FootPrintsSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
|
[Dependency] private readonly IMapManager _map = default!;
|
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
[Dependency] private readonly StandingStateSystem _standingState = default!; // WD EDIT
|
|
|
|
private EntityQuery<TransformComponent> _transformQuery;
|
|
private EntityQuery<MobThresholdsComponent> _mobThresholdQuery;
|
|
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_transformQuery = GetEntityQuery<TransformComponent>();
|
|
_mobThresholdQuery = GetEntityQuery<MobThresholdsComponent>();
|
|
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
|
|
|
SubscribeLocalEvent<FootPrintsComponent, ComponentStartup>(OnStartupComponent);
|
|
SubscribeLocalEvent<FootPrintsComponent, MoveEvent>(OnMove);
|
|
}
|
|
|
|
private void OnStartupComponent(EntityUid uid, FootPrintsComponent component, ComponentStartup args)
|
|
{
|
|
component.StepSize = Math.Max(0f, component.StepSize + _random.NextFloat(-0.05f, 0.05f));
|
|
}
|
|
|
|
private void OnMove(EntityUid uid, FootPrintsComponent component, ref MoveEvent args)
|
|
{
|
|
if (component.PrintsColor.A <= 0f
|
|
|| !_transformQuery.TryComp(uid, out var transform)
|
|
|| !_mobThresholdQuery.TryComp(uid, out var mobThreshHolds)
|
|
|| !_map.TryFindGridAt(_transform.GetMapCoordinates((uid, transform)), out var gridUid, out _))
|
|
return;
|
|
|
|
var dragging = mobThreshHolds.CurrentThresholdState is MobState.Critical or MobState.Dead
|
|
|| _standingState.IsDown(uid); // WD EDIT
|
|
var distance = (transform.LocalPosition - component.StepPos).Length();
|
|
var stepSize = dragging ? component.DragSize : component.StepSize;
|
|
|
|
if (!(distance > stepSize))
|
|
return;
|
|
|
|
component.RightStep = !component.RightStep;
|
|
|
|
var entity = Spawn(component.StepProtoId, CalcCoords(gridUid, component, transform, dragging));
|
|
var footPrintComponent = EnsureComp<FootPrintComponent>(entity);
|
|
|
|
footPrintComponent.PrintOwner = uid;
|
|
Dirty(entity, footPrintComponent);
|
|
|
|
if (_appearanceQuery.TryComp(entity, out var appearance))
|
|
{
|
|
_appearance.SetData(entity, FootPrintVisualState.State, PickState(uid, dragging), appearance);
|
|
_appearance.SetData(entity, FootPrintVisualState.Color, component.PrintsColor, appearance);
|
|
}
|
|
|
|
if (!_transformQuery.TryComp(entity, out var stepTransform))
|
|
return;
|
|
|
|
stepTransform.LocalRotation = dragging
|
|
? (transform.LocalPosition - component.StepPos).ToAngle() + Angle.FromDegrees(-90f)
|
|
: transform.LocalRotation + Angle.FromDegrees(180f);
|
|
|
|
component.PrintsColor = component.PrintsColor.WithAlpha(Math.Max(0f, component.PrintsColor.A - component.ColorReduceAlpha));
|
|
component.StepPos = transform.LocalPosition;
|
|
|
|
if (!TryComp<SolutionContainerManagerComponent>(entity, out var solutionContainer)
|
|
|| !_solution.ResolveSolution((entity, solutionContainer), footPrintComponent.SolutionName, ref footPrintComponent.Solution, out var solution)
|
|
|| string.IsNullOrWhiteSpace(component.ReagentToTransfer) || solution.Volume >= 1)
|
|
return;
|
|
|
|
_solution.TryAddReagent(footPrintComponent.Solution.Value, component.ReagentToTransfer, 1, out _);
|
|
}
|
|
|
|
private EntityCoordinates CalcCoords(EntityUid uid, FootPrintsComponent component, TransformComponent transform, bool state)
|
|
{
|
|
if (state)
|
|
return new EntityCoordinates(uid, transform.LocalPosition);
|
|
|
|
var offset = component.RightStep
|
|
? new Angle(Angle.FromDegrees(180f) + transform.LocalRotation).RotateVec(component.OffsetPrint)
|
|
: new Angle(transform.LocalRotation).RotateVec(component.OffsetPrint);
|
|
|
|
return new EntityCoordinates(uid, transform.LocalPosition + offset);
|
|
}
|
|
|
|
private FootPrintVisuals PickState(EntityUid uid, bool dragging)
|
|
{
|
|
var state = FootPrintVisuals.BareFootPrint;
|
|
|
|
if (_inventory.TryGetSlotEntity(uid, "shoes", out _))
|
|
state = FootPrintVisuals.ShoesPrint;
|
|
|
|
if (_inventory.TryGetSlotEntity(uid, "outerClothing", out var suit) && TryComp<PressureProtectionComponent>(suit, out _))
|
|
state = FootPrintVisuals.SuitPrint;
|
|
|
|
if (dragging)
|
|
state = FootPrintVisuals.Dragging;
|
|
|
|
return state;
|
|
}
|
|
}
|