Esempio n. 1
0
 public void TakeAll()
 {
     if (!LootAgent)
     {
         return;
     }
     foreach (ItemInfo item in LootAgent.lootItems)
     {
         int takeAmount = BackpackManager.Instance.TryGetItem_Integer(item);
         if (BackpackManager.Instance.GetItem(item.item, takeAmount))
         {
             item.Amount -= takeAmount;
         }
         ItemAgent ia = GetItemAgentByInfo(item);
         if (ia)
         {
             ia.UpdateInfo();
         }
     }
     LootAgent.lootItems.RemoveAll(x => x.Amount < 1);
     if (LootAgent.lootItems.Count < 1)
     {
         LootAgent.Recycle();
         CloseWindow();
     }
 }
Esempio n. 2
0
    private bool LoseItem(ItemInfo info, int amount)
    {
        if (MWarehouse == null || info == null || !info.item || amount < 1)
        {
            return(false);
        }
        if (!BackpackManager.Instance.TryGetItem_Boolean(info, amount))
        {
            return(false);
        }
        BackpackManager.Instance.GetItem(info, amount);
        MWarehouse.LoseItemSimple(info, amount);
        ItemAgent ia = GetItemAgentByInfo(info);

        if (ia)
        {
            ia.UpdateInfo();
        }
        UpdateUI();
        if (!BackpackManager.Instance.IsUIOpen)
        {
            BackpackManager.Instance.OpenWindow();
        }
        return(true);
    }
Esempio n. 3
0
 public void Init()
 {
     if (!UI || !UI.gameObject)
     {
         return;
     }
     if (Backpack != null)
     {
         foreach (ItemAgent ia in itemAgents)
         {
             ia.Empty();
         }
         while (Backpack.size.Max > itemAgents.Count)
         {
             ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
             itemAgents.Add(ia);
             ia.Init(ItemAgentType.Backpack, itemAgents.Count - 1, UI.gridScrollRect);
         }
         while (Backpack.size.Max < itemAgents.Count)
         {
             itemAgents[itemAgents.Count - 1].Clear(true);
             itemAgents.RemoveAt(itemAgents.Count - 1);
         }
         UpdateUI();
     }
     UI.pageSelector.SetValueWithoutNotify(0);
 }
Esempio n. 4
0
    private void OnTake(ItemInfo item, int amount)
    {
        if (!LootAgent)
        {
            return;
        }
        if (!LootAgent.lootItems.Contains(item))
        {
            return;
        }
        int takeAmount = BackpackManager.Instance.TryGetItem_Integer(item, amount);

        if (BackpackManager.Instance.GetItem(item.item, takeAmount))
        {
            item.Amount -= takeAmount;
        }
        if (item.Amount < 1)
        {
            LootAgent.lootItems.Remove(item);
        }
        ItemAgent ia = GetItemAgentByInfo(item);

        if (ia)
        {
            ia.UpdateInfo();
        }
        if (LootAgent.lootItems.Count < 1)
        {
            LootAgent.Recycle();
            CloseWindow();
        }
    }
Esempio n. 5
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left)
        {
#if UNITY_STANDALONE
            if (DragableManager.Instance.IsDraging)
            {
                ItemAgent source = DragableManager.Instance.Current as ItemAgent;
                if (source)
                {
                    BackpackManager.Instance.DiscardItem(source.MItemInfo);
                    AmountManager.Instance.SetPosition(eventData.position);
                    source.FinishDrag();
                }
            }
            else
            {
                BackpackManager.Instance.OpenDiscardWindow();
            }
#elif UNITY_ANDROID
            BackpackManager.Instance.OpenDiscardWindow();
            TipsManager.Instance.ShowText(transform.position, "将物品拖拽至此按钮丢弃,或者点击该按钮进行选取。", 3);
#endif
        }
    }
