/// <summary>
/// Destroy the character item. Pre-Runtime character items can only be destroyed if forced.
/// </summary>
/// <param name="characterItem">The character item to destroy.</param>
/// <param name="forceDestroy">Force destroy even if the character item is a pre-runtime character item.</param>
/// <returns>Returns true if the character item was destroyed successfully.</returns>
public override bool DestroyCharacterItem(CharacterItem characterItem, bool forceDestroy = false)
{
if (m_CachedCharacterItems.Contains(characterItem))
{
// Don't destroy cached character items.
return true;
}
return base.DestroyCharacterItem(characterItem, forceDestroy);
}
/// <summary>
/// This function will scan the Items in the ItemPlacement component and initialize all the CharacterItems.
/// </summary>
protected override void InitializePreAddedCharacterItems()
{
// Do nothing, since we only want to initialize pre-added items when they are picked up.
}
/// <summary>
/// When a character item is spawned send events to notify objects outside the inventory.
/// </summary>
/// <param name="characterItem">The character Item that was added.</param>
public virtual void OnCharacterItemSpawned(CharacterItem characterItem)
{
if (!m_ValidCharacterItems.Contains(characterItem)) {
m_ValidCharacterItems.Add(characterItem);
}
/*
if (m_AllCharacterItems.Contains(characterItem)) {
return;
}
*/
EventHandler.ExecuteEvent(m_GameObject, "OnInventoryWillAddItem", characterItem);
// @CustomCode Start: Only add the character item if its not already in all character items.
if (!m_AllCharacterItems.Contains(characterItem))
{
m_AllCharacterItems.Add(characterItem);
m_CharacterItemsBySlot[characterItem.SlotID].Add(characterItem);
}
// @CustomCode End
// Notify those interested that an item has been added.
EventHandler.ExecuteEvent(m_GameObject, "OnInventoryAddItem", characterItem);
if (m_OnAddItemEvent != null) {
m_OnAddItemEvent.Invoke(characterItem);
}
// The ItemIdentifier event should also be called in cases where the amount is greater than 0.
// This allows the ItemIdentifier to be picked up before the item has been added.
if (GetItemIdentifierAmount(characterItem.ItemIdentifier) > 0) {
OnItemIdentifierPickedUp(characterItem.ItemIdentifier, characterItem.SlotID, 1, false, false);
}
}
If the item exists in m_AllCharacterItems, it means that was is aleady spawned on the character.I didn't understand why this function originally returns early if all characters items contains the character item already?