コード例 #1
0
        // 方便GM命令
        public static List <LingYuData> GetLingYuList(GameClient client)
        {
            List <LingYuData> dataList = new List <LingYuData>();

            Dictionary <int, LingYuType> .KeyCollection keys = LingYuManager.LingYuTypeDict.Keys;
            foreach (int type in keys)
            {
                LingYuData lyData = null;
                lock (client.ClientData.LingYuDict)
                {
                    if (!client.ClientData.LingYuDict.TryGetValue(type, out lyData))
                    {
                        lyData       = new LingYuData();
                        lyData.Type  = type;
                        lyData.Level = DEFAULT_LINGYU_LEVEL;
                        lyData.Suit  = 0;
                    }
                }
                dataList.Add(lyData);
            }
            return(dataList);
        }
コード例 #2
0
        /// <summary>
        /// 翎羽功能开启时,执行初始化,因为默认是1级0阶
        /// 1级时已经有属性加成
        /// </summary>
        /// <param name="client"></param>
        public static void InitAsOpened(GameClient client)
        {
            Dictionary <int, LingYuType> .KeyCollection keys = LingYuManager.LingYuTypeDict.Keys;
            foreach (int type in keys)
            {
                lock (client.ClientData.LingYuDict)
                {
                    if (!client.ClientData.LingYuDict.ContainsKey(type))
                    {
                        LingYuData data = new LingYuData()
                        {
                            Type  = type,
                            Level = DEFAULT_LINGYU_LEVEL,
                            Suit  = 0
                        };
                        UpdateLingYu2DB(client.ClientData.RoleID, type, 1, 0, client.ServerId);
                        client.ClientData.LingYuDict[type] = data;
                    }
                }
            }

            UpdateLingYuProps(client);
        }
コード例 #3
0
        public static LingYuError AdvanceLingYuSuit(GameClient client, int roleID, int type, int useZuanshiIfNoMaterial)
        {
            if (!GlobalNew.IsGongNengOpened(client, GongNengIDs.WingLingYu))
            {
                return(LingYuError.NotOpen);
            }

            LingYuType lyType = null;

            if (!LingYuTypeDict.TryGetValue(type, out lyType))
            {
                //找不到该翎羽
                return(LingYuError.ErrorParams);
            }

            LingYuData lyData = null;

            lock (client.ClientData.LingYuDict)
            {
                if (!client.ClientData.LingYuDict.TryGetValue(type, out lyData))
                {
                    lyData       = new LingYuData();
                    lyData.Type  = type;
                    lyData.Level = DEFAULT_LINGYU_LEVEL;
                    lyData.Suit  = 0;
                }
            }

            //已满阶
            if (lyData.Suit == LingYuSuitLimit)
            {
                return(LingYuError.SuitFull);
            }

            //需要提升等级
            if (lyData.Level == 0 || lyData.Level / 10 == lyData.Suit)
            {
                return(LingYuError.NeedLevelUp);
            }

            LingYuSuit nextSuit = null;

            if (!lyType.SuitDict.TryGetValue(lyData.Suit + 1, out nextSuit)) //找不到下一阶配置
            {
                return(LingYuError.ErrorConfig);
            }

            if (Global.GetTotalBindTongQianAndTongQianVal(client) < nextSuit.JinBiCost)
            {
                return(LingYuError.SuitUpJinBiNotEnough);
            }

            int haveGoodsCnt = Global.GetTotalGoodsCountByID(client, nextSuit.GoodsCost);

            if (haveGoodsCnt < nextSuit.GoodsCostCnt && useZuanshiIfNoMaterial == 0)
            {
                return(LingYuError.SuitUpMaterialNotEnough);
            }

            //  本来的处理方式是,假设要消耗10个材料,现在玩家只有5个材料,并且勾选了使用钻石
            //  那么将会消耗玩家的这5个材料,不足的5个材料使用钻石替补

            /*
             * int goodsCostCnt = nextSuit.GoodsCostCnt;
             * int zuanshiCost = 0;
             * if (haveGoodsCnt < nextSuit.GoodsCostCnt)
             * {
             *  goodsCostCnt = haveGoodsCnt;
             *  int goodsPrice = 0;
             *  if (!Data.LingYuMaterialZuanshiDict.TryGetValue(nextSuit.GoodsCost, out goodsPrice))
             *      return LingYuError.ErrorConfig;
             *  zuanshiCost = (nextSuit.GoodsCostCnt - haveGoodsCnt) * goodsPrice;
             *  if (client.ClientData.UserMoney < zuanshiCost)
             *      return LingYuError.ZuanShiNotEnough;
             * }
             */

            //  现在的处理方式是,假设要消耗10个材料,现在玩家只有5个材料,并且勾选了使用钻石
            //  那么直接扣除10个材料的钻石价格,玩家的5个材料不消耗
            int goodsCostCnt = nextSuit.GoodsCostCnt;
            int zuanshiCost  = 0;

            if (haveGoodsCnt < nextSuit.GoodsCostCnt)
            {
                goodsCostCnt = 0;
                int goodsPrice = 0;
                if (!Data.LingYuMaterialZuanshiDict.TryGetValue(nextSuit.GoodsCost, out goodsPrice))
                {
                    return(LingYuError.ErrorConfig);
                }
                zuanshiCost = nextSuit.GoodsCostCnt * goodsPrice;
                if (client.ClientData.UserMoney < zuanshiCost)
                {
                    return(LingYuError.ZuanShiNotEnough);
                }
            }

            //先扣钱
            if (!Global.SubBindTongQianAndTongQian(client, nextSuit.JinBiCost, "翎羽升阶消耗"))
            {
                return(LingYuError.DBSERVERERROR);
            }

            //有可能出现消耗一部分材料,其余用钻石购买的情况
            if (goodsCostCnt > 0)
            {
                bool bUsedBinding     = false;
                bool bUsedTimeLimited = false;

                if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener,
                                                          Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, nextSuit.GoodsCost, goodsCostCnt, false, out bUsedBinding, out bUsedTimeLimited))
                {
                    return(LingYuError.DBSERVERERROR);
                }
            }

            if (zuanshiCost > 0)
            {
                //先DBServer请求扣费  扣除用户点卷
                if (!GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, zuanshiCost, "翎羽升级"))
                {
                    return(LingYuError.DBSERVERERROR);
                }
            }

            //生效,计算属性加成,写数据库
            int iRet = UpdateLingYu2DB(roleID, type, lyData.Level, lyData.Suit + 1, client.ServerId);

            if (iRet < 0)
            {
                return(LingYuError.DBSERVERERROR);
            }

            lyData.Suit++;
            lock (client.ClientData.LingYuDict)
            {
                client.ClientData.LingYuDict[type] = lyData;
            }

            if (LingYuManager.SuitOfNotifyList.Contains(lyData.Suit))
            {
                // 【{0}】将【{1}】提升到{2}阶,翅膀的力量得到了提升。
                string broadcastMsg = StringUtil.substitute(Global.GetLang("【{0}】将【{1}】提升到{2}阶,翅膀的力量得到了提升。"),
                                                            Global.FormatRoleName(client, client.ClientData.RoleName), lyType.Name, lyData.Suit);
                //播放用户行为消息
                Global.BroadcastRoleActionMsg(client, RoleActionsMsgTypes.HintMsg, broadcastMsg, true, GameInfoTypeIndexes.Hot, ShowGameInfoTypes.OnlySysHint);
            }

            UpdateLingYuProps(client);
            // 通知客户端属性变化
            GameManager.ClientMgr.NotifyUpdateEquipProps(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, client);
            // 总生命值和魔法值变化通知(同一个地图才需要通知)
            GameManager.ClientMgr.NotifyOthersLifeChanged(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, client);

            return(LingYuError.Success);
        }
