Clothing/item ECS & cleanup (#9706)

This commit is contained in:
Kara
2022-07-27 03:53:47 -07:00
committed by GitHub
parent 0f0420eca9
commit 258ec0cac1
164 changed files with 938 additions and 918 deletions

View File

@@ -38,7 +38,7 @@ public abstract partial class InventorySystem
SubscribeAllEvent<UseSlotNetworkMessage>(OnUseSlot);
}
protected void QuickEquip(EntityUid uid, SharedItemComponent component, UseInHandEvent args)
protected void QuickEquip(EntityUid uid, SharedClothingComponent component, UseInHandEvent args)
{
if (!TryComp(args.User, out InventoryComponent? inv)
|| !TryComp(args.User, out SharedHandsComponent? hands)
@@ -53,7 +53,7 @@ public abstract partial class InventorySystem
if (TryGetSlotEntity(args.User, slotDef.Name, out var slotEntity, inv))
{
// Item in slot has to be quick equipable as well
if (TryComp(slotEntity, out SharedItemComponent? item) && !item.QuickEquip)
if (TryComp(slotEntity, out SharedClothingComponent? item) && !item.QuickEquip)
continue;
if (!TryUnequip(args.User, slotDef.Name, true, inventory: inv))
@@ -157,19 +157,23 @@ public abstract partial class InventorySystem
}
public bool TryEquip(EntityUid uid, EntityUid itemUid, string slot, bool silent = false, bool force = false, bool predicted = false,
InventoryComponent? inventory = null, SharedItemComponent? item = null) =>
TryEquip(uid, uid, itemUid, slot, silent, force, predicted, inventory, item);
InventoryComponent? inventory = null, SharedClothingComponent? clothing = null) =>
TryEquip(uid, uid, itemUid, slot, silent, force, predicted, inventory, clothing);
public bool TryEquip(EntityUid actor, EntityUid target, EntityUid itemUid, string slot, bool silent = false, bool force = false, bool predicted = false,
InventoryComponent? inventory = null, SharedItemComponent? item = null)
InventoryComponent? inventory = null, SharedClothingComponent? clothing = null)
{
if (!Resolve(target, ref inventory, false) || !Resolve(itemUid, ref item, false))
if (!Resolve(target, ref inventory, false))
{
if(!silent && _gameTiming.IsFirstTimePredicted)
_popup.PopupCursor(Loc.GetString("inventory-component-can-equip-cannot"), Filter.Local());
return false;
}
// Not required to have, since pockets can take any item.
// CanEquip will still check, so we don't have to worry about it.
Resolve(itemUid, ref clothing, false);
if (!TryGetSlotContainer(target, slot, out var slotContainer, out var slotDefinition, inventory))
{
if(!silent && _gameTiming.IsFirstTimePredicted)
@@ -177,7 +181,7 @@ public abstract partial class InventorySystem
return false;
}
if (!force && !CanEquip(actor, target, itemUid, slot, out var reason, slotDefinition, inventory, item))
if (!force && !CanEquip(actor, target, itemUid, slot, out var reason, slotDefinition, inventory, clothing))
{
if(!silent && _gameTiming.IsFirstTimePredicted)
_popup.PopupCursor(Loc.GetString(reason), Filter.Local());
@@ -191,7 +195,7 @@ public abstract partial class InventorySystem
return false;
}
if(!silent && item.EquipSound != null && _gameTiming.IsFirstTimePredicted)
if(!silent && clothing != null && clothing.EquipSound != null && _gameTiming.IsFirstTimePredicted)
{
Filter filter;
@@ -206,7 +210,7 @@ public abstract partial class InventorySystem
filter.RemoveWhereAttachedEntity(entity => entity == actor);
}
SoundSystem.Play(item.EquipSound.GetSound(), filter, target, item.EquipSound.Params.WithVolume(-2f));
SoundSystem.Play(clothing.EquipSound.GetSound(), filter, target, clothing.EquipSound.Params.WithVolume(-2f));
}
inventory.Dirty();
@@ -245,22 +249,27 @@ public abstract partial class InventorySystem
public bool CanEquip(EntityUid uid, EntityUid itemUid, string slot, [NotNullWhen(false)] out string? reason,
SlotDefinition? slotDefinition = null, InventoryComponent? inventory = null,
SharedItemComponent? item = null) =>
CanEquip(uid, uid, itemUid, slot, out reason, slotDefinition, inventory, item);
SharedClothingComponent? clothing = null, ItemComponent? item = null) =>
CanEquip(uid, uid, itemUid, slot, out reason, slotDefinition, inventory, clothing, item);
public bool CanEquip(EntityUid actor, EntityUid target, EntityUid itemUid, string slot, [NotNullWhen(false)] out string? reason, SlotDefinition? slotDefinition = null, InventoryComponent? inventory = null, SharedItemComponent? item = null)
public bool CanEquip(EntityUid actor, EntityUid target, EntityUid itemUid, string slot, [NotNullWhen(false)] out string? reason, SlotDefinition? slotDefinition = null,
InventoryComponent? inventory = null, SharedClothingComponent? clothing = null, ItemComponent? item = null)
{
reason = "inventory-component-can-equip-cannot";
if (!Resolve(target, ref inventory, false) || !Resolve(itemUid, ref item, false))
if (!Resolve(target, ref inventory, false))
return false;
Resolve(itemUid, ref clothing, ref item, false);
if (slotDefinition == null && !TryGetSlot(target, slot, out slotDefinition, inventory: inventory))
return false;
if (slotDefinition.DependsOn != null && !TryGetSlotEntity(target, slotDefinition.DependsOn, out _, inventory))
return false;
if(!item.SlotFlags.HasFlag(slotDefinition.SlotFlags) && (!slotDefinition.SlotFlags.HasFlag(SlotFlags.POCKET) || item.Size > (int) ReferenceSizes.Pocket))
var fittingInPocket = slotDefinition.SlotFlags.HasFlag(SlotFlags.POCKET) && item is { Size: <= (int) ReferenceSizes.Pocket };
if (clothing == null && !fittingInPocket
|| clothing != null && !clothing.Slots.HasFlag(slotDefinition.SlotFlags) && !fittingInPocket)
{
reason = "inventory-component-can-equip-does-not-fit";
return false;
@@ -304,17 +313,17 @@ public abstract partial class InventorySystem
}
public bool TryUnequip(EntityUid uid, string slot, bool silent = false, bool force = false, bool predicted = false,
InventoryComponent? inventory = null, SharedItemComponent? item = null) => TryUnequip(uid, uid, slot, silent, force, predicted, inventory, item);
InventoryComponent? inventory = null, SharedClothingComponent? clothing = null) => TryUnequip(uid, uid, slot, silent, force, predicted, inventory, clothing);
public bool TryUnequip(EntityUid actor, EntityUid target, string slot, bool silent = false,
bool force = false, bool predicted = false, InventoryComponent? inventory = null, SharedItemComponent? item = null) =>
TryUnequip(actor, target, slot, out _, silent, force, predicted, inventory, item);
bool force = false, bool predicted = false, InventoryComponent? inventory = null, SharedClothingComponent? clothing = null) =>
TryUnequip(actor, target, slot, out _, silent, force, predicted, inventory, clothing);
public bool TryUnequip(EntityUid uid, string slot, [NotNullWhen(true)] out EntityUid? removedItem, bool silent = false, bool force = false, bool predicted = false,
InventoryComponent? inventory = null, SharedItemComponent? item = null) => TryUnequip(uid, uid, slot, out removedItem, silent, force, predicted, inventory, item);
InventoryComponent? inventory = null, SharedClothingComponent? clothing = null) => TryUnequip(uid, uid, slot, out removedItem, silent, force, predicted, inventory, clothing);
public bool TryUnequip(EntityUid actor, EntityUid target, string slot, [NotNullWhen(true)] out EntityUid? removedItem, bool silent = false,
bool force = false, bool predicted = false, InventoryComponent? inventory = null, SharedItemComponent? item = null)
bool force = false, bool predicted = false, InventoryComponent? inventory = null, SharedClothingComponent? clothing = null)
{
removedItem = null;
if (!Resolve(target, ref inventory, false))
@@ -370,7 +379,7 @@ public abstract partial class InventorySystem
Transform(removedItem.Value).Coordinates = Transform(target).Coordinates;
if (!silent && Resolve(removedItem.Value, ref item) && item.UnequipSound != null && _gameTiming.IsFirstTimePredicted)
if (!silent && Resolve(removedItem.Value, ref clothing, false) && clothing.UnequipSound != null && _gameTiming.IsFirstTimePredicted)
{
Filter filter;
@@ -385,7 +394,7 @@ public abstract partial class InventorySystem
filter.RemoveWhereAttachedEntity(entity => entity == actor);
}
SoundSystem.Play(item.UnequipSound.GetSound(), filter, target, item.UnequipSound.Params.WithVolume(-2f));
SoundSystem.Play(clothing.UnequipSound.GetSound(), filter, target, clothing.UnequipSound.Params.WithVolume(-2f));
}
inventory.Dirty();