CatStation/Content.Server/ImmovableRod/ImmovableRodSystem.cs
ScarKy0 3c0f62c006
Changeling Resilience (#44421)
* boom

TODO:
- actual organs

* silly! silly! silly! silly!

* consentual murder

* cleaning

* how woke

* fuck everything

* remove organ replacement, do metabolizer instead

* oops

* thank you, comment i left for myself!

* no ammonia immunity

* whitespace

* Handle a few small things myself

Signed-off-by: Connor Huffine <chuffine@gmail.com>

* some requested changes

* Remove TryGib and Friends

Signed-off-by: Connor Huffine <chuffine@gmail.com>

* Make changelings indestructible

Signed-off-by: Connor Huffine <chuffine@gmail.com>

* Recycler

Signed-off-by: Connor Huffine <chuffine@gmail.com>

* Fix recycler

* Add comments

* Opps!

* Remove metabolizer

* Opps metabolizer system and remove systems!

* Forgot to add them...

* typo

Co-authored-by: SnappingOpossum <snappingopossum@outlook.com>

* Renamed component, fix various systems

* stuff

---------

Signed-off-by: Connor Huffine <chuffine@gmail.com>
Co-authored-by: Connor Huffine <chuffine@gmail.com>
Co-authored-by: beck-thompson <beck314159@hotmail.com>
Co-authored-by: SnappingOpossum <snappingopossum@outlook.com>
2026-07-23 17:49:52 +00:00

155 lines
5.4 KiB
C#

using Content.Server.Destructible;
using Content.Server.Polymorph.Components;
using Content.Server.Popups;
using Content.Shared.Administration.Logs;
using Content.Shared.Body;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Gibbing;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
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 partial class ImmovableRodSystem : EntitySystem
{
[Dependency] private IRobustRandom _random = default!;
[Dependency] private GibbingSystem _gibbing = default!;
[Dependency] private PopupSystem _popup = default!;
[Dependency] private SharedPhysicsSystem _physics = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private DamageableSystem _damageable = default!;
[Dependency] private DestructibleSystem _destructible = default!;
[Dependency] private SharedTransformSystem _transform = default!;
[Dependency] private SharedMapSystem _map = default!;
[Dependency] private ISharedAdminLogManager _adminLogger = 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 EntityQuery<ImmovableRodComponent, TransformComponent>(true))
{
if (!rod.DestroyTiles)
continue;
if (!TryComp<MapGridComponent>(trans.GridUid, out var grid))
continue;
_map.SetTile(trans.GridUid.Value, grid, 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 (TryComp(uid, out PhysicsComponent? phys))
{
_physics.SetLinearDamping(uid, phys, 0f);
_physics.SetFriction(uid, phys, 0f);
_physics.SetBodyStatus(uid, phys, BodyStatus.InAir);
var xform = Transform(uid);
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(uid);
var vel = worldRot.ToWorldVec() * component.MaxSpeed;
if (component.RandomizeVelocity)
{
vel = component.DirectionOverride.Degrees switch
{
0f => _random.NextVector2(component.MinSpeed, component.MaxSpeed),
_ => worldRot.RotateVec(component.DirectionOverride.ToVec()) * _random.NextFloat(component.MinSpeed, component.MaxSpeed)
};
}
_physics.ApplyLinearImpulse(uid, vel, body: phys);
xform.LocalRotation = (vel - worldPos).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);
_adminLogger.Add(LogType.Gib, LogImpact.Low, $"{ToPrettyString(uid)} and {ToPrettyString(ent)} created singularity at X:{coords.X} Y:{coords.Y}");
Del(uid);
Del(ent);
Spawn("Singularity", coords);
return;
}
// Don't delete/hurt self if polymorphed into a rod
if (TryComp<PolymorphedEntityComponent>(uid, out var polymorphed))
{
if (polymorphed.Parent == ent)
return;
}
// gib or damage em
if (HasComp<BodyComponent>(ent))
{
component.MobCount++;
var coords = Transform(uid).Coordinates;
_adminLogger.Add(LogType.Gib, LogImpact.Medium, $"Entity {ToPrettyString(uid)} hit {ToPrettyString(ent)} at X:{coords.X} Y:{coords.Y}");
if (!component.ShouldGib || !_destructible.DestroyEntity(ent))
{
if (component.Damage is null)
return;
_damageable.TryChangeDamage(ent, component.Damage, ignoreResistances: true);
return;
}
_gibbing.Gib(ent);
_popup.PopupEntity(Loc.GetString("immovable-rod-penetrated-mob", ("rod", uid), ("mob", ent)), uid, PopupType.LargeCaution);
return;
}
_destructible.DestroyEntity(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)));
}
}
}