Esempio n. 6
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. 7
0
    public void OnEndDrag(PointerEventData eventData)//用于安卓拖拽
    {
#if UNITY_ANDROID
        if (parentScrollRect)
        {
            parentScrollRect.OnEndDrag(eventData);                  //修复ScrollRect冲突
        }
        if (agentType == ItemAgentType.None)
        {
            return;
        }
        if (!IsEmpty && eventData.button == PointerEventData.InputButton.Left && DragableManager.Instance.IsDraging && eventData.pointerCurrentRaycast.gameObject)
        {
            ItemAgent target = eventData.pointerCurrentRaycast.gameObject.GetComponentInParent <ItemAgent>();
            if (target)
            {
                SwapInfoTo(target);
            }
            else if (eventData.pointerCurrentRaycast.gameObject.GetComponentInParent <DiscardButton>() == BackpackManager.Instance.DiscardButton && agentType == ItemAgentType.Backpack)
            {
                BackpackManager.Instance.DiscardItem(MItemInfo);
                AmountManager.Instance.SetPosition(eventData.position);
            }
            else if (eventData.pointerCurrentRaycast.gameObject == ItemSelectionManager.Instance.PlacementArea && agentType == ItemAgentType.Backpack)
            {
                ItemSelectionManager.Instance.Place(MItemInfo);
            }
        }
#endif
        FinishDrag();
    }
 public void LoadFromBagInfo()
 {
     if (!isInit)
     {
         return;
     }
     bagInfo = PlayerInfoManager.Instance.PlayerInfo.bag;
     if (bagInfo == null)
     {
         return;
     }
     Clear();
     SetBagCells();
     //Debug.Log("当前背包中物品数量" + PlayerInfoManager.Self.playerInfo.bag.itemList.Count);
     //Debug.Log(PlayerInfoManager.Self.playerInfo.bag.itemList.Find(i => i.Item == item) != null ? PlayerInfoManager.Self.playerInfo.bag.itemList.Find(i => i.Item == item).Quantity.ToString() : string.Empty);
     foreach (ItemInfo item in bagInfo.itemList)
     {
         for (int i = 0; i < bagCells.Count; i++)
         {
             if (bagCells[i].transform.childCount <= 0)
             {
                 if (item != null && item.Quantity > 0)
                 {
                     ItemAgent tempCell = (Instantiate(itemCellPrefab, bagCells[i].transform) as GameObject).GetComponent <ItemAgent>();
                     tempCell.itemInfo = item;
                     tempCell.isStored = false;
                     itemAgents.Add(tempCell);
                 }
                 break;
             }
         }
     }
 }
Esempio n. 9
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left && agentType == ItemAgentType.Making)
        {
            ItemWindowManager.Instance.SetItemAndOpenWindow(this);
            return;
        }
#if UNITY_STANDALONE
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            if (DragableManager.Instance.IsDraging && (agentType == ItemAgentType.Backpack || agentType == ItemAgentType.Warehouse))
            {
                ItemAgent source = DragableManager.Instance.Current as ItemAgent;
                if (source)
                {
                    source.SwapInfoTo(this);
                }
            }
            else
            {
                if (!IsEmpty && agentType != ItemAgentType.None && agentType != ItemAgentType.Loot && agentType != ItemAgentType.Purchasing)
                {
                    BeginDrag();
                }
            }
        }
        else if (eventData.button == PointerEventData.InputButton.Right && !IsEmpty)
        {
            OnRightClick();
        }
#elif UNITY_ANDROID
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            if (clickCount < 1)
            {
                isClick = true;
            }
            if (clickTime <= 0.2f)
            {
                clickCount++;
            }
            if (!IsEmpty)
            {
                if (clickCount > 1)
                {
                    OnRightClick();
                    isClick    = false;
                    clickCount = 0;
                    clickTime  = 0;
                }
                else if (clickCount == 1 && touchTime < 0.5f)
                {
                    ItemWindowManager.Instance.SetItemAndOpenWindow(this);
                }
            }
        }
#endif
    }
Esempio n. 10
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. 11
0
 public void SetItem(ItemAgent itemAgent)
 {
     if (!itemAgent)
     {
         return;
     }
     itemInfo            = itemAgent.itemInfo;
     icon.overrideSprite = itemAgent.iconImage;
     iconImage           = icon.overrideSprite;
 }
Esempio n. 12
0
        public static ArrayList DataTableToBizItems(Guid logoid, DataTable dt, string roidname = "PLM_R_OID")
        {
            if (dt == null)
            {
                return(new ArrayList());
            }
            ArrayList revOids = new ArrayList();

            foreach (DataRow row in dt.Rows)
            {
                revOids.Add(new Guid((byte[])row[roidname.ToUpper()]));
            }
            return(ItemAgent.GetBizItemsByRevisions(revOids, Guid.Empty, logoid, BizItemMode.BizItem));
        }
