More (IComponent) shenanigans and also some contaminated IoCManager.Resolve<IEntityManager>() very long yes calls

This commit is contained in:
metalgearsloth
2021-12-07 22:22:34 +11:00
parent 373b5988d7
commit 8af335097f
55 changed files with 176 additions and 172 deletions

View File

@@ -191,7 +191,7 @@ namespace Content.Shared.Body.Components
{
// TODO BODY SYSTEM KILL : Find a more elegant way of killing em than just dumping bloodloss damage.
var damage = new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Bloodloss"), 300);
EntitySystem.Get<DamageableSystem>().TryChangeDamage(((IComponent) part).Owner, damage);
EntitySystem.Get<DamageableSystem>().TryChangeDamage(part.Owner, damage);
}
OnBodyChanged();
@@ -468,7 +468,7 @@ namespace Content.Shared.Body.Components
var i = 0;
foreach (var (part, slot) in SlotParts)
{
parts[i] = (slot.Id, Owner: ((IComponent) part).Owner);
parts[i] = (slot.Id, Owner: part.Owner);
i++;
}

View File

@@ -304,7 +304,7 @@ namespace Content.Shared.Body.Components
foreach (var mechanism in _mechanisms)
{
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(((IComponent) mechanism).Owner, new AddedToBodyEvent(body));
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(mechanism.Owner, new AddedToBodyEvent(body));
}
}
@@ -319,7 +319,7 @@ namespace Content.Shared.Body.Components
foreach (var mechanism in _mechanisms)
{
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(((IComponent) mechanism).Owner, new RemovedFromBodyEvent(old));
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(mechanism.Owner, new RemovedFromBodyEvent(old));
}
}

View File

@@ -75,9 +75,9 @@ namespace Content.Shared.Chemistry
if (component.ModifierTimer > currentTime) continue;
_components.RemoveAt(i);
EntityManager.RemoveComponent<MovespeedModifierMetabolismComponent>(((IComponent) component).Owner);
EntityManager.RemoveComponent<MovespeedModifierMetabolismComponent>(component.Owner);
_movespeed.RefreshMovementSpeedModifiers(((IComponent) component).Owner);
_movespeed.RefreshMovementSpeedModifiers(component.Owner);
}
}
}

View File

@@ -128,9 +128,9 @@ namespace Content.Shared.Damage
SetTotalDamage(component, component.Damage.Total, logChange);
component.Dirty();
if (EntityManager.TryGetComponent<AppearanceComponent>(((IComponent) component).Owner, out var appearance) && damageDelta != null)
if (EntityManager.TryGetComponent<AppearanceComponent>(component.Owner, out var appearance) && damageDelta != null)
appearance.SetData(DamageVisualizerKeys.DamageUpdateGroups, damageDelta.GetDamagePerGroup().Keys.ToList());
RaiseLocalEvent(((IComponent) component).Owner, new DamageChangedEvent(component, damageDelta, interruptsDoAfters), false);
RaiseLocalEvent(component.Owner, new DamageChangedEvent(component, damageDelta, interruptsDoAfters), false);
}
/// <summary>

View File

@@ -56,7 +56,7 @@ namespace Content.Shared.Friction
if (body.Deleted ||
prediction && !body.Predict ||
body.BodyStatus == BodyStatus.InAir ||
Mover.UseMobMovement(((IComponent) body).Owner)) continue;
Mover.UseMobMovement(body.Owner)) continue;
var surfaceFriction = GetTileFriction(body);
var bodyModifier = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<SharedTileFrictionModifier>(body.Owner)?.Modifier ?? 1.0f;

View File

