// FIXME: total check & tests public void Prepare() { NWField fld = (NWField)Owner; ExtRect r = Area; r.Inflate(-1, -1); int id = (int)ID; var blRec = StaticData.dbBuildings[id]; if (ID >= BuildingID.bid_MerchantShop && ID <= BuildingID.bid_WoodsmanShop) { NWCreature merchant = (NWCreature)Holder; if (merchant == null) { Item coins = new Item(fSpace, null); coins.CLSID = GlobalVars.iid_Coin; coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); int x = RandomHelper.GetBoundedRnd(r.Left, r.Right); int y = RandomHelper.GetBoundedRnd(r.Top, r.Bottom); merchant = fld.AddCreature(x, y, GlobalVars.nwrDB.FindEntryBySign(StaticData.dbSysCreatures[(int)blRec.Owner].Sign).GUID); merchant.IsTrader = true; merchant.AddItem(coins); Holder = merchant; } else { Item coins = (Item)merchant.Items.FindByCLSID(GlobalVars.iid_Coin); if (coins != null) { coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); } } ProbabilityTable <int> data = blRec.Wares; if (((data != null) ? data.Size() : 0) > 0) { for (int y = r.Top; y <= r.Bottom; y++) { for (int x = r.Left; x <= r.Right; x++) { Item item = (Item)fld.FindItem(x, y); if (item == null) { item = new Item(fSpace, this); item.CLSID = data.GetRandomItem(); item.SetPos(x, y); item.Owner = merchant; item.GenCount(); fld.Items.Add(item, false); } else { if (AuxUtils.Chance(20)) { item.CLSID = data.GetRandomItem(); item.GenCount(); } } } } } } }