示例#1
0
        // create a new game session
        public static Session Create(CreationArgs args)
        {
            Session session = new Session();

            session.name         = args.Name;
            session.rename       = args.Name;
            session.transferPath = args.TransferPath;

            session.installation = args.Installation;
            session.version      = args.Installation.Version;
            session.modName      = args.Mod.Name;
            session.campaignName = args.Campaign.Name;

            session.difficulty             = args.Difficulty;
            session.startFactionIndex      = args.StartFaction.Index;
            session.lastPlayedFactionIndex = 0;
            session.playerFactionIndex     = args.StartFaction.Index;
            session.autoSolve         = args.AutoSolve;
            session.autoManage        = args.AutoManage;
            session.shortCampaign     = args.ShortCampaign;
            session.arcadeBattles     = args.ArcadeBattles;
            session.noBattleTimeLimit = args.NoBattleTimeLimit;

            session.takenFactionIndices.Add(args.StartFaction.Index);
            session.freeFactionIndices.AddRange(args.FreeFactions.Where(f => f != args.StartFaction).Select(f => f.Index));

            session.InitGameInfo();
            session.InitFactionsInfo();

            session.SavePlayerInfo();
            session.SaveGameInfo();
            session.SaveFactionsFile();

            session.UpdateCurrentFaction();

            sessions.Add(session.GamePath, session);

            return(session);
        }
示例#2
0
        void CreateGame(object sender, RoutedEventArgs e)
        {
            try
            {
                string name = cNameTextBox.Text;
                if (string.IsNullOrWhiteSpace(name))
                {
                    Debug.ShowWarning("Please type in a game session name.");
                    cNameTextBox.Focus();
                    return;
                }

                int invalidChar = name.IndexOfAny(Path.GetInvalidFileNameChars());
                if (invalidChar >= 0)
                {
                    Debug.ShowWarning("The symbol {0} is not allowed in the game session name.", name[invalidChar].ToString());
                    cNameTextBox.Focus();
                    return;
                }

                if (Session.ContainsSession(name))
                {
                    Debug.ShowWarning("There is already a game session with the name " + name);
                    cNameTextBox.Focus();
                    return;
                }

                string transferPath = Path.GetFullPath(cTransferTextBox.Text);
                Directory.CreateDirectory(transferPath);

                string gameFile = Path.Combine(transferPath, name, Session.GameFileName);
                if (File.Exists(gameFile))
                {
                    Debug.ShowWarning("There is already a game session file in the following path. It might be from an older session which you left. If you are sure it's not used by / transferring to other players anymore delete it manually.\n\n" + gameFile);
                    return;
                }

                Difficulty difficulty = (byte)cDifficultyComboBox.SelectedIndex;
                if (difficulty == Difficulty.Unset)
                {
                    Debug.ShowWarning("Invalid difficulty.");
                    cDifficultyComboBox.Focus();
                    return;
                }

                if (cFactionComboBox.SelectedItem == null)
                {
                    Debug.ShowWarning("Please choose your starter faction.");
                    cFactionComboBox.Focus();
                    return;
                }

                FactionInfo faction = ((CampaignFaction)cFactionComboBox.SelectedItem).Faction;
                if (faction == null || faction.Index == 0 || string.IsNullOrWhiteSpace(faction.Name))
                {
                    Debug.ShowWarning("Invalid starter faction.");
                    cFactionComboBox.Focus();
                    return;
                }

                CreationArgs args = new CreationArgs();
                args.Installation      = (Installation)cInstallListView.SelectedItem;
                args.Mod               = (ModFolder)cModComboBox.SelectedItem;
                args.Campaign          = (Campaign)cCampaignComboBox.SelectedItem;
                args.Name              = name;
                args.TransferPath      = transferPath;
                args.Difficulty        = difficulty;
                args.StartFaction      = faction;
                args.FreeFactions      = cSelectedFactionsListBox.Items.Cast <CampaignFaction>().Select(f => f.Faction);
                args.AutoSolve         = cAutoSolveComboBox.IsChecked == true;
                args.AutoManage        = cManageAllComboBox.IsChecked != true;
                args.ShortCampaign     = cShortCampaignComboBox.IsChecked == true;
                args.ArcadeBattles     = cArcadeBattlesComboBox.IsChecked == true;
                args.NoBattleTimeLimit = cNoTimeLimitComboBox.IsChecked == true;
                Session.Create(args);

                Settings.LastTransferPath = transferPath;
                Settings.Save();

                ShowMenu(Menus.GameList);
            }
            catch (Exception exc)
            {
                Debug.ShowException(exc);
            }
        }