Beispiel #1
0
        public static Vector3 AttemptToFindSafeLocation(Lot lot, bool isHorse)
        {
            if (lot == null)
            {
                return(Vector3.Invalid);
            }

            if (isHorse)
            {
                Mailbox mailbox = lot.FindMailbox();
                if (mailbox != null)
                {
                    return(mailbox.Position);
                }
                else
                {
                    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)
                            {
                                return(RandomUtil.GetRandomObjectFromList(objects).Position);
                            }
                        }
                    }
                }
            }

            return(lot.EntryPoint());
        }
Beispiel #2
0
        public static Vector3 AttemptToFindSafeLocation(Lot lot, bool isHorse)
        {
            if (lot == null) return Vector3.Invalid;

            if (isHorse)
            {
                Mailbox mailbox = lot.FindMailbox();
                if (mailbox != null)
                {
                    return mailbox.Position;
                }
                else
                {
                    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)
                            {
                                return RandomUtil.GetRandomObjectFromList(objects).Position;
                            }
                        }
                    }
                }
            }

            return lot.EntryPoint();
        }
Beispiel #3
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
         }
     }
 }