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

@@ -3,6 +3,8 @@ using Content.Server.AI.WorldState.States.Clothing;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.Clothing.Components;
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Clothing
{
@@ -23,7 +25,7 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (!entity.TryGetComponent(out ClothingComponent? clothingComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ClothingComponent? clothingComponent))
{
continue;
}

View File

@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.Weapon.Melee.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Combat.Melee
{
@@ -10,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
{
var target = context.GetState<WeaponEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MeleeWeaponComponent? meleeWeaponComponent))
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out MeleeWeaponComponent? meleeWeaponComponent))
{
return 0.0f;
}

View File

@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Combat;
using Content.Server.Weapon.Melee.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Combat.Melee
{
@@ -10,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat.Melee
{
var target = context.GetState<WeaponEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MeleeWeaponComponent? meleeWeaponComponent))
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out MeleeWeaponComponent? meleeWeaponComponent))
{
return 0.0f;
}

View File

@@ -12,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid) || !target.TryGetComponent(out DamageableComponent? damageableComponent))
if (target == null || !IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid) || !IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out DamageableComponent? damageableComponent))
{
return 0.0f;
}

View File

@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Shared.MobState.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Combat
{
@@ -10,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MobStateComponent? mobState))
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out MobStateComponent? mobState))
{
return 0.0f;
}

View File

@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Shared.MobState.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Combat
{
@@ -10,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Combat
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !target.TryGetComponent(out MobStateComponent? mobState))
if (target == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(target.Uid, out MobStateComponent? mobState))
{
return 0.0f;
}

View File

@@ -5,6 +5,7 @@ using Content.Server.Storage.Components;
using Content.Shared.Interaction;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Containers
{
@@ -24,7 +25,7 @@ namespace Content.Server.AI.Utility.Considerations.Containers
if (target.TryGetContainer(out var container))
{
if (container.Owner.TryGetComponent(out EntityStorageComponent? storageComponent))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(container.Owner.Uid, out EntityStorageComponent? storageComponent))
{
if (storageComponent.IsWeldedShut && !storageComponent.Open)
{

View File

@@ -1,6 +1,8 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.Hands.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Hands
{
@@ -10,7 +12,7 @@ namespace Content.Server.AI.Utility.Considerations.Hands
{
var owner = context.GetState<SelfState>().GetValue();
if (owner == null || !owner.TryGetComponent(out HandsComponent? handsComponent))
if (owner == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out HandsComponent? handsComponent))
{
return 0.0f;
}

View File

@@ -2,6 +2,8 @@ using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.Nutrition.Components;
using Content.Shared.Nutrition.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
{
@@ -11,7 +13,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
{
var owner = context.GetState<SelfState>().GetValue();
if (owner == null || !owner.TryGetComponent(out ThirstComponent? thirst))
if (owner == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out ThirstComponent? thirst))
{
return 0.0f;
}

View File

@@ -14,7 +14,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !IoCManager.Resolve<IEntityManager>().EntityExists(target.Uid)
|| !target.TryGetComponent<FoodComponent>(out var foodComp)
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent<FoodComponent?>(target.Uid, out var foodComp)
|| !EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(target.Uid, foodComp.SolutionName, out var food))
{
return 0.0f;

View File

@@ -2,6 +2,8 @@ using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.Nutrition.Components;
using Content.Shared.Nutrition.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
{
@@ -12,7 +14,7 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food
{
var owner = context.GetState<SelfState>().GetValue();
if (owner == null || !owner.TryGetComponent(out HungerComponent? hunger))
if (owner == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner.Uid, out HungerComponent? hunger))
{
return 0.0f;
}