Esempio n. 1
0
 protected Point GetPlayerPoint(MapPoint mapPos, int team)
 {
     List<Point> list = team == 1 ? mapPos.PosX : mapPos.PosX1;
     int rand = m_random.Next(list.Count);
     Point pos = list[rand];
     list.Remove(pos);
     return pos;
 }
Esempio n. 2
0
        public static bool LoadMap(Dictionary <int, MapPoint> maps, Dictionary <int, Map> mapInfos)
        {
            try
            {
                MapInfo[] query;
                using (MapBussiness db = new MapBussiness())
                {
                    query = db.GetAllMap();
                }

                foreach (MapInfo m in query)
                {
                    if (string.IsNullOrEmpty(m.PosX)) //|| string.IsNullOrEmpty(m.PosX1))
                    {
                        continue;
                    }

                    if (!maps.Keys.Contains(m.ID))
                    {
                        string[] tmp  = m.PosX.Split('|');
                        string[] tmp1 = m.PosX1.Split('|');
                        //List<Point> pos = new List<Point>();
                        MapPoint pos = new MapPoint();
                        foreach (string s in tmp)
                        {
                            if (string.IsNullOrEmpty(s.Trim()))
                            {
                                continue;
                            }

                            string[] xy = s.Split(',');
                            pos.PosX.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                            //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1]));
                            //pos.Add(temp);
                        }

                        foreach (string s in tmp1)
                        {
                            if (string.IsNullOrEmpty(s.Trim()))
                            {
                                continue;
                            }

                            string[] xy = s.Split(',');
                            pos.PosX1.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                            //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1]));
                            //pos.Add(temp);
                        }

                        maps.Add(m.ID, pos);
                    }

                    if (!mapInfos.ContainsKey(m.ID))
                    {
                        Tile   force = null;
                        string file  = string.Format("map\\{0}\\fore.map", m.ID);
                        if (File.Exists(file))
                        {
                            force = new Tile(file, true);
                        }

                        Tile dead = null;
                        file = string.Format("map\\{0}\\dead.map", m.ID);
                        if (File.Exists(file))
                        {
                            dead = new Tile(file, false);
                        }

                        if (force != null || dead != null)
                        {
                            mapInfos.Add(m.ID, new Map(m, force, dead));
                        }
                        else
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Map's file is not exist!");
                            }
                            return(false);
                        }
                    }
                }

                if (maps.Count == 0 || mapInfos.Count == 0)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("maps:" + maps.Count + ",mapInfos:" + mapInfos.Count);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("MapMgr", e);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        public static MapPoint GetMapRandomPos(int index)
        {
            MapPoint pos = new MapPoint();
            MapPoint temp;
            if (index != 0 && !_maps.Keys.Contains(index))
                index = 0;

            if (index == 0)
            {
                int[] map = _maps.Keys.ToArray();
                temp = _maps[map[random.Next(map.Length)]];
            }
            else
            {
                temp = _maps[index];
            }

            if (random.Next(2) == 1)
            {
                pos.PosX.AddRange(temp.PosX);
                pos.PosX1.AddRange(temp.PosX1);
            }
            else
            {
                pos.PosX.AddRange(temp.PosX1);
                pos.PosX1.AddRange(temp.PosX);
            }

            return pos;
        }