Esempio n. 13
0
 public void Init(Warehouse warehouse)
 {
     if (warehouse != null)
     {
         MWarehouse = warehouse;
         foreach (ItemAgent ia in itemAgents)
         {
             ia.Empty();
         }
         while (itemAgents.Count < MWarehouse.size.Max)//格子不够用,新建
         {
             ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
             itemAgents.Add(ia);
             ia.Empty();
             ia.Init(ItemAgentType.Warehouse, itemAgents.Count - 1, UI.gridRect);
         }
         int originalSize = itemAgents.Count;
         for (int i = MWarehouse.size.Max; i < originalSize - MWarehouse.size.Max; i++)//用不到的格子隐藏
         {
             itemAgents[i].Hide();
         }
         for (int i = 0; i < MWarehouse.size.Max; i++)//用得到的格子显示
         {
             itemAgents[i].Show();
         }
         foreach (ItemInfo info in MWarehouse.Items)
         {
             if (info.indexInGrid > 0 && info.indexInGrid < itemAgents.Count)
             {
                 itemAgents[info.indexInGrid].SetItem(info);
             }
             else
             {
                 for (int i = 0; i < MWarehouse.size.Max; i++)
                 {
                     if (itemAgents[i].IsEmpty)
                     {
                         itemAgents[i].SetItem(info);
                         break;
                     }
                 }
             }
         }
         UpdateUI();
     }
     UI.pageSelector.SetValueWithoutNotify(0);
     SetPage(0);
 }
Esempio n. 14
0
 private new void Awake()
 {
     if (!UI || !UI.gameObject)
     {
         return;
     }
     base.Awake();
     for (int i = 0; i < 100; i++)
     {
         ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
         itemAgents.Add(ia);
         ia.Init(ItemAgentType.Warehouse, itemAgents.Count - 1, UI.gridRect);
         ia.Empty();
         ZetanUtility.SetActive(ia.gameObject, false);
     }
 }
Esempio n. 15
0
    public override void CloseWindow()
    {
        base.CloseWindow();
        if (itemAgent)
        {
            itemAgent.DeSelect();
        }
        itemAgent               = null;
        MItemInfo               = null;
        UI.nameText.text        = null;
        UI.descriptionText.text = string.Empty;
        UI.priceText.text       = string.Empty;
        ZetanUtility.SetActive(UI.durability.gameObject, false);
        CloseSubWindow();
#if UNITY_ANDROID
        ZetanUtility.SetActive(UI.buttonsArea, false);
        ZetanUtility.SetActive(UI.closeButton.gameObject, false);
#endif
    }
Esempio n. 16
0
    public void ShowQuestDescription(Quest quest)
    {
        if (quest == null)
        {
            return;
        }
        CurrentQuest            = quest;
        UI.descriptionText.text = new StringBuilder().AppendFormat("<b>{0}</b>\n[委托人: {1}]\n{2}",
                                                                   CurrentQuest.Title,
                                                                   CurrentQuest.originalQuestHolder.TalkerName,
                                                                   CurrentQuest.Description).ToString();
        UI.moneyText.text = CurrentQuest.RewardMoney > 0 ? CurrentQuest.RewardMoney.ToString() : "无";
        UI.EXPText.text   = CurrentQuest.RewardEXP > 0 ? CurrentQuest.RewardEXP.ToString() : "无";
        int befCount = rewardCells.Count;

        for (int i = 0; i < 10 - befCount; i++)
        {
            ItemAgent rwc = ObjectPool.Get(UI.rewardCellPrefab, UI.rewardCellsParent).GetComponent <ItemAgent>();
            rwc.Init();
            rewardCells.Add(rwc);
        }
        foreach (ItemAgent rwc in rewardCells)
        {
            if (rwc)
            {
                rwc.Empty();
            }
        }
        foreach (ItemInfo info in quest.RewardItems)
        {
            foreach (ItemAgent rw in rewardCells)
            {
                if (rw.IsEmpty)
                {
                    rw.SetItem(info);
                    break;
                }
            }
        }
        UI.descriptionWindow.alpha          = 1;
        UI.descriptionWindow.blocksRaycasts = true;
    }
