Files
crystall-punk-14/Content.Server/StationEvents/Events/ImmovableRodRule.cs

47 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System.Numerics;
2023-07-02 16:40:07 +03:00
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;
2023-07-02 16:40:07 +03:00
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
2023-09-30 14:35:32 +10:00
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
using System.Linq;
2023-07-02 16:40:07 +03:00
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);
2023-07-02 16:40:07 +03:00
if (proto.TryGetComponent<ImmovableRodComponent>(out var rod) && proto.TryGetComponent<TimedDespawnComponent>(out var despawn))
{
if (!TryFindRandomTile(out _, out _, out _, out var targetCoords))
return;
2023-07-02 16:40:07 +03:00
var speed = RobustRandom.NextFloat(rod.MinSpeed, rod.MaxSpeed);
var angle = RobustRandom.NextAngle();
var direction = angle.ToVec();
var spawnCoords = targetCoords.ToMap(EntityManager, _transform).Offset(-direction * speed * despawn.Lifetime / 2);
var ent = Spawn(protoName, spawnCoords);
2023-07-02 16:40:07 +03:00
_gun.ShootProjectile(ent, direction, Vector2.Zero, uid, speed: speed);
}
else
{
Sawmill.Error($"Invalid immovable rod prototype: {protoName}");
2023-07-02 16:40:07 +03:00
}
}
}