/// <summary> /// 处理请求升级逻辑 /// </summary> /// <param name="pack"></param> public void ReqStrong(MsgPack pack) { ReqStrong data = pack.msg.reqStrong; GameMsg msg = new GameMsg { cmd = (int)CMD.RspStrong, }; PlayerData pd = cacheSvc.GetPlayerDataBySettion(pack.session); int curtStartLv = pd.strongArr[data.pos];//请求升级的武器 StrongCfg nextSd = cfgSvc.GetStrongCfg(data.pos, curtStartLv + 1); //数据校验(这是必须的,如果客户端均已校验,则此校验结果可以作为玩家是否作弊的依据) if (pd.lv < nextSd.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextSd.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextSd.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else//校验通过 { //资产变化 pd.coin -= nextSd.coin; pd.crystal -= nextSd.crystal; pd.strongArr[data.pos] += 1; //属性变化 pd.hp += nextSd.addhp; pd.ad += nextSd.addhurt; pd.ap += nextSd.addhurt; pd.addef += nextSd.adddef; pd.apdef += nextSd.adddef; //任务进度更新 TaskSys.Instance.CalcTaskPrgs(pd, 3); //数据库更新 if (cacheSvc.UpdatePlayerData(pd.id, pd)) { msg.rspStrong = new RspStrong { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strongArr = pd.strongArr }; } else { msg.err = (int)ErrorCode.UpdateDbError; } } pack.session.SendMsg(msg); }
/// <summary> /// 回应强化请求 /// </summary> public void ReqStrong(PackMsg pack) { ReqStrong data = pack.msg.reqStrong; ServerSession session = pack.session; GameMsg msg = new GameMsg { cmd = (int)CMD.RspStrong, }; PlayerData playerData = cacheSvc.GetPlayerDataCache(session); if (playerData.strongArr[data.pos] == data.starlv) { int nextStarLv = data.starlv + 1; StrongCfg nextStrongCfg = cfgSvc.GetStrongCfg(data.pos, nextStarLv); if (playerData.lv < nextStrongCfg.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (playerData.coin < nextStrongCfg.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (playerData.crystal < nextStrongCfg.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else { //更新任务进度 PshTaskProgs pshTaskProgs = TaskSys.Instance.CalcTaskProgs(playerData, 3); playerData.hp += nextStrongCfg.addhp; playerData.ad += nextStrongCfg.addhurt; playerData.ap += nextStrongCfg.addhurt; playerData.addef += nextStrongCfg.adddef; playerData.apdef += nextStrongCfg.adddef; playerData.strongArr[data.pos] += 1; playerData.coin -= nextStrongCfg.coin; playerData.crystal -= nextStrongCfg.crystal; if (!cacheSvc.UpdatePlayerData(playerData.id, playerData)) { msg.err = (int)ErrorCode.UpdateDBError; } else { RspStrong rspStrong = new RspStrong { pos = nextStrongCfg.pos, starlv = nextStrongCfg.starlv, addhp = nextStrongCfg.addhp, addhurt = nextStrongCfg.addhurt, adddef = nextStrongCfg.adddef, minlv = nextStrongCfg.minlv, coin = nextStrongCfg.coin, crystal = nextStrongCfg.crystal, strongArr = playerData.strongArr }; msg.rspStrong = rspStrong; if (pshTaskProgs != null) { msg.pshTaskProgs = pshTaskProgs; } } } } else { msg.err = (int)ErrorCode.ServerDataError; } pack.session.SendMsg(msg); }