Esempio n. 17
0
    /// <summary>
    /// 失去道具(精确到个例)
    /// </summary>
    /// <param name="info">道具信息</param>
    /// <param name="amount">失去数量</param>
    /// <param name="simulGetItems">会同时获得的道具</param>
    /// <returns>是否成功</returns>
    public bool LoseItem(ItemInfo info, int amount, params ItemInfo[] simulGetItems)
    {
        if (Backpack == null || info == null || !info.item || amount < 1)
        {
            return(false);
        }
        if (!TryLoseItem_Boolean(info, amount))
        {
            return(false);
        }
        if (simulGetItems != null)
        {
            foreach (var si in simulGetItems)
            {
                if (!TryGetItem_Boolean(si, new ItemInfo(info.item, amount)))
                {
                    return(false);
                }
            }
        }
        Backpack.LoseItemSimple(info, amount);
        ItemAgent ia = itemAgents.Find(x => x.MItemInfo == info);

        if (ia)
        {
            ia.UpdateInfo();
        }
        OnLoseItemEvent?.Invoke(info.ItemID, GetItemAmount(info.item));
        if (ItemWindowManager.Instance.MItemInfo == info && info.Amount < 1)
        {
            ItemWindowManager.Instance.CloseWindow();
        }
        if (simulGetItems != null)
        {
            foreach (var si in simulGetItems)
            {
                GetItem(si);
            }
        }
        UpdateUI();
        return(true);
    }
Esempio n. 18
0
    /// <summary>
    /// 扩展容量
    /// </summary>
    /// <param name="size">扩展数量</param>
    /// <returns>是否成功扩展</returns>
    public bool ExpandSize(int size)
    {
        if (size < 1)
        {
            return(false);
        }
        if (Backpack.size.Max >= 192)
        {
            MessageManager.Instance.New(GameManager.BackpackName + "已经达到最大容量了");
            return(false);
        }
        int finallyExpand = Backpack.size.Max + size > 192 ? 192 - Backpack.size.Max : size;

        Backpack.size.Max += finallyExpand;
        for (int i = 0; i < finallyExpand; i++)
        {
            ItemAgent ia = ObjectPool.Get(UI.itemCellPrefab, UI.itemCellsParent).GetComponent <ItemAgent>();
            itemAgents.Add(ia);
            ia.Init(ItemAgentType.Backpack, itemAgents.Count - 1, UI.gridScrollRect);
        }
        MessageManager.Instance.New(GameManager.BackpackName + "空间增加了");
        return(true);
    }
Esempio n. 19
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. 20
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. 21
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);
 }
    public void GetItem(ItemBase item, int get_num)
    {
        if (!isInit)
        {
            return;
        }
        if (bagInfo == null || item == null || get_num <= 0)
        {
            return;
        }
        int finallyGet = 0;

        if (item.StackAble)
        {
            finallyGet = bagInfo.itemList.Find(i => i.ItemID == item.ID) == null ?
                         0 : bagInfo.itemList.Find(i => i.ItemID == item.ID).Quantity;
        }
        List <ItemInfo> itemsBefore = bagInfo.itemList.FindAll(i => i.ItemID == item.ID);

        try
        {
            bagInfo.GetItem(item, get_num);
        }
        catch (System.Exception ex)
        {
            NotificationManager.Instance.NewNotification(ex.Message);
            return;
        }
        List <ItemInfo> itemsAfter = bagInfo.itemList.FindAll(i => i.ItemID == item.ID);
        List <ItemInfo> difference = new List <ItemInfo>();

        if (itemsBefore.Count > 0)
        {
            foreach (ItemInfo info in itemsAfter)
            {
                if (itemsBefore.Find(i => i.Item == info.Item) == null)
                {
                    difference.Add(info);
                }
            }
        }
        else
        {
            difference = itemsAfter;
        }
        if (item.StackAble)
        {
            finallyGet = bagInfo.itemList.Find(i => i.ItemID == item.ID) == null ?
                         0 : bagInfo.itemList.Find(i => i.ItemID == item.ID).Quantity
                         - finallyGet;
        }
        else
        {
            finallyGet = difference.Count;
        }
        if (finallyGet > 0)
        {
            NotificationManager.Instance.NewNotification("获得了" + finallyGet + "个<color=orange>" + item.Name + "</color>");
        }
        if (item.StackAble && itemAgents.Exists(ic => ic.GetComponent <ItemAgent>().itemInfo.ItemID == item.ID))
        {
            return;
        }
        if (difference.Count > 0)
        {
            foreach (ItemInfo info in difference)
            {
                for (int i = 0; i < bagCells.Count; i++)
                {
                    if (bagCells[i].transform.childCount <= 0)
                    {
                        ItemAgent tempCell = (Instantiate(itemCellPrefab, bagCells[i].transform) as GameObject).GetComponent <ItemAgent>();
                        tempCell.itemInfo = info;
                        tempCell.isStored = false;
                        itemAgents.Add(tempCell);
                        break;
                    }
                }
            }
        }
    }
