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); }
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); }