コード例 #1
0
        public static GameScreen Create(ScreenManager screenManager)
        {
            GCM gcm = screenManager.AsDynamic().GCM;

            void Noop()
            {
                var gameplayScreen = screenManager.FirstOrDefault <GameplayScreen>();

                if (gameplayScreen != null && gameplayScreen.Settings != null)
                {
                    gcm.UpdateMinimapColors(gameplayScreen.Settings);
                }
            }

            gcm.LoadAllResources(screenManager.AsDynamic().GeneralContentManager, screenManager.GraphicsDevice);

            return((GameScreen)Activator.CreateInstance(JournalMenuType, GameSave.DemoSave, gcm, (Action)Noop));
        }
コード例 #2
0
        public override bool Handle(GameConsole console, string[] parameters)
        {
            string user;
            string password;

            if (parameters.Length == 2)
            {
                user     = parameters[1];
                password = null;
            }
            else if (parameters.Length == 2)
            {
                user     = parameters[1];
                password = parameters[2];
            }
            else
            {
                return(false);
            }

            var saveFileManager = ((object)screenManager.AsDynamic().SaveFileManager).AsDynamic();

            if (saveFileManager.AreSaveFilesFull())
            {
                console.AddLine("No free save slots found", Color.Yellow);
                return(true);
            }

            string server;
            string port;

            var serverUriParts = parameters[0].Split(':');

            if (serverUriParts.Length == 1)
            {
                server = serverUriParts[0];
                port   = "38281";
            }
            else if (serverUriParts.Length == 2)
            {
                server = serverUriParts[0];
                port   = serverUriParts[1];
            }
            else
            {
                return(false);
            }

            var serverUri = new Uri($"ws://{server}:{port}");

            var connectionResult = Client.Connect(serverUri.ToString(), user, password);

            if (!connectionResult.Successful)
            {
                console.AddLine($"Connection Failed: {string.Join(", ", ((LoginFailure)connectionResult).Errors)}", Color.Yellow);
                return(true);
            }

            console.AddLine("Connected!");

            var connected      = (LoginSuccessful)connectionResult;
            var slotDataParser = new SlotDataParser(connected.SlotData, Client.SeedString);

            IsWaitingForDifficulty = true;
            Seed     = slotDataParser.GetSeed();
            Settings = slotDataParser.GetSettings();
            OnDifficultySelectedHook = saveGame => {
                saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSaveServerKey] = serverUri.ToString();
                saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSaveUserKey]   = user;
                if (string.IsNullOrEmpty(password))
                {
                    saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSavePasswordKey] = password;
                }
                saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSaveConnectionId] = Client.ConnectionId;
                saveGame.DataKeyInts[ArchipelagoItemLocationMap.GameItemIndex] = 0;
                saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSavePyramidsKeysUnlock] =
                    slotDataParser.GetPyramidKeysGate().ToString();
                saveGame.DataKeyStrings[ArchipelagoItemLocationRandomizer.GameSavePersonalItemIds] =
                    JsonConvert.SerializeObject(slotDataParser.GetPersonalItems());
            };

            object safeFileManager = screenManager.AsDynamic().SaveFileManager;

            var gameDifficultyMenu =
                (GameScreen)GameDifficultyMenuType.CreateInstance(false, safeFileManager, (Action <GameSave.EGameDifficultyType>)OnDifficultySelected);

            screenManager.AddScreen(gameDifficultyMenu, PlayerIndex.One);

            console.Close();

            return(true);
        }