Esempio n. 1
0
        public string Dump()
        {
            StringBuilder builder = new StringBuilder();

            Dictionary <ulong, List <SimDescription> > sims = SimListing.AllSims <SimDescription>(null, true);

            foreach (KeyValuePair <ulong, List <DiseaseVector> > simPair in mVectors)
            {
                if (simPair.Value.Count == 0)
                {
                    continue;
                }

                List <SimDescription> choices;
                if (!sims.TryGetValue(simPair.Key, out choices))
                {
                    continue;
                }

                builder.Append(Common.NewLine + choices[0].FullName);

                foreach (DiseaseVector vector in simPair.Value)
                {
                    builder.Append(Common.NewLine + " " + vector.UnlocalizedName);
                }
            }

            return(builder.ToString());
        }
Esempio n. 2
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupTraits");

            foreach (List <SimDescription> sims in SimListing.AllSims <SimDescription>(null, true).Values)
            {
                foreach (SimDescription sim in sims)
                {
                    if (sim.TraitManager == null)
                    {
                        continue;
                    }

                    List <ulong> remove = new List <ulong>();

                    foreach (KeyValuePair <ulong, Trait> trait in sim.TraitManager.mValues)
                    {
                        if (TraitManager.sDictionary.ContainsKey(trait.Key))
                        {
                            continue;
                        }

                        remove.Add(trait.Key);
                    }

                    foreach (ulong trait in remove)
                    {
                        sim.TraitManager.mValues.Remove(trait);

                        Overwatch.Log(" Removed: " + sim.FullName);
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void Perform(SimDescription obj, object parent, FieldInfo field)
        {
            //if (obj.IsValidDescription) return;

            if (mSims == null)
            {
                mSims = SimListing.AllSims <SimDescription>(null, true);
            }

            // All residents, ancestors, and urnstone sims are considered valid
            if (mSims.ContainsKey(obj.SimDescriptionId))
            {
                return;
            }

            GameObjectReference reference = ObjectLookup.GetReference(new ReferenceWrapper(obj));

            if (!DereferenceManager.Perform(obj, reference, false, false))
            {
                return;
            }

            DereferenceManager.Perform(obj, reference, true, false);

            string fullName = obj.FullName;

            if (!string.IsNullOrEmpty(fullName))
            {
                fullName = fullName.Trim();
            }

            if (!string.IsNullOrEmpty(fullName))
            {
                bool found = false;
                foreach (List <SimDescription> list in mSims.Values)
                {
                    foreach (SimDescription sim in list)
                    {
                        if (sim.FullName == fullName)
                        {
                            found = true;
                            break;
                        }
                    }
                }

                if (!found)
                {
                    if (reference.Count > 0)
                    {
                        ErrorTrap.LogCorrection("SimDescription Removed: " + fullName);
                    }
                    else
                    {
                        ErrorTrap.DebugLogCorrection("Zero Reference SimDescription Removed: " + fullName);
                    }
                }
            }
        }
Esempio n. 4
0
        protected override OptionResult Run(GameHitParameters <GameObject> parameters)
        {
            Common.StringBuilder builder = new Common.StringBuilder();

            Dictionary <ulong, List <SimDescription> > allSims = SimListing.AllSims <SimDescription>(null, true);

            foreach (VectorBooter.Data vector in VectorBooter.Vectors)
            {
                Dictionary <string, List <SimDescription> > stages = new Dictionary <string, List <SimDescription> >();

                foreach (KeyValuePair <ulong, List <DiseaseVector> > sims in Vector.Settings.AllVectors)
                {
                    List <SimDescription> choices;
                    if (!allSims.TryGetValue(sims.Key, out choices))
                    {
                        continue;
                    }

                    SimDescription sim = choices[0];

                    foreach (DiseaseVector disease in sims.Value)
                    {
                        if (disease.Guid != vector.Guid)
                        {
                            continue;
                        }

                        string key = disease.StageName + " " + disease.Strain;

                        List <SimDescription> value;
                        if (!stages.TryGetValue(key, out value))
                        {
                            value = new List <SimDescription>();
                            stages.Add(key, value);
                        }

                        value.Add(sim);
                    }
                }

                string result = Common.NewLine + vector.Guid;

                foreach (KeyValuePair <string, List <SimDescription> > stage in stages)
                {
                    result += Common.NewLine + " " + stage.Key + " : " + stage.Value.Count;

                    foreach (SimDescription sim in stage.Value)
                    {
                        result += Common.NewLine + "  " + sim.FullName;
                    }
                }

                builder.Append(result);
            }

            Common.DebugWriteLog(builder);

            return(OptionResult.SuccessRetain);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupRelationships");

            Dictionary <ulong, List <SimDescription> > lookup = SimListing.AllSims <SimDescription>(null, true);

            List <SimDescription> removeA = new List <SimDescription>();

            foreach (KeyValuePair <SimDescription, Dictionary <SimDescription, Relationship> > relationsA in Relationship.sAllRelationships)
            {
                if (!lookup.ContainsKey(relationsA.Key.SimDescriptionId))
                {
                    removeA.Add(relationsA.Key);
                }
                else
                {
                    List <SimDescription> removeB = new List <SimDescription>();

                    foreach (KeyValuePair <SimDescription, Relationship> relationB in relationsA.Value)
                    {
                        if (!lookup.ContainsKey(relationB.Key.SimDescriptionId))
                        {
                            removeB.Add(relationB.Key);
                        }
                    }

                    foreach (SimDescription remove in removeB)
                    {
                        Relationship.sAllRelationships.Remove(remove);

                        Overwatch.Log(" Removed B: " + remove.FullName);
                    }
                }
            }

            foreach (SimDescription remove in removeA)
            {
                Relationship.sAllRelationships.Remove(remove);

                Overwatch.Log(" Removed A: " + remove.FullName);
            }
        }
Esempio n. 7
0
            public void CleanupSims()
            {
                Dictionary <ulong, List <SimDescription> > allSims = SimListing.AllSims <SimDescription>(null, true);

                List <ulong> remove = new List <ulong>();

                foreach (ulong sim in mTested.Keys)
                {
                    if (allSims.ContainsKey(sim))
                    {
                        continue;
                    }

                    remove.Add(sim);
                }

                foreach (ulong sim in remove)
                {
                    mTested.Remove(sim);
                }

                remove.Clear();
                foreach (ulong sim in mOutfitCount.Keys)
                {
                    if (allSims.ContainsKey(sim))
                    {
                        continue;
                    }

                    remove.Add(sim);
                }

                foreach (ulong sim in remove)
                {
                    mOutfitCount.Remove(sim);
                }
            }
Esempio n. 8
0
        public void FilterSims(ICollection <ICriteria> fullCriteria, IEnumerable <ICriteria> savedFilters, bool automatic, out bool canceled)
        {
            bool showSpecial = false;

            IEnumerable <ICriteria> criteria = null;

            canceled = false;

            bool manual = false;

            if (fullCriteria != null)
            {
                if (fullCriteria.Count > 1)
                {
                    List <ICriteria> allCriteria = new List <ICriteria>(fullCriteria);

                    if (savedFilters != null)
                    {
                        allCriteria.AddRange(savedFilters);
                    }

                    if (!automatic)
                    {
                        CriteriaSelection.Results results = new CriteriaSelection(Title, allCriteria).SelectMultiple();

                        criteria = results;

                        canceled = !results.mOkayed;
                    }
                    else
                    {
                        criteria = allCriteria;
                    }

                    manual = true;
                }
                else
                {
                    criteria = new List <ICriteria>(fullCriteria);
                }
            }
            else
            {
                showSpecial = true;
            }

            if (criteria == null)
            {
                criteria = new List <ICriteria>();
            }

            criteria = AlterCriteria(criteria, manual, canceled);

            foreach (ICriteria crit in criteria)
            {
                if (crit.IsSpecial)
                {
                    showSpecial = true;
                }
            }

            List <T> chosen = new List <T>();

            foreach (List <T> sims in SimListing.AllSims(mMe, showSpecial).Values)
            {
                foreach (T sim in sims)
                {
                    if (!showSpecial)
                    {
                        if (IsSpecial(sim))
                        {
                            continue;
                        }
                    }

                    if (!Allow(sim))
                    {
                        continue;
                    }

                    chosen.Add(sim);
                }
            }

            List <ICriteria> delayed = new List <ICriteria>();

            foreach (ICriteria crit in criteria)
            {
                if (crit.Update(mMe, criteria, chosen, false) == UpdateResult.Delay)
                {
                    delayed.Add(crit);
                }
            }

            foreach (ICriteria crit in delayed)
            {
                crit.Update(mMe, criteria, chosen, true);
            }

            if (chosen.Count == 0)
            {
                mItems = null;
            }
            else
            {
                mItems = chosen;
            }
        }
Esempio n. 9
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupCareers");

            foreach (List <SimDescription> sims in SimListing.AllSims <SimDescription>(null, true).Values)
            {
                foreach (SimDescription sim in sims)
                {
                    if (sim.CareerManager == null)
                    {
                        continue;
                    }

                    if (sim.CareerManager.mCoworkerAt != null)
                    {
                        List <Occupation> remove = new List <Occupation>();

                        foreach (Occupation occupation in sim.CareerManager.mCoworkerAt.Keys)
                        {
                            if (!Corrections.IsValidCoworker(occupation.OwnerDescription, occupation is School))
                            {
                                remove.Add(occupation);
                            }
                        }

                        foreach (Occupation occ in remove)
                        {
                            sim.CareerManager.ClearCoworkerAtOccupation(occ);

                            Overwatch.Log(" CoworkerAt Removed " + sim.FullName);
                        }
                    }

                    Corrections.FixCareer(sim.Occupation, true, Overwatch.Log);

                    Corrections.FixCareer(sim.CareerManager.RetiredCareer, false, Overwatch.Log);

                    Corrections.FixCareer(sim.CareerManager.School, true, Overwatch.Log);

                    if (sim.CareerManager.QuitCareers != null)
                    {
                        foreach (Occupation occ in sim.CareerManager.QuitCareers.Values)
                        {
                            Corrections.FixCareer(occ, false, Overwatch.Log);
                        }
                    }
                }
            }

            foreach (RabbitHole hole in Sims3.Gameplay.Queries.GetObjects <RabbitHole>())
            {
                foreach (CareerLocation location in hole.CareerLocations.Values)
                {
                    for (int i = location.Workers.Count - 1; i >= 0; i--)
                    {
                        SimDescription worker = location.Workers[i];

                        if (!Corrections.IsValidCoworker(worker, location.Career is School))
                        {
                            Overwatch.Log(" Invalid Worker Dropped " + worker.FullName);

                            location.Workers.RemoveAt(i);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public void OnWorldLoadFinished()
        {
            Dictionary <ulong, List <SimDescription> > sims = SimListing.AllSims <SimDescription>(null, true, false);

            List <ulong> remove = new List <ulong>();

            foreach (KeyValuePair <ulong, List <DiseaseVector> > vectors in Vector.Settings.AllVectors)
            {
                if (sims.ContainsKey(vectors.Key))
                {
                    for (int i = vectors.Value.Count - 1; i >= 0; i--)
                    {
                        DiseaseVector vector = vectors.Value[i];

                        if (!vector.OnLoadFixup())
                        {
                            vectors.Value.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    remove.Add(vectors.Key);
                }
            }

            foreach (ulong sim in remove)
            {
                Vector.Settings.RemoveSim(sim);
            }

            Dictionary <string, ResistanceBooter.Data> resistances = new Dictionary <string, ResistanceBooter.Data>();

            foreach (VectorBooter.Data vector in VectorBooter.Vectors)
            {
                vector.GetResistances(resistances);
            }

            Dictionary <EventTypeId, bool> events = new Dictionary <EventTypeId, bool>();

            foreach (ResistanceBooter.Data resistance in resistances.Values)
            {
                resistance.GetEvents(events);
            }

            foreach (EventTypeId id in events.Keys)
            {
                new Common.DelayedEventListener(id, OnResistance);
            }

            // Must be immediate
            new Common.ImmediateEventListener(EventTypeId.kUsedObect, OnUsedObject);

            new Common.DelayedEventListener(EventTypeId.kTraitGained, OnTraitGained);

            new Common.DelayedEventListener(EventTypeId.kWooHooed, OnWoohoo);
            new Common.DelayedEventListener(EventTypeId.kSocialInteraction, OnSocial);
            new Common.DelayedEventListener(EventTypeId.kRoomChanged, OnRoomChanged);
            new Common.DelayedEventListener(EventTypeId.kFought, OnFought);

            new Common.DelayedEventListener(EventTypeId.kBabyToddlerSnuggle, OnInoculate);
            new Common.DelayedEventListener(EventTypeId.kHadBaby, OnBirth);

            new Common.AlarmTask(30, TimeUnit.Minutes, OnVectorCheck, 30, TimeUnit.Minutes);
        }
Esempio n. 11
0
        // 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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        protected static void OnPerform()
        {
            Dictionary <ulong, List <SimDescription> > allSims = null;

            foreach (VectorBooter.Data vector in VectorBooter.Vectors)
            {
                if (!vector.IsEnabled)
                {
                    continue;
                }

                if (vector.HasInstigators)
                {
                    continue;
                }

                if (!vector.CanOutbreak)
                {
                    continue;
                }

                if (!Vector.Settings.IsAutomated(vector.Guid))
                {
                    continue;
                }

                bool active = false;
                foreach (KeyValuePair <ulong, List <DiseaseVector> > vectors in Vector.Settings.AllVectors)
                {
                    if (allSims == null)
                    {
                        allSims = SimListing.AllSims <SimDescription>(null, false);
                    }

                    List <SimDescription> sims;
                    if (!allSims.TryGetValue(vectors.Key, out sims))
                    {
                        continue;
                    }

                    if (SimTypes.IsDead(sims[0]))
                    {
                        continue;
                    }

                    foreach (DiseaseVector subVector in vectors.Value)
                    {
                        if (subVector.Guid != vector.Guid)
                        {
                            continue;
                        }

                        if (subVector.IsActive)
                        {
                            active = true;
                            break;
                        }
                    }

                    if (active)
                    {
                        break;
                    }
                }

                if (active)
                {
                    ScoringLog.sLog.IncStat(vector.Guid + " Active In Town");
                }
                else
                {
                    StartOutbreak(vector, false);
                }
            }
        }
Esempio n. 14
0
        protected override OptionResult Run(GameHitParameters <GameObject> parameters)
        {
            Dictionary <ulong, List <IMiniSimDescription> > sims = SimListing.AllSims <IMiniSimDescription>(null, true);

            if ((sims == null) || (sims.Count == 0))
            {
                return(OptionResult.Failure);
            }

            List <IMiniSimDescription> dead = new List <IMiniSimDescription>();

            foreach (List <IMiniSimDescription> miniSims in sims.Values)
            {
                foreach (IMiniSimDescription miniSim in miniSims)
                {
                    SimDescription sim = miniSim as SimDescription;
                    if (sim == null)
                    {
                        continue;
                    }

                    if ((!sim.IsDead) && (!sim.IsGhost) && (sim.Household != null))
                    {
                        continue;
                    }

                    if (sim.IsPlayableGhost)
                    {
                        continue;
                    }

                    Urnstone urnstone = Sims3.Gameplay.Objects.Urnstone.FindGhostsGrave(sim);
                    if (urnstone != null)
                    {
                        if ((urnstone.InInventory) || (urnstone.InWorld))
                        {
                            continue;
                        }
                    }

                    dead.Add(sim);
                }
            }

            int count = 0;

            if (dead.Count > 0)
            {
                if (!AcceptCancelDialog.Show(Common.Localize("ReconstituteTheDead:Prompt", false, new object[] { dead.Count })))
                {
                    return(OptionResult.Failure);
                }

                foreach (SimDescription sim in dead)
                {
                    if (Urnstones.CreateGrave(sim, false) != null)
                    {
                        count++;
                    }
                }
            }

            SimpleMessageDialog.Show(Name, Common.Localize("ReconstituteTheDead:Success", false, new object[] { count }));
            return(OptionResult.SuccessClose);
        }
Esempio n. 15
0
        public void PerformAction(bool prompt)
        {
            try
            {
                Overwatch.Log("Cleanup Genealogy");

                Dictionary <IMiniSimDescription, IMiniSimDescription> duplicates = new Dictionary <IMiniSimDescription, IMiniSimDescription>();

                Dictionary <ulong, IMiniSimDescription> lookup = new Dictionary <ulong, IMiniSimDescription>();

                Dictionary <IMiniSimDescription, bool> urnstones = new Dictionary <IMiniSimDescription, bool>();

                foreach (SimDescription sim in SimDescription.GetHomelessSimDescriptionsFromUrnstones())
                {
                    if (urnstones.ContainsKey(sim))
                    {
                        continue;
                    }

                    urnstones.Add(sim, true);
                }

                Dictionary <IGenealogy, bool> allGenealogies = new Dictionary <IGenealogy, bool>();

                List <IGenealogy> geneList = new List <IGenealogy>();

                foreach (KeyValuePair <ulong, List <IMiniSimDescription> > ids in SimListing.AllSims <IMiniSimDescription>(null, true, false))
                {
                    List <IMiniSimDescription> list = ids.Value;

                    foreach (IMiniSimDescription miniSim in list)
                    {
                        if (miniSim.CASGenealogy == null)
                        {
                            continue;
                        }

                        if (allGenealogies.ContainsKey(miniSim.CASGenealogy))
                        {
                            continue;
                        }

                        allGenealogies.Add(miniSim.CASGenealogy, true);

                        geneList.Add(miniSim.CASGenealogy);
                    }

                    IMiniSimDescription choice = null;
                    if (list.Count == 1)
                    {
                        choice = list[0];
                    }
                    else if (list.Count > 1)
                    {
                        List <IMiniSimDescription> choices = new List <IMiniSimDescription>();

                        foreach (IMiniSimDescription miniSim in list)
                        {
                            SimDescription sim = miniSim as SimDescription;
                            if (sim == null)
                            {
                                continue;
                            }

                            if (sim.Household == Household.ActiveHousehold)
                            {
                                choices.Add(miniSim);
                            }
                        }

                        if (choices.Count >= 1)
                        {
                            choice = choices[0];

                            Overwatch.Log("Doppleganger Active-Inactive (" + list.Count + "): " + Relationships.GetFullName(choice));
                        }
                        else
                        {
                            choices.Clear();
                            foreach (IMiniSimDescription sim in list)
                            {
                                if (urnstones.ContainsKey(sim))
                                {
                                    choices.Add(sim);
                                }
                            }

                            if (choices.Count == 1)
                            {
                                choice = choices[0];

                                Overwatch.Log("Doppleganger Urnstone (" + list.Count + "): " + Relationships.GetFullName(choice));
                            }
                            else
                            {
                                choices.Clear();
                                foreach (IMiniSimDescription sim in list)
                                {
                                    Genealogy genealogy = sim.CASGenealogy as Genealogy;

                                    if ((genealogy != null) && (object.ReferenceEquals(sim, genealogy.mSim)))
                                    {
                                        choices.Add(sim);
                                    }
                                }

                                if (choices.Count == 1)
                                {
                                    choice = choices[0];

                                    Overwatch.Log("Doppleganger Personal Genealogy (" + list.Count + "): " + Relationships.GetFullName(choice));
                                }
                                else
                                {
                                    choices.Clear();

                                    MiniSimDescription miniSim = MiniSimDescription.Find(ids.Key);
                                    if ((miniSim != null) && (miniSim.Genealogy != null) && (miniSim.Genealogy.mSim != null))
                                    {
                                        foreach (IMiniSimDescription sim in list)
                                        {
                                            if (object.ReferenceEquals(sim, miniSim.Genealogy.mSim))
                                            {
                                                choices.Add(sim);
                                            }
                                        }
                                    }

                                    if (choices.Count == 1)
                                    {
                                        choice = choices[0];

                                        Overwatch.Log("Doppleganger MiniSim Genealogy (" + list.Count + "): " + Relationships.GetFullName(choice));
                                    }
                                    else
                                    {
                                        choices.Clear();

                                        int maxLinks = 0;

                                        foreach (IMiniSimDescription sim in list)
                                        {
                                            if (choice == null)
                                            {
                                                choice = sim;
                                            }
                                            else
                                            {
                                                int numLinks = 0;

                                                Genealogy gene = sim.CASGenealogy as Genealogy;
                                                if (gene != null)
                                                {
                                                    if (gene.mNaturalParents != null)
                                                    {
                                                        numLinks += gene.mNaturalParents.Count;
                                                    }

                                                    if (gene.mChildren != null)
                                                    {
                                                        numLinks += gene.mChildren.Count;
                                                    }

                                                    if (gene.mSiblings != null)
                                                    {
                                                        numLinks += gene.mSiblings.Count;
                                                    }

                                                    if (maxLinks < numLinks)
                                                    {
                                                        maxLinks = numLinks;

                                                        choice = sim;
                                                    }
                                                }
                                            }
                                        }

                                        Overwatch.Log("Doppleganger By Link Count (" + list.Count + "): " + Relationships.GetFullName(choice));
                                    }
                                }
                            }
                        }
                    }

                    if (choice != null)
                    {
                        lookup.Add(choice.SimDescriptionId, choice);

                        foreach (IMiniSimDescription sim in list)
                        {
                            if (object.ReferenceEquals(sim, choice))
                            {
                                continue;
                            }

                            duplicates.Add(sim, choice);

                            Genealogy genealogy = ReconcileGenealogy(choice.CASGenealogy as Genealogy, sim.CASGenealogy as Genealogy);
                            if (genealogy != null)
                            {
                                SetGenealogy(choice, genealogy);
                            }
                        }
                    }
                }

                int index = 0;
                while (index < geneList.Count)
                {
                    Genealogy genealogy = geneList[index] as Genealogy;
                    index++;

                    if (genealogy == null)
                    {
                        continue;
                    }

                    AddToList(geneList, allGenealogies, genealogy.mNaturalParents);
                    AddToList(geneList, allGenealogies, genealogy.mChildren);
                    AddToList(geneList, allGenealogies, genealogy.mSiblings);
                }

                Dictionary <string, List <Genealogy> > broken = new Dictionary <string, List <Genealogy> >();

                foreach (IGenealogy iGene in geneList)
                {
                    Genealogy gene = iGene as Genealogy;
                    if (gene == null)
                    {
                        continue;
                    }

                    if ((gene.mMiniSim == null) && (gene.mSim == null))
                    {
                        if (!string.IsNullOrEmpty(gene.Name))
                        {
                            List <Genealogy> genes;
                            if (!broken.TryGetValue(gene.Name, out genes))
                            {
                                genes = new List <Genealogy>();
                                broken.Add(gene.Name, genes);
                            }

                            genes.Add(gene);
                        }
                    }

                    MiniSimDescription miniSim = gene.mMiniSim as MiniSimDescription;
                    if (miniSim == null)
                    {
                        continue;
                    }

                    if ((MiniSimDescription.sMiniSims != null) && (!MiniSimDescription.sMiniSims.ContainsKey(miniSim.SimDescriptionId)))
                    {
                        MiniSimDescription.sMiniSims.Add(miniSim.SimDescriptionId, miniSim);

                        if (!lookup.ContainsKey(miniSim.SimDescriptionId))
                        {
                            lookup.Add(miniSim.SimDescriptionId, miniSim);
                        }

                        Overwatch.Log("Genealogy Minisim Added " + Relationships.GetFullName(miniSim));
                    }
                }

                CleanupMiniSimGenealogy(lookup, broken);

                foreach (IMiniSimDescription sim in lookup.Values)
                {
                    try
                    {
                        IMiniSimDescription lookupSim = Relationships.Find(sim.SimDescriptionId, lookup);

                        Genealogy genealogy = null;

                        if (lookupSim != null)
                        {
                            genealogy = lookupSim.CASGenealogy as Genealogy;

                            if ((genealogy != null) && (sim.CASGenealogy != null) && (!object.ReferenceEquals(genealogy, sim.CASGenealogy)))
                            {
                                sim.CASGenealogy = genealogy;

                                Overwatch.Log("Lookup Genealogy Replaced: " + Relationships.GetFullName(sim));
                            }
                        }

                        if (genealogy == null)
                        {
                            genealogy = sim.CASGenealogy as Genealogy;
                        }

                        if (genealogy == null)
                        {
                            MiniSimDescription miniSim = MiniSimDescription.Find(sim.SimDescriptionId);
                            if (miniSim != null)
                            {
                                genealogy = miniSim.mGenealogy;

                                if ((genealogy != null) && (sim.CASGenealogy != null) && (!object.ReferenceEquals(genealogy, sim.CASGenealogy)))
                                {
                                    sim.CASGenealogy = genealogy;

                                    Overwatch.Log("MiniSim Genealogy Replaced: " + Relationships.GetFullName(sim));
                                }
                            }
                        }

                        if (genealogy == null)
                        {
                            SimDescription trueSim = sim as SimDescription;
                            if (trueSim != null)
                            {
                                trueSim.Fixup();

                                genealogy = sim.CASGenealogy as Genealogy;
                                if (genealogy == null)
                                {
                                    Overwatch.Log("No SimDesc Genealogy: " + Relationships.GetFullName(sim));
                                }
                                else
                                {
                                    Overwatch.Log("Genealogy Fixup Performed: " + Relationships.GetFullName(sim));
                                }
                            }
                            else
                            {
                                MiniSimDescription miniSim = sim as MiniSimDescription;
                                if (miniSim != null)
                                {
                                    // This minisim may be part of a family tree, so must be uncorrupted
                                    genealogy = new Genealogy(miniSim.FullName);

                                    Overwatch.Log("MiniSim Genealogy Created: " + Relationships.GetFullName(sim));
                                }
                                else
                                {
                                    Overwatch.Log("No MiniSim Genealogy: " + Relationships.GetFullName(sim));
                                }
                            }
                        }

                        SetGenealogy(sim, genealogy);
                    }
                    catch (Exception e)
                    {
                        Common.Exception("Phase One: " + Relationships.GetFullName(sim), e);
                    }
                }

                foreach (IMiniSimDescription sim in lookup.Values)
                {
                    try
                    {
                        SimDescription trueSim = sim as SimDescription;
                        if (trueSim != null)
                        {
                            MiniSimDescription miniSim = MiniSimDescription.Find(trueSim.SimDescriptionId);
                            if (miniSim != null)
                            {
                                List <MiniRelationship> relationships = new List <MiniRelationship>(miniSim.MiniRelationships);
                                foreach (MiniRelationship relationship in relationships)
                                {
                                    IMiniSimDescription otherSim = MiniSimDescription.Find(relationship.GetOtherSimDescriptionId(sim));
                                    if (otherSim == null)
                                    {
                                        miniSim.mMiniRelationships.Remove(relationship);
                                    }
                                    else
                                    {
                                        Genealogy gene = otherSim.CASGenealogy as Genealogy;
                                        if (gene == null)
                                        {
                                            miniSim.mMiniRelationships.Remove(relationship);
                                        }
                                    }
                                }
                            }

                            Dictionary <ulong, bool> existingRelations = new Dictionary <ulong, bool>();

                            Dictionary <SimDescription, Relationship> oldRelations;
                            if (Relationship.sAllRelationships.TryGetValue(trueSim, out oldRelations))
                            {
                                Dictionary <SimDescription, Relationship> newRelations = new Dictionary <SimDescription, Relationship>();

                                foreach (KeyValuePair <SimDescription, Relationship> relation in new Dictionary <SimDescription, Relationship>(oldRelations))
                                {
                                    IMiniSimDescription townSim;
                                    if (lookup.TryGetValue(relation.Key.SimDescriptionId, out townSim))
                                    {
                                        if (!object.ReferenceEquals(townSim, relation.Key))
                                        {
                                            Overwatch.Log(Relationships.GetFullName(sim) + " Dropped bad relation for " + Relationships.GetFullName(relation.Key));

                                            Relationships.SafeRemoveRelationship(relation.Value);
                                            continue;
                                        }
                                    }

                                    if (existingRelations.ContainsKey(relation.Key.SimDescriptionId))
                                    {
                                        Overwatch.Log(Relationships.GetFullName(sim) + " Dropped duplicate relation for " + Relationships.GetFullName(relation.Key));

                                        Relationships.SafeRemoveRelationship(relation.Value);
                                        continue;
                                    }

                                    existingRelations.Add(relation.Key.SimDescriptionId, true);

                                    Relationships.RepairRelationship(relation.Value, Overwatch.Log);

                                    newRelations.Add(relation.Key, relation.Value);
                                }

                                Relationship.sAllRelationships[trueSim] = newRelations;
                            }

                            /*
                             * MiniSimDescription miniDesc = MiniSimDescription.Find(trueSim.SimDescriptionId);
                             * if (miniDesc != null)
                             * {
                             *  for (int i = miniDesc.mMiniRelationships.Count - 1; i >= 0; i--)
                             *  {
                             *      MiniRelationship relation = miniDesc.mMiniRelationships[i];
                             *
                             *      if (existingRelations.ContainsKey(relation.SimDescriptionId))
                             *      {
                             *          miniDesc.mMiniRelationships.RemoveAt(i);
                             *
                             *          Overwatch.Log(GetFullName(trueSim) + " Dropped duplicate mini relation");
                             *      }
                             *  }
                             * }
                             */

                            RepairMissingPartner(trueSim);

                            // Legacy repair for an issue with an earlier Phase of Overwatch
                            List <Relationship> relations = new List <Relationship>(Relationship.GetRelationships(trueSim));
                            foreach (Relationship relation in relations)
                            {
                                if ((relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Divorce)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.BreakUp)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.BreakEngagement)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Marry)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Propose)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.MakeCommitment)))
                                {
                                    relation.LTR.AddInteractionBit(LongTermRelationship.InteractionBits.HaveBeenPartners);
                                }
                            }
                        }

                        Genealogy genealogy = sim.CASGenealogy as Genealogy;
                        if (genealogy != null)
                        {
                            genealogy.ClearDerivedData();

                            new Relationships.RepairParents().Perform(sim, Overwatch.Log, lookup);
                            new Relationships.RepairChildren().Perform(sim, Overwatch.Log, lookup);
                            new Relationships.RepairSiblings().Perform(sim, Overwatch.Log, lookup);

                            RepairSpouse(sim, lookup);

                            if ((sim.IsMarried) && (genealogy.mPartnerType != PartnerType.Marriage))
                            {
                                genealogy.mPartnerType = PartnerType.Marriage;

                                if (genealogy.Spouse != null)
                                {
                                    genealogy.Spouse.mPartnerType = PartnerType.Marriage;
                                }

                                Overwatch.Log(Relationships.GetFullName(sim) + " PartnerType Corrected");
                            }
                        }

                        RepairMiniSim(trueSim);
                    }
                    catch (Exception e)
                    {
                        Common.Exception("Phase Two: " + Relationships.GetFullName(sim), e);
                    }
                }

                CleanupMiniSims(lookup);

                // Must be performed after repairing the genealogy as the mSim is wiped from the genealogy during deletion
                foreach (KeyValuePair <IMiniSimDescription, IMiniSimDescription> duplicate in duplicates)
                {
                    CustomAnnihilation(duplicate.Key as SimDescription, duplicate.Value as SimDescription);
                }
            }
            catch (Exception e)
            {
                Common.Exception(Name, e);
            }
        }
Esempio n. 16
0
 protected override OptionResult Run(GameHitParameters <GameObject> parameters)
 {
     return(Perform(SimListing.AllSims <IMiniSimDescription>(null, true)));
 }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        // 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);
        }