Ejemplo n.º 1
0
        public void StartUp()
        {
            try
            {
                XElement xml  = null;
                string   file = "";

                file = @"Config\CoupleWar.xml";
                xml  = XElement.Load(KuaFuServerManager.GetResourcePath(file, KuaFuServerManager.ResourcePathTypes.GameRes));
                foreach (var xmlItem in xml.Elements())
                {
                    string[] fields = xmlItem.Attribute("TimePoints").Value.Split(new char[] { ',', '-', '|' });
                    for (int i = 0; i < fields.Length; i += 3)
                    {
                        var tp = new _CoupleArenaWarTimePoint();
                        tp.Weekday = Convert.ToInt32(fields[i]);
                        if (tp.Weekday < 1 || tp.Weekday > 7)
                        {
                            throw new Exception("weekday error!");
                        }
                        tp.DayStartTicks = DateTime.Parse(fields[i + 1]).TimeOfDay.Ticks;
                        tp.DayEndTicks   = DateTime.Parse(fields[i + 2]).TimeOfDay.Ticks;

                        _WarTimePointList.Add(tp);
                    }

                    _WarTimePointList.Sort((_l, _r) => { return(_l.Weekday - _r.Weekday); });

                    break;
                }

                file = @"Config\CoupleDuanWei.xml";
                xml  = XElement.Load(KuaFuServerManager.GetResourcePath(file, KuaFuServerManager.ResourcePathTypes.GameRes));
                foreach (var xmlItem in xml.Elements())
                {
                    var cfg = new _CoupleArenaDuanWeiCfg();
                    cfg.NeedJiFen    = Convert.ToInt32(xmlItem.Attribute("NeedCoupleDuanWeiJiFen").Value.ToString());
                    cfg.DuanWeiType  = Convert.ToInt32(xmlItem.Attribute("Type").Value.ToString());
                    cfg.DuanWeiLevel = Convert.ToInt32(xmlItem.Attribute("Level").Value.ToString());
                    cfg.WinJiFen     = Convert.ToInt32(xmlItem.Attribute("WinJiFen").Value.ToString());
                    cfg.LoseJiFen    = Convert.ToInt32(xmlItem.Attribute("LoseJiFen").Value.ToString());

                    _DuanWeiCfgList.Add(cfg);
                }
                _DuanWeiCfgList.Sort((_l, _r) => { return(_l.NeedJiFen - _r.NeedJiFen); });

                DateTime now = TimeUtil.NowDateTime();
                Persistence.CheckClearRank(CurrRankWeek(now));
                SyncData.RankList = Persistence.LoadRankFromDb();
                SyncData.BuildRoleDict();
                SyncData.ModifyTime = now;

                this.IsNeedSort = false;
                for (int i = 1; i < SyncData.RankList.Count && !this.IsNeedSort; i++)
                {
                    this.IsNeedSort |= SyncData.RankList[i].CompareTo(SyncData.RankList[i - 1]) < 0;
                    this.IsNeedSort |= this.SyncData.RankList[i].Rank != this.SyncData.RankList[i - 1].Rank + 1;
                }

                CheckRebuildRank(now);
                CheckFlushRank2Db();
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, "CoupleArenaService.InitConfig failed!", ex);
            }
        }
Ejemplo n.º 2
0
        private void HandlePkResult(int man, int manzone, byte[] mandata, int wife, int wifezone, byte[] wifedata, int pkDuanWeiType, int pkDuanWeiLevel, CoupleArenaPkResultItem retData)
        {
            CoupleArenaCoupleDataK coupleData = null;

            if (!SyncData.RoleDict.TryGetValue(man, out coupleData))
            {
                coupleData                  = new CoupleArenaCoupleDataK();
                coupleData.Db_CoupleId      = Persistence.GetNextDbCoupleId();
                coupleData.ManRoleId        = man;
                coupleData.ManZoneId        = manzone;
                coupleData.ManSelectorData  = mandata;
                coupleData.WifeRoleId       = wife;
                coupleData.WifeZoneId       = wifezone;
                coupleData.WifeSelectorData = wifedata;
                coupleData.DuanWeiLevel     = _DuanWeiCfgList[0].DuanWeiLevel;
                coupleData.DuanWeiType      = _DuanWeiCfgList[0].DuanWeiType;
                coupleData.Rank             = SyncData.RankList.Count + 1;
                if (retData.Result != (int)ECoupleArenaPkResult.Invalid)
                {
                    SyncData.RankList.Add(coupleData);
                    SyncData.RoleDict[coupleData.ManRoleId]  = coupleData;
                    SyncData.RoleDict[coupleData.WifeRoleId] = coupleData;
                }
            }
            else
            {
                // 更新形象
                coupleData.ManSelectorData  = mandata;
                coupleData.WifeSelectorData = wifedata;
            }

            retData.OldDuanWeiType  = coupleData.DuanWeiType;
            retData.OldDuanWeiLevel = coupleData.DuanWeiLevel;

            // 失败扣除自己段位的积分
            _CoupleArenaDuanWeiCfg duanweiCfgLose = _DuanWeiCfgList.Find(
                _d => _d.DuanWeiLevel == coupleData.DuanWeiLevel && _d.DuanWeiType == coupleData.DuanWeiType);

            if (duanweiCfgLose == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("couplearena.HandlePkResult can't find duanwei cfg ,type={0}, level={1}", coupleData.DuanWeiType, coupleData.DuanWeiLevel));
                return;
            }

            // 胜利奖励对方段位的积分
            _CoupleArenaDuanWeiCfg duanweiCfgWin = _DuanWeiCfgList.Find(
                _d => _d.DuanWeiLevel == pkDuanWeiLevel && _d.DuanWeiType == pkDuanWeiType);

            if (duanweiCfgWin == null)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("couplearena.HandlePkResult can't find duanwei cfg ,type={0}, level={1}", pkDuanWeiType, pkDuanWeiLevel));
                return;
            }

            if (retData.Result == (int)ECoupleArenaPkResult.Invalid)
            {
                retData.NewDuanWeiType  = coupleData.DuanWeiType;
                retData.NewDuanWeiLevel = coupleData.DuanWeiLevel;
            }
            else
            {
                coupleData.TotalFightTimes++;
                if (retData.Result == (int)ECoupleArenaPkResult.Win)
                {
                    coupleData.WinFightTimes++;
                    coupleData.LianShengTimes++;
                    coupleData.JiFen += duanweiCfgWin.WinJiFen;

                    retData.GetJiFen = duanweiCfgWin.WinJiFen;
                }
                else
                {
                    coupleData.LianShengTimes = 0;
                    coupleData.JiFen         += duanweiCfgLose.LoseJiFen;
                    coupleData.JiFen          = Math.Max(coupleData.JiFen, 0);

                    retData.GetJiFen = duanweiCfgLose.LoseJiFen;
                }

                ParseDuanweiByJiFen(coupleData.JiFen, out coupleData.DuanWeiType, out coupleData.DuanWeiLevel);
                SyncData.ModifyTime = TimeUtil.NowDateTime();

                retData.NewDuanWeiLevel = coupleData.DuanWeiLevel;
                retData.NewDuanWeiType  = coupleData.DuanWeiType;
                this.IsNeedSort         = true;
            }

            if (retData.Result != (int)ECoupleArenaPkResult.Invalid)
            {
                Persistence.WriteCoupleData(coupleData);
            }
        }
