Skip to content

Commit

Permalink
Fix ClearInventory (#2140)
Browse files Browse the repository at this point in the history
* Fix ClearInventory

* Update Exiled.API/Features/Player.cs

Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Thunder <thundermaker300@gmail.com>

---------

Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com>
Co-authored-by: Thunder <thundermaker300@gmail.com>
Co-authored-by: Nao <60253860+NaoUnderscore@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 24, 2023
1 parent 42e3092 commit 3c3a9fa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2587,11 +2587,36 @@ public void ResetInventory(IEnumerable<Item> newItems)
/// <seealso cref="ResetInventory(IEnumerable{ItemType})"/>
/// <seealso cref="DropItems()"/>
public void ClearInventory(bool destroy = true)
{
ClearItems(destroy);
ClearAmmo();
}

/// <summary>
/// Clears the player's items.
/// </summary>
/// <param name="destroy">Whether or not to fully destroy the old items.</param>
/// <seealso cref="ResetInventory(IEnumerable{Item})"/>
/// <seealso cref="ResetInventory(IEnumerable{ItemType})"/>
/// <seealso cref="DropItems()"/>
public void ClearItems(bool destroy = true)
{
while (Items.Count > 0)
RemoveItem(Items.ElementAt(0), destroy);
}

/// <summary>
/// Clears all ammo in the inventory.
/// </summary>
/// <seealso cref="ResetInventory(IEnumerable{Item})"/>
/// <seealso cref="SetAmmo(AmmoType, ushort)"/>
/// <seealso cref="DropItems()"/>
public void ClearAmmo()
{
ReferenceHub.inventory.UserInventory.ReserveAmmo.Clear();
ReferenceHub.inventory.SendAmmoNextFrame = true;
}

/// <summary>
/// Drops all items in the player's inventory, including all ammo and items.
/// </summary>
Expand Down

0 comments on commit 3c3a9fa

Please sign in to comment.