public static Urnstone CreateGrave(SimDescription me, SimDescription.DeathType deathType, bool ignoreExisting, bool report) { Urnstone urnstone = FindGhostsGrave(me); if ((urnstone != null) && (!ignoreExisting)) { if ((urnstone.InInventory) || (urnstone.InWorld)) { return(urnstone); } } Household originalHousehold = me.Household; bool addOnly = false; if (urnstone == null) { urnstone = PrivateCreateGrave(me); if (urnstone == null) { return(null); } } else { addOnly = true; } bool success = MoveToMausoleum(urnstone); if (!success) { if (me.CreatedSim != null) { if (Inventories.TryToMove(urnstone, me.CreatedSim.Inventory)) { success = true; } } if ((!success) && (Sim.ActiveActor != null)) { if (Inventories.TryToMove(urnstone, Sim.ActiveActor.Inventory)) { success = true; } } if (!success) { return(null); } } if (report) { Common.Notify(Common.Localize("ForceKill:Success", me.IsFemale, new object[] { me })); } if ((addOnly) && (!ignoreExisting)) { return(urnstone); } if ((originalHousehold == Household.ActiveHousehold) && (me.CreatedSim != null)) { HudModel model = HudController.Instance.Model as HudModel; foreach (SimInfo info in model.mSimList) { if (info.mGuid == me.CreatedSim.ObjectId) { model.RemoveSimInfo(info); model.mSimList.Remove(info); break; } } } if (me.CreatedSim != null) { me.CreatedSim.Destroy(); } if (originalHousehold != null) { originalHousehold.Remove(me, !originalHousehold.IsSpecialHousehold); } if (me.DeathStyle == SimDescription.DeathType.None) { if (me.IsHuman) { switch (deathType) { case SimDescription.DeathType.None: case SimDescription.DeathType.PetOldAgeBad: case SimDescription.DeathType.PetOldAgeGood: deathType = SimDescription.DeathType.OldAge; break; } } else { switch (deathType) { case SimDescription.DeathType.None: case SimDescription.DeathType.OldAge: deathType = SimDescription.DeathType.PetOldAgeGood; break; } } me.SetDeathStyle(deathType, true); } me.IsNeverSelectable = true; me.Contactable = false; me.Marryable = false; if (me.CreatedSim == PlumbBob.SelectedActor) { LotManager.SelectNextSim(); } if (me.CareerManager != null) { me.CareerManager.LeaveAllJobs(Sims3.Gameplay.Careers.Career.LeaveJobReason.kDied); } urnstone.OnHandToolMovement(); Urnstone.FinalizeSimDeath(me, originalHousehold); int num = ((int)Math.Floor((double)SimClock.ConvertFromTicks(SimClock.CurrentTime().Ticks, TimeUnit.Minutes))) % 60; urnstone.MinuteOfDeath = num; return(urnstone); }
// Lacks the "greater than eight" restriction public static bool GhostToPlayableGhost(Urnstone ths, Household newHousehold, Vector3 ghostPosition) { SimDescription simDescription = ths.DeadSimsDescription; if (!simDescription.IsValidDescription) { simDescription.Fixup(); } if (simDescription.Household != null) { simDescription.Household.Remove(simDescription, !simDescription.Household.IsSpecialHousehold); } if (!newHousehold.Contains(simDescription)) { newHousehold.Add(simDescription); } Sim ghost = Instantiation.Perform(simDescription, ghostPosition, null, null); if (ghost == null) { return(false); } ths.GhostSetup(ghost, true); ths.RemoveMourningRelatedBuffs(ghost); simDescription.ShowSocialsOnSim = true; simDescription.IsNeverSelectable = false; simDescription.Marryable = true; simDescription.Contactable = true; if (!simDescription.IsEP11Bot) { simDescription.AgingEnabled = true; simDescription.AgingState.ResetAndExtendAgingStage(0f); simDescription.PushAgingEnabledToAgingManager(); } string failureReason; if (!Inventories.TryToMove(ths, ghost.Inventory, true, out failureReason)) { Common.DebugNotify(failureReason); } //Inventories.TryToMove(ths, ghost); if (simDescription.Child || simDescription.Teen) { simDescription.AssignSchool(); } if (ghost.IsSelectable) { ghost.OnBecameSelectable(); } return(true); }
public static Vehicle GetOwnedAndUsableVehicle(Sim ths, Lot lot, bool bAddPending, bool bAllowBikes, bool bIgnoreCanDrive, bool allowUFO) { if (ths.IsPet) { return(null); } Vehicle vehicleForCurrentInteraction = ths.GetVehicleForCurrentInteraction(); if (vehicleForCurrentInteraction != null) { return(vehicleForCurrentInteraction); } /* * if (GameUtils.IsInstalled(ProductVersion.EP2)) * { * ActiveFireFighter occupation = ths.Occupation as ActiveFireFighter; * if (occupation != null) * { * Car vehicle = occupation.GetVehicle(bAddPending); * if (vehicle != null) * { * return vehicle; * } * } * } */ Vehicle reservedVehicle = ths.GetReservedVehicle(); if ((reservedVehicle != null) && (bAllowBikes || (!(reservedVehicle is Bicycle) && !(reservedVehicle is MagicBroom)))) { IOwnableVehicle vehicle3 = reservedVehicle as IOwnableVehicle; if (vehicle3 == null) { return(reservedVehicle); } if (ths.CanUseVehicleRightNow(vehicle3, true, true)) { if (bAddPending) { vehicle3.PendingUse = true; } return(reservedVehicle); } } /* * if (ths.OccupationAsPerformanceCareer != null) * { * Car car2 = ths.OccupationAsPerformanceCareer.GetCareerCar(); * if (car2 != null) * { * return car2; * } * } * else if (ths.CareerManager.OccupationAsCareer != null) * { * FortuneTellerCareer career = ths.CareerManager.Occupation as FortuneTellerCareer; * if (((career != null) && (career.CurLevelBranchName == "ScamArtist")) && (career.Level >= FortuneTellerCareer.kLevelNeededForLimoRide)) * { * Car car3 = GlobalFunctions.CreateObjectOutOfWorld("CarLimo") as Car; * car3.DestroyOnRelease = true; * return car3; * } * } */ IOwnableVehicle preferredVehicle = ths.GetPreferredVehicle(); if (ths.CanUseVehicleRightNow(preferredVehicle, true, bIgnoreCanDrive) && (bAllowBikes || (!(reservedVehicle is Bicycle) && !(reservedVehicle is MagicBroom)))) { if (bAddPending) { preferredVehicle.PendingUse = true; } return(preferredVehicle as Vehicle); } if (bAllowBikes && ths.HasTrait(TraitNames.Rebellious)) { IOwnableVehicle motorcycleIfAvailable = ths.GetMotorcycleIfAvailable(bAddPending, bIgnoreCanDrive); if (motorcycleIfAvailable != null) { return(motorcycleIfAvailable as Vehicle); } } if (bAllowBikes && ths.HasTrait(TraitNames.EnvironmentallyConscious)) { IOwnableVehicle bikeIfAvailable = ths.GetBikeIfAvailable(bAddPending, bIgnoreCanDrive); if (bikeIfAvailable != null) { return(bikeIfAvailable as Vehicle); } } // Custom List <IOwnableVehicle> vehicles = Inventories.QuickDuoFind <IOwnableVehicle, Vehicle>(ths.Inventory); IOwnableVehicle vehicle = ths.GetBroomOrMostExpensiveUsableVehicle(vehicles, bAllowBikes, bAddPending, bIgnoreCanDrive, allowUFO, false); if (vehicle != null) { return(vehicle as Vehicle); } vehicles.Clear(); vehicle = ths.GetMostExpensiveUsableParkedVehicle(lot, bAllowBikes, bAddPending, bIgnoreCanDrive, allowUFO); if (vehicle != null) { return(vehicle as Vehicle); } if (lot != ths.LotHome) { vehicle = ths.GetMostExpensiveUsableParkedVehicle(ths.LotHome, bAllowBikes, bAddPending, bIgnoreCanDrive, allowUFO); if (vehicle != null) { return(vehicle as Vehicle); } } /* * Car careerCar = ths.GetCareerCar(); * if (careerCar != null) * { * IOwnableVehicle vehicle8 = careerCar as IOwnableVehicle; * if (bAddPending && (vehicle8 != null)) * { * vehicle8.PendingUse = true; * } * return careerCar; * } */ return(null); }
protected static void Cleanup1 <TConsigned>(Logger log, string prefix, int maximumAge, ref Dictionary <ulong, List <TConsigned> > list) where TConsigned : ICancelSellableUIItem, ISellableUIItem, IShopItem { if (list == null) { list = new Dictionary <ulong, List <TConsigned> >(); if (log != null) { log(" " + prefix + ".sConsignedObjects Restarted"); } } List <ulong> remove = new List <ulong>(); foreach (KeyValuePair <ulong, List <TConsigned> > objects in list) { if ((objects.Value == null) || (objects.Value.Count == 0)) { remove.Add(objects.Key); } else { SimDescription owner = null; for (int i = objects.Value.Count - 1; i >= 0; i--) { TConsigned obj = objects.Value[i]; IGameObject consignedObj = null; int age = 0; if (obj is ConsignmentRegister.ConsignedObject) { ConsignmentRegister.ConsignedObject castObj = obj as ConsignmentRegister.ConsignedObject; consignedObj = castObj.Object; age = castObj.Age; } else if (obj is PotionShopConsignmentRegister.ConsignedObject) { PotionShopConsignmentRegister.ConsignedObject castObj = obj as PotionShopConsignmentRegister.ConsignedObject; consignedObj = castObj.Object; age = castObj.Age; } else if (obj is BotShopRegister.ConsignedObject) { BotShopRegister.ConsignedObject castObj = obj as BotShopRegister.ConsignedObject; consignedObj = castObj.Object; age = castObj.Age; } else if (obj is FruitVeggieStand.ConsignedObject) { FruitVeggieStand.ConsignedObject castObj = obj as FruitVeggieStand.ConsignedObject; consignedObj = castObj.Object; age = castObj.Age; } try { if ((age < 0) || (age >= maximumAge)) { if (owner == null) { owner = SimDescription.Find(objects.Key); } bool success = false; if (owner != null) { if (owner.CreatedSim != null) { success = Inventories.TryToMove(consignedObj, owner.CreatedSim); } if ((!success) && (owner.Household != null) && (owner.Household.SharedFamilyInventory != null)) { success = Inventories.TryToMove(consignedObj, owner.Household.SharedFamilyInventory.Inventory); } } if (!success) { consignedObj.Destroy(); if (log != null) { log(" Over Age Object deleted"); } } else { if (log != null) { log(" Over Age Object returned"); } } objects.Value.RemoveAt(i); } } catch (Exception e) { Common.Exception(consignedObj, e); } } } } foreach (ulong id in remove) { list.Remove(id); if (log != null) { log(" Removed: " + id); } } }
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; } }
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); } }
public static void CreateSimInventories(List <SimDescription> sims, HouseholdContents contents, List <ulong> indexMap) { List <Sim> newborns = new List <Sim>(); for (int i = 0x0; i < sims.Count; i++) { SimDescription description = sims[i]; // Custom Try/Catch try { if ((description != null) && (description.CreatedSim != null)) { int index = i; if (indexMap != null) { for (int j = 0x0; j < indexMap.Count; j++) { if (indexMap[j] == description.SimDescriptionId) { index = j; break; } } } ulong id = contents.Inventories[index]; if (id != 0x0L) { Diploma diploma = description.CreatedSim.Inventory.Find <Diploma>(); if ((diploma != null) && !description.CreatedSim.Inventory.TryToRemove(diploma)) { diploma = null; } IPhoneSmart smart = null; if (GameUtils.IsInstalled(ProductVersion.EP9)) { smart = description.CreatedSim.Inventory.Find <IPhoneSmart>(); if ((smart != null) && !description.CreatedSim.Inventory.TryToRemove(smart)) { smart = null; } } DownloadContent.ImportInventory(id, new InventoryProxy(description.CreatedSim.Inventory)); DownloadContent.DeleteInventory(id); if (diploma != null) { Inventories.TryToMove(diploma, description.CreatedSim.Inventory, false); } if (smart != null) { IPhoneCell cell = description.CreatedSim.Inventory.Find <IPhoneCell>(); if (cell != null) { cell.Destroy(); } description.CreatedSim.Inventory.TryToAdd(smart); } } else { if (description.Toddler) { newborns.Add(description.CreatedSim); } description.CreatedSim.AddInitialObjects(false); } } } catch (Exception e) { Common.Exception(description, e); } } // Custom Try/Catch try { OccultImaginaryFriend.DeliverDollToHousehold(newborns, true); } catch (Exception e) { Common.Exception("DeliverDollToHousehold", e); } }