public static int GetMapIndex(int index, byte type, int serverId) { if (index != 0 && !MapMgr._maps.Keys.Contains(index)) { index = 0; } if (index != 0) { return(index); } List <int> list = new List <int>(); foreach (int current in MapMgr._serverMap[serverId]) { MapInfo mapInfo = MapMgr.FindMapInfo(current); if ((type & mapInfo.Type) != 0) { list.Add(current); } } if (list.Count == 0) { int count = MapMgr._serverMap[serverId].Count; return(MapMgr._serverMap[serverId][MapMgr.random.Next(count)]); } int count2 = list.Count; return(list[MapMgr.random.Next(count2)]); }
public static bool ReLoadMap() { try { Dictionary <int, MapPoint> maps = new Dictionary <int, MapPoint>(); Dictionary <int, Map> mapInfos = new Dictionary <int, Map>(); if (MapMgr.LoadMap(maps, mapInfos)) { MapMgr.m_lock.AcquireWriterLock(15000); try { MapMgr._maps = maps; MapMgr._mapInfos = mapInfos; return(true); } catch { } finally { MapMgr.m_lock.ReleaseWriterLock(); } } } catch (Exception exception) { if (MapMgr.log.IsErrorEnabled) { MapMgr.log.Error("ReLoadMap", exception); } } return(false); }
public override void Stop() { if (base.GameState == eGameState.GameOver) { this.m_gameState = eGameState.Stopped; List <Player> players = base.GetAllFightPlayers(); foreach (Player p in players) { if (p.IsActive && !p.FinishTakeCard && p.CanTakeOut > 0) { this.TakeCard(p, true); } } Dictionary <int, Player> players2; Monitor.Enter(players2 = this.m_players); try { this.m_players.Clear(); } finally { Monitor.Exit(players2); } MapMgr.ReleaseMapInstance(this.m_map); base.Stop(); } }
public static bool ReLoadServerMap() { bool result; try { Dictionary <int, List <int> > temServerMapList = new Dictionary <int, List <int> >(); Dictionary <int, List <int> > temSimpleMapList = new Dictionary <int, List <int> >(); Dictionary <int, List <int> > temNormalMapList = new Dictionary <int, List <int> >(); Dictionary <int, List <int> > temDifficultMapList = new Dictionary <int, List <int> >(); Dictionary <int, List <int> > temProfessionalMapList = new Dictionary <int, List <int> >(); if (MapMgr.InitServerMap(temServerMapList, temSimpleMapList, temNormalMapList, temDifficultMapList, temProfessionalMapList)) { MapMgr.m_lock.AcquireWriterLock(-1); try { MapMgr._serverMap = temServerMapList; MapMgr.simpleMapList = temSimpleMapList; MapMgr.normalMapList = temNormalMapList; MapMgr.difficultMapList = temDifficultMapList; MapMgr.professionalMapList = temProfessionalMapList; result = true; return(result); } catch { } finally { MapMgr.m_lock.ReleaseWriterLock(); } } } catch (Exception e) { //if (MapMgr.log.IsErrorEnabled) { MapMgr.log.Error("ReLoadMapWeek", e); } } result = false; return(result); }
public void StartGame() { if (base.GameState == eGameState.Loading) { this.m_gameState = eGameState.Playing; base.ClearWaitTimer(); base.SendSyncLifeTime(); List <Player> list = base.GetAllFightPlayers(); MapPoint mapPos = MapMgr.GetMapRandomPos(this.m_map.Info.ID); GSPacketIn pkg = new GSPacketIn(91); pkg.WriteByte(99); pkg.WriteInt(list.Count); foreach (Player p in list) { p.Reset(); Point pos = base.GetPlayerPoint(mapPos, p.Team); p.SetXY(pos); this.AddPlayer(p); p.StartFalling(true); p.StartGame(); pkg.WriteInt(p.Id); pkg.WriteInt(p.X); pkg.WriteInt(p.Y); pkg.WriteInt(p.Direction); pkg.WriteInt(p.Blood); } base.SendToAll(pkg); if (this.m_npcID != 0 && base.RoomType == eRoomType.Match) { SimpleNpc npc = new SimpleNpc(this.physicalId++, this, NPCInfoMgr.GetNpcInfoById(this.m_npcID), 1, -1, 0); Point npcPos = base.GetPlayerPoint(mapPos, 3); npc.Reset(); npc.SetXY(npcPos); this.AddLiving(npc); npc.StartFalling(false); npc.IsNoHole = true; } base.WaitTime(list.Count * 1000); base.OnGameStarted(); } }
public static Map AllocateMapInstance(int mapId) { Map result; if (MapMgr._mapInstancePool.ContainsKey(mapId)) { Map source = MapMgr.FindMap(mapId); Map map = null; MapMgr.m_lock.AcquireWriterLock(-1); try { if (MapMgr._mapInstancePool[mapId].Count > 0) { map = MapMgr._mapInstancePool[mapId].Dequeue(); } } catch { } finally { MapMgr.m_lock.ReleaseWriterLock(); } if (map == null) { result = source.Clone(); } else { map.CopyData(source); result = map; } } else { result = null; } return(result); }
public static bool Init() { bool result; try { MapMgr.m_lock = new ReaderWriterLock(); MapMgr._maps = new Dictionary <int, MapPoint>(); MapMgr._mapInfos = new Dictionary <int, Map>(); MapMgr._mapInstancePool = new Dictionary <int, Queue <Map> >(); if (!MapMgr.LoadMap(MapMgr._maps, MapMgr._mapInfos)) { result = false; return(result); } MapMgr._serverMap = new Dictionary <int, List <int> >(); MapMgr.simpleMapList = new Dictionary <int, List <int> >(); MapMgr.normalMapList = new Dictionary <int, List <int> >(); MapMgr.difficultMapList = new Dictionary <int, List <int> >(); MapMgr.professionalMapList = new Dictionary <int, List <int> >(); if (!MapMgr.InitServerMap(MapMgr._serverMap, MapMgr.simpleMapList, MapMgr.normalMapList, MapMgr.difficultMapList, MapMgr.professionalMapList)) { result = false; return(result); } } catch (Exception e) { //if (MapMgr.log.IsErrorEnabled) { MapMgr.log.Error("MapMgr", e); } result = false; return(result); } result = true; return(result); }
public static bool ReLoadMap() { bool result; try { MapMgr._mapInstancePool.Clear(); Dictionary <int, MapPoint> tempMaps = new Dictionary <int, MapPoint>(); Dictionary <int, Map> tempMapInfos = new Dictionary <int, Map>(); if (MapMgr.LoadMap(tempMaps, tempMapInfos)) { MapMgr.m_lock.AcquireWriterLock(-1); try { MapMgr._maps = tempMaps; MapMgr._mapInfos = tempMapInfos; result = true; return(result); } catch { } finally { MapMgr.m_lock.ReleaseWriterLock(); } } } catch (Exception e) { //if (MapMgr.log.IsErrorEnabled) { MapMgr.log.Error("ReLoadMap", e); } } result = false; return(result); }
public static int GetMapIndex(int index, byte type, int serverId) { if (index != 0 && !MapMgr._maps.Keys.Contains(index)) { index = 0; } int result; if (index == 0) { List <int> tempIndex = new List <int>(); foreach (int id in MapMgr._serverMap[serverId]) { MapInfo tempInfo = MapMgr.FindMapInfo(id); if ((type & tempInfo.Type) != 0) { tempIndex.Add(id); } } if (tempIndex.Count == 0) { int count = MapMgr._serverMap[serverId].Count; result = MapMgr._serverMap[serverId][MapMgr.random.Next(count)]; } else { int count = tempIndex.Count; result = tempIndex[MapMgr.random.Next(count)]; } } else { result = index; } return(result); }