예제 #1
0
        protected override OptionResult Run(GameHitParameters <GameObject> parameters)
        {
            Lot lot = Porter.GetLot(parameters.mTarget);

            if (lot == null)
            {
                return(OptionResult.Failure);
            }

            List <SimDescription> selection = null;

            List <HouseholdItem> allHouses = new List <HouseholdItem>();

            foreach (Household house in Household.sHouseholdList)
            {
                allHouses.Add(new HouseholdItem(house, house == lot.Household));
            }

            string houseName = null;

            while (selection == null)
            {
                List <Household> houses = HouseholdSelection.Perform(lot.Household.Name, allHouses);
                if ((houses == null) || (houses.Count == 0))
                {
                    return(OptionResult.Failure);
                }

                houseName = houses[0].Name;

                selection = GetSimSelection(houses);
            }

            if ((selection == null) || (selection.Count == 0))
            {
                return(OptionResult.Failure);
            }

            Dictionary <Household, int> finalHouses = new Dictionary <Household, int>();

            int nextID = 1;

            foreach (SimDescription sim in selection)
            {
                if (sim.Household == null)
                {
                    continue;
                }

                if (sim.Household.IsServiceNpcHousehold)
                {
                    continue;
                }

                if (!finalHouses.ContainsKey(sim.Household))
                {
                    finalHouses.Add(sim.Household, nextID);
                    nextID++;
                }
            }

            string name = StringInputDialog.Show(Common.Localize("Title"), Common.Localize("Pack:NamePrompt", false, new object[] { finalHouses.Count, selection.Count }), houseName);

            if (string.IsNullOrEmpty(name))
            {
                return(OptionResult.Failure);
            }

            Household export = Household.Create();

            SpeedTrap.Sleep();

            foreach (Household house in finalHouses.Keys)
            {
                if (house.LotHome != null)
                {
                    export.SetFamilyFunds(export.FamilyFunds + house.FamilyFunds + house.LotHome.Cost);
                }
                else
                {
                    export.SetFamilyFunds(export.FamilyFunds + house.NetWorth());
                }
            }

            Dictionary <SimDescription, Household> saveHouses = new Dictionary <SimDescription, Household>();

            Dictionary <Sim, bool> resetDNP = new Dictionary <Sim, bool>();

            Dictionary <Household, bool> inventoried = new Dictionary <Household, bool>();

            foreach (SimDescription sim in selection)
            {
                if (sim.CreatedSim != null)
                {
                    sim.CreatedSim.SetReservedVehicle(null);

                    if (sim.CreatedSim.DreamsAndPromisesManager != null)
                    {
                        sim.CreatedSim.NullDnPManager();

                        if (!resetDNP.ContainsKey(sim.CreatedSim))
                        {
                            resetDNP.Add(sim.CreatedSim, true);
                        }
                    }

                    if ((sim.Household != null) && (!inventoried.ContainsKey(sim.Household)))
                    {
                        inventoried.Add(sim.Household, true);

                        if ((sim.Household.SharedFamilyInventory != null) &&
                            (sim.Household.SharedFamilyInventory.Inventory != null))
                        {
                            foreach (GameObject obj in Inventories.QuickFind <GameObject>(sim.Household.SharedFamilyInventory.Inventory))
                            {
                                if (Inventories.TryToMove(obj, sim.CreatedSim.Inventory, false))
                                {
                                    continue;
                                }

                                Inventories.TryToMove(obj.Clone(), export.SharedFamilyInventory.Inventory);
                            }
                        }

                        if ((sim.Household.SharedFridgeInventory != null) &&
                            (sim.Household.SharedFridgeInventory.Inventory != null))
                        {
                            foreach (GameObject obj in Inventories.QuickFind <GameObject>(sim.Household.SharedFridgeInventory.Inventory))
                            {
                                if (Inventories.TryToMove(obj, sim.CreatedSim.Inventory, false))
                                {
                                    continue;
                                }

                                Inventories.TryToMove(obj.Clone(), export.SharedFridgeInventory.Inventory);
                            }
                        }
                    }
                }

                int id = 0;
                if ((sim.Household != null) && (finalHouses.ContainsKey(sim.Household)))
                {
                    id = finalHouses[sim.Household];
                }
                else
                {
                    Urnstone grave = Urnstones.CreateGrave(sim, false);
                    if (grave == null)
                    {
                        continue;
                    }

                    SpeedTrap.Sleep();

                    bool success = false;
                    try
                    {
                        success = Urnstones.GhostToPlayableGhost(grave, Household.NpcHousehold, lot.EntryPoint());
                    }
                    catch (Exception exception)
                    {
                        Common.DebugException(grave.DeadSimsDescription, exception);
                    }

                    if (!success)
                    {
                        Porter.Notify(Common.Localize("Pack:SimFailure", sim.IsFemale, new object[] { sim }));

                        Porter.PlaceGraveTask.Perform(sim);
                        //export.SharedFamilyInventory.Inventory.TryToMove(grave);
                        continue;
                    }
                }

                HouseData data = new HouseData(id, sim);

                sim.mBio = data.ToString();

                saveHouses.Add(sim, sim.Household);

                sim.OnHouseholdChanged(export, false);

                export.mMembers.Add(sim, null);

                Porter.AddExport(sim);
            }

            string packageName = null;

            try
            {
                try
                {
                    ProgressDialog.Show(Responder.Instance.LocalizationModel.LocalizeString("Ui/Caption/Global:Processing", new object[0x0]), false);

                    if (export.mMembers.Count > 0)
                    {
                        export.Name = "NRaas.Porter:" + name;

                        ThumbnailHelper.CacheSimAtlasesForHousehold(export);
                        ThumbnailManager.GenerateHouseholdThumbnail(export.HouseholdId, export.HouseholdId, ThumbnailSizeMask.Large);

                        packageName = BinEx.ExportHousehold(Bin.Singleton, export, false);
                        if (packageName != null)
                        {
                            BinModel.Singleton.AddToExportBin(packageName);
                        }
                    }

                    foreach (Sim sim in resetDNP.Keys)
                    {
                        try
                        {
                            sim.ResetDnP();
                        }
                        catch (Exception e)
                        {
                            Common.DebugException(sim, e);
                        }
                    }

                    List <Urnstone> graves = Inventories.QuickFind <Urnstone>(export.SharedFamilyInventory.Inventory);

                    foreach (Urnstone grave in graves)
                    {
                        Porter.PlaceGraveTask.Perform(grave.DeadSimsDescription);
                    }

                    while (export.mMembers.Count > 0)
                    {
                        SimDescription sim = export.mMembers.SimDescriptionList[0];
                        if (sim != null)
                        {
                            sim.OnHouseholdChanged(saveHouses[sim], false);

                            if ((sim.Household == null) || (sim.Household.IsServiceNpcHousehold))
                            {
                                Porter.PlaceGraveTask.Perform(sim);
                            }
                        }

                        export.mMembers.RemoveAt(0);
                    }

                    export.Destroy();
                    export.Dispose();
                }
                finally
                {
                    ProgressDialog.Close();
                }
            }
            catch (ExecutionEngineException)
            {
                // Ignored
            }
            catch (Exception e)
            {
                Common.Exception(name, e);
                packageName = null;
            }

            if (packageName != null)
            {
                SimpleMessageDialog.Show(Common.Localize("Title"), Common.Localize("Pack:Success", false, new object[] { export.Name }));
            }
            else
            {
                SimpleMessageDialog.Show(Common.Localize("Title"), Common.Localize("Pack:Failure"));
            }

            return(OptionResult.SuccessClose);
        }
