public void InitTrainingMode()
        {
            datamanager           = DataManager.GetInstance();
            conscriptSoldierCache = new List <ConscriptSoldier>();

            for (int i = 0; i < 8; i++)
            {
                ConscriptSoldier temp = new ConscriptSoldier();
                temp.Reset();
                temp.isExpired = true;
                conscriptSoldierCache.Add(temp);
            }

            inputHandler    = InputHandler.Instance;
            aiSoldierIDList = new List <long>();

            MessageDispatcher.AddObserver(DestorySoldier, MessageType.SoldierDeath);
            MessageDispatcher.AddObserver(BattleStop, MessageType.BattleEnd);
            MessageDispatcher.AddObserver(PassiveDetectionAI, MessageType.BuildTower);
            MessageDispatcher.AddObserver(SoldierCommand, MessageType.SimUnitEnterIdleState);

            //MessageDispatcher.AddObserver( BattlePause, MessageType.BattlePause );

            if (currentWaveId == 0)
            {
                InitTrainingModeData();
            }

            //Tell ui trainingMode ready.
            MessageDispatcher.PostMessage(MessageType.TrainingModeReady);
        }
Beispiel #2
0
        public void InitEndlessMode()
        {
            datamanager           = DataManager.GetInstance();
            conscriptSoldierCache = new List <ConscriptSoldier>();

            for (int i = 0; i < 15; i++)
            {
                ConscriptSoldier temp = new ConscriptSoldier();
                temp.Reset();
                temp.isExpired = true;
                conscriptSoldierCache.Add(temp);
            }

            InitData();
            MessageDispatcher.AddObserver(DestorySoldier, MessageType.SoldierDeath);
            MessageDispatcher.AddObserver(BattleStop, MessageType.BattleEnd);
            MessageDispatcher.AddObserver(PassiveDetectionAI, MessageType.BuildTower);
            MessageDispatcher.AddObserver(SoldierCommand, MessageType.SimUnitEnterIdleState);
            MessageDispatcher.AddObserver(DestroyDemolisher, MessageType.DemolisherDestroyed);
            //MessageDispatcher.AddObserver( BattlePause, MessageType.BattlePause );
        }
