Fix debug asserts when unequipping items (#38274)
This commit is contained in:
@@ -11,12 +11,11 @@ namespace Content.Shared.Clothing.Components;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handles entities which can be equipped.
|
/// This handles entities which can be equipped.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NetworkedComponent]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||||
[RegisterComponent]
|
|
||||||
[Access(typeof(ClothingSystem), typeof(InventorySystem))]
|
[Access(typeof(ClothingSystem), typeof(InventorySystem))]
|
||||||
public sealed partial class ClothingComponent : Component
|
public sealed partial class ClothingComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("clothingVisuals")]
|
[DataField]
|
||||||
public Dictionary<string, List<PrototypeLayerData>> ClothingVisuals = new();
|
public Dictionary<string, List<PrototypeLayerData>> ClothingVisuals = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -25,8 +24,7 @@ public sealed partial class ClothingComponent : Component
|
|||||||
[DataField]
|
[DataField]
|
||||||
public string? MappedLayer;
|
public string? MappedLayer;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
[DataField("quickEquip")]
|
|
||||||
public bool QuickEquip = true;
|
public bool QuickEquip = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -36,22 +34,18 @@ public sealed partial class ClothingComponent : Component
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Note that this may be a combination of different slot flags, not a singular bit.
|
/// Note that this may be a combination of different slot flags, not a singular bit.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField(required: true)]
|
[DataField(required: true)]
|
||||||
[Access(typeof(ClothingSystem), typeof(InventorySystem), Other = AccessPermissions.ReadExecute)]
|
[Access(typeof(ClothingSystem), typeof(InventorySystem), Other = AccessPermissions.ReadExecute)]
|
||||||
public SlotFlags Slots = SlotFlags.NONE;
|
public SlotFlags Slots = SlotFlags.NONE;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
[DataField("equipSound")]
|
|
||||||
public SoundSpecifier? EquipSound;
|
public SoundSpecifier? EquipSound;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
[DataField("unequipSound")]
|
|
||||||
public SoundSpecifier? UnequipSound;
|
public SoundSpecifier? UnequipSound;
|
||||||
|
|
||||||
[Access(typeof(ClothingSystem))]
|
[Access(typeof(ClothingSystem))]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField, AutoNetworkedField]
|
||||||
[DataField("equippedPrefix")]
|
|
||||||
public string? EquippedPrefix;
|
public string? EquippedPrefix;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,11 +53,9 @@ public sealed partial class ClothingComponent : Component
|
|||||||
/// useful when prototyping INNERCLOTHING items into OUTERCLOTHING items without duplicating/modifying RSIs etc.
|
/// useful when prototyping INNERCLOTHING items into OUTERCLOTHING items without duplicating/modifying RSIs etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Access(typeof(ClothingSystem))]
|
[Access(typeof(ClothingSystem))]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField, AutoNetworkedField]
|
||||||
[DataField("equippedState")]
|
|
||||||
public string? EquippedState;
|
public string? EquippedState;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("sprite")]
|
[DataField("sprite")]
|
||||||
public string? RsiPath;
|
public string? RsiPath;
|
||||||
|
|
||||||
@@ -72,7 +64,7 @@ public sealed partial class ClothingComponent : Component
|
|||||||
/// Note that this being non-null does not mean the clothing is considered "worn" or "equipped" unless the slot
|
/// Note that this being non-null does not mean the clothing is considered "worn" or "equipped" unless the slot
|
||||||
/// satisfies the <see cref="Slots"/> flags.
|
/// satisfies the <see cref="Slots"/> flags.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public string? InSlot;
|
public string? InSlot;
|
||||||
// TODO CLOTHING
|
// TODO CLOTHING
|
||||||
// Maybe keep this null unless its in a valid slot?
|
// Maybe keep this null unless its in a valid slot?
|
||||||
@@ -82,16 +74,16 @@ public sealed partial class ClothingComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Slot flags of the slot the clothing is currently in. See also <see cref="InSlot"/>.
|
/// Slot flags of the slot the clothing is currently in. See also <see cref="InSlot"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public SlotFlags? InSlotFlag;
|
public SlotFlags? InSlotFlag;
|
||||||
// TODO CLOTHING
|
// TODO CLOTHING
|
||||||
// Maybe keep this null unless its in a valid slot?
|
// Maybe keep this null unless its in a valid slot?
|
||||||
// And when doing this, combine InSlot and InSlotFlag, as it'd be a breaking change for downstreams anyway
|
// And when doing this, combine InSlot and InSlotFlag, as it'd be a breaking change for downstreams anyway
|
||||||
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
public TimeSpan EquipDelay = TimeSpan.Zero;
|
public TimeSpan EquipDelay = TimeSpan.Zero;
|
||||||
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField]
|
||||||
public TimeSpan UnequipDelay = TimeSpan.Zero;
|
public TimeSpan UnequipDelay = TimeSpan.Zero;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -102,17 +94,6 @@ public sealed partial class ClothingComponent : Component
|
|||||||
public TimeSpan StripDelay = TimeSpan.Zero;
|
public TimeSpan StripDelay = TimeSpan.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class ClothingComponentState : ComponentState
|
|
||||||
{
|
|
||||||
public string? EquippedPrefix;
|
|
||||||
|
|
||||||
public ClothingComponentState(string? equippedPrefix)
|
|
||||||
{
|
|
||||||
EquippedPrefix = equippedPrefix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ClothingMask : byte
|
public enum ClothingMask : byte
|
||||||
{
|
{
|
||||||
NoMask = 0,
|
NoMask = 0,
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ public abstract class ClothingSystem : EntitySystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<ClothingComponent, UseInHandEvent>(OnUseInHand);
|
SubscribeLocalEvent<ClothingComponent, UseInHandEvent>(OnUseInHand);
|
||||||
SubscribeLocalEvent<ClothingComponent, ComponentGetState>(OnGetState);
|
SubscribeLocalEvent<ClothingComponent, AfterAutoHandleStateEvent>(AfterAutoHandleState);
|
||||||
SubscribeLocalEvent<ClothingComponent, ComponentHandleState>(OnHandleState);
|
|
||||||
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
|
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
|
||||||
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
|
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
|
||||||
|
|
||||||
@@ -84,6 +83,7 @@ public abstract class ClothingSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
component.InSlot = args.Slot;
|
component.InSlot = args.Slot;
|
||||||
component.InSlotFlag = args.SlotFlags;
|
component.InSlotFlag = args.SlotFlags;
|
||||||
|
Dirty(uid, component);
|
||||||
|
|
||||||
if ((component.Slots & args.SlotFlags) == SlotFlags.NONE)
|
if ((component.Slots & args.SlotFlags) == SlotFlags.NONE)
|
||||||
return;
|
return;
|
||||||
@@ -108,19 +108,12 @@ public abstract class ClothingSystem : EntitySystem
|
|||||||
|
|
||||||
component.InSlot = null;
|
component.InSlot = null;
|
||||||
component.InSlotFlag = null;
|
component.InSlotFlag = null;
|
||||||
|
Dirty(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetState(EntityUid uid, ClothingComponent component, ref ComponentGetState args)
|
private void AfterAutoHandleState(Entity<ClothingComponent> ent, ref AfterAutoHandleStateEvent args)
|
||||||
{
|
{
|
||||||
args.State = new ClothingComponentState(component.EquippedPrefix);
|
_itemSys.VisualsChanged(ent.Owner);
|
||||||
}
|
|
||||||
|
|
||||||
private void OnHandleState(EntityUid uid, ClothingComponent component, ref ComponentHandleState args)
|
|
||||||
{
|
|
||||||
if (args.Current is not ClothingComponentState state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SetEquippedPrefix(uid, state.EquippedPrefix, component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEquipDoAfter(Entity<ClothingComponent> ent, ref ClothingEquipDoAfterEvent args)
|
private void OnEquipDoAfter(Entity<ClothingComponent> ent, ref ClothingEquipDoAfterEvent args)
|
||||||
|
|||||||
@@ -75,13 +75,13 @@ public sealed class MaskSystem : EntitySystem
|
|||||||
private void ToggleMaskComponents(EntityUid uid, MaskComponent mask, EntityUid wearer, string? equippedPrefix = null, bool isEquip = false)
|
private void ToggleMaskComponents(EntityUid uid, MaskComponent mask, EntityUid wearer, string? equippedPrefix = null, bool isEquip = false)
|
||||||
{
|
{
|
||||||
Dirty(uid, mask);
|
Dirty(uid, mask);
|
||||||
if (mask.ToggleActionEntity is {} action)
|
if (mask.ToggleActionEntity is { } action)
|
||||||
_actionSystem.SetToggled(action, mask.IsToggled);
|
_actionSystem.SetToggled(action, mask.IsToggled);
|
||||||
|
|
||||||
var maskEv = new ItemMaskToggledEvent((wearer, mask), wearer);
|
var maskEv = new ItemMaskToggledEvent((uid, mask), wearer);
|
||||||
RaiseLocalEvent(uid, ref maskEv);
|
RaiseLocalEvent(uid, ref maskEv);
|
||||||
|
|
||||||
var wearerEv = new WearerMaskToggledEvent((wearer, mask));
|
var wearerEv = new WearerMaskToggledEvent((uid, mask));
|
||||||
RaiseLocalEvent(wearer, ref wearerEv);
|
RaiseLocalEvent(wearer, ref wearerEv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user