예제 #2
0
파일: BinEx.cs 프로젝트: yakoder/NRaas
        public static string ExportHousehold(Bin ths, Household household, bool includeLotContents, bool isMovingPacked)
        {
            try
            {
                string str = null;
                if (GameUtils.IsInstalled(ProductVersion.EP4))
                {
                    OccultImaginaryFriend.ForceHouseholdImaginaryFriendsBackToInventory(household);
                }

                foreach (Sim sim in household.AllActors)
                {
                    sim.SetObjectToReset();
                }

                Common.Sleep();

                if (includeLotContents)
                {
                    Lot lotHome = household.LotHome;
                    if (lotHome != null)
                    {
                        int num  = household.FamilyFunds;
                        int num2 = World.GetEmptyLotWorth(lotHome.LotId) + ((int)World.GetLotAdditionalPropertyValue(lotHome.LotId));
                        household.SetFamilyFunds(household.FamilyFunds + num2, false);
                        EditTownModel.SendObjectsToProperLot(lotHome);
                        ulong contentId = DownloadContent.StoreLotContents(lotHome, lotHome.LotId);
                        if (contentId != 0x0L)
                        {
                            ThumbnailHelper.GenerateLotThumbnailSet(lotHome.LotId, contentId, ThumbnailSizeMask.ExtraLarge);
                            ThumbnailHelper.GenerateLotThumbnail(lotHome.LotId, contentId, 0x0, ThumbnailSizeMask.Large | ThumbnailSizeMask.Medium);
                            ThumbnailSizeMask mask = ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium;
                            ThumbnailManager.GenerateHouseholdThumbnail(household.HouseholdId, contentId, mask);
                            ths.GenerateSimThumbnails(household, contentId, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge);
                            HouseholdContentsProxy contents = new HouseholdContentsProxy(household);
                            if (DownloadContent.StoreHouseholdContents(contents, contentId))
                            {
                                str = DownloadContent.ExportLotContentsToExportBin(contentId);
                            }
                            ThumbnailManager.InvalidateLotThumbnails(lotHome.LotId, contentId, ThumbnailSizeMask.ExtraLarge);
                            ThumbnailManager.InvalidateLotThumbnailsForGroup(lotHome.LotId, contentId, ThumbnailSizeMask.Medium, 0x0);
                            ThumbnailManager.InvalidateHouseholdThumbnail(household.HouseholdId, contentId, mask);
                            ths.InvalidateSimThumbnails(household, contentId);
                        }
                        household.SetFamilyFunds(num, false);
                    }
                    return(str);
                }

                int familyFunds     = household.FamilyFunds;
                int realEstateFunds = 0;
                if (household.RealEstateManager != null)
                {
                    foreach (IPropertyData data in household.RealEstateManager.AllProperties)
                    {
                        realEstateFunds += data.TotalValue;
                    }
                }
                if (household.LotHome != null)
                {
                    int lotWorth = 0;
                    if (isMovingPacked)
                    {
                        lotWorth = World.GetUnfurnishedLotWorth(household.LotHome.LotId) + realEstateFunds;
                    }
                    else
                    {
                        lotWorth = World.GetLotWorth(household.LotHome.LotId) + realEstateFunds;
                    }

                    household.SetFamilyFunds(household.FamilyFunds + lotWorth, false);
                }

                if (household.FamilyFunds < 0x4e20)
                {
                    household.SetFamilyFunds(0x4e20, false);
                }

                ulong cacheId = DownloadContent.GenerateGUID();
                HouseholdContentsProxy householdContents = new HouseholdContentsProxy(household);
                householdContents.Contents.ContentId = cacheId;
                ThumbnailSizeMask sizeMask = ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium;
                ThumbnailManager.GenerateHouseholdThumbnail(household.HouseholdId, cacheId, sizeMask);
                ths.GenerateSimThumbnails(household, cacheId, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge);
                if (DownloadContent.StoreHouseholdContents(householdContents, cacheId))
                {
                    str = DownloadContent.ExportLotContentsToExportBin(cacheId);
                }

                ThumbnailManager.InvalidateHouseholdThumbnail(household.HouseholdId, cacheId, sizeMask);
                ths.InvalidateSimThumbnails(household, cacheId);
                household.SetFamilyFunds(familyFunds, false);
                return(str);
            }
            catch (Exception e)
            {
                Common.Exception("ExportHousehold", e);
                return(null);
            }
        }
