Beispiel #1
0
        protected override void Initialize()
        {
            base.Initialize();
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            Engine = new fbEngine(this);
            Engine.SetSize(1280, 720);
            LoadTexturesFromFile("cfg/textures.cfg");

            Engine.DefaultFont           = new Font();
            Engine.DefaultFont.FontSheet = Engine.GetTexture("font");
            Engine.DefaultFont.CharSize  = new Vector2(8);

            NetMessage3.Setup();

            Game       = new fbGame();
            Game.Ready = false;
            Game.SetupClientSideEventHandler(Engine);

            //eugh
            fbNetClient.Game = Game;

            UI = new fbInterface(Game, Engine);

            Engine.StartNetClient();
        }
Beispiel #2
0
        private void ReceiveMessage(string fullmessage)
        {
            foreach (string message in fullmessage.Split(';'))
            {
                if (message == "")
                {
                    continue;
                }

                if (Verbose)
                {
                    Game.Log.Add(
                        string.Format(
                            "<- s: {0}",
                            message
                            )
                        );
                }

                NetMessage3 nm3message = new NetMessage3(message);
                Game.HandleNetMessage(nm3message);
            }
        }
Beispiel #3
0
        public void HandleNetMessage(NetMessage3 message)
        {
            switch (message.Signature.MessageType)
            {
            case NM3MessageType.message:
                Log.Add(message.Get <string>("message"));
                break;

            case NM3MessageType.world_create:
                World = new fbWorld(
                    this,
                    message.Get <int>("width"),
                    message.Get <int>("height")
                    );
                break;

            case NM3MessageType.world_playerstart:
                int x = message.Get <int>("x");
                int y = message.Get <int>("y");

                if (!World.PlayerStarts
                    .Any(v2 => v2.X == x && v2.Y == y))
                {
                    World.PlayerStarts.Add(new Vector2i(x, y));
                }
                break;

            case NM3MessageType.station_create:
                World.SpawnStation(
                    message.Get <int>("owner"),
                    message.Get <int>("id"),
                    message.Get <int>("x"),
                    message.Get <int>("y")
                    );
                break;

            case NM3MessageType.station_set_project:
                Station s = World.Map.Stations
                            [message.Get <int>("station-id")];

                ProjectType type =
                    (ProjectType)message.Get <int>("projecttype");

                switch (type)
                {
                case ProjectType.UnitProject:
                    s.Project = new BuildingProject(
                        this,
                        message.Get <int>("owner"),
                        s,
                        message.Get <int>("length"),
                        UnitType.GetType(
                            (UnitTypes)
                            message.Get <int>("project")
                            )
                        );
                    break;

                case ProjectType.TechProject:
                    s.Project = new TechProject(
                        this,
                        message.Get <int>("owner"),
                        s,
                        message.Get <int>("length"),
                        (TechID)message.Get <int>("project")
                        );
                    break;

                default:
                    throw new ArgumentException();
                }

                break;

            case NM3MessageType.player_add_tech:
                World.Players[message.Get <int>("id")]
                .Tech.Add((TechID)message.Get <int>("tech"));
                break;

            case NM3MessageType.planet_create:
                World.SpawnPlanet(
                    message.Get <int>("x"),
                    message.Get <int>("y")
                    );
                break;

            case NM3MessageType.unit_create:
                EventHandler.Push(
                    new CreateUnitEvent(
                        UnitType.GetType(
                            (UnitTypes)
                            message.Get <int>("type")
                            ),
                        message.Get <int>("owner"),
                        message.Get <int>("id"),
                        message.Get <int>("x"),
                        message.Get <int>("y")
                        )
                    );
                break;

            case NM3MessageType.unit_move:
                EventHandler.Push(
                    new UnitMoveEvent(
                        message.Get <int>("id"),
                        message.Get <int>("x"),
                        message.Get <int>("y"),
                        false
                        )
                    );
                break;

            case NM3MessageType.player_new:
                World.AddPlayer(
                    new Player(
                        "Unnamed player",
                        message.Get <int>("id"),
                        Color.White
                        )
                    );
                break;

            case NM3MessageType.player_assign_id:
                We = message.Get <int>("id");
                break;

            case NM3MessageType.player_name:
                EventHandler.Push(
                    new NameEvent(
                        message.Get <int>("id"),
                        message.Get <string>("name"),
                        message.Get <string>("color")
                        )
                    );
                break;

            case NM3MessageType.player_current:
                World.CurrentID = message.Get <int>("index");

                //todo: event this?
                Log.Add(
                    string.Format(
                        "It is now {0}'s turn.",
                        World.Players[World.CurrentID].Name
                        )
                    );
                break;

            case NM3MessageType.unit_status:
                Unit u = World.Units[message.Get <int>("id")];
                u.Moves    = message.Get <int>("moves");
                u.Attacks  = message.Get <int>("attacks");
                u.Strength = message.Get <int>("strength");

                //todo: should probably be an event
                if (u.Strength <= 0)
                {
                    World.DespawnUnit(u);
                }
                break;

            case NM3MessageType.player_status:
                World.GetPlayer(message.Get <int>("id"))
                .Money = message.Get <int>("money");
                break;

            case NM3MessageType.client_disconnect:
                EventHandler.Push(
                    new PlayerDisconnectEvent(
                        message.Get <int>("id")
                        )
                    );
                break;

            case NM3MessageType.client_pass:
                World.Pass();
                break;

            case NM3MessageType.client_ready:
                Ready = true;
                break;

            case NM3MessageType.client_unready:
                Ready = false;
                break;

            default:
                throw new Exception();
            }
        }
Beispiel #4
0
 public void Send(NetMessage3 message)
 {
     SendQueue.Add(message.Format());
 }