Exemplo n.º 1
0
    private void OnReqBuy(UserToken token, SocketModel model)
    {
        ReqBuy      req = SerializeUtil.Deserialize <ReqBuy>(model.message);
        AccountData acc = CacheManager.instance.GetAccount(token.accountid);
        ItemCfg     cfg = ConfigManager.instance.items[req.itemid];

        if (acc.diamond < cfg.Price)
        {
            TipsError tips = new TipsError();
            tips.code = (int)ECode.EBuyError;
            NetworkManager.Send <TipsError>(token, (int)MsgID.TipError, tips);
        }
        else
        {
            acc.diamond -= cfg.Price;

            ItemData item = new ItemData();
            item.account = token.accountid;
            item.itemid  = req.itemid;
            item.count   = 1;
            CacheManager.instance.AddItem(token.accountid, item);

            RspBuy rsp = new RspBuy();
            rsp.diamond      = acc.diamond;
            rsp.item         = new ItemDTO();
            rsp.item.id      = item.Id;
            rsp.item.account = item.account;
            rsp.item.itemid  = item.itemid;
            rsp.item.count   = item.count;
            rsp.item.slot    = item.slot;

            NetworkManager.Send <RspBuy>(token, (int)MsgID.RspBuy, rsp);
        }
    }
Exemplo n.º 2
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy  data = pack.msg.reqBuy;
        GameMsg msg  = new GameMsg {
            cmd = (int)CMD.RspBuy
        };

        PlayerData playerData = cacheSvc.GetPlayerDataBySession(pack.session);

        if (playerData.diamond < data.cost)
        {
            msg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            playerData.diamond -= data.cost;
            PshTaskPrgs pshTaskPrgs = null;
            switch (data.type)
            {
            case 0:

                playerData.power += 100;
                // 任务进度更新
                pshTaskPrgs = TaskSys.Instance.GetCalcTaskPrgs(playerData, 4);
                break;

            case 1:

                playerData.coin += 1000;
                // 任务进度更新
                pshTaskPrgs = TaskSys.Instance.GetCalcTaskPrgs(playerData, 5);
                break;
            }

            if (cacheSvc.UpdatePlayerData(playerData.id, playerData) == false)
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                RspBuy rspBuy = new RspBuy
                {
                    type    = data.type,
                    diamond = playerData.diamond,
                    coin    = playerData.coin,
                    power   = playerData.power
                };

                msg.rspBuy = rspBuy;

                // 并包处理
                msg.pshTaskPrgs = pshTaskPrgs;
            }
        }


        pack.session.SendMsg(msg);
    }
Exemplo n.º 3
0
    private void OnBuy(PointerEventData ped)
    {
        int    itemid = int.Parse(ped.selectedObject.name);
        ReqBuy req    = new ReqBuy();

        req.itemid = itemid;

        NetClient.instance.Send <ReqBuy>((int)MsgID.ReqBuy, req);
    }
Exemplo n.º 4
0
    public void ClickSureBtn()
    {
        GameEntry.Sound.PlayUISound(Constants.UIClickBtn);
        //发送网络购买消息
        CSPacketBase msg = new ReqBuy {
            Type = buyType,
            Cost = 10
        };

        GameEntry.Net.SendMsg(msg);
        btnSure.interactable = false;
    }
Exemplo n.º 5
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy     data = (ReqBuy)pack.msg;
        RspBuy     msg  = new RspBuy();
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);

        if (pd.Diamond < data.Cost)
        {
            msg.error = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.Diamond -= data.Cost;
            PshTaskPrgs pshTaskPrgs = null;
            switch (data.Type)
            {
            case 0:
                pd.Power += 100;
                //任务进度数据更新
                pshTaskPrgs = TaskSys.Instance.GetTaskPrgs(pd, 4);
                break;

            case 1:
                pd.Coin += 1000;
                //任务进度数据更新
                pshTaskPrgs = TaskSys.Instance.GetTaskPrgs(pd, 5);
                break;
            }

            if (!cacheSvc.UpdatePlayerData(pd.Id, pd))
            {
                msg.error = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                RspBuy rspBuy = new RspBuy {
                    Type   = data.Type,
                    Dimond = pd.Diamond,
                    Coin   = pd.Coin,
                    Power  = pd.Power
                };
                msg = rspBuy;

                //并包处理
                //msg.pshTaskPrgs = pshTaskPrgs;
                if (pshTaskPrgs != null)
                {
                    pack.session.SendMsg(pshTaskPrgs);
                }
            }
        }
        pack.session.SendMsg(msg);
    }
Exemplo n.º 6
0
        public void ReqBuy(MsgPack pack)
        {
            ReqBuy data = pack.msg.reqBuy;

            GameMsg msg = new GameMsg
            {
                cmd = (int)CMD.RspBuy,
            };

            PlayerData pd = cacheSev.GetPlayerDataBySession(pack.session);

            switch (data.type)
            {
            case 0:
                msg.pshTaskPrgs = TaskSystem.Instance.CalcTaskPrg(pd, 4);
                break;

            case 1:
                msg.pshTaskPrgs = TaskSystem.Instance.CalcTaskPrg(pd, 5);
                break;
            }

            if (pd.diamond < data.cost)
            {
                msg.err = (int)ErrorCode.LackDiamond;
                pack.session.SendMsg(msg);
                return;
            }
            pd.diamond -= data.cost;
            switch (data.type)
            {
            case 0:
                pd.power += 100;
                break;

            case 1:
                pd.coin += 1000;
                break;
            }
            if (!cacheSev.UpdatePlayerData(pd))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
                pack.session.SendMsg(msg);
            }
            msg.rspBuy = new RspBuy
            {
                type   = data.type,
                coin   = pd.coin,
                power  = pd.power,
                dimond = pd.diamond
            };
            pack.session.SendMsg(msg);
        }
