public BuildDefinitionManager(FakeDAL dal, GameBuild game, Build build) { this.dal = dal; this.build = build; var blp = dal.Get <BuildLevelParameter>().Where(x => x.Build.id == build.id); buildParams = dal.Get <BuildParameter>() .ToList() .Where(x => x.Game.id == build.Game.id) .SelectMany(x => Enumerable.Range(1, game.MaxLevel).Select(i => { // get or create the levelparameter var b = blp.FirstOrDefault(l => l.Parameter.id == x.id && l.Level == i); if (b == null) { b = new BuildLevelParameter { Game = build.Game, Build = build, Parameter = x, Amount = x.Type.Minimum, Level = i }; } return(b); })) .ToList(); foreach (var b in buildParams) { dal.Save(b); } }
public Action ChangeRequest(BuildLevelParameter param, int amount) { // breaking type level max limit? var newVal = param.Amount + amount; var lRule = dal.Get <BuildParameterTypeLevelPoints>() .Where(x => x.Type.id == param.Parameter.Type.id) .Where(x => x.Level == param.Level) .Single(); if (newVal > lRule.Limit) { return(null); } var prevLevelVal = GetPreviousLevel(param).Amount; if (newVal < prevLevelVal && amount < 0) { return(null); // neither would that really. } // check level restrictions var ldep = dal.Get <BuildParameterRequiement>() .Where(x => x.Depend.id == param.Parameter.id) .Where(x => x.On == null) .ToArray(); // Cant be picked/pushed that far at this level, ever. if (ldep.Where(x => newVal >= x.DAmount) .Where(x => param.Level < x.OAmount) .Any()) { return(null); } // ok you could... return(() => { param.Amount += amount; dal.Save(param); ParameterChanged(param.Level); }); }