コード例 #4
0
        public static TCPProcessCmdResults ProcessAdvanceLingYuLevel(
            TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool,
            TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            string[] fields = null;
            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                fields = cmdData.Split(':');
                //角色id:翎羽Type:材料不足时消耗钻石
                if (fields.Length != 3)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int        roleID = Convert.ToInt32(fields[0]);
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int type = Convert.ToInt32(fields[1]);
                int useZuanshiIfNoMaterial = Convert.ToInt32(fields[2]);

                LingYuError lyError = LingYuManager.AdvanceLingYuLevel(client, roleID, type, useZuanshiIfNoMaterial);
                LingYuData  lyData  = null;
                lock (client.ClientData.LingYuDict)
                {
                    if (!client.ClientData.LingYuDict.TryGetValue(type, out lyData))
                    {
                        lyData       = new LingYuData();
                        lyData.Type  = type;
                        lyData.Level = DEFAULT_LINGYU_LEVEL;
                        lyData.Suit  = 0;
                    }
                }

                string strcmd = string.Format("{0}:{1}:{2}:{3}", roleID, (int)lyError, lyData.Type, lyData.Level);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, strcmd, nID);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "ProcessAdvanceLingYuLevel", false);
            }

            return(TCPProcessCmdResults.RESULT_DATA);
        }