Ejemplo n.º 3
0
 public void StartUp()
 {
     try
     {
         int  num;
         bool flag;
         IEnumerator <XElement> objA = XElement.Load(KuaFuServerManager.GetResourcePath(@"Config\CoupleWar.xml", KuaFuServerManager.ResourcePathTypes.GameRes)).Elements().GetEnumerator();
         try
         {
             flag = objA.MoveNext();
             if (flag)
             {
                 string[] strArray = objA.Current.Attribute("TimePoints").Value.Split(new char[] { ',', '-', '|' });
                 num = 0;
                 while (true)
                 {
                     flag = num < strArray.Length;
                     if (!flag)
                     {
                         this._WarTimePointList.Sort((_l, _r) => _l.Weekday - _r.Weekday);
                         break;
                     }
                     _CoupleArenaWarTimePoint item = new _CoupleArenaWarTimePoint
                     {
                         Weekday = Convert.ToInt32(strArray[num])
                     };
                     if ((item.Weekday < 1) || (item.Weekday > 7))
                     {
                         throw new Exception("weekday error!");
                     }
                     item.DayStartTicks = DateTime.Parse(strArray[num + 1]).TimeOfDay.Ticks;
                     item.DayEndTicks   = DateTime.Parse(strArray[num + 2]).TimeOfDay.Ticks;
                     this._WarTimePointList.Add(item);
                     num += 3;
                 }
             }
         }
         finally
         {
             if (!ReferenceEquals(objA, null))
             {
                 objA.Dispose();
             }
         }
         objA = XElement.Load(KuaFuServerManager.GetResourcePath(@"Config\CoupleDuanWei.xml", KuaFuServerManager.ResourcePathTypes.GameRes)).Elements().GetEnumerator();
         try
         {
             while (true)
             {
                 flag = objA.MoveNext();
                 if (!flag)
                 {
                     break;
                 }
                 XElement current            = objA.Current;
                 _CoupleArenaDuanWeiCfg item = new _CoupleArenaDuanWeiCfg
                 {
                     NeedJiFen    = Convert.ToInt32(current.Attribute("NeedCoupleDuanWeiJiFen").Value.ToString()),
                     DuanWeiType  = Convert.ToInt32(current.Attribute("Type").Value.ToString()),
                     DuanWeiLevel = Convert.ToInt32(current.Attribute("Level").Value.ToString()),
                     WinJiFen     = Convert.ToInt32(current.Attribute("WinJiFen").Value.ToString()),
                     LoseJiFen    = Convert.ToInt32(current.Attribute("LoseJiFen").Value.ToString())
                 };
                 this._DuanWeiCfgList.Add(item);
             }
         }
         finally
         {
             if (!ReferenceEquals(objA, null))
             {
                 objA.Dispose();
             }
         }
         this._DuanWeiCfgList.Sort((_l, _r) => _l.NeedJiFen - _r.NeedJiFen);
         DateTime time = TimeUtil.NowDateTime();
         this.Persistence.CheckClearRank(this.CurrRankWeek(time));
         this.SyncData.RankList = this.Persistence.LoadRankFromDb();
         this.SyncData.BuildRoleDict();
         this.SyncData.ModifyTime = time;
         this.IsNeedSort          = false;
         num = 1;
         while (true)
         {
             flag = (num < this.SyncData.RankList.Count) && !this.IsNeedSort;
             if (!flag)
             {
                 this.CheckRebuildRank(time);
                 this.CheckFlushRank2Db();
                 break;
             }
             this.IsNeedSort |= this.SyncData.RankList[num].CompareTo(this.SyncData.RankList[num - 1]) < 0;
             this.IsNeedSort |= this.SyncData.RankList[num].Rank != (this.SyncData.RankList[num - 1].Rank + 1);
             num++;
         }
     }
     catch (Exception exception)
     {
         LogManager.WriteLog(LogTypes.Error, "CoupleArenaService.InitConfig failed!", exception, true);
     }
 }