Exemple #1
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupOccult");

            foreach (SimDescription sim in Household.AllSimsLivingInWorld())
            {
                OccultTypeHelper.ValidateOccult(sim, Overwatch.Log);

                OccultTypeHelper.TestAndRebuildWerewolfOutfit(sim);

                // Compensate for a missing line in OccultWerewolf:FixupOccult
                if ((sim.CreatedSim != null) && (sim.ToddlerOrAbove) && (OccultTypeHelper.HasType(sim, OccultTypes.Werewolf)))
                {
                    World.ObjectSetVisualOverride(sim.CreatedSim.ObjectId, eVisualOverrideTypes.Werewolf, null);
                }
            }
        }
Exemple #2
0
        public static bool DoRoute(RoutingComponent ths, Route r)
        {
            Sim owner = ths.Owner as Sim;

            if ((!r.ExecutionFromNonSimTaskIsSafe && (owner != null)) && (Simulator.CurrentTask != ths.Owner.ObjectId))
            {
                Simulator.CurrentTask.ObjectFromId <GameObject>();
                return(false);
            }

            IBoat boat = ths.Owner as IBoat;

            if (ths.RoutingParent != null)
            {
                if (!(ths.RoutingParent is IBoat) || (r.GetOption2(Route.RouteOption2.EndAsBoat) && (!r.PlanResult.Succeeded() || !RoutingComponent.PlannedRouteHasNonBoatSubpath(r))))
                {
                    // Custom
                    if (ths.RoutingParent.RoutingComponent is CarRoutingComponent)
                    {
                        return(CarRoutingComponentEx.DoRoute(ths.RoutingParent.RoutingComponent as CarRoutingComponent, r));
                    }
                    else
                    {
                        return(ths.RoutingParent.RoutingComponent.DoRoute(r));
                    }
                }
            }
            else if (((boat != null) && r.PlanResult.Succeeded()) && (!r.GetOption2(Route.RouteOption2.EndAsBoat) || RoutingComponent.PlannedRouteHasNonBoatSubpath(r)))
            {
                Sim driver = boat.GetDriver();
                if (driver != null)
                {
                    return(driver.RoutingComponent.DoRoute(r));
                }
            }

            Common.StringBuilder msg = new Common.StringBuilder("RoutingComponentEx:DoRoute" + Common.NewLine);
            if (owner != null)
            {
                msg += Common.NewLine + owner.FullName + Common.NewLine;
            }

            ths.mRouteActions.Clear();
            bool routeSuccess = true;

            try
            {
                RouteAction.FailureExplanation explanation = RouteAction.FailureExplanation.None;
                RoutingComponent.mnNumDoRouteCalls += (ulong)0x1L;
                if (r.PlanResult.Succeeded())
                {
                    ths.OnAboutToStartFollowingRoute(r);
                    if (r.PlanResult.Succeeded())
                    {
                        ths.PushActionsForRoute(r, r);
                        if (owner != null)
                        {
                            owner.PushBackpackPostureIfNecessary();
                            owner.PushCanePostureIfNecessary();
                            owner.PushJetpackPostureIfNecessary();
                        }
                    }
                    else
                    {
                        routeSuccess = false;
                    }
                }
                else
                {
                    routeSuccess = false;
                }

                msg.Append("A");

                if (!routeSuccess)
                {
                    explanation |= RouteAction.FailureExplanation.InitialPlanFailure;
                    LogFailure(ths.Owner, RouteAction.FailureExplanation.InitialPlanFailure, r.PlanResult, "Initial Path Plan Failure (WILL NOT play route fail)");
                    r.SetRouteActionResult(0x2);
                    return(false);
                }

                msg.Append("B");

                int failures = 0;

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, false);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, false);
                }

                Vector3 originalPosition = ths.Owner.Position;
                int     loops            = 0;

                bool  success       = true;
                Route processedPath = r;
                bool  isOutside     = ths.Owner.IsOutside;
                ths.mNumWaterEntriesThisRoute = 0;
                while (ths.mRouteActions.Count != 0x0)
                {
                    // Custom
                    if (ths.Owner.Position == originalPosition)
                    {
                        loops++;
                    }

                    if ((loops > 30) || (ths.mRouteActions.Count > 30))
                    {
                        success = false;
                        ths.mRouteActions.Clear();
                        break;
                    }

                    if (ths.mRouteActions[0] is GetInBoatRouteAction)
                    {
                        ths.mNumWaterEntriesThisRoute++;
                        if (ths.mNumWaterEntriesThisRoute > 10)
                        {
                            if (owner != null)
                            {
                                owner.SetToResetAndSendHome();
                            }
                            else
                            {
                                ths.Owner.SetObjectToReset();
                            }
                            return(false);
                        }
                    }

                    if ((owner != null) && owner.IsOutside)
                    {
                        owner.PushHoverboardPostureIfNecessary();
                    }

                    // Custom
                    RouteAction routeAction = ths.mRouteActions[0x0];

                    msg.Append(Common.NewLine + routeAction.GetType());

                    RouteAction.ActionResult actionResult = RouteAction.ActionResult.Continue;

                    //using (BuffsChangedProxy buffsProxy = new BuffsChangedProxy(owner))
                    {
                        try
                        {
                            if (routeAction is ObstacleEncounteredRouteInterruptAction)
                            {
                                actionResult = ObstacleEncounteredRouteInterruptActionEx.PerformAction(routeAction as ObstacleEncounteredRouteInterruptAction);
                            }
                            else
                            {
                                actionResult = routeAction.PerformAction();
                            }
                        }
                        catch (ResetException)
                        {
                            throw;
                        }
                        catch (SacsErrorException e)
                        {
                            Common.DebugException(owner, null, msg, e);

                            failures++;

                            if (failures > 10)
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                            }

                            routeAction.OnReset();
                        }
                        catch (Exception e)
                        {
                            Common.Exception(owner, null, msg.ToString(), e);

                            string stackTrace = e.StackTrace.ToString();

                            if (stackTrace.Contains("OccultManager:DisallowClothesChange"))
                            {
                                OccultTypeHelper.ValidateOccult(owner.SimDescription, null);

                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("CommonDoor:IsAllowedThrough"))
                            {
                                Corrections.CleanupCommonDoors(null);
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("SimRoutingComponent:RequestWalkStyle"))
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                failures++;

                                if (failures > 10)
                                {
                                    actionResult = RouteAction.ActionResult.Terminate;
                                }
                                else
                                {
                                    actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                                }
                            }

                            routeAction.OnReset();
                        }
                    }

                    msg.Append(Common.NewLine + "C");

                    // Custom
                    if ((ths.mRouteActions.Count > 0) && (ths.mRouteActions[0x0].ForciblyReplanned) && (actionResult == RouteAction.ActionResult.ContinueAndPopPath))
                    {
                        actionResult = RouteAction.ActionResult.ContinueAndFollowPath;
                    }

                    msg.Append(Common.NewLine + actionResult + Common.NewLine);

                    if (GoHere.Settings.mDetailedRouting)
                    {
                        if (Sim.ActiveActor == owner)
                        {
                            Common.DebugNotify(msg);
                        }
                    }

                    if (ths.mRouteActions.Count == 0x0)
                    {
                        explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                        success      = false;
                        break;
                    }

                    msg.Append("D");

                    ths.mPreviousRouteAction = ths.mRouteActions[0x0];
                    switch (actionResult)
                    {
                    case RouteAction.ActionResult.Continue:
                    case RouteAction.ActionResult.ContinueAndPopPath:
                    case RouteAction.ActionResult.ContinueAndPopPathAndReplan:
                    case RouteAction.ActionResult.ContinueAndPopPathAndRestart:
                    case RouteAction.ActionResult.ContinueAndFollowPath:
                        msg.Append("E");

                        ths.mRouteActions.RemoveAt(0x0);
                        bool flag3 = (processedPath.GetNumPaths() > 0x1) || (processedPath.IsLoop());
                        if (((actionResult == RouteAction.ActionResult.ContinueAndPopPath) && flag3) || ((actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart) || (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)))
                        {
                            if (flag3)
                            {
                                processedPath.PopPath();
                            }

                            msg.Append("F");

                            if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)
                            {
                                Vector3 outPosition = new Vector3();
                                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                                {
                                    outPosition = ths.RoutingParent.PositionOnFloor;
                                }
                                else if (ths.Owner != null)
                                {
                                    if ((owner != null) && (owner.Posture is SwimmingInPool))
                                    {
                                        outPosition = ths.Owner.Position;
                                    }
                                    else
                                    {
                                        outPosition = ths.Owner.PositionOnFloor;
                                    }
                                }
                                else
                                {
                                    processedPath.GetPathStartPoint(0x0, ref outPosition);
                                }
                                processedPath.ReplanFromPoint(outPosition);
                            }

                            msg.Append("G");

                            if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart)
                            {
                                Vector3 positionOnFloor = new Vector3();
                                if (ths.Owner != null)
                                {
                                    positionOnFloor = ths.Owner.PositionOnFloor;
                                }
                                else
                                {
                                    processedPath.GetPathStartPoint(0x0, ref positionOnFloor);
                                }
                                processedPath.SetOption(Route.RouteOption.EnablePlanningAsCar, false);
                                processedPath.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                                processedPath.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
                                processedPath.ReplanFromPoint(positionOnFloor);
                                explanation |= RouteAction.FailureExplanation.CancelledByScript;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                            else if (processedPath.PlanResult.Succeeded())
                            {
                                ths.PushActionsForRoute(r, processedPath);
                            }
                            else
                            {
                                explanation |= RouteAction.FailureExplanation.ReplanFailure;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                        }
                        else if ((actionResult == RouteAction.ActionResult.ContinueAndFollowPath) && (r.GetNumPaths() > 0x0))
                        {
                            msg.Append("H");

                            if (r.PlanResult.Succeeded())
                            {
                                ths.PushActionsForRoute(r, processedPath);
                            }
                            else
                            {
                                explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                        }
                        break;

                    default:
                        msg.Append("I");

                        explanation |= ths.mPreviousRouteAction.FailureExplanations;
                        success      = false;
                        ths.mRouteActions.Clear();
                        break;
                    }
                }

                msg.Append("J");

                ths.mRouteActions.Clear();
                r.SetRouteActionResult((uint)explanation);
                if (!success)
                {
                    if (ths.mPreviousRouteAction == null)
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(Null mPreviousRouteAction failure)");
                    }
                    else
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(failure in " + ths.mPreviousRouteAction.ToString() + ")");
                    }
                }

                msg.Append("K");

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, true);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, true);
                }

                routeSuccess             = (success && (processedPath == r)) && r.PlanResult.Succeeded();
                ths.mPreviousRouteAction = null;
                if (ths.OnRouteActionsFinished != null)
                {
                    ths.OnRouteActionsFinished(ths.Owner, routeSuccess);
                }

                if (((SeasonsManager.Enabled && routeSuccess) && (isOutside && (owner != null))) && ((owner.IsHuman && owner.SimDescription.ChildOrAbove) && (!owner.IsOutside && (owner.CurrentOutfitCategory == OutfitCategories.Outerwear))))
                {
                    owner.SwitchToOutfitWithSpin(Sim.ClothesChangeReason.RemovingOuterwear);
                }

                if (owner != null)
                {
                    SwimmingInPool posture = owner.Posture as SwimmingInPool;
                    if ((posture != null) && posture.UsedShortEntryAnimation)
                    {
                        posture.UsedShortEntryAnimation = false;
                        if (owner.SimDescription.IsMatureMermaid)
                        {
                            OccultMermaid.PutOnTailWithSpin(owner.SimDescription);
                        }
                    }
                }
            }
            catch (ResetException)
            {
                routeSuccess = false;
                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(owner, null, msg.ToString(), e);
                routeSuccess = false;

                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
            }
            finally
            {
                ths.mRouteActions.Clear();
                if (owner != null)
                {
                    owner.RestoreUsedHoverboard();
                }

                if ((owner != null) && (owner.FirstName == "Roberto"))
                {
                    Common.DebugStackLog(msg);
                }
            }

            return(routeSuccess);
        }
