// PUBLIC METHODS: ------------------------------------------------------------------------ public int GetMerchantAmount(Merchant merchant, Item item) { string key = MerchantData.GetKey(merchant.uuid, item.uuid.ToString()); if (!this.wares.ContainsKey(key)) { int maxAmount = -1; for (int i = 0; maxAmount == -1 && i < merchant.warehouse.wares.Length; ++i) { if (merchant.warehouse.wares[i].item.item != null && merchant.warehouse.wares[i].item.item.uuid == item.uuid) { if (merchant.warehouse.wares[i].limitAmount) { maxAmount = merchant.warehouse.wares[i].maxAmount; } else { maxAmount = int.MaxValue; } } } this.wares.Add(key, new MerchantData(merchant.uuid, item.uuid.ToString(), maxAmount)); } return(this.wares[key].remainingAmount); }
public bool BuyFromMerchant(Merchant merchant, Item item, int buyAmount) { int curAmount = this.GetMerchantAmount(merchant, item); int remainingAmount = curAmount - buyAmount; if (remainingAmount < 0) { return(false); } if (InventoryManager.Instance.BuyItem(item.uuid, buyAmount, merchant)) { string key = MerchantData.GetKey(merchant.uuid, item.uuid.ToString()); if (!this.wares.ContainsKey(key)) { this.wares.Add( key, new MerchantData(merchant.uuid, item.uuid.ToString(), remainingAmount) ); } else { this.wares[key].remainingAmount = remainingAmount; } return(true); } return(false); }
public void OnLoad(object generic) { MerchantSaveData saveData = (MerchantSaveData)generic; this.wares = new Dictionary <string, MerchantData>(); for (int i = 0; i < saveData.warehouses.Count; ++i) { MerchantData saveDataItem = saveData.warehouses[i]; string key = MerchantData.GetKey(saveDataItem.merchantID, saveDataItem.itemID); if (this.wares.ContainsKey(key)) { continue; } this.wares.Add(key, saveDataItem); } }