Пример #1
0
        public void CreateNewGame(NewGameInfo Info)
        {
            new LogicFactory();

            // load game settings
            settings = new GameSettings("gamesettings.txt");
            settings.SetDifficulty(Info.Difficulty);

            // set up game server
            SetupServer();

            // get root game object
            ClassicGame game = container.Root as ClassicGame;

            LogicFactory.SetParameter("resource", app.ResourceManager);

            // open gam.dat
            IGameObjectCreator creator = new ClassicBurnGfxCreator();

            creator.Create(game);
            var gamdat = LogicFactory.GetParameter <Burntime.Data.BurnGfx.Save.SaveGame>("gamdat");

            // create world object
            game.World = container.Create <ClassicWorld>();
            game.World.VictoryCondition = container.Create <VictoryCondition>();

            // set difficulty
            game.World.Difficulty = Info.Difficulty;

            // add player objects
            AddPlayer(game, Info, gamdat, settings);

            // set main map
            game.World.Map = container.Create <Map>(new object[] { "maps/mat_000.burnmap" });
            LogicFactory.SetParameter("mainmap", game.World.Map);
            game.World.Ways = container.Create <Ways>(new object[] { "ways@maps/mat_000-ways.txt" });

            // set constructions
            game.Constructions = (Constructions)app.ResourceManager.GetData("*****@*****.**");
            game.ItemTypes     = container.Create <ItemTypes>(new object[] { "*****@*****.**" });

            // set productions
            LoadProductions(game, gamdat);

            // create respawn class
            game.World.Respawn = container.Create <CharacterRespawn>(new object[] { settings.Respawn.NPC, settings.Respawn.Trader,
                                                                                    settings.Respawn.Mutant, settings.Respawn.Dog });

            // create locations
            creator = new OriginalLocationCreator();
            creator.Create(game);
            creator = new LocationCreator();
            creator.Create(game);

            // place npcs
            LoadNPCs(game, gamdat);

            // set start locations for player
            SetStartLocations(game);

            // place items
            LoadItems(game, gamdat);

            // set trader
            LoadTrader(game, gamdat);

            // set start inventory for player
            SetStartInventory(game);

            container.Synchronize(false); // DEBUG

            app.Server.Run();
        }
