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

            if (lot == null)
            {
                return(false);
            }

            return(lot.Household == null);
        }
예제 #2
0
        protected override bool Test(IActor a, GameObject target, GameObjectHit hit, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
        {
            Lot lot = Porter.GetLot(target);

            if (lot == null)
            {
                return(false);
            }

            return(lot.IsResidentialLot);
        }
예제 #3
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);
        }
예제 #4
0
        protected override OptionResult Run(GameHitParameters <GameObject> parameters)
        {
            Common.StringBuilder log = new Common.StringBuilder("Run");

            try
            {
                Lot targetLot = Porter.GetLot(parameters.mTarget);
                if (targetLot == null)
                {
                    return(OptionResult.Failure);
                }

                Dictionary <ulong, IMiniSimDescription> preExistingSims = SimListing.GetSims <IMiniSimDescription>(null, true);

                Household me = targetLot.Household;
                if (me == null)
                {
                    me = GetImportSelection(targetLot);

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

                Dictionary <ulong, IMiniSimDescription> allSims = SimListing.GetSims <IMiniSimDescription>(null, true);

                Dictionary <int, HouseData> houses       = new Dictionary <int, HouseData>();
                Dictionary <int, HouseData> doppleHouses = new Dictionary <int, HouseData>();

                List <SimDescription> cleanUp = new List <SimDescription>();
                List <SimDescription> fixUp   = new List <SimDescription>();

                List <Household> importedHouses = new List <Household>();
                importedHouses.Add(me);

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

                log += Common.NewLine + "A";

                List <SimDescription> sims = new List <SimDescription>(me.AllSimDescriptions);
                foreach (SimDescription sim in sims)
                {
                    if (sim == null)
                    {
                        continue;
                    }

                    log += Common.NewLine + sim.FullName;

                    Porter.AddExport(sim);

                    string description = sim.mBio;
                    if (string.IsNullOrEmpty(description))
                    {
                        continue;
                    }

                    if (!description.Contains("NRaas.Porter:"))
                    {
                        continue;
                    }

                    description = description.Replace("NRaas.Porter:", "");
                    if (string.IsNullOrEmpty(description))
                    {
                        continue;
                    }

                    HouseData lookup = new HouseData(description);

                    lookup.Reconcile(sim);

                    ValidateTask.Perform(sim);

                    List <SimDescription> dependents = new List <SimDescription>();
                    if (HandleDoppleganger(sim, preExistingSims, allSims, dependents))
                    {
                        if (!houses.ContainsKey(lookup.mID))
                        {
                            if (!doppleHouses.ContainsKey(lookup.mID))
                            {
                                doppleHouses.Add(lookup.mID, lookup);
                            }
                        }

                        checkSims.AddRange(dependents);

                        cleanUp.Add(sim);
                        continue;
                    }
                    else
                    {
                        fixUp.Add(sim);
                    }

                    HouseData data;
                    if (!houses.TryGetValue(lookup.mID, out data))
                    {
                        data = lookup;
                        houses.Add(data.mID, data);
                    }

                    doppleHouses.Remove(lookup.mID);

                    data.mSims.Add(sim);
                }

                log += Common.NewLine + "B";

                foreach (SimDescription sim in fixUp)
                {
                    log += Common.NewLine + sim.FullName;

                    new Relationships.RepairParents().Perform(sim, UnusedLog, allSims);
                    new Relationships.RepairChildren().Perform(sim, UnusedLog, allSims);
                    new Relationships.RepairSiblings().Perform(sim, UnusedLog, allSims);
                }

                log += Common.NewLine + "C";

                foreach (SimDescription cleanup in cleanUp)
                {
                    log += Common.NewLine + cleanup.FullName;

                    try
                    {
                        if (cleanup.Household != null)
                        {
                            cleanup.Household.Remove(cleanup);
                        }

                        checkSims.Remove(cleanup);

                        cleanup.Genealogy.ClearAllGenealogyInformation();
                        cleanup.Dispose();
                    }
                    catch (Exception e)
                    {
                        Common.DebugException(log, e);
                    }
                }

                log += Common.NewLine + "D";

                if (houses.Count == 0)
                {
                    SimpleMessageDialog.Show(Common.Localize("Title"), Common.Localize("Unpack:NotProper"));
                    return(OptionResult.Failure);
                }
                else if (houses.Count == 1)
                {
                    int funds = -1;
                    foreach (HouseData data in houses.Values)
                    {
                        if (data.mID != 0)
                        {
                            funds = data.mFunds;
                        }
                    }

                    if (funds >= 0)
                    {
                        me.SetFamilyFunds(funds);

                        SimpleMessageDialog.Show(Common.Localize("Title"), Common.Localize("Unpack:Unneeded"));
                        return(OptionResult.Failure);
                    }
                }

                log += Common.NewLine + "E";

                int unpacked = 0, failed = 0;

                List <HouseData> sorted = new List <HouseData>(houses.Values);
                sorted.Sort(new Comparison <HouseData>(HouseData.SortByCost));

                foreach (HouseData data in sorted)
                {
                    log += Common.NewLine + "House: " + data.mID;

                    if (data.mID != 1)
                    {
                        Household house = null;

                        if (data.mID != 0)
                        {
                            Lot lot = FindLot(data.mFunds, data.mSims);
                            if (lot == null)
                            {
                                lot = FindLot(-1, null);
                                if (lot == null)
                                {
                                    failed++;
                                    continue;
                                }
                            }

                            house = Household.Create();

                            importedHouses.Add(house);

                            lot.MoveIn(house);

                            house.Name = data.mName;

                            int finalFunds = (data.mFunds - lot.Cost);
                            if (finalFunds >= 0)
                            {
                                house.SetFamilyFunds(finalFunds);

                                me.ModifyFamilyFunds(-data.mFunds);
                            }
                            else
                            {
                                house.SetFamilyFunds(0);

                                me.ModifyFamilyFunds(-data.mFunds);
                                me.ModifyFamilyFunds(finalFunds);
                            }

                            if (me.FamilyFunds < 0)
                            {
                                me.SetFamilyFunds(0);
                            }

                            if (house.FamilyFunds < 0)
                            {
                                house.SetFamilyFunds(0);
                            }

                            unpacked++;
                        }

                        foreach (SimDescription sim in data.mSims)
                        {
                            log += Common.NewLine + sim.FullName;

                            if (house != null)
                            {
                                log += Common.NewLine + "Moved";

                                me.Remove(sim);
                                house.Add(sim);

                                Instantiation.Perform(sim, null);
                            }
                            else
                            {
                                log += Common.NewLine + "PlaceGrave";

                                Porter.PlaceGraveTask.Perform(sim);
                            }
                        }

                        if (house != null)
                        {
                            string name = house.LotHome.Name;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = house.LotHome.Address;
                            }

                            Porter.Notify(Common.Localize("Unpack:Success", false, new object[] { house.Name, name }), house.LotHome.ObjectId);
                        }
                    }
                    else
                    {
                        unpacked++;
                    }

                    foreach (SimDescription sim in data.mSims)
                    {
                        sim.mBio = null;
                    }
                }

                log += Common.NewLine + "F";

                foreach (SimDescription checkSim in checkSims)
                {
                    log += Common.NewLine + checkSim.FullName;

                    if (checkSim.ChildOrBelow)
                    {
                        bool found = false;

                        Household parentHousehold = null;
                        foreach (SimDescription parent in Relationships.GetParents(checkSim))
                        {
                            if ((checkSim.Household != null) && (parent.Household == checkSim.Household))
                            {
                                found = true;
                                break;
                            }
                            else
                            {
                                parentHousehold = parent.Household;
                            }
                        }

                        if (!found)
                        {
                            if (parentHousehold == null)
                            {
                                if ((checkSim.Household != null) && (checkSim.Household.NumMembers == 1))
                                {
                                    foreach (Household house in Household.sHouseholdList)
                                    {
                                        foreach (SimDescription sim in Households.All(house))
                                        {
                                            if (Relationships.IsCloselyRelated(checkSim, sim, false))
                                            {
                                                parentHousehold = house;
                                                break;
                                            }
                                        }

                                        if (parentHousehold != null)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }

                            if (parentHousehold != null)
                            {
                                if (checkSim.Household != null)
                                {
                                    checkSim.Household.Remove(checkSim);
                                }

                                parentHousehold.Add(checkSim);

                                Instantiation.AttemptToPutInSafeLocation(checkSim.CreatedSim, false);
                            }
                        }
                    }
                }

                log += Common.NewLine + "G";

                foreach (Household house in importedHouses)
                {
                    foreach (Sim sim in Households.AllSims(house))
                    {
                        foreach (GameObject obj in Inventories.QuickFind <GameObject>(sim.Inventory))
                        {
                            bool moveToFamily = false;

                            if (!sim.Inventory.ValidForThisInventory(obj))
                            {
                                moveToFamily = true;
                            }
                            else if (obj is IStageProp)
                            {
                                moveToFamily = true;
                            }

                            if (moveToFamily)
                            {
                                sim.Inventory.RemoveByForce(obj);

                                Inventories.TryToMove(obj, house.SharedFamilyInventory.Inventory);
                            }
                        }
                    }
                }

                log += Common.NewLine + "H";

                int doppleFunds = 0;
                foreach (HouseData data in doppleHouses.Values)
                {
                    doppleFunds += data.mFunds;
                }

                me.ModifyFamilyFunds(-doppleFunds);

                if (me.FamilyFunds < 0)
                {
                    me.SetFamilyFunds(0);
                }

                SimpleMessageDialog.Show(Common.Localize("Title"), Common.Localize("Unpack:Completion", false, new object[] { unpacked, failed }));
            }
            catch (Exception e)
            {
                Common.Exception(log, e);
            }

            return(OptionResult.SuccessClose);
        }