Example #1
0
 private bool GetItem(ItemInfo info, int amount)
 {
     if (MWarehouse == null || info == null || !info.item || amount < 1)
     {
         return(false);
     }
     if (!BackpackManager.Instance.TryLoseItem_Boolean(info, amount))
     {
         return(false);
     }
     if (!info.item.StackAble && MWarehouse.IsFull)
     {
         MessageManager.Instance.New("仓库已满");
         return(false);
     }
     if (!info.item.StackAble && amount > MWarehouse.size.Rest)
     {
         MessageManager.Instance.New(string.Format("请至少多留出{0}个仓库空间", amount - MWarehouse.size.Rest));
         return(false);
     }
     if (info.item.StackAble)
     {
         MWarehouse.GetItemSimple(info, amount);
         ItemAgent ia = itemAgents.Find(x => !x.IsEmpty && x.MItemInfo.item == info.item);
         if (ia)
         {
             ia.UpdateInfo();
         }
         else
         {
             ia = itemAgents.Find(x => x.IsEmpty);
             if (ia)
             {
                 ia.SetItem(MWarehouse.Latest);
             }
             else
             {
                 MessageManager.Instance.New("发生内部错误!");
                 Debug.Log("[Store Item Error: Can't find ItemAgent] ID: " + info.ItemID + "[" + DateTime.Now.ToString() + "]");
             }
         }
     }
     else
     {
         for (int i = 0; i < amount; i++)
         {
             MWarehouse.GetItemSimple(info);
             foreach (ItemAgent ia in itemAgents)
             {
                 if (ia.IsEmpty)
                 {
                     ia.SetItem(MWarehouse.Latest);
                     break;
                 }
             }
         }
     }
     BackpackManager.Instance.LoseItem(info, amount);
     UpdateUI();
     return(true);
 }