Files
tbd-station-14/Content.Server/StationEvents/Events/ImmovableRodRule.cs
B_Kirill c1a21693fa Cleanup warnings: Use TransformSystem for anchoring (#39778)
* Cleanup

* Bonus

* I hope this helps

* Revert
2025-09-23 14:52:51 +12:00

49 lines
2.0 KiB
C#

using System.Numerics;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.ImmovableRod;
using Content.Server.StationEvents.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.GameTicking.Components;
using Content.Shared.Storage;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
using System.Linq;
namespace Content.Server.StationEvents.Events;
public sealed class ImmovableRodRule : StationEventSystem<ImmovableRodRuleComponent>
{
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly GunSystem _gun = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
protected override void Started(EntityUid uid, ImmovableRodRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
var protoName = EntitySpawnCollection.GetSpawns(component.RodPrototypes).First();
var proto = _prototypeManager.Index<EntityPrototype>(protoName);
if (proto.TryGetComponent<ImmovableRodComponent>(out var rod, EntityManager.ComponentFactory) &&
proto.TryGetComponent<TimedDespawnComponent>(out var despawn, EntityManager.ComponentFactory))
{
if (!TryFindRandomTile(out _, out _, out _, out var targetCoords))
return;
var speed = RobustRandom.NextFloat(rod.MinSpeed, rod.MaxSpeed);
var angle = RobustRandom.NextAngle();
var direction = angle.ToVec();
var mapCoords = _transform.ToMapCoordinates(targetCoords);
var spawnCoords = mapCoords.Offset(-direction * speed * despawn.Lifetime / 2);
var ent = Spawn(protoName, spawnCoords);
_gun.ShootProjectile(ent, direction, Vector2.Zero, uid, speed: speed);
}
else
{
Sawmill.Error($"Invalid immovable rod prototype: {protoName}");
}
}
}