Files
OldThink/Content.Server/ImmovableRod/ImmovableRodSystem.cs
Aviu00 8922181b84 Cherrypicks 4 (#393)
* Immovable Rod changes (#26757)

* Adds non randomized rod velocity (#27123)

* adds non randomized rod velocity

* Adds despawn suffix to despawn rod

* make fire spreading scale with mass (#27202)

* make fire spreading scale with mass

* realer

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* lower max firestacks to 10, refactor flammable (#27159)

* lower max firestacks to 10, refactor flammable

* fix

* uncap fire stack damage, lower fire stack damage

* fix fire spread round removal (#27986)

* fix a resolve debug assert

* rewrite fire spread

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* fire troll fix (#28034)

Co-authored-by: deltanedas <@deltanedas:kde.org>

* Hide doafters if you're in a container (#29487)

* Hide doafters if you're in a container

* Out of the loop

---------

Co-authored-by: plykiya <plykiya@protonmail.com>

* Add ghost role raffles (#26629)

* Add ghost role raffles

* GRR: Fix dialogue sizing, fix merge

* GRR: Add raffle deciders (winner picker)

* GRR: Make settings prototype based with option to override

* GRR: Use Raffles folder and namespace

* GRR: DataFieldify and TimeSpanify

* GRR: Don't actually DataFieldify HashSet<ICommonSession>s

* GRR: add GetGhostRoleCount() + docs

* update engine on branch

* Ghost role raffles: docs, fix window size, cleanup, etc

* GRR: Admin UI

* GRR: Admin UI: Display initial/max/ext of selected raffle settings proto

* GRR: Make a ton of roles raffled

* Make ERT use short raffle timer (#27830)

Co-authored-by: plykiya <plykiya@protonmail.com>

* gives loneops a proper ghost role raffle (#27841)

* shorten short raffle (#28685)

* - fix: Conflicts.

* - fix.

---------

Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>
Co-authored-by: Plykiya <58439124+Plykiya@users.noreply.github.com>
Co-authored-by: plykiya <plykiya@protonmail.com>
Co-authored-by: no <165581243+pissdemon@users.noreply.github.com>
Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com>
Co-authored-by: HS <81934438+HolySSSS@users.noreply.github.com>
2024-06-29 23:02:26 +03:00

144 lines
4.9 KiB
C#

using Content.Server.Body.Systems;
using Content.Server.Polymorph.Components;
using Content.Server.Popups;
using Content.Shared.Body.Components;
using Content.Shared.Damage;
using Content.Shared.Examine;
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 class ImmovableRodSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = 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!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedTransformSystem _transform = 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 (!TryComp<MapGridComponent>(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);
var xform = Transform(uid);
var worldRot = _transform.GetWorldRotation(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 - _transform.GetWorldPosition(uid)).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;
}
// dont delete/hurt self if polymoprhed into a rod
if (TryComp<PolymorphedEntityComponent>(uid, out var polymorphed))
{
if (polymorphed.Parent == ent)
return;
}
// gib or damage 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);
if (!component.ShouldGib)
{
if (component.Damage == null || !TryComp<DamageableComponent>(ent, out var damageable))
return;
_damageable.SetDamage(ent, damageable, component.Damage);
return;
}
_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)));
}
}
}