Exemple #1
0
        public static bool RandomActiveHouseholdAndActiveActor()
        {
            if (GameStates.IsGameShuttingDown /* || Sims3.SimIFace.Environment.HasEditInGameModeSwitch */)
            {
                return(false);
            }
            List <Sim> list = new List <Sim>();

            foreach (Sim actor in LotManager.Actors)
            {
                if (actor.SimDescription.CreatedSim != null && !actor.IsInActiveHousehold && actor.IsHuman && !actor.SimDescription.IsGhost && actor.SimDescription.Household != Household.NpcHousehold && actor.SimDescription.Household != Household.PetHousehold && actor.SimDescription.Household != Household.MermaidHousehold && actor.SimDescription.Household != Household.TouristHousehold && actor.SimDescription.Household != Household.PreviousTravelerHousehold && actor.SimDescription.Household != Household.AlienHousehold && actor.SimDescription.Household != Household.ServobotHousehold)
                {
                    list.Add(actor);
                }
            }
            if (list.Count == 0)
            {
                return(false);
            }

            else if (list.Count > 0)
            {
                Sim randomObjectFromList = RandomUtil.GetRandomObjectFromList(list);
                if (!randomObjectFromList.InWorld)
                {
                    randomObjectFromList.AddToWorld();
                }
                PlumbBob.ForceSelectActor(randomObjectFromList);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static bool AttemptToPutInSafeLocation(Sim ths, Vector3 destination, bool allowHibernate)
        {
            if ((ths == null) || (ths.HasBeenDestroyed)) return false;

            if ((ths.LotHome == null) || (destination != Vector3.Invalid))
            {
                Lot lot = ths.LotHome;
                if (lot == null)
                {
                    lot = ths.VirtualLotHome;
                }

                Vector3 pos = destination;

                if (pos == Vector3.Invalid)
                {
                    pos = AttemptToFindSafeLocation(lot, ths.IsHorse);
                }

                if (pos != Vector3.Invalid)
                {
                    try
                    {
                        Vector3 fwd;
                        ths.SetPosition(FindRoutableLocation(ths, pos, out fwd));
                        ths.SetForward(fwd);
                        ths.RemoveFromWorld();
                        ths.AddToWorld();
                        ths.SetHiddenFlags(HiddenFlags.Nothing);
                        ths.SetOpacity(1f, 0f);
                        ths.SimRoutingComponent.ForceUpdateDynamicFootprint();
                    }
                    catch (Exception e)
                    {
                        Common.Exception(ths, e);
                    }

                    return true;
                }
                else
                {
                    if (allowHibernate)
                    {
                        ths.FadeOut(false, true);
                    }
                    return false;
                }
            }

            Vector3 originalPos = ths.Position;

            try
            {
                if (!ths.AttemptToPutInSafeLocation(true)) return false;
            }
            catch (Exception e)
            {
                Common.DebugException(ths, e);
                return false;
            }

            return (ths.Position != originalPos);
        }
        protected bool Test(Sim sim, List<InteractionDefinition> interactions)
        {
            if (InteractionsEx.HasInteraction<ICountsAsWorking>(sim))
            {
                IncStat("At Work");
                return false;
            }
            else if (Situations.HasInteraction(sim, interactions, true))
            {
                IncStat("At Work");
                return false;
            }
            else
            {
                if (Situations.DebuggingLevel >= Common.DebugLevel.High)
                {
                    if (sim.InteractionQueue == null)
                    {
                        IncStat("Interaction Queue = null");
                    }
                    else
                    {
                        if (sim.InteractionQueue.Count == 0)
                        {
                            IncStat("Interaction Queue empty");
                        }
                        else
                        {
                            foreach (InteractionInstance instance2 in sim.InteractionQueue.InteractionList)
                            {
                                IncStat("Interaction: " + instance2.ToString());
                            }
                        }
                    }
                }

                VisitSituation.AnnounceTimeToGoToWork(sim);

                if (SimTypes.IsSpecial(Sim))
                {
                    IncStat("Special Pushed to Work");
                }
                else
                {
                    IncStat("Pushed to Work");
                }

                try
                {
                    // Don't queue stomp on their birthday
                    if (sim.SimDescription.YearsSinceLastAgeTransition != 0)
                    {
                        sim.InteractionQueue.CancelAllInteractions();

                        IncStat("Queue Stomped");

                        if ((!SimTypes.IsSelectable(sim.SimDescription)) && (sim.LotCurrent != null) && (sim.LotCurrent.CanSimTreatAsHome(sim)))
                        {
                            Callbox callbox = sim.LotHome.FindCallbox();
                            if (callbox != null)
                            {
                                Vector3 fwd = Vector3.Invalid;
                                Vector3 pos = Vector3.Invalid;

                                World.FindGoodLocationParams fglParams = new World.FindGoodLocationParams(callbox.Position);
                                fglParams.BooleanConstraints = FindGoodLocationBooleans.Routable | FindGoodLocationBooleans.PreferEmptyTiles;
                                if (GlobalFunctions.FindGoodLocation(sim, fglParams, out pos, out fwd))
                                {
                                    sim.ResetBindPoseWithRotation();
                                    sim.SetPosition(pos);
                                    sim.SetForward(fwd);
                                    sim.RemoveFromWorld();
                                    sim.AddToWorld();
                                    sim.SetHiddenFlags(HiddenFlags.Nothing);
                                    sim.SetOpacity(1f, 0f);

                                    IncStat("Bounce to Mailbox");
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.DebugException(sim, e);

                    IncStat("Cancel Fail");
                }

                sim.InteractionQueue.RemoveGoHomeInteractions(true);

                return true;
            }
        }
Exemple #4
0
 protected static void ResetStuckSim(Sim sim, Vector3 destination, string suffix, bool deep = false)
 {
     if (sim != null &&
         !sim.HasBeenDestroyed &&
         sim.SimDescription != null)
     {
         //Alive.WriteLog("sim_is_stuck:reset_sim_in_progress:sim:"+sim.Name+";destination:"+destination);
         Lot lot = null;
         if (sim.SimDescription.IsBonehilda)
         {
             lot = BonehildaCoffin.FindBonehildaCoffin(sim)?.LotCurrent;
             if (lot == null)
             {
                 lot = sim.LotHome;
             }
         }
         else
         {
             lot = sim.LotHome;
         }
         if (lot == null)
         {
             lot = sim.VirtualLotHome;
         }
         if (lot == null)
         {
             lot = Sim.ActiveActor?.LotHome;
         }
         bool    addToWorld   = (true);
         Vector3 resetRawDest = destination;
         StuckSims.TryGetValue(sim.SimDescription.SimDescriptionId, out StuckSimData stuckSim);
         if (stuckSim != null)
         {
             //-------------------------
             if (stuckSim.Detections <= 2)
             {
                 Daycare daycare;
                 if ((sim.Household == null ||
                      (!sim.Household.InWorld &&
                       !sim.Household.IsSpecialHousehold)) &&
                     (!Passport.IsHostedPassportSim(sim) &&
                      sim.SimDescription.AssignedRole == null) &&
                     (LunarCycleManager.sFullMoonZombies == null ||
                      !LunarCycleManager.sFullMoonZombies.Contains(sim.SimDescription)) &&
                     ((daycare = sim.SimDescription.Occupation as Daycare) == null ||
                      !daycare.IsDaycareChild(sim.SimDescription)) &&
                     !sim.SimDescription.IsBonehilda &&
                     sim.Service == null)
                 {
                     addToWorld = (false);
                 }
                 if (destination != Vector3.Invalid)
                 {
                     goto DestSet;
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 3)
             {
                 if (lot == null)
                 {
                     lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 }
                 if (lot != null)
                 {
                     resetRawDest = lot.EntryPoint();
                     goto DestSet;
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 4)
             {
                 if (lot == null)
                 {
                     lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 }
                 if (lot != null)
                 {
                     Mailbox mailbox = lot.FindMailbox();
                     if (mailbox != null)
                     {
                         resetRawDest = mailbox.Position;
                         goto DestSet;
                     }
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 5 || sim.SimDescription.IsBonehilda)
             {
                 if (lot == null)
                 {
                     lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 }
                 if (lot != null)
                 {
                     Door frontDoor = lot.FindFrontDoor();
                     if (frontDoor != null)
                     {
                         int roomId = frontDoor.GetRoomIdOfDoorSide(CommonDoor.tSide.Front);
                         if (roomId != 0)
                         {
                             roomId = frontDoor.GetRoomIdOfDoorSide(CommonDoor.tSide.Back);
                         }
                         if (roomId == 0)
                         {
                             List <GameObject> objects = lot.GetObjectsInRoom <GameObject>(roomId);
                             if (objects.Count > 0)
                             {
                                 resetRawDest = RandomUtil.GetRandomObjectFromList(objects).Position;
                                 goto DestSet;
                             }
                         }
                     }
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 6)
             {
                 lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 if (lot != null)
                 {
                     resetRawDest = lot.EntryPoint();
                     goto DestSet;
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 7)
             {
                 lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 if (lot != null)
                 {
                     Mailbox mailbox = lot.FindMailbox();
                     if (mailbox != null)
                     {
                         resetRawDest = mailbox.Position;
                         goto DestSet;
                     }
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 8)
             {
                 lot = RandomUtil.GetRandomObjectFromList(Sims3.Gameplay.Queries.GetObjects <Lot>());
                 if (lot != null)
                 {
                     Door frontDoor = lot.FindFrontDoor();
                     if (frontDoor != null)
                     {
                         int roomId = frontDoor.GetRoomIdOfDoorSide(CommonDoor.tSide.Front);
                         if (roomId != 0)
                         {
                             roomId = frontDoor.GetRoomIdOfDoorSide(CommonDoor.tSide.Back);
                         }
                         if (roomId == 0)
                         {
                             List <GameObject> objects = lot.GetObjectsInRoom <GameObject>(roomId);
                             if (objects.Count > 0)
                             {
                                 resetRawDest = RandomUtil.GetRandomObjectFromList(objects).Position;
                                 goto DestSet;
                             }
                         }
                     }
                 }
             }
             //-------------------------
             if (stuckSim.Detections <= 9)
             {
                 resetRawDest        = Sim.ActiveActor.Position;
                 stuckSim.Detections = (1);
                 goto DestSet;
             }
             //-------------------------
             DestSet : {}
         }
         Vector3 resetValidatedDest;
         Vector3 forward = sim.ForwardVector;
         if (sim.SimDescription.IsHorse)
         {
             FindGoodLocationBooleans fglBooleans = FindGoodLocationBooleans.Routable |
                                                    FindGoodLocationBooleans.PreferEmptyTiles |
                                                    FindGoodLocationBooleans.AllowOnSlopes |
                                                    //FindGoodLocationBooleans.AllowIntersectionWithPlatformWalls|
                                                    //FindGoodLocationBooleans.AllowInFrontOfDoors          |
                                                    //FindGoodLocationBooleans.AllowOnStairTopAndBottomTiles|
                                                    FindGoodLocationBooleans.AllowOffLot |
                                                    FindGoodLocationBooleans.AllowOnStreets |
                                                    FindGoodLocationBooleans.AllowOnBridges |
                                                    FindGoodLocationBooleans.AllowOnSideWalks;
             if (stuckSim != null)
             {
                 if (stuckSim.Detections <= 5)
                 {
                     if (!GlobalFunctions.FindGoodLocationNearbyOnLevel(sim, sim.Level, ref resetRawDest, ref forward, fglBooleans))
                     {
                         GlobalFunctions.FindGoodLocationNearbyOnLevel(sim, sim.Level, ref resetRawDest, ref forward, FindGoodLocationBooleans.None);
                     }
                 }
             }
             World.FindGoodLocationParams fglParams = new World.FindGoodLocationParams(resetRawDest);
             fglParams.BooleanConstraints = fglBooleans;
             if (!GlobalFunctions.FindGoodLocation(sim, fglParams, out resetValidatedDest, out forward))
             {
                 fglParams.BooleanConstraints = FindGoodLocationBooleans.None;
                 GlobalFunctions.FindGoodLocation(sim, fglParams, out resetValidatedDest, out forward);
             }
         }
         else
         {
             World.FindGoodLocationParams fglParams = new World.FindGoodLocationParams(resetRawDest);
             fglParams.BooleanConstraints = FindGoodLocationBooleans.Routable |
                                            FindGoodLocationBooleans.PreferEmptyTiles |
                                            FindGoodLocationBooleans.AllowOnSlopes |
                                            FindGoodLocationBooleans.AllowIntersectionWithPlatformWalls |
                                            FindGoodLocationBooleans.AllowInFrontOfDoors |
                                            FindGoodLocationBooleans.AllowOnStairTopAndBottomTiles |
                                            FindGoodLocationBooleans.AllowOffLot |
                                            FindGoodLocationBooleans.AllowOnStreets |
                                            FindGoodLocationBooleans.AllowOnBridges |
                                            FindGoodLocationBooleans.AllowOnSideWalks;
             if (!GlobalFunctions.FindGoodLocation(sim, fglParams, out resetValidatedDest, out forward))
             {
                 fglParams.BooleanConstraints = FindGoodLocationBooleans.None;
                 GlobalFunctions.FindGoodLocation(sim, fglParams, out resetValidatedDest, out forward);
             }
         }
         if (!deep)
         {
             if (sim.InteractionQueue != null && sim.InteractionQueue.mInteractionList != null)
             {
                 InteractionInstance
                     currentInteraction;
                 if ((currentInteraction = sim.InteractionQueue.GetCurrentInteraction()) != null)
                 {
                     //
                     sim.InteractionQueue.CancelInteraction(currentInteraction.Id, ExitReason.CanceledByScript);
                 }
             }
         }
         sim.SetPosition(resetValidatedDest);
         sim.SetForward(forward);
         sim.RemoveFromWorld();
         if (addToWorld || deep)
         {
             if (!deep)
             {
                 try{
                     sim.Posture?.CancelPosture(sim);
                 }catch (Exception exception) {
                     Alive.WriteLog(exception.Message + "\n\n" +
                                    exception.StackTrace + "\n\n" +
                                    exception.Source);
                 }
             }
             sim.AddToWorld();
             sim.SetHiddenFlags(HiddenFlags.Nothing);
             sim.SetOpacity(1f, 0f);
         }
         else
         {
             sim.SetHiddenFlags(HiddenFlags.Everything);
             sim.SetOpacity(0f, 0f);
         }
         sim.SimRoutingComponent?.ForceUpdateDynamicFootprint();
         if (stuckSim != null)
         {
             stuckSim.Resetting = (false);                                       //  Pode detectar novos eventos Stuck
         }
     }
 }
Exemple #5
0
        protected bool Test(Sim sim, List <InteractionDefinition> interactions)
        {
            if (InteractionsEx.HasInteraction <ICountsAsWorking>(sim))
            {
                IncStat("At Work");
                return(false);
            }
            else if (Situations.HasInteraction(sim, interactions, true))
            {
                IncStat("At Work");
                return(false);
            }
            else
            {
                if (Situations.DebuggingLevel >= Common.DebugLevel.High)
                {
                    if (sim.InteractionQueue == null)
                    {
                        IncStat("Interaction Queue = null");
                    }
                    else
                    {
                        if (sim.InteractionQueue.Count == 0)
                        {
                            IncStat("Interaction Queue empty");
                        }
                        else
                        {
                            foreach (InteractionInstance instance2 in sim.InteractionQueue.InteractionList)
                            {
                                IncStat("Interaction: " + instance2.ToString());
                            }
                        }
                    }
                }

                VisitSituation.AnnounceTimeToGoToWork(sim);

                if (SimTypes.IsSpecial(Sim))
                {
                    IncStat("Special Pushed to Work");
                }
                else
                {
                    IncStat("Pushed to Work");
                }

                try
                {
                    // Don't queue stomp on their birthday
                    if (sim.SimDescription.YearsSinceLastAgeTransition != 0)
                    {
                        sim.InteractionQueue.CancelAllInteractions();

                        IncStat("Queue Stomped");

                        if ((!SimTypes.IsSelectable(sim.SimDescription)) && (sim.LotCurrent != null) && (sim.LotCurrent.CanSimTreatAsHome(sim)))
                        {
                            Callbox callbox = sim.LotHome.FindCallbox();
                            if (callbox != null)
                            {
                                Vector3 fwd = Vector3.Invalid;
                                Vector3 pos = Vector3.Invalid;

                                World.FindGoodLocationParams fglParams = new World.FindGoodLocationParams(callbox.Position);
                                fglParams.BooleanConstraints = FindGoodLocationBooleans.Routable | FindGoodLocationBooleans.PreferEmptyTiles;
                                if (GlobalFunctions.FindGoodLocation(sim, fglParams, out pos, out fwd))
                                {
                                    sim.ResetBindPoseWithRotation();
                                    sim.SetPosition(pos);
                                    sim.SetForward(fwd);
                                    sim.RemoveFromWorld();
                                    sim.AddToWorld();
                                    sim.SetHiddenFlags(HiddenFlags.Nothing);
                                    sim.SetOpacity(1f, 0f);

                                    IncStat("Bounce to Mailbox");
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.DebugException(sim, e);

                    IncStat("Cancel Fail");
                }

                sim.InteractionQueue.RemoveGoHomeInteractions(true);

                return(true);
            }
        }