Esempio n. 4
0
        public static bool LoadMap(Dictionary<int, MapPoint> maps, Dictionary<int, Map> mapInfos)
        {
            try
            {
                MapBussiness db = new MapBussiness();
                MapInfo[] query = db.GetAllMap();

                foreach (MapInfo m in query)
                {
                    if (string.IsNullOrEmpty(m.PosX) )//|| string.IsNullOrEmpty(m.PosX1))
                        continue;

                    if (!maps.Keys.Contains(m.ID))
                    {
                        string[] tmp = m.PosX.Split('|');
                        string[] tmp1 = m.PosX1.Split('|');
                        //List<Point> pos = new List<Point>();
                        MapPoint pos = new MapPoint();
                        foreach (string s in tmp)
                        {
                            if (string.IsNullOrEmpty(s.Trim()))
                                continue;

                            string[] xy = s.Split(',');
                            pos.PosX.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                            //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1]));
                            //pos.Add(temp);
                        }

                        foreach (string s in tmp1)
                        {
                            if (string.IsNullOrEmpty(s.Trim()))
                                continue;

                            string[] xy = s.Split(',');
                            pos.PosX1.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                            //Point temp = new Point(int.Parse(xy[0]), int.Parse(xy[1]));
                            //pos.Add(temp);
                        }

                        maps.Add(m.ID, pos);
                    }

                    if (!mapInfos.ContainsKey(m.ID))
                    {
                        Tile force = null;
                        string file = string.Format("map\\{0}\\fore.map", m.ID);
                        if (File.Exists(file))
                        {
                            force = new Tile(file, true);
                        }

                        Tile dead = null;
                        file = string.Format("map\\{0}\\dead.map", m.ID);
                        if (File.Exists(file))
                        {
                            dead = new Tile(file, false);
                        }

                        if (force != null || dead != null)
                        {
                            mapInfos.Add(m.ID, new Map(m, force, dead));
                        }
                        else
                        {
                            if (log.IsErrorEnabled)
                                log.Error("Map's file is not exist!");
                            return false;
                        }
                    }
                }

                if (maps.Count == 0 || mapInfos.Count == 0)
                {
                    if (log.IsErrorEnabled)
                        log.Error("maps:" + maps.Count + ",mapInfos:" + mapInfos.Count);
                    return false;
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                    log.Error("MapMgr", e);
                return false;
            }
            return true;
        }
Esempio n. 5
0
        public void StartGame()
        {
            if (GameState == eGameState.Loading)
            {
                m_gameState = eGameState.GameStart;

                //同步时间
                SendSyncLifeTime();

                TotalKillCount = 0;
                TotalNpcGrade = 0;
                TotalNpcExperience = 0;
                TotalHurt = 0;

                m_bossCardCount = 0;
                BossCards = null;

                List<Player> list = GetAllFightPlayers();
                mapPos = MapMgr.GetPVEMapRandomPos(m_map.Info.ID);
                GSPacketIn pkg = new GSPacketIn((byte)ePackageType.GAME_CMD);
                pkg.WriteByte((byte)eTankCmdType.START_GAME);
                pkg.WriteInt(list.Count);
                foreach (Player p in list)
                {
                    if (!p.IsLiving)
                    {
                        AddLiving(p);
                    }
                    p.Reset();

                    Point pos = GetPlayerPoint(mapPos, p.Team);
                    p.SetXY(pos);
                    m_map.AddPhysical(p);
                    p.StartMoving();
                    p.StartGame();

                    pkg.WriteInt(p.Id);
                    pkg.WriteInt(p.X);
                    pkg.WriteInt(p.Y);

                    if (pos.X < 600)
                    {
                        p.Direction = 1;

                    }
                    else
                    {
                        p.Direction = -1;
                    }
                    pkg.WriteInt(p.Direction);

         
                    pkg.WriteInt(p.Blood);
                    //Weapon refineLevel
                    pkg.WriteInt(2);
                    //ratio
                    pkg.WriteInt(34);
                    //dander
                    pkg.WriteInt(p.Dander);
                    //pkg.WriteInt(0);
                    pkg.WriteInt(p.PlayerDetail.EquipEffect.Count);
                    foreach (var templateID in p.PlayerDetail.EquipEffect)
                    {
                        ItemTemplateInfo item = ItemMgr.FindItemTemplate(templateID);
                        if (item.Property3 < 27)
                        {
                            pkg.WriteInt(item.Property3);
                            pkg.WriteInt(item.Property4);
                        }
                        else
                        {
                            pkg.WriteInt(0);
                            pkg.WriteInt(0);

                        }
                    }
                   // pkg.WriteInt(0);
                
                }

                SendToAll(pkg);
                SendUpdateUiData();
                WaitTime(PlayerCount * 2500 + 1000);
                OnGameStarted();
            }
        }
Esempio n. 6
0
        public static bool LoadMap(Dictionary <int, MapPoint> maps, Dictionary <int, Map> mapInfos)
        {
            bool result;

            try
            {
                using (MapBussiness db = new MapBussiness())
                {
                    MapInfo[] query = db.GetAllMap();
                    MapInfo[] array = query;
                    for (int j = 0; j < array.Length; j++)
                    {
                        MapInfo i = array[j];
                        if (!string.IsNullOrEmpty(i.PosX))
                        {
                            MapMgr._mapInstancePool.Add(i.ID, new Queue <Map>());
                            if (!maps.Keys.Contains(i.ID))
                            {
                                string[] tmp = i.PosX.Split(new char[]
                                {
                                    '|'
                                });
                                string[] tmp2 = i.PosX1.Split(new char[]
                                {
                                    '|'
                                });
                                string[] tmp3 = i.PosX2.Split(new char[]
                                {
                                    '|'
                                });
                                MapPoint pos    = new MapPoint();
                                string[] array2 = tmp;
                                for (int k = 0; k < array2.Length; k++)
                                {
                                    string s = array2[k];
                                    if (!string.IsNullOrEmpty(s.Trim()))
                                    {
                                        string[] xy = s.Split(new char[]
                                        {
                                            ','
                                        });
                                        pos.PosX.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                                    }
                                }
                                array2 = tmp2;
                                for (int k = 0; k < array2.Length; k++)
                                {
                                    string s = array2[k];
                                    if (!string.IsNullOrEmpty(s.Trim()))
                                    {
                                        string[] xy = s.Split(new char[]
                                        {
                                            ','
                                        });
                                        pos.PosX1.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                                    }
                                }
                                array2 = tmp3;
                                for (int k = 0; k < array2.Length; k++)
                                {
                                    string s = array2[k];
                                    if (!string.IsNullOrEmpty(s.Trim()))
                                    {
                                        string[] xy = s.Split(new char[]
                                        {
                                            ','
                                        });
                                        pos.PosX2.Add(new Point(int.Parse(xy[0]), int.Parse(xy[1])));
                                    }
                                }
                                maps.Add(i.ID, pos);
                            }
                            if (!mapInfos.ContainsKey(i.ID))
                            {
                                Tile   force = null;
                                string file  = string.Format("map\\{0}\\fore.map", i.ID);
                                if (File.Exists(file))
                                {
                                    force = new Tile(file, true);
                                }
                                Tile dead = null;
                                file = string.Format("map\\{0}\\dead.map", i.ID);
                                if (File.Exists(file))
                                {
                                    dead = new Tile(file, false);
                                }
                                if (force == null && dead == null)
                                {
                                    //if (MapMgr.log.IsErrorEnabled)
                                    {
                                        MapMgr.log.Error("地图" + i.ID.ToString() + "不存在!");
                                    }
                                    result = false;
                                    return(result);
                                }
                                mapInfos.Add(i.ID, new Map(i, force, dead));
                            }
                        }
                    }
                    if (maps.Count == 0 || mapInfos.Count == 0)
                    {
                        //if (MapMgr.log.IsErrorEnabled)
                        {
                            MapMgr.log.Error(string.Concat(new object[]
                            {
                                "maps:",
                                maps.Count,
                                ",mapInfos:",
                                mapInfos.Count
                            }));
                        }
                        result = false;
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                //if (MapMgr.log.IsErrorEnabled)
                {
                    MapMgr.log.Error("MapMgr", e);
                }
                result = false;
                return(result);
            }
            result = true;
            return(result);
        }