Files
tbd-station-14/Content.Client/CardboardBox/CardboardBoxSystem.cs
TemporalOroboros f284b43ff6 Fixes obsolete Transform warnings in Content. (#25256)
* Fix TransformComponent.MapPosition warnings in Content.Client

* Fix TransformComponent.MapPosition warnings in Content.IntegrationTests

* Fix TransformComponent.MapPosition warnings in Content.Shared

* Fix TransformComponent.MapPosition warnings in Content.Server

* Fix TransformComponent.WorldPosition warnings in Content.Shared

* Fix TransformComponent.WorldPosition warnings in Content.Client
Excepts ClickableComponent b/c that needs to be ECS'd entirely later

* Fix TransformComponent.WorldPosition warnings in Content.Server

* Fix TransformComponent.WorldRotation warnings in Content.*

* Fix TransformComponent.MapPosition warnings I missed

* Fix TransformComponent.WorldMatrix warnings in Content.*

* Fix TransformComponent.InvWorldMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrixWithInv warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotation warnings in Content.*

* Fix TransformComponent.Anchored.set warnings in Content.*

* Fix TransformComponent.Coordinates.set warnings in Content.*

* Fix TransformComponent.LocalPosition.set warnings in Content.*

* Fix TransformComponent.AttachToGridOrMap warnings in Content.*

* Fix TransformComponent.AttachParent warnings in Content.*

* Preempt TransformComponent.LocalRotation.set warnings in Content.Shared

* Preempt TransformComponent.LocalRotation.set warnings in Content.Client

* Preempt TransformComponent.LocalRotation.set warnings in Content.IntegrationTests

* Preempt TransformComponent.LocalRotation.set warnings in Content.Server

* Fix/Preempt the remaining obsolete TransformComponent properties/methods in Content.*

* ECS ClickableComponent

* Fix obsolete SharedTransformSystem methods in Content.*

* Fix ExplosionOverlay `SharedTransformSystem` dependency

* Maybe fix null eye position breaking tests

* MGS requested changes
2024-02-27 12:06:20 +11:00

72 lines
2.4 KiB
C#

using System.Numerics;
using Content.Shared.CardboardBox;
using Content.Shared.CardboardBox.Components;
using Content.Shared.Examine;
using Content.Shared.Movement.Components;
using Robust.Client.GameObjects;
namespace Content.Client.CardboardBox;
public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
{
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<PlayBoxEffectMessage>(OnBoxEffect);
}
private void OnBoxEffect(PlayBoxEffectMessage msg)
{
var source = GetEntity(msg.Source);
if (!TryComp<CardboardBoxComponent>(source, out var box))
return;
var xformQuery = GetEntityQuery<TransformComponent>();
if (!xformQuery.TryGetComponent(source, out var xform))
return;
var sourcePos = _transform.GetMapCoordinates((source, xform));
//Any mob that can move should be surprised?
//God mind rework needs to come faster so it can just check for mind
//TODO: Replace with Mind Query when mind rework is in.
var mobMoverEntities = new List<EntityUid>();
var mover = GetEntity(msg.Mover);
//Filter out entities in range to see that they're a mob and add them to the mobMoverEntities hash for faster lookup
var movers = new HashSet<Entity<MobMoverComponent>>();
_entityLookup.GetEntitiesInRange(xform.Coordinates, box.Distance, movers);
foreach (var moverComp in movers)
{
var uid = moverComp.Owner;
if (uid == mover)
continue;
mobMoverEntities.Add(uid);
}
//Play the effect for the mobs as long as they can see the box and are in range.
foreach (var mob in mobMoverEntities)
{
var mapPos = _transform.GetMapCoordinates(mob);
if (!ExamineSystemShared.InRangeUnOccluded(sourcePos, mapPos, box.Distance, null))
continue;
var ent = Spawn(box.Effect, mapPos);
if (!xformQuery.TryGetComponent(ent, out var entTransform) || !TryComp<SpriteComponent>(ent, out var sprite))
continue;
sprite.Offset = new Vector2(0, 1);
_transform.SetParent(ent, entTransform, mob);
}
}
}