Пример #1
0
    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;
        }
    }
Пример #2
0
    private CoverPoint closestCombatLocationAvaialbe()
    {
        float minimumDistanceToIdealCoverPoint = 999;
        float minimumDistanceToSafeCoverPoint  = 999;
        float maximumDistanceToRiskyCoverPoint = 0;

        CoverPoint tempIDealCoverPoint = null;
        CoverPoint tempSafeCoverPoint  = null;
        CoverPoint tempRiskyCoverPoint = null;


        foreach (CoverPoint point in coverPoints)
        {
            if (!point.isOccupied())
            {
                point.setTargetToCover(opponent);
                if (point.isSafeFromTarget())
                {
                    // Find the safe cover point.
                    if (minimumDistanceToSafeCoverPoint > point.distanceTo(opponent.getCurrentPosition()))
                    {
                        minimumDistanceToSafeCoverPoint = point.distanceTo(opponent.getCurrentPosition());
                        tempSafeCoverPoint = point;
                    }

                    // Find the ideal closest cover point.
                    if (point.canFireToTarget(fireRangeDistance))
                    {
                        if (minimumDistanceToIdealCoverPoint > point.distanceTo(m_selfAgent.getCurrentPosition()))
                        {
                            minimumDistanceToIdealCoverPoint = point.distanceTo(m_selfAgent.getCurrentPosition());
                            tempIDealCoverPoint = point;
                        }
                    }
                }
                else
                {
                    // Find the safe cover point.
                    float distanceFromRiskyPoint = point.distanceTo(opponent.getCurrentPosition());
                    if (maximumDistanceToRiskyCoverPoint < distanceFromRiskyPoint && distanceFromRiskyPoint < COVER_POINT_MIN_DISTANCE)
                    {
                        maximumDistanceToRiskyCoverPoint = point.distanceTo(opponent.getCurrentPosition());
                        tempRiskyCoverPoint = point;
                    }
                }
            }
        }

        if (tempIDealCoverPoint != null)
        {
            //tempIDealCoverPoint.stPointOccupentsName(selfAgent.getName());
            tempIDealCoverPoint.setOccupent(m_selfAgent);
            return(tempIDealCoverPoint);
        }
        else if (tempSafeCoverPoint != null && Vector2.Distance(opponent.getCurrentPosition(), tempSafeCoverPoint.transform.position) <= COVER_POINT_MIN_DISTANCE)
        {
            //tempSafeCoverPoint.stPointOccupentsName(selfAgent.getName());
            tempSafeCoverPoint.setOccupent(m_selfAgent);
            return(tempSafeCoverPoint);
        }
        else if (tempRiskyCoverPoint != null)
        {
            return(tempRiskyCoverPoint);
        }

        return(null);
    }