CatStation/Content.Server/StationEvents/Events/ImmovableRodRule.cs
Whatstone f42f8df6d1
Cleanup: ProtoMan Part 2 - remove Client and Server EntitySystem IPrototypeManager instances (#44416)
* Remove all IPrototypeManager instances

* Remove redundant IComponentFactory instances too

* Found some stragglers

* DestructibleSystem.PrototypeManager: no dependency

* not based
2026-06-29 21:33:56 +00:00

46 lines
1.9 KiB
C#

using System.Numerics;
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 TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
using System.Linq;
namespace Content.Server.StationEvents.Events;
public sealed partial class ImmovableRodRule : StationEventSystem<ImmovableRodRuleComponent>
{
[Dependency] private SharedTransformSystem _transform = default!;
[Dependency] private GunSystem _gun = default!;
[Dependency] private 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.TryComp<ImmovableRodComponent>(out var rod, EntityManager.ComponentFactory) &&
proto.TryComp<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}");
}
}
}