public Vendor(Identity parent, Identity id, string templateHash) : base(parent, id) { DBVendorTemplate vendorTemplate = VendorTemplateDao.Instance.GetWhere(new { Hash = templateHash }).FirstOrDefault(); if (vendorTemplate == null) { LogUtil.Debug( DebugInfoDetail.Shopping, "Could not find a hash entry for this shop, pls check vendors table."); } this.Stats = new SimpleStatList(); // Fallback on Advy adv. crystals shop this.Template = ItemLoader.ItemList[vendorTemplate != null ? vendorTemplate.ItemTemplate : 46522]; foreach (KeyValuePair <int, int> s in this.Template.Stats) { this.Stats[s.Key].Value = s.Value; } this.BaseInventory = new VendorInventory(this); if (vendorTemplate != null) { this.TemplateHash = vendorTemplate.Hash; this.Name = vendorTemplate.Name; this.BaseInventory.Read(); this.Stats[StatIds.sellmodifier].BaseValue = (uint)(vendorTemplate.Sell * 100.0f); this.Stats[StatIds.buymodifier].BaseValue = (uint)(vendorTemplate.Buy * 100.0f); } }
public override bool Read() { Random rnd = new Random(Environment.TickCount); Vendor owner; if (!this.ownerReference.TryGetTarget(out owner)) { throw new Exception("Could not retrieve vendor target."); } string templateHash = owner.TemplateHash; if (!String.IsNullOrEmpty(templateHash)) { DBVendorTemplate vendorTemplate = VendorTemplateDao.Instance.GetWhere(new { Hash = templateHash }).FirstOrDefault(); if (vendorTemplate == null) { throw new DataBaseException( "No vendor found for Template " + templateHash + "." + Environment.NewLine + "Please fill in the database :)"); } int slotNumber = 0; DBShopInventoryTemplate[] inventoryEntries = ShopInventoryTemplateDao.Instance.GetWhere(new { Hash = vendorTemplate.ShopInvHash }).ToArray(); foreach (DBShopInventoryTemplate inventoryEntry in inventoryEntries) { // Skip entries which are out of vendortemplate's QL range if ((inventoryEntry.MinQl > vendorTemplate.MaxQl) || (inventoryEntry.MaxQl < vendorTemplate.MinQl)) { continue; } // narrow down the range to least amount of QL int minQl = inventoryEntry.MinQl > vendorTemplate.MinQl ? inventoryEntry.MinQl : vendorTemplate.MinQl; int maxQl = inventoryEntry.MaxQl < vendorTemplate.MaxQl ? inventoryEntry.MaxQl : vendorTemplate.MaxQl; int itemQl = minQl + rnd.Next(maxQl - minQl); Item item = new Item(itemQl, inventoryEntry.LowId, inventoryEntry.HighId); this.Add(slotNumber, item); slotNumber++; if (slotNumber >= this.MaxSlots) { break; } } } return(true); }