Example #1
0
        public static Sim Perform(Sim sim, bool fadeOut)
        {
            if (sim == null)
            {
                return(null);
            }

            try
            {
                SimDescription simDesc = sim.SimDescription;

                if (Simulator.GetProxy(sim.ObjectId) == null)
                {
                    if (simDesc != null)
                    {
                        sim.Destroy();
                    }

                    //sim.mSimDescription = null;
                    return(null);
                }

                if (simDesc == null)
                {
                    sim.mSimDescription = new SimDescription();

                    sim.Destroy();
                    return(null);
                }

                if (sim.LotHome != null)
                {
                    simDesc.IsZombie = false;

                    if (simDesc.CreatedSim != sim)
                    {
                        sim.Destroy();

                        simDesc.CreatedSim = null;

                        return(null);
                    }
                    else
                    {
                        Bed     myBed     = null;
                        BedData myBedData = null;

                        foreach (Bed bed in sim.LotHome.GetObjects <Bed>())
                        {
                            myBedData = bed.GetPartOwnedBy(sim);
                            if (myBedData != null)
                            {
                                myBed = bed;
                                break;
                            }
                        }

                        ResetPosture(sim);

                        if (simDesc.TraitManager == null)
                        {
                            simDesc.mTraitManager = new TraitManager();
                        }

                        try
                        {
                            simDesc.Fixup();

                            Corrections.CleanupBrokenSkills(simDesc, null);

                            ResetCareer(simDesc);

                            simDesc.ClearSpecialFlags();

                            if (simDesc.Pregnancy == null)
                            {
                                try
                                {
                                    if (simDesc.mMaternityOutfits == null)
                                    {
                                        simDesc.mMaternityOutfits = new OutfitCategoryMap();
                                    }
                                    simDesc.SetPregnancy(0, false);

                                    simDesc.ClearMaternityOutfits();
                                }
                                catch (Exception e)
                                {
                                    Common.Exception(sim, null, "Pregnancy", e);
                                }
                            }

                            if (sim.CurrentCommodityInteractionMap == null)
                            {
                                try
                                {
                                    LotManager.PlaceObjectOnLot(sim, sim.ObjectId);

                                    if (sim.CurrentCommodityInteractionMap == null)
                                    {
                                        sim.ChangeCommodityInteractionMap(sim.LotHome.Map);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Common.Exception(sim, null, "ChangeCommodityInteractionMap", e);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Common.Exception(sim, null, "Fixup", e);
                        }

                        ResetSituations(sim);

                        CleanupSlots(sim);

                        ResetInventory(sim);

                        if (fadeOut)
                        {
                            bool active = (Sim.ActiveActor == sim);

                            if (sSimReset.Valid)
                            {
                                sSimReset.Invoke <bool>(new object[] { simDesc.SimDescriptionId });
                            }

                            ResetRouting(sim);

                            using (CreationProtection protection = new CreationProtection(simDesc, sim, false, true, false))
                            {
                                sim.Destroy();

                                Common.Sleep();

                                sim = FixInvisibleTask.InstantiateAtHome(simDesc, null);
                            }

                            if (sim != null)
                            {
                                if (active)
                                {
                                    try
                                    {
                                        foreach (Sim member in Households.AllSims(sim.Household))
                                        {
                                            if (member.CareerManager == null)
                                            {
                                                continue;
                                            }

                                            Occupation occupation = member.CareerManager.Occupation;
                                            if (occupation == null)
                                            {
                                                continue;
                                            }

                                            occupation.FormerBoss = null;
                                        }

                                        using (DreamCatcher.HouseholdStore store = new DreamCatcher.HouseholdStore(sim.Household, true))
                                        {
                                            PlumbBob.DoSelectActor(sim, true);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Common.Exception(sim, null, "DoSelectActor", e);
                                    }
                                }

                                if ((myBed != null) && (myBedData != null))
                                {
                                    if (!(myBed is BedMultiPart) || (myBed is BedMultiPart && ((sim.Partner != null) && (sim.Partner.CreatedSim != null))))
                                    {
                                        myBed.ClaimOwnership(sim, myBedData);
                                    }
                                    else
                                    {
                                        HandleDoubleBed(sim, myBed, myBedData);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (sim.Inventory == null)
                            {
                                sim.AddComponent <InventoryComponent>(new object[0x0]);
                            }

                            if (Instantiation.AttemptToPutInSafeLocation(sim, false))
                            {
                                ResetRouting(sim);

                                sim.SetObjectToReset();

                                // This is necessary to clear certain types of interactions
                                //   (it is also called in SetObjectToReset(), though doesn't always work there)
                                if (sim.InteractionQueue != null)
                                {
                                    sim.InteractionQueue.OnReset();
                                }
                            }
                        }

                        ResetSkillModifiers(simDesc);

                        ResetRole(sim);

                        if (simDesc.IsEnrolledInBoardingSchool())
                        {
                            simDesc.BoardingSchool.OnRemovedFromSchool();
                        }

                        MiniSimDescription miniSim = MiniSimDescription.Find(simDesc.SimDescriptionId);
                        if (miniSim != null)
                        {
                            miniSim.Instantiated = true;
                        }

                        UpdateInterface(sim);

                        return(sim);
                    }
                }
                else if (simDesc.Service is Butler)
                {
                    if (Instantiation.AttemptToPutInSafeLocation(sim, true))
                    {
                        sim.Motives.RecreateMotives(sim);
                        sim.SetObjectToReset();
                    }

                    return(sim);
                }
                else if (simDesc.IsImaginaryFriend)
                {
                    OccultImaginaryFriend friend;
                    if (OccultImaginaryFriend.TryGetOccultFromSim(sim, out friend))
                    {
                        if (Simulator.GetProxy(friend.mDollId) != null)
                        {
                            friend.TurnBackIntoDoll(OccultImaginaryFriend.Destination.Owner);

                            return(null);
                        }
                    }
                }
                else if (simDesc.IsBonehilda)
                {
                    foreach (BonehildaCoffin coffin in Sims3.Gameplay.Queries.GetObjects <BonehildaCoffin>())
                    {
                        if (coffin.mBonehilda == simDesc)
                        {
                            coffin.mBonehildaSim = null;
                            break;
                        }
                    }
                }

                if (fadeOut)
                {
                    sim.Destroy();
                }

                return(null);
            }
            catch (Exception exception)
            {
                Common.Exception(sim, exception);
                return(sim);
            }
        }