Repository navigation
feat(Player): Player::RemoveItem(ItemType, bool) method - #801
Conversation
louis1706
left a comment
There was a problem hiding this comment.
can you also add a method for DropItem(ItemType
Player::RemoveItem(ItemType, bool) method
Ive added these |
|
@louis1706 is it stupid but or adding something like "allInstances/allOccurrences" is good? Like I can see myself needing that, just so I don't need to type a for loop |
Someone-193
left a comment
There was a problem hiding this comment.
Maybe some of the docs could be improved, but it looks fine
|
@Mr-Baguetter, talked with yamato and it should be ok abt adding the allOccurrences, just made this one fast if you want change it /// <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">Is the item Thrown?.</param>
/// <param name="allOccurrences">If it should drop all matching occurrences.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was dropped.</returns>
public bool DropItem(ItemType item, bool isThrown = false, bool allOccurrences = false)
{
List<Item> itemsToDrop = Items.Where(i => i?.Type == item).ToList();
if (itemsToDrop.Count == 0)
return false;
if (!allOccurrences)
{
DropItem(itemsToDrop[0], isThrown);
return true;
}
foreach (Item i in itemsToDrop)
DropItem(i, isThrown);
return true;
}
/// <summary>
/// Drops an item from the player's inventory.
/// </summary>
/// <param name="item">The specified <see cref="ItemType"/> to be dropped.</param>
/// <param name="allOccurrences">If it should drop all matching occurrences.</param>
/// <returns>A list of dropped <see cref="Pickup"/>.</returns>
public List<Pickup> DropItem(ItemType item, bool allOccurrences = false)
{
List<Item> itemsToDrop = Items.Where(i => i?.Type == item).ToList();
List<Pickup> pickups = new();
if (itemsToDrop.Count == 0)
return pickups;
if (!allOccurrences)
{
pickups.Add(DropItem(itemsToDrop[0]));
return pickups;
}
foreach (Item i in itemsToDrop)
pickups.Add(DropItem(i));
return pickups;
} /// <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="allOccurrences">If it should drop all matching occurrences.</param>
/// <returns>A value indicating whether the <see cref="Item"/> was removed.</returns>
public bool RemoveItem(ItemType item, bool destroy = true, bool allOccurrences = false)
{
List<Item> itemsToRemove = Items.Where(i => i?.Type == item).ToList();
if (itemsToRemove.Count == 0)
return false;
if (!allOccurrences)
{
RemoveItem(itemsToRemove[0], destroy);
return true;
}
foreach (Item i in itemsToRemove)
RemoveItem(i, destroy);
return true;
} |
|
Nvm, I'll wait for y'all to do something |
|
Following @louis1706's suggestion in my dms of using /// <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">Is the item Thrown?.</param>
/// <param name="amount">The amount of matching occurrences that will be removed.</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).ToList();
if (itemsToDrop.Count == 0)
return false;
foreach (Item i in itemsToDrop)
DropItem(i, isThrown);
return true;
}
/// <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 amount of matching occurrences that will be removed.</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();
if (itemsToDrop.Count == 0)
return pickups;
foreach (Item i in itemsToDrop)
pickups.Add(DropItem(i));
return pickups;
} /// <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 amount of matching occurrences that will be removed.</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;
} |
Player::RemoveItem(ItemType, bool) methodPlayer::RemoveItem(ItemType, bool) method
Co-authored-by: Unbistrackted <jvg0dtv@gmail.com>
Co-authored-by: Unbistrackted <jvg0dtv@gmail.com>
The base branch was changed.
* Add: Player::RemoveItem method that uses ItemType instead of a item instance * Updated parameter name * Updated parameter name * Revert param change * Added Player::DropItem(ItemType) methods * Update EXILED/Exiled.API/Features/Player.cs Co-authored-by: Unbistrackted <jvg0dtv@gmail.com> * fix: error * apply change Co-authored-by: Unbistrackted <jvg0dtv@gmail.com> --------- Co-Authored-By: Yamato <66829532+louis1706@users.noreply.github.com> Co-Authored-By: Unbistrackted <jvg0dtv@gmail.com> Co-Authored-By: @Someone <45270312+Someone-193@users.noreply.github.com>
|
goated |
…nstance
Description
Added a new Player::RemoveItem method that uses ItemType instead of a item instance
Types of changes
Submission checklist