/// <summary>
        /// Called when the game is over
        /// </summary>
        private void OnGameOver(bool didWin, float efficiency)
        {
            var currentLevel   = LevelManager.CurrentInstance.CurrentLevel;
            var completedLevel = new MapNodeSaveData(currentLevel.SaveData);
            var finalScore     = this._scoreData.Last();

            completedLevel.IsBeat     = didWin;
            completedLevel.HighScore  = finalScore;
            completedLevel.Efficiency = efficiency;

            completedLevel.GeneratingResources = new List <MapNodeResource>(currentLevel.ResourceReward);

            if (efficiency > 0)
            {
                foreach (var resource in completedLevel.GeneratingResources)
                {
                    resource.ProduceAmount *= efficiency;
                    resource.CapacityBoost *= efficiency;
                }
            }

            this._isGameOver = true;
            SaveManager.CurrentInstance.OnLevelComplete(completedLevel, this.TimeSinceFightStart);
            this.GameOverScreenObject.gameObject.SetActive(true);
            var enemyPassPenalty = (this.TotalCoreHealth - this._coreHealthData.Last()) * GeneralSettings.EnemySurvivalPenaltyMultiplier;

            this.GameOverScreenObject.OnGameOver(didWin, enemyPassPenalty, this._incomeData, this._costData, this._coreHealthData);
            this.SetBuildPhase();
        }
Exemple #2
0
        /// <summary>
        /// Called when the level was completed
        /// </summary>
        /// <param name="data">The target level that was completed</param>
        /// <param name="defenseTime">How long the defense lasted</param>
        public void OnLevelComplete(MapNodeSaveData data, float defenseTime)
        {
            var existingData = this.GetLevelData(data.LevelId);

            data.HighScore = Math.Max(data.HighScore, existingData.HighScore);
            data.IsBeat    = existingData.IsBeat || data.IsBeat;
            this.CurrentSaveFile.NodeProgress[data.LevelId] = data;
            this.AddIncome(defenseTime);
        }
Exemple #3
0
        /// <summary>
        /// Save the state into a file
        /// </summary>
        /// <param name="mapNodeId">Id of the level</param>
        /// <param name="state">Target state to save</param>
        public void SaveMapGridState(int mapNodeId, MapGridState state)
        {
            var targetLevel = this.CurrentSaveFile.NodeProgress.Find(level => level.LevelId == mapNodeId);

            if (targetLevel != null)
            {
                targetLevel.SavedState = state;
            }
            else
            {
                var newLevelData = new MapNodeSaveData();
                newLevelData.LevelId    = mapNodeId;
                newLevelData.SavedState = state;
                this.CurrentSaveFile.NodeProgress.Add(newLevelData);
            }

            this.Save();
        }