@@ -36,7 +36,7 @@ public class SlowContactsSystem : EntitySystem
foreach (var colliding in _physics.GetCollidingEntities(physicsComponent))
{
var ent = ((IComponent) colliding).Owner;
var ent = colliding.Owner;
if (!EntityManager.TryGetComponent<SlowContactsComponent>(ent, out var slowContactsComponent))
continue;
@@ -49,7 +49,7 @@ public class SlowContactsSystem : EntitySystem
private void OnEntityExit(EntityUid uid, SlowContactsComponent component, EndCollideEvent args)
{
var otherUid = ((IComponent) args.OtherFixture.Body).Owner;
var otherUid = args.OtherFixture.Body.Owner;
if (!EntityManager.HasComponent<MovementSpeedModifierComponent>(otherUid)
|| !EntityManager.HasComponent<SlowsOnContactComponent>(otherUid))
return;
@@ -64,7 +64,7 @@ public class SlowContactsSystem : EntitySystem
private void OnEntityEnter(EntityUid uid, SlowContactsComponent component, StartCollideEvent args)
{
var otherUid = ((IComponent) args.OtherFixture.Body).Owner;
var otherUid = args.OtherFixture.Body.Owner;
if (!EntityManager.HasComponent<MovementSpeedModifierComponent>(otherUid))
return;
if (!_statusCapableInContact.ContainsKey(otherUid))

View File

@@ -167,7 +167,7 @@ namespace Content.Shared.Movement
IoCManager.Resolve<IEntityManager>().HasComponent<MobStateComponent>(body.Owner) &&
// If we're being pulled then don't mess with our velocity.
(!IoCManager.Resolve<IEntityManager>().TryGetComponent(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled) &&
_blocker.CanMove(((IComponent) body).Owner);
_blocker.CanMove((body).Owner);
}
/// <summary>

View File

@@ -47,7 +47,7 @@ namespace Content.Shared.Pulling.Systems
if (args.Puller.Owner != uid)
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out SharedAlertsComponent? alerts))
if (EntityManager.TryGetComponent(component.Owner, out SharedAlertsComponent? alerts))
alerts.ShowAlert(AlertType.Pulling);
RefreshMovementSpeed(component);
@@ -61,7 +61,7 @@ namespace Content.Shared.Pulling.Systems
if (args.Puller.Owner != uid)
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out SharedAlertsComponent? alerts))
if (EntityManager.TryGetComponent(component.Owner, out SharedAlertsComponent? alerts))
alerts.ClearAlert(AlertType.Pulling);
RefreshMovementSpeed(component);
@@ -74,7 +74,7 @@ namespace Content.Shared.Pulling.Systems
private void RefreshMovementSpeed(SharedPullerComponent component)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(((IComponent) component).Owner);
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers((component).Owner);
}
}
}

View File