Beispiel #3
0
        private void EndLessModeWaveLogic(float deltaTime)
        {
            endLessModeTimer += deltaTime;

            if (endLessModeTimer >= currentWaveDelayTime && isWaitingForComplete == false)
            {
                EndlessWavesProto.EndlessWaves currentWave;
                endlessModeWavesData.TryGetValue(currentWaveId, out currentWave);

                if (currentWave != null)
                {
                    for (int i = 0; i < currentWaveQuantity; i++)
                    {
                        int  rangeInt = Random.Range(1, 101);
                        long id       = 0;
                        int  currentWaveUnitID;

                        currentWaveUnitID = GetWavesUnitID(rangeInt, currentWave);
                        endlessModeUnitData.TryGetValue(currentWaveUnitID, out unit);

                        if (unit != null && currentWaveUnitID != -1)
                        {
                            unit = UnitLevelPropertyRatio(unit, currentWave);
                            id   = CreateSoldier(currentWaveUnitID, unit);

                            DebugUtils.Assert(id != 0, "Endless Mode: Soldier ID is 0!");

                            aiSoldierIDList.Add(id);
                        }
                        else
                        {
                            DebugUtils.LogError(DebugUtils.Type.Endless, "Can not find this ID : " + currentWaveUnitID + "unit in EndlessModeUnitData");
                        }

                        int pathMask = NavMeshAreaType.WALKABLE;                        //Walkable

                        if (rangeInt >= currentWave.Deploy_Lane)
                        {
                            pathMask = NavMeshAreaType.BOTTOMPATH;                            //BottomPath
                        }

                        DebugUtils.Log(DebugUtils.Type.Endless, "rangeInt is " + rangeInt + "pathMask is " + pathMask);

                        ConscriptSoldier conscriptSoldier = null;

                        for (int j = 0; j < conscriptSoldierCache.Count; j++)
                        {
                            if (conscriptSoldierCache[j].isExpired)
                            {
                                conscriptSoldier = conscriptSoldierCache[j];
                                conscriptSoldier.Reset();
                                conscriptSoldier.soldierID = id;
                                conscriptSoldier.navArea   = pathMask;
                                break;
                            }
                        }

                        if (conscriptSoldier == null)
                        {
                            conscriptSoldier = new ConscriptSoldier();

                            conscriptSoldier.soldierID       = id;
                            conscriptSoldier.navArea         = pathMask;
                            conscriptSoldier.readyFightTimer = 0f;

                            conscriptSoldierCache.Add(conscriptSoldier);
                        }
                    }
                }
                else
                {
                    DebugUtils.LogError(DebugUtils.Type.Endless, "Can not find EndlessMode AI unit data");
                }

                // For the PVE statistics
                datamanager.AddPveWaveNumber();

                currentWaveId        = currentWave.NextWave;
                currentWaveDelayTime = currentWave.NextDelay;
                currentWaveQuantity  = currentWave.NextQuantity;

                if (currentWave.WaitForComplete == true)
                {
                    isWaitingForComplete = true;
                }

                endLessModeTimer = 0;
            }
        }
        private void TrainingModeWaveLogic(float deltatime)
        {
            trainingModeTimer += deltatime;

            if (trainingModeTimer >= currentWaveDelayTime && isWaitingForComplete == false)
            {
                TrainingWavesProto.TrainingWaves currentWave;
                trainingModeWavesData.TryGetValue(currentWaveId, out currentWave);

                if (currentWave != null)
                {
                    //TODO: there will change about designer, maybe need waiting a short time spacing to spwan new soldier
                    for (int i = 0; i < currentWaveQuantity; i++)
                    {
                        int  rangeInt = Random.Range(1, 101);
                        long id       = 0;
                        int  currenWavetUnitID;

                        currenWavetUnitID = GetWavesUnitID(rangeInt, currentWave);
                        trainingModeUnitData.TryGetValue(currenWavetUnitID, out unit);

                        if (unit != null && currenWavetUnitID != -1)
                        {
                            unit = UnitLevelPropertyRatio(unit, currentWave);
                            id   = CreateSoldiers(currenWavetUnitID, unit);

                            DebugUtils.Assert(id != 0, "Training Mode: Soldier ID is 0!");

                            aiSoldierIDList.Add(id);
                        }
                        else
                        {
                            DebugUtils.LogError(DebugUtils.Type.Training, "Can not find this ID : " + currenWavetUnitID + "unit in TrainingModeUnitData");
                        }

                        int pathMask = NavMeshAreaType.WALKABLE;//walkable

                        if (rangeInt >= currentWave.Deploy_Lane)
                        {
                            pathMask = NavMeshAreaType.BOTTOMPATH;//BottomPath
                        }

                        DebugUtils.Log(DebugUtils.Type.Training, "rangeInt is " + rangeInt + "pathMask is " + pathMask);

                        ConscriptSoldier conscriptSoldier = null;

                        for (int j = 0; j < conscriptSoldierCache.Count; j++)
                        {
                            if (conscriptSoldierCache[j].isExpired)
                            {
                                conscriptSoldier = conscriptSoldierCache[j];
                                conscriptSoldier.Reset();
                                conscriptSoldier.soldierID = id;
                                conscriptSoldier.navArea   = pathMask;
                                break;
                            }
                        }

                        if (conscriptSoldier == null)
                        {
                            conscriptSoldier = new ConscriptSoldier();

                            conscriptSoldier.soldierID       = id;
                            conscriptSoldier.navArea         = pathMask;
                            conscriptSoldier.readyFightTimer = 0f;

                            conscriptSoldierCache.Add(conscriptSoldier);
                        }
                    }
                }

                // For the PVE statistics
                datamanager.AddPveWaveNumber();

                currentWaveId        = currentWave.NextWave;
                currentWaveDelayTime = currentWave.NextDelay;
                currentWaveQuantity  = currentWave.NextQuantity;

                if (currentWave.WaitForComplete == true)
                {
                    isWaitingForComplete = true;
                }

                trainingModeTimer = 0;
            }
            else
            {
                DebugUtils.Log(DebugUtils.Type.Training, "TrainingModeTiming... Not need to do anything");
            }
        }