public RandomSettingsWindow(IEnumerable <Mod> mods, RandomSettings defaultSettings)
        {
            InitializeComponent();

            Settings = defaultSettings;
            Settings.PropertyChanged += Settings_PropertyChanged;
            MainGrid.DataContext      = Settings;

            this.mods = mods;

            modsToIncludeListBox.ItemsSource = mods;
        }
        public RandomSettingsWindow(IEnumerable<Mod> mods, RandomSettings defaultSettings)
        {
            InitializeComponent();

            Settings = defaultSettings;
            Settings.PropertyChanged += Settings_PropertyChanged;
            MainGrid.DataContext = Settings;

            this.mods = mods;

            modsToIncludeListBox.ItemsSource = mods;
        }
 private void Window_ContextMenu_ResetToDefaults_Click(object sender, RoutedEventArgs e)
 {
     Settings             = new RandomSettings();
     MainGrid.DataContext = Settings;
 }
 private void Window_ContextMenu_ResetToDefaults_Click(object sender, RoutedEventArgs e)
 {
     Settings = new RandomSettings();
     MainGrid.DataContext = Settings;
 }
 private void SaveRandomSettings(RandomSettings randomSettings)
 {
     Grabber.Settings.Set(x => {
         x.RandomSettingsInitialized = true;
         x.RandomSettingsMinCraft = randomSettings.MinimumCraft;
         x.RandomSettingsMaxCraft = randomSettings.MaximumCraft;
         x.RandomSettingsMinActors = randomSettings.MinimumActorsPerCraft;
         x.RandomSettingsMaxActors = randomSettings.MaximumActorsPerCraft;
         x.RandomSettingsMinWeapons = randomSettings.MinimumWeaponsPerActor;
         x.RandomSettingsMaxWeapons = randomSettings.MaximumWeaponsPerActor;
         x.RandomSettingsCrabsHoldWeapons = randomSettings.CrabsCanCarryWeapons;
     });
 }
        /// <summary>Generates a random skirmish based on the parameters, returning the list of craft to form the root.</summary>
        private IEnumerable<InventoryItem> GenerateRandomSkirmish(RandomSettings settings, IEnumerable<Mod> mods, IEnumerable<ActivityItem> items)
        {
            items = items.Where(x => mods.Contains(x.Mod));
            var craft = items.Where(x => x.Group == ActivityItemGroup.Craft).ToList();
            var actors = items.Where(x => x.Group == ActivityItemGroup.Actor).ToList();
            var weapons = items.Where(x => x.Group == ActivityItemGroup.Weapon).ToList();

            Random random = new Random();

            var allCraft = new List<InventoryItem>();

            var numCraft = random.Next(settings.MinimumCraft, settings.MaximumCraft + 1);

            for (var i = 0; i < numCraft; i++)
            {
                if (craft.Count == 0) break;
                var craftItem = new InventoryItem(craft[random.Next(0, craft.Count )]);
                allCraft.Add(craftItem);

                var actorsInCraft = random.Next(settings.MinimumActorsPerCraft, settings.MaximumActorsPerCraft + 1);
                for (var a = 0; a < actorsInCraft; a++)
                {
                    if (actors.Count == 0) break;
                    var actor = actors[random.Next(0, actors.Count)];
                    var actorItem = new InventoryItem(actor);
                    craftItem.SubItems.Add(actorItem);

                    var actorWeapons = actor.Type == ActivityItemType.ACrab && !settings.CrabsCanCarryWeapons ? 0 :
                        random.Next(settings.MinimumWeaponsPerActor, settings.MaximumWeaponsPerActor + 1);

                    for (var w = 0; w < actorWeapons; w++)
                    {
                        if (weapons.Count == 0) break;
                        var weaponItem = new InventoryItem(weapons[random.Next(0, weapons.Count)]);
                        actorItem.SubItems.Add(weaponItem);
                    }
                }
            }

            return allCraft;
        }
        private void skirmishWavesTreeViewItem_Random_Click(object sender, RoutedEventArgs e)
        {
            if (Grabber.ActivityItemCache == null || Grabber.ActivityItemCache.CacheIsValid == false)
            {
                //new ActivityItemLoaderWindow(){Owner = this, WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner}.ShowDialog();
            }

            var items = Grabber.ActivityItemCache.GetAll();
            var mods = items.Select(x => x.Mod).Distinct();

            var settings = Grabber.Settings.Get();
            var randomSettings = new RandomSettings();
            if(settings.RandomSettingsInitialized)
                randomSettings = new RandomSettings
                {
                    MinimumCraft = settings.RandomSettingsMinCraft,
                    MaximumCraft = settings.RandomSettingsMaxCraft,
                    MinimumActorsPerCraft = settings.RandomSettingsMinActors,
                    MaximumActorsPerCraft = settings.RandomSettingsMaxActors,
                    MinimumWeaponsPerActor = settings.RandomSettingsMinWeapons,
                    MaximumWeaponsPerActor = settings.RandomSettingsMaxWeapons,
                    CrabsCanCarryWeapons = settings.RandomSettingsCrabsHoldWeapons
                };

            RandomSettingsWindow randomWindow = new RandomSettingsWindow(mods, randomSettings) { Owner = this, WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner };
            randomWindow.GenerateRandomSkirmishClicked += (a, b) => {
                SaveRandomSettings(a);
                var mainItems = GenerateRandomSkirmish(a, b, items);
                Dispatcher.Invoke(new Action(() => PlaceRandomSkirmishInList(mainItems)));
            };

            randomWindow.Show();
        }