@@ -36,14 +36,14 @@ namespace Content.Shared.Pulling
// They do not expect to be cancellable.
private void ForceDisconnect(SharedPullerComponent puller, SharedPullableComponent pullable)
{
var pullerPhysics = IoCManager.Resolve<IEntityManager>().GetComponent<PhysicsComponent>(puller.Owner);
var pullablePhysics = IoCManager.Resolve<IEntityManager>().GetComponent<PhysicsComponent>(pullable.Owner);
var pullerPhysics = EntityManager.GetComponent<PhysicsComponent>(puller.Owner);
var pullablePhysics = EntityManager.GetComponent<PhysicsComponent>(pullable.Owner);
// MovingTo shutdown
ForceSetMovingTo(pullable, null);
// Joint shutdown
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<JointComponent?>(puller.Owner, out var jointComp))
if (EntityManager.TryGetComponent<JointComponent?>(puller.Owner, out var jointComp))
{
if (jointComp.GetJoints.Contains(pullable.PullJoint!))
{
@@ -59,10 +59,10 @@ namespace Content.Shared.Pulling
// Messaging
var message = new PullStoppedMessage(pullerPhysics, pullablePhysics);
RaiseLocalEvent(((IComponent) puller).Owner, message, broadcast: false);
RaiseLocalEvent(puller.Owner, message, broadcast: false);
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(pullable.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(pullable.Owner).EntityLifeStage) <= EntityLifeStage.MapInitialized)
RaiseLocalEvent(((IComponent) pullable).Owner, message);
if ((!EntityManager.EntityExists(pullable.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(pullable.Owner).EntityLifeStage) <= EntityLifeStage.MapInitialized)
RaiseLocalEvent(pullable.Owner, message);
// Networking
puller.Dirty();
@@ -81,22 +81,22 @@ namespace Content.Shared.Pulling
var pullableOldPullerE = pullable?.Puller;
if (pullableOldPullerE != null)
{
ForceDisconnect(IoCManager.Resolve<IEntityManager>().GetComponent<SharedPullerComponent>(pullableOldPullerE.Value), pullable!);
ForceDisconnect(EntityManager.GetComponent<SharedPullerComponent>(pullableOldPullerE.Value), pullable!);
}
// Continue with the puller.
var pullerOldPullableE = puller?.Pulling;
if (pullerOldPullableE != null)
{
ForceDisconnect(puller!, IoCManager.Resolve<IEntityManager>().GetComponent<SharedPullableComponent>(pullerOldPullableE.Value));
ForceDisconnect(puller!, EntityManager.GetComponent<SharedPullableComponent>(pullerOldPullableE.Value));
}
// And now for the actual connection (if any).
if ((puller != null) && (pullable != null))
{
var pullerPhysics = IoCManager.Resolve<IEntityManager>().GetComponent<PhysicsComponent>(puller.Owner);
var pullablePhysics = IoCManager.Resolve<IEntityManager>().GetComponent<PhysicsComponent>(pullable.Owner);
var pullerPhysics = EntityManager.GetComponent<PhysicsComponent>(puller.Owner);
var pullablePhysics = EntityManager.GetComponent<PhysicsComponent>(pullable.Owner);
// State startup
puller.Pulling = pullable.Owner;
@@ -106,7 +106,7 @@ namespace Content.Shared.Pulling
var union = pullerPhysics.GetWorldAABB().Union(pullablePhysics.GetWorldAABB());
var length = Math.Max(union.Size.X, union.Size.Y) * 0.75f;
pullable.PullJoint = _jointSystem.CreateDistanceJoint(((IComponent) pullablePhysics).Owner, pullerPhysics.Owner, id:$"pull-joint-{pullablePhysics.Owner}");
pullable.PullJoint = _jointSystem.CreateDistanceJoint(pullablePhysics.Owner, pullerPhysics.Owner, id:$"pull-joint-{pullablePhysics.Owner}");
pullable.PullJoint.CollideConnected = false;
// This maximum has to be there because if the object is constrained too closely, the clamping goes backwards and asserts.
pullable.PullJoint.MaxLength = Math.Max(1.0f, length);
@@ -117,8 +117,8 @@ namespace Content.Shared.Pulling
// Messaging
var message = new PullStartedMessage(pullerPhysics, pullablePhysics);
RaiseLocalEvent(((IComponent) puller).Owner, message, broadcast: false);
RaiseLocalEvent(((IComponent) pullable).Owner, message);
RaiseLocalEvent(puller.Owner, message, broadcast: false);
RaiseLocalEvent(pullable.Owner, message);
// Networking
puller.Dirty();

View File

@@ -29,7 +29,7 @@ namespace Content.Shared.Pulling
public bool CanPull(EntityUid puller, EntityUid pulled)
{
if (!IoCManager.Resolve<IEntityManager>().HasComponent<SharedPullerComponent>(puller))
if (!EntityManager.HasComponent<SharedPullerComponent>(puller))
{
return false;
}
@@ -39,7 +39,7 @@ namespace Content.Shared.Pulling
return false;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<IPhysBody?>(pulled, out var _physics))
if (!EntityManager.TryGetComponent<IPhysBody?>(pulled, out var _physics))
{
return false;
}
@@ -59,7 +59,7 @@ namespace Content.Shared.Pulling
return false;
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedBuckleComponent?>(puller, out var buckle))
if (EntityManager.TryGetComponent<SharedBuckleComponent?>(puller, out var buckle))
{
// Prevent people pulling the chair they're on, etc.
if (buckle.Buckled && (buckle.LastEntityBuckledTo == pulled))
@@ -92,7 +92,7 @@ namespace Content.Shared.Pulling
}
var msg = new StopPullingEvent(user);
RaiseLocalEvent(((IComponent) pullable).Owner, msg);
RaiseLocalEvent(pullable.Owner, msg);
if (msg.Cancelled) return false;
@@ -173,14 +173,14 @@ namespace Content.Shared.Pulling
var pullAttempt = new PullAttemptMessage(pullerPhysics, pullablePhysics);
RaiseLocalEvent(((IComponent) puller).Owner, pullAttempt, broadcast: false);
RaiseLocalEvent(puller.Owner, pullAttempt, broadcast: false);
if (pullAttempt.Cancelled)
{
return false;
}
RaiseLocalEvent(((IComponent) pullable).Owner, pullAttempt);
RaiseLocalEvent(pullable.Owner, pullAttempt);
if (pullAttempt.Cancelled)
{
@@ -198,7 +198,7 @@ namespace Content.Shared.Pulling
return false;
}
if (!IoCManager.Resolve<IEntityManager>().HasComponent<PhysicsComponent>(pullable.Owner))
if (!EntityManager.HasComponent<PhysicsComponent>(pullable.Owner))
{
return false;
}

View File

@@ -164,7 +164,7 @@ namespace Content.Shared.Pulling
// The pulled object may have already been deleted.
// TODO: Work out why. Monkey + meat spike is a good test for this,
// assuming you're still pulling the monkey when it gets gibbed.
if ((!EntityManager.EntityExists(pulled.Value) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(pulled.Value).EntityLifeStage) >= EntityLifeStage.Deleted)
if ((!EntityManager.EntityExists(pulled.Value) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(pulled.Value).EntityLifeStage) >= EntityLifeStage.Deleted)
{
return;
}
@@ -249,16 +249,18 @@ namespace Content.Shared.Pulling
private void UpdatePulledRotation(EntityUid puller, EntityUid pulled)
{
// TODO: update once ComponentReference works with directed event bus.
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(pulled, out RotatableComponent? rotatable))
if (!EntityManager.TryGetComponent(pulled, out RotatableComponent? rotatable))
return;
if (!rotatable.RotateWhilePulling)
return;
var dir = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(puller).WorldPosition - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pulled).WorldPosition;
var pulledXform = EntityManager.GetComponent<TransformComponent>(pulled);
var dir = EntityManager.GetComponent<TransformComponent>(puller).WorldPosition - pulledXform.WorldPosition;
if (dir.LengthSquared > ThresholdRotDistance * ThresholdRotDistance)
{
var oldAngle = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pulled).WorldRotation;
var oldAngle = pulledXform.WorldRotation;
var newAngle = Angle.FromWorldVec(dir);
var diff = newAngle - oldAngle;
@@ -268,10 +270,10 @@ namespace Content.Shared.Pulling
// Otherwise PIANO DOOR STUCK! happens.
// But it also needs to work with station rotation / align to the local parent.
// So...
var baseRotation = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pulled).Parent?.WorldRotation ?? 0f;
var baseRotation = pulledXform.Parent?.WorldRotation ?? 0f;
var localRotation = newAngle - baseRotation;
var localRotationSnapped = Angle.FromDegrees(Math.Floor((localRotation.Degrees / ThresholdRotAngle) + 0.5f) * ThresholdRotAngle);
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(pulled).LocalRotation = localRotationSnapped;
pulledXform.LocalRotation = localRotationSnapped;
}
}
}

