Ejemplo n.º 1
0
 public static Base BaseFactory(ServerGame game, Vector2 position)
 {
     Base baseObj = new Base(game.GameObjectCollection);
     game.GameObjectCollection.Add(baseObj);
     Base.ServerInitialize(baseObj, position);
     return baseObj;
 }
Ejemplo n.º 2
0
        //This method starts running the lobby and blocks until the lobby ends
        public void Run()
        {
            //Start the client listener in its own thread
            //This thread allows clients to asynchronously join the lobby
            Thread clientListenerThread = new Thread(new ThreadStart(ClientListener));
            clientListenerThread.Start();

            //wait to start
            MessageBox.Show("Enter to start", NetUtils.GetLocalIP());

            //lock client list
            clientsMutex.WaitOne();
            clientsLocked = true;
            clientsMutex.ReleaseMutex();

            // Start up the game.
            ServerGame game = new ServerGame(this);
            game.Run();

            //the game has finished
            foreach (RemotePlayer c in clients)
            {
                c.Disconnect();
            }

            //this.prelimListener.Stop();
            UdpTcpPair.StopListener();
            clientListenerThread.Join();
        }
Ejemplo n.º 3
0
 public static Company Factory(ServerGame game, PlayerGameObject controllingPlayer)
 {
     Company obj = new Company(game.GameObjectCollection);
     game.GameObjectCollection.Add(obj);
     Company.ServerInitialize(obj, controllingPlayer);
     return obj;
 }
Ejemplo n.º 4
0
 public static PlayerGameObject Factory(ServerGame game, RemotePlayer player)
 {
     PlayerGameObject obj = new PlayerGameObject(game.GameObjectCollection);
     game.GameObjectCollection.Add(obj);
     PlayerGameObject.ServerInitialize(obj, player.Id);
     return obj;
 }
Ejemplo n.º 5
0
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int baseObjID = message.ReadInt();

            Base obj = game.GameObjectCollection.Get<Base>(baseObjID);
            if (player.Owns(obj))
            {
                obj.BuildTransportVehicle();
            }
        }
Ejemplo n.º 6
0
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int coID = message.ReadInt();

            Company obj = game.GameObjectCollection.Get<Company>(coID);
            if (player.Owns(obj))
            {
                obj.Destroy();
            }
        }
Ejemplo n.º 7
0
        public ServerLogic(ServerGame game, Lobby lobby, Vector2 worldSize)
        {
            RemotePlayer player1 = null;
            RemotePlayer player2 = null;

            foreach (RemotePlayer player in lobby.Clients)
            {
                player.CreatPlayerGameObject(game);
            }

            if (lobby.Clients.Count > 0)
            {
                player1 = lobby.Clients[0];
            }

            if (lobby.Clients.Count > 1)
            {
                player2 = lobby.Clients[1];
            }

            Base player2Base = Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.84 * worldSize.X), (float)(0.75 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.11 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.37 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.63 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.67 * worldSize.X), (float)(0.89 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.5 * worldSize.X), (float)(0.75 * worldSize.Y)));

            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.11 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.37 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.63 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.33 * worldSize.X), (float)(0.89 * worldSize.Y)));

            Base player1Base = Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.5 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.25 * worldSize.Y)));
            Base.BaseFactory(game, new Vector2((float)(0.16 * worldSize.X), (float)(0.75 * worldSize.Y)));

            player1Base.SetPlayerInControll(player1);
            Company.Factory(game, player1.GameObject);

            for(int i = 0; i < 5; i++)
            {
                CombatVehicle.CombatVehicleFactory(game.GameObjectCollection, player1.GameObject, player1Base.Position + new Vector2(i * 20, 100));
                Transport.TransportFactory(game.GameObjectCollection, player1.GameObject, player1Base.Position + new Vector2(i * 20, 200));
            }


            player2Base.SetPlayerInControll(player2);
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int companyId = message.ReadInt();
            int vehicleId = message.ReadInt();

            Company co = game.GameObjectCollection.Get<Company>(companyId);
            CombatVehicle vic = game.GameObjectCollection.Get<CombatVehicle>(vehicleId);
            if (player.Owns(co) && player.Owns(co))
            {
                co.AddVehicle(vic);
            }
        }
Ejemplo n.º 9
0
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int baseObjID = message.ReadInt();
            int coID = message.ReadInt();

            Base obj = game.GameObjectCollection.Get<Base>(baseObjID);
            Company co = game.GameObjectCollection.Get<Company>(coID);
            if (player.Owns(obj) && player.Owns(co))
            {
                co.ResupplyPoint = obj;
            }
        }
        public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
        {
            int companyId = message.ReadInt();
            int positionCount = message.ReadInt();
            List<Vector2> positions = new List<Vector2>();

            for (int i = 0; i < positionCount; i++)
            {
                positions.Add(message.ReadVector2());
            }

            Company co = game.GameObjectCollection.Get<Company>(companyId);
            if (player.Owns(co))
            {
                co.SetPositions(game.GameObjectCollection, positions);
            }
        }
Ejemplo n.º 11
0
 public static void ExecuteCommand(RtsCommandMessage message, ServerGame game, RemotePlayer player)
 {
     player.GameObject.AddCompany(game);
 }
Ejemplo n.º 12
0
 public void Execute(ServerGame game, RemotePlayer player)
 {
     this.ResetReader();
     int typeID = this.ReadInt();
     commandDelegates[typeID](this, game, player);
 }
Ejemplo n.º 13
0
 public void HandleAllTCPMessages(ServerGame game)
 {
     foreach (RemotePlayer client in clients)
     {
         client.HandleAllTCPMessages(game);
     }
 }
Ejemplo n.º 14
0
 public Company AddCompany(ServerGame serverGame)
 {
     Company co = Company.Factory(serverGame, this);
     companies.Value.Add(co);
     return co;
 }