get that crap outta here (completely rewrites inventorysystem) (#5807)

* some work

* equip: done
unequip: todo

* unequipping done & refactored events

* workin

* movin

* reee namespaces

* stun

* mobstate

* fixes

* some work on events

* removes serverside itemcomp & misc fixes

* work

* smol merge fix

* ports template to prototype & finishes ui

* moves relay & adds containerenumerator

* actions & cuffs

* my god what is actioncode

* more fixes

* im loosing my grasp on reality

* more fixes

* more work

* explosions

* yes

* more work

* more fixes

* merge master & misc fixed because i forgot to commit before merging master

* more fixes

* fixes

* moar

* more work

* moar fixes

* suffixmap

* more work on client

* motivation low

* no. no containers

* mirroring client to server

* fixes

* move serverinvcomp

* serverinventorycomponent is dead

* gaming

* only strippable & ai left...

* only ai and richtext left

* fixes ai

* fixes

* fixes sprite layers

* more fixes

* resolves optional

* yes

* stable™️

* fixes

* moar fixes

* moar

* fix some tests

* lmao

* no comment

* good to merge™️

* fixes build but for real

* adresses some reviews

* adresses some more reviews

* nullables, yo

* fixes lobbyscreen

* timid refactor to differentiate actor & target

* adresses more reviews

* more

* my god what a mess

* removed the rest of duplicates

* removed duplicate slotflags and renamed shoes to feet

* removes another unused one

* yes

* fixes lobby & makes tryunequip return unequipped item

* fixes

* some funny renames

* fixes

* misc improvements to attemptevents

* fixes

* merge fixes

Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
This commit is contained in:
Paul Ritter
2021-12-30 22:56:10 +01:00
committed by GitHub
parent 7a5adb47a1
commit 512d6a38c3
199 changed files with 2493 additions and 3300 deletions

View File

@@ -1,7 +1,7 @@
using Content.Server.Hands.Components;
using Content.Server.Interaction;
using Content.Server.Items;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -25,7 +25,7 @@ namespace Content.Server.AI.Operators.Inventory
var entMan = IoCManager.Resolve<IEntityManager>();
if (entMan.Deleted(_target)
|| !entMan.HasComponent<ItemComponent>(_target)
|| !entMan.HasComponent<SharedItemComponent>(_target)
|| _target.IsInContainer()
|| !_owner.InRangeUnobstructed(_target, popup: true))
{

View File

@@ -1,5 +1,5 @@
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Shared.Item;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -29,7 +29,7 @@ namespace Content.Server.AI.Operators.Inventory
return Outcome.Failed;
}
if (!entMan.TryGetComponent(_target, out ItemComponent? itemComponent))
if (!entMan.TryGetComponent(_target, out SharedItemComponent? itemComponent))
{
return Outcome.Failed;
}

View File

@@ -1,7 +1,7 @@
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Nutrition.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -34,7 +34,7 @@ namespace Content.Server.AI.Operators.Nutrition
// TODO: Also have this check storage a la backpack etc.
if (entities.Deleted(_target) ||
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent) ||
!entities.TryGetComponent(_target, out ItemComponent? itemComponent))
!entities.TryGetComponent(_target, out SharedItemComponent? itemComponent))
{
return Outcome.Failed;
}

View File

@@ -1,6 +1,6 @@
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Nutrition.Components;
using Content.Shared.Item;
using Content.Shared.Nutrition.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -33,7 +33,7 @@ namespace Content.Server.AI.Operators.Nutrition
// TODO: Also have this check storage a la backpack etc.
if (entities.Deleted(_target) ||
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent) ||
!entities.TryGetComponent(_target, out ItemComponent? itemComponent))
!entities.TryGetComponent(_target, out SharedItemComponent? itemComponent))
{
return Outcome.Failed;
}

View File