View File

@@ -32,7 +32,7 @@ namespace Content.Shared.Slippery
private void HandleCollide(EntityUid uid, SlipperyComponent component, StartCollideEvent args)
{
var otherUid = ((IComponent) args.OtherFixture.Body).Owner;
var otherUid = args.OtherFixture.Body.Owner;
if (!CanSlip(component, otherUid)) return;

View File

@@ -21,7 +21,7 @@ namespace Content.Shared.Storage.EntitySystems
private void CounterEntityInserted(EntityUid uid, ItemCounterComponent itemCounter,
EntInsertedIntoContainerMessage args)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner, out AppearanceComponent? appearanceComponent)) return;
if (!EntityManager.TryGetComponent(itemCounter.Owner, out AppearanceComponent? appearanceComponent)) return;
var count = GetCount(args, itemCounter);
if (count == null)
@@ -36,7 +36,7 @@ namespace Content.Shared.Storage.EntitySystems
private void CounterEntityRemoved(EntityUid uid, ItemCounterComponent itemCounter,
EntRemovedFromContainerMessage args)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(itemCounter.Owner, out AppearanceComponent? appearanceComponent)) return;
if (!EntityManager.TryGetComponent(itemCounter.Owner, out AppearanceComponent? appearanceComponent)) return;
var count = GetCount(args, itemCounter);
if (count == null)

View File

@@ -21,7 +21,7 @@ namespace Content.Shared.Storage.EntitySystems
private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
{
var list = new List<string>(component.MapLayers.Keys);
appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list));
@@ -31,7 +31,7 @@ namespace Content.Shared.Storage.EntitySystems
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
EntRemovedFromContainerMessage args)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers))
{
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
@@ -41,7 +41,7 @@ namespace Content.Shared.Storage.EntitySystems
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
EntInsertedIntoContainerMessage args)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers))
{
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));

View File

@@ -54,7 +54,7 @@ namespace Content.Shared.Throwing
private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args)
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent) ||
if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent) ||
physicsComponent.Fixtures.Count != 1) return;
if (_fixtures.GetFixtureOrNull(physicsComponent, ThrowingFixture) != null)
@@ -114,13 +114,13 @@ namespace Content.Shared.Throwing
public void LandComponent(ThrownItemComponent thrownItem)
{
if (thrownItem.Deleted || (!IoCManager.Resolve<IEntityManager>().EntityExists(thrownItem.Owner) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(thrownItem.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || _containerSystem.IsEntityInContainer(thrownItem.Owner)) return;
if (thrownItem.Deleted || (!EntityManager.EntityExists(thrownItem.Owner) ? EntityLifeStage.Deleted : EntityManager.GetComponent<MetaDataComponent>(thrownItem.Owner).EntityLifeStage) >= EntityLifeStage.Deleted || _containerSystem.IsEntityInContainer(thrownItem.Owner)) return;
var landing = thrownItem.Owner;
// Unfortunately we can't check for hands containers as they have specific names.
if (thrownItem.Owner.TryGetContainerMan(out var containerManager) &&
IoCManager.Resolve<IEntityManager>().HasComponent<SharedHandsComponent>(containerManager.Owner))
EntityManager.HasComponent<SharedHandsComponent>(containerManager.Owner))
{
EntityManager.RemoveComponent(landing, thrownItem);
return;