Skip to content
Open
Changes from 10 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
59 changes: 59 additions & 0 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,49 @@
/// <returns>dropped <see cref="Pickup"/>.</returns>
public Pickup DropItem(Item item) => item is not null ? Pickup.Get(Inventory.ServerDropItem(item.Serial)) : null;

/// <summary>
/// Drops an <see cref="Item"/> from the player's inventory by its <see cref="ItemType"/>.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be dropped.</param>
/// <param name="isThrown">Whether the item should be thrown.</param>
/// <param name="amount">The number of matching items to remove.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was dropped.</returns>
public bool DropItem(ItemType item, bool isThrown = false, int amount = 1)
{
if (amount <= 0)
return false;

List<Item> itemsToDrop = Items.Where(i => i?.Type == item).Take(amount).ToList();

if (itemsToDrop.Count == 0)
return false;

foreach (Item i in itemsToDrop)
DropItem(i, isThrown);

return itemsToDrop.Count > 0;
}

/// <summary>
/// Drops an item from the player's inventory.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be dropped.</param>
/// <param name="amount">The number of matching items to remove.</param>
/// <returns>A list of dropped <see cref="Pickup"/>s.</returns>
public List<Pickup> DropItem(ItemType item, int amount = 1)
{
List<Pickup> pickups = new();

if (amount <= 0)
return pickups;

List<Item> itemsToDrop = Items.Where(i => i?.Type == item).Take(amount).ToList();
Comment thread
Someone-193 marked this conversation as resolved.

Comment thread
Mr-Baguetter marked this conversation as resolved.
foreach (Item i in itemsToDrop)
pickups.Add(DropItem(i));

return pickups;
}
/// <summary>
/// Drops the held item. Will not do anything if the player is not holding an item.
/// </summary>
Expand Down Expand Up @@ -2112,8 +2155,8 @@
ItemCategory.Ammo => Inventory.UserInventory.ReserveAmmo.Count(ammo => ammo.Value > 0),
_ => Inventory.UserInventory.Items.Count(tempItem => tempItem.Value.Category == category),
};

Check failure on line 2158 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 2158 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 2158 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 2158 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 2158 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

/// <summary>

Check failure on line 2159 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)

Check failure on line 2159 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)

Check failure on line 2159 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)

Check failure on line 2159 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)

Check failure on line 2159 in EXILED/Exiled.API/Features/Player.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)
/// Removes an <see cref="Item"/> from the player's inventory.
/// </summary>
/// <param name="item">The <see cref="Item"/> to remove.</param>
Expand Down Expand Up @@ -2155,6 +2198,22 @@
return true;
}

/// <summary>
/// Removes an <see cref="Item"/> from the player's inventory by its <see cref="ItemType"/>.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be removed.</param>
/// <param name="destroy">Whether to destroy the item.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was removed.</returns>
public bool RemoveItem(ItemType item, bool destroy = true)
{
Item itemtoremove = Items.FirstOrDefault(tempItem => tempItem.Type == item);
if (itemtoremove == null)
return false;

RemoveItem(itemtoremove, destroy);
return true;
}

Comment on lines +2273 to +2288

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <summary>
/// Removes an <see cref="Item"/> from the player's inventory by its <see cref="ItemType"/>.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be removed.</param>
/// <param name="destroy">Whether to destroy the item.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was removed.</returns>
public bool RemoveItem(ItemType item, bool destroy = true)
{
Item itemtoremove = Items.FirstOrDefault(tempItem => tempItem.Type == item);
if (itemtoremove == null)
return false;
RemoveItem(itemtoremove, destroy);
return true;
}
/// <summary>
/// Removes an <see cref="Item"/> from the player's inventory by its <see cref="ItemType"/>.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be removed.</param>
/// <param name="destroy">Whether to destroy the item.</param>
/// <param name="amount">The number of matching items to remove.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was removed.</returns>
public bool RemoveItem(ItemType item, bool destroy = true, int amount = 1)
{
if (amount <= 0)
return false;
List<Item> itemsToRemove = Items.Where(i => i?.Type == item).Take(amount).ToList();
if (itemsToRemove.Count == 0)
return false;
foreach (Item i in itemsToRemove)
RemoveItem(i, destroy);
return true;
}

/// <summary>
/// Removes an <see cref="Item"/> from the player's inventory.
/// </summary>
Expand Down
Loading