Ejemplo n.º 1
0
        public static bool EnsureInstantiate(SimDescription sim, Lot lot)
        {
            if (sim.CreatedSim == null)
            {
                if (sim.Household == null)
                {
                    if (!sim.IsValidDescription)
                    {
                        sim.Fixup();
                    }

                    Urnstone urnstone = Urnstones.CreateGrave(sim, SimDescription.DeathType.OldAge, false, true);
                    if (urnstone != null)
                    {
                        Common.Sleep();

                        if (!Urnstones.GhostSpawn(urnstone, lot))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    Instantiation.Perform(sim, null);
                }
            }

            return(sim.CreatedSim != null);
        }
Ejemplo n.º 2
0
        public static bool GhostToSim(SimDescription me)
        {
            Urnstone stone = Urnstones.FindGhostsGrave(me);

            if (stone != null)
            {
                if (me.CreatedSim != null)
                {
                    stone.GhostToSim(me.CreatedSim, false, false);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public AddSims(Household house, IEnumerable <IMiniSimDescription> miniSims, bool overStuff, bool transferFunds, bool dreamCatcher)
        {
            mOldMembers = new List <SimDescription>(CommonSpace.Helpers.Households.All(house));

            foreach (IMiniSimDescription iMiniSim in new List <IMiniSimDescription>(miniSims))
            {
                if (overStuff)
                {
                    if (iMiniSim.IsHuman)
                    {
                        if (CommonSpace.Helpers.Households.NumHumansIncludingPregnancy(house) >= 8)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (CommonSpace.Helpers.Households.NumPetsIncludingPregnancy(house) >= 6)
                        {
                            continue;
                        }
                    }
                }

                MiniSimDescription miniSim = null;

                bool lastActiveSim = false;

                SimDescription sim = iMiniSim as SimDescription;
                if (sim == null)
                {
                    miniSim = iMiniSim as MiniSimDescription;
                    if (miniSim == null)
                    {
                        continue;
                    }

                    sim = MiniSims.UnpackSimAndUpdateRel(miniSim);
                    if (sim == null)
                    {
                        continue;
                    }
                }
                else if (sim.CreatedSim == Sim.ActiveActor)
                {
                    if (Households.NumSims(sim.Household) == 1)
                    {
                        lastActiveSim = true;
                    }
                    else
                    {
                        LotManager.SelectNextSim();
                    }
                }

                Household oldHouse = sim.Household;
                if (oldHouse != null)
                {
                    if (oldHouse == Household.ActiveHousehold)
                    {
                        Household.RoommateManager.RemoveRoommateInternal(sim);
                    }

                    if ((transferFunds) && (oldHouse.NumMembers == 1))
                    {
                        int funds = oldHouse.FamilyFunds;

                        if (oldHouse.LotHome != null)
                        {
                            funds += oldHouse.LotHome.Cost;
                        }

                        house.ModifyFamilyFunds(funds);

                        Households.TransferData(house, oldHouse);
                    }

                    house.AddWardrobeToWardrobe(oldHouse.Wardrobe);
                    house.AddServiceUniforms(oldHouse.mServiceUniforms);

                    oldHouse.Remove(sim, !oldHouse.IsSpecialHousehold);

                    if (PetAdoption.sNeighborAdoption != null)
                    {
                        PetAdoption.sNeighborAdoption.mPetsToAdopt.Remove(sim);
                    }

                    if (sim.CreatedSim != null)
                    {
                        oldHouse.GetCaregiverRoutingMonitor(sim.CreatedSim.LotCurrent, true);
                    }
                }

                if ((oldHouse != null) && (!mOldHouses.ContainsKey(oldHouse)))
                {
                    mOldHouses.Add(oldHouse, true);
                }

                mNewMembers.Add(sim);

                if (house.Name == null)
                {
                    house.Name = sim.LastName;
                }

                if ((sim.IsDead) && (!sim.IsPlayableGhost))
                {
                    Urnstone grave = Urnstones.CreateGrave(sim, false);
                    if (grave != null)
                    {
                        Urnstones.GhostToPlayableGhost(grave, house, house.LotHome.EntryPoint());
                    }
                }
                else
                {
                    // Must be performed or the Household:Add() will bounce
                    if (!sim.IsValidDescription)
                    {
                        sim.Fixup();
                    }

                    MiniSims.ProtectedAddHousehold(house, sim);

                    if (sim.IsPet)
                    {
                        foreach (PetPoolType type in Enum.GetValues(typeof(PetPoolType)))
                        {
                            if (PetPoolManager.IsPetInPoolType(sim, type))
                            {
                                PetPoolManager.RemovePet(type, sim, true);
                            }
                        }
                    }

                    if ((CarNpcManager.Singleton != null) && (CarNpcManager.Singleton.NpcDriversManager != null))
                    {
                        if (CarNpcManager.Singleton.NpcDriversManager.mDescPools != null)
                        {
                            for (int i = 0; i < CarNpcManager.Singleton.NpcDriversManager.mDescPools.Length; i++)
                            {
                                Stack <SimDescription> stack = CarNpcManager.Singleton.NpcDriversManager.mDescPools[i];
                                if (stack == null)
                                {
                                    continue;
                                }

                                List <SimDescription> list = new List <SimDescription>();

                                foreach (SimDescription stackSim in stack)
                                {
                                    if (stackSim == sim)
                                    {
                                        while (stack.Count > 0)
                                        {
                                            list.Add(stack.Pop());
                                        }

                                        list.Remove(sim);

                                        for (int j = list.Count - 1; j >= 0; j--)
                                        {
                                            stack.Push(list[j]);
                                        }
                                    }
                                }
                            }
                        }

                        if ((sim.CreatedSim != null) && (CarNpcManager.Singleton.NpcDriversManager.mNpcDrivers != null))
                        {
                            CarNpcManager.Singleton.NpcDriversManager.mNpcDrivers.Remove(sim.CreatedSim);
                        }
                    }
                }

                if (house.LotHome != null)
                {
                    Instantiation.EnsureInstantiate(sim, house.LotHome);
                }

                if (miniSim != null)
                {
                    (Sims3.Gameplay.UI.Responder.Instance.HudModel as HudModel).OnSimCurrentWorldChanged(true, miniSim);

                    AgingManager.Singleton.AddSimDescription(sim);

                    sim.AgingState.MergeTravelInformation(miniSim);

                    sim.SetFlags(SimDescription.FlagField.AgingEnabled, true);
                }

                try
                {
                    if (sim.Service != null)
                    {
                        sim.Service.EndService(sim);
                    }

                    if (sim.CreatedSim != null)
                    {
                        sim.CreatedSim.BuffManager.RemoveElement(BuffNames.StrayPet);

                        DreamCatcher.AdjustSelectable(sim, sim.Household == Household.ActiveHousehold, dreamCatcher);

                        sim.CreatedSim.SetObjectToReset();

                        sim.CreatedSim.Motives.RecreateMotives(sim.CreatedSim);

                        Sim.MakeSimGoHome(sim.CreatedSim, false);

                        if (lastActiveSim)
                        {
                            PlumbBob.DoSelectActor(sim.CreatedSim, false);
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.DebugException(sim, e);
                }
            }
        }
Ejemplo n.º 4
0
        public static bool Dispose(SimDescription sim, Logger log)
        {
            if (sim == null)
            {
                return(false);
            }

            Genealogy oldGene = sim.Genealogy;

            if (sim.CelebrityManager == null)
            {
                // If missing, the Dispose() fires a script error
                sim.CelebrityManager = new Sims3.Gameplay.CelebritySystem.CelebrityManager();
            }

            try
            {
                if (sim.Genealogy == null)
                {
                    MiniSimDescription miniSim = MiniSimDescription.Find(sim.SimDescriptionId);
                    if (miniSim != null)
                    {
                        sim.mGenealogy = miniSim.Genealogy;
                    }

                    if (sim.Genealogy == null)
                    {
                        sim.mGenealogy = new Genealogy(sim);
                    }
                }

                Urnstone stone = Urnstones.FindGhostsGrave(sim);
                if (stone != null)
                {
                    Inventory inventory = Inventories.ParentInventory(stone);
                    if (inventory != null)
                    {
                        inventory.RemoveByForce(stone);
                    }

                    try
                    {
                        stone.Dispose();
                        stone.Destroy();
                    }
                    catch (Exception e)
                    {
                        Common.Exception(sim, e);

                        if (inventory != null)
                        {
                            inventory.TryToAdd(stone, false);
                        }
                    }
                }
                else
                {
                    sim.Dispose(true, false, true);
                }

                if (log != null)
                {
                    log(" Disposed: " + sim.FullName);
                }

                return(true);
            }
            catch (Exception e)
            {
                Common.Exception(sim, e);
                return(false);
            }
            finally
            {
                // Reassign the genealogy, to compensate for an issue where the miniSim is reprocessed later
                sim.mGenealogy = oldGene;
            }
        }
Ejemplo n.º 5
0
        public static bool Perform(SimDescription sim, bool cleanse)
        {
            if (sim == null)
            {
                return(false);
            }

            Common.StringBuilder msg = new Common.StringBuilder("Perform" + Common.NewLine);

            Household house = sim.Household;

            try
            {
                Sim createdSim = sim.CreatedSim;

                if (createdSim != null)
                {
                    createdSim.ReservedVehicle = null;
                }

                if (PetAdoption.sNeighborAdoption != null)
                {
                    if (PetAdoption.sNeighborAdoption.mMother == sim)
                    {
                        try
                        {
                            PetAdoption.ResetNeighborAdoption();
                        }
                        catch (Exception e)
                        {
                            Common.Exception(sim, e);
                        }
                        finally
                        {
                            PetAdoption.sNeighborAdoption = null;
                        }
                    }
                    else
                    {
                        PetAdoption.sNeighborAdoption.mPetsToAdopt.Remove(sim);
                    }
                }

                foreach (Service service in Services.AllServices)
                {
                    try
                    {
                        if (service == null)
                        {
                            continue;
                        }

                        msg += Common.NewLine + "Service: " + service.GetType();

                        if (sim.CreatedSim != null)
                        {
                            service.RemoveAssignment(sim.CreatedSim);
                        }

                        service.RemovePreferredSim(sim);

                        service.mPool.Remove(sim);

                        ResortWorker resortWorker = service as ResortWorker;
                        if (resortWorker != null)
                        {
                            if (resortWorker.mWorkerInfo != null)
                            {
                                List <ObjectGuid> remove = new List <ObjectGuid>();

                                foreach (KeyValuePair <ObjectGuid, ResortWorker.WorkerInfo> info in resortWorker.mWorkerInfo)
                                {
                                    if ((info.Value.CurrentSimDescriptionID == sim.SimDescriptionId) ||
                                        (info.Value.DesiredSimDescriptionID == sim.SimDescriptionId))
                                    {
                                        remove.Add(info.Key);
                                    }
                                }

                                foreach (ObjectGuid rem in remove)
                                {
                                    resortWorker.mWorkerInfo[rem] = new ResortWorker.WorkerInfo();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Common.Exception(sim, null, msg, e);
                    }
                }

                msg += Common.NewLine + "A";

                List <Household> houses = new List <Household>();
                if (house != null)
                {
                    houses.Add(house);
                }

                foreach (Household check in Household.sHouseholdList)
                {
                    if (check == house)
                    {
                        continue;
                    }

                    if (check.Contains(sim))
                    {
                        houses.Add(check);
                    }
                }

                foreach (Household remove in houses)
                {
                    Household.HouseholdSimsChangedCallback changedCallback = null;

                    try
                    {
                        changedCallback             = remove.HouseholdSimsChanged;
                        remove.HouseholdSimsChanged = null;

                        remove.Remove(sim, !remove.IsSpecialHousehold);
                    }
                    finally
                    {
                        remove.HouseholdSimsChanged = changedCallback;
                    }
                }

                msg += Common.NewLine + "B";

                try
                {
                    if (cleanse)
                    {
                        if (sim.LifeEventManager != null)
                        {
                            sim.LifeEventManager.Purge();
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.Exception(sim, null, msg, e);
                }

                msg += Common.NewLine + "C";

                RemoveSimDescriptionRelationships(sim);

                msg += Common.NewLine + "D";

                PetPoolManager.RemoveIdFromPool(sim.SimDescriptionId);

                msg += Common.NewLine + "E";

                try
                {
                    if (sim.CareerManager != null)
                    {
                        sim.CareerManager.LeaveAllJobs(Career.LeaveJobReason.kDied);
                    }
                }
                catch (Exception e)
                {
                    sim.CareerManager.mJob    = null;
                    sim.CareerManager.mSchool = null;

                    Common.Exception(sim, null, msg, e);
                }

                msg += Common.NewLine + "F";

                if (sim.CASGenealogy == null)
                {
                    // Necessary to stop an error in MidLifeCrisisManager
                    sim.mGenealogy = new Genealogy(sim);
                }

                msg += Common.NewLine + "G";

                try
                {
                    if (sim.Partner != null)
                    {
                        sim.Partner.Partner = null;
                    }

                    sim.Partner = null;
                }
                catch (Exception e)
                {
                    Common.Exception(sim, null, msg, e);
                }

                msg += Common.NewLine + "H";

                if (sim.DeathStyle != SimDescription.DeathType.None)
                {
                    // Passing in a household can invoke the social worker, so don't bother
                    Urnstone.FinalizeSimDeath(sim, null /*house*/);
                }

                msg += Common.NewLine + "I";

                Urnstone urnstone = Urnstones.FindGhostsGrave(sim);

                msg += Common.NewLine + "J";

                if ((cleanse) && (urnstone != null))
                {
                    if (urnstone.InInventory)
                    {
                        Inventory inventory = Inventories.ParentInventory(urnstone);
                        if (inventory != null)
                        {
                            inventory.RemoveByForce(urnstone);
                        }
                    }

                    if (urnstone.DeadSimsDescription != null)
                    {
                        urnstone.DeadSimsDescription.Fixup();
                    }

                    try
                    {
                        urnstone.Dispose();
                    }
                    catch (Exception e)
                    {
                        Common.DebugException(sim, null, msg, e);
                    }

                    urnstone.Destroy();
                }

                msg += Common.NewLine + "K";

                if ((FakeMetaAutonomy.Instance != null) && (FakeMetaAutonomy.Instance.mPool != null))
                {
                    FakeMetaAutonomy.Instance.mPool.Remove(sim);
                }

                msg += Common.NewLine + "L";

                if (Sims3.Gameplay.Services.FakeMetaAutonomy.mToDestroy != null)
                {
                    Sims3.Gameplay.Services.FakeMetaAutonomy.mToDestroy.Remove(sim);
                }

                msg += Common.NewLine + "M";

                if ((houses.Contains(Household.ActiveHousehold)) && (sim.CreatedSim != null))
                {
                    HudModel model = HudController.Instance.Model as HudModel;

                    foreach (SimInfo info in model.mSimList)
                    {
                        if (info.mGuid == sim.CreatedSim.ObjectId)
                        {
                            model.RemoveSimInfo(info);
                            model.mSimList.Remove(info);
                            break;
                        }
                    }
                }

                msg += Common.NewLine + "N";

                try
                {
                    if (sim.AssignedRole != null)
                    {
                        sim.AssignedRole.RemoveSimFromRole();
                    }
                }
                catch (Exception e)
                {
                    Common.DebugException(sim, null, msg, e);

                    sim.AssignedRole = null;
                }

                msg += Common.NewLine + "O1";

                if ((CarNpcManager.Singleton != null) && (CarNpcManager.Singleton.NpcDriversManager != null))
                {
                    foreach (Stack <SimDescription> stack in CarNpcManager.Singleton.NpcDriversManager.mDescPools)
                    {
                        if (stack == null)
                        {
                            continue;
                        }

                        List <SimDescription> sims = new List <SimDescription>();

                        bool found = false;
                        foreach (SimDescription stackSim in stack)
                        {
                            if (stackSim == sim)
                            {
                                found = true;
                            }
                            else
                            {
                                sims.Add(stackSim);
                            }
                        }

                        if (found)
                        {
                            stack.Clear();

                            foreach (SimDescription stackSim in sims)
                            {
                                stack.Push(stackSim);
                            }
                        }
                    }
                }

                msg += Common.NewLine + "O2";

                if (cleanse)
                {
                    sim.Dispose();
                }

                msg += Common.NewLine + "P";

                if ((house != null) && (createdSim != null))
                {
                    house.OnMemberChanged(sim, createdSim);
                }
                return(true);
            }
            catch (Exception e)
            {
                Common.Exception(sim, null, msg, e);

                if (house != null)
                {
                    Household.HouseholdSimsChangedCallback changedCallback = null;

                    try
                    {
                        changedCallback            = house.HouseholdSimsChanged;
                        house.HouseholdSimsChanged = null;

                        house.Add(sim);
                    }
                    finally
                    {
                        house.HouseholdSimsChanged = changedCallback;
                    }
                }
                return(false);
            }
        }