Skip to content

Commit

Permalink
Mass Bug Fixing (#1256)
Browse files Browse the repository at this point in the history
<!--
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]?
-->

Mass bug fixing, for bugs related to #1220.
Feel free to link or send bugs.

Fix list:
- #1242 
- #1243 
- #1244
- space-wizards/space-station-14#28084
- space-wizards/space-station-14#28282
- Actually fixed PirateRadioSpawnRule heisentest (with a bandaid) (I
cancel if it's 0)
- #1263

---

# Changelog

<!--
You can add an author after the `:cl:` to change the name that appears
in the changelog (ex: `:cl: Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

:cl:
- fix: Fixed chair visuals drawing depth wrongly if you sat in a
north-facing chair.
- fix: Fixed buckling doing several buckles each time you did one.
- fix: Fixed the magic mirror.
- fix: Fixed beds re-positioning you every few seconds.
- fix: Fixed E not opening containers that are in another container.
- fix: Fixed disposal systems not flushing or ejecting properly.

---------

Co-authored-by: sleepyyapril <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>
Co-authored-by: Nemanja <[email protected]>
  • Loading branch information
sleepyyapril and EmoGarbage404 authored Nov 22, 2024
1 parent 1b57045 commit 41501bd
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 125 deletions.
49 changes: 33 additions & 16 deletions Content.Client/Buckle/BuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,41 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
SubscribeLocalEvent<BuckleComponent, BuckledEvent>(OnBuckledEvent);
SubscribeLocalEvent<BuckleComponent, UnbuckledEvent>(OnUnbuckledEvent);
}

/// <summary>
/// Is the strap entity already rotated north? Lower the draw depth of the buckled entity.
/// </summary>
private void OnBuckledEvent(Entity<BuckleComponent> ent, ref BuckledEvent args)
{
if (!TryComp<SpriteComponent>(args.Strap, out var strapSprite) ||
!TryComp<SpriteComponent>(ent.Owner, out var buckledSprite))
return;

if (Transform(args.Strap.Owner).LocalRotation.GetCardinalDir() == Direction.North)
{
ent.Comp.OriginalDrawDepth ??= buckledSprite.DrawDepth;
buckledSprite.DrawDepth = strapSprite.DrawDepth - 1;
}
}

/// <summary>
/// Was the draw depth of the buckled entity lowered? Reset it upon unbuckling.
/// </summary>
private void OnUnbuckledEvent(Entity<BuckleComponent> ent, ref UnbuckledEvent args)
{
if (!TryComp<SpriteComponent>(ent.Owner, out var buckledSprite))
return;

if (ent.Comp.OriginalDrawDepth.HasValue)
{
buckledSprite.DrawDepth = ent.Comp.OriginalDrawDepth.Value;
ent.Comp.OriginalDrawDepth = null;
}
}

private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveEvent args)
Expand Down Expand Up @@ -57,21 +89,6 @@ private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveE
}
}

private void OnHandleState(Entity<BuckleComponent> ent, ref ComponentHandleState args)
{
if (args.Current is not BuckleState state)
return;

ent.Comp.DontCollide = state.DontCollide;
ent.Comp.BuckleTime = state.BuckleTime;
var strapUid = EnsureEntity<BuckleComponent>(state.BuckledTo, ent);

SetBuckledTo(ent, strapUid == null ? null : new (strapUid.Value, null));

var (uid, component) = ent;

}

private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
{
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals)
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Disposal/Tube/DisposalTubeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ private void UpdateAnchored(EntityUid uid, DisposalTubeComponent component, bool
{
if (!Resolve(target, ref targetTube))
return null;

var oppositeDirection = nextDirection.GetOpposite();

var xform = Transform(target);
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
return null;

var position = xform.Coordinates;
var entities = _mapSystem.GetInDir(target, grid, position, nextDirection);
var entities = _mapSystem.GetInDir((EntityUid) xform.GridUid, grid, position, nextDirection);

foreach (var entity in entities)
{
Expand Down
15 changes: 6 additions & 9 deletions Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ public void ExitDisposals(EntityUid uid, DisposalHolderComponent? holder = null,

if (!Resolve(uid, ref holder, ref holderTransform))
return;

if (holder.IsExitingDisposals)
{
Log.Error("Tried exiting disposals twice. This should never happen.");
return;
}

holder.IsExitingDisposals = true;

// Check for a disposal unit to throw them into and then eject them from it.
Expand Down Expand Up @@ -164,11 +166,13 @@ public bool EnterTube(EntityUid holderUid, EntityUid toUid, DisposalHolderCompon
{
if (!Resolve(holderUid, ref holder, ref holderTransform))
return false;

if (holder.IsExitingDisposals)
{
Log.Error("Tried entering tube after exiting disposals. This should never happen.");
return false;
}

if (!Resolve(toUid, ref to, ref toTransform))
{
ExitDisposals(holderUid, holder, holderTransform);
Expand All @@ -193,6 +197,7 @@ public bool EnterTube(EntityUid holderUid, EntityUid toUid, DisposalHolderCompon
holder.PreviousTube = holder.CurrentTube;
holder.PreviousDirection = holder.CurrentDirection;
}

holder.CurrentTube = toUid;
var ev = new GetDisposalsNextDirectionEvent(holder);
RaiseLocalEvent(toUid, ref ev);
Expand All @@ -212,9 +217,7 @@ public bool EnterTube(EntityUid holderUid, EntityUid toUid, DisposalHolderCompon
if (holder.CurrentDirection != holder.PreviousDirection)
{
foreach (var ent in holder.Container.ContainedEntities)
{
_damageable.TryChangeDamage(ent, to.DamageOnTurn);
}
_audio.PlayPvs(to.ClangSound, toUid);
}

Expand All @@ -225,9 +228,7 @@ public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<DisposalHolderComponent>();
while (query.MoveNext(out var uid, out var holder))
{
UpdateComp(uid, holder, frameTime);
}
}

private void UpdateComp(EntityUid uid, DisposalHolderComponent holder, float frameTime)
Expand All @@ -236,9 +237,7 @@ private void UpdateComp(EntityUid uid, DisposalHolderComponent holder, float fra
{
var time = frameTime;
if (time > holder.TimeLeft)
{
time = holder.TimeLeft;
}

holder.TimeLeft -= time;
frameTime -= time;
Expand Down Expand Up @@ -268,17 +267,15 @@ private void UpdateComp(EntityUid uid, DisposalHolderComponent holder, float fra

// Find next tube
var nextTube = _disposalTubeSystem.NextTubeFor(currentTube, holder.CurrentDirection);
if (!EntityManager.EntityExists(nextTube))
if (!EntityManager.EntityExists(nextTube))
{
ExitDisposals(uid, holder);
break;
}

// Perform remainder of entry process
if (!EnterTube(uid, nextTube!.Value, holder))
{
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public bool TryFlush(EntityUid uid, SharedDisposalUnitComponent component)
return false;

var coords = xform.Coordinates;
var entry = _sharedMapSystem.GetLocal(uid, grid, coords)
var entry = _sharedMapSystem.GetLocal((EntityUid) xform.GridUid, grid, coords)
.FirstOrDefault(HasComp<DisposalEntryComponent>);

if (entry == default || component is not DisposalUnitComponent sDisposals)
Expand Down
64 changes: 10 additions & 54 deletions Content.Server/MagicMirror/MagicMirrorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System.Linq;
using Content.Server.DoAfter;
using Content.Server.Humanoid;
using Content.Shared.UserInterface;
using Content.Shared.DoAfter;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Interaction;
using Content.Shared.MagicMirror;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;

namespace Content.Server.MagicMirror;

Expand All @@ -22,14 +19,13 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly MarkingManager _markings = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);

Subs.BuiEvents<MagicMirrorComponent>(MagicMirrorUiKey.Key, subs =>
Subs.BuiEvents<MagicMirrorComponent>(MagicMirrorUiKey.Key,
subs =>
{
subs.Event<BoundUIClosedEvent>(OnUiClosed);
subs.Event<MagicMirrorSelectMessage>(OnMagicMirrorSelect);
Expand All @@ -38,31 +34,13 @@ public override void Initialize()
subs.Event<MagicMirrorRemoveSlotMessage>(OnTryMagicMirrorRemoveSlot);
});

SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);

SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectDoAfterEvent>(OnSelectSlotDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorDoAfterEvent>(OnChangeColorDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorRemoveSlotDoAfterEvent>(OnRemoveSlotDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotDoAfterEvent>(OnAddSlotDoAfter);
}

private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
{
if (!args.CanReach || args.Target == null)
return;

if (!_uiSystem.TryOpenUi(mirror.Owner, MagicMirrorUiKey.Key, args.User))
return;

UpdateInterface(mirror.Owner, args.Target.Value, mirror.Comp);
}

private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
{
if (!HasComp<HumanoidAppearanceComponent>(args.User))
args.Cancel();
}

private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message)
{
if (component.Target is not { } target)
Expand All @@ -87,7 +65,8 @@ private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component,
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
}, out var doAfterId);
},
out var doAfterId);

component.DoAfter = doAfterId;
_audio.PlayPvs(component.ChangeHairSound, uid);
Expand Down Expand Up @@ -143,7 +122,8 @@ private void OnTryMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent com
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
}, out var doAfterId);
},
out var doAfterId);

component.DoAfter = doAfterId;
}
Expand Down Expand Up @@ -198,7 +178,8 @@ private void OnTryMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent comp
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
}, out var doAfterId);
},
out var doAfterId);

component.DoAfter = doAfterId;
_audio.PlayPvs(component.ChangeHairSound, uid);
Expand Down Expand Up @@ -252,7 +233,8 @@ private void OnTryMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent compone
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
}, out var doAfterId);
},
out var doAfterId);

component.DoAfter = doAfterId;
_audio.PlayPvs(component.ChangeHairSound, uid);
Expand Down Expand Up @@ -287,32 +269,6 @@ private void OnAddSlotDoAfter(EntityUid uid, MagicMirrorComponent component, Mag

}

private void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component)
{
if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
return;

var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
? new List<Marking>(hairMarkings)
: new();

var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings)
? new List<Marking>(facialHairMarkings)
: new();

var state = new MagicMirrorUiState(
humanoid.Species,
hair,
humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count,
facialHair,
humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count);

// TODO: Component states
component.Target = targetUid;
_uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
Dirty(mirrorUid, component);
}

private void OnUiClosed(Entity<MagicMirrorComponent> ent, ref BoundUIClosedEvent args)
{
ent.Comp.Target = null;
Expand Down
21 changes: 16 additions & 5 deletions Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class PirateRadioSpawnRule : StationEventSystem<PirateRadioSpawnRu
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly TransformSystem _xform = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;

protected override void Started(EntityUid uid, PirateRadioSpawnRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
Expand All @@ -48,11 +48,12 @@ protected override void Started(EntityUid uid, PirateRadioSpawnRuleComponent com
return;

var targetStation = _random.Pick(stations);
if (!_mapManager.MapExists(Transform(targetStation).MapID))
return; /// SHUT UP HEISENTESTS. DIE.
var targetMapId = Transform(targetStation).MapID;

var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance);
if (!_mapSystem.MapExists(targetMapId))
return;

var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance);
var outpostOptions = new MapLoadOptions
{
Offset = _xform.GetWorldPosition(targetStation) + randomOffset,
Expand All @@ -75,6 +76,7 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList<
{
var outpostaabb = _xform.GetWorldPosition(id);
var k = 0;

while (k < component.DebrisCount)
{
var debrisRandomOffset = _random.NextVector2(component.MinimumDebrisDistance, component.MaximumDebrisDistance);
Expand All @@ -85,7 +87,16 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList<
LoadMap = false,
};

var salvageProto = _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList());
var salvPrototypes = _prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList();
var salvageProto = _random.Pick(salvPrototypes);

if (!_mapSystem.MapExists(GameTicker.DefaultMap))
return;

// Round didn't start before running this, leading to a null-space test fail.
if (GameTicker.DefaultMap == MapId.Nullspace)
return;

if (!_map.TryLoad(GameTicker.DefaultMap, salvageProto.MapPath.ToString(), out _, debrisOptions))
return;

Expand Down
Loading

0 comments on commit 41501bd

Please sign in to comment.