/// <summary> /// The ability has started. /// </summary> protected override void AbilityStarted() { base.AbilityStarted(); // If the item pickup isn't null then the ability is currently working on equipping another item. if (m_ItemPickup != null && m_ItemPickup != m_AvailableItemPickups[0]) { m_ItemPickup.DoItemTypePickup(m_GameObject, m_Inventory, m_SlotID, true, false); } m_ItemPickup = m_AvailableItemPickups[0]; m_AvailablePickupCount--; for (int i = 0; i < m_AvailablePickupCount; ++i) { m_AvailableItemPickups[i] = m_AvailableItemPickups[i + 1]; } // If the PickupItemType array contains any ItemTypes then the PickupItem ability should only start if the PickupItem object contains one of the ItemTypes // within the array. If it doesn't contain the ItemType then that ItemType should be equipped as if the PickupItem ability doesn't exist. var immediatePickup = false; if (m_PickupItemTypes != null && m_PickupItemTypes.Length > 0) { immediatePickup = true; for (int i = 0; i < m_PickupItemTypes.Length; ++i) { for (int j = 0; j < m_ItemPickup.ItemTypeCounts.Length; ++j) { if (m_PickupItemTypes[i] == m_ItemPickup.ItemTypeCounts[j].ItemType) { immediatePickup = false; break; } } if (immediatePickup) { break; } } } m_ItemPickup.DoItemPickup(m_GameObject, m_Inventory, m_SlotID, !immediatePickup, immediatePickup); // The ability shouldn't start if the ItemType has already been picked up. if (immediatePickup) { StopAbility(); return; } // Assume every ItemType can be picked up. The local mask should be set so the ability doesn't block the pickup with EquipUnequip.ShouldEquip. m_AllowEquippedSlotsMask = (1 << m_Inventory.SlotCount) - 1; var allowedEquippedSlotsMask = 0; // Before the item can be picked up the currently equipped items need to be unequipped. for (int i = 0; i < m_EquipUnequipAbilities.Length; ++i) { m_EquipUnequipAbilities[i].WillStartPickup(); } for (int i = 0; i < m_ItemPickup.ItemTypeCounts.Length; ++i) { var itemType = m_ItemPickup.ItemTypeCounts[i].ItemType; for (int j = 0; j < m_Inventory.SlotCount; ++j) { var item = m_Inventory.GetItem(j, itemType); if (item == null) { continue; } // Determine if the item should be equipped. The current item needs to be unequipped if it doesn't match the item being picked up. var categoryIndex = 0; var shouldEquip = false; for (int k = 0; k < m_EquipUnequipAbilities.Length; ++k) { if (itemType.CategoryIDMatch(m_EquipUnequipAbilities[k].ItemSetCategoryID) && m_EquipUnequipAbilities[k].ShouldEquip(item, m_ItemPickup.ItemTypeCounts[i].Count)) { shouldEquip = true; categoryIndex = m_EquipUnequipAbilities[k].ItemSetCategoryIndex; break; } } if (!shouldEquip) { continue; } // The item should be equipped. var equippedItemType = m_Inventory.GetItem(item.SlotID); if (itemType != equippedItemType) { allowedEquippedSlotsMask |= (1 << item.SlotID); } break; } } m_AllowEquippedSlotsMask = allowedEquippedSlotsMask; // If the item doesn't need to be equipped then it should still be picked up. if (m_AllowEquippedSlotsMask == 0) { m_ItemPickup.DoItemPickup(m_GameObject, m_Inventory, m_SlotID, false, true); StopAbility(); return; } // If the ability index is -1 then an animation will not play and the item should be picked up immediately. if (m_AbilityIndexParameter == -1) { DoItemPickup(); } else if (!m_PickupEvent.WaitForAnimationEvent) { Scheduler.ScheduleFixed(m_PickupEvent.Duration, DoItemPickup); } }