Ejemplo n.º 1
0
        public Unit(
            fbWorld world,
            UnitType unitType,
            int owner,
            int id,
            int x,
            int y
            )
        {
            animateable = new Animateable(this);

            World = world;
            game  = World.Game;

            UnitType = unitType;
            Owner    = owner;
            ID       = id;
            this.x   = x;
            this.y   = y;
            Moves    = UnitType.Moves;
            Attacks  = UnitType.Attacks;
            Strength = UnitType.Strength;
        }
Ejemplo n.º 2
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();
            }
        }