Files
wwdpublic/Content.Server/ImmovableRod/ImmovableRodSystem.cs
SimpleStation14 156dfb61a8 Mirror: Code cleanup: Purge obsoleted SharedPhysicsSystem methods (#384)
## Mirror of PR #26287: [Code cleanup: Purge obsoleted
SharedPhysicsSystem
methods](https://github.com/space-wizards/space-station-14/pull/26287)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `964c6d54caae45b205a326143f56d6458a1bbc8a`

PR opened by <img
src="https://avatars.githubusercontent.com/u/85356?v=4" width="16"/><a
href="https://github.com/Tayrtahn"> Tayrtahn</a> at 2024-03-20 13:37:25
UTC

---

PR changed 16 files with 43 additions and 43 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> Requires https://github.com/space-wizards/RobustToolbox/pull/4979
> 
> ## About the PR
> <!-- What did you change in this PR? -->
> Cleans up some obsolete method calls.
> 
> ## Why / Balance / Technical
> <!-- Why was it changed? Link any discussions or issues here. Please
discuss how this would affect game balance. -->
> Cleaning up obsolete Dirty calls in RT required changing the
signatures of some public methods in SharedPhysicsSystem. This updates
the calls to those methods here in Content to use the new signatures
passing in UIDs.
> 
> 


</details>

Co-authored-by: SimpleStation14 <Unknown>
2024-05-20 23:57:56 +01:00

122 lines
4.0 KiB
C#

using Content.Server.Body.Systems;
using Content.Server.Popups;
using Content.Shared.Body.Components;
using Content.Shared.Examine;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Random;
namespace Content.Server.ImmovableRod;
public sealed class ImmovableRodSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
// we are deliberately including paused entities. rod hungers for all
foreach (var (rod, trans) in EntityManager.EntityQuery<ImmovableRodComponent, TransformComponent>(true))
{
if (!rod.DestroyTiles)
continue;
if (!_map.TryGetGrid(trans.GridUid, out var grid))
continue;
grid.SetTile(trans.Coordinates, Tile.Empty);
}
}
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ImmovableRodComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<ImmovableRodComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ImmovableRodComponent, ExaminedEvent>(OnExamined);
}
private void OnMapInit(EntityUid uid, ImmovableRodComponent component, MapInitEvent args)
{
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? phys))
{
_physics.SetLinearDamping(uid, phys, 0f);
_physics.SetFriction(uid, phys, 0f);
_physics.SetBodyStatus(uid, phys, BodyStatus.InAir);
if (!component.RandomizeVelocity)
return;
var xform = Transform(uid);
var vel = component.DirectionOverride.Degrees switch
{
0f => _random.NextVector2(component.MinSpeed, component.MaxSpeed),
_ => xform.WorldRotation.RotateVec(component.DirectionOverride.ToVec()) * _random.NextFloat(component.MinSpeed, component.MaxSpeed)
};
_physics.ApplyLinearImpulse(uid, vel, body: phys);
xform.LocalRotation = (vel - xform.WorldPosition).ToWorldAngle() + MathHelper.PiOver2;
}
}
private void OnCollide(EntityUid uid, ImmovableRodComponent component, ref StartCollideEvent args)
{
var ent = args.OtherEntity;
if (_random.Prob(component.HitSoundProbability))
{
_audio.PlayPvs(component.Sound, uid);
}
if (HasComp<ImmovableRodComponent>(ent))
{
// oh god.
var coords = Transform(uid).Coordinates;
_popup.PopupCoordinates(Loc.GetString("immovable-rod-collided-rod-not-good"), coords, PopupType.LargeCaution);
Del(uid);
Del(ent);
Spawn("Singularity", coords);
return;
}
// gib em
if (TryComp<BodyComponent>(ent, out var body))
{
component.MobCount++;
_popup.PopupEntity(Loc.GetString("immovable-rod-penetrated-mob", ("rod", uid), ("mob", ent)), uid, PopupType.LargeCaution);
_bodySystem.GibBody(ent, body: body);
return;
}
QueueDel(ent);
}
private void OnExamined(EntityUid uid, ImmovableRodComponent component, ExaminedEvent args)
{
if (component.MobCount == 0)
{
args.PushText(Loc.GetString("immovable-rod-consumed-none", ("rod", uid)));
}
else
{
args.PushText(Loc.GetString("immovable-rod-consumed-souls", ("rod", uid), ("amount", component.MobCount)));
}
}
}