Ejemplo n.º 1
0
    private void SellOrPurchaseCurrentItem()
    {
        MerchandiseAgent agent = ShopManager.Instance.GetMerchandiseAgentByItem(MItemInfo);

        if (agent)
        {
            agent.OnSellOrPurchase();
        }
        else
        {
            ShopManager.Instance.PurchaseItem(MItemInfo);
        }
        CloseWindow();
    }
Ejemplo n.º 2
0
    bool OnPurchase(MerchandiseInfo info, int amount = 1)
    {
        if (MShop == null || info == null || !info.IsValid || amount < 1)
        {
            return(false);
        }
        if (!MShop.Acquisitions.Contains(info))
        {
            return(false);
        }
        var itemAgents = BackpackManager.Instance.GetItemAgentsByItem(info.Item).ToArray();

        if (itemAgents.Length < 1)
        {
            MessageManager.Instance.New(GameManager.BackpackName + "中没有这种物品");
            return(false);
        }
        if (info.EmptyAble && amount > info.LeftAmount)
        {
            if (!info.IsEmpty)
            {
                MessageManager.Instance.New("不收够这么多的这种物品");
            }
            else
            {
                MessageManager.Instance.New("这种物品暂无收购需求");
            }
            return(false);
        }
        ItemBase item = itemAgents[0].MItemInfo.item;

        if (!BackpackManager.Instance.TryLoseItem_Boolean(item, amount))
        {
            return(false);
        }
        BackpackManager.Instance.GetMoney(amount * info.PurchasePrice);
        BackpackManager.Instance.LoseItem(item, amount);
        if (info.EmptyAble)
        {
            info.LeftAmount -= amount;
        }
        MerchandiseAgent ma = merchandiseAgents.Find(x => x.merchandiseInfo == info);

        if (ma)
        {
            ma.UpdateInfo();
        }
        return(true);
    }
Ejemplo n.º 3
0
    bool OnSell(MerchandiseInfo info, int amount = 1)
    {
        if (MShop == null || info == null || !info.IsValid || amount < 1)
        {
            return(false);
        }
        if (!MShop.Commodities.Contains(info))
        {
            return(false);
        }
        if (!BackpackManager.Instance.TryGetItem_Boolean(info.Item, amount))
        {
            return(false);
        }
        if (info.EmptyAble && amount > info.LeftAmount)
        {
            if (!info.IsEmpty)
            {
                MessageManager.Instance.New("该商品数量不足");
            }
            else
            {
                MessageManager.Instance.New("该商品暂时缺货");
            }
            return(false);
        }
        if (!BackpackManager.Instance.TryLoseMoney(amount * info.SellPrice))
        {
            return(false);
        }
        BackpackManager.Instance.LoseMoney(amount * info.SellPrice);
        BackpackManager.Instance.GetItem(info.Item, amount);
        if (info.EmptyAble)
        {
            info.LeftAmount -= amount;
        }
        MerchandiseAgent ma = merchandiseAgents.Find(x => x.merchandiseInfo == info);

        if (ma)
        {
            ma.UpdateInfo();
        }
        return(true);
    }
Ejemplo n.º 4
0
    public void SetPage(int page)
    {
        if (!UI || !UI.gameObject || !MShop)
        {
            return;
        }
        switch (page)
        {
        case 0:
            int originalSize = merchandiseAgents.Count;
            if (MShop.Commodities.Count >= originalSize)
            {
                for (int i = 0; i < MShop.Commodities.Count - originalSize; i++)
                {
                    MerchandiseAgent ma = ObjectPool.Get(UI.merchandiseCellPrefab, UI.merchandiseCellsParent).GetComponent <MerchandiseAgent>();
                    ma.Clear();
                    merchandiseAgents.Add(ma);
                }
            }
            else
            {
                for (int i = 0; i < originalSize - MShop.Commodities.Count; i++)
                {
                    merchandiseAgents[i].Clear(true);
                }
                merchandiseAgents.RemoveAll(x => !x.gameObject.activeSelf);
            }
            foreach (MerchandiseAgent ma in merchandiseAgents)
            {
                ma.Clear();
            }
            foreach (MerchandiseInfo mi in MShop.Commodities)
            {
                foreach (MerchandiseAgent ma in merchandiseAgents)
                {
                    if (ma.IsEmpty && mi.IsValid)
                    {
                        ma.Init(mi, MerchandiseType.SellToPlayer);
                        break;
                    }
                }
            }
            break;

        case 1:
            originalSize = merchandiseAgents.Count;
            int acqCount = MShop.Acquisitions.FindAll(x => x.IsValid && x.Item.SellAble).Count;
            if (acqCount >= originalSize)
            {
                for (int i = 0; i < acqCount - originalSize; i++)
                {
                    MerchandiseAgent ma = ObjectPool.Get(UI.merchandiseCellPrefab, UI.merchandiseCellsParent).GetComponent <MerchandiseAgent>();
                    ma.Clear();
                    merchandiseAgents.Add(ma);
                }
            }
            else
            {
                for (int i = 0; i < originalSize - acqCount; i++)
                {
                    merchandiseAgents[i].Clear(true);
                }
                merchandiseAgents.RemoveAll(x => !x.gameObject.activeSelf);
            }
            foreach (MerchandiseAgent ma in merchandiseAgents)
            {
                ma.Clear();
            }
            foreach (MerchandiseInfo mi in MShop.Acquisitions)
            {
                foreach (MerchandiseAgent ma in merchandiseAgents)
                {
                    if (ma.IsEmpty && mi.IsValid && mi.Item.SellAble)
                    {
                        ma.Init(mi, MerchandiseType.BuyFromPlayer);
                        break;
                    }
                }
            }
            break;

        default: break;
        }
        ItemWindowManager.Instance.CloseWindow();
    }