Exemple #1
0
        private void CalcPowerAdd(int id)
        {
            GameMsg msg = new GameMsg
            {
                cmd      = (int)CMD.PshPower,
                pshPower = new PshPower()
            };

            // 向所有在线玩家推送
            Dictionary <ServerSession, PlayerData> onlineDic = cacheSev.GetOnlinePlayers();

            foreach (var pair in onlineDic)
            {
                PlayerData    pd      = pair.Value;
                ServerSession session = pair.Key;

                int powerMax = NETCommon.GetPowerLimit(pd.lv);
                if (pd.power >= powerMax)
                {
                    continue;
                }

                pd.power += NETCommon.PowerAddCount;
                if (pd.power > powerMax)
                {
                    pd.power = powerMax;
                }

                pd.time = timeSev.GetNowTime();

                if (!cacheSev.UpdatePlayerData(pd))
                {
                    msg.err = (int)ErrorCode.UpdateDBError;
                }
                else
                {
                    msg.pshPower.power = pd.power;
                }
                session.SendMsg(msg);
            }
        }
Exemple #2
0
        public void ReqStrong(MsgPack pack)
        {
            ServerSession session = pack.session;
            ReqStrong     data    = pack.msg.reqStrong;

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

            PlayerData pd      = cacheSev.GetPlayerDataBySession(session);
            int        curStar = pd.strongArr[data.pos];
            StrongCfg  nextSc  = cfgSev.GetStrongCfgData(data.pos, curStar + 1);

            // 条件判断
            if (pd.lv < nextSc.minLv)
            {
                msg.err = (int)ErrorCode.LackLevel;
                session.SendMsg(msg);
                return;
            }
            if (pd.coin < nextSc.coin)
            {
                msg.err = (int)ErrorCode.LackCoin;
                session.SendMsg(msg);
                return;
            }
            if (pd.crystal < nextSc.crystal)
            {
                msg.err = (int)ErrorCode.LackCrystal;
                session.SendMsg(msg);
                return;
            }

            // 资源扣除
            pd.coin    -= nextSc.coin;
            pd.crystal -= nextSc.crystal;

            // 属性增益
            pd.strongArr[data.pos] += 1;
            pd.hp    += nextSc.addHp;
            pd.ad    += nextSc.addHurt * (1 + 1 / (data.pos + 1));
            pd.ap    += nextSc.addHurt;
            pd.addef += nextSc.addDef;
            pd.apdef += nextSc.addDef;

            // 任务进度更新
            msg.pshTaskPrgs = TaskSystem.Instance.CalcTaskPrg(pd, 3);

            // 更新数据库
            if (!cacheSev.UpdatePlayerData(pd))
            {
                msg.err = (int)ErrorCode.UpdateDBError;
                session.SendMsg(msg);
                return;
            }

            // 返回消息
            msg.rspStrong = new RspStrong
            {
                coin      = pd.coin,
                crystal   = pd.crystal,
                hp        = pd.hp,
                ad        = pd.ad,
                ap        = pd.ap,
                adddef    = pd.addef,
                apdef     = pd.apdef,
                strongArr = pd.strongArr
            };
            session.SendMsg(msg);
        }