public static List <string> GetAllCriteriaOptions(string criteria, IMiniSimDescription actor) { List <string> results = new List <string>(); SimSelection.ICriteria pick = null; foreach (SimSelection.ICriteria crit in SelectionOption.List) { if (crit.Name == criteria) { pick = crit; break; } } if (pick != null) { if (actor == null && PlumbBob.SelectedActor != null) { actor = PlumbBob.SelectedActor.SimDescription.GetMiniSimDescription(); } List <IMiniSimDescription> picks = new List <IMiniSimDescription>(); foreach (List <IMiniSimDescription> sims in SimListing.AllSims(actor, false).Values) { foreach (IMiniSimDescription sim in sims) { if (SimSelection.IsSpecial(sim)) { continue; } picks.Add(sim); } } List <ICommonOptionItem> options = pick.GetOptions(actor, new List <SimSelection.ICriteria>(), picks); foreach (ICommonOptionItem opt in options) { results.Add(opt.Name); } } return(results); }
protected override OptionResult Run(GameHitParameters <GameObject> parameters) { SimSelection.CriteriaSelection.Results uncheckedCriteria = new SimSelection.CriteriaSelection(Name, SelectionCriteria.SelectionOption.List).SelectMultiple(20); if (uncheckedCriteria.Count == 0) { if (uncheckedCriteria.mOkayed) { return(OptionResult.SuccessClose); } else { return(OptionResult.Failure); } } bool showSpecial = false; foreach (SimSelection.ICriteria crit in uncheckedCriteria) { if (crit is SimTypeOr) { showSpecial = true; break; } } Sim sim = parameters.mActor as Sim; List <IMiniSimDescription> simsList = new List <IMiniSimDescription>(); foreach (List <IMiniSimDescription> sims in SimListing.AllSims <IMiniSimDescription>(sim.SimDescription, showSpecial).Values) { if (!showSpecial) { sims.RemoveAll((e) => { return(SimSelection.IsSpecial(e)); }); } simsList.AddRange(sims); } List <SimSelection.ICriteria> criteria = new List <SimSelection.ICriteria> (); foreach (SimSelection.ICriteria crit in uncheckedCriteria) { // Update changes the sims list, so we need a new copy for each call List <IMiniSimDescription> newList = new List <IMiniSimDescription>(simsList); if (crit.Update(sim.SimDescription, uncheckedCriteria, newList, false) != SimSelection.UpdateResult.Failure) { criteria.Add(crit); } } string name = null; while (true) { name = StringInputDialog.Show(Name, Common.Localize("SaveFilterSetting:Prompt"), name, 256, StringInputDialog.Validation.None); if (string.IsNullOrEmpty(name)) { return(OptionResult.Failure); } if (callingMod != string.Empty) { name = callingMod + "." + name; } if (Find(name) == null) { break; } else if (AcceptCancelDialog.Show(Common.Localize("SaveFilterSetting:Exists"))) { Delete(name); break; } } NRaas.MasterController.Settings.mFilters.Add(new SavedFilter(name, criteria)); SimpleMessageDialog.Show(Name, Common.Localize("SaveFilterSetting:Success")); return(OptionResult.SuccessRetain); }
// this needs to be updated to use the cleaner ICreationData interface public static string CreateAndReturnRandomFilter(string callingNamespace, IMiniSimDescription actor, List <string> forbiddenCrit, Dictionary <string, string> forbiddenOptions, int[] minMaxCrit, Dictionary <string, int[]> minMaxOptions) { List <SimSelection.ICriteria> validCriteria = new List <SimSelection.ICriteria>(); foreach (SimSelection.ICriteria crit in SelectionOption.List) { if (!forbiddenCrit.Contains(crit.Name)) { validCriteria.Add(crit); } } if (validCriteria.Count == 0) { return(string.Empty); } if (actor == null && PlumbBob.SelectedActor != null) { actor = PlumbBob.SelectedActor.SimDescription.GetMiniSimDescription(); } List <IMiniSimDescription> picks = new List <IMiniSimDescription>(); foreach (List <IMiniSimDescription> sims in SimListing.AllSims(actor, false).Values) { foreach (IMiniSimDescription sim in sims) { if (SimSelection.IsSpecial(sim)) { continue; } picks.Add(sim); } } if (picks.Count == 0) { return(string.Empty); } if (minMaxCrit.Length < 2) { minMaxCrit[0] = 1; minMaxCrit[1] = 2; } int critpicks = RandomUtil.GetInt(minMaxCrit[0], minMaxCrit[1]); Common.Notify("Picking " + critpicks + " from " + validCriteria.Count); List <SimSelection.ICriteria> finalPicks = new List <SimSelection.ICriteria>(); if (validCriteria.Count == critpicks) { finalPicks = validCriteria; } else { while (true) { if (validCriteria.Count < critpicks && finalPicks.Count == validCriteria.Count) { break; } if (finalPicks.Count < critpicks) { SimSelection.ICriteria critpick = RandomUtil.GetRandomObjectFromList <SimSelection.ICriteria>(validCriteria); if (!finalPicks.Contains(critpick)) { finalPicks.Add(critpick); } continue; } break; } } bool failed = false; foreach (SimSelection.ICriteria crit2 in finalPicks) { Common.Notify("Picked " + crit2.Name); List <ICommonOptionItem> finalOpts = new List <ICommonOptionItem>(); List <ICommonOptionItem> opts = crit2.GetOptions(actor, finalPicks, picks); if (opts != null && opts.Count > 0) { Common.Notify("Opts not null"); int optpicks = 0; if (minMaxOptions.ContainsKey(crit2.Name) && minMaxOptions[crit2.Name].Length > 1) { optpicks = RandomUtil.GetInt(minMaxOptions[crit2.Name][0], minMaxOptions[crit2.Name][1]); } else { optpicks = 1; } Common.Notify("Picking " + optpicks + " from " + opts.Count); if (opts.Count == optpicks) { finalOpts = opts; } else { while (true) { if (opts.Count < optpicks && finalOpts.Count == opts.Count) { break; } if (finalOpts.Count < optpicks) { ICommonOptionItem opt = RandomUtil.GetRandomObjectFromList <ICommonOptionItem>(opts); ITestableOption testOpt = opt as ITestableOption; if (!finalOpts.Contains(opt) && (!forbiddenOptions.ContainsKey(crit2.Name) || (testOpt != null && !forbiddenOptions[crit2.Name].Contains(testOpt.OptionName)))) { // test if this gives me the name, if so we can revert the changes to ITestableOption Common.Notify("Picked " + opt.Name); finalOpts.Add(opt); } continue; } break; } } crit2.SetOptions(finalOpts); } else { failed = true; break; } } if (failed) { Common.Notify("Failed"); return(string.Empty); } string filterName; while (true) { filterName = callingNamespace + ".SimAttractionFilter" + RandomGen.NextDouble(); if (GetFilter(filterName) != null) { continue; } else { MasterController.Settings.mFilters.Add(new SavedFilter(filterName, finalPicks)); break; } } Common.Notify("Set and returning filter " + filterName); return(filterName); }
// settled on a seperate interface within attraction profiles to set certain criteria as random which will use the above to pull the options allowing users to allow/disallow criteria. Problems begin with localization of values when handling them as strings. I'll deal with that later. public static string CreateFilterWithCriteria(string callingNamespace, IMiniSimDescription actor, List <SimSelection.ICriteriaCreation> creationData) { if (creationData == null) { Common.Notify("Creation Data null"); return(string.Empty); } if (actor == null && PlumbBob.SelectedActor != null) { actor = PlumbBob.SelectedActor.SimDescription.GetMiniSimDescription(); } List <IMiniSimDescription> picks = new List <IMiniSimDescription>(); foreach (List <IMiniSimDescription> sims in SimListing.AllSims(actor, false).Values) { foreach (IMiniSimDescription sim in sims) { if (SimSelection.IsSpecial(sim)) { continue; } picks.Add(sim); } } List <SimSelection.ICriteria> finalCriteria = new List <SimSelection.ICriteria>(); foreach (SimSelection.ICriteriaCreation cData in creationData) { List <SimSelection.ICriteria> validCriteria = new List <SimSelection.ICriteria>(); List <string> forbiddenCrit = new List <string>(); if (cData.RandomCriteria && cData.ForbiddenRandomCriteria != null) { forbiddenCrit = cData.ForbiddenRandomCriteria; } foreach (SimSelection.ICriteria crit in SelectionOption.List) { if (crit.Name == cData.CriteriaName) { validCriteria.Add(crit); break; } if (!forbiddenCrit.Contains(crit.Name)) { validCriteria.Add(crit); } } SimSelection.ICriteria pickedCritera = null; if (validCriteria.Count == 1) { pickedCritera = validCriteria[0]; } else { int loop = 0; while (true) { if (loop > 4) { break; } pickedCritera = RandomUtil.GetRandomObjectFromList <SimSelection.ICriteria>(validCriteria); if (finalCriteria.Contains(pickedCritera)) { loop++; continue; } } } if (pickedCritera == null) { Common.Notify("pickedCriteria was null"); continue; } List <ICommonOptionItem> criteriaOptions = pickedCritera.GetOptions(actor, new List <SimSelection.ICriteria>(), picks); if (criteriaOptions == null || criteriaOptions.Count == 0) { Common.Notify("criteriaOptions null or 0"); continue; } List <string> forbiddenOptions = new List <string>(); if (cData.RandomOptions && cData.ForbiddenRandomOptions != null) { forbiddenOptions = cData.ForbiddenRandomOptions; } List <ICommonOptionItem> finalOptions = new List <ICommonOptionItem>(); List <ICommonOptionItem> validRandomOptions = new List <ICommonOptionItem>(); foreach (ICommonOptionItem opt in criteriaOptions) { if (cData.CriteriaOptions != null && cData.CriteriaOptions.Contains(opt.Name) && !finalOptions.Contains(opt)) { finalOptions.Add(opt); if (validRandomOptions.Contains(opt)) { validRandomOptions.Remove(opt); } continue; } if (cData.RandomOptions && !forbiddenOptions.Contains(opt.Name) && !finalOptions.Contains(opt)) { validRandomOptions.Add(opt); } } if (validRandomOptions.Count > 0) { List <ICommonOptionItem> pickedRandomOptions = new List <ICommonOptionItem>(); if (cData.MinMaxRandomOptions != null || cData.MinMaxRandomOptions.Length == 2) { int numOpt = RandomUtil.GetInt(cData.MinMaxRandomOptions[0], cData.MinMaxRandomOptions[1]); if (numOpt != 0) { while (true) { if (validRandomOptions.Count == 0 || pickedRandomOptions.Count == numOpt) { break; } ICommonOptionItem opt = RandomUtil.GetRandomObjectFromList <ICommonOptionItem>(validRandomOptions); if (opt != null) { pickedRandomOptions.Add(opt); validRandomOptions.Remove(opt); } } } finalOptions.AddRange(pickedRandomOptions); } } pickedCritera.SetOptions(finalOptions); finalCriteria.Add(pickedCritera); } if (finalCriteria.Count > 0) { string filterName; while (true) { filterName = callingNamespace + ".SimAttractionFilter" + RandomGen.NextDouble(); if (GetFilter(filterName) != null) { continue; } else { MasterController.Settings.mFilters.Add(new SavedFilter(filterName, finalCriteria)); break; } } return(filterName); } return(string.Empty); }
public virtual List <SimSelection.ICriteria> RunCriteriaSelection(GameHitParameters <GameObject> parameters, int maxSelection, bool withOptions) { List <SimSelection.ICriteria> selCrit = new List <SimSelection.ICriteria>(); if (mForbiddenCrit.Count > 0) { foreach (SimSelection.ICriteria critItem in SelectionCriteria.SelectionOption.List) { if (!mForbiddenCrit.Contains(critItem.GetType().Name)) { selCrit.Add(critItem); } } } else { selCrit = SelectionCriteria.SelectionOption.List; } SimSelection.CriteriaSelection.Results uncheckedCriteria = new SimSelection.CriteriaSelection(Name, selCrit).SelectMultiple(maxSelection); if (uncheckedCriteria.Count == 0) { if (uncheckedCriteria.mOkayed) { return(selCrit); } else { return(selCrit); } } bool showSpecial = false; foreach (SimSelection.ICriteria crit in uncheckedCriteria) { Common.Notify("Selected: " + crit.GetType().Name); if (crit is SimTypeOr) { showSpecial = true; break; } } Sim sim = parameters.mActor as Sim; List <IMiniSimDescription> simsList = new List <IMiniSimDescription>(); foreach (List <IMiniSimDescription> sims in SimListing.AllSims <IMiniSimDescription>(sim.SimDescription, showSpecial).Values) { if (!showSpecial) { sims.RemoveAll((e) => { return(SimSelection.IsSpecial(e)); }); } simsList.AddRange(sims); } List <SimSelection.ICriteria> criteria = new List <SimSelection.ICriteria>(); foreach (SimSelection.ICriteria crit in uncheckedCriteria) { if (withOptions) { // Update changes the sims list, so we need a new copy for each call List <IMiniSimDescription> newList = new List <IMiniSimDescription>(simsList); if (crit.Update(sim.SimDescription, uncheckedCriteria, newList, false, false, false) != SimSelection.UpdateResult.Failure) { Common.Notify("Adding: " + crit.GetType().Name); criteria.Add(crit); } } else { criteria.Add(crit); } } return(criteria); }