Esempio n. 1
0
        public static void FixupOccults(FutureDescendantService ths, FutureDescendantService.FutureDescendantHouseholdInfo descendantHouseholdInfo)
        {
            Common.StringBuilder msg = new Common.StringBuilder("FixupOccults");

            if (descendantHouseholdInfo == null)
            {
                msg += Common.NewLine + "descendantHouseholdInfo null";
            }

            if (descendantHouseholdInfo.DescendantHousehold == null)
            {
                msg += Common.NewLine + "descendantHouseholdInfo.DescendantHousehold null";
            }

            if (!descendantHouseholdInfo.mFutureDescendantHouseholdInfoDirty)
            {
                msg += Common.NewLine + "mFutureDescendantHosueholdInfoDirty is false";
            }

            if (Traveler.Settings.mChanceOfOccultHybrid == 0)
            {
                msg += Common.NewLine + "Hybrid 0, returning";
                Common.DebugWriteLog(msg);
                ths.FixupOccults(descendantHouseholdInfo);
                return;
            }

            try
            {
                if (((descendantHouseholdInfo != null) && descendantHouseholdInfo.mFutureDescendantHouseholdInfoDirty) && (descendantHouseholdInfo.DescendantHousehold != null))
                {
                    descendantHouseholdInfo.mFutureDescendantHouseholdInfoDirty = false;
                    List <OccultTypes> list  = null;
                    float minAlienPercentage = 0f;
                    float maxAlienPercentage = 0f;
                    if (descendantHouseholdInfo.mProgenitorSimIds != null)
                    {
                        foreach (ulong num in descendantHouseholdInfo.mProgenitorSimIds)
                        {
                            SimDescription item     = null;
                            bool           unpacked = false;
                            msg += Common.NewLine + "Num: " + num;
                            item = FutureDescendantHouseholdInfoEx.CreateProgenitor(num, out unpacked);

                            if (CrossWorldControl.sRetention.transitionedOccults.ContainsKey(num))
                            {
                                list = CrossWorldControl.sRetention.transitionedOccults[num];
                            }
                            else
                            {
                                msg += Common.NewLine + "Couldn't find Sim in transitionedOccults (Maybe they had none?)";
                            }

                            if (item != null)
                            {
                                // EA appears to transition this... I hope :)
                                msg += Common.NewLine + "Working on " + item.FullName;
                                if (SimTypes.IsServiceAlien(item))
                                {
                                    msg += Common.NewLine + "Is full blood Alien";
                                    maxAlienPercentage = 1f;
                                }
                                else
                                {
                                    msg += Common.NewLine + "Died (2)";
                                    if (item.AlienDNAPercentage == 0 && item.IsAlien)
                                    {
                                        msg += Common.NewLine + "IsAlien";
                                        minAlienPercentage = 0;
                                        maxAlienPercentage = 1;
                                    }
                                    else
                                    {
                                        if (item.AlienDNAPercentage > maxAlienPercentage)
                                        {
                                            maxAlienPercentage = item.mAlienDNAPercentage;
                                        }
                                        else if (item.AlienDNAPercentage > minAlienPercentage)
                                        {
                                            minAlienPercentage = item.mAlienDNAPercentage;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                msg += Common.NewLine + "Failed to find SimDesc";
                            }
                        }
                    }

                    if (descendantHouseholdInfo.mHouseholdMembers != null)
                    {
                        foreach (ulong num3 in descendantHouseholdInfo.mHouseholdMembers)
                        {
                            SimDescription newSim = SimDescription.Find(num3);
                            if (newSim != null && !newSim.IsDead)
                            {
                                msg += Common.NewLine + "Processing: " + newSim.FullName;
                                if (Traveler.Settings.mChanceOfOccultMutation == 0)
                                {
                                    msg += Common.NewLine + "Occult Mutation 0";
                                    List <OccultTypes> descendantOccults = OccultTypeHelper.CreateList(newSim, true);
                                    foreach (OccultTypes type in descendantOccults)
                                    {
                                        if (list == null || !list.Contains(type))
                                        {
                                            OccultTypeHelper.Remove(newSim, type, true);
                                        }
                                    }
                                }

                                if (list != null && list.Count > 0)
                                {
                                    msg += Common.NewLine + "Applying Occult Chance to " + newSim.FullName;
                                    bool success = FutureDescendantHouseholdInfoEx.ApplyOccultChance(newSim, list, Traveler.Settings.mChanceOfOccultHybrid, Traveler.Settings.mChanceOfOccultMutation, Traveler.Settings.mMaxOccult);
                                    if (success)
                                    {
                                        msg += Common.NewLine + "Added occults";
                                    }
                                }
                                else
                                {
                                    msg += Common.NewLine + "No occults found...";
                                }

                                if (minAlienPercentage > 0 || maxAlienPercentage > 0 && RandomUtil.CoinFlip())
                                {
                                    float percent = (minAlienPercentage + maxAlienPercentage) / 2f;
                                    float jitter  = SimDescription.kAlienDNAJitterPercent * 2; // 2 generations have passed considering Travelers approach to descendants
                                    percent = RandomUtil.GetFloat(-jitter, jitter);
                                    newSim.SetAlienDNAPercentage(MathUtils.Clamp(percent, 0f, 1f));

                                    msg += Common.NewLine + "Made alien. Percent: " + newSim.mAlienDNAPercentage;
                                }
                            }
                            else
                            {
                                msg += Common.NewLine + "New Sim was null.";
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Common.Exception("", e);
            }
            finally
            {
                Common.DebugWriteLog(msg);
            }
        }
Esempio n. 2
0
        private static bool ProcessDescendantHouseholds(FutureDescendantService ths)
        {
            Common.StringBuilder msg = new Common.StringBuilder("ProcessDescendantHouseholds");

            for (int i = 0x0; i < FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo.Count; i++)
            {
                try
                {
                    FutureDescendantService.FutureDescendantHouseholdInfo info = FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo[i];
                    Household descendantHousehold = info.DescendantHousehold;
                    if (descendantHousehold != null)
                    {
                        if (Household.ActiveHousehold != null && info.HasAncestorFromHousehold(Household.ActiveHousehold))
                        {
                            msg += Common.NewLine + "descendantHousehold is not null.";
                            while (descendantHousehold.NumMembers > info.mCurrentDesiredHouseholdSize)
                            {
                                msg += Common.NewLine + "Removing descendant because the current size (" + descendantHousehold.NumMembers + ") is greater than the desired (" + info.mCurrentDesiredHouseholdSize + ")";
                                info.RemoveDescendant();
                            }

                            while (descendantHousehold.NumMembers < info.mCurrentDesiredHouseholdSize)
                            {
                                msg += Common.NewLine + "Adding descendant because the current size (" + descendantHousehold.NumMembers + ") is less  than the desired (" + info.mCurrentDesiredHouseholdSize + ")";
                                // Custom
                                if (!FutureDescendantHouseholdInfoEx.CreateAndAddDescendant(info))
                                {
                                    break;
                                }
                            }

                            foreach (ulong num2 in Household.mDirtyNameSimIds)
                            {
                                if (info.IsSimAProgenitor(num2))
                                {
                                    SimDescription description = SimDescription.Find(num2);
                                    if (description != null)
                                    {
                                        foreach (SimDescription description2 in info.DescendantHousehold.SimDescriptions)
                                        {
                                            description2.LastName = description.LastName;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        msg += Common.NewLine + "descendantHousehold is null so instatiating a new one.";
                        // Custom
                        Household household2 = FutureDescendantHouseholdInfoEx.Instantiate(info);
                        FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo[i].mFutureDescendantHouseholdInfoDirty = true;
                        if (household2 == null)
                        {
                            msg += Common.NewLine + "NULL";
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.Exception(i.ToString(), e);
                }
                finally
                {
                    Common.DebugWriteLog(msg);
                }
            }
            Household.ClearDirtyNameSimIDs();
            return(true);
        }