コード例 #5
0
        public static LingYuError AdvanceLingYuLevel(GameClient client, int roleID, int type, int useZuanshiIfNoMaterial)
        {
            if (!GlobalNew.IsGongNengOpened(client, GongNengIDs.WingLingYu))
            {
                return(LingYuError.NotOpen);
            }

            LingYuType lyType = null;

            if (!LingYuTypeDict.TryGetValue(type, out lyType))
            {
                //找不到该翎羽
                return(LingYuError.ErrorParams);
            }

            LingYuData lyData = null;

            lock (client.ClientData.LingYuDict)
            {
                if (!client.ClientData.LingYuDict.TryGetValue(type, out lyData))
                {
                    lyData       = new LingYuData();
                    lyData.Type  = type;
                    lyData.Level = DEFAULT_LINGYU_LEVEL;
                    lyData.Suit  = 0;
                }
            }

            //已满级
            if (lyData.Level == LingYuLevelLimit)
            {
                return(LingYuError.LevelFull);
            }

            //需要提升品阶
            if (lyData.Level > 0 && lyData.Level % 10 == 0 && lyData.Level / 10 != lyData.Suit)
            {
                return(LingYuError.NeedSuitUp);
            }

            LingYuLevel nextLevel = null;

            if (!lyType.LevelDict.TryGetValue(lyData.Level + 1, out nextLevel)) //找不到下一级配置
            {
                return(LingYuError.ErrorConfig);
            }

            if (Global.GetTotalBindTongQianAndTongQianVal(client) < nextLevel.JinBiCost)
            {
                return(LingYuError.LevelUpJinBiNotEnough);
            }

            int haveGoodsCnt = Global.GetTotalGoodsCountByID(client, nextLevel.GoodsCost);

            if (haveGoodsCnt < nextLevel.GoodsCostCnt && useZuanshiIfNoMaterial == 0)
            {
                return(LingYuError.LevelUpMaterialNotEnough);
            }

            //  本来的处理方式是,假设要消耗10个材料,现在玩家只有5个材料,并且勾选了使用钻石
            //  那么将会消耗玩家的这5个材料,不足的5个材料使用钻石替补

            /*
             * int goodsCostCnt = nextLevel.GoodsCostCnt;
             * int zuanshiCost = 0;
             * if (haveGoodsCnt < nextLevel.GoodsCostCnt)
             * {
             *  goodsCostCnt = haveGoodsCnt;
             *  int goodsPrice = 0;
             *  if (!Data.LingYuMaterialZuanshiDict.TryGetValue(nextLevel.GoodsCost, out goodsPrice))
             *      return LingYuError.ErrorConfig;
             *  zuanshiCost = (nextLevel.GoodsCostCnt - haveGoodsCnt) * goodsPrice;
             *  if (client.ClientData.UserMoney < zuanshiCost)
             *      return LingYuError.ZuanShiNotEnough;
             * }
             */

            //  现在的处理方式是,假设要消耗10个材料,现在玩家只有5个材料,并且勾选了使用钻石
            //  那么直接扣除10个材料的钻石价格,玩家的5个材料不消耗
            int goodsCostCnt = nextLevel.GoodsCostCnt;
            int zuanshiCost  = 0;

            if (haveGoodsCnt < nextLevel.GoodsCostCnt)
            {
                goodsCostCnt = 0;
                int goodsPrice = 0;
                if (!Data.LingYuMaterialZuanshiDict.TryGetValue(nextLevel.GoodsCost, out goodsPrice))
                {
                    return(LingYuError.ErrorConfig);
                }
                zuanshiCost = nextLevel.GoodsCostCnt * goodsPrice;
                if (client.ClientData.UserMoney < zuanshiCost)
                {
                    return(LingYuError.ZuanShiNotEnough);
                }
            }

            // 先扣钱
            if (!Global.SubBindTongQianAndTongQian(client, nextLevel.JinBiCost, "翎羽升级消耗"))
            {
                return(LingYuError.DBSERVERERROR);
            }

            //有可能出现消耗一部分材料,其余用钻石购买的情况
            if (goodsCostCnt > 0)
            {
                bool bUsedBinding     = false;
                bool bUsedTimeLimited = false;

                if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener,
                                                          Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, nextLevel.GoodsCost, goodsCostCnt, false, out bUsedBinding, out bUsedTimeLimited))
                {
                    return(LingYuError.DBSERVERERROR);
                }
            }

            if (zuanshiCost > 0)
            {
                //先DBServer请求扣费
                //扣除用户点卷
                if (!GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, zuanshiCost, "翎羽升级"))
                {
                    return(LingYuError.DBSERVERERROR);
                }
            }

            //生效,计算属性加成,写数据库
            int iRet = UpdateLingYu2DB(roleID, type, lyData.Level + 1, lyData.Suit, client.ServerId);

            if (iRet < 0)
            {
                return(LingYuError.DBSERVERERROR);
            }

            lyData.Level++;
            lock (client.ClientData.LingYuDict)
            {
                client.ClientData.LingYuDict[type] = lyData;
            }

            UpdateLingYuProps(client);
            // 通知客户端属性变化
            GameManager.ClientMgr.NotifyUpdateEquipProps(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, client);
            // 总生命值和魔法值变化通知(同一个地图才需要通知)
            GameManager.ClientMgr.NotifyOthersLifeChanged(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, client);

            return(LingYuError.Success);
        }