/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Character.Abilities.Items { using Opsive.UltimateCharacterController.Utility; using UnityEngine; /// /// The EquipPrevious ability will equip the previous ItemSet in the specified category. /// [DefaultStartType(AbilityStartType.ButtonDown)] [DefaultInputName("Equip Previous Item")] [AllowDuplicateTypes] public class EquipPrevious : EquipSwitcher { private int m_PrevItemSetIndex; private int m_ItemSetIndex = -1; /// /// The EquipUnequip ability has changed the active ItemSet. /// /// The updated active ItemSet index value. protected override void OnItemSetIndexChange(int itemSetIndex) { if (itemSetIndex == -1 || (m_ItemSetIndex != -1 && itemSetIndex == m_ItemSetManager.GetDefaultItemSetIndex(m_ItemSetCategoryIndex) && !m_ItemSetManager.CategoryItemSets[m_ItemSetCategoryIndex].ItemSetList[itemSetIndex].CanSwitchTo)) { return; } m_PrevItemSetIndex = itemSetIndex; if (m_ItemSetIndex == -1) { m_ItemSetIndex = itemSetIndex; } } /// /// Called when the ablity is tried to be started. If false is returned then the ability will not be started. /// /// True if the ability can be started. public override bool CanStartAbility() { // An attribute may prevent the ability from starting. if (!base.CanStartAbility()) { return false; } m_ItemSetIndex = m_ItemSetManager.NextActiveItemSetIndex(m_ItemSetCategoryIndex, m_PrevItemSetIndex, false); return m_ItemSetIndex != -1 && m_ItemSetIndex != m_EquipUnequipItemAbility.ActiveItemSetIndex; } /// /// The ability has started. /// protected override void AbilityStarted() { base.AbilityStarted(); m_EquipUnequipItemAbility.StartEquipUnequip(m_ItemSetIndex); // It is up to the EquipUnequip ability to do the actual equip - stop the current ability. StopAbility(); } /// /// The character has died. /// /// The position of the force. /// The amount of force which killed the character. /// The GameObject that killed the character. protected override void OnDeath(Vector3 position, Vector3 force, GameObject attacker) { if (m_Inventory.RemoveAllOnDeath) { m_PrevItemSetIndex = m_ItemSetIndex = -1; } } } }