Esempio n. 1
0
 private void Init()
 {
     foreach (var ia in itemAgents)
     {
         ia.Empty();
     }
     while (itemAgents.Count < slotCount)
     {
         ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
         ia.Init(ItemAgentType.Loot);
         itemAgents.Add(ia);
     }
     while (itemAgents.Count > slotCount)
     {
         itemAgents[itemAgents.Count - 1].Clear(true);
         itemAgents.RemoveAt(itemAgents.Count - 1);
     }
     if (LootAgent)
     {
         foreach (ItemInfo li in LootAgent.lootItems)
         {
             foreach (ItemAgent ia in itemAgents)
             {
                 if (ia.IsEmpty)
                 {
                     ia.SetItem(li);
                     break;
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 仓库、装备专用获取道具
 /// </summary>
 /// <param name="info">道具信息</param>
 /// <param name="amount">获取数量</param>
 /// <param name="simulLoseItems">会同时失去的道具</param>
 /// <returns>是否成功</returns>
 public bool GetItem(ItemInfo info, int amount, params ItemInfo[] simulLoseItems)//仓库、装备专用
 {
     if (Backpack == null || info == null || !info.item || amount < 1)
     {
         return(false);
     }
     if (!TryGetItem_Boolean(info, amount, simulLoseItems))
     {
         return(false);
     }
     if (simulLoseItems != null)
     {
         foreach (var si in simulLoseItems)
         {
             LoseItem(si.item, si.Amount);
         }
     }
     if (info.item.StackAble)
     {
         Backpack.GetItemSimple(info, amount);
         ItemAgent ia = itemAgents.Find(x => !x.IsEmpty && (x.MItemInfo.item == info.item || x.MItemInfo.ItemID == info.ItemID));
         if (ia)
         {
             ia.UpdateInfo();
         }
         else//如果找不到,说明该物品是新的,原来背包里没有的
         {
             ia = itemAgents.Find(x => x.IsEmpty);
             if (ia)
             {
                 ia.SetItem(Backpack.LatestInfo);
             }
             else
             {
                 MessageManager.Instance.New("发生内部错误!");
                 Debug.Log("[Get Item Error: Can't find ItemAgent] ID: " + info.item.ID + "[" + System.DateTime.Now.ToString() + "]");
             }
         }
     }
     else
     {
         for (int i = 0; i < amount; i++)
         {
             Backpack.GetItemSimple(info);
             foreach (ItemAgent ia in itemAgents)
             {
                 if (ia.IsEmpty)
                 {
                     ia.SetItem(Backpack.LatestInfo);
                     break;
                 }
             }
         }
     }
     OnGetItemEvent?.Invoke(info.ItemID, amount);
     UpdateUI();
     return(true);
 }
Esempio n. 3
0
 /// <summary>
 /// 交换单元格内容
 /// </summary>
 /// <param name="target"></param>
 public void SwapInfoTo(ItemAgent target)
 {
     if (target != this && agentType != ItemAgentType.None)
     {
         if (target.agentType == agentType && (agentType == ItemAgentType.Backpack || agentType == ItemAgentType.Warehouse))
         {
             if (target.IsEmpty)
             {
                 target.SetItem(MItemInfo);
                 Empty();;
             }
             else
             {
                 ItemInfo targetInfo = target.MItemInfo;
                 target.SetItem(MItemInfo);
                 SetItem(targetInfo);
             }
         }
         else if (target.agentType == ItemAgentType.Warehouse && agentType == ItemAgentType.Backpack)
         {
             WarehouseManager.Instance.StoreItem(MItemInfo);
         }
         else if (target.agentType == ItemAgentType.Backpack && agentType == ItemAgentType.Warehouse)
         {
             WarehouseManager.Instance.TakeOutItem(MItemInfo);
         }
         else if (target.agentType == ItemAgentType.Backpack && agentType == ItemAgentType.Selling)
         {
             ShopManager.Instance.SellItem(ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo).merchandiseInfo);
         }
         else if (target.agentType == ItemAgentType.Selection && agentType == ItemAgentType.Backpack)
         {
             ItemSelectionManager.Instance.Place(MItemInfo);
         }
     }
     FinishDrag();
 }
Esempio n. 4
0
 public void Init(MerchandiseInfo info, MerchandiseType type)
 {
     if (info == null || !info.Item)
     {
         return;
     }
     merchandiseInfo = info;
     merchandiseType = type;
     if (type == MerchandiseType.SellToPlayer)
     {
         itemAgentSon.Init(ItemAgentType.Selling);
     }
     else
     {
         itemAgentSon.Init(ItemAgentType.Purchasing);
     }
     itemAgentSon.SetItem(new ItemInfo(info.Item));
     UpdateInfo();
 }
Esempio n. 5
0
 public bool Place(ItemInfo info)
 {
     if (info == null || info.item == null || info.Amount < 0)
     {
         return(false);
     }
     if (info.item.StackAble)
     {
         if (SelectionType == ItemSelectionType.Discard)
         {
             if (info.item.DiscardAble && BackpackManager.Instance.TryLoseItem_Boolean(info))
             {
                 if (itemAgents.Exists(x => x.MItemInfo == info))
                 {
                     MessageManager.Instance.New("已选择该道具");
                     return(false);
                 }
                 ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
                 ia.Init(ItemAgentType.Selection, -1, UI.gridScrollRect);
                 itemAgents.Add(ia);
                 ia.SetItem(info);
                 if (itemAgents.Count > 0)
                 {
                     ZetanUtility.SetActive(UI.tips, false);
                 }
                 return(true);
             }
         }
         else
         {
             if (SelectionType == ItemSelectionType.Making && info.item.MaterialType == MaterialType.None)
             {
                 return(false);
             }
             if (info.Amount < 2)
             {
                 if (BackpackManager.Instance.TryLoseItem_Boolean(info))
                 {
                     if (itemAgents.Exists(x => x.MItemInfo == info || x.MItemInfo.item == info.item))
                     {
                         MessageManager.Instance.New("已选择该道具");
                         return(false);
                     }
                     ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
                     ia.Init(ItemAgentType.Selection, -1, UI.gridScrollRect);
                     itemAgents.Add(ia);
                     ia.SetItem(info);
                     if (itemAgents.Count > 0)
                     {
                         ZetanUtility.SetActive(UI.tips, false);
                     }
                     return(true);
                 }
             }
             else
             {
                 if (itemAgents.Exists(x => x.MItemInfo == info || x.MItemInfo.item == info.item))
                 {
                     MessageManager.Instance.New("已选择该道具");
                     return(false);
                 }
                 AmountManager.Instance.New(delegate
                 {
                     if (BackpackManager.Instance.TryLoseItem_Boolean(info, (int)AmountManager.Instance.Amount))
                     {
                         ItemAgent ia = itemAgents.Find(x => x.MItemInfo.item == info.item);
                         if (ia)
                         {
                             ia.MItemInfo.Amount = (int)AmountManager.Instance.Amount;
                         }
                         else
                         {
                             ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
                             ia.Init(ItemAgentType.Selection, -1, UI.gridScrollRect);
                             itemAgents.Add(ia);
                             ia.SetItem(new ItemInfo(info.item, (int)AmountManager.Instance.Amount));
                         }
                         if (itemAgents.Count > 0)
                         {
                             ZetanUtility.SetActive(UI.tips, false);
                         }
                     }
                 }, info.Amount);
                 return(true);
             }
         }
     }
     else if ((SelectionType != ItemSelectionType.Discard || SelectionType == ItemSelectionType.Discard && info.item.DiscardAble) &&
              BackpackManager.Instance.TryLoseItem_Boolean(info))
     {
         if (itemAgents.Exists(x => x.MItemInfo == info))
         {
             MessageManager.Instance.New("已选择该道具");
             return(false);
         }
         ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
         ia.Init(ItemAgentType.Selection, -1, UI.gridScrollRect);
         itemAgents.Add(ia);
         ia.SetItem(info);
         if (itemAgents.Count > 0)
         {
             ZetanUtility.SetActive(UI.tips, false);
         }
         return(true);
     }
     return(false);
 }
Esempio n. 6
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);
 }