IEnumerable <(ShopLayoutNode, string)> GetShops(ShopLayoutNode node, string path = "") { if (avoids.Any(x => node.Name == x)) { yield break; } if (node.ShopInventoryNodes?.Length > 0) { yield return(node, path); } if (node.ShopLayoutNodes?.Length > 0) { foreach (var layout in node.ShopLayoutNodes) { foreach (var(shop, p) in GetShops(layout, Path.Combine(path, layout.Name))) { yield return(shop, p); } } } yield break; }
List <ShopItem> GetInventory(Node prices, ShopLayoutNode shopNode) { var items = new List <ShopItem>(); if (shopNode?.ShopInventoryNodes.Length > 0) { foreach (var itemNode in shopNode.ShopInventoryNodes) { var product = FindInventoryNode(prices, itemNode.InventoryID); if (product == null) { Console.WriteLine($"ShopLoader: Can't find product {itemNode.Name} ({itemNode.InventoryID}) "); } else { var entity = entitySvc.GetByFilename(Path.Combine(DataRoot, product.Filename)); var item = new ShopItem { name = itemNode.Name.ToLower(), basePriceOffsetPercentage = itemNode.BasePriceOffsetPercentage, maxDiscountPercentage = itemNode.MaxDiscountPercentage, maxPremiumPercentage = itemNode.MaxPremiumPercentage, inventory = itemNode.Inventory, optimalInventoryLevel = itemNode.OptimalInventoryLevel, maxInventory = itemNode.MaxInventory, autoRestock = Convert.ToBoolean(itemNode.AutoRestock), autoConsume = Convert.ToBoolean(itemNode.AutoConsume), refreshRatePercentagePerMinute = itemNode.RefreshRatePercentagePerMinute, shopBuysThis = itemNode.TransactionTypes.Any(x => x.Data == "Sell"), shopSellsThis = itemNode.TransactionTypes.Any(x => x.Data == "Buy"), shopRentThis = itemNode.TransactionTypes.Any(x => x.Data == "Rent"), basePrice = product.BasePrice, filename = product.Filename, node_reference = itemNode.ID, item_reference = itemNode.InventoryID, rentalTemplates = new List <ShopRentalTemplate>() }; foreach (var rentalTemplate in itemNode.RentalTemplates) { var template = rentalTemplates.Find(y => y.ShopRentalTemplate.ID == rentalTemplate.Data); if (template != null) { item.rentalTemplates.Add(template.ShopRentalTemplate); } } if (entity?.Components.SAttachableComponentParams != null) { item.displayName = localisationService.GetText(entity.Components.SAttachableComponentParams.AttachDef.Localization.Name); item.tags = entity.Components.SAttachableComponentParams.AttachDef.Tags.Split(" "); item.type = entity.Components.SAttachableComponentParams.AttachDef.Type; item.subType = entity.Components.SAttachableComponentParams.AttachDef.SubType; } if (entity?.Components.CommodityComponentParams != null) { item.displayName = localisationService.GetText(entity.Components.CommodityComponentParams.name); } items.Add(item); } } } return(items); }