/// <summary> /// The item ability has been started or stopped. /// </summary> /// <param name="itemAbility">The item ability which was started or stopped.</param> /// <param name="active">True if the ability was started, false if it was stopped.</param> private void OnItemAbilityActive(ItemAbility itemAbility, bool active) { if (!IsActive || !(itemAbility is Reload)) { return; } var reloadAbility = itemAbility as Reload; for (int i = 0; i < reloadAbility.ReloadableItems.Length; ++i) { if (reloadAbility.ReloadableItems[i] == null) { continue; } var slotID = reloadAbility.ReloadableItems[i].Item.SlotID; if (m_SlotID != -1) { if (m_SlotID != slotID) { continue; } // If a slot ID is specified then there will only be one element. slotID = 0; } // If the reload ability is active the CanStop event shouldn't fire so the character can continue to fire after reloading. if (active) { ResetCanStopEvent(slotID); } else { m_CanStopEvent[slotID] = Scheduler.ScheduleFixed(m_UsableItems[slotID].StopUseAbilityDelay, AbilityCanStop, slotID); } } }
/// <summary> /// The item ability has been started or stopped. /// </summary> /// <param name="itemAbility">The item ability which was started or stopped.</param> /// <param name="active">True if the ability was started, false if it was stopped.</param> private void OnItemAbilityActive(ItemAbility itemAbility, bool active) { if (!(itemAbility is Reload)) { return; } // Use currently is not active, but it may have to start if the Use ability is trying to be started. if (!active && InputIndex != -1 && m_PlayerInput != null) { // Change the start type so the button up won't affect if the ability can start. var startType = m_StartType; if (startType == AbilityStartType.ButtonDown) { m_StartType = AbilityStartType.ButtonDownContinuous; } if (CanInputStartAbility(m_PlayerInput)) { if (IsActive) { // The use state should be reset if the ability is currently active. for (int i = 0; i < m_UsableItems.Length; ++i) { if (m_UsableItems[i] == null) { continue; } m_UsableItems[i].StartItemUse(this); ResetCanStopEvent(i); } InputIndex = -1; } else { // The ability isn't active, but it should be. StartAbility(); } } m_StartType = startType; return; } var reloadAbility = itemAbility as Reload; for (int i = 0; i < reloadAbility.ReloadableItems.Length; ++i) { if (reloadAbility.ReloadableItems[i] == null) { continue; } var slotID = reloadAbility.ReloadableItems[i].Item.SlotID; if (m_SlotID != -1) { if (m_SlotID != slotID) { continue; } // If a slot ID is specified then there will only be one element. slotID = 0; } // If the reload ability is active the CanStop event shouldn't fire so the character can continue to fire after reloading. if (active) { // If the ability index is not -1 then the item is trying to be stopped. Prevent the item from being used again when reload is complete. if (InputIndex != -1) { StopAbility(true); } else { ResetCanStopEvent(slotID); } } else { m_CanStopEvent[slotID] = Scheduler.ScheduleFixed(m_UsableItems[slotID].StopUseAbilityDelay, AbilityCanStop, slotID); } } }
/// <summary> /// An ItemAbility has been activated or deactivated. /// </summary> /// <param name="itemAbility">The ItemAbility activated or deactivated.</param> /// <param name="active">Was the ItemAbility activated?</param> private void OnItemAbilityActive(ItemAbility itemAbility, bool active) { if (!active || IsActive) { return; } // If another use ability is started or a use is active then the character shouldn't be able to counter attack. if (!(itemAbility is Block) || m_CharacterLocomotion.IsAbilityTypeActive <Use>()) { m_ImpactTime = -1; return; } // The block ability has been activated. The source of the block must be a melee weapon - counter attack doesn't work against non-melee weapons. var blockAbility = itemAbility as Block; m_OpponentMeleeWeapon = null; for (int i = 0; i < blockAbility.ImpactSources.Length; ++i) { if (blockAbility.ImpactSources[i] == null || !(blockAbility.ImpactSources[i] is MeleeWeapon)) { continue; } m_OpponentMeleeWeapon = blockAbility.ImpactSources[i] as MeleeWeapon; break; } if (m_OpponentMeleeWeapon == null) { return; } // The opponent must actively be attacking. m_OpponentLocomotion = m_OpponentMeleeWeapon.CharacterLocomotion; m_OpponentUseAbility = null; var useAbilities = m_OpponentLocomotion.GetAbilities <Use>(); if (useAbilities == null || useAbilities.Length == 0) { m_ImpactTime = -1; return; } for (int i = 0; i < useAbilities.Length; ++i) { if (!useAbilities[i].IsActive) { continue; } // The ability is active. Ensure it is using a melee weapon. for (int j = 0; j < useAbilities[i].UsableItems.Length; ++j) { var meleeWeapon = useAbilities[i].UsableItems[j] as MeleeWeapon; if (meleeWeapon != m_OpponentMeleeWeapon) { continue; } m_OpponentUseAbility = useAbilities[i]; break; } if (m_OpponentUseAbility != null) { break; } } if (m_OpponentUseAbility == null) { m_ImpactTime = -1; return; } m_ImpactTime = Time.time; }