Exemplo n.º 1
0
    /// <summary>
    /// 卖出(一键卖出)
    /// </summary>
    public static void OnSale(List <GoodsData> goodsDatas, Action <bool, List <int> > saleAction)
    {
        //创建上传数据
        CSGoodSellData goodSellData = new CSGoodSellData();
        List <int>     ids          = new List <int>();

        for (int i = 0; i < goodsDatas.Count; i++)
        {
            CSGoodStruct cSGoodStruct = new CSGoodStruct();
            cSGoodStruct.GoodId = goodsDatas[i]._id;
            goodSellData.GoodSellInfo.Add(cSGoodStruct);
            ids.Add(goodsDatas[i]._id);
        }

        ProtocalManager.Instance().SendCSGoodSellData(goodSellData, (SCGoodSellData data) =>
        {
            saleAction?.Invoke(true, ids);
            //更新玩家的金币和钻石数据
            for (int i = 0; i < data.GoodSellInfo.Count; i++)
            {
                int id = data.GoodSellInfo[i].GoodId;
                StaticData.UpdateWareHouseItems(id, data.GoodSellInfo[i].GoodNum);
            }
            for (int i = 0; i < goodsDatas.Count; i++)
            {
                StaticData.UpdateWareHouseItems(goodsDatas[i]._id, 0);
            }
            Debug.Log("一键卖出成功:" + data.GoodSellInfo.Count);
        }, (ErrorInfo er) =>
        {
            saleAction?.Invoke(false, ids);
            Debug.Log("一键卖出失败:" + er.ErrorMessage);
        });
    }
Exemplo n.º 2
0
    GiveGiftInfo giftInfo = new GiveGiftInfo();//玩家对某个NPC增送的礼物信息
    /// <summary>
    /// 赠送礼物
    /// </summary>
    public void GiveGift(int goodsID, int goodsAmount, int NpcFavorable, int PlayerFavorable)
    {
        bool isGive = false;

        foreach (var item in giftInfo.giftInfo)//赠送礼物列表里有该道具是只增数量
        {
            if (item.GoodId == goodsID)
            {
                isGive = true;
            }
            if (isGive)
            {
                item.GoodNum += goodsAmount;
                break;
            }
        }
        if (!isGive)//礼物列表里没有时添加到列表里
        {
            CSGoodStruct gift = new CSGoodStruct();
            gift.GoodId  = goodsID;
            gift.GoodNum = goodsAmount;
            giftInfo.giftInfo.Add(gift);
        }
        //好感度增加动画TODO
        AddFavorable(goodsAmount, NpcFavorable, PlayerFavorable);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 卖出
    /// </summary>
    public static void OnSale(GoodsData goodsData, int number, Action <bool> saleAction)
    {
        //创建上传数据
        CSGoodSellData goodSellData = new CSGoodSellData();
        CSGoodStruct   cSGoodStruct = new CSGoodStruct();

        //获取当前点击数据
        cSGoodStruct.GoodId  = goodsData._id;
        cSGoodStruct.GoodNum = number;
        goodSellData.GoodSellInfo.Add(cSGoodStruct);

        ProtocalManager.Instance().SendCSGoodSellData(goodSellData, (SCGoodSellData data) =>
        {
            //更新玩家的金币和钻石数据
            for (int i = 0; i < data.GoodSellInfo.Count; i++)
            {
                int id = data.GoodSellInfo[i].GoodId;
                StaticData.UpdateWareHouseItems(id, data.GoodSellInfo[i].GoodNum);
                Debug.Log("刷新金币:" + id + "   Number:" + data.GoodSellInfo[i].GoodNum);
            }
            saleAction(true);
            //修改本地数据
            StaticData.UpdateWareHouseItem(goodsData._id, -number);
            Debug.Log("卖出物品成功ID:" + goodsData._id + "   Number:" + number);
        }, (ErrorInfo er) =>
        {
            saleAction(false);
            Debug.Log("卖出物品失败ID:" + goodsData._id + "   Number:" + number + "  ErrorMessage:" + er.ErrorMessage);
        });
    }