public override void OnStart() { m_CurrentAgent = GetDefaultGameObject(m_Agent.Value); if (m_CurrentAgent != m_PrevAgent) { FpsInventoryBase inventory = m_CurrentAgent.GetComponent <FpsInventoryBase>(); if (inventory.selected != null) { m_Weapon = inventory.selected.gameObject.GetComponent <IAiWeapon>(); inventory.onSelectionChanged += WieldableSelectionChanged; } else { m_Weapon = null; } if (m_PrevAgent != null) { inventory = m_PrevAgent.GetComponent <FpsInventoryBase>(); inventory.onSelectionChanged -= WieldableSelectionChanged; } m_PrevAgent = m_CurrentAgent; } }
//Called once per frame while the condition is active. //Return whether the condition is success or failure. protected override bool OnCheck() { IQuickSlotItem selected = agent.quickSlots.selected; m_Weapon = selected.GetComponent <IAiWeapon>(); bool isReady = HasWeaponEquipped(); isReady &= InSuitablePosition(); return(isReady); }
/// <summary> /// Attempt to damage the Target. /// </summary> /// <returns>Return true if an attack was made (whether damage was done or not)</returns> IEnumerator DamageTarget() { IAiWeapon weapon = m_AiCharacter.quickSlots.selected.GetComponent <IAiWeapon>(); if (weapon == null) { yield return(null); } var character = currentTarget.GetComponent <NeoFPS.ICharacter>(); if (character == null) { yield return(null); } var kicker = character.headTransformHandler.GetComponent <NeoFPS.AdditiveKicker>(); if (kicker == null) { yield return(null); } m_AiAnimator.SetTrigger("Attack"); m_CurrentStatus = TaskStatus.Running; yield return(new WaitForSeconds(weapon.timeToImpact)); bool isCritical = false; m_TargetHealthManager.AddDamage(weapon.damageAmount, isCritical, this); // Get direction of attack var direction = m_Target.Value.transform.position - transform.position; direction.y = 0; direction.Normalize(); // Kick the camera position & rotation kicker.KickPosition(direction * weapon.kickDistance, weapon.kickDuration); kicker.KickRotation(Quaternion.AngleAxis(weapon.kickRotation, Vector3.Cross(direction, Vector3.up)), weapon.kickDuration); yield return(new WaitForSeconds(weapon.recoveryTime)); m_CurrentStatus = TaskStatus.Success; }
//This is called once each time the task is enabled. //Call EndAction() to mark the action as finished, either in success or failure. //EndAction can be called from anywhere. protected override void OnExecute() { if (m_CooldownCompleteTime > Time.timeSinceLevelLoad) { EndAction(false); return; } if (stop.value && m_NavMeshAgent != null) { m_NavMeshAgent.isStopped = true; } IQuickSlotItem selected = agent.quickSlots.selected; m_Weapon = selected.GetComponent <IAiWeapon>(); originalAnimatorSpeed = m_Animator.speed; m_Animator.speed = attackSpeed.value; m_Animator.SetTrigger(AnimParams.ATTACK); m_CooldownCompleteTime = Time.timeSinceLevelLoad + m_Weapon.recoveryTime; }
private void WieldableSelectionChanged(IQuickSlotItem item) { m_Weapon = item.gameObject.GetComponent <IAiWeapon>(); }