Пример #1
0
        public static void UpdateLingYuProps(GameClient client)
        {
            if (null == client.ClientData.MyWingData)
            {
                return;
            }
            if (client.ClientData.MyWingData.WingID <= 0)
            {
                return;
            }
            //if (1 != client.ClientData.MyWingData.Using) return;

            double MinAttackV   = 0;
            double MaxAttackV   = 0;
            double MinMAttackV  = 0;
            double MaxMAttackV  = 0;
            double MinDefenseV  = 0;
            double MaxDefenseV  = 0;
            double MinMDefenseV = 0;
            double MaxMDefenseV = 0;
            double HitV         = 0;
            double LifeV        = 0;

            //Key: 阶数  Value: 个数
            //List<int> suitCnt = new List<int>(LingYuManager.LingYuSuitLimit + 1);
            int[] suitCnt = new int[LingYuManager.LingYuSuitLimit + 1];

            if (client.ClientData.MyWingData.Using == 1)
            {
                lock (client.ClientData.LingYuDict)
                {
                    foreach (KeyValuePair <int, LingYuData> kv in client.ClientData.LingYuDict)
                    {
                        int type  = kv.Value.Type;
                        int level = kv.Value.Level;
                        int suit  = kv.Value.Suit;

                        for (int i = 0; i <= suit; ++i)
                        {
                            suitCnt[i]++;
                        }

                        LingYuType lyType = null;
                        if (!LingYuTypeDict.TryGetValue(type, out lyType))
                        {
                            continue;
                        }
                        LingYuLevel lyLevel = null;
                        lyType.LevelDict.TryGetValue(level, out lyLevel);
                        LingYuSuit lySuit = null;
                        lyType.SuitDict.TryGetValue(suit, out lySuit);

                        if (lyLevel != null)
                        {
                            MinAttackV   += lyLevel.MinAttackV;
                            MaxAttackV   += lyLevel.MaxAttackV;
                            MinMAttackV  += lyLevel.MinMAttackV;
                            MaxMAttackV  += lyLevel.MaxMAttackV;
                            MinDefenseV  += lyLevel.MinDefenseV;
                            MaxDefenseV  += lyLevel.MaxDefenseV;
                            MinMDefenseV += lyLevel.MinMDefenseV;
                            MaxMDefenseV += lyLevel.MaxMDefenseV;
                            HitV         += lyLevel.HitV;
                            LifeV        += lyLevel.LifeV;
                        }

                        if (lySuit != null)
                        {
                            MinAttackV   += lySuit.MinAttackV;
                            MaxAttackV   += lySuit.MaxAttackV;
                            MinMAttackV  += lySuit.MinMAttackV;
                            MaxMAttackV  += lySuit.MaxMAttackV;
                            MinDefenseV  += lySuit.MinDefenseV;
                            MaxDefenseV  += lySuit.MaxDefenseV;
                            MinMDefenseV += lySuit.MinMDefenseV;
                            MaxMDefenseV += lySuit.MaxMDefenseV;
                            HitV         += lySuit.HitV;
                            LifeV        += lySuit.LifeV;
                        }
                    }
                }
            }

            // 翎羽属性加成
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MinAttack, MinAttackV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MaxAttack, MaxAttackV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MinMAttack, MinMAttackV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MaxMAttack, MaxMAttackV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MinDefense, MinDefenseV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MaxDefense, MaxDefenseV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MinMDefense, MinMDefenseV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MaxMDefense, MaxMDefenseV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.HitV, HitV);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.MaxLifeV, LifeV);

            double lucky   = 0.0;
            double deLucky = 0.0;

            // 翎羽阶数满足条件的加成
            if (client.ClientData.MyWingData.Using == 1)
            {
                for (int i = LingYuCollectList.Count() - 1; i >= 0; i--)
                {
                    LingYuCollect lyCollect = LingYuCollectList[i];
                    if (suitCnt[lyCollect.NeedSuit] >= lyCollect.Num)
                    {
                        lucky   = lyCollect.Luck;
                        deLucky = lyCollect.DeLuck;
                        break;
                    }
                }
            }
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.Lucky, lucky);
            client.ClientData.PropsCacheManager.SetExtPropsSingle((int)PropsSystemTypes.LingYuProps, (int)ExtPropIndexes.DeLucky, deLucky);
        }
Пример #2
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);
        }