@@ -10,7 +10,7 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
{
public sealed class ClothingInInventoryCon : Consideration
{
public ClothingInInventoryCon Slot(EquipmentSlotDefines.SlotFlags slotFlags, Blackboard context)
public ClothingInInventoryCon Slot(SlotFlags slotFlags, Blackboard context)
{
// Ideally we'd just use a variable but then if we were iterating through multiple AI at once it'd be
// Stuffed so we need to store it on the AI's context.
@@ -21,16 +21,17 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
protected override float GetScore(Blackboard context)
{
var slots = context.GetState<ClothingSlotConState>().GetValue();
var slotFlags = EquipmentSlotDefines.SlotMasks[slots];
if (slots == null) return 0.0f;
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothingComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothingComponent) ||
!EntitySystem.Get<InventorySystem>().TryGetSlot(entity, slots, out var slotDef))
{
continue;
}
if ((clothingComponent.SlotFlags & slotFlags) != 0)
if ((clothingComponent.SlotFlags & slotDef.SlotFlags) != 0)
{
return 1.0f;
}

View File

@@ -7,7 +7,7 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
public class ClothingInSlotCon : Consideration
{
public ClothingInSlotCon Slot(EquipmentSlotDefines.Slots slot, Blackboard context)
public ClothingInSlotCon Slot(string slot, Blackboard context)
{
context.GetState<ClothingSlotConState>().SetValue(slot);
return this;
@@ -17,7 +17,7 @@ namespace Content.Server.AI.Utility.Considerations.Clothing
{
var slot = context.GetState<ClothingSlotConState>().GetValue();
var inventory = context.GetState<EquippedClothingState>().GetValue();
return inventory.ContainsKey(slot) ? 1.0f : 0.0f;
return slot != null && inventory.ContainsKey(slot) ? 1.0f : 0.0f;
}
}
}

View File

@@ -2,7 +2,7 @@ using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.WorldState.States.Hands;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.Items;
using Content.Shared.Item;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -16,7 +16,7 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
// If not then check if we have a free hand
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !IoCManager.Resolve<IEntityManager>().HasComponent<ItemComponent>(target))
if (target == null || !IoCManager.Resolve<IEntityManager>().HasComponent<SharedItemComponent>(target))
{
return 0.0f;
}

View File

@@ -1,7 +1,7 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.Items;
using Content.Shared.Item;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -13,7 +13,7 @@ namespace Content.Server.AI.Utility.Considerations.Inventory
{
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !IoCManager.Resolve<IEntityManager>().HasComponent<ItemComponent>(target))
if (target == null || !IoCManager.Resolve<IEntityManager>().HasComponent<SharedItemComponent>(target))
{
return 0.0f;
}

View File

@@ -27,7 +27,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
return new []
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("gloves", context)
.InverseBoolCurve(context),
};
}
@@ -39,7 +39,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.GLOVES) != 0)
(clothing.SlotFlags & SlotFlags.GLOVES) != 0)
{
yield return new EquipGloves {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -23,9 +23,9 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("gloves", context)
.InverseBoolCurve(context),
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context)
considerationsManager.Get<ClothingInInventoryCon>().Slot(SlotFlags.GLOVES, context)
.InverseBoolCurve(context),
};
}
@@ -37,7 +37,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
foreach (var entity in context.GetState<NearbyClothingState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.GLOVES) != 0)
(clothing.SlotFlags & SlotFlags.GLOVES) != 0)
{
yield return new PickUpGloves {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -26,7 +26,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[] {
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("head", context)
.InverseBoolCurve(context),
};
}
@@ -38,7 +38,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.HEAD) != 0)
(clothing.SlotFlags & SlotFlags.HEAD) != 0)
{
yield return new EquipHead {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -23,9 +23,9 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("head", context)
.InverseBoolCurve(context),
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context)
considerationsManager.Get<ClothingInInventoryCon>().Slot(SlotFlags.HEAD, context)
.InverseBoolCurve(context)
};
}
@@ -37,7 +37,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
foreach (var entity in context.GetState<NearbyClothingState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.HEAD) != 0)
(clothing.SlotFlags & SlotFlags.HEAD) != 0)
{
yield return new PickUpHead {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -27,7 +27,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("outerClothing", context)
.InverseBoolCurve(context),
};
}
@@ -39,7 +39,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.OUTERCLOTHING) != 0)
(clothing.SlotFlags & SlotFlags.OUTERCLOTHING) != 0)
{
yield return new EquipOuterClothing {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -24,9 +24,9 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("outerClothing", context)
.InverseBoolCurve(context),
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context)
considerationsManager.Get<ClothingInInventoryCon>().Slot(SlotFlags.OUTERCLOTHING, context)
.InverseBoolCurve(context)
};
}
@@ -38,7 +38,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
foreach (var entity in context.GetState<NearbyClothingState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.OUTERCLOTHING) != 0)
(clothing.SlotFlags & SlotFlags.OUTERCLOTHING) != 0)
{
yield return new PickUpOuterClothing {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -27,7 +27,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("shoes", context)
.InverseBoolCurve(context),
};
}
@@ -39,7 +39,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
foreach (var entity in context.GetState<EnumerableInventoryState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.SHOES) != 0)
(clothing.SlotFlags & SlotFlags.FEET) != 0)
{
yield return new EquipShoes {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -24,9 +24,9 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
return new[]
{
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
considerationsManager.Get<ClothingInSlotCon>().Slot("shoes", context)
.InverseBoolCurve(context),
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context)
considerationsManager.Get<ClothingInInventoryCon>().Slot(SlotFlags.FEET, context)
.InverseBoolCurve(context)
};
}
@@ -38,7 +38,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
foreach (var entity in context.GetState<NearbyClothingState>().GetValue())
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClothingComponent? clothing) &&
(clothing.SlotFlags & EquipmentSlotDefines.SlotFlags.SHOES) != 0)
(clothing.SlotFlags & SlotFlags.FEET) != 0)
{
yield return new PickUpShoes {Owner = owner, Target = entity, Bonus = Bonus};
}

