/// <summary> /// Gets the battlefield. /// </summary> /// <param name="mapType">Type of the map.</param> /// <param name="level">The level.</param> /// <returns></returns> public Battlefield GetBattlefield(BattlefieldMapType mapType, byte level) { Battlefield battlefield = null; BattlefielDsLock.AcquireReaderLock(_clusterServiceLocator.GlobalConstants.DEFAULT_LOCK_TIMEOUT); foreach (var b in BattlefielDs) { if (b.Value.MapType == mapType && b.Value.LevelMax >= level && b.Value.LevelMin <= level) { battlefield = b.Value; } } BattlefielDsLock.ReleaseReaderLock(); // DONE: Create new if not found any if (battlefield is null) { var map = (uint)GetBattleGrounMapIdByTypeId((BattleGroundTypeId)mapType); if (_clusterServiceLocator.WcNetwork.WorldServer.BattlefieldCheck(map)) { battlefield = new Battlefield(mapType, level, map, _clusterServiceLocator); } else { return(null); } } return(battlefield); }
public Battlefield(BattlefieldMapType rMapType, byte rLevel, uint rMap, ClusterServiceLocator clusterServiceLocator) { _clusterServiceLocator = clusterServiceLocator; Id = Interlocked.Increment(ref _clusterServiceLocator.WcHandlersBattleground._battlefielDsCounter); LevelMin = 0; LevelMax = 60; MapType = rMapType; _map = rMap; _maxPlayersPerTeam = _clusterServiceLocator.WsDbcDatabase.Battlegrounds[(byte)rMapType].MaxPlayersPerTeam; _minPlayersPerTeam = _clusterServiceLocator.WsDbcDatabase.Battlegrounds[(byte)rMapType].MinPlayersPerTeam; _clusterServiceLocator.WcHandlersBattleground.BattlefielDsLock.AcquireWriterLock(_clusterServiceLocator.GlobalConstants.DEFAULT_LOCK_TIMEOUT); _clusterServiceLocator.WcHandlersBattleground.BattlefielDs.Add(Id, this); _clusterServiceLocator.WcHandlersBattleground.BattlefielDsLock.ReleaseWriterLock(); _bfTimer = new Timer(Update, null, 20000, 20000); }
public Battlefield(BattlefieldMapType rMapType, uint rMap) { MembersTeam1 = new List <WS_PlayerData.CharacterObject>(); MembersTeam2 = new List <WS_PlayerData.CharacterObject>(); WorldServiceLocator._WS_Battlegrounds.BATTLEFIELDs.Add(ID, this); }