feat(Player):Player::RemoveItem(ItemType, bool) method#801
feat(Player):Player::RemoveItem(ItemType, bool) method#801Mr-Baguetter wants to merge 8 commits intoExMod-Team:devfrom
Player::RemoveItem(ItemType, bool) method#801Conversation
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;
} |
| /// <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> | ||
| /// <returns>A value indicating whether the <see cref="Item"/> was dropped.</returns> | ||
| public bool DropItem(ItemType item, bool isThrown = false) | ||
| { | ||
| Item itemtodrop = Items.FirstOrDefault(tempItem => tempItem.Type == item); | ||
| if (itemtodrop == null) | ||
| return false; | ||
|
|
||
| DropItem(itemtodrop, 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> | ||
| /// <returns>dropped <see cref="Pickup"/>.</returns> | ||
| public Pickup DropItem(ItemType item) | ||
| { | ||
| Item itemtodrop = Items.FirstOrDefault(tempItem => tempItem.Type == item); | ||
| if (itemtodrop == null) | ||
| return null; | ||
|
|
||
| return Pickup.Get(Inventory.ServerDropItem(itemtodrop.Serial)); | ||
| } | ||
|
|
There was a problem hiding this comment.
| /// <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> | |
| /// <returns>A value indicating whether the <see cref="Item"/> was dropped.</returns> | |
| public bool DropItem(ItemType item, bool isThrown = false) | |
| { | |
| Item itemtodrop = Items.FirstOrDefault(tempItem => tempItem.Type == item); | |
| if (itemtodrop == null) | |
| return false; | |
| DropItem(itemtodrop, 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> | |
| /// <returns>dropped <see cref="Pickup"/>.</returns> | |
| public Pickup DropItem(ItemType item) | |
| { | |
| Item itemtodrop = Items.FirstOrDefault(tempItem => tempItem.Type == item); | |
| if (itemtodrop == null) | |
| return null; | |
| return Pickup.Get(Inventory.ServerDropItem(itemtodrop.Serial)); | |
| } | |
| /// <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(); | |
| 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> | ||
| /// <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; | ||
| } | ||
|
|
There was a problem hiding this comment.
| /// <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; | |
| } |
…nstance
Description
Added a new Player::RemoveItem method that uses ItemType instead of a item instance
Types of changes
Submission checklist