View File

@@ -1,13 +1,11 @@
using Content.Shared.Inventory;
namespace Content.Server.AI.WorldState.States.Clothing
{
public sealed class ClothingSlotConState : PlanningStateData<EquipmentSlotDefines.Slots>
public sealed class ClothingSlotConState : PlanningStateData<string>
{
public override string Name => "ClothingSlotCon";
public override void Reset()
{
Value = EquipmentSlotDefines.Slots.NONE;
Value = "";
}
}
}

View File

@@ -2,12 +2,12 @@ using Content.Shared.Inventory;
namespace Content.Server.AI.WorldState.States.Clothing
{
public sealed class ClothingSlotFlagConState : PlanningStateData<EquipmentSlotDefines.SlotFlags>
public sealed class ClothingSlotFlagConState : PlanningStateData<SlotFlags>
{
public override string Name => "ClothingSlotFlagCon";
public override void Reset()
{
Value = EquipmentSlotDefines.SlotFlags.NONE;
Value = SlotFlags.NONE;
}
}
}

View File

@@ -1,34 +1,35 @@
using System.Collections.Generic;
using Content.Server.Inventory.Components;
using Content.Shared.Inventory;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
namespace Content.Server.AI.WorldState.States.Clothing
{
[UsedImplicitly]
public sealed class EquippedClothingState : StateData<Dictionary<EquipmentSlotDefines.Slots, EntityUid>>
public sealed class EquippedClothingState : StateData<Dictionary<string, EntityUid>>
{
public override string Name => "EquippedClothing";
public override Dictionary<EquipmentSlotDefines.Slots, EntityUid> GetValue()
public override Dictionary<string, EntityUid> GetValue()
{
var result = new Dictionary<EquipmentSlotDefines.Slots, EntityUid>();
var result = new Dictionary<string, EntityUid>();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out InventoryComponent? inventoryComponent))
var invSystem = EntitySystem.Get<InventorySystem>();
if (!invSystem.TryGetSlots(Owner, out var slotDefinitions))
{
return result;
}
foreach (var slot in EquipmentSlotDefines.AllSlots)
foreach (var slot in slotDefinitions)
{
if (!inventoryComponent.HasSlot(slot)) continue;
var slotItem = inventoryComponent.GetSlotItem(slot);
if (!invSystem.HasSlot(Owner, slot.Name)) continue;
if (slotItem != null)
if (invSystem.TryGetSlotEntity(Owner, slot.Name, out var entityUid))
{
result.Add(slot, slotItem.Owner);
result.Add(slot.Name, entityUid.Value);
}
}