Пример #1
0
        public void RequestBattleEnd(MsgPack msgPack)
        {
            RequestBattleEnd data = msgPack.Msg.RequestBattleEnd;

            NetMsg netMsg = new NetMsg
            {
                cmd = (int)Command.ResponseBattleEnd
            };

            //校验战斗是否合法
            if (data.IsWin)
            {
                if (data.CostTime > 0 && data.RestHp > 0)
                {
                    //获取战斗副本相应的奖励
                    MapCfg     mapCfg     = _resCfgSvc.GetMapData(data.BattleId);
                    PlayerData playerData = _cacheSvc.GetPlayerDataBySession(msgPack.Session);

                    TaskSys.Instance.CalcTaskPrangs(playerData, 2);
                    playerData.Coin    += mapCfg.Coin;
                    playerData.Crystal += mapCfg.Crystal;

                    PeRoot.CalcExp(playerData, mapCfg.Exp);

                    if (playerData.Battle == data.BattleId)
                    {
                        playerData.Battle += 1;
                    }

                    if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData))
                    {
                        netMsg.err = (int)ErrorCode.UpdateDbError;
                    }
                    else
                    {
                        ResponseBattleEnd battleEnd = new ResponseBattleEnd
                        {
                            IsWin    = data.IsWin,
                            Battle   = data.BattleId,
                            CostTime = data.CostTime,
                            RestHp   = data.RestHp,


                            Coin     = playerData.Coin,
                            Level    = playerData.Level,
                            Exp      = playerData.Exp,
                            Crystal  = playerData.Crystal,
                            BattleId = playerData.Battle,
                        };
                        netMsg.ResponseBattleEnd = battleEnd;
                    }
                }
            }
            else
            {
                netMsg.err = (int)ErrorCode.ClientDataError;
            }
            msgPack.Session.SendMsg(netMsg);
        }
Пример #2
0
        public void RequestTaskReward(MsgPack msgPack)
        {
            RequestTask data   = msgPack.Msg.RequestTask;
            NetMsg      netMsg = new NetMsg
            {
                cmd = (int)Command.ResponseTask
            };
            PlayerData playerData = _cacheSvc.GetPlayerDataBySession(msgPack.Session);

            TaskRewardCfg  taskCfg  = _resCfgSvc.GetTaskData(data.TaskId);
            TaskRewardData taskData = CalcTaskRewardData(playerData, data.TaskId);

            if (taskData.Prangs == taskCfg.Count && !taskData.Tasked)
            {
                playerData.Coin += taskCfg.Coin;
                PeRoot.CalcExp(playerData, taskCfg.Exp);
                playerData.Diamond += taskCfg.Diamond;
                taskData.Tasked     = true;
                CalcTaskArray(playerData, taskData);

                if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData))
                {
                    netMsg.err = (int)ErrorCode.UpdateDbError;
                }
                else
                {
                    ResponseTask responseTask = new ResponseTask
                    {
                        Coin      = playerData.Coin,
                        Level     = playerData.Level,
                        Diamond   = playerData.Diamond,
                        Exp       = playerData.Exp,
                        TaskArray = playerData.TaskArray,
                    };
                    netMsg.ResponseTask = responseTask;
                }
            }
            else
            {
                netMsg.err = (int)ErrorCode.ClientDataError;
            }

            msgPack.Session.SendMsg(netMsg);
        }
Пример #3
0
        public void RequestGuide(MsgPack pack)
        {
            RequestGuide data   = pack.Msg.RequestGuide;
            NetMsg       netMsg = new NetMsg
            {
                cmd = (int)Command.RspGuide
            };
            PlayerData playerData = _cacheSvc.GetPlayerDataBySession(pack.Session);
            GuideCfg   guideCfg   = _resCfgSvc.GetGuideData(data.GuideId);

            //更新引导Id
            if (playerData.GuideId == data.GuideId)
            {
                if (playerData.GuideId == 1001)
                {
                    TaskSys.Instance.CalcTaskPrangs(playerData, 1);
                }
                playerData.GuideId += 1;

                //更新玩家数据
                playerData.Coin += guideCfg.Coin;
                PeRoot.CalcExp(playerData, guideCfg.Exp);
                if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData))
                {
                    netMsg.err = (int)ErrorCode.UpdateDbError;
                }
                else
                {
                    netMsg.ResponseGuide = new ResponseGuide
                    {
                        GuideId = playerData.GuideId,
                        Coin    = playerData.Coin,
                        Level   = playerData.Level,
                        Exp     = playerData.Exp,
                    };
                }
            }
            else
            {
                netMsg.err = (int)ErrorCode.ServerDataError;
            }
            pack.Session.SendMsg(netMsg);
        }