private Advantage GetNewAdvantage(List <Advantage> a) { Array enumValues = Enum.GetValues(typeof(AdvantageCategory)); AdvantageCategory advantageCategory = (AdvantageCategory)Enum.Parse(typeof(AdvantageCategory), rand.Next(enumValues.Length).ToString()); try { List <Advantage> advantageList = advantages.GetAdvantages(advantageCategory); Advantage newAdvantage = advantageList[rand.Next(0, advantageList.Count)]; int count = 0; while (a.Contains(newAdvantage)) { newAdvantage = advantageList[rand.Next(0, advantageList.Count)]; count++; if (count == (advantages.Size * 10)) { throw new NullReferenceException(); } } return(newAdvantage); } catch (KeyNotFoundException) { throw new KeyNotFoundException(); } }
public override bool Equals(object obj) { if (!(obj is Advantage)) { return(false); } Advantage other = (Advantage)obj; return(Name.Equals(other.Name) && Points == other.Points); }
public void AddAdvantage(AdvantageCategory aC, Advantage advantage) { try { advantageDict[aC].Add(advantage); } catch (KeyNotFoundException) { Console.WriteLine("Key not found"); } }
private void AddAdvantages(bool exotic, bool supernatural) { if (npc != null) { int points = pointDistribution.AdvantagePoints; int failCount = 0; List <Advantage> a = new List <Advantage>(); while (points > 0) { try { Advantage newAdvantage = GetNewAdvantage(a); if ((newAdvantage.Type.Equals(AdvantageType.Exotic) && !exotic) || (newAdvantage.Type.Equals(AdvantageType.Supernatural) && !supernatural)) { continue; } if ((points - newAdvantage.Points) > 0) { failCount = 0; points -= newAdvantage.Points; npc.AddAdvantage(newAdvantage); a.Add(newAdvantage); } else { failCount++; if (failCount == 3) { break; } } } catch (KeyNotFoundException) { } catch (NullReferenceException) { break; } } } }
public void AddAdvantage(Advantage a) { Points += a.Points; advantages.Add(a); }