void PreHandlerShops() { foreach (var sPreHandler in _builder.Sheet("PreHandler")) { var sNpcs = _builder.Realm.GameData.ENpcs.FindWithData(sPreHandler.Key); var sTarget = (Saint.XivRow)sPreHandler["Target"]; if (sTarget is Saint.IShop sShop) { var shop = new GarlandShop(sShop); shop.Key = sShop.Key; shop.ENpcs = sNpcs; // Overwrite, FindWithData doesn't see this. _shops.Add(shop); } // Otherwise it's likely a link to some other non-shop thing. } }
public override void Start() { // Collect and index all shops to use. _shops.AddRange(GarlandShop.Convert(_builder.Sheet <Saint.GilShop>(), _builder)); _shops.AddRange(GarlandShop.Convert(_builder.Sheet <Saint.SpecialShop>(), _builder)); _shops.AddRange(GarlandShop.Convert(_builder.Sheet <Saint.GCShop>(), _builder)); _shops.AddRange(GarlandShop.Convert(_builder.Sheet <Saint.FccShop>(), _builder)); _shopsByKey = _shops.ToDictionary(s => s.Key); // Fill extra information on shop names and NPCs from chat tables and hacks. TopicSelectShops(); CustomTalkShops(); PreHandlerShops(); Hacks.SetManualShops(_builder.Realm, _shopsByKey); // FCC shop credit var fccredit = _builder.CreateItem("fccredit"); fccredit.en = new JObject(); fccredit.en.description = "Credits for the enrichment of an Eorzean free company."; fccredit.en.name = "Company Credit"; fccredit.fr = new JObject(); fccredit.fr.name = "Company Credit"; fccredit.de = new JObject(); fccredit.de.name = "Company Credit"; fccredit.ja = new JObject(); fccredit.ja.name = "Company Credit"; fccredit.ilvl = 1; fccredit.category = 63; // Other fccredit.icon = "custom/fccredit"; // Convert them. foreach (var shop in _shops) { ConvertShop(shop); } }
public void CreateNpcGilShop(GarlandShop gShop, dynamic npc) { var shopName = gShop.Name == "Unknown Shop" ? "Purchase Items" : gShop.Name; var shop = CreateShop(shopName, npc, false); if (shop == null) { return; // Skipped. } var npcId = (int)npc.id; foreach (var sItem in gShop.GtShopListings.SelectMany(l => l.Rewards.Select(r => r.Item))) { if (!_db.ItemsById.TryGetValue(sItem.Key, out var item)) { if (!string.IsNullOrWhiteSpace(sItem.Name)) { DatabaseBuilder.PrintLine($"Skipping shop item: {sItem.Name}"); } continue; } JArray vendors = item.vendors; if (vendors == null) { item.vendors = vendors = new JArray(); } if (!vendors.Any(i => (int)i == npcId)) { item.vendors.Add(npcId); Db.AddReference(item, "npc", npcId, true); } shop.entries.Add(sItem.Key); Db.AddReference(npc, "item", sItem.Key, false); } }
void ConvertShop(GarlandShop gShop) { if (gShop.GtShopListings.Count == 0) { return; } if (Hacks.ExcludedShops.Contains(gShop.Key)) { return; } // Create the NPCs to use. List <dynamic> npcs = new List <dynamic>(); foreach (var sNpc in gShop.ENpcs) { try { npcs.Add(_builder.Db.NpcsById[sNpc.Key]); } catch (KeyNotFoundException e) { } } // Shortcut for gil shops. if (gShop.GtShopListings.All(l => l.Costs.All(c => c.Item.Key == 1))) { foreach (var npc in npcs) { _builder.CreateNpcGilShop(gShop, npc); } return; } // Build entries for trade shops. var shop = _builder.CreateShop(gShop.Name, null, true); foreach (var listing in gShop.GtShopListings.ToArray()) { var isValid = true; if (listing.Costs.Any(c => c.ItemKey.HasValue && !_builder.Db.ItemsById.ContainsKey(c.ItemKey.Value))) { isValid = false; } if (listing.Rewards.Any(r => r.ItemKey.HasValue && !_builder.Db.ItemsById.ContainsKey(r.ItemKey.Value))) { isValid = false; } if (!isValid) { var costNames = listing.Costs.Select(c => c.Count + " " + ((c.ItemKey.HasValue && _builder.Db.ItemsById.ContainsKey(c.ItemKey.Value)) ? _builder.Db.ItemsById[c.ItemKey.Value].en.name : c.ItemId)); var rewardNames = listing.Rewards.Select(c => c.Count + " " + ((c.ItemKey.HasValue && _builder.Db.ItemsById.ContainsKey(c.ItemKey.Value)) ? _builder.Db.ItemsById[c.ItemKey.Value].en.name : c.ItemId)); DatabaseBuilder.PrintLine($"Placeholder in '{shop.name}': {string.Join(", ", costNames)} -> {string.Join(", ", rewardNames)}"); gShop.GtShopListings.Remove(listing); continue; } // Add the listing to the shop. shop.entries.Add(_builder.CreateShopEntry(listing.Costs, listing.Rewards)); } gShop.AddItemTrades(_builder); // Add the shop to each npc. // Can't do it above because the shop is copied. foreach (var npc in npcs) { npc.trade = 1; if (npc.shops == null) { npc.shops = new JArray(); } npc.shops.Add(shop); } }