Skip to content

feat(Player):Player::RemoveItem(ItemType, bool) method#801

Open
Mr-Baguetter wants to merge 8 commits intoExMod-Team:devfrom
Mr-Baguetter:master
Open

feat(Player):Player::RemoveItem(ItemType, bool) method#801
Mr-Baguetter wants to merge 8 commits intoExMod-Team:devfrom
Mr-Baguetter:master

Conversation

@Mr-Baguetter
Copy link
Copy Markdown

…nstance

Description

Added a new Player::RemoveItem method that uses ItemType instead of a item instance


Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • [x ] I have checked the project can be compiled
  • [ x] I have tested my changes and it worked as expected

@github-actions github-actions bot added the API label Apr 3, 2026
@louis1706 louis1706 changed the title New Player::RemoveItem method feay:New Player::RemoveItem method Apr 3, 2026
Copy link
Copy Markdown

@louis1706 louis1706 left a comment

Choose a reason for hiding this comment

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

can you also add a method for DropItem(ItemType

@louis1706 louis1706 changed the title feay:New Player::RemoveItem method feat(Player):Player::RemoveItem(ItemType, bool) method Apr 4, 2026
@Mr-Baguetter
Copy link
Copy Markdown
Author

can you also add a method for DropItem(ItemType

Ive added these

@Unbistrackted
Copy link
Copy Markdown

Unbistrackted commented Apr 7, 2026

@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

Copy link
Copy Markdown

@Someone-193 Someone-193 left a comment

Choose a reason for hiding this comment

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

Maybe some of the docs could be improved, but it looks fine

@Unbistrackted
Copy link
Copy Markdown

Unbistrackted commented Apr 11, 2026

@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;
        }

Copy link
Copy Markdown

@VALERA771 VALERA771 left a comment

Choose a reason for hiding this comment

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

Lgtm

@VALERA771
Copy link
Copy Markdown

Nvm, I'll wait for y'all to do something

@Unbistrackted
Copy link
Copy Markdown

Unbistrackted commented Apr 11, 2026

Following @louis1706's suggestion in my dms of using amount instead of allOccurrences
idk how to do reviews so that's why I'm sending the code here lul

        /// <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;
        }

Comment on lines +2034 to +2063
/// <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));
}

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>
/// 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;
}

Comment on lines +2171 to +2186
/// <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;
}

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants