Exemplo n.º 1
0
        protected bool ValidContent(UISimInfo sim, CASAgeGenderFlags species, SimDescription exclude)
        {
            if (sim == null)
            {
                return(false);
            }

            if (sim.SimName == null)
            {
                return(false);
            }

            if (sim.Species != species)
            {
                return(false);
            }

            if (exclude != null)
            {
                if (sim.SimName.Contains(exclude.LastName))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        protected SimDescription GetSim(CASAgeGenderFlags gender, CASAgeGenderFlags species, SimDescription exclude)
        {
            if (RandomUtil.RandomChance(mBinChance))
            {
                List <ExportBinContents> contents = new List <ExportBinContents>();
                foreach (IExportBinContents iContent in BinModel.Singleton.ExportBinContents)
                {
                    ExportBinContents content = iContent as ExportBinContents;
                    if (content == null)
                    {
                        continue;
                    }

                    contents.Add(content);
                }

                Dictionary <UISimInfo, ExportBinContents> uiSims = new Dictionary <UISimInfo, ExportBinContents>();

                if (Manager.GetValue <EqualBinChanceOption <TManager>, bool>())
                {
                    foreach (ExportBinContents content in contents)
                    {
                        if (!ValidContent(content))
                        {
                            continue;
                        }

                        foreach (UISimInfo sim in content.HouseholdSims)
                        {
                            if (!ValidContent(sim, species, exclude))
                            {
                                continue;
                            }

                            if (uiSims.ContainsKey(sim))
                            {
                                continue;
                            }

                            uiSims.Add(sim, content);
                        }
                    }
                }
                else
                {
                    RandomUtil.RandomizeListOfObjects(contents);
                    foreach (ExportBinContents content in contents)
                    {
                        if (!ValidContent(content))
                        {
                            continue;
                        }

                        foreach (UISimInfo sim in content.HouseholdSims)
                        {
                            if (!ValidContent(sim, species, exclude))
                            {
                                continue;
                            }

                            uiSims.Add(sim, content);
                        }

                        if (uiSims.Count > 0)
                        {
                            break;
                        }
                    }
                }

                if (uiSims.Count > 0)
                {
                    UISimInfo choice = RandomUtil.GetRandomObjectFromList(new List <UISimInfo>(uiSims.Keys));

                    ExportBinContents content = uiSims[choice];

                    if (!content.IsLoaded())
                    {
                        Dictionary <string, List <News.NewsTuning.ArticleTuning> > namedArticles = News.sNewsTuning.mNamedArticles;

                        bool fail = false;
                        try
                        {
                            // Doing so stops Marriage notices of imported sims from appearing in the newspaper
                            News.sNewsTuning.mNamedArticles = new Dictionary <string, List <News.NewsTuning.ArticleTuning> >();

                            ExportBinContentsEx.Import(content, false);

                            mStats.AddStat("Import Size", content.HouseholdSims.Count);
                        }
                        catch (Exception e)
                        {
                            Common.DebugException(content.HouseholdName, e);
                            fail = true;
                        }
                        finally
                        {
                            News.sNewsTuning.mNamedArticles = namedArticles;
                        }

                        mLoaded[content] = true;

                        if (fail)
                        {
                            return(null);
                        }
                    }

                    if ((content.Household != null) && (content.Household.AllSimDescriptions.Count > 0))
                    {
                        List <SimDescription> choices = new List <SimDescription>();

                        foreach (SimDescription sim in Households.All(content.Household))
                        {
                            if (SimTypes.IsSkinJob(sim))
                            {
                                continue;
                            }

                            if (SimTypes.IsOccult(sim, OccultTypes.ImaginaryFriend))
                            {
                                continue;
                            }

                            mStats.IncStat("Immigrant: Bin Sim");

                            if (sim.Species == choice.Species)
                            {
                                choices.Add(sim);

                                if (sim.FullName == choice.SimName)
                                {
                                    return(sim);
                                }
                            }
                        }

                        if (choices.Count > 0)
                        {
                            return(RandomUtil.GetRandomObjectFromList(choices));
                        }
                    }
                }
            }

            if ((RandomUtil.RandomChance(mRandomChance)) || (Manager.Sims.All.Count <= 20))
            {
                return(GetRandomSim(gender, species));
            }

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

            bool allowAlien = Manager.GetValue <AllowAlienHouseholdOption <TManager>, bool>();

            foreach (SimDescription sim in Manager.Sims.All)
            {
                if (SimTypes.InServicePool(sim, ServiceType.GrimReaper))
                {
                    continue;
                }

                if (sim.Species != species)
                {
                    continue;
                }

                if (!allowAlien)
                {
                    if (SimTypes.IsServiceAlien(sim))
                    {
                        continue;
                    }
                }

                if (exclude != null)
                {
                    if (exclude == sim)
                    {
                        continue;
                    }

                    if (exclude.LastName == sim.LastName)
                    {
                        continue;
                    }
                }

                sims.Add(sim);
            }

            if (sims.Count == 0)
            {
                return(null);
            }
            else
            {
                mStats.IncStat("Immigrant: Town Sim");

                return(RandomUtil.GetRandomObjectFromList(sims));
            }
        }