Inline GetComponent

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 11:55:25 +01:00
parent c2e6da1e54
commit b835bea086
131 changed files with 363 additions and 299 deletions

View File

@@ -153,7 +153,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
return false;
}
var itemComponent = ammo.GetComponent<ItemComponent>();
var itemComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(ammo.Uid);
if (!handsComponent.CanPutInHand(itemComponent))
{
ammo.Transform.Coordinates = eventArgs.User.Transform.Coordinates;

View File

@@ -106,7 +106,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
return false;
}
var itemComponent = ammo.GetComponent<ItemComponent>();
var itemComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(ammo.Uid);
if (!handsComponent.CanPutInHand(itemComponent))
{
ServerRangedBarrelComponent.EjectCasing(ammo);

View File

@@ -296,7 +296,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
{
return false;
}
if (!chamberedEntity.GetComponent<AmmoComponent>().Caseless)
if (!IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity.Uid).Caseless)
{
EjectCasing(chamberedEntity);
}

View File

@@ -167,7 +167,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (chamberedEntity != null)
{
_chamberContainer.Remove(chamberedEntity);
var ammoComponent = chamberedEntity.GetComponent<AmmoComponent>();
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(chamberedEntity.Uid);
if (!ammoComponent.Caseless)
{
EjectCasing(chamberedEntity);

View File

@@ -209,7 +209,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
IEntity? bullet = null;
if (ammo != null)
{
var ammoComponent = ammo.GetComponent<AmmoComponent>();
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(ammo.Uid);
bullet = ammoComponent.TakeBullet(spawnAt);
if (ammoComponent.Caseless)
{

View File

@@ -55,7 +55,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
return 0;
}
return (int) Math.Ceiling(powerCell.GetComponent<BatteryComponent>().CurrentCharge / _baseFireCost);
return (int) Math.Ceiling(IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCell.Uid).CurrentCharge / _baseFireCost);
}
}
@@ -70,7 +70,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
return 0;
}
return (int) Math.Ceiling((float) (powerCell.GetComponent<BatteryComponent>().MaxCharge / _baseFireCost));
return (int) Math.Ceiling((float) (IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCell.Uid).MaxCharge / _baseFireCost));
}
}
@@ -150,7 +150,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
return null;
}
var capacitor = powerCellEntity.GetComponent<BatteryComponent>();
var capacitor = IoCManager.Resolve<IEntityManager>().GetComponent<BatteryComponent>(powerCellEntity.Uid);
if (capacitor.CurrentCharge < _lowerChargeLimit)
{
return null;
@@ -256,7 +256,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
Dirty();
UpdateAppearance();
if (!hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
if (!hands.PutInHand(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(cell.Owner.Uid)))
{
cell.Owner.Transform.Coordinates = user.Transform.Coordinates;
}

View File

@@ -58,7 +58,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
var magazine = MagazineContainer.ContainedEntity;
if (magazine != null)
{
count += magazine.GetComponent<RangedMagazineComponent>().ShotsLeft;
count += IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine.Uid).ShotsLeft;
}
return count;
@@ -74,7 +74,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
var magazine = MagazineContainer.ContainedEntity;
if (magazine != null)
{
count += magazine.GetComponent<RangedMagazineComponent>().Capacity;
count += IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine.Uid).Capacity;
}
return count;
@@ -206,7 +206,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
var entity = _chamberContainer.ContainedEntity;
Cycle();
return entity?.GetComponent<AmmoComponent>().TakeBullet(spawnAt);
return (entity != null ? IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(entity.Uid) : null).TakeBullet(spawnAt);
}
private void Cycle(bool manual = false)
@@ -280,7 +280,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
{
return false;
}
var ammoComponent = chamberEntity.GetComponent<AmmoComponent>();
var ammoComponent = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(chamberEntity.Uid);
if (!ammoComponent.Caseless)
{
EjectCasing(chamberEntity);
@@ -299,7 +299,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// Try and pull a round from the magazine to replace the chamber if possible
var magazine = MagazineContainer.ContainedEntity;
var nextRound = magazine?.GetComponent<RangedMagazineComponent>().TakeAmmo();
var nextRound = (magazine != null ? IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine.Uid) : null).TakeAmmo();
if (nextRound == null)
{
@@ -308,7 +308,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
_chamberContainer.Insert(nextRound);
if (_autoEjectMag && magazine != null && magazine.GetComponent<RangedMagazineComponent>().ShotsLeft == 0)
if (_autoEjectMag && magazine != null && IoCManager.Resolve<IEntityManager>().GetComponent<RangedMagazineComponent>(magazine.Uid).ShotsLeft == 0)
{
SoundSystem.Play(Filter.Pvs(Owner), _soundAutoEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
@@ -340,7 +340,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
if (user.TryGetComponent(out HandsComponent? handsComponent))
{
handsComponent.PutInHandOrDrop(mag.GetComponent<ItemComponent>());
handsComponent.PutInHandOrDrop(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(mag.Uid));
}
Dirty();

View File

@@ -273,7 +273,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
{Direction.East, Direction.North, Direction.NorthWest, Direction.South, Direction.SouthEast, Direction.West};
const float ejectOffset = 1.8f;
var ammo = entity.GetComponent<AmmoComponent>();
var ammo = IoCManager.Resolve<IEntityManager>().GetComponent<AmmoComponent>(entity.Uid);
var offsetPos = ((robustRandom.NextFloat() - 0.5f) * ejectOffset, (robustRandom.NextFloat() - 0.5f) * ejectOffset);
entity.Transform.Coordinates = entity.Transform.Coordinates.Offset(offsetPos);
entity.Transform.LocalRotation = robustRandom.Pick(ejectDirections).ToAngle();
@@ -346,10 +346,10 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
projectileAngle = angle;
}
var physics = projectile.GetComponent<IPhysBody>();
var physics = IoCManager.Resolve<IEntityManager>().GetComponent<IPhysBody>(projectile.Uid);
physics.BodyStatus = BodyStatus.InAir;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
var projectileComponent = IoCManager.Resolve<IEntityManager>().GetComponent<ProjectileComponent>(projectile.Uid);
projectileComponent.IgnoreEntity(shooter);
// FIXME: Work around issue where inserting and removing an entity from a container,
@@ -357,8 +357,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
// See SharedBroadphaseSystem.HandleContainerInsert()... It sets Awake to false, which causes this.
projectile.SpawnTimer(TimeSpan.FromMilliseconds(25), () =>
{
projectile
.GetComponent<IPhysBody>()
IoCManager.Resolve<IEntityManager>().GetComponent<IPhysBody>(projectile.Uid)
.LinearVelocity = projectileAngle.ToVec() * velocity;
});