/// <summary> /// Construct a GameServerInfo object from a VTankObject.ServerInfo object. It uses a /// communicator to create a proxy pointing to the game server. /// </summary> /// <param name="communicator">Pre-initialized communicator.</param> /// <param name="server">Server information.</param> public GameServerInfo(Ice.Communicator communicator, VTankObject.ServerInfo server) { Name = server.name; Host = server.host; Port = server.port; UseGlacier2 = server.usingGlacier2; PlayerLimit = server.playerLimit; NumberOfPlayers = server.players; Approved = server.approved; CurrentMap = server.currentMap; CurrentGameMode = server.gameMode; Ice.ObjectPrx proxy = null; if (server.usingGlacier2) { proxy = communicator.stringToProxy(String.Format( "Theatre/router:tcp -h {0} -p {1} -t 5000", server.host, server.port)); } else { proxy = communicator.stringToProxy(String.Format( "GameSessionFactory:tcp -h {0} -p {1} -t 5000", server.host, server.port)); } // Ping once to make sure that the proxy is a valid one. // If it isn't, it throws Ice.ConnectionRefusedException, which is handled elsewhere. proxy.ice_ping(); pinger = new Pinger(proxy); }
/// <summary> /// Initialize any components required by this state. /// </summary> public override void Initialize() { ServiceManager.Game.FormManager.ClearWindow(); Options options = ServiceManager.Game.Options; RendererAssetPool.DrawShadows = GraphicOptions.ShadowMaps; mouseCursor = new MouseCursor(options.KeySettings.Pointer); mouseCursor.EnableCustomCursor(); renderer = ServiceManager.Game.Renderer; fps = new FrameCounter(); Chat = new ChatArea(); Projectiles = new ProjectileManager(); Tiles = new TexturedTileGroupManager(); Utilities = new UtilityManager(); cd = new Countdown(); Lazers = new LazerBeamManager(this); Scene.Add(Lazers, 0); Players = new PlayerManager(); currentGameMode = ServiceManager.Theater.GetCurrentGameMode(); Flags = new FlagManager(); Bases = new BaseManager(); EnvironmentEffects = new EnvironmentEffectManager(); buffbar = new BuffBar(); Scores = new ScoreBoard(currentGameMode, Players); input = new ChatInput(new Vector2(5, ServiceManager.Game.GraphicsDevice.Viewport.Height), 300);//300 is a magic number...Create a chat width variable. input.Visible = false; hud = HUD.GetHudForPlayer(Players.GetLocalPlayer()); localPlayer = Players.GetLocalPlayer(); Scene.MainEntity = localPlayer; sky = ServiceManager.Resources.GetTexture2D("textures\\misc\\background\\sky"); tips = new GameTips(new GameContext(CurrentGameMode, localPlayer)); helpOverlay = new HelpOverlay(); }
private GameModeHandler CreateGameHandler(VTankObject.GameMode mode) { if (mode == VTankObject.GameMode.CAPTURETHEBASE) { return(new CaptureTheBaseMode(Game.CurrentMap)); } return(null); }
/// <summary> /// Refresh the in-game data. This is typically called when new information is needed /// due to a map rotation. /// </summary> private void Refresh() { lock (this) { timeLeft = session.GetTimeLeft(); currentMapName = session.GetCurrentMapName(); currentGameMode = session.GetGameMode(); NeedsRefresh = false; } }
public void SetMap(Map map, GamePlayState _state) { currentGameMode = _state.CurrentGameMode; flags = _state.Flags; utilities = _state.Utilities; bases = _state.Bases; try { GraphicsDevice device = Renderer.GraphicOptions.graphics.GraphicsDevice; PresentationParameters pp = device.PresentationParameters; renderTarget = new RenderTarget2D(device, (int)map.Width * miniMapScaleFactor + 2 * miniMapBorderBuffer, (int)map.Height * miniMapScaleFactor + 2 * miniMapBorderBuffer, 1, SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality, RenderTargetUsage.PreserveContents); DepthStencilBuffer previousDepth = device.DepthStencilBuffer; device.DepthStencilBuffer = null; device.SetRenderTarget(0, renderTarget); device.Clear(Color.Black); ServiceManager.Game.Batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); Texture2D miniMapDrawer = ServiceManager.Resources.GetTexture2D("textures\\misc\\MiniMap\\wallandbackground"); for (uint x = 0; x < map.Width; x++) { for (uint y = 0; y < map.Height; y++) { Tile tmpTile = map.GetTile(x, y); if (!tmpTile.IsPassable) { ServiceManager.Game.Batch.Draw(miniMapDrawer, new Vector2(x * miniMapScaleFactor + miniMapBorderBuffer, y * miniMapScaleFactor + miniMapBorderBuffer), new Rectangle(0, 0, miniMapScaleFactor, miniMapScaleFactor), Color.White); } } } ServiceManager.Game.Batch.End(); device.DepthStencilBuffer = previousDepth; device.SetRenderTarget(0, null); texture = renderTarget.GetTexture(); renderTarget = new RenderTarget2D(device, 235, 235, 1, SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality, RenderTargetUsage.PreserveContents); } catch (Exception ex) { Console.Error.WriteLine(ex); } }
/// <summary> /// Downloads the current map if necessary. /// </summary> public void DownloadAndLoadMap() { const string MapFolder = "maps"; DirectoryInfo dir = new DirectoryInfo(MapFolder); if (!dir.Exists) { dir.Create(); } currentMapName = GameServer.GetCurrentMapName(); GameMode = GameServer.GetCurrentGameMode(); string fileName = String.Format("{0}{1}{2}", MapFolder, System.IO.Path.DirectorySeparatorChar, currentMapName); Map playableMap = MapDownloader.GetMap(currentMapName, fileName, MainServer); Game.CurrentMap = playableMap; }
public void InvokeOnMapRotation() { buffer.PopAll(); const int MAX_TRIES = 20; string mapName = null; for (int i = 0; i < MAX_TRIES; ++i) { mapName = GameServer.GetCurrentMapName(); if (currentMapName != mapName) { break; } Thread.Sleep(1000); } VTankObject.GameMode mode = GameServer.GetCurrentGameMode(); MapRotationEventArgs args = new MapRotationEventArgs(mapName, mode); Game.Reset(); if (Game.GameModeHandler != null) { Game.GameModeHandler.Dispose(); } DownloadAndLoadMap(); Game.GameModeHandler = CreateGameHandler(mode); RefreshPlayerList(); OnMapRotation(args); GameServer.Ready(); }
/// <summary> /// Constructs the game mode. /// </summary> /// <param name="currentMap"></param> /// <param name="currentGameMode"></param> public GameModeHandler(Map currentMap, VTankObject.GameMode currentGameMode) { CurrentMap = currentMap; CurrentGameMode = currentGameMode; }
public void SetMap(Map map, GamePlayState _state) { currentGameMode = _state.CurrentGameMode; flags = _state.Flags; utilities = _state.Utilities; bases = _state.Bases; try { GraphicsDevice device = Renderer.GraphicOptions.graphics.GraphicsDevice; PresentationParameters pp = device.PresentationParameters; renderTarget = new RenderTarget2D(device, (int)map.Width * miniMapScaleFactor + 2 * miniMapBorderBuffer, (int)map.Height * miniMapScaleFactor + 2 * miniMapBorderBuffer, 1, SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality, RenderTargetUsage.PreserveContents); DepthStencilBuffer previousDepth = device.DepthStencilBuffer; device.DepthStencilBuffer = null; device.SetRenderTarget(0, renderTarget); device.Clear(Color.Black); ServiceManager.Game.Batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); Texture2D miniMapDrawer = ServiceManager.Resources.GetTexture2D("textures\\misc\\MiniMap\\wallandbackground"); for (uint x = 0; x < map.Width; x++) { for (uint y = 0; y < map.Height; y++) { Tile tmpTile = map.GetTile(x, y); if (!tmpTile.IsPassable) ServiceManager.Game.Batch.Draw(miniMapDrawer, new Vector2(x * miniMapScaleFactor + miniMapBorderBuffer, y * miniMapScaleFactor + miniMapBorderBuffer), new Rectangle(0, 0, miniMapScaleFactor, miniMapScaleFactor), Color.White); } } ServiceManager.Game.Batch.End(); device.DepthStencilBuffer = previousDepth; device.SetRenderTarget(0, null); texture = renderTarget.GetTexture(); renderTarget = new RenderTarget2D(device, 235, 235, 1, SurfaceFormat.Color, pp.MultiSampleType, pp.MultiSampleQuality, RenderTargetUsage.PreserveContents); } catch (Exception ex) { Console.Error.WriteLine(ex); } }
public MapRotationEventArgs(string mapName, VTankObject.GameMode gameMode) { MapName = mapName; GameMode = gameMode; }