private async Task <bool> LoadWeaponsInternal() { var fullFilenames = new List <string>(); foreach (string filename in weaponFilenames) { string fullFilename = Path.Combine(AppContext.BaseDirectory, "data", $"{filename}.json"); if (File.Exists(fullFilename) == false) { IsFeatureEnabled = false; FeatureDisabledReason = $"Weapons data unavailable ('{filename}' missing)"; return(false); } fullFilenames.Add(fullFilename); } IList <WeaponPrimitive> allWeaponPrimitives = await LoadPrimitives(fullFilenames); allWeapons = allWeaponPrimitives .Select(x => new WeaponViewModel(x)) .ToDictionary(x => x.Id, x => x); bool hasRoots = false; foreach (WeaponPrimitive primitive in allWeaponPrimitives) { WeaponViewModel weapon = allWeapons[primitive.Id]; WeaponViewModel previous = null; if (primitive.Crafting.Previous.HasValue) { previous = allWeapons[primitive.Crafting.Previous.Value]; } if (previous == null) { hasRoots = true; } weapon.Update(previous, primitive.Crafting.Branches.Select(id => allWeapons[id]).ToList()); } if (hasRoots == false) { IsFeatureEnabled = false; FeatureDisabledReason = "No weapons available"; } WeaponTypes = allWeaponPrimitives .Where(x => x.Crafting.Previous == null) .Select(x => allWeapons[x.Id]) .GroupBy(x => x.Type) .Select(x => new WeaponTypeViewModel(x.Key, x.ToList(), this)) .ToList(); return(true); }
internal void AddChild(WeaponViewModel child) { if (child == null) { throw new ArgumentNullException(nameof(child)); } if (Branches == null) { Branches = new List <WeaponViewModel>(); } Branches.Add(child); }
internal void Update(WeaponViewModel previous, IList <WeaponViewModel> children) { Previous = previous; if (Previous != null) { HasParent = true; if (Previous.Branches == null) { // TODO: file data issue to mhw-db.com Previous.Branches = new WeaponViewModel[] { this }; } } if (children != null && children.Count > 0) { Branches = children; HasChildren = true; } }
private bool IsWeaponMatchingSlots(WeaponViewModel weapon, IList <int> inputSlots) { if (weapon.Slots.Count < inputSlots.Count) { return(false); } IList <int> sortedSlots = weapon.Slots.OrderByDescending(x => x).ToList(); int count = inputSlots.Count; for (int i = 0; i < count; i++) { if (sortedSlots[i] < inputSlots[i]) { return(false); } } return(true); }
internal void SetParent(WeaponViewModel parent) { Previous = parent; parent.AddChild(this); }