Пример #1
0
 public void Update()
 {
     if (_tickingCommands.Count > 0)
     {
         if (_time % 3 == 0)
         {
             foreach (var t in _tickingCommands)
             {
                 if (t.Ticks == t.MaxTicks) break;
                 var target = _combatants.Single(c => c.Name == t.TargetName);
                 var user = _combatants.Single(c => c.Name == t.UserName);
                 t.Execute(user, target);
                 t.Ticks++;
             }
         }
     }
     foreach (var c in _combatants)
     {
         var vit = c.Components.Where(cm => cm is StatComponent).Cast<StatComponent>().Single(s => s.Name == StatName.Life);
         if (vit.CurrentValue <= 0)
             c.Alive = false;
         if (!c.Alive) break;
         var t = c.Components.Where(cm => cm is ActionTimerComponent).Cast<ActionTimerComponent>().Single();
         var lvl = c.Components.Where(cm => cm is LevelComponent).Cast<LevelComponent>().Single();
         var haste = c.Components.Where(cm => cm is StatComponent).Cast<StatComponent>().Single(s => s.Name == StatName.Haste);
         t.AddToMeter(2.00f + ((haste.CurrentValue / 75) - (lvl.LevelValue / 40)));
         if (t.Current == 100.00f)
         {
             if (c.Tags.Contains(TypeTag.Player))
             {
                 var input = c.Components.Where(cmp => cmp is PlayerInputComponent).Cast<PlayerInputComponent>().Single();
                 var command = new Command();
                 var target = new GameEntity();
                 bool can = false;
                 while (!can)
                 {
                     command = input.HandleInput();
                     target = ChooseTarget();
                     var cost = c.Components.Where(s => s is StatComponent)
                                            .Cast<StatComponent>()
                                            .Single(s => s.Name == command._costStat);
                     if (!(command._cost > cost.CurrentValue)) can = true;
                     if (!can) Console.WriteLine("Not enough {0}.", cost.Name);
                 }
                 if (command is TimedCommand)
                 {
                     var ticker = command as TimedCommand;
                     ticker.Ticks = 0;
                     ticker.UserName = c.Name;
                     ticker.TargetName = target.Name;
                     _tickingCommands.Add(ticker);
                 }
                 command.Execute(c, target);
             }
             if(c.Tags.Contains(TypeTag.Monster))
             {
                 var input = c.Components.Where(cmp => cmp is AIInputComponent).Cast<AIInputComponent>().Single();
                 var command = new Command();
                 var target = new GameEntity();
                 bool can = false;
                 while (!can)
                 {
                     command = input.HandleInput();
                     target = _players().First();
                     var cost = c.Components.Where(s => s is StatComponent)
                                            .Cast<StatComponent>()
                                            .Single(s => s.Name == command._costStat);
                     if (!(command._cost > cost.CurrentValue)) can = true;
                     if (!can)
                     {
                         Console.WriteLine("Not enough {0}.", cost.Name);
                         break;
                     }
                 }
                 if (command is TimedCommand)
                 {
                     var ticker = command as TimedCommand;
                     ticker.Ticks = 0;
                     ticker.UserName = c.Name;
                     ticker.TargetName = target.Name;
                     _tickingCommands.Add(ticker);
                 }
                 command.Execute(c, target);
             }
             t.Current = 0;
         }
     }
     if(_stats(_monsters()).Where(s => s.Name == StatName.Life && s.CurrentValue <= 0).Count() > 0)
     {
         PlayerVictory();
     }
     if (_stats(_players()).Where(s => s.Name == StatName.Life && s.CurrentValue <= 0).Count() > 0)
     {
         MonsterVictory();
     }
     _time += 1;
 }