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 void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { foreach (var cmd in Childs) { buffer.Add(cmd); } }
public static void AppendReward(string rewardLevel, GameState state, ConfigRoot config, ICommandBuffer buffer) { var reward = RewardLogic.GenerateReward(rewardLevel, config, state.CreateRandom()); foreach (var pair in reward.Resources) { buffer.Add(new AddResourceCommand(pair.Key, pair.Value)); } foreach (var itemDesc in reward.Items) { buffer.Add(new AddItemCommand(state.NewEntityId(), itemDesc)); } foreach (var unitDesc in reward.Units) { buffer.Add(new AddUnitCommand(state.NewEntityId(), unitDesc)); } buffer.Add(new UpdateRandomSeedCommand()); }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { var unit = state.Units[UnitId]; unit.Experience += Amount; if (unit.Experience >= config.UnitLevels[unit.Level]) { buffer.Add(new LevelUpCommand(UnitId)); } }
public static void AddCommands(GameState state, ConfigRoot config, ICommandBuffer buffer) { var level = state.Level; var damages = new Dictionary <ulong, int>(); foreach (var enemy in level.EnemyUnits) { var enemyId = enemy.Id; if (!TrySelectPlayerToAttack(level.PlayerUnits, damages, out var playerUnit)) { break; } var playerId = playerUnit.Id; var attackCommand = new AttackCommand(enemyId, playerId); buffer.Add(attackCommand); var damage = DamageLogic.GetDamage(state, config, enemyId, playerId); damages[playerId] = damages.GetOrDefault(playerId) + damage; } buffer.Add(new EndEnemyTurnCommand()); }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { state.Level.MovedUnits.Add(DealerId); var damage = DamageLogic.GetDamage(state, config, DealerId, TargetId); var target = state.Level.FindUnitById(TargetId); target.Health -= damage; if (target.Health <= 0) { buffer.Add(new KillUnitCommand(target.Id)); } }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { var unit = state.Units[UnitId]; var oldLevel = unit.Level; unit.Level++; unit.Experience -= config.UnitLevels[oldLevel]; var isLastLevel = (unit.Level == config.UnitLevels.Length); if (isLastLevel) { unit.Experience = 0; } buffer.Add(new HealUnitCommand(UnitId)); if (!isLastLevel && (unit.Experience >= config.UnitLevels[unit.Level])) { buffer.Add(new LevelUpCommand(UnitId)); } }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { var item = state.Items[Id]; var upgradePrices = GetUpgradePrices(config, item.Descriptor)[item.Level]; foreach (var pair in upgradePrices) { var res = pair.Key; var price = pair.Value; buffer.Add(new SpendResourceCommand(res, price)); } item.Level++; }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { var level = state.Level; if (TryKill(level.PlayerUnits, out var player)) { if (config.IsFeatureEnabled(Features.AutoHeal)) { buffer.Add(new HealUnitCommand(player.Id)); } state.Units.Add(UnitId, player); if (level.PlayerUnits.Count == 0) { buffer.Add(new FinishLevelCommand(false)); } } TryKill(level.EnemyUnits, out _); if (level.EnemyUnits.Count == 0) { buffer.Add(new FinishLevelCommand(true)); } }
public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer) { buffer.Add(new AddResourceCommand(Resource.Coins, 50)); buffer.Add(new AddUnitCommand(state.NewEntityId(), "weak_unit")); }