public override void UpdateAct()
    {
        base.UpdateAct();

        #region Pre
        if (doPres)
        {
            if (ShouldCheckPlayerCriticalSitu())
            {
                soldInfo.SlowlyUpdatePlayerCritic();
            }

            #region FightInPoint
            if (pre_FightInPoint)
            {
                DoPre_FightInPoint();
            }
            #endregion
        }
        #endregion

StartSteps:

        #region Start01
        if (step == FightInRegStep.Start01)
        {
            if (ShouldStartCampMode())
            {
                step = FightInRegStep.Camp01;
            }
            else
            {
                step = FightInRegStep.TryStartMoving01;
            }
        }
        #endregion

        #region TryStartMoving01
        if (step == FightInRegStep.TryStartMoving01)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            if (!NeedsDistantMoveToGetToPos(controlledSoldier.transform.position, selectedFightPoint.transform.position))
            {
                step = FightInRegStep.ShortMoving01;
                goto StartSteps;
            }

            step = FightInRegStep.NoramlMoving01;
            goto StartSteps;

            //if (IsSoldOnPoint(controlledSoldier.gameObject, selectedFightPoint.transform.position, maxErrorToPos))
            //{
            //    step = FightInRegStep.FightingInPoint01;
            //    goto StartSteps;
            //}
            //else
            //{
            //    Vector3[] newPath;

            //    if (mapLogic.FindCurvePath(controlledSoldier.transform.position, selectedFightPoint.transform.position, maxErrorToPos, out newPath))
            //    {
            //        currentMovementPath = newPath;
            //        step = FightInRegStep.NoramlMoving01;
            //        goto StartSteps;
            //    }
            //    else
            //    {
            //        step = FightInRegStep.TryStartMoving02;
            //        goto StartSteps;
            //    }
            //}
        }
        #endregion

        #region TryStartMoving02
        if (step == FightInRegStep.TryStartMoving02)
        {
            aStarResultTimeCounter = aStarResultMaxTime;
            soldInfo.FindNewAStarPath(controlledSoldier.transform.position, selectedFightPoint.transform.position);
            step = FightInRegStep.TryStartMoving03;
            goto StartSteps;
        }
        #endregion

        #region TryStartMoving03
        if (step == FightInRegStep.TryStartMoving03)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            if (soldInfo.isAStarPathResultRecievedInThisRun)
            {
                if (!soldInfo.isAStarPathError)
                {
                    currentMovementPath = soldInfo.aStarLastPath;
                    step = FightInRegStep.NoramlMoving01;
                    goto StartSteps;
                }
                else
                {
                    //FightPoint fp;
                    //if (IsSoldierOnAPoint(out fp))
                    //{
                    //    //<Temp>
                    //    Debug.LogError("No path founded to point!");
                    //    //</Temp>

                    //    selectedFightPoint = fp;
                    //    step = FightInRegStep.FightingInPoint01;
                    //    goto StartSteps;
                    //}

                    //<Temp>
                    Debug.LogError("No path founded to point!");
                    //</Temp>

                    time_SelectNewPointToGoFromFightingInPos_Counter = time_SelectNewPointToGoFromFightingInPos_Max_WhileNoPath;
                    step = FightInRegStep.FightingInPos01;
                    goto StartSteps;
                }
            }

            aStarResultTimeCounter -= Time.deltaTime;
            if (aStarResultTimeCounter <= 0)
            {
                //<Temp>
                Debug.LogError("No path founded in needed time!");
                //</Temp>

                //FightPoint fp;
                //if (IsSoldierOnAPoint(out fp))
                //{
                //    selectedFightPoint = fp;
                //    step = FightInRegStep.FightingInPoint01;
                //    goto StartSteps;
                //}

                time_SelectNewPointToGoFromFightingInPos_Counter = time_SelectNewPointToGoFromFightingInPos_Max_WhileNoPath;
                step = FightInRegStep.FightingInPos01;
                goto StartSteps;
            }
        }
        #endregion

        #region NoramlMoving01
        if (step == FightInRegStep.NoramlMoving01)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            initialTargetForAfterMovementChecked = false;
            shouldSetInitialTargForFightInPoint  = false;
            initialTargetForFightInPoint         = null;

            currentMovementType = fightReg.movementType; //GetMovementTypeForMovingToTarget(currentMovementPath);

            movementAct = controlledSoldier.gameObject.AddComponent <SoldierAction_Movement>();
            movementAct.Init(controlledSoldier);
            movementAct.InitDefaultParams(currentMovementType);
            movementAct.initialEnemies = initialEnemies;

            if (doMoveFight)
            {
                movementAct.Init_DoFightWhileMove(true);
            }


            //SetMovementParams(currentMovementType);

            movementAct.SetNextActAnimToCrossfade(selectedFightPoint.defaultfightInfo.GetAStartAnim());
            movementAct.SetEndingRotNormal(selectedFightPoint.transform.forward);

            movementAct.Init_PosToFindPath(selectedFightPoint.transform.position);

            //movementAct.Init_SetPath(currentMovementPath);

            movementAct.StartAct();
            SetCurrentAction(movementAct);

            step = FightInRegStep.NoramlMoving02;
        }
        #endregion

        #region NoramlMoving02
        if (step == FightInRegStep.NoramlMoving02)
        {
            if (needsToBeFinished)
            {
                movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
                step = FightInRegStep.Finishing01;
                goto StartSteps;
            }

            if (!initialTargetForAfterMovementChecked && movementAct.isBeforeEndAnimRun)
            {
                initialTargetForAfterMovementChecked = true;

                GameObject targ = SelectBestTargetForPoint(selectedFightPoint);

                if (targ != null)
                {
                    shouldSetInitialTargForFightInPoint = true;
                    initialTargetForFightInPoint        = targ;
                    movementAct.SetEndingRotLookTarget(initialTargetForFightInPoint.transform);

                    gunDirForFightInPointInitialTarget = SoldierStats.GetSoldierGunDirectionForTarget(controlledSoldier.gameObject, initialTargetForFightInPoint);

                    movementAct.SetNextActAnimToCrossfade(selectedFightPoint.defaultfightInfo.GetAnimList_FightLookAllBody(gunDirForFightInPointInitialTarget).GetRandomAnimName());
                }
            }

            if (movementAct.finishReport == FinishReportEnum.FinishedOK)
            {
                if (selectedFightPoint == initialPoint)
                {
                    needsToGoToInitialPoint = false;
                }

                Destroy(movementAct);
                SetCurrentAction(null);
                step = FightInRegStep.FightingInPoint01;
                goto StartSteps;
            }


            if (!movementAct.isEndingV && SlowlyCheckPlayerCritStateWhileMoving())
            {
                step = FightInRegStep.NoramlMoving_StopMovingAndGoToFightInPos01;
                goto StartSteps;
            }
        }
        #endregion

        #region NoramlMoving_StopMovingAndGoToFightInPos01
        if (step == FightInRegStep.NoramlMoving_StopMovingAndGoToFightInPos01)
        {
            if (IsPlayerStillInCriticSitu())
            {
                shouldSetPlayerAsTargetForFightInPos  = true;
                gunDirForTargettingPlayerInFightInPos = SoldierStats.GetSoldierGunDirectionForTarget(controlledSoldier.gameObject, mapLogic.player);

                Transform playerTr = null;

                if (mapLogic.player != null)
                {
                    playerTr = mapLogic.player.transform;
                }

                movementAct.SetNeedsToStop(normalMovementStopTime, onPosFightInPointInfo.GetAnimList_FightLookAllBody(gunDirForTargettingPlayerInFightInPos).GetRandomAnimName(), playerTr);
            }
            else
            {
                movementAct.SetNeedsToStop(normalMovementStopTime, onPosFightInPointInfo.GetAStartAnim());
            }

            step = FightInRegStep.NoramlMoving_StopMovingAndGoToFightInPos02;
        }
        #endregion

        #region NoramlMoving_StopMovingAndGoToFightInPos02
        if (step == FightInRegStep.NoramlMoving_StopMovingAndGoToFightInPos02)
        {
            if (movementAct.finishReport == FinishReportEnum.FinishedOK)
            {
                Destroy(movementAct);
                SetCurrentAction(null);
                step = FightInRegStep.FightingInPos00;
            }
        }
        #endregion

        #region FightingInPos00
        if (step == FightInRegStep.FightingInPos00)
        {
            time_SelectNewPointToGoFromFightingInPos_Counter = time_SelectNewPointToGoFromFightingInPos_Max;
            step = FightInRegStep.FightingInPos01;
        }
        #endregion

        #region FightingInPos01
        if (step == FightInRegStep.FightingInPos01)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            fightInPointAct = controlledSoldier.gameObject.AddComponent <SoldierAction_FightInPoint>();
            fightInPointAct.Init(controlledSoldier);
            fightInPointAct.InitForPos(controlledSoldier.transform.position, controlledSoldier.transform.rotation, onPosFightInPointInfo);
            fightInPointAct.InitAIVoiceSitu(voiceSituation);
            fightInPointAct.initialEnemies = initialEnemies;

            if (shouldSetPlayerAsTargetForFightInPos)
            {
                fightInPointAct.Init_StartInShootSituForTarget(mapLogic.player);
                fightInPointAct.currentGunDirection = gunDirForTargettingPlayerInFightInPos;

                shouldSetPlayerAsTargetForFightInPos = false;
            }

            fightInPointAct.SetOwnerFightInRegAct(this);

            fightInPointAct.StartAct();

            SetCurrentAction(fightInPointAct);

            step = FightInRegStep.FightingInPos02;
        }
        #endregion

        #region FightingInPos02
        if (step == FightInRegStep.FightingInPos02)
        {
            if (needsToBeFinished)
            {
                fightInPointAct.SetNeedsToBeFinished(evenStopMovingForFinish);
                step = FightInRegStep.Finishing01;
                goto StartSteps;
            }

            time_SelectNewPointToGoFromFightingInPos_Counter = MathfPlus.DecByDeltatimeToZero(time_SelectNewPointToGoFromFightingInPos_Counter);

            if (IsPlayerStillInCriticSitu())
            {
                time_CheckPlayerInCritStateWhileInFightInPos_Counter = MathfPlus.DecByDeltatimeToZero(time_CheckPlayerInCritStateWhileInFightInPos_Counter);

                if (time_CheckPlayerInCritStateWhileInFightInPos_Counter <= 0)
                {
                    time_CheckPlayerInCritStateWhileInFightInPos_Counter = time_CheckPlayerInCritStateWhileInFightInPos_Max;

                    if (!soldInfo.IsPlayerInView())
                    {
                        if (time_SelectNewPointToGoFromFightingInPos_Counter == 0)
                        {
                            time_SelectNewPointToGoFromFightingInPos_Counter = time_SelectNewPointToGoFromFightingInPos_Max;

                            //<Temp>
                            newFightPointToGo = SelectBestFightPointForPlayerCritState();
                            step = FightInRegStep.FightingInPoint_ChangePoint01;
                            //</Temp>

                            goto StartSteps;
                        }
                    }
                }
            }
            else
            {
                if (time_SelectNewPointToGoFromFightingInPos_Counter == 0)
                {
                    time_SelectNewPointToGoFromFightingInPos_Counter = time_SelectNewPointToGoFromFightingInPos_Max;

                    newFightPointToGo = SelectNewFightPoint();
                    step = FightInRegStep.FightingInPoint_ChangePoint01;
                    goto StartSteps;
                }
            }
        }
        #endregion

        #region FightingInPoint01
        if (step == FightInRegStep.FightingInPoint01)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            pre_FightInPoint = true;

            //ResetDelayTimeToChangePoint();
            //ResetTimeToGoToClosePoint();
            ResetTimeToCheckAvailableTargets();
            ResetTime_ChangePoint();

            fightInPointAct = controlledSoldier.gameObject.AddComponent <SoldierAction_FightInPoint>();
            fightInPointAct.Init(controlledSoldier);
            fightInPointAct.InitForFightPoint(selectedFightPoint);
            fightInPointAct.InitAIVoiceSitu(voiceSituation);
            fightInPointAct.initialEnemies = initialEnemies;

            if (shouldSetInitialTargForFightInPoint)
            {
                fightInPointAct.Init_StartInShootSituForTarget(initialTargetForFightInPoint);
                fightInPointAct.currentGunDirection = gunDirForFightInPointInitialTarget;
            }

            fightInPointAct.SetOwnerFightInRegAct(this);

            fightInPointAct.StartAct();

            if (nowReadyForGreandeLaunch)
            {
                fightInPointAct.SetItsNowReadyForLaunchGrenade();
            }

            SetCurrentAction(fightInPointAct);

            step = FightInRegStep.FightingInPoint02;
        }
        #endregion

        #region FightingInPoint02
        if (step == FightInRegStep.FightingInPoint02)
        {
            if (needsToBeFinished)
            {
                fightInPointAct.SetNeedsToBeFinished(evenStopMovingForFinish);
                step = FightInRegStep.Finishing01;
                goto StartSteps;
            }

            if (IsPlayerStillInCriticSitu())
            {
                time_CheckPlayerInCritStateWhileInFightInPoint_Counter = MathfPlus.DecByDeltatimeToZero(time_CheckPlayerInCritStateWhileInFightInPoint_Counter);

                if (time_CheckPlayerInCritStateWhileInFightInPoint_Counter <= 0)
                {
                    time_CheckPlayerInCritStateWhileInFightInPoint_Counter = time_CheckPlayerInCritStateWhileInFightInPoint_Max;

                    if (!CheckIsCurrentPointOkForPlayerCritState())
                    {
                        FightPoint newFP = SelectBestFightPointForPlayerCritState();

                        if (newFP != selectedFightPoint)
                        {
                            newFightPointToGo = newFP;

                            step = FightInRegStep.FightingInPoint_ChangePoint01;
                            goto StartSteps;
                        }
                    }
                }
            }
            else
            {
                bool newPointSelected = false;

                if (timeToCheckAvailableTargets_Counter == 0)
                {
                    ResetTimeToCheckAvailableTargets();

                    List <CharRayCastRsltForFightInPoInf> targsResults;

                    targsResults = mapLogic.GetAllAttackableEnemiesForListOfFightInfos(selectedFightPoint.fightInfos, controlledSoldier.gameObject, initialEnemies, selectedFightPoint.transform.position, selectedFightPoint.transform.rotation);

                    float sumOfRatings = 0;

                    sumOfRatings = mapLogic.GetSumOfRatings(targsResults);

                    if (sumOfRatings == 0)
                    {
                        FightPointWithRating newFPWithRating = SelectNewFightPointWithRating();

                        if (newFPWithRating != null &&
                            newFPWithRating.fightPoint != null &&
                            newFPWithRating.fightPoint != selectedFightPoint &&
                            newFPWithRating.rating > sumOfRatings)
                        {
                            newPointSelected  = true;
                            newFightPointToGo = newFPWithRating.fightPoint;

                            step = FightInRegStep.FightingInPoint_ChangePoint01;
                            goto StartSteps;
                        }
                    }
                }

                if (!newPointSelected)
                {
                    if (time_ChangePoint_Counter == 0)
                    {
                        ResetTime_ChangePoint();

                        List <FightPointWithRating> fightPointWithRatings = mapLogic.RateFightPointsAndSort(fightReg.GetFightPointsOfLane(soldInfo.curFightRegLaneNum), controlledSoldier.gameObject, initialEnemies);

                        if (fightPointWithRatings.Count == 1)
                        {
                            if (fightPointWithRatings[0].fightPoint != selectedFightPoint)
                            {
                                newPointSelected  = true;
                                newFightPointToGo = fightPointWithRatings[0].fightPoint;

                                step = FightInRegStep.FightingInPoint_ChangePoint01;
                                goto StartSteps;
                            }
                        }

                        if (fightPointWithRatings.Count > 1)
                        {
                            if (fightPointWithRatings[0].fightPoint != selectedFightPoint)
                            {
                                newPointSelected  = true;
                                newFightPointToGo = fightPointWithRatings[0].fightPoint;

                                step = FightInRegStep.FightingInPoint_ChangePoint01;
                                goto StartSteps;
                            }
                            else
                            {
                                fightPointWithRatings[0].rating *= (1 - Random.Range(0f, maxValueToDecreaseFromCurrentPointRating));

                                if (fightPointWithRatings[1].rating >= fightPointWithRatings[0].rating)
                                {
                                    if (fightPointWithRatings[1].rating > 0)
                                    {
                                        newPointSelected  = true;
                                        newFightPointToGo = fightPointWithRatings[1].fightPoint;

                                        step = FightInRegStep.FightingInPoint_ChangePoint01;
                                        goto StartSteps;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        #endregion

        #region FightingInPoint_ChangePoint01
        if (step == FightInRegStep.FightingInPoint_ChangePoint01)
        {
            if (fightInPointAct != null && fightInPointAct.status != ActionStatusEnum.Finished)
            {
                fightInPointAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            }

            step = FightInRegStep.FightingInPoint_ChangePoint02;
        }
        #endregion

        #region FightingInPoint_ChangePoint02
        if (step == FightInRegStep.FightingInPoint_ChangePoint02)
        {
            if ((fightInPointAct != null && fightInPointAct.status == ActionStatusEnum.Finished) || fightInPointAct == null)
            {
                if (fightInPointAct != null)
                {
                    Destroy(fightInPointAct);
                }

                SetCurrentAction(null);
                pre_FightInPoint = false;

                selectedFightPoint = newFightPointToGo;
                step = FightInRegStep.TryStartMoving01;
            }
        }
        #endregion

        #region Finishing01
        if (step == FightInRegStep.Finishing01)
        {
            if (currentAction == null)
            {
                SetFinished(true);
                step = FightInRegStep.Finishing02;
                goto StartSteps;
            }

            //<Alpha>
            if (needsToBeFinished)
            {
                currentAction.SetNeedsToBeFinished(evenStopMovingForFinish);
            }
            //</Alpha>

            if (currentAction.status == ActionStatusEnum.Finished)
            {
                Destroy(currentAction);
                SetCurrentAction(null);

                SetFinished(true);
                step = FightInRegStep.Finishing02;
                goto StartSteps;
            }
        }
        #endregion

        #region Camp01
        if (step == FightInRegStep.Camp01)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            campAct = controlledSoldier.gameObject.AddComponent <SoldierAction_Camp>();
            campAct.Init(controlledSoldier);

            if (campCurveInfos != null)
            {
                campAct.InitCampCurveInfos(campCurveInfos);
            }
            else
            {
                campAct.InitCampType(campInfo.campType);
            }

            campAct.StartAct();

            SetCurrentAction(campAct);

            step = FightInRegStep.Camp02;
        }
        #endregion

        #region Camp02
        if (step == FightInRegStep.Camp02)
        {
            if (needsToBeFinished)
            {
                campAct.SetNeedsToBeFinished(evenStopMovingForFinish);
                step = FightInRegStep.Finishing01;
                goto StartSteps;
            }

            if (campAct.playerHasBeenDetected)
            {
                SetPlayerIsDetectedInCampMode();
            }

            if (isPlayerDetectedInCampMode)
            {
                step = FightInRegStep.CampFinishingForStartingNormalMode01;
                goto StartSteps;
            }
        }
        #endregion

        #region CampFinishingForStartingNormalMode01
        if (step == FightInRegStep.CampFinishingForStartingNormalMode01)
        {
            campAct.SetNeedsToBeFinished(true);

            step = FightInRegStep.CampFinishingForStartingNormalMode02;
            goto StartSteps;
        }
        #endregion

        #region CampFinishingForStartingNormalMode02
        if (step == FightInRegStep.CampFinishingForStartingNormalMode02)
        {
            if (campAct == null || (campAct != null && campAct.status == ActionStatusEnum.Finished))
            {
                if (campAct != null)
                {
                    Destroy(campAct);
                }

                SetCurrentAction(null);
                step = FightInRegStep.TryStartMoving01;
            }
        }
        #endregion
    }
Exemplo n.º 2
0
    public override void UpdateAct()
    {
        base.UpdateAct();

        if (setSoldierExactPos)
        {
            Vector3 newPos = Vector3.Lerp(controlledSoldier.position, machineGun.standPosTr.position, Time.deltaTime * 8);
            controlledSoldier.position = new Vector3(newPos.x, controlledSoldier.position.y, newPos.z);
        }

StartSteps:

        #region Start01
        if (step == ActMachineGunStep.Start01)
        {
            //if (IsSoldOnPos(machineGun.standPosTr.position))
            //{
            //    step = ActMachineGunStep.FirstSoldierRotation01;
            //    goto StartSteps;
            //}
            //else
            //{

            step = ActMachineGunStep.GoingToPos01;
            goto StartSteps;

            //}
        }
        #endregion

        #region GoingToPos01

        if (step == ActMachineGunStep.GoingToPos01)
        {
            movementAct = controlledSoldier.gameObject.AddComponent <SoldierAction_Movement>();
            movementAct.Init(controlledSoldier);
            movementAct.InitDefaultParams(currentMovementType);
            movementAct.Init_PosToFindPath(machineGun.standPosTr.position);
            movementAct.initialEnemies = initialEnemies;

            movementAct.SetNextActAnimToCrossfade(anim_SoldierOnMachineGun_Mid);
            movementAct.SetEndingRotNormal(machineGun.transform.forward);

            movementAct.StartAct();

            step = ActMachineGunStep.GoingToPos02;
        }
        #endregion

        #region GoingToPos02
        if (step == ActMachineGunStep.GoingToPos02)
        {
            if (needsToBeFinished)
            {
                step = ActMachineGunStep.Finishing_MovementAct01;
                goto StartSteps;
            }

            if (movementAct.finishReport == FinishReportEnum.FinishedOK)
            {
                Destroy(movementAct);

                step = ActMachineGunStep.WaitForFirstAnim;
                goto StartSteps;
            }
        }
        #endregion

        #region WaitForFirstAnim
        if (step == ActMachineGunStep.WaitForFirstAnim)
        {
            if (needsToBeFinished)
            {
                SetFinished(true);
                return;
            }

            if (soldInfo.IsFullyInNewMainAnim())
            {
                step = ActMachineGunStep.UsingMachineGun01_Init;
            }
        }
        #endregion

        #region UsingMachineGun01_Init
        if (step == ActMachineGunStep.UsingMachineGun01_Init)
        {
            machineGun.SetControllingSoldier(controlledSoldier.gameObject);

            setSoldierExactPos = true;

            StartAnims();

            machineGunShootCounter = machineGun.shootSpeed;

            ResetShootDuration();
            ResetIdleTime();

            step = ActMachineGunStep.UsingMachineGun02_Restart;
        }
        #endregion

        #region UsingMachineGun02_Restart
        if (step == ActMachineGunStep.UsingMachineGun02_Restart)
        {
            ReselectTarget();
            ResetLockTargetTime();
            ResetRecheckTargetTime();

            step = ActMachineGunStep.UsingMachineGun03_Using;
        }
        #endregion

        #region UsingMachineGun03_Using
        if (step == ActMachineGunStep.UsingMachineGun03_Using)
        {
            if (needsToBeFinished)
            {
                step = ActMachineGunStep.Finishing_UsingMachineGun01;
                goto EndSteps;
            }

            lockTargetCounter = MathfPlus.DecByDeltatimeToZero(lockTargetCounter);

            recheckTargetCounter = MathfPlus.DecByDeltatimeToZero(recheckTargetCounter);

            if (lockTargetCounter == 0)
            {
                step = ActMachineGunStep.UsingMachineGun02_Restart;
                return;
            }

            if (recheckTargetCounter == 0)
            {
                ResetRecheckTargetTime();

                if (!mapLogic.IsCharacterOkAsTarget(gameObject, target.character, machineGun.raycastStartTr.position, machineGun.transform.rotation, range, -maxAngle, maxAngle, out target))
                {
                    ReselectTarget();
                }
            }

            if (!isIdle)
            {
                shootDurationCounter = MathfPlus.DecByDeltatimeToZero(shootDurationCounter);

                if (shootDurationCounter == 0)
                {
                    ResetShootDuration();
                    isIdle = true;
                }
            }
            else
            {
                idleTimeCounter = MathfPlus.DecByDeltatimeToZero(idleTimeCounter);

                if (idleTimeCounter == 0)
                {
                    ResetIdleTime();
                    isIdle = false;
                }
            }

            bool needsToShoot = false;

            if (mapLogic.IsCharacterTotallyFightable(target.character))
            {
                if (GentlySetAngleToTarget())
                {
                    if (!isIdle)
                    {
                        needsToShoot = true;
                    }
                }
            }

            if (needsToShoot)
            {
                //machineGunShootCounter = MathfPlus.DecByDeltatimeToZero(machineGunShootCounter);

                //if (machineGunShootCounter == 0)
                //{
                //    machineGunShootCounter = machineGun.shootSpeed;
                if (machineGun.gun.IsReady())
                {
                    Vector3 targetFirePos;

                    List <Transform> okPoses;

                    if (target.isCharacterHitted)
                    {
                        okPoses = target.characterHittedPoses;
                    }
                    else
                    {
                        okPoses = target.haloHittedPoses;
                    }

                    if (okPoses.Count > 0)
                    {
                        targetFirePos = okPoses[Random.Range(0, okPoses.Count)].position;

                        machineGun.gun.TryFire(machineGun.shootPosTr.position, targetFirePos);

                        //Vector3 bulletDir = targetFirePos - machineGun.shootPosTr.position;

                        //GameObject bulObj = GameObject.Instantiate(machineGun.bullet.gameObject, machineGun.shootPosTr.position, Quaternion.LookRotation(bulletDir)) as GameObject;
                        //Bullet bul = bulObj.GetComponent<Bullet>();
                        //bul.InitBulletProp(bulletDir, gameObject);

                        ////soundPlay.PlaySound_FX(fireSound);
                    }
                }
                //}
            }

            SetActiveAnims();

            SetMachineGunRotatingObjectAngle();
        }
        #endregion

        #region Finishing_MovementAct01
        if (step == ActMachineGunStep.Finishing_MovementAct01)
        {
            movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            step = ActMachineGunStep.Finishing_MovementAct02;
            goto EndSteps;
        }
        #endregion

        #region Finishing_MovementAct02
        if (step == ActMachineGunStep.Finishing_MovementAct02)
        {
            //<Alpha>
            if (needsToBeFinished)
            {
                movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            }
            //</Alpha>

            if (movementAct.status == ActionStatusEnum.Finished)
            {
                SetFinished(false);
                return;
            }
        }
        #endregion

        #region Finishing_UsingMachineGun01
        if (step == ActMachineGunStep.Finishing_UsingMachineGun01)
        {
            machineGun.SetControllingSoldier(null);
            step = ActMachineGunStep.Finishing_UsingMachineGun02;
        }
        #endregion

        #region Finishing_UsingMachineGun02
        if (step == ActMachineGunStep.Finishing_UsingMachineGun02)
        {
            float endWeightSpeed = machineGun.endRotateTimeCoef;

            midWeight += Time.deltaTime * endWeightSpeed;
            midWeight  = Mathf.Clamp01(midWeight);

            leftWeight -= Time.deltaTime * endWeightSpeed;
            leftWeight  = Mathf.Clamp01(leftWeight);


            rightWeight -= Time.deltaTime * endWeightSpeed;
            rightWeight  = Mathf.Clamp01(rightWeight);

            if (midWeight == 1
                &&
                leftWeight == 0
                &&
                rightWeight == 0)
            {
                EndAnims();
                SetFinished(true);
                return;
            }
        }
        #endregion

        EndSteps :;
    }
Exemplo n.º 3
0
    public override void RunIt()
    {
        base.RunIt();

    StartSteps:

        #region 1 Start
        if (step == 1)
        {
            if (needsToBeFinished)
            {
                SetFinished(false);
                return;
            }

            SetStep(3);

            //if (IsSoldOnPoint(controlledSoldier.gameObject, destinationPoint.transform.position, maxErrorToPos))
            //{
            //    SetFinished(true);
            //    return;
            //}
            //else
            //{
            //    if (movementPath != null && movementPath.Length > 0)
            //    {
            //        SetStep(3);
            //        goto StartSteps;
            //    }

            //    Vector3[] newPath;

            //    if (mapLogic.FindCurvePath(controlledSoldier.transform.position, destinationPoint.transform.position, maxErrorToPos, out newPath))
            //    {
            //        movementPath = newPath;
            //        SetStep(3);
            //        goto StartSteps;
            //    }
            //    else
            //    {
            //        SetStep(2);
            //        goto StartSteps;
            //    }
            //}
        }
        #endregion

        #region 2 Start AStar
        if (step == 2)
        {
            aStarResultTimeCounter = aStarResultMaxTime;
            restartAStarTimeCounter = restartAStarMaxTime;

            soldInfo.FindNewAStarPath(controlledSoldier.transform.position, destinationPoint.transform.position);

            if (soldInfo.isAStarPathResultRecievedInThisRun)
            {
                if (!soldInfo.isAStarPathError)
                {
                    movementPath = soldInfo.aStarLastPath;
                    SetStep(3);
                    goto StartSteps;
                }
                else
                {
                    Debug.LogError("No path founded to point!");
                    SetStep(2.2f);
                    goto EndSteps;
                }
            }

            SetStep(2.1f);
            goto StartSteps;
        }
        #endregion

        #region 2.1 Wait for Astar result
        if (step == 2.1f)
        {
            if (needsToBeFinished)
            {
                SetFinished(false);
                return;
            }

            if (soldInfo.isAStarPathResultRecievedInThisRun)
            {
                if (!soldInfo.isAStarPathError)
                {
                    movementPath = soldInfo.aStarLastPath;
                    SetStep(3);
                    goto StartSteps;
                }
                else
                {
                    Debug.LogError("No path founded to point!");
                    SetStep(2.2f);
                    goto EndSteps;
                }
            }

            aStarResultTimeCounter -= Time.deltaTime;
            if (aStarResultTimeCounter <= 0)
            {
                Debug.LogError("No path founded in needed time!");

                SetStep(2);
                goto EndSteps;
            }
        }
        #endregion

        #region 2.2 Waiting to restart Astar
        if (step == 2.2f)
        {
            if (needsToBeFinished)
            {
                SetFinished(false);
                return;
            }

            restartAStarTimeCounter = MathfPlus.DecByDeltatimeToZero(restartAStarTimeCounter);

            if (restartAStarTimeCounter == 0)
            {
                SetStep(2);
                goto StartSteps;
            }
        }
        #endregion

        #region 3 Start Moving
        if (step == 3)
        {
            if (needsToBeFinished)
            {
                SetFinished(false);
                return;
            }

            movementAct = controlledSoldier.gameObject.AddComponent<SoldierAction_Movement>();
            movementAct.Init(controlledSoldier.transform);
            movementAct.InitDefaultParams(movementType);

            movementAct.SetNextActAnimToCrossfade(nextActAnim);
            movementAct.SetEndingRotNormal(destinationPoint.transform.forward);

            movementAct.Init_PosToFindPath(destinationPoint.transform.position);

            //movementAct.Init_SetPath(movementPath);

            movementAct.StartAct();

            SetStep(3.1f);
        }
        #endregion

        #region 3.1 Moving
        if (step == 3.1f)
        {
            if (movementAct.status == SoldierAction.ActionStatusEnum.Finished)
            {
                Destroy(movementAct);
                SetFinished(true);
                return;
            }

            if (needsToBeFinished)
            {
                movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
                SetStep(4);
                goto StartSteps;
            }
        }
        #endregion

        #region 4 Finishing
        if (step == 4)
        {
            if (movementAct == null)
            {
                SetFinished(false);
                return;
            }

            //<Alpha>
            if (needsToBeFinished)
            {
                movementAct.SetNeedsToBeFinished(evenStopMovingForFinish);
            }
            //</Alpha>

            if (movementAct.status == SoldierAction.ActionStatusEnum.Finished)
            {
                Destroy(movementAct);
                SetFinished(false);
                return;
            }
        }
        #endregion

    EndSteps:
        ;
    }