public void Make(BagInfo bag, int num) { if (num <= 0) { return; } CheckMaxMake(bag); if (num > MaxMake) { throw new System.Exception("无法制作该数量的该物品"); } if (bag.Money < Cost * num) { throw new System.Exception("制作费用不足"); } if (bag.IsMax) { throw new System.Exception("行囊空间不足"); } if (bag.IsMaxWeight) { throw new System.Exception("超重状态无法制作"); } if ((bag.Current_Weight + Item.Weight * num) / bag.MaxWeight >= 1.5f) { throw new System.Exception("该物品太重了"); } Check(bag, num); if (!MakeAble) { throw new System.Exception("材料不足,无法制作"); } foreach (MaterialInfo minfo in Item.MaterialsList) { ItemBase find = bag.itemList.Find(m => m.ItemID == minfo.Material.ID).Item; if (find == null) { throw new System.Exception("找不到该材料"); } bag.LoseItem(find, minfo.Required * num); } bag.GetItem(Item, num); bag.LoseMoney(Cost * num); }
public virtual void OnSell(BagInfo bag, int sell_num) { if (sell_num <= 0) { return; } if (SellAble) { ItemInfo itemInBag = bag.itemList.Find(i => i.Item == this); if (itemInBag == null) { throw new System.Exception("行囊中不存在该物品"); } int finallySell = itemInBag.Quantity > sell_num ? sell_num : itemInBag.Quantity; bag.GetMoney(SellPrice * finallySell); bag.LoseItem(itemInBag.Item, finallySell); } else { throw new System.Exception("该物品不可贩卖"); } }
public void StoreItem(ItemBase item, BagInfo bagInfo, int store_num) { if (item == null || store_num <= 0) { return; } ItemInfo itemInBag = bagInfo.itemList.Find(i => i.Item == item); if (itemInBag == null) { throw new System.Exception("背包中不存在该物品"); } int finallyStore = store_num; ItemInfo find = itemList.Find(i => i.ItemID == item.ID); //Debug.Log(find); if (find != null && item.StackAble) { if (finallyStore != 0) { find.Quantity += finallyStore; } } else if (!item.StackAble) { finallyStore = MaxSize - Current_Size > store_num ? store_num : MaxSize - Current_Size; if (!IsMax) { for (int i = 0; i < finallyStore; i++) { Current_Size++; ItemInfo info = new ItemInfo(item.Clone()) { Quantity = 1 }; itemList.Add(info); } } else { throw new System.Exception("仓库已满"); } } else { finallyStore = item.MaxCount > store_num ? store_num : item.MaxCount; if (!IsMax) { Current_Size++; ItemInfo info = new ItemInfo(item.Clone()); info.Quantity += finallyStore; if (info.Quantity >= info.MaxCount) { info.IsMax = true; } itemList.Add(info); } else { throw new System.Exception("仓库已满"); } } bagInfo.LoseItem(item, finallyStore); }