private void updateSubStages() { findTargetLocationToFire(); switch (currentCombatSubStage) { case CombatSubStages.InCover: //Debug.Log("In Cover"); m_selfAgent.lookAtTarget(); if (currentCoverPoint.isSafeFromTarget() && currentCoverPoint.canFireToTarget(fireRangeDistance)) { switch (currentCoverShootingSubStage) { case CoverShootingSubStages.Cover: m_selfAgent.aimWeapon(); currentCoverShootingSubStage = CoverShootingSubStages.Peek; shotsFromCover = (int)(Random.value * 5); //Debug.Log(shotsFromCover); break; case CoverShootingSubStages.Peek: m_selfAgent.weaponFireForAI(); currentCoverShootingSubStage = CoverShootingSubStages.Shoot; setStepIntervalSize(0.3f); break; case CoverShootingSubStages.Shoot: currentShotsFromCover++; if (currentShotsFromCover > shotsFromCover) { currentCoverShootingSubStage = CoverShootingSubStages.Cover; currentShotsFromCover = 0; m_selfAgent.stopAiming(); setStepIntervalSize(0.8f); } else { currentCoverShootingSubStage = CoverShootingSubStages.Peek; } break; } } else { //Debug.Log("Cover is not safe or cannot fire to target"); currentCombatSubStage = CombatSubStages.LookingForCover; setStepIntervalSize(1); } break; case CombatSubStages.LookingForCover: //Debug.Log("Looking for cover"); CoverPoint tempCurrentCoverPoint = closestCombatLocationAvaialbe(); if (tempCurrentCoverPoint != null) { if (currentCoverPoint) { //currentCoverPoint.stPointOccupentsName(""); currentCoverPoint.setOccupent(null); } currentCoverPoint = tempCurrentCoverPoint; m_navMeshAgent.SetDestination(currentCoverPoint.getPosition()); currentCombatSubStage = CombatSubStages.MovingToCover; // Get up and move m_selfAgent.toggleHide(); m_selfAgent.aimWeapon(); } break; case CombatSubStages.MovingToCover: //Debug.Log("Moving to cover"); if (!m_navMeshAgent.pathPending && m_navMeshAgent.remainingDistance > 1) { if (m_navMeshAgent.remainingDistance > 3 && Vector3.Distance(m_selfAgent.getCurrentPosition(), opponent.getCurrentPosition()) > fireRangeDistance) { m_enableRun = true; m_selfAgent.stopAiming(); } else { if (Vector3.Distance(m_selfAgent.getCurrentPosition(), opponent.getCurrentPosition()) < fireRangeDistance) { m_selfAgent.aimWeapon(); m_enableRun = false; m_selfAgent.weaponFireForAI(); } } } else { m_selfAgent.lookAtTarget(); currentCombatSubStage = CombatSubStages.InCover; // Get down on cover m_selfAgent.toggleHide(); m_selfAgent.stopAiming(); setStepIntervalSize(0.8f); m_navMeshAgent.velocity = Vector3.zero; } break; } }
private bool isCoverPointUsable(CoverPoint point) { return(point.isSafeFromTarget() && point.canFireToTarget(fireRangeDistance)); }