public ItemBalanceDefinition Merge(ItemTypeDefinition itemType) { var balances = new List<ItemBalanceDefinition>(); var current = this; do { balances.Insert(0, current); current = current.Base; } while (current != null); var merged = new ItemBalanceDefinition() { ResourcePath = this.ResourcePath, Parts = new ItemBalancePartCollection() { Mode = PartReplacementMode.Complete, AlphaParts = itemType.AlphaParts.ToList(), BetaParts = itemType.BetaParts.ToList(), GammaParts = itemType.GammaParts.ToList(), DeltaParts = itemType.DeltaParts.ToList(), EpsilonParts = itemType.EpsilonParts.ToList(), ZetaParts = itemType.ZetaParts.ToList(), EtaParts = itemType.EtaParts.ToList(), ThetaParts = itemType.ThetaParts.ToList(), MaterialParts = itemType.MaterialParts.ToList(), }, }; foreach (var balance in balances) { if (balance.Type != null) { merged.Type = balance.Type; } if (balance.Types != null) { merged.Types = balance.Types.ToList(); } if (balance.Manufacturers != null) { merged.Manufacturers = balance.Manufacturers.ToList(); } if (balance.Parts == null) { continue; } if (balance.Parts.Type != null) { merged.Parts.Type = balance.Parts.Type; } MergePartList(merged.Parts.AlphaParts, balance.Parts.Mode, balance.Parts.AlphaParts); MergePartList(merged.Parts.BetaParts, balance.Parts.Mode, balance.Parts.BetaParts); MergePartList(merged.Parts.GammaParts, balance.Parts.Mode, balance.Parts.GammaParts); MergePartList(merged.Parts.DeltaParts, balance.Parts.Mode, balance.Parts.DeltaParts); MergePartList(merged.Parts.EpsilonParts, balance.Parts.Mode, balance.Parts.EpsilonParts); MergePartList(merged.Parts.ZetaParts, balance.Parts.Mode, balance.Parts.ZetaParts); MergePartList(merged.Parts.EtaParts, balance.Parts.Mode, balance.Parts.EtaParts); MergePartList(merged.Parts.ThetaParts, balance.Parts.Mode, balance.Parts.ThetaParts); MergePartList(merged.Parts.MaterialParts, balance.Parts.Mode, balance.Parts.MaterialParts); } if (merged.Type != itemType && merged.Types.Contains(itemType) == false) { throw new KeyNotFoundException("item type '" + itemType.ResourcePath + "' not valid for '" + this.ResourcePath + "'"); } return merged; }
public ItemBalanceDefinition Create(ItemDefinition item) { var balances = this.GetBalances(); ItemDefinition balanceItem = null; foreach (var balance in balances) { if (balance.Item != null) { balanceItem = balance.Item; } } var wantBalanceParts = item.Type == ItemType.ClassMod || item.Type == ItemType.CrossDLCClassMod || item == balanceItem; List <string> getList(IEnumerable <string> enumerable) { return(enumerable == null ? new List <string>() : enumerable.ToList()); } var result = new ItemBalanceDefinition() { ResourcePath = this.ResourcePath, Item = balanceItem, Parts = new ItemBalancePartCollection() { Mode = PartReplacementMode.Complete, AlphaParts = getList(item.AlphaParts), BetaParts = getList(item.BetaParts), GammaParts = getList(item.GammaParts), DeltaParts = getList(item.DeltaParts), EpsilonParts = getList(item.EpsilonParts), ZetaParts = getList(item.ZetaParts), EtaParts = getList(item.EtaParts), ThetaParts = getList(item.ThetaParts), MaterialParts = getList(item.MaterialParts), }, }; if (wantBalanceParts == true) { foreach (var balance in balances) { if (balance.Items != null) { result.Items = balance.Items.ToList(); } if (balance.Manufacturers != null) { result.Manufacturers = balance.Manufacturers.ToList(); } if (balance.Parts == null) { continue; } if (balance.Parts.Item != null) { result.Parts.Item = balance.Parts.Item; } AddPartList(balance.Parts.AlphaParts, balance.Parts.Mode, result.Parts.AlphaParts); AddPartList(balance.Parts.BetaParts, balance.Parts.Mode, result.Parts.BetaParts); AddPartList(balance.Parts.GammaParts, balance.Parts.Mode, result.Parts.GammaParts); AddPartList(balance.Parts.DeltaParts, balance.Parts.Mode, result.Parts.DeltaParts); AddPartList(balance.Parts.EpsilonParts, balance.Parts.Mode, result.Parts.EpsilonParts); AddPartList(balance.Parts.ZetaParts, balance.Parts.Mode, result.Parts.ZetaParts); AddPartList(balance.Parts.EtaParts, balance.Parts.Mode, result.Parts.EtaParts); AddPartList(balance.Parts.ThetaParts, balance.Parts.Mode, result.Parts.ThetaParts); AddPartList(balance.Parts.MaterialParts, balance.Parts.Mode, result.Parts.MaterialParts); } } if (result.Item != item && result.Items.Contains(item) == false) { throw new ResourceNotFoundException($"item type '{item.ResourcePath}' is not valid for '{this.ResourcePath}'"); } return(result); }
public ItemBalanceDefinition Create(ItemTypeDefinition type) { var result = new ItemBalanceDefinition() { ResourcePath = this.ResourcePath, Parts = new ItemBalancePartCollection() { Mode = PartReplacementMode.Complete, AlphaParts = type.AlphaParts.ToList(), BetaParts = type.BetaParts.ToList(), GammaParts = type.GammaParts.ToList(), DeltaParts = type.DeltaParts.ToList(), EpsilonParts = type.EpsilonParts.ToList(), ZetaParts = type.ZetaParts.ToList(), EtaParts = type.EtaParts.ToList(), ThetaParts = type.ThetaParts.ToList(), MaterialParts = type.MaterialParts.ToList(), }, }; var balances = new List <ItemBalanceDefinition>(); var current = this; do { balances.Insert(0, current); current = current.Base; }while (current != null); foreach (var balance in balances) { if (balance.Type != null) { result.Type = balance.Type; } if (balance.Types != null) { result.Types = balance.Types.ToList(); } if (balance.Manufacturers != null) { result.Manufacturers = balance.Manufacturers.ToList(); } if (balance.Parts == null) { continue; } if (balance.Parts.Type != null) { result.Parts.Type = balance.Parts.Type; } AddPartList(balance.Parts.AlphaParts, balance.Parts.Mode, result.Parts.AlphaParts); AddPartList(balance.Parts.BetaParts, balance.Parts.Mode, result.Parts.BetaParts); AddPartList(balance.Parts.GammaParts, balance.Parts.Mode, result.Parts.GammaParts); AddPartList(balance.Parts.DeltaParts, balance.Parts.Mode, result.Parts.DeltaParts); AddPartList(balance.Parts.EpsilonParts, balance.Parts.Mode, result.Parts.EpsilonParts); AddPartList(balance.Parts.ZetaParts, balance.Parts.Mode, result.Parts.ZetaParts); AddPartList(balance.Parts.EtaParts, balance.Parts.Mode, result.Parts.EtaParts); AddPartList(balance.Parts.ThetaParts, balance.Parts.Mode, result.Parts.ThetaParts); AddPartList(balance.Parts.MaterialParts, balance.Parts.Mode, result.Parts.MaterialParts); } if (result.Type != type && result.Types.Contains(type) == false) { throw new ResourceNotFoundException($"item type '{type.ResourcePath}' is not valid for '{this.ResourcePath}'"); } return(result); }
public ItemBalanceDefinition Merge(ItemTypeDefinition itemType) { var balances = new List <ItemBalanceDefinition>(); var current = this; do { balances.Insert(0, current); current = current.Base; }while (current != null); var merged = new ItemBalanceDefinition() { ResourcePath = this.ResourcePath, Parts = new ItemBalancePartCollection() { Mode = PartReplacementMode.Complete, AlphaParts = itemType.AlphaParts.ToList(), BetaParts = itemType.BetaParts.ToList(), GammaParts = itemType.GammaParts.ToList(), DeltaParts = itemType.DeltaParts.ToList(), EpsilonParts = itemType.EpsilonParts.ToList(), ZetaParts = itemType.ZetaParts.ToList(), EtaParts = itemType.EtaParts.ToList(), ThetaParts = itemType.ThetaParts.ToList(), MaterialParts = itemType.MaterialParts.ToList(), }, }; foreach (var balance in balances) { if (balance.Type != null) { merged.Type = balance.Type; } if (balance.Types != null) { merged.Types = balance.Types.ToList(); } if (balance.Manufacturers != null) { merged.Manufacturers = balance.Manufacturers.ToList(); } if (balance.Parts == null) { continue; } if (balance.Parts.Type != null) { merged.Parts.Type = balance.Parts.Type; } MergePartList(merged.Parts.AlphaParts, balance.Parts.Mode, balance.Parts.AlphaParts); MergePartList(merged.Parts.BetaParts, balance.Parts.Mode, balance.Parts.BetaParts); MergePartList(merged.Parts.GammaParts, balance.Parts.Mode, balance.Parts.GammaParts); MergePartList(merged.Parts.DeltaParts, balance.Parts.Mode, balance.Parts.DeltaParts); MergePartList(merged.Parts.EpsilonParts, balance.Parts.Mode, balance.Parts.EpsilonParts); MergePartList(merged.Parts.ZetaParts, balance.Parts.Mode, balance.Parts.ZetaParts); MergePartList(merged.Parts.EtaParts, balance.Parts.Mode, balance.Parts.EtaParts); MergePartList(merged.Parts.ThetaParts, balance.Parts.Mode, balance.Parts.ThetaParts); MergePartList(merged.Parts.MaterialParts, balance.Parts.Mode, balance.Parts.MaterialParts); } if (merged.Type != itemType && merged.Types.Contains(itemType) == false) { throw new KeyNotFoundException("item type '" + itemType.ResourcePath + "' not valid for '" + this.ResourcePath + "'"); } return(merged); }