Beispiel #1
0
 public static FutureDescendantService GetInstance()
 {
     if (FutureDescendantService.sInstance == null)
     {
         FutureDescendantService.CreateInstance();
     }
     return(FutureDescendantService.GetInstance());
 }
        protected override bool Allow(GameHitParameters <GameObject> parameters)
        {
            if (!Common.kDebugging)
            {
                return(false);
            }

            if (FutureDescendantService.GetInstance() == null)
            {
                return(false);
            }

            return(base.Allow(parameters));
        }
        protected override OptionResult Run(GameHitParameters <GameObject> parameters)
        {
            Common.StringBuilder results = new Common.StringBuilder("BuildDescendantHouseholdSpecs");

            FutureDescendantService instance = FutureDescendantService.GetInstance();

            instance.CleanUpFutureDescendantService(true);
            instance.InitializeFutureDescendantService();

            FutureDescendantServiceEx.BuildDescendantHouseholdSpecs(instance);

            foreach (FutureDescendantService.FutureDescendantHouseholdInfo info in FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo)
            {
                if (info.HasAncestorFromHousehold(Household.ActiveHousehold))
                {
                    FutureDescendantHouseholdInfoEx.CalculateHouseholdFamilyScore(info, results);
                }
            }

            Common.DebugWriteLog(results);

            return(OptionResult.SuccessClose);
        }
        public static void RunStatic()
        {
            if (!GameUtils.IsInstalled(ProductVersion.EP11))
            {
                return;
            }

            Overwatch.Log("CleanupFutureDescendantService");

            FutureDescendantService instance = FutureDescendantService.GetInstance();

            if (instance != null)
            {
                List <ulong> removeFromMap        = new List <ulong>();
                List <ulong> simsToPossiblyVanish = new List <ulong>();
                List <ulong> simsToKeep           = new List <ulong>();
                Dictionary <ulong, FutureDescendantService.FutureDescendantHouseholdInfo> houses = new Dictionary <ulong, FutureDescendantService.FutureDescendantHouseholdInfo>();

                foreach (ulong num in FutureDescendantService.sPersistableData.DescendantHouseholdsMap.Keys)
                {
                    bool flag = false;
                    IMiniSimDescription ancestorSim = SimDescription.GetIMiniSimDescription(num);
                    if (ancestorSim == null)
                    {
                        flag = true;
                        removeFromMap.Add(num);
                    }

                    foreach (FutureDescendantService.FutureDescendantHouseholdInfo info in FutureDescendantService.sPersistableData.DescendantHouseholdsMap[num])
                    {
                        Household descendantHousehold = info.DescendantHousehold;

                        if (descendantHousehold != null)
                        {
                            if (!houses.ContainsKey(info.mHouseholdId))
                            {
                                houses.Add(info.mHouseholdId, info);
                            }

                            foreach (SimDescription desc in descendantHousehold.SimDescriptions)
                            {
                                if (flag)
                                {
                                    if (!simsToKeep.Contains(desc.SimDescriptionId))
                                    {
                                        simsToPossiblyVanish.Add(desc.SimDescriptionId);
                                    }
                                }
                                else
                                {
                                    if (simsToPossiblyVanish.Contains(desc.SimDescriptionId))
                                    {
                                        simsToPossiblyVanish.Remove(desc.SimDescriptionId);
                                    }
                                    simsToKeep.Add(desc.SimDescriptionId);
                                }
                            }
                        }
                    }
                }

                foreach (ulong num in removeFromMap)
                {
                    FutureDescendantService.sPersistableData.DescendantHouseholdsMap.Remove(num);

                    Overwatch.Log(" Missing Removed: " + num);
                }

                if (!GameUtils.IsFutureWorld())
                {
                    // because sims can possibly be deleted beyond here and I don't believe you can delete sims who are minisims while in the homeworld?
                    return;
                }
                else
                {
                    // this causes a script error if it deletes Sims while cleanup of relationships is running so let that run and come back in a bit...
                    if (!wasRescheduled)
                    {
                        new Common.AlarmTask(10, TimeUnit.Minutes, RunStatic);
                        wasRescheduled = true;
                        return;
                    }
                }

                Dictionary <ulong, SimDescription> sims = SimListing.GetResidents(false);
                foreach (SimDescription sim in sims.Values)
                {
                    if (sim.TraitManager == null)
                    {
                        continue;
                    }

                    foreach (KeyValuePair <ulong, Trait> trait in sim.TraitManager.mValues)
                    {
                        if ((trait.Value.Guid == TraitNames.DescendantHiddenTrait) && (!simsToKeep.Contains(sim.SimDescriptionId)) && (sim.Household != null && !sim.Household.IsActive))
                        {
                            simsToPossiblyVanish.Add(sim.SimDescriptionId);
                            break;
                        }
                    }
                }

                foreach (ulong desc in simsToPossiblyVanish)
                {
                    IMiniSimDescription mini = SimDescription.GetIMiniSimDescription(desc);
                    if (mini != null)
                    {
                        Annihilation.Cleanse(mini);

                        if (houses.ContainsKey(mini.LotHomeId))
                        {
                            houses[mini.LotHomeId].mHouseholdMembers.Remove(desc);
                        }
                    }

                    Overwatch.Log(" Annihilated: " + mini.FullName);
                }

                FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo = new List <FutureDescendantService.FutureDescendantHouseholdInfo>();
                foreach (KeyValuePair <ulong, FutureDescendantService.FutureDescendantHouseholdInfo> houseInfo in houses)
                {
                    Household house = houseInfo.Value.DescendantHousehold;
                    if ((house != null) && (houseInfo.Value.mHouseholdMembers.Count == 0))
                    {
                        Annihilation.Cleanse(house);
                        Overwatch.Log(" Annihilated household: " + house.Name);
                    }
                    else
                    {
                        FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo.Add(houseInfo.Value);
                    }
                }

                FutureDescendantService.sPersistableData.InvalidDescendantHouseholdsInfo.Clear();
                houses = null;
                simsToPossiblyVanish = null;
                simsToKeep           = null;
            }
        }