Inline TryGetComponent completely, for real
This commit is contained in:
@@ -51,7 +51,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private bool _bufferModeTransfer = true;
|
||||
|
||||
[ViewVariables]
|
||||
private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables]
|
||||
private Solution BufferSolution => _bufferSolution ??= EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner.Uid, SolutionName);
|
||||
@@ -183,7 +183,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private ChemMasterBoundUserInterfaceState GetUserInterfaceState()
|
||||
{
|
||||
var beaker = BeakerSlot.Item;
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
if (beaker is null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(beaker.Uid, out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
{
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, false, FixedPoint2.New(0), FixedPoint2.New(0),
|
||||
@@ -208,7 +208,7 @@ namespace Content.Server.Chemistry.Components
|
||||
if (!BeakerSlot.HasItem && _bufferModeTransfer) return;
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
if (beaker is null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(beaker.Uid, out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var beakerSolution))
|
||||
return;
|
||||
|
||||
@@ -316,8 +316,8 @@ namespace Content.Server.Chemistry.Components
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(bottle.Uid, bottleSolution, bufferSolution);
|
||||
|
||||
//Try to give them the bottle
|
||||
if (user.TryGetComponent<HandsComponent>(out var hands) &&
|
||||
bottle.TryGetComponent<ItemComponent>(out var item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands) &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(bottle.Uid, out var item))
|
||||
{
|
||||
if (hands.CanPutInHand(item))
|
||||
{
|
||||
@@ -357,15 +357,15 @@ namespace Content.Server.Chemistry.Components
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(pill.Uid, pillSolution, bufferSolution);
|
||||
|
||||
//Change pill Sprite component state
|
||||
if (!pill.TryGetComponent(out SpriteComponent? sprite))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(pill.Uid, out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sprite?.LayerSetState(0, "pill" + _pillType);
|
||||
|
||||
//Try to give them the bottle
|
||||
if (user.TryGetComponent<HandsComponent>(out var hands) &&
|
||||
pill.TryGetComponent<ItemComponent>(out var item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(user.Uid, out var hands) &&
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(pill.Uid, out var item))
|
||||
{
|
||||
if (hands.CanPutInHand(item))
|
||||
{
|
||||
@@ -393,12 +393,12 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
void IActivate.Activate(ActivateEventArgs args)
|
||||
{
|
||||
if (!args.User.TryGetComponent(out ActorComponent? actor))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.User.TryGetComponent(out HandsComponent? hands))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("chem-master-component-activate-no-hands"));
|
||||
return;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
protected override void UpdateVisuals()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance) &&
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
appearance.SetData(FoamVisuals.Color, solution.Color.WithAlpha(0.80f));
|
||||
@@ -35,13 +35,13 @@ namespace Content.Server.Chemistry.Components
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
return;
|
||||
|
||||
if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out BloodstreamComponent? bloodstream))
|
||||
return;
|
||||
|
||||
// TODO: Add a permeability property to clothing
|
||||
// For now it just adds to protection for each clothing equipped
|
||||
var protection = 0f;
|
||||
if (entity.TryGetComponent(out InventoryComponent? inventory))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out InventoryComponent? inventory))
|
||||
{
|
||||
foreach (var slot in inventory.Slots)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityLifeStage) >= EntityLifeStage.Deleted)
|
||||
return;
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(FoamVisuals.State, true);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
TryInject(targetEntity, refillableSolution, eventArgs.User, true);
|
||||
}
|
||||
else if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
else if (IoCManager.Resolve<IEntityManager>().TryGetComponent(targetEntity.Uid, out BloodstreamComponent? bloodstream))
|
||||
{
|
||||
TryInjectIntoBloodstream(bloodstream, eventArgs.User);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ReagentDispenserUiKey.Key);
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace Content.Server.Chemistry.Components
|
||||
private ReagentDispenserBoundUserInterfaceState GetUserInterfaceState()
|
||||
{
|
||||
var beaker = BeakerSlot.Item;
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
if (beaker == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(beaker.Uid, out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
{
|
||||
return new ReagentDispenserBoundUserInterfaceState(Powered, false, FixedPoint2.New(0),
|
||||
@@ -251,7 +251,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (beaker == null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits) ||
|
||||
if (beaker == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(beaker.Uid, out FitsInDispenserComponent? fits) ||
|
||||
!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(beaker.Uid, fits.Solution, out var solution))
|
||||
return;
|
||||
@@ -269,7 +269,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
var beaker = BeakerSlot.Item;
|
||||
|
||||
if (beaker is null || !beaker.TryGetComponent(out FitsInDispenserComponent? fits)
|
||||
if (beaker is null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(beaker.Uid, out FitsInDispenserComponent? fits)
|
||||
|| !EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(beaker.Uid, fits.Solution, out var solution)) return;
|
||||
|
||||
@@ -285,12 +285,12 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
void IActivate.Activate(ActivateEventArgs args)
|
||||
{
|
||||
if (!args.User.TryGetComponent(out ActorComponent? actor))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.User.TryGetComponent(out HandsComponent? hands))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(args.User.Uid, out HandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("reagent-dispenser-component-activate-no-hands"));
|
||||
return;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
protected override void UpdateVisuals()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance) &&
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
{
|
||||
appearance.SetData(SmokeVisuals.Color, solution.Color);
|
||||
@@ -31,10 +31,10 @@ namespace Content.Server.Chemistry.Components
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
|
||||
return;
|
||||
|
||||
if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out BloodstreamComponent? bloodstream))
|
||||
return;
|
||||
|
||||
if (entity.TryGetComponent(out InternalsComponent? internals) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out InternalsComponent? internals) &&
|
||||
internals.AreInternalsWorking())
|
||||
return;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Content.Server.Chemistry.Components
|
||||
|
||||
var newEffect = IoCManager.Resolve<IEntityManager>().SpawnEntity(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype.ID, grid.DirectionToGrid(coords, dir));
|
||||
|
||||
if (!newEffect.TryGetComponent(out SolutionAreaEffectComponent? effectComponent))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(newEffect.Uid, out SolutionAreaEffectComponent? effectComponent))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(newEffect.Uid);
|
||||
return;
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace Content.Server.Chemistry.Components
|
||||
}
|
||||
|
||||
|
||||
if (CanReceive && target.TryGetComponent(out ReagentTankComponent? tank)
|
||||
if (CanReceive && IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out ReagentTankComponent? tank)
|
||||
&& solutionsSys.TryGetRefillableSolution(Owner.Uid, out var ownerRefill)
|
||||
&& solutionsSys.TryGetDrainableSolution(eventArgs.Target.Uid, out var targetDrain))
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Chemistry.Components
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SpriteComponent? sprite) &&
|
||||
sprite.BaseRSIPath != null)
|
||||
{
|
||||
InitialSprite = new SpriteSpecifier.Rsi(new ResourcePath(sprite.BaseRSIPath), "icon");
|
||||
|
||||
Reference in New Issue
Block a user