Пример #1
0
        private List <BirthTimePoint> ParseBirthTimePoints(string s)
        {
            List <BirthTimePoint> result;

            if (string.IsNullOrEmpty(s))
            {
                result = null;
            }
            else
            {
                string[] fields = s.Split(new char[]
                {
                    '|'
                });
                if (fields.Length <= 0)
                {
                    result = null;
                }
                else
                {
                    List <BirthTimePoint> list = new List <BirthTimePoint>();
                    for (int i = 0; i < fields.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(fields[i]))
                        {
                            string[] fields2 = fields[i].Split(new char[]
                            {
                                ':'
                            });
                            if (fields2.Length == 2)
                            {
                                string str = fields2[0].TrimStart(new char[]
                                {
                                    '0'
                                });
                                string str2 = fields2[1].TrimStart(new char[]
                                {
                                    '0'
                                });
                                BirthTimePoint birthTimePoint = new BirthTimePoint
                                {
                                    BirthHour   = Global.SafeConvertToInt32(str),
                                    BirthMinute = Global.SafeConvertToInt32(str2)
                                };
                                list.Add(birthTimePoint);
                            }
                        }
                    }
                    result = ((list.Count > 0) ? list : null);
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 获取爆怪的时间点
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private List <BirthTimePoint> ParseBirthTimePoints(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }

            string[] fields = s.Split('|');
            if (fields.Length <= 0)
            {
                return(null);
            }

            List <BirthTimePoint> list = new List <BirthTimePoint>();

            for (int i = 0; i < fields.Length; i++)
            {
                if (string.IsNullOrEmpty(fields[i]))
                {
                    continue;
                }

                string[] fields2 = fields[i].Split(':');
                if (fields2.Length != 2)
                {
                    continue;
                }

                string         str1           = fields2[0].TrimStart('0');
                string         str2           = fields2[1].TrimStart('0');
                BirthTimePoint birthTimePoint = new BirthTimePoint()
                {
                    BirthHour   = Global.SafeConvertToInt32(str1),
                    BirthMinute = Global.SafeConvertToInt32(str2),
                };

                list.Add(birthTimePoint);
            }

            return(list.Count > 0 ? list : null);
        }
Пример #3
0
        /// <summary>
        /// 加载怪物
        /// </summary>
        public void AddMapMonsters(int mapCode, GameMap gameMap)
        {
            //对于每一个地图,都要加入一个动态刷怪区域,用于动态刷怪管理
            AddDynamicMonsterZone(mapCode);

            string   fileName = string.Format("Map/{0}/Monsters.xml", mapCode);
            XElement xml      = null;

            try
            {
                xml = XElement.Load(Global.ResPath(fileName));
            }
            catch (Exception)
            {
                throw new Exception(string.Format("加载地图怪物配置文件:{0}, 失败。没有找到相关XML配置文件!", fileName));
            }

            IEnumerable <XElement> monsterItems = xml.Elements("Monsters").Elements();

            if (null == monsterItems)
            {
                return;
            }

            //判断是否是副本地图
            bool isFuBenMap = FuBenManager.IsFuBenMap(mapCode);

            foreach (var monsterItem in monsterItems)
            {
                String timePoints      = Global.GetSafeAttributeStr(monsterItem, "TimePoints");
                int    configBirthType = (int)Global.GetSafeAttributeLong(monsterItem, "BirthType");
                int    realBirthType   = configBirthType;

                String realTimePoints = timePoints;
                int    spawnMonstersAfterKaiFuDays = 0;
                int    spawnMonstersDays           = 0;
                List <BirthTimeForDayOfWeek> CreateMonstersDayOfWeek = new List <BirthTimeForDayOfWeek>();
                List <BirthTimePoint>        birthTimePointList      = null;

                //对于开服多少天之后才开始刷怪,进行特殊配置 格式:开服多少天;连续刷多少天[负数0表示一直];刷怪方式0或1;0或1的配置
                if ((int)MonsterBirthTypes.AfterKaiFuDays == configBirthType || (int)MonsterBirthTypes.AfterHeFuDays == configBirthType || (int)MonsterBirthTypes.AfterJieRiDays == configBirthType)
                {
                    String[] arr = timePoints.Split(';');
                    if (4 != arr.Length)
                    {
                        throw new Exception(String.Format("地图{0}的类型4的刷怪配置参数个数不对!!!!", mapCode));
                    }

                    spawnMonstersAfterKaiFuDays = int.Parse(arr[0]);
                    spawnMonstersDays           = int.Parse(arr[1]);
                    realBirthType  = int.Parse(arr[2]);
                    realTimePoints = arr[3];

                    if ((int)MonsterBirthTypes.TimePoint != realBirthType && (int)MonsterBirthTypes.TimeSpan != realBirthType)
                    {
                        throw new Exception(String.Format("地图{0}的类型4的刷怪配置子类型不对!!!!", mapCode));
                    }
                }

                // MU新增 一周中的哪天刷 TimePoints 配置形式 周几,时间点|周几,时间点|周几,时间点... [1/10/2014 LiaoWei]
                if ((int)MonsterBirthTypes.CreateDayOfWeek == configBirthType)
                {
                    String[] arrTime = timePoints.Split('|');

                    if (arrTime.Length > 0)
                    {
                        for (int nIndex = 0; nIndex < arrTime.Length; ++nIndex)
                        {
                            string sTimePoint = null;
                            sTimePoint = arrTime[nIndex];

                            if (sTimePoint != null)
                            {
                                String[] sTime = null;
                                sTime = sTimePoint.Split(',');

                                if (sTime != null && sTime.Length == 2)
                                {
                                    string sTimeString = null;
                                    int    nDayOfWeek  = -1;

                                    nDayOfWeek  = int.Parse(sTime[0]);
                                    sTimeString = sTime[1];

                                    if (nDayOfWeek != -1 && !string.IsNullOrEmpty(sTimeString))
                                    {
                                        string[] fields2 = sTimeString.Split(':');
                                        if (fields2.Length != 2)
                                        {
                                            continue;
                                        }

                                        string str1 = fields2[0].TrimStart('0');
                                        string str2 = fields2[1].TrimStart('0');

                                        BirthTimePoint birthTimePoint = new BirthTimePoint()
                                        {
                                            BirthHour   = Global.SafeConvertToInt32(str1),
                                            BirthMinute = Global.SafeConvertToInt32(str2),
                                        };

                                        BirthTimeForDayOfWeek BirthTimeTmp = new BirthTimeForDayOfWeek();

                                        BirthTimeTmp.BirthDayOfWeek = nDayOfWeek;
                                        BirthTimeTmp.BirthTime      = birthTimePoint;

                                        CreateMonstersDayOfWeek.Add(BirthTimeTmp);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    birthTimePointList = ParseBirthTimePoints(realTimePoints);
                }

                MonsterZone monsterZone = new MonsterZone()
                {
                    MapCode                     = mapCode,
                    ID                          = (int)Global.GetSafeAttributeLong(monsterItem, "ID"),
                    Code                        = (int)Global.GetSafeAttributeLong(monsterItem, "Code"),
                    ToX                         = (int)Global.GetSafeAttributeLong(monsterItem, "X") / gameMap.MapGridWidth,
                    ToY                         = (int)Global.GetSafeAttributeLong(monsterItem, "Y") / gameMap.MapGridHeight,
                    Radius                      = (int)Global.GetSafeAttributeLong(monsterItem, "Radius") / gameMap.MapGridWidth,
                    TotalNum                    = (int)Global.GetSafeAttributeLong(monsterItem, "Num"),
                    Timeslot                    = (int)Global.GetSafeAttributeLong(monsterItem, "Timeslot"),
                    IsFuBenMap                  = isFuBenMap,
                    BirthType                   = realBirthType,
                    ConfigBirthType             = configBirthType,
                    SpawnMonstersAfterKaiFuDays = spawnMonstersAfterKaiFuDays,
                    SpawnMonstersDays           = spawnMonstersDays,
                    SpawnMonstersDayOfWeek      = CreateMonstersDayOfWeek,
                    BirthTimePointList          = birthTimePointList,
                    BirthRate                   = (int)(Global.GetSafeAttributeDouble(monsterItem, "BirthRate") * 10000),
                };

                XAttribute attrib = monsterItem.Attribute("PursuitRadius");
                if (null != attrib)
                {
                    monsterZone.PursuitRadius = (int)Global.GetSafeAttributeLong(monsterItem, "PursuitRadius");
                }
                else
                {
                    monsterZone.PursuitRadius = (int)Global.GetSafeAttributeLong(monsterItem, "Radius");
                }

                lock (InitMonsterZoneMutex)
                {
                    //加入列表
                    MonsterZoneList.Add(monsterZone);

                    //如果是副本地图, 则加入副本爆怪区域列表
                    if (isFuBenMap)
                    {
                        FuBenMonsterZoneList.Add(monsterZone);
                    }

                    //加入爆怪区域
                    AddMap2MonsterZoneDict(monsterZone);
                }

                //加载静态的怪物信息
                monsterZone.LoadStaticMonsterInfo();

                //加载怪物
                monsterZone.LoadMonsters();//暂时屏蔽怪物加载
            }
        }
Пример #4
0
        public void AddMapMonsters(int mapCode, GameMap gameMap)
        {
            this.AddDynamicMonsterZone(mapCode);
            string   fileName = string.Format("Map/{0}/Monsters.xml", mapCode);
            XElement xml      = null;

            try
            {
                xml = XElement.Load(Global.ResPath(fileName));
            }
            catch (Exception)
            {
                throw new Exception(string.Format("加载地图怪物配置文件:{0}, 失败。没有找到相关XML配置文件!", fileName));
            }
            IEnumerable <XElement> monsterItems = xml.Elements("Monsters").Elements <XElement>();

            if (null != monsterItems)
            {
                bool isFuBenMap = FuBenManager.IsFuBenMap(mapCode);
                foreach (XElement monsterItem in monsterItems)
                {
                    string timePoints                  = Global.GetSafeAttributeStr(monsterItem, "TimePoints");
                    int    configBirthType             = (int)Global.GetSafeAttributeLong(monsterItem, "BirthType");
                    int    realBirthType               = configBirthType;
                    string realTimePoints              = timePoints;
                    int    spawnMonstersAfterKaiFuDays = 0;
                    int    spawnMonstersDays           = 0;
                    List <BirthTimeForDayOfWeek> CreateMonstersDayOfWeek = new List <BirthTimeForDayOfWeek>();
                    List <BirthTimePoint>        birthTimePointList      = null;
                    if (4 == configBirthType || 5 == configBirthType || 6 == configBirthType)
                    {
                        string[] arr = timePoints.Split(new char[]
                        {
                            ';'
                        });
                        if (4 != arr.Length)
                        {
                            throw new Exception(string.Format("地图{0}的类型4的刷怪配置参数个数不对!!!!", mapCode));
                        }
                        spawnMonstersAfterKaiFuDays = int.Parse(arr[0]);
                        spawnMonstersDays           = int.Parse(arr[1]);
                        realBirthType  = int.Parse(arr[2]);
                        realTimePoints = arr[3];
                        if (1 != realBirthType && 0 != realBirthType)
                        {
                            throw new Exception(string.Format("地图{0}的类型4的刷怪配置子类型不对!!!!", mapCode));
                        }
                    }
                    if (7 == configBirthType)
                    {
                        string[] arrTime = timePoints.Split(new char[]
                        {
                            '|'
                        });
                        if (arrTime.Length > 0)
                        {
                            int nIndex = 0;
                            while (nIndex < arrTime.Length)
                            {
                                string sTimePoint = arrTime[nIndex];
                                if (sTimePoint != null)
                                {
                                    string[] sTime = sTimePoint.Split(new char[]
                                    {
                                        ','
                                    });
                                    if (sTime != null && sTime.Length == 2)
                                    {
                                        int    nDayOfWeek  = int.Parse(sTime[0]);
                                        string sTimeString = sTime[1];
                                        if (nDayOfWeek != -1 && !string.IsNullOrEmpty(sTimeString))
                                        {
                                            string[] fields2 = sTimeString.Split(new char[]
                                            {
                                                ':'
                                            });
                                            if (fields2.Length == 2)
                                            {
                                                string str = fields2[0].TrimStart(new char[]
                                                {
                                                    '0'
                                                });
                                                string str2 = fields2[1].TrimStart(new char[]
                                                {
                                                    '0'
                                                });
                                                BirthTimePoint birthTimePoint = new BirthTimePoint
                                                {
                                                    BirthHour   = Global.SafeConvertToInt32(str),
                                                    BirthMinute = Global.SafeConvertToInt32(str2)
                                                };
                                                CreateMonstersDayOfWeek.Add(new BirthTimeForDayOfWeek
                                                {
                                                    BirthDayOfWeek = nDayOfWeek,
                                                    BirthTime      = birthTimePoint
                                                });
                                            }
                                        }
                                    }
                                }
IL_2E5:
                                nIndex++;
                                continue;
                                goto IL_2E5;
                            }
                        }
                    }
                    else
                    {
                        birthTimePointList = this.ParseBirthTimePoints(realTimePoints);
                    }
                    MonsterZone monsterZone = new MonsterZone
                    {
                        MapCode                     = mapCode,
                        ID                          = (int)Global.GetSafeAttributeLong(monsterItem, "ID"),
                        Code                        = (int)Global.GetSafeAttributeLong(monsterItem, "Code"),
                        ToX                         = (int)Global.GetSafeAttributeLong(monsterItem, "X") / gameMap.MapGridWidth,
                        ToY                         = (int)Global.GetSafeAttributeLong(monsterItem, "Y") / gameMap.MapGridHeight,
                        Radius                      = (int)Global.GetSafeAttributeLong(monsterItem, "Radius") / gameMap.MapGridWidth,
                        TotalNum                    = (int)Global.GetSafeAttributeLong(monsterItem, "Num"),
                        Timeslot                    = (int)Global.GetSafeAttributeLong(monsterItem, "Timeslot"),
                        IsFuBenMap                  = isFuBenMap,
                        BirthType                   = realBirthType,
                        ConfigBirthType             = configBirthType,
                        SpawnMonstersAfterKaiFuDays = spawnMonstersAfterKaiFuDays,
                        SpawnMonstersDays           = spawnMonstersDays,
                        SpawnMonstersDayOfWeek      = CreateMonstersDayOfWeek,
                        BirthTimePointList          = birthTimePointList,
                        BirthRate                   = (int)(Global.GetSafeAttributeDouble(monsterItem, "BirthRate") * 10000.0)
                    };
                    XAttribute attrib = monsterItem.Attribute("PursuitRadius");
                    if (null != attrib)
                    {
                        monsterZone.PursuitRadius = (int)Global.GetSafeAttributeLong(monsterItem, "PursuitRadius");
                    }
                    else
                    {
                        monsterZone.PursuitRadius = (int)Global.GetSafeAttributeLong(monsterItem, "Radius");
                    }
                    lock (this.InitMonsterZoneMutex)
                    {
                        this.MonsterZoneList.Add(monsterZone);
                        if (isFuBenMap)
                        {
                            this.FuBenMonsterZoneList.Add(monsterZone);
                        }
                        this.AddMap2MonsterZoneDict(monsterZone);
                    }
                    monsterZone.LoadStaticMonsterInfo_2();
                    monsterZone.LoadMonsters();
                }
            }
        }