Пример #3
0
        public static void LoadConfig()
        {
            XElement xml = null;

            #region 加载LingYuTypeFile

            GeneralCachingXmlMgr.RemoveCachingXml(Global.GameResPath(LingYuTypeFile));
            xml = GeneralCachingXmlMgr.GetXElement(Global.GameResPath(LingYuTypeFile));
            if (xml == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时出错!!!文件不存在", LingYuTypeFile));
            }
            else
            {
                try
                {
                    LingYuTypeDict.Clear();
                    IEnumerable <XElement> xmlItems = xml.Elements();
                    foreach (var xmlItem in xmlItems)
                    {
                        if (null == xmlItem)
                        {
                            continue;
                        }

                        LingYuType lyType = new LingYuType();
                        lyType.Type                 = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "TypeID", "0"));
                        lyType.Name                 = Global.GetDefAttributeStr(xmlItem, "Name", "no-name");
                        lyType.LifeScale            = Global.GetSafeAttributeDouble(xmlItem, "LifeScale");
                        lyType.AttackScale          = Global.GetSafeAttributeDouble(xmlItem, "AttackScale");
                        lyType.DefenseScale         = Global.GetSafeAttributeDouble(xmlItem, "DefenseScale");
                        lyType.MAttackScale         = Global.GetSafeAttributeDouble(xmlItem, "MAttackScale");
                        lyType.MDefenseScale        = Global.GetSafeAttributeDouble(xmlItem, "MDefenseScale");
                        lyType.HitScale             = Global.GetSafeAttributeDouble(xmlItem, "HitScale");
                        LingYuTypeDict[lyType.Type] = lyType;
                    }
                }
                catch (Exception ex)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时异常{1}", LingYuTypeFile, ex));
                }
            }

            #endregion

            #region 加载LingYuLevelUpFile

            xml = null;
            GeneralCachingXmlMgr.RemoveCachingXml(Global.GameResPath(LingYuLevelUpFile));
            xml = GeneralCachingXmlMgr.GetXElement(Global.GameResPath(LingYuLevelUpFile));
            if (xml == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时出错!!!文件不存在", LingYuLevelUpFile));
            }
            else
            {
                try
                {
                    IEnumerable <XElement> xmlItems = xml.Elements();
                    foreach (var xmlItem in xmlItems)
                    {
                        if (null == xmlItem)
                        {
                            continue;
                        }

                        // 先读取翎羽类型
                        int        TypeID = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "TypeID", "0"));
                        LingYuType lyType = null;
                        if (!LingYuTypeDict.TryGetValue(TypeID, out lyType))
                        {
                            LogManager.WriteLog(LogTypes.Error, string.Format("加载翎羽升级文件{0}时,未找到类型为{1}的翎羽配置", LingYuLevelUpFile, TypeID));
                            continue;
                        }

                        // 读取翎羽的每个级别的信息
                        IEnumerable <XElement> xmlItemLevels = xmlItem.Elements();
                        foreach (var xmlItemLevel in xmlItemLevels)
                        {
                            LingYuLevel lyLevel = new LingYuLevel();
                            lyLevel.Level        = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "Level", "0"));
                            lyLevel.MinAttackV   = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinAttackV", "0"));
                            lyLevel.MaxAttackV   = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxAttackV", "0"));
                            lyLevel.MinMAttackV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinMAttackV", "0"));
                            lyLevel.MaxMAttackV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxMAttackV", "0"));
                            lyLevel.MinDefenseV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinDefenseV", "0"));
                            lyLevel.MaxDefenseV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxDefenseV", "0"));
                            lyLevel.MinMDefenseV = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinMDefenseV", "0"));
                            lyLevel.MaxMDefenseV = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxMDefenseV", "0"));
                            lyLevel.HitV         = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "HitV", "0"));
                            lyLevel.LifeV        = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "LifeV", "0"));
                            lyLevel.JinBiCost    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "JinBiCost", "0"));
                            string   costGoods      = Global.GetDefAttributeStr(xmlItemLevel, "GoodsCost", "0");
                            string[] costGoodsField = costGoods.Split(',');
                            if (costGoodsField.Length != 2)
                            {
                                LogManager.WriteLog(LogTypes.Error, string.Format("翎羽Type{0},级别{1}, 消耗物品配置错误", TypeID, lyLevel.Level));
                                continue;
                            }

                            lyLevel.GoodsCost    = Convert.ToInt32(costGoodsField[0]);
                            lyLevel.GoodsCostCnt = Convert.ToInt32(costGoodsField[1]);

                            lyType.LevelDict[lyLevel.Level] = lyLevel;

                            LingYuLevelLimit = Global.GMax(LingYuLevelLimit, lyLevel.Level);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时异常{1}", LingYuLevelUpFile, ex));
                }
            }

            #endregion

            #region 加载LingYuSuitUpFile

            xml = null;
            GeneralCachingXmlMgr.RemoveCachingXml(Global.GameResPath(LingYuSuitUpFile));
            xml = GeneralCachingXmlMgr.GetXElement(Global.GameResPath(LingYuSuitUpFile));
            if (xml == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时出错!!!文件不存在", LingYuSuitUpFile));
            }
            else
            {
                try
                {
                    lock (LingYuTypeDict)
                    {
                        IEnumerable <XElement> xmlItems = xml.Elements();
                        foreach (var xmlItem in xmlItems)
                        {
                            if (null == xmlItem)
                            {
                                continue;
                            }

                            // 先读取翎羽类型
                            int        TypeID = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "TypeID", "0"));
                            LingYuType lyType = null;
                            if (!LingYuTypeDict.TryGetValue(TypeID, out lyType))
                            {
                                LogManager.WriteLog(LogTypes.Error, string.Format("加载翎羽进阶文件{0}时,未找到类型为{1}的翎羽配置", LingYuSuitUpFile, TypeID));
                                continue;
                            }

                            // 读取翎羽的每个级别的信息
                            IEnumerable <XElement> xmlItemLevels = xmlItem.Elements();
                            foreach (var xmlItemLevel in xmlItemLevels)
                            {
                                LingYuSuit lySuit = new LingYuSuit();
                                lySuit.Suit         = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "SuitID", "0"));
                                lySuit.MinAttackV   = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinAttackV", "0"));
                                lySuit.MaxAttackV   = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxAttackV", "0"));
                                lySuit.MinMAttackV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinMAttackV", "0"));
                                lySuit.MaxMAttackV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxMAttackV", "0"));
                                lySuit.MinDefenseV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinDefenseV", "0"));
                                lySuit.MaxDefenseV  = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxDefenseV", "0"));
                                lySuit.MinMDefenseV = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MinMDefenseV", "0"));
                                lySuit.MaxMDefenseV = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "MaxMDefenseV", "0"));
                                lySuit.HitV         = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "HitV", "0"));
                                lySuit.LifeV        = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "LifeV", "0"));
                                lySuit.JinBiCost    = Convert.ToInt32(Global.GetDefAttributeStr(xmlItemLevel, "JinBiCost", "0"));
                                string   costGoods      = Global.GetDefAttributeStr(xmlItemLevel, "GoodsCost", "0");
                                string[] costGoodsField = costGoods.Split(',');
                                if (costGoodsField.Length != 2)
                                {
                                    LogManager.WriteLog(LogTypes.Error, string.Format("翎羽Type{0},级别{1}, 消耗物品配置错误", TypeID, lySuit.Suit));
                                    continue;
                                }

                                lySuit.GoodsCost    = Convert.ToInt32(costGoodsField[0]);
                                lySuit.GoodsCostCnt = Convert.ToInt32(costGoodsField[1]);

                                lyType.SuitDict[lySuit.Suit] = lySuit;

                                LingYuSuitLimit = Global.GMax(LingYuSuitLimit, lySuit.Suit);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时异常{1}", LingYuSuitUpFile, ex));
                }
            }

            #endregion

            #region 加载LingYuCollect

            xml = null;
            GeneralCachingXmlMgr.RemoveCachingXml(Global.GameResPath(LingYuCollectFile));
            xml = GeneralCachingXmlMgr.GetXElement(Global.GameResPath(LingYuCollectFile));
            if (xml == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时出错!!!文件不存在", LingYuCollectFile));
            }
            else
            {
                try
                {
                    LingYuCollectList.Clear();
                    IEnumerable <XElement> xmlItems = xml.Elements();
                    foreach (var xmlItem in xmlItems)
                    {
                        if (null == xmlItem)
                        {
                            continue;
                        }

                        LingYuCollect lyCollect = new LingYuCollect();
                        lyCollect.Num      = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "Num", "0"));
                        lyCollect.NeedSuit = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "NeedSuit", "0"));
                        lyCollect.Luck     = Global.GetSafeAttributeDouble(xmlItem, "Luck");
                        lyCollect.DeLuck   = Global.GetSafeAttributeDouble(xmlItem, "DeLuck");

                        LingYuCollectList.Add(lyCollect);
                    }

                    //排序
                    LingYuCollectList.Sort((left, right) =>
                    {
                        if (left.NeedSuit > right.NeedSuit)
                        {
                            return(1);
                        }
                        else if (left.NeedSuit == right.NeedSuit)
                        {
                            if (left.Num > right.Num)
                            {
                                return(1);
                            }
                            else if (left.Num == right.Num)
                            {
                                return(0);
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    });
                }
                catch (Exception ex)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("加载{0}时异常{1}", LingYuCollectFile, ex));
                }
            }

            #endregion
        }