public HeroData Suggest() { // What type of class do we need? List <PowerSource> power_sources = RequiredPowerSources; List <PrimaryAbility> abilities = RequiredAbilities; List <HeroRoleType> roles = RequiredRoles; // Make up a class candidate list List <ClassData> class_candidates = Sourcebook.Filter(power_sources, abilities, roles); if (class_candidates.Count == 0) { // Try without the ability score restriction class_candidates = Sourcebook.Filter(power_sources, new List <PrimaryAbility>(), roles); if (class_candidates.Count == 0) { return(null); } } // Remove classes we already have List <ClassData> obsolete_classes = new List <ClassData>(); foreach (ClassData cd in class_candidates) { if (Contains(cd)) { obsolete_classes.Add(cd); } } if (obsolete_classes.Count != class_candidates.Count) { foreach (ClassData cd in obsolete_classes) { class_candidates.Remove(cd); } } // Select a class candidate int class_index = Session.Random.Next() % class_candidates.Count; ClassData selected_class = class_candidates[class_index]; // Make up a race candidate list List <RaceData> race_candidates = Sourcebook.Filter(selected_class.KeyAbility); if (race_candidates.Count == 0) { return(null); } // Remove races we already have List <RaceData> obsolete_races = new List <RaceData>(); foreach (RaceData rd in race_candidates) { if (Contains(rd)) { obsolete_races.Add(rd); } } if (obsolete_races.Count != race_candidates.Count) { foreach (RaceData rd in obsolete_races) { race_candidates.Remove(rd); } } // Select a race candidate int race_index = Session.Random.Next() % race_candidates.Count; RaceData selected_race = race_candidates[race_index]; return(new HeroData(selected_race, selected_class)); }
public HeroData Suggest() { List <PowerSource> requiredPowerSources = this.RequiredPowerSources; List <PrimaryAbility> requiredAbilities = this.RequiredAbilities; List <HeroRoleType> requiredRoles = this.RequiredRoles; List <ClassData> classDatas = Sourcebook.Filter(requiredPowerSources, requiredAbilities, requiredRoles); if (classDatas.Count == 0) { classDatas = Sourcebook.Filter(requiredPowerSources, new List <PrimaryAbility>(), requiredRoles); if (classDatas.Count == 0) { return(null); } } List <ClassData> classDatas1 = new List <ClassData>(); foreach (ClassData classDatum in classDatas) { if (!this.Contains(classDatum)) { continue; } classDatas1.Add(classDatum); } if (classDatas1.Count != classDatas.Count) { foreach (ClassData classData in classDatas1) { classDatas.Remove(classData); } } int num = Session.Random.Next() % classDatas.Count; ClassData item = classDatas[num]; List <RaceData> raceDatas = Sourcebook.Filter(item.KeyAbility); if (raceDatas.Count == 0) { return(null); } List <RaceData> raceDatas1 = new List <RaceData>(); foreach (RaceData raceDatum in raceDatas) { if (!this.Contains(raceDatum)) { continue; } raceDatas1.Add(raceDatum); } if (raceDatas1.Count != raceDatas.Count) { foreach (RaceData raceData in raceDatas1) { raceDatas.Remove(raceData); } } int num1 = Session.Random.Next() % raceDatas.Count; return(new HeroData(raceDatas[num1], item)); }