Beispiel #1
0
 public static void RecoverMissingSim(SimDescription sim, bool ignorePlaceholders)
 {
     try{
         if (!SimIsMissing(sim, ignorePlaceholders))
         {
             return;
         }
         if (sim.CreatedSim == null)
         {
             return;
         }
         StuckSimData stuckSim;
         if (!StuckSims.TryGetValue(sim.SimDescriptionId, out stuckSim))
         {
             stuckSim = new StuckSimData();
             StuckSims.Add(sim.SimDescriptionId, stuckSim);
         }
         if (!stuckSim.Resetting)
         {
             stuckSim.Detections++;
             Vector3 destination = Vector3.Invalid;
             if (sim.CreatedSim.RoutingComponent != null)
             {
                 sim.CreatedSim.RoutingComponent.GetDestination(out destination);
             }
             if (stuckSim.resetTask == null)
             {
                 stuckSim.resetTask = new ResetStuckSimTask(sim.CreatedSim, destination, "Missing");
             }
             else
             {
                 stuckSim.resetTask.Renew();
             }
         }
     }catch (Exception exception) {
         Alive.WriteLog(exception.Message + "\n\n" +
                        exception.StackTrace + "\n\n" +
                        exception.Source + "\n\n" +
                        "RecoverMissingSim");
     }finally{
     }
 }
