CatStation/Content.Shared/Magic/Systems/AnimateSpellSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

48 lines
2 KiB
C#

using Content.Shared.Magic.Components;
using Content.Shared.Physics;
using Robust.Shared.Containers;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using System.Linq;
namespace Content.Shared.Magic.Systems;
public sealed partial class AnimateSpellSystem : EntitySystem
{
[Dependency] private SharedPhysicsSystem _physics = default!;
[Dependency] private SharedTransformSystem _transform = default!;
[Dependency] private SharedContainerSystem _container = default!;
public override void Initialize()
{
SubscribeLocalEvent<AnimateComponent, MapInitEvent>(OnAnimate);
}
private void OnAnimate(Entity<AnimateComponent> ent, ref MapInitEvent args)
{
// Physics bullshittery necessary for object to behave properly
if (!TryComp<FixturesComponent>(ent, out var fixtures) || !TryComp<PhysicsComponent>(ent, out var physics))
return;
var xform = Transform(ent);
var fixture = fixtures.Fixtures.First();
_transform.Unanchor(ent); // If left anchored they are effectively stuck/immobile and not a threat
_physics.SetCanCollide(ent, true, true, false, fixtures, physics);
_physics.SetCollisionMask(ent, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobMask, fixtures, physics);
_physics.SetCollisionLayer(ent, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobLayer, fixtures, physics);
_physics.SetBodyType(ent, BodyType.KinematicController, fixtures, physics, xform);
_physics.SetBodyStatus(ent, physics, BodyStatus.InAir, true);
_physics.SetFixedRotation(ent, false, true, fixtures, physics);
_physics.SetHard(ent, fixture.Value, true, fixtures);
_container.AttachParentToContainerOrGrid((ent, xform)); // Items animated inside inventory now exit, they can't be picked up and so can't escape otherwise
var ev = new AnimateSpellEvent();
RaiseLocalEvent(ent, ref ev);
}
}
[ByRefEvent]
public readonly record struct AnimateSpellEvent;