Esempio n. 23
0
    public void SetItemAndOpenWindow(ItemAgent itemAgent)
    {
        //UI.windowsRect.position = new Vector3(Input.mousePosition.x - UI.windowsRect.sizeDelta.x, UI.windowsRect.position.y);
        ZetanUtility.KeepInsideScreen(UI.window.transform as RectTransform);
        if (itemAgent == null || itemAgent.IsEmpty || this.itemAgent == itemAgent)
        {
            return;
        }
        itemAgent.Select();
        if (this.itemAgent)
        {
            this.itemAgent.DeSelect();
        }
        this.itemAgent = itemAgent;
        LeftOrRight(itemAgent.transform.position);
        animated = false;
        OpenWindow();
        MItemInfo               = itemAgent.MItemInfo;
        itemAgentType           = itemAgent.agentType;
        UI.icon.overrideSprite  = MItemInfo.item.Icon;
        UI.nameText.text        = MItemInfo.ItemName;
        UI.nameText.color       = GameManager.QualityToColor(MItemInfo.item.Quality);
        UI.typeText.text        = ItemBase.GetItemTypeString(MItemInfo.item.ItemType);
        UI.priceText.text       = MItemInfo.item.SellAble ? MItemInfo.item.SellPrice + GameManager.CoinName : "不可出售";
        UI.weightText.text      = "重量:" + MItemInfo.item.Weight.ToString("F2") + "WL";
        UI.descriptionText.text = MItemInfo.item.Description;
        switch (MItemInfo.item.ItemType)
        {
        case ItemType.Weapon:
            WeaponItem weapon = MItemInfo.item as WeaponItem;
            UI.effectText.text = (weapon.CutATK > 0 ? "斩击攻击力+" + weapon.CutATK + "\n" : string.Empty) +
                                 (weapon.PunATK > 0 ? "刺击攻击力+" + weapon.PunATK + "\n" : string.Empty) +
                                 (weapon.BluATK > 0 ? "钝击攻击力+" + weapon.BluATK + "\n" : string.Empty) +
                                 (weapon.DEF > 0 ? "防御力力+" + weapon.DEF + "\n" : string.Empty) +
                                 (weapon.Hit > 0 ? "命中+" + weapon.Hit + "\n" : string.Empty);
            if (weapon.Powerup.IsEffective)
            {
                ZetanUtility.SetActive(UI.mulFunTitle.gameObject, true);
                ZetanUtility.SetActive(UI.mulFunText.gameObject, true);
                UI.mulFunTitle.text = "-附加能力";
                UI.mulFunText.text  = weapon.Powerup.ToString();
            }
            else
            {
                ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
                ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
                UI.mulFunTitle.text = string.Empty;
                UI.mulFunText.text  = string.Empty;
            }
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, weapon.GemSlotAmout > 0);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, weapon.GemSlotAmout > 1);
            ZetanUtility.SetActive(UI.durability.gameObject, true);
            if (PlayerManager.Instance.PlayerInfo.HasPrimaryWeapon)
            {
                OpenSubItemWindow(PlayerManager.Instance.PlayerInfo.primaryWeapon);
            }
            else if (PlayerManager.Instance.PlayerInfo.HasSecondaryWeapon)
            {
                OpenSubItemWindow(PlayerManager.Instance.PlayerInfo.secondaryWeapon);
            }
            break;

        case ItemType.Bag:
            UI.effectText.text = GameManager.BackpackName + "容量+" + (MItemInfo.item as BagItem).ExpandSize;
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;

        case ItemType.Box:
            UI.effectText.text = string.Empty;
            BoxItem box = MItemInfo.item as BoxItem;
            UI.mulFunTitle.text = "-内含物品";
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, true);
            System.Text.StringBuilder itemsInfo = new System.Text.StringBuilder();
            for (int i = 0; i < box.ItemsInBox.Count; i++)
            {
                itemsInfo.Append("[" + box.ItemsInBox[i].ItemName + "] × " + box.ItemsInBox[i].Amount);
                if (i != box.ItemsInBox.Count - 1)
                {
                    itemsInfo.Append("\n");
                }
            }
            UI.mulFunText.text = itemsInfo.ToString();
            ZetanUtility.SetActive(UI.mulFunText.gameObject, true);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;

        default:
            UI.effectText.text = string.Empty;
            ZetanUtility.SetActive(UI.mulFunTitle.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunText.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_1.gameObject, false);
            ZetanUtility.SetActive(UI.gemstone_2.gameObject, false);
            ZetanUtility.SetActive(UI.durability.gameObject, false);
            CloseSubWindow();
            break;
        }
        //UI.window.alpha = 1;
