Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions EXILED/Exiled.CustomItems/API/Features/CustomGoggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override ItemType Type
/// <inheritdoc/>
protected override void SubscribeEvents()
{
InventorySystem.InventoryExtensions.OnInventoryDropped += RemoveSafely;
Exiled.Events.Handlers.Player.UsingItem += OnInternalUsingItem;
Exiled.Events.Handlers.Player.ItemRemoved += OnInternalItemRemoved;
Exiled.Events.Handlers.Scp1344.Deactivating += OnInternalDeactivating;
Expand All @@ -67,6 +68,7 @@ protected override void SubscribeEvents()
/// <inheritdoc/>
protected override void UnsubscribeEvents()
{
InventorySystem.InventoryExtensions.OnInventoryDropped -= RemoveSafely;
Exiled.Events.Handlers.Player.UsingItem -= OnInternalUsingItem;
Exiled.Events.Handlers.Player.ItemRemoved -= OnInternalItemRemoved;
Exiled.Events.Handlers.Scp1344.Deactivating -= OnInternalDeactivating;
Expand Down Expand Up @@ -175,11 +177,11 @@ private void InternalEquip(Player player, Scp1344 goggles)

private void InternalRemove(Player player, Scp1344 goggles)
{
if (!Remove1344Effect)
player.DisableEffect(EffectType.Scp1344);

if (CanBeRemoveSafely)
{
if (!Remove1344Effect)
player.DisableEffect(EffectType.Scp1344);

player.DisableEffect(EffectType.Blindness);
player.ReferenceHub?.DisableWearables(WearableElements.Scp1344Goggles);
}
Expand Down Expand Up @@ -211,5 +213,29 @@ private void OnInternalChangingStatus(ChangingStatusEventArgs ev)

InternalRemove(ev.Player, ev.Scp1344);
}

private void RemoveSafely(ReferenceHub hub)
{
if (!Player.TryGet(hub, out Player owner))
return;

foreach (Item item in owner.Items)
{
if (item.Type != ItemType.SCP1344)
continue;

if (item is not Scp1344 { IsWorn: true } scp1344)
continue;

if (!Check(item))
continue;

if (!CanBeRemoveSafely)
continue;

scp1344.Status = Scp1344Status.Idle;
InternalRemove(owner, scp1344);
}
}
}
}
Loading