예제 #3
0
        public static PlaceResult PlaceFromExportBin(Household household, ExportBinContents exportBinItem, Lot lot, PlaceAction action, bool buyFurnished, GetLotCost onLotCost, ref Sim newActiveSim)
        {
            if (household == null)
            {
                return(PlaceResult.InvalidBinHousehold);
            }
            else if (lot == null)
            {
                return(PlaceResult.InvalidLot);
            }
            else if (exportBinItem == null)
            {
                return(PlaceResult.ContentFailure);
            }

            bool flag = exportBinItem.IsLoaded();

            if (!flag)
            {
                ExportBinContentsEx.Import(exportBinItem, false);
            }

            PlaceResult contentFailure = PlaceResult.ContentFailure;

            if (household != null)
            {
                if (((action & PlaceAction.PlaceAndPay) != PlaceAction.PlaceOnly) && !PayForLot(household, lot, buyFurnished, onLotCost))
                {
                    if (!flag)
                    {
                        ExportBinContentsEx.Flush(exportBinItem);
                    }
                    Household.CleanupOldIdToNewSimDescriptionMap();
                    return(PlaceResult.InsufficientFunds);
                }

                if ((!buyFurnished) && (!lot.IsApartmentLot))
                {
                    lot.MakeLotUnfurnished();
                    Common.Sleep();
                    lot.UpdateCachedValues();
                }

                CreateActors(household, lot, false);
                CreateInventories(household, exportBinItem.HouseholdContents, exportBinItem.IndexMap);
                Common.Sleep();
                BinCommon.UpdateImportedUrnstones(household, lot);
                household.PostImport();

                if ((action & PlaceAction.MoveIn) != PlaceAction.PlaceOnly)
                {
                    BinCommon.MoveIn(household, lot);
                }
                if ((action & PlaceAction.Activate) != PlaceAction.PlaceOnly)
                {
                    newActiveSim = BinCommon.ActivateSim(exportBinItem.Household, lot);
                }

                ThumbnailManager.GenerateHouseholdThumbnail(household.HouseholdId, household.HouseholdId, ThumbnailSizeMask.Large | ThumbnailSizeMask.Medium);
                contentFailure = PlaceResult.Success;
            }

            if (!flag)
            {
                ExportBinContentsEx.Flush(exportBinItem);
            }

            return(contentFailure);
        }