Exemplo n.º 7
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy data = pack.msg.reqBuy;

        GameMsg msg = new GameMsg
        {
            cmd = (int)CMD.RspBuy,
        };

        PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.session);

        if (pd.diamond < data.diamond)
        {
            msg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.diamond -= 10;
            switch (data.type)
            {
            case 0:
                //购买体力
                pd.power += 100;
                //更新任务进度
                TaskSys.Instance.CalcTaskPrgs(pd, 4);
                break;

            case 1:
                //购买金币
                pd.coin += 1000;
                //更新任务进度
                TaskSys.Instance.CalcTaskPrgs(pd, 5);
                break;
            }

            if (!DBMgr.Instance.UpdatePlayerData(pd.id, pd))
            {
                msg.err = (int)ErrorCode.ServerDataError;
            }
            else
            {
                msg.rspBuy = new RspBuy
                {
                    type    = data.type,
                    diamond = pd.diamond,
                    power   = pd.power,
                    coin    = pd.coin,
                };
            }
        }
        pack.session.SendMsg(msg);
    }
Exemplo n.º 8
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy  data = pack.msg.reqBuy;
        GameMsg msg  = new GameMsg
        {
            cmd = (int)CMD.RspBuy,
        };

        PlayerData pd = CacheSvc.Instance.GetPlayerDataBySession(pack.session);

        if (pd.diamond < data.cost)
        {
            msg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.diamond -= data.cost;
            switch (data.buyType)
            {
            case 0:                                   //体力
                pd.power += 100;
                TaskSys.Instance.CalcTaskPrgs(pd, 4); //更新任务进度数据
                break;

            case 1:                                   //金币
                pd.coin += 1000;
                TaskSys.Instance.CalcTaskPrgs(pd, 5); //更新任务进度数据
                break;
            }

            if (!CacheSvc.Instance.UpdatePlayerData(pd.id, pd, pack.session))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }

            else
            {
                msg.rspBuy = new RspBuy
                {
                    diamond = pd.diamond,
                    coin    = pd.coin,
                    power   = pd.power,
                    buyType = data.buyType,
                };
            }
        }

        pack.session.SendMsg(msg);
    }
Exemplo n.º 9
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy  data = pack.msg.reqBuy;
        GameMsg msg  = new GameMsg {
            cmd = (int)CMD.RspBuy
        };
        PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.session);

        if (pd.diamond < data.cost)
        {
            msg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.diamond -= data.cost;
            PshTaskPrgs pshTaskPrgs = null;
            switch (data.type)
            {
            case 0:
                pd.power += 100;
                //TaskSys.Instance.GetTaskPrgs(pd, 4); // 不让他发送了,网络并包流量优化
                pshTaskPrgs = TaskSys.Instance.GetTaskPrgs(pd, 4);     // 任务进度数据更新
                break;

            case 1:
                pd.coin    += 1000;
                pshTaskPrgs = TaskSys.Instance.GetTaskPrgs(pd, 5);     // 任务进度数据更新
                break;
            }
            if (!cacheSvc.UpdatePlayerData(pd.id, pd))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                RspBuy rspBuy = new RspBuy {
                    type   = data.type,
                    dimond = pd.diamond,
                    coin   = pd.coin,
                    power  = pd.power
                };
                msg.rspBuy = rspBuy;
                // 并包处理
                msg.pshTaskPrgs = pshTaskPrgs;
            }
        }
        pack.session.SendMsg(msg); // 发送的就是合并后的两个包
    }
Exemplo n.º 10
0
    public void ReqBuy(MsgPack pack)
    {
        ReqBuy     data = pack.gameMsg.val as ReqBuy;
        PlayerData pd   = cacheSvc.GetPlayerDataBySession(pack.session);
        GameMsg    msg  = new GameMsg()
        {
            cmd = (int)CMD.RspBuy
        };

        if (pd.diamond < data.cost)
        {
            msg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.diamond -= data.cost;
            switch (data.type)
            {
            case 0:
                TaskSys.Instance.CalcTaskPrgs(pd, 4);
                pd.power += 100;
                break;

            case 1:
                TaskSys.Instance.CalcTaskPrgs(pd, 5);
                pd.coin += 1000;
                break;
            }

            if (!cacheSvc.UpdatePlayerData(pd.id, pd))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                msg.val = new RspBuy()
                {
                    type   = data.type,
                    dimond = pd.diamond,
                    coin   = pd.coin,
                    power  = pd.power
                };
            }
        }
        pack.session.SendMsg(msg);
    }
Exemplo n.º 11
0
    public void HandleReqBuy(MsgPack pack)
    {
        ReqBuy reqData = pack.msg.ReqBuy;

        NetMsg newMsg = new NetMsg
        {
            cmd = (int)MsgType.RspBuy,
        };

        PlayerData pd = CacheSvc.Instance.GetPlayerDataBySession(pack.session);

        if (pd.Diamond < 10)
        {
            newMsg.err = (int)ErrorCode.LackDiamond;
        }
        else
        {
            pd.Diamond -= 10;
            switch (reqData.buyType)
            {
            case (int)CommonBuyType.Coin:
                pd.Coin += 100;
                break;

            case (int)CommonBuyType.Power:
                pd.Power += 50;
                break;
            }
            if (CacheSvc.Instance.UpdatePlayerDataToDB(pd.ID, pd))
            {
                newMsg.RspBuy = new RspBuy
                {
                    buyType = reqData.buyType,
                    data    = pd,
                };
            }
            else
            {
                newMsg.err = (int)ErrorCode.UpdateDBFailed;
            }
        }

        pack.session.SendMsg(newMsg);
    }