Exemple #3
0
        public SimDescription CreateNewSim(SimDescription mom, SimDescription dad, CASAgeGenderFlags ages, CASAgeGenderFlags genders, CASAgeGenderFlags species, bool updateGenealogy)
        {
            if (dad == null)
            {
                dad = GetSim(CASAgeGenderFlags.Male, species, mom);
                if (dad == null)
                {
                    dad = GetSim(CASAgeGenderFlags.Female, species, mom);
                    if (dad == null)
                    {
                        return(null);
                    }
                }
            }

            CASAgeGenderFlags gender = (CASAgeGenderFlags)RandomUtil.SelectOneRandomBit((uint)(genders));
            CASAgeGenderFlags age    = (CASAgeGenderFlags)RandomUtil.SelectOneRandomBit((uint)(ages));

            if (dad.CelebrityManager == null)
            {
                dad.Fixup();
            }

            if (mom.CelebrityManager == null)
            {
                mom.Fixup();
            }

            SimDescription newSim = null;

            try
            {
                if (mom.Species == CASAgeGenderFlags.Human)
                {
                    newSim = Genetics.MakeDescendant(dad, mom, age, gender, 100, new Random(), false, updateGenealogy, true, GetGeneticWorld(), false);

                    newSim.HomeWorld = GameUtils.GetCurrentWorld();
                }
                else
                {
                    newSim = GeneticsPet.MakePetDescendant(dad, mom, age, gender, mom.Species, new Random(), updateGenealogy, GeneticsPet.SetName.SetNameNonInteractive, 0, OccultTypes.None);
                }
            }
            catch (Exception e)
            {
                Common.Exception(dad, mom, e);
            }

            if (newSim == null)
            {
                return(null);
            }

            if (!updateGenealogy)
            {
                FacialBlends.RandomizeBlends(mStats.AddStat, newSim, new Vector2(0f, 0f), true, Manager.GetValue <MutationUnsetRangeOption <TManager>, Vector2>(), true, Manager.GetValue <AllowAlienHouseholdOption <TManager>, bool>());
            }

            List <OccultTypes> occults = new List <OccultTypes>();

            occults.AddRange(OccultTypeHelper.CreateList(mom.OccultManager.CurrentOccultTypes, true));
            occults.AddRange(OccultTypeHelper.CreateList(dad.OccultManager.CurrentOccultTypes, true));

            if (updateGenealogy)
            {
                Manager.Sims.ApplyOccultChance(Manager, newSim, occults, Manager.GetValue <ChanceOfHybridOption <TManager>, int>(), Manager.GetValue <MaximumOccultOption <TManager>, int>());
            }
            else if (species == CASAgeGenderFlags.Human)
            {
                int maxCelebrityLevel = Manager.GetValue <MaxCelebrityLevelOption <TManager>, int>();

                if (maxCelebrityLevel >= 0)
                {
                    newSim.CelebrityManager.mOwner = newSim;

                    Skill scienceSkill = SkillManager.GetStaticSkill(SkillNames.Science);
                    if (scienceSkill != null)
                    {
                        scienceSkill.mNonPersistableData.SkillCategory |= SkillCategory.Hidden;
                    }

                    try
                    {
                        newSim.CelebrityManager.ForceSetLevel((uint)RandomUtil.GetInt(maxCelebrityLevel));
                    }
                    finally
                    {
                        if (scienceSkill != null)
                        {
                            scienceSkill.mNonPersistableData.SkillCategory &= ~SkillCategory.Hidden;
                        }
                    }
                }

                occults.AddRange(Manager.GetValue <ImmigrantOccultOption <TManager>, List <OccultTypes> >());
                if (occults.Count > 0)
                {
                    if (RandomUtil.RandomChance(Manager.GetValue <ChanceOfOccultOption <TManager>, int>()))
                    {
                        OccultTypeHelper.Add(newSim, RandomUtil.GetRandomObjectFromList(occults), false, false);
                    }
                }
            }

            Manager.Sims.ApplyOccultChance(Manager, newSim, occults, Manager.GetValue <ChanceOfHybridOption <TManager>, int>(), Manager.GetValue <MaximumOccultOption <TManager>, int>());

            OccultTypeHelper.ValidateOccult(newSim, null);

            OccultTypeHelper.TestAndRebuildWerewolfOutfit(newSim);

            newSim.FirstName = Manager.Sims.EnsureUniqueName(newSim);

            List <Trait> traits = new List <Trait>(newSim.TraitManager.List);

            foreach (Trait trait in traits)
            {
                if (trait.IsHidden)
                {
                    newSim.TraitManager.RemoveElement(trait.Guid);
                }
            }

            List <Trait> choices = AgingManager.GetValidTraits(newSim, true, true, true);

            if (choices.Count > 0)
            {
                while (!newSim.TraitManager.TraitsMaxed())
                {
                    Trait choice = RandomUtil.GetRandomObjectFromList <Trait>(choices);
                    if (!newSim.TraitManager.AddElement(choice.Guid))
                    {
                        break;
                    }
                }
            }

            if (SimFromBinEvents.OnGeneticSkinBlend != null)
            {
                SimFromBinEvents.OnGeneticSkinBlend(mStats, newSim, mom, dad, Manager);
            }

            FixInvisibleTask.Perform(newSim, true);

            if (SimFromBinEvents.OnSimFromBinUpdate != null)
            {
                SimFromBinEvents.OnSimFromBinUpdate(mStats, newSim, mom, dad, Manager);
            }

            INameTakeOption nameTake = Manager.GetOption <NameTakeOption <TManager> >();

            if ((!updateGenealogy) && (nameTake != null))
            {
                bool wasEither;
                newSim.LastName = Manager.Sims.HandleName(nameTake, mom, dad, out wasEither);
            }
            else if (mom != null)
            {
                newSim.LastName = mom.LastName;
            }
            else if (dad != null)
            {
                newSim.LastName = dad.LastName;
            }

            if (!updateGenealogy && Manager.GetValue <CustomNamesOnlyOption <TManager>, bool>())
            {
                newSim.LastName = LastNameListBooter.GetRandomName(!Manager.GetValue <CustomNamesOnlyOption <TManager>, bool>(), newSim.Species, newSim.IsFemale);
            }

            return(newSim);
        }
