public List <WarGearCombination> GetAllowedCombinations() { //On recupere complètement les données nécessaires Member membre = KTContext.Db.Members.Where(m => m.Id == Id) .Include(m => m.ModelProfile.WarGearOptions) .Include(m => m.ModelProfile.Model.WarGearOptions) .Include(m => m.ModelProfile.Model.ModelWeapons) .ThenInclude(sn => sn.Weapon) .First(); List <WarGearCombination> configs = new List <WarGearCombination>(); List <Weapon> ArmesBase = membre.GetDefaultWeapons(); //Configuration de base WarGearCombination config = new WarGearCombination() { Weapons = ArmesBase }; configs.Add(config); foreach (WarGearOption remplacement in membre.ModelProfile.GetAllWarGearOptions()) { List <WarGearCombination> configInit = new List <WarGearCombination>(); WarGearCombination oldconf = new WarGearCombination(); oldconf.Weapons.AddRange(ArmesBase); configInit.Add(oldconf); configs.AddRange(new ReplaceNode().Evaluate(configInit, remplacement.Operation)); } return(configs); }
public WarGearCombination Copy() { WarGearCombination conf = new WarGearCombination(); conf.Weapons.AddRange(Weapons); CostOverrides.AddRange(CostOverrides); return(conf); }
public static PossibleSwap Create(String membreId) { PossibleSwap cp = new PossibleSwap(); //On recupere complètement les données nécessaires cp.Member = KTContext.Db.Members.Where(m => m.Id == membreId) .Include(m => m.Team) .Include(m => m.MemberWarGearOptions) .Include(m => m.MemberWeapons) .Include(m => m.ModelProfile.CostOverrides) .Include(m => m.ModelProfile.WarGearOptions) .Include(m => m.ModelProfile.Model.WarGearOptions) .Include(m => m.ModelProfile.Model.ModelWeapons) .ThenInclude(sn => sn.Weapon) .Include(m => m.ModelProfile.ModelProfileWeapons) .ThenInclude(sn => sn.Weapon) .AsNoTracking() .First(); List <CostOverride> costOverrides = cp.Member.ModelProfile.CostOverrides.ToList(); List <Weapon> baseWeapon = cp.Member.GetDefaultWeapons(); //Configuration de base WarGearCombination combination = new WarGearCombination() { Weapons = baseWeapon }; cp.WarGearCombinations.Add(combination); //On passe toutes les modifs sans exclusions ICollection <WarGearOption> remplPossibles = cp.Member.ModelProfile.GetAllWarGearOptions(); foreach (WarGearOption remplacement in remplPossibles.Where(r => String.IsNullOrWhiteSpace(r.Exclusion))) { //Remplacement limité en nombre if (remplacement.MaximumPerTeam > 0 && !cp.Member.Team.Roster) { int nbUsed = KTContext.Db.MemberWarGearOptions.Count(mr => mr.Member.TeamId == cp.Member.TeamId && mr.MemberId != cp.Member.Id && mr.WarGearOptionId == remplacement.Id); if (nbUsed >= remplacement.MaximumPerTeam) { continue; } } if (remplacement.IsOption()) { List <WarGearCombination> lc = new List <WarGearCombination>(); lc.Add(new WarGearCombination()); Weapon arme = new ReplaceNode().Evaluate(lc, remplacement.Operation).First().Weapons.First(); WarGearCombination cf = new WarGearCombination(); cf.CostOverrides = costOverrides; cf.Weapons.Add(arme); cf.WarGearOption.Add(remplacement); cf.Selected = cp.Member.MemberWarGearOptions.Any(mr => mr.WarGearOptionId == remplacement.Id); cp.OptionalWeapons.Add(cf); } else { List <WarGearCombination> confs = new ReplaceNode().Evaluate(cp.WarGearCombinations, remplacement.Operation); confs.ForEach(c => c.Weapons = c.Weapons.Where(a => a != null).ToList()); AddRemplacement(confs, remplacement); cp.WarGearCombinations.AddRange(confs); } } //On copie les configurations simples List <WarGearCombination> confSimples = new List <WarGearCombination>(); confSimples.AddRange(cp.WarGearCombinations); //puis on passe tous ceux avec exclusion l'un après l'autre foreach (WarGearOption remplacement in remplPossibles.Where(r => !String.IsNullOrWhiteSpace(r.Exclusion))) { //Remplacement limité en nombre if (remplacement.MaximumPerTeam > 0 && !cp.Member.Team.Roster) { int nbUsed = KTContext.Db.MemberWarGearOptions.Count(mr => mr.Member.TeamId == cp.Member.TeamId && mr.MemberId != cp.Member.Id && mr.WarGearOptionId == remplacement.Id); if (nbUsed >= remplacement.MaximumPerTeam) { continue; } } List <WarGearCombination> confs = new ReplaceNode().Evaluate(confSimples, remplacement.Operation); AddRemplacement(confs, remplacement); cp.WarGearCombinations.AddRange(confs); } cp.ExtractArmesCommunes(); //Marque les remplacements utilisés précédement foreach (WarGearCombination configuration in cp.WarGearCombinations) { //C'est la bonne configuration si toutes les armes et tous les remplacements sont présents configuration.Selected = true; foreach (WarGearOption remplacement in configuration.WarGearOption) { configuration.Selected = configuration.Selected && cp.Member.MemberWarGearOptions.Any(mr => mr.WarGearOptionId == remplacement.Id); configuration.CostOverrides = costOverrides; } foreach (Weapon arme in configuration.Weapons) { configuration.Selected = configuration.Selected && cp.Member.MemberWeapons.Any(mr => mr.WeaponId == arme.Id); configuration.CostOverrides = costOverrides; } } List <WarGearCombination> configurations = new List <WarGearCombination>(); configurations.AddRange(cp.WarGearCombinations); foreach (WarGearCombination configuration in configurations) { var configs = cp.WarGearCombinations.Where(c => c.Weapons.Select(a => a.Id).OrderBy(id => id).SequenceEqual(configuration.Weapons.Select(a => a.Id).OrderBy(id => id))).Skip(1).ToList(); foreach (WarGearCombination c in configs) { cp.WarGearCombinations.Remove(c); } } var configSelected = cp.WarGearCombinations.Where(c => c.Selected); if (configSelected.Count() > 1 && configSelected.SelectMany(c => c.Weapons).Select(a => a.Id).Distinct().Count() == 1) { configSelected.OrderByDescending(c => c.Weapons.Count()).Skip(1).ForEach(c => c.Selected = false); } if (configSelected.Count() > 1) { configSelected.Where(c => c.Weapons.Count != c.Weapons.Select(a => a.Id).Distinct().Count()).ForEach(c => c.Selected = false); configSelected.OrderByDescending(c => c.Weapons.Count).Skip(1).ForEach(c => c.Selected = false); } return(cp); }