예제 #4
0
        //public static string NExportHousehold(Bin ths, Household household, bool includeLotContents, bool isMovingPacked)
        //{
        //    return NExportHousehold(ths, household, includeLotContents, isMovingPacked, false);
        //}
        public static string NExportHousehold(Bin ths, Household household, bool includeLotContents, bool isMovingPacked, bool noReset, bool noThum)
        {
            if (ths == null)
            {
                throw new NullReferenceException();
            }
            if (household == null)
            {
                throw new ArgumentNullException("household");
            }
            try
            {
                string createdPackageFile = null;
                if (GameUtils.IsInstalled(ProductVersion.EP4))
                {
                    OccultImaginaryFriend.ForceHouseholdImaginaryFriendsBackToInventory(household);
                }

                if (!noReset)
                {
                    foreach (Sim sim in household.AllActors)
                    {
                        sim.SetObjectToReset();
                    }
                }

                if (Simulator.CheckYieldingContext(false))
                {
                    Simulator.Sleep(0);
                }

                ThumbnailSizeMask sizeMask;
                if (includeLotContents)
                {
                    Lot lotHome = household.LotHome;
                    if (lotHome != null)
                    {
                        int householdFunds  = household.FamilyFunds;
                        int lotHomeLotWorth = World.GetEmptyLotWorth(lotHome.LotId) + ((int)World.GetLotAdditionalPropertyValue(lotHome.LotId));

                        household.SetFamilyFunds(householdFunds + lotHomeLotWorth, false);

                        EditTownModel.SendObjectsToProperLot(lotHome);

                        ulong contentID = DownloadContent.StoreLotContents(lotHome, lotHome.LotId);
                        if (contentID != 0)
                        {
                            ThumbnailHelper.GenerateLotThumbnailSet(lotHome.LotId, contentID, ThumbnailSizeMask.ExtraLarge);
                            ThumbnailHelper.GenerateLotThumbnail(lotHome.LotId, contentID, 0, ThumbnailSizeMask.Large | ThumbnailSizeMask.Medium);
                            sizeMask = ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium;
                            ThumbnailManager.GenerateHouseholdThumbnail(household.HouseholdId, contentID, sizeMask);

                            if (!noThum && household.AllSimDescriptions.Count < 12)
                            {
                                ths.GenerateSimThumbnails(household, contentID, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge);
                            }

                            HouseholdContentsProxy contents = new HouseholdContentsProxy(household);

                            if (DownloadContent.StoreHouseholdContents(contents, contentID))
                            {
                                createdPackageFile = DownloadContent.ExportLotContentsToExportBin(contentID);
                            }

                            ThumbnailManager.InvalidateLotThumbnails(lotHome.LotId, contentID, ThumbnailSizeMask.ExtraLarge);
                            ThumbnailManager.InvalidateLotThumbnailsForGroup(lotHome.LotId, contentID, ThumbnailSizeMask.Medium, 0);
                            ThumbnailManager.InvalidateHouseholdThumbnail(household.HouseholdId, contentID, sizeMask);

                            try
                            {
                                ths.InvalidateSimThumbnails(household, contentID);
                            }
                            catch (Exception)
                            { if (IsOpenDGSInstalled)
                              {
                                  return(null);
                              }
                            }
                        }
                        household.SetFamilyFunds(householdFunds, false);
                        return(createdPackageFile);
                    }
                    //return createdPackageFile;
                }

                int familyFunds     = household.FamilyFunds;
                int realEstateFunds = 0;
                if (household.RealEstateManager != null)
                {
                    foreach (IPropertyData data in household.RealEstateManager.AllProperties)
                    {
                        realEstateFunds += data.TotalValue;
                    }
                }

                if (household.LotHome != null)
                {
                    int lotWorth = 0;
                    if (isMovingPacked)
                    {
                        lotWorth = World.GetUnfurnishedLotWorth(household.LotHome.LotId) + realEstateFunds;
                    }
                    else
                    {
                        lotWorth = World.GetLotWorth(household.LotHome.LotId) + realEstateFunds;
                    }

                    household.SetFamilyFunds(household.FamilyFunds + lotWorth, false);
                }

                if (household.FamilyFunds < 20000)
                {
                    household.SetFamilyFunds(20000, false);
                }

                ulong gGUID = DownloadContent.GenerateGUID();
                HouseholdContentsProxy householdContents = new HouseholdContentsProxy(household);
                householdContents.Contents.ContentId = gGUID;

                sizeMask = ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium;

                if (!noThum && household.AllSimDescriptions.Count < 12)
                {
                    ThumbnailManager.GenerateHouseholdThumbnail(household.HouseholdId, gGUID, sizeMask);
                    ths.GenerateSimThumbnails(household, gGUID, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge);
                }

                if (DownloadContent.StoreHouseholdContents(householdContents, gGUID))
                {
                    createdPackageFile = DownloadContent.ExportLotContentsToExportBin(gGUID);
                }

                ThumbnailManager.InvalidateHouseholdThumbnail(household.HouseholdId, gGUID, sizeMask);

                try
                {
                    ths.InvalidateSimThumbnails(household, gGUID);
                }
                catch (Exception)
                { if (IsOpenDGSInstalled)
                  {
                      return(null);
                  }
                }

                household.SetFamilyFunds(familyFunds, false);
                return(createdPackageFile);
            }
            catch (Exception)
            { return(null); }
        }