Exemple #4
0
        public static bool ApplyOccultChance(SimDescription sim, List <OccultTypes> validTypes, int chanceOfOccult, int chanceOfMutation, int maximumOccultPerSim)
        {
            if (sim == null)
            {
                return(false);
            }

            if (FutureDescendantServiceEx.OccultProcessed.Contains(sim.SimDescriptionId))
            {
                return(false);
            }

            List <OccultTypes> possibleOccults = OccultTypeHelper.CreateListOfAllOccults(true);

            int occultsAdded = -1;

            if (OccultTypeHelper.CreateList(sim).Count > 0) // this handles the possible occult added by EA when the Sim was generated
            {
                occultsAdded = 0;
            }

            foreach (OccultTypes type in validTypes)
            {
                if (occultsAdded >= maximumOccultPerSim)
                {
                    break;
                }

                if (!RandomUtil.RandomChance(chanceOfOccult))
                {
                    continue;
                }

                if (RandomUtil.RandomChance(chanceOfMutation) && possibleOccults.Count > 0)
                {
                    while (possibleOccults.Count > 0)
                    {
                        OccultTypes mutationType = RandomUtil.GetRandomObjectFromList <OccultTypes>(possibleOccults);

                        if (OccultTypeHelper.Add(sim, mutationType, false, false))
                        {
                            possibleOccults.Remove(mutationType);
                            occultsAdded++;
                            break;
                        }

                        possibleOccults.Remove(mutationType);
                    }
                }

                if (OccultTypeHelper.Add(sim, type, false, false))
                {
                    occultsAdded++;
                }
            }

            OccultTypeHelper.ValidateOccult(sim, null);
            FutureDescendantServiceEx.OccultProcessed.Add(sim.SimDescriptionId);

            if (occultsAdded > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
            protected override void OnPerform()
            {
                OccultTypeHelper.ValidateOccult(mSim, null);

                OccultTypeHelper.TestAndRebuildWerewolfOutfit(mSim);
            }