Beispiel #2
0
        public static void   FixInvisibleSim(SimDescription sim, bool force = false, bool reset = false)
        {
            try{
                OutfitCategories[] categoriesArray = null;
                switch (sim.Species)
                {
                case CASAgeGenderFlags.Human:
                    categoriesArray = new OutfitCategories[] { OutfitCategories.Everyday,
                                                               OutfitCategories.Naked,
                                                               OutfitCategories.Athletic,
                                                               OutfitCategories.Formalwear,
                                                               OutfitCategories.Sleepwear,
                                                               OutfitCategories.Swimwear };
                    break;

                case CASAgeGenderFlags.Horse:
                    categoriesArray = new OutfitCategories[] { OutfitCategories.Everyday,
                                                               OutfitCategories.Naked,
                                                               OutfitCategories.Racing,
                                                               OutfitCategories.Bridle,
                                                               OutfitCategories.Jumping };
                    break;

                default:
                    categoriesArray = new OutfitCategories[] { OutfitCategories.Everyday,
                                                               OutfitCategories.Naked };
                    break;
                }
                bool necessary = force;
                if (!necessary)
                {
                    foreach (OutfitCategories category in categoriesArray)
                    {
                        if (sim.IsHuman)
                        {
                            if (category == OutfitCategories.Naked)
                            {
                                continue;
                            }
                        }
                        SimOutfit outfit2 = sim.GetOutfit(category, 0);
                        if ((outfit2 == null) || (!outfit2.IsValid))
                        {
                            necessary = true;
                        }
                    }
                }
                if (!necessary)
                {
                    return;
                }
                SimOutfit sourceOutfit = null;
                for (int i = 0; i < 2; i++)
                {
                    OutfitCategoryMap map = null;
                    if (i == 0)
                    {
                        map = sim.mOutfits;
                    }
                    else
                    {
                        map = sim.mMaternityOutfits;
                    }
                    if (map == null)
                    {
                        continue;
                    }
                    foreach (OutfitCategories category in Enum.GetValues(typeof(OutfitCategories)))
                    {
                        if (category == OutfitCategories.Supernatural)
                        {
                            continue;
                        }
                        ArrayList outfits = map[category] as ArrayList;
                        if (outfits == null)
                        {
                            continue;
                        }
                        foreach (SimOutfit anyOutfit in outfits)
                        {
                            if ((anyOutfit != null) && (anyOutfit.IsValid))
                            {
                                sourceOutfit = anyOutfit;
                                break;
                            }
                        }
                    }
                }
                SimBuilder builder = new SimBuilder();
                builder.UseCompression = true;
                var simTone = sim.SkinToneKey;
                List <ResourceKey> choiceTones = new List <ResourceKey>();
                KeySearch          tones       = new KeySearch(0x0354796a);
                foreach (ResourceKey tone in tones)
                {
                    choiceTones.Add(tone);
                }
                tones.Reset();
                if ((simTone.InstanceId == 0) || (!choiceTones.Contains(simTone)))
                {
                    simTone = RandomUtil.GetRandomObjectFromList(choiceTones);
                }
                ResourceKey newTone = simTone;

                builder.Age           = sim.Age;
                builder.Gender        = sim.Gender;
                builder.Species       = sim.Species;
                builder.SkinTone      = newTone;
                builder.SkinToneIndex = sim.SkinToneIndex;
                builder.MorphFat      = sim.mCurrentShape.Fat;
                builder.MorphFit      = sim.mCurrentShape.Fit;
                builder.MorphThin     = sim.mCurrentShape.Thin;
                GeneticsPet.SpeciesSpecificData speciesData = OutfitUtils.GetSpeciesSpecificData(sim);
                try{
                    if (sourceOutfit != null)
                    {
                        foreach (SimOutfit.BlendInfo blend in sourceOutfit.Blends)
                        {
                            builder.SetFacialBlend(blend.key, blend.amount);
                        }
                        CASParts.OutfitBuilder.CopyGeneticParts(builder, sourceOutfit);
                    }
                    else
                    {
                        if (sim.Genealogy != null)
                        {
                            List <SimDescription> parents      = new List <SimDescription>();
                            List <SimDescription> grandParents = new List <SimDescription>();
                            if (sim.Genealogy.Parents != null)
                            {
                                foreach (Genealogy gene in sim.Genealogy.Parents)
                                {
                                    SimDescription relative = gene.SimDescription;
                                    if (relative == null)
                                    {
                                        continue;
                                    }
                                    parents.Add(relative);
                                    if (relative.Genealogy != null)
                                    {
                                        if (relative.Genealogy.Parents != null)
                                        {
                                            foreach (Genealogy grandGene in relative.Genealogy.Parents)
                                            {
                                                var grandRelative = grandGene.SimDescription;
                                                if (grandRelative == null)
                                                {
                                                    continue;
                                                }
                                                grandParents.Add(grandRelative);
                                            }
                                        }
                                    }
                                }
                            }
                            if (parents.Count > 0)
                            {
                                if (sim.IsHuman)
                                {
                                    Genetics.InheritFacialBlends(builder, parents.ToArray(), new Random());
                                }
                                else
                                {
                                    GeneticsPet.InheritBodyShape(builder, parents, grandParents, new Random());
                                    GeneticsPet.InheritBasePeltLayer(builder, parents, grandParents, new Random());
                                    GeneticsPet.InheritPeltLayers(builder, parents, grandParents, new Random());
                                }
                            }
                        }
                    }
                }catch (Exception exception) {
                    Alive.WriteLog(exception.Message + "\n\n" +
                                   exception.StackTrace + "\n\n" +
                                   exception.Source);
                }
                if (sim.IsRobot)
                {
                    OutfitUtils.AddMissingPartsBots(builder, (OutfitCategories)0x200002, true, sim);
                    Sleep();
                    OutfitUtils.AddMissingPartsBots(builder, OutfitCategories.Everyday, true, sim);
                    Sleep();
                }
                else
                if (sim.IsHuman)
                {
                    OutfitUtils.AddMissingParts(builder, (OutfitCategories)0x200002, true, sim, sim.IsAlien);
                    Sleep();
                    OutfitUtils.AddMissingParts(builder, OutfitCategories.Everyday, true, sim, sim.IsAlien);
                    Sleep();
                }
                else
                {
                    OutfitUtils.AddMissingPartsPet(builder, OutfitCategories.Everyday | (OutfitCategories)0x200000, true, sim, speciesData);
                    Sleep();
                    OutfitUtils.AddMissingPartsPet(builder, OutfitCategories.Everyday, true, sim, speciesData);
                    Sleep();
                }
                ResourceKey uniformKey = new ResourceKey();
                if (sim.IsHuman)
                {
                    if (LocaleConstraints.GetUniform(ref uniformKey, sim.HomeWorld, builder.Age, builder.Gender, OutfitCategories.Everyday))
                    {
                        OutfitUtils.SetOutfit(builder, new SimOutfit(uniformKey), sim);
                    }
                }
                OutfitUtils.SetAutomaticModifiers(builder);
                sim.ClearOutfits(OutfitCategories.Career, false);
                sim.ClearOutfits(OutfitCategories.MartialArts, false);
                sim.ClearOutfits(OutfitCategories.Special, false);
                foreach (OutfitCategories category in categoriesArray)
                {
                    ArrayList outfits = null;
                    if (!force)
                    {
                        outfits = sim.Outfits[category] as ArrayList;
                        if (outfits != null)
                        {
                            int index = 0;
                            while (index < outfits.Count)
                            {
                                SimOutfit anyOutfit = outfits[index] as SimOutfit;
                                if (anyOutfit == null)
                                {
                                    outfits.RemoveAt(index);
                                }
                                else
                                if (!anyOutfit.IsValid)
                                {
                                    outfits.RemoveAt(index);
                                }
                                else
                                {
                                    index++;
                                }
                            }
                        }
                    }

                    if ((outfits == null) || (outfits.Count == 0))
                    {
                        OutfitUtils.MakeCategoryAppropriate(builder, category, sim);
                        if (sim.IsHuman)
                        {
                            if (LocaleConstraints.GetUniform(ref uniformKey, sim.HomeWorld, builder.Age, builder.Gender, category))
                            {
                                OutfitUtils.SetOutfit(builder, new SimOutfit(uniformKey), sim);
                            }
                        }
                        sim.RemoveOutfits(category, false);
                        CASParts.AddOutfit(sim, category, builder, true);
                    }
                    if (sim.IsUsingMaternityOutfits)
                    {
                        sim.BuildPregnantOutfit(category);
                    }
                }
                if (sim.IsMummy)
                {
                    OccultMummy
                    .OnMerge(sim);
                }
                else
                if (sim.IsFrankenstein)
                {
                    OccultFrankenstein
                    .OnMerge(sim, sim.OccultManager.mIsLifetimeReward);
                }
                else
                if (sim.IsGenie)
                {
                    OccultGenie
                    .OverlayUniform(sim, OccultGenie.CreateUniformName(sim.Age, sim.Gender), ProductVersion.EP6, OutfitCategories.Everyday, CASSkinTones.BlueSkinTone, 0.68f);
                }
                else
                if (sim.IsImaginaryFriend)
                {
                    OccultImaginaryFriend friend = sim.OccultManager.GetOccultType(Sims3.UI.Hud.OccultTypes.ImaginaryFriend) as OccultImaginaryFriend;
                    OccultBaseClass
                    .OverlayUniform(sim, OccultImaginaryFriend.CreateUniformName(sim.Age, friend.Pattern), ProductVersion.EP4, OutfitCategories.Special, CASSkinTones.NoSkinTone, 0f);
                }
                if (sim.IsMermaid)
                {
                    OccultMermaid
                    .AddOutfits(sim, null);
                }
                if (sim.IsWerewolf)
                {
                    if (sim.ChildOrAbove)
                    {
                        SimOutfit newWerewolfOutfit =
                            OccultWerewolf
                            .GetNewWerewolfOutfit(sim.Age, sim.Gender);
                        if (newWerewolfOutfit != null)
                        {
                            sim.AddOutfit(newWerewolfOutfit, OutfitCategories.Supernatural, 0x0);
                        }
                    }
                }
                SimOutfit currentOutfit = null;
                if (sim.CreatedSim != null)
                {
                    if (reset)
                    {
                        StuckSimData stuckSim;
                        if (!StuckSims.TryGetValue(sim.SimDescriptionId, out stuckSim))
                        {
                            stuckSim = new StuckSimData();
                            StuckSims.Add(sim.SimDescriptionId, stuckSim);
                        }
                        if (!stuckSim.Resetting)
                        {
                            stuckSim.Detections++;
                            Vector3 destination = Vector3.Invalid;
                            if (sim.CreatedSim.RoutingComponent != null)
                            {
                                sim.CreatedSim.RoutingComponent.GetDestination(out destination);
                            }
                            if (stuckSim.resetTask == null)
                            {
                                stuckSim.resetTask = new ResetStuckSimTask(sim.CreatedSim, destination, "Invisible");
                            }
                            else
                            {
                                stuckSim.resetTask.Renew();
                            }
                        }
                    }
                    try{
                        sim.CreatedSim.SwitchToOutfitWithoutSpin(Sim.ClothesChangeReason.GoingOutside, OutfitCategories.Everyday, true);
                    }catch (Exception exception) {
                        Alive.WriteLog(exception.Message + "\n\n" +
                                       exception.StackTrace + "\n\n" +
                                       exception.Source);
                    }
                    currentOutfit = sim.CreatedSim.CurrentOutfit;
                }
                else
                {
                    currentOutfit = sim.GetOutfit(OutfitCategories.Everyday, 0);
                }
                if (currentOutfit != null)
                {
                    ThumbnailManager.GenerateHouseholdSimThumbnail(currentOutfit.Key, currentOutfit.Key.InstanceId, 0x0, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium | ThumbnailSizeMask.Small, ThumbnailTechnique.Default, true, false, sim.AgeGenderSpecies);
                }
            }catch (Exception exception) {
                Alive.WriteLog(exception.Message + "\n\n" +
                               exception.StackTrace + "\n\n" +
                               exception.Source + "\n\n" +
                               "FixInvisibleSim");
            }finally{
            }
        }
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
         }
     }
 }