Inline TryGetComponent completely, for real

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 14:17:01 +01:00
parent 2ff4ec65d5
commit 69b270017b
425 changed files with 1143 additions and 995 deletions

View File

@@ -38,12 +38,12 @@ namespace Content.Server.Hands.Components
protected override void OnHeldEntityRemovedFromHand(IEntity heldEntity, HandState handState)
{
if (heldEntity.TryGetComponent(out ItemComponent? item))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity.Uid, out ItemComponent? item))
{
item.RemovedFromSlot();
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedHandInteraction(Owner, heldEntity, handState);
}
if (heldEntity.TryGetComponent(out SpriteComponent? sprite))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity.Uid, out SpriteComponent? sprite))
{
sprite.RenderOrder = IoCManager.Resolve<IEntityManager>().CurrentTick.Value;
}
@@ -123,8 +123,8 @@ namespace Content.Server.Hands.Components
private bool BreakPulls()
{
// What is this API??
if (!Owner.TryGetComponent(out SharedPullerComponent? puller)
|| puller.Pulling == null || !puller.Pulling.TryGetComponent(out SharedPullableComponent? pullable))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedPullerComponent? puller)
|| puller.Pulling == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(puller.Pulling.Uid, out SharedPullableComponent? pullable))
return false;
return _entitySystemManager.GetEntitySystem<PullingSystem>().TryStopPull(pullable);
@@ -163,7 +163,7 @@ namespace Content.Server.Hands.Components
if (!TryGetHeldEntity(handName, out var heldEntity))
return null;
heldEntity.TryGetComponent(out ItemComponent? item);
IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity.Uid, out ItemComponent? item);
return item;
}
@@ -177,7 +177,7 @@ namespace Content.Server.Hands.Components
if (!TryGetHeldEntity(handName, out var heldEntity))
return false;
return heldEntity.TryGetComponent(out item);
return IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity.Uid, out item);
}
/// <summary>
@@ -190,7 +190,7 @@ namespace Content.Server.Hands.Components
if (!TryGetActiveHeldEntity(out var heldEntity))
return null;
heldEntity.TryGetComponent(out ItemComponent? item);
IoCManager.Resolve<IEntityManager>().TryGetComponent(heldEntity.Uid, out ItemComponent? item);
return item;
}
}
@@ -199,7 +199,7 @@ namespace Content.Server.Hands.Components
{
foreach (var entity in GetAllHeldEntities())
{
if (entity.TryGetComponent(out ItemComponent? item))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ItemComponent? item))
yield return item;
}
}

View File

@@ -85,7 +85,7 @@ namespace Content.Server.Hands.Systems
foreach (var hand in component.Hands)
{
if (hand.HeldEntity == null
|| !hand.HeldEntity.TryGetComponent(out HandVirtualItemComponent? virtualItem)
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(hand.HeldEntity.Uid, out HandVirtualItemComponent? virtualItem)
|| virtualItem.BlockingEntity != args.Pulled.Owner.Uid)
continue;
@@ -101,7 +101,7 @@ namespace Content.Server.Hands.Systems
if (player == null)
return;
if (!player.TryGetComponent(out SharedHandsComponent? hands))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.Uid, out SharedHandsComponent? hands))
return;
if (!hands.TryGetSwapHandsResult(out var nextHand))
@@ -117,7 +117,7 @@ namespace Content.Server.Hands.Systems
if (player == null)
return false;
if (!player.TryGetComponent(out SharedHandsComponent? hands))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(player.Uid, out SharedHandsComponent? hands))
return false;
var activeHand = hands.ActiveHand;
@@ -194,7 +194,7 @@ namespace Content.Server.Hands.Systems
if (playerEnt == null || !IoCManager.Resolve<IEntityManager>().EntityExists(playerEnt.Uid))
return false;
return playerEnt.TryGetComponent(out hands);
return IoCManager.Resolve<IEntityManager>().TryGetComponent(playerEnt.Uid, out hands);
}
private void HandleActivateItem(ICommonSession? session)
@@ -223,12 +223,12 @@ namespace Content.Server.Hands.Systems
if (playerEnt == null ||
!IoCManager.Resolve<IEntityManager>().EntityExists(playerEnt.Uid) ||
playerEnt.IsInContainer() ||
!playerEnt.TryGetComponent(out SharedHandsComponent? hands) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(playerEnt.Uid, out SharedHandsComponent? hands) ||
!hands.TryGetActiveHeldEntity(out var throwEnt) ||
!_actionBlockerSystem.CanThrow(playerEnt.Uid))
return false;
if (throwEnt.TryGetComponent(out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(throwEnt.Uid, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
{
var splitStack = _stackSystem.Split(throwEnt.Uid, 1, playerEnt.Transform.Coordinates, stack);
@@ -272,12 +272,12 @@ namespace Content.Server.Hands.Systems
if (plyEnt == null || !IoCManager.Resolve<IEntityManager>().EntityExists(plyEnt.Uid))
return;
if (!plyEnt.TryGetComponent(out SharedHandsComponent? hands) ||
!plyEnt.TryGetComponent(out InventoryComponent? inventory))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(plyEnt.Uid, out SharedHandsComponent? hands) ||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(plyEnt.Uid, out InventoryComponent? inventory))
return;
if (!inventory.TryGetSlotItem(equipmentSlot, out ItemComponent? equipmentItem) ||
!equipmentItem.Owner.TryGetComponent(out ServerStorageComponent? storageComponent))
!IoCManager.Resolve<IEntityManager>().TryGetComponent(equipmentItem.Owner.Uid, out ServerStorageComponent? storageComponent))
{
plyEnt.PopupMessage(Loc.GetString("hands-system-missing-equipment-slot", ("slotName", SlotNames[equipmentSlot].ToLower())));
return;