private void AddCombatant(DD4ECombatant combatant)
 {
     if (Combatants.Any(c => c.Name.Equals(combatant.Name) && c.IsPlayer == false))
     {
         int id = Combatants.Count(c => c.Name.Equals(combatant.Name) && c.IsPlayer == false);
         combatant.ID = id;
     }
     else
     {
         if (Combatants.Any(c => c.Name.Equals(combatant.Name)))
         {
             MessageBox.Show("You cannot add the same player character twice.", "Warning");
             return;
         }
     }
     Combatants.Add(combatant);
 }
Esempio n. 2
0
        private void Add()
        {
            int initiative;

            if (!int.TryParse(Initiative, out initiative))
            {
                throw new Exception($"{Initiative} is not a valid value.");
            }

            bool initiativeTied = Combatants.Any(c => c.Initiative == initiative);
            var  newCombatant   = new Combatant(Name, initiative, Combatants.Count == 0);

            Combatants.Add(newCombatant);
            if (initiativeTied && InitiativeTied != null)
            {
                newCombatant.TieBreaker = Combatants.Max(c => c.TieBreaker) + 1;
                InitiativeTied?.Invoke(this, new TieInitiativeEventArgs(Combatants.Where(c => c.Initiative == initiative)));
            }
            Combatants.Sort();
            Name       = null;
            Initiative = null;
        }