示例#1
0
 public void ReadXml(XmlReader reader)
 {
     if (reader.IsEmptyElement) return;
     reader.ReadStartElement("CommandCollection");
     reader.ReadStartElement("Commands");
     while(reader.NodeType != XmlNodeType.EndElement)
     {
         var c = new Command();
         switch(reader.Name)
         {
             case "AttackCommand":
                 _mutableSerializer = new XmlSerializer(typeof(AttackCommand));
                 c = (AttackCommand)_mutableSerializer.Deserialize(reader);
                 Commands.Add(c);
                 break;
             case "TimedCommand":
                 _mutableSerializer = new XmlSerializer(typeof(TimedCommand));
                 c = (TimedCommand)_mutableSerializer.Deserialize(reader);
                 Commands.Add(c);
                 break;
         }
     }
     reader.ReadEndElement();
     reader.ReadEndElement();
 }
示例#2
0
 //MoveCommand MoveA;
 public PlayerInputComponent()
 {
     if (CommandCollection == null || CommandCollection.Commands.Count < 1)
     {
         CommandCollection = new CommandCollection();
         CommandA = new Command("nullCommand");
         CommandB = new Command("nullCommand");
         CommandC = new Command("nullCommand");
         CommandD = new Command("nullCommand");
     }
     else
     {
         for(var i = 0; i < 4; i++)
         {
             switch(i)
             {
                 case 0:
                     CommandA = CommandCollection.Commands[i];
                     break;
                 case 1:
                     CommandB = CommandCollection.Commands[i];
                     break;
                 case 2:
                     CommandC = CommandCollection.Commands[i];
                     break;
                 case 3:
                     CommandD = CommandCollection.Commands[i];
                     break;
                 default:
                     if (CommandA == null) CommandA = new Command("nullCommand");
                     if (CommandB == null) CommandB = new Command("nullCommand");
                     if (CommandC == null) CommandC = new Command("nullCommand");
                     if (CommandD == null) CommandD = new Command("nullCommand");
                     break;
             }
         }
     }
 }
示例#3
0
 public void AddCommand(Command c)
 {
     CommandCollection.Commands.Add(c);
     Console.WriteLine("New Command {0} Added.", c.ToString());
 }
示例#4
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;
 }