Beispiel #1
0
    public void ReqTakeTaskReward(MsgPack pack)
    {
        ReqTakeTaskReward data = pack.Msg.reqTakeTaskReward;

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

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

        TaskRewardCfg  trc = cfgSvc.GetTaskRewardCfg(data.tid);
        TaskRewardData trd = CalcTaskRewardData(pd, data.tid);


        if (trd.prgs == trc.count && !trd.taked)
        {
            pd.coin += trc.coin;
            PECommon.CalcExp(pd, trc.exp);
            trd.taked = true;
            //更新任务进度数据
            CalcTaskArr(pd, trd);

            if (!cacheSvc.UpdatePlayerData(pd.id, pd))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                RspTakeTaskReward rspTakeTaskReward = new RspTakeTaskReward()
                {
                    coin    = pd.coin,
                    lv      = pd.lv,
                    exp     = pd.exp,
                    taskArr = pd.taskArr
                };
                msg.rspTakeTaskReward = rspTakeTaskReward;
            }
        }
        else
        {
            msg.err = (int)ErrorCode.ClientDataError;
        }

        pack.Session.SendMsg(msg);
    }
Beispiel #2
0
    public void ReqTakeTaskReward(PackMsg pack)
    {
        ReqTakeTaskReward data    = pack.msg.reqTakeTaskReward;
        ServerSession     session = pack.session;
        GameMsg           msg     = new GameMsg
        {
            cmd = (int)CMD.RspTakeTaskReward,
        };
        int        rewardID   = data.rid;
        PlayerData playerData = cacheSvc.GetPlayerDataCache(session);

        TaskRewardCfg  trc = cfgSvc.GetTaskRewardCfg(rewardID);
        TaskRewardData trd = GetTaskRewardData(playerData, rewardID);

        //安全验证
        if (trd.progress == trc.count && !trd.taked)
        {
            playerData.coin += trc.coin;
            PECommon.UpdateExp(playerData, trc.exp);
            trd.taked = true;
            //更新任务进度数据
            CalcTaskArr(playerData, trd);

            if (!cacheSvc.UpdatePlayerData(playerData.id, playerData))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                msg.rspTakeTaskReward = new RspTakeTaskReward
                {
                    coin    = playerData.coin,
                    exp     = playerData.exp,
                    lv      = playerData.lv,
                    hp      = playerData.hp,
                    taskArr = playerData.taskArr,
                };
                session.SendMsg(msg);
            }
        }
        else
        {
            msg.err = (int)ErrorCode.ClientDataError;
        }
    }
Beispiel #3
0
    public void ReqTakeTaskReward(MsgPack pack)
    {
        ReqTakeTaskReward data = pack.msg.reqTakeTaskReward;

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

        PlayerData     playerData = cacheSvc.GetPlayerDataBySession(pack.session);
        TaskRewardCfg  trc        = cfgSvc.GetTaskRewardCfg(data.rid);
        TaskRewardData trd        = CalcTaskRewardData(playerData, data.rid);

        if (trd.prgs == trc.count && trd.isTakenReward == false)
        {
            playerData.coin += trc.coin;
            Common.CalcExp(playerData, trc.exp);
            trd.isTakenReward = true;

            // 更新任务进度数据
            CalcTaskArr(playerData, trd);

            if (cacheSvc.UpdatePlayerData(playerData.id, playerData) == true)
            {
                RspTakeTaskReward rspTakeTaskReward = new RspTakeTaskReward {
                    coin    = playerData.coin,
                    lv      = playerData.lv,
                    exp     = playerData.exp,
                    taskArr = playerData.taskArr
                };

                msg.rspTakeTaskReward = rspTakeTaskReward;
            }
            else
            {
                msg.err = (int)ErrorCode.UpdateDBError;
            }
        }
        else
        {
            msg.err = (int)ErrorCode.ClientDataError;
        }

        pack.session.SendMsg(msg);
    }
Beispiel #4
0
    public void ReqTakeTaskReward(MsgPack pack)
    {
        ReqTakeTaskReward data = (ReqTakeTaskReward)pack.msg;

        SCPacketBase msg = new RspTakeTaskReward();
        PlayerData   pd  = cacheSvc.GetPlayerDataBySession(pack.session);

        TaskRewardCfg  trc = cfgSvc.GetTaskRewardCfg(data.Rid);
        TaskRewardData trd = CalcTaskRewardData(pd, data.Rid);

        if (trd.prgs == trc.count && !trd.taked)
        {
            pd.Coin += trc.coin;
            KDCommon.CalcExp(pd, trc.exp);
            trd.taked = true;
            //更新任务进度数据
            CalcTaskArr(pd, trd);

            if (!cacheSvc.UpdatePlayerData(pd.Id, pd))
            {
                msg.error = (int)ErrorCode.UpdateDBError;
            }
            else
            {
                RspTakeTaskReward rspTakeTaskReward = new RspTakeTaskReward {
                    Coin = pd.Coin,
                    Lv   = pd.Lv,
                    Exp  = pd.Exp,
                };
                rspTakeTaskReward.TaskArr.SetRepeated <string>(pd.TaskArr);
                msg = rspTakeTaskReward;
            }
        }
        else
        {
            msg.error = (int)ErrorCode.ClientDataError;
        }
        pack.session.SendMsg(msg);
    }