# Remove() Methods

{% hint style="info" %}
Example code here is from `GameStatList.cs`, though similar methods are on other list classes as well.

Methods for specific list types are below.
{% endhint %}

{% hint style="info" %}
The common methods can be found in `GameModuleListExtensions.cs`
{% endhint %}

## `Remove()`

There are many ways to remove an item from the list

{% hint style="warning" %}
`Remove(gameStat)` will remove the first item that has the `uid` of the `gameStat` provided. If you want to ensure you remove the specific `GameStat` object, use `RemoveExact(gameStat)` instead.
{% endhint %}

```csharp
// Remove by Stat, GameStat, or uid
gameStatList.Remove(stat);
gameStatList.Remove(gameStat);
gameStatList.Remove(uid);

// Remove all by Stat, GameStat, or uid
gameStatList.RemoveAll(stat);
gameStatList.RemoveAll(gameStat);
gameStatList.RemoveAll(uid);

// Remove by a gameId -- These do the same thing
gameStatList.RemoveGameId(gameId);
gameStatList.RemoveExact(gameId);

// Remove an exact Game Module Object
gameStatList.RemoveExact(gameStat); // pass in the gameStat we want to remove

// Clear the entire list
gameStatList.Clear();
```

## `GameConditionList`

#### Remove all from a specific `IHaveStats` source

<pre class="language-csharp"><code class="lang-csharp"><strong>// These will remove the conditions -- Expiration Conditions will not be added!
</strong><strong>public void RemoveAllFromSource(IHaveStats source, Condition condition)
</strong>public void RemoveAllFromSource(IHaveStats source, GameCondition gameCondition)
public void RemoveAllFromSource(IHaveStats source, string conditionUid = null)
</code></pre>

#### Expire all from a specific `IHaveStats` source

<pre class="language-csharp"><code class="lang-csharp"><strong>// ExpireNow() sets the expiration time to Now. They actually will expire
</strong><strong>// the next frame.
</strong>public void ExpireAllFromSource(IHaveStats source, Condition condition)
public void ExpireAllFromSource(IHaveStats source, GameCondition gameCondition)
public void ExpireAllFromSource(IHaveStats source, string conditionUid = null)

// Example -- Assumes "witch" is an Actor which implements IHaveStats
public void RemoveAllCursesFromWitch() => ExpireAllFromSource(witch);
</code></pre>

## `GameItemObjectList`

{% hint style="warning" %}
The `Remove()` methods below do not take into account "Equipment" -- that is, they do not update `Stats` when they are removed. If you plan on removing `ItemObjects` that are active in an "Equipment" list, you'll want to create your own remove methods to handle your inventory appropriately.
{% endhint %}

#### Remove all based on number of `ItemAttributes`

<pre class="language-csharp"><code class="lang-csharp">// If GameItemObject, ItemObject, or itemObjectUid is provided, only those of
// that ItemObject will be removed

// Remove all with exact number of attributes
<strong>public void RemoveAllWithExactlyXAttributes(int amount, ItemObject itemObject)
</strong>public void RemoveAllWithExactlyXAttributes(int amount, GameItemObject gameItemObject)
public void RemoveAllWithExactlyXAttributes(int amount, string itemObjectUid = null)

// Remove all with less than X attributes
public void RemoveAllWithLessThanXAttributes(int amount, ItemObject itemObject)
public void RemoveAllWithLessThanXAttributes(int amount, GameItemObject gameItemObject)
public void RemoveAllWithLessThanXAttributes(int amount, string itemObjectUid = null) 

// Remove all with more than X attributes
public void RemoveAllWithMoreThanXAttributes(int amount, ItemObject itemObject)
public void RemoveAllWithMoreThanXAttributes(int amount, GameItemObject gameItemObject)
public void RemoveAllWithMoreThanXAttributes(int amount, string itemObjectUid = null)

// Remove all with no attributes
public void RemoveAllWithNoAttributes(ItemObject itemObject)
public void RemoveAllWithNoAttributes(GameItemObject gameItemObject)
public void RemoveAllWithNoAttributes(string itemObjectUid = null)
</code></pre>

#### Remove all based on  specific `ItemAttributes`

```csharp
// If itemObjectUid is provided, only those of that ItemObject will be removed

// Remove all with specific ItemAttribute
public void RemoveAllWithAttribute(ItemAttribute attribute, string itemObjectUid = null)
public void RemoveAllWithAttribute(GameItemAttribute gameAttribute, string itemObjectUid = null)
public void RemoveAllWithAttribute(string attributeUid, string itemObjectUid = null)

// Remove all with ALL of the specified ItemAttributes
public void RemoveAllWithAllAttributes(IEnumerable<ItemAttribute> attributes, string itemObjectUid = null)
public void RemoveAllWithAllAttributes(IEnumerable<GameItemAttribute> gameAttributes, string itemObjectUid = null)
public void RemoveAllWithAllAttributes(IEnumerable<string> attributeUids, string itemObjectUid = null)

// Remove all with ANY of the specified ItemAttributes
public void RemoveAllWithAnyAttributes(IEnumerable<ItemAttribute> attributes, string itemObjectUid = null)
public void RemoveAllWithAnyAttributes(IEnumerable<GameItemAttribute> gameAttributes, string itemObjectUid = null)
public void RemoveAllWithAnyAttributes(IEnumerable<string> attributeUids, string itemObjectUid = null)

// Example
ItemAttribute[] itemAttributes = new[] { Rare, Epic, Legendary };
gameItemObjectList.RemoveAllWithAnyAttributes(itemAttributes);
Debug.Log("All your good loot has been removed!");
```

#### Remove duplicates

These methods will remove any duplicates. The single-object methods have an optional `itemObjectUid`, when `null`, will remove any duplicate in the entire list.

There is also an optional `bool` `includeItemAttributes`, which is `false` by default. When `true`, a `GameItemObject` must match both its `Uid()` and its list of `ItemAttributes` to qualify as a duplicate.

```csharp
public void RemoveDuplicates(ItemObject itemObject, bool includeItemAttributes = false)
public void RemoveDuplicates(GameItemObject gameItemObject, bool includeItemAttributes = false)
public void RemoveDuplicates(string itemObjectUid = null, bool includeItemAttributes = false)

// Only check a set of ItemObjects
public void RemoveDuplicates(IEnumerable<ItemObject> itemObjects, bool includeItemAttributes = false)
public void RemoveDuplicates(IEnumerable<GameItemObject> gameItemObjects, bool includeItemAttributes = false)
public void RemoveDuplicates(IEnumerable<string> itemObjectUids, bool includeItemAttributes = false)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/game-module-lists/remove-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