#if UNITY_STANDALONE
        UI.window.blocksRaycasts = false;
#elif UNITY_ANDROID
        //UI.window.blocksRaycasts = true;
        ZetanUtility.SetActive(UI.buttonsArea, true);
        UI.mulFunButton.onClick.RemoveAllListeners();
        ZetanUtility.SetActive(UI.closeButton.gameObject, true);
        UI.priceTitle.text = "贩卖价格";
#endif
        switch (itemAgentType)
        {
        case ItemAgentType.Backpack:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, MItemInfo.item.DiscardAble);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, false);
            UI.mulFunButton.onClick.RemoveAllListeners();
            if (!WarehouseManager.Instance.IsUIOpen && !ShopManager.Instance.IsUIOpen && !ItemSelectionManager.Instance.IsUIOpen)
            {
                if (MItemInfo.item.Usable)
                {
                    ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                    UI.mulFunButton.GetComponentInChildren <Text>().text = MItemInfo.item.IsEquipment ? "装备" : "使用";
                    UI.mulFunButton.onClick.AddListener(UseCurrenItem);
                }
            }
            else if (WarehouseManager.Instance.IsUIOpen)
            {
                ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                UI.mulFunButton.GetComponentInChildren <Text>().text = "存入";
                UI.mulFunButton.onClick.AddListener(StoreCurrentItem);
            }
            else if (ShopManager.Instance.IsUIOpen)
            {
                if (MItemInfo.item.SellAble)
                {
                    ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                    UI.mulFunButton.GetComponentInChildren <Text>().text = "出售";
                    UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
                }
                ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            }
            else if (ItemSelectionManager.Instance.IsUIOpen)
            {
                switch (ItemSelectionManager.Instance.SelectionType)
                {
                case ItemSelectionType.Discard:
                    if (MItemInfo.item.DiscardAble)
                    {
                        ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                        UI.mulFunButton.GetComponentInChildren <Text>().text = "选取";
                        UI.mulFunButton.onClick.AddListener(delegate
                        {
                            if (ItemSelectionManager.Instance.Place(MItemInfo))
                            {
                                CloseWindow();
                            }
                        });
                    }
                    break;

                case ItemSelectionType.Gift:
                    break;

                case ItemSelectionType.Making:
                    if (MItemInfo.item.MaterialType != MaterialType.None)
                    {
                        ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
                        UI.mulFunButton.GetComponentInChildren <Text>().text = "选取";
                        UI.mulFunButton.onClick.AddListener(delegate
                        {
                            if (ItemSelectionManager.Instance.Place(MItemInfo))
                            {
                                CloseWindow();
                            }
                        });
                    }
                    break;

                case ItemSelectionType.None:
                default:
                    break;
                }
                ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            }
#endif
            break;

        case ItemAgentType.Warehouse:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeOutCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "取出";
#endif
            break;

        case ItemAgentType.Making:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, MItemInfo.Amount > 0);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(MakeCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "制作";
#endif
            break;

        case ItemAgentType.Selling:
            UI.priceTitle.text = "售价";
            if (ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo))
            {
                UI.priceText.text = ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo).merchandiseInfo.SellPrice.ToString() + GameManager.CoinName;
            }
            else
            {
                CloseWindow();
            }
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "购买";
#endif
            break;

        case ItemAgentType.Purchasing:
            UI.priceTitle.text = "收购价";
            if (ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo))
            {
                UI.priceText.text = ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo).merchandiseInfo.PurchasePrice.ToString() + GameManager.CoinName;
            }
            else
            {
                CloseWindow();
            }
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, BackpackManager.Instance.GetItemAmount(MItemInfo.ItemID) > 0);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(SellOrPurchaseCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "出售";
#endif
            break;

        case ItemAgentType.Loot:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "拾取";
#endif
            break;

        case ItemAgentType.Selection:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, true);
            UI.mulFunButton.onClick.RemoveAllListeners();
            UI.mulFunButton.onClick.AddListener(TakeOutCurrentItem);
            UI.mulFunButton.GetComponentInChildren <Text>().text = "取出";
#endif
            break;

        default:
#if UNITY_ANDROID
            ZetanUtility.SetActive(UI.buttonsArea.gameObject, false);
            ZetanUtility.SetActive(UI.closeButton.gameObject, true);
#endif
            ZetanUtility.SetActive(UI.discardButton.gameObject, false);
            ZetanUtility.SetActive(UI.mulFunButton.gameObject, false);
            UI.mulFunButton.onClick.RemoveAllListeners();
            break;
        }
    }