예제 #5
0
        public static PlaceResult MergeHouseholdFromExportBin(ExportBinContents exportBinItem, Lot lot, bool showConfirmDialog, bool allowOverstuff)
        {
            try
            {
                if (exportBinItem == null)
                {
                    return(PlaceResult.ContentFailure);
                }

                bool flag = exportBinItem.IsLoaded();
                if (!flag)
                {
                    ExportBinContentsEx.Import(exportBinItem, false);
                }

                PlaceResult householdPresent = PlaceResult.HouseholdPresent;
                Household   household        = exportBinItem.Household;
                Household   otherHouse       = lot.Household;
                if (household == null)
                {
                    householdPresent = PlaceResult.InvalidBinHousehold;
                }

                if (lot == null)
                {
                    householdPresent = PlaceResult.InvalidLot;
                }

                if (exportBinItem == null)
                {
                    householdPresent = PlaceResult.ContentFailure;
                }

                try
                {
                    try
                    {
                        if (((household != null) && (householdPresent == PlaceResult.HouseholdPresent)) && (otherHouse != null))
                        {
                            // Custom
                            if ((!allowOverstuff) && (!household.CanMergeWithHousehold(otherHouse, false)))
                            {
                                SimpleMessageDialog.Show(Common.LocalizeEAString("Ui/Caption/GameEntry/EditTown:MergeWarning"), Common.LocalizeEAString("Ui/Caption/MovingDialog:TooManySims"));
                            }
                            // Custom
                            else if ((!allowOverstuff) && (!household.CanMergeWithHousehold(otherHouse, true)))
                            {
                                SimpleMessageDialog.Show(Common.LocalizeEAString("Ui/Caption/GameEntry/EditTown:MergeWarning"), Common.LocalizeEAString("Ui/Caption/MovingDialog:TooManySims_Pregnant"));
                            }
                            else if (!showConfirmDialog || PlayFlowConfirmMergePetHousehold.Show(BinCommon.CreateInWorldBinInfo(lot.LotId), exportBinItem.BinInfo))
                            {
                                ProgressDialog.Show(Common.LocalizeEAString("Ui/Caption/Global:Processing"));

                                otherHouse.ModifyFamilyFunds(household.FamilyFunds);

                                List <SimDescription> simDescs = new List <SimDescription>();
                                foreach (SimDescription description in household.AllSimDescriptions)
                                {
                                    simDescs.Add(description);
                                }

                                CreateActors(simDescs, null, false);
                                BinCommon.CreateFamilyInventories(household, exportBinItem.HouseholdContents);
                                BinCommon.MoveInventoryInto(household, otherHouse);
                                household.PostImport();

                                List <Sim> sims = new List <Sim>();
                                foreach (SimDescription description2 in simDescs)
                                {
                                    otherHouse.AddSim(description2.CreatedSim);
                                    sims.Add(description2.CreatedSim);
                                }

                                otherHouse.AddWardrobeToWardrobe(household.Wardrobe);
                                otherHouse.AddServiceUniforms(household.ServiceUniforms);
                                CreateSimInventories(simDescs, exportBinItem.HouseholdContents, exportBinItem.IndexMap);
                                BinCommon.PlaceSims(sims, lot);
                                ThumbnailManager.GenerateHouseholdThumbnail(otherHouse.HouseholdId, otherHouse.HouseholdId, ThumbnailSizeMask.Large | ThumbnailSizeMask.Medium);
                                (Sims3.UI.Responder.Instance.EditTownModel as EditTownModel).DirtyWorldBins();
                                Bin.Singleton.FireContentsChanged();
                            }
                        }

                        Household.CleanupOldIdToNewSimDescriptionMap();
                        if (!flag)
                        {
                            ExportBinContentsEx.Flush(exportBinItem);
                        }
                    }
                    finally
                    {
                        ProgressDialog.Close();
                    }
                }
                catch (ExecutionEngineException)
                { }

                return(householdPresent);
            }
            catch (Exception e)
            {
                Common.Exception("MergeHouseholdFromExportBin", e);
                return(PlaceResult.ContentFailure);
            }
        }