Пример #2
0
        void AddPlayer(ClassicGame game, NewGameInfo Info, Burntime.Data.BurnGfx.Save.SaveGame gamdat, GameSettings settings)
        {
            // share container for all local player
            Burntime.Framework.States.StateManager sharedContainer = null;
            // if no synchronization mode is active, then share container with game server
            if (!BurntimeClassic.Instance.Settings["game"].GetBool("always_synchronize"))
            {
                sharedContainer = container;
            }

            // no ai mode
            bool disableAI = BurntimeClassic.Instance.Settings["game"].GetBool("disable_ai");

            app.ActiveClient = Burntime.Framework.Network.GameClient.NoClient;

            PixelColor[] colors = new PixelColor[4] {
                new PixelColor(0, 208, 0),
                new PixelColor(240, 64, 56),
                new PixelColor(0, 0, 0),    // not used
                new PixelColor(0, 0, 0)
            };                              // not used

            PixelColor[] colorsdark = new PixelColor[4] {
                new PixelColor(0, 132, 0),
                new PixelColor(192, 0, 0),
                new PixelColor(80, 80, 132),
                new PixelColor(156, 156, 156)
            };

            int[] iconIDs = new int[] { 0, 1, 3, 2 };

            for (int i = 0; i < 4; i++)
            {
                game.World.Players.Add(container.Create <Player>(new object[] { i }));
                game.World.Players[i].Type                              = PlayerType.Ai;
                game.World.Players[i].IconID                            = iconIDs[i];
                game.World.Players[i].Character                         = container.Create <PlayerCharacter>();
                game.World.Players[i].Name                              = app.ResourceManager.GetString("burn?" + (170 + i).ToString());
                game.World.Players[i].Character.Position                = new Vector2();
                game.World.Players[i].Character.Body                    = app.ResourceManager.GetData("syssze.raw?" + gamdat.Characters[i].SpriteId + "-" + (gamdat.Characters[i].SpriteId + 15));
                game.World.Players[i].Character.Path                    = container.Create <PathFinding.ComplexPath>();
                game.World.Players[i].Character.Mind                    = container.Create <AI.PlayerControlledMind>(new object[] { game.World.Players[i].Character });
                game.World.Players[i].Character.Items.MaxCount          = 6;
                game.World.Players[i].Flag                              = app.ResourceManager.GetData("[email protected]?" + gamdat.Player[i].Info.FlagId + "-" + (gamdat.Player[i].Info.FlagId + 3));
                game.World.Players[i].Flag.Object.Animation.Progressive = false;
                game.World.Players[i].Character.Health                  = settings.StartHealth;
                game.World.Players[i].Character.Experience              = settings.StartExperience;
                game.World.Players[i].Character.Food                    = settings.StartFood;
                game.World.Players[i].Character.Water                   = settings.StartWater;
                game.World.Players[i].Character.Class                   = (CharClass)gamdat.Characters[i].Type;
                game.World.Players[i].Character.Player                  = game.World.Players[i];
                game.World.Players[i].Color                             = colors[i];
                game.World.Players[i].ColorDark                         = colorsdark[i];
                game.World.Players[i].OnMainMap                         = true;
                game.World.Players[i].BaseExperience                    = settings.StartExperience;

                game.World.AllCharacters += game.World.Players[i].Character;
            }

            if (Info.NameOne != "" && Info.NameOne != null)
            {
                game.World.Players[0].Name             = Info.NameOne;
                game.World.Players[0].Character.FaceID = Info.FaceOne;
                game.World.Players[0].Type             = PlayerType.Human;

                Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 0, sharedContainer);
                sharedContainer = client.StateContainer;
                app.GameServer.AddClient(client);
                app.Clients.Add(client);
            }
            else
            {
                Burntime.Framework.AI.GameClientAI client = new AI.AiPlayer(app, 0, container);
                app.Server.AddAI(client);
            }

            game.World.Players[0].Color          = colors[(int)Info.ColorOne];
            game.World.Players[0].ColorDark      = colorsdark[(int)Info.ColorOne];
            game.World.Players[0].IconID         = Info.ColorOne == BurntimePlayerColor.Green ? 0 : 1;
            game.World.Players[0].BodyColorSet   = Info.ColorOne == BurntimePlayerColor.Green ? 2 : 0;
            game.World.Players[0].Character.Body = Helper.GetCharacterBody(2, game.World.Players[0].BodyColorSet);
            game.World.Players[0].Flag           = app.ResourceManager.GetData(Info.ColorOne == BurntimePlayerColor.Green ? "[email protected]?0-3" : "[email protected]?8-11");

            if (Info.NameTwo != "" && Info.NameTwo != null)
            {
                game.World.Players[1].Name             = Info.NameTwo;
                game.World.Players[1].Character.FaceID = Info.FaceTwo;
                game.World.Players[1].Type             = PlayerType.Human;

                Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 1, sharedContainer);
                app.GameServer.AddClient(client);
                app.Clients.Add(client);
            }
            else
            {
                app.Server.AddAI(new AI.AiPlayer(app, 1, container));
            }

            game.World.Players[1].Color          = colors[(int)Info.ColorTwo];
            game.World.Players[1].ColorDark      = colorsdark[(int)Info.ColorTwo];
            game.World.Players[1].IconID         = Info.ColorTwo == BurntimePlayerColor.Green ? 0 : 1;
            game.World.Players[1].BodyColorSet   = Info.ColorTwo == BurntimePlayerColor.Green ? 2 : 0;
            game.World.Players[1].Character.Body = Helper.GetCharacterBody(2, game.World.Players[1].BodyColorSet);
            game.World.Players[1].Flag           = app.ResourceManager.GetData(Info.ColorTwo == BurntimePlayerColor.Green ? "[email protected]?0-3" : "[email protected]?8-11");

            game.World.Players[2].BodyColorSet = -1;
            game.World.Players[3].BodyColorSet = 1;

            app.Server.AddAI(new AI.AiPlayer(app, 2, container));
            app.Server.AddAI(new AI.AiPlayer(app, 3, container));

            // add ai state objects
            foreach (Player p in game.World.Players)
            {
                if (p.Type == PlayerType.Ai)
                {
                    p.AiState = container.Create <AI.ClassicAiState>(p, settings.AiSettings);
                }
            }

            // kill all ai player
            if (disableAI)
            {
                foreach (Player p in game.World.Players)
                {
                    if (p.Type == PlayerType.Ai)
                    {
                        p.IsDead = true;
                    }
                }

                foreach (Burntime.Framework.Network.GameClient client in app.Server.Clients)
                {
                    if (game.World.Players[client.Player].Type == PlayerType.Ai)
                    {
                        client.Die();
                    }
                }
            }
        }