Exemple #1
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            foreach (var unit in state.Level.PlayerUnits)
            {
                state.AddUnit(unit);
                if (!config.IsFeatureEnabled(Features.AutoHeal))
                {
                    continue;
                }
                var unitConfig = config.Units[unit.Descriptor];
                if (unit.Health < unitConfig.MaxHealth[unit.Level])
                {
                    buffer.Add(new HealUnitCommand(unit.Id));
                }
            }

            var levelDesc   = state.Level.Descriptor;
            var playerUnits = state.Level.PlayerUnits;

            state.Level = null;

            if (!Win)
            {
                return;
            }

            foreach (var unit in playerUnits)
            {
                if (unit.Level >= config.UnitLevels.Length)
                {
                    continue;
                }
                var expAccum = 0;
                foreach (var enemyDesc in config.Levels[levelDesc].EnemyDescriptors)
                {
                    var enemyConfig = config.Units[enemyDesc];
                    expAccum += enemyConfig.Experience;
                }
                if (expAccum > 0)
                {
                    buffer.Add(new AddExperienceCommand(unit.Id, expAccum));
                }
            }

            var scope = LevelUtils.GetScope(levelDesc);

            state.Progress[scope] = Math.Min(state.Progress.GetOrDefault(scope) + 1, LevelUtils.GetIndex(levelDesc) + 1);

            var rewardLevel = config.Levels[levelDesc].RewardLevel;

            RewardLogic.AppendReward(rewardLevel, state, config, buffer);
        }
Exemple #2
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer _)
        {
            var playerUnits = FindPlayerUnits(state);
            var enemyUnits  = CreateEnemyUnits(state, config);

            state.Level            = new LevelState(LevelDesc, playerUnits, enemyUnits);
            state.Level.PlayerTurn = true;

            foreach (var unitId in PlayerUnits)
            {
                state.Units.Remove(unitId);
            }
            if (FarmLogic.IsFarmigLevel(LevelDesc, config))
            {
                var scope = LevelUtils.GetScope(LevelDesc);
                state.Farming[scope] = state.Time.GetRealTime();
            }
        }
Exemple #3
0
        public bool IsValid(GameState state, ConfigRoot config)
        {
            if (string.IsNullOrEmpty(LevelDesc))
            {
                return(false);
            }
            if (!config.Levels.ContainsKey(LevelDesc))
            {
                return(false);
            }
            var scope           = LevelUtils.GetScope(LevelDesc);
            var currentProgress = state.Progress.GetOrDefault(scope);

            if (currentProgress < LevelUtils.GetIndex(LevelDesc))
            {
                return(false);
            }
            if ((PlayerUnits == null) || (PlayerUnits.Count == 0) || (PlayerUnits.Count > 4))
            {
                return(false);
            }
            var playerUnits = FindPlayerUnits(state);

            if (playerUnits == null)
            {
                return(false);
            }
            foreach (var unit in playerUnits)
            {
                if (unit.Health <= 0)
                {
                    return(false);
                }
            }
            if (FarmLogic.IsFarmigLevel(LevelDesc, config))
            {
                if (!FarmLogic.IsAvailable(scope, state, config))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        public static bool IsFarmigLevel(string desc, ConfigRoot config)
        {
            var scope = LevelUtils.GetScope(desc);

            return(config.Farming.ContainsKey(scope));
        }