Пример #1
0
        protected static bool IsConsignable(GameObject obj)
        {
            if (!obj.CanBeSold())
            {
                return(false);
            }

            if ((!GameUtils.IsInstalled(ProductVersion.EP2)) && (!GameUtils.IsInstalled(ProductVersion.EP7)))
            {
                return(false);
            }

            if (GameUtils.IsInstalled(ProductVersion.EP2))
            {
                if (ConsignmentRegister.IsObjectConsignable(obj, null))
                {
                    return(true);
                }
            }

            if (GameUtils.IsInstalled(ProductVersion.EP7))
            {
                if (PotionShopConsignmentRegister.IsObjectConsignable(obj, null))
                {
                    return(true);
                }
            }

            if (obj is ICraftedArt)
            {
                return(true);
            }

            if (obj is MinorPet)
            {
                return(true);
            }

            return(Consignments.IsCollectable(obj));
        }
Пример #2
0
        protected static bool ShowShoppingDialog(ShoppingRegister ths, Sim sim)
        {
            float num = (1f - ths.GetSalePercentage(sim)) * 100f;

            Dictionary <object, IList> objectsForSale = Consignments.Cleanup(null);

            Dictionary <string, List <StoreItem> > itemDictionary = ths.ItemDictionary(sim);

            // ItemDictionary will remove objects from the Consignment list, but not delete them, correct for that now
            Consignments.ValidateObjectForSale(objectsForSale);

            if (itemDictionary.Count == 0x0)
            {
                return(false);
            }

            ShoppingRabbitHole.CreateSellableCallback createSellableCallback = ths.CreateSellableObjectsList;

            if (ths is ConsignmentRegister)
            {
                createSellableCallback = CreateConsignmentObjectsList;
            }
            else if (ths is PotionShopConsignmentRegister)
            {
                createSellableCallback = CreatePotionObjectsList;
            }
            else if (ths is BotShopRegister)
            {
                createSellableCallback = CreateFutureObjectsList;
            }
            else if (ths is PetstoreRegister)
            {
                createSellableCallback = CreatePetObjectsList;
            }

            ShoppingModel.CurrentStore = ths;
            ShoppingRabbitHole.StartShopping(sim, itemDictionary, ths.PercentModifier, (float)((int)num), 0x0, null, sim.Inventory, null, ths.FinishedCallBack, createSellableCallback, ths.GetRegisterType != RegisterType.General);
            return(true);
        }
Пример #3
0
        public int Sell(SimDescription sim, GameObject obj)
        {
            if ((mAllowConsignment) && (sim.CreatedSim != null) && (IsConsignable(obj)))
            {
                Inventory inventory = Inventories.ParentInventory(obj);
                if ((inventory == null) || (inventory.TryToRemove(obj)))
                {
                    try
                    {
                        if (GameUtils.IsInstalled(ProductVersion.EP2))
                        {
                            ConsignmentRegister.OnConsignedItem(sim.CreatedSim, obj);
                        }
                        else if (GameUtils.IsInstalled(ProductVersion.EP7))
                        {
                            PotionShopConsignmentRegister.OnConsignedItem(sim.CreatedSim, obj);
                        }

                        return(0);
                    }
                    catch (Exception e)
                    {
                        Common.DebugException(obj, e);
                    }
                }
            }

            int value = obj.Value;

            Consignments.NotifySell(sim, obj);

            AdjustFunds(sim, "SellItem", value);

            obj.Destroy();

            return(value);
        }
Пример #4
0
        protected static void Consign(Dictionary <ulong, List <ConsignedObjectProxy> > lookup, Dictionary <ObjectGuid, float> consignAttempts, float[] consignmentPrices, float madeGoodSaleThreshold, float reputationBonusForPositiveFeedback, Curve qualityVsReputationCurve, float sellXItemsOpportunityReputationGainMultiplier, int consignmentLifespan, float dailyNumberOfAttemptsDecrement, Curve reputationVsStoreFeeCurve, int numberOfTopSellingItems, float makeXSimoleonsOpportunityConsignmentFeeMultiplier)
        {
            if (lookup != null)
            {
                Dictionary <ulong, SimDescription> sims = SimListing.GetSims <SimDescription>(null, false);

                foreach (ulong num in lookup.Keys)
                {
                    SimDescription desc = null;
                    sims.TryGetValue(num, out desc);
                    if ((desc != null) && (desc.CreatedSim != null))// && desc.CreatedSim.IsInActiveHousehold)
                    {
                        Consignment consignment = desc.SkillManager.AddElement(SkillNames.Consignment) as Consignment;

                        bool unsold = false;

                        int totalSale = 0x0;

                        List <Pair <int, IGameObject> > list = new List <Pair <int, IGameObject> >();

                        bool bornSalesmanAdded = false;

                        string displayName = null;

                        List <ConsignedObjectProxy> list2 = lookup[num];

                        int index = 0x0;
                        while (index < list2.Count)
                        {
                            ConsignedObjectProxy local1 = list2[index];
                            local1.Age++;

                            float chance = 0;

                            try
                            {
                                if (list2[index].Object != null)
                                {
                                    chance = list2[index].GetChanceOfSale(desc.CreatedSim);
                                }
                                else
                                {
                                    list2.RemoveAt(index);
                                    continue;
                                }
                            }
                            catch (Exception e)
                            {
                                Common.DebugException("Consignment Section A", e);
                                chance = 1f;
                            }

                            if (RandomUtil.RandomChance01(chance))
                            {
                                if (list2[index].Age >= consignmentPrices.Length)
                                {
                                    list2[index].Age = consignmentPrices.Length - 1;
                                }

                                int valueOfSale = list2[index].GetValueOfSale(desc);
                                totalSale += valueOfSale;

                                float quality = list2[index].GetQuality();

                                try
                                {
                                    if ((((float)valueOfSale) / ((float)list2[index].Object.Value)) >= madeGoodSaleThreshold)
                                    {
                                        desc.CreatedSim.BuffManager.AddElement(BuffNames.MadeGoodSale, Origin.None);
                                    }

                                    if (!bornSalesmanAdded && (((desc.TraitManager.HasElement(TraitNames.BornSalesman) && (quality >= TraitTuning.BornSalesmanQualityMinimumThresholdForPositiveFeedback)) && RandomUtil.InterpolatedChance(TraitTuning.BornSalesmanQualityMinimumThresholdForPositiveFeedback, 1f, TraitTuning.BornSalesmanQualityMinimumChanceOfPositiveFeedback, TraitTuning.BornSalesmanQualityMaximumChanceOfPositiveFeedback, quality)) || ((!desc.TraitManager.HasElement(TraitNames.BornSalesman) && (quality >= ConsignmentRegister.kQualityMinimumThreshold)) && RandomUtil.InterpolatedChance(ConsignmentRegister.kQualityMinimumThreshold, 1f, ConsignmentRegister.kQualityMinimumChanceOfPositiveFeedback, ConsignmentRegister.kQualityMaximumChanceOfPositiveFeedback, quality))))
                                    {
                                        bornSalesmanAdded = true;
                                        displayName       = list2[index].DisplayName;
                                        consignment.TrackReputationChange(reputationBonusForPositiveFeedback);
                                    }

                                    float reputationChange = qualityVsReputationCurve.Fx(quality);
                                    if (consignment.OppItemsSoldLifetimeOpportunityCompleted && (reputationChange > 0f))
                                    {
                                        reputationChange *= sellXItemsOpportunityReputationGainMultiplier;
                                    }

                                    if (desc.TraitManager.HasElement(TraitNames.BornSalesman) && (reputationChange > 0f))
                                    {
                                        reputationChange *= TraitTuning.BornSalesmanReputationOnSaleBonusMultiplier;
                                    }

                                    consignment.TrackConsignmentSale(list2[index].Object, valueOfSale, reputationChange);
                                }
                                catch (Exception e)
                                {
                                    Common.DebugException("Consignment Section B", e);
                                }

                                list.Add(new Pair <int, IGameObject>(valueOfSale, list2[index].Object));

                                EventTracker.SendEvent(EventTypeId.kSoldConsignedObject, desc.CreatedSim);

                                GameObject obj2 = list2[index].Object as GameObject;
                                if (obj2 != null)
                                {
                                    Consignments.NotifySell(desc, obj2, valueOfSale);
                                }
                                list2.RemoveAt(index);
                            }
                            else if (list2[index].Age >= consignmentLifespan)
                            {
                                unsold = true;
                                consignment.TrackConsignmentReturn();

                                if (desc.CreatedSim.Inventory.ValidForThisInventory(list2[index].Object))
                                {
                                    Inventories.TryToMove(list2[index].Object, desc.CreatedSim);
                                }
                                else
                                {
                                    desc.CreatedSim.Household.SharedFamilyInventory.Inventory.TryToAdd(list2[index].Object);
                                }

                                list2[index].Object.EnableInteractions();
                                list2.RemoveAt(index);
                            }
                            else
                            {
                                index++;
                            }
                        }

                        DisplayStory(desc, list, totalSale, unsold, displayName, reputationVsStoreFeeCurve, numberOfTopSellingItems, makeXSimoleonsOpportunityConsignmentFeeMultiplier);
                    }
                }
            }

            foreach (ObjectGuid guid in new List <ObjectGuid>(consignAttempts.Keys))
            {
                float attempts = consignAttempts[guid];

                consignAttempts[guid] = Math.Max((float)0f, (float)(attempts - dailyNumberOfAttemptsDecrement));
            }
        }
Пример #5
0
        public static bool Perform(string title, string subTitle, List <Inventory> inventories)
        {
            Dictionary <string, Item> stack = new Dictionary <string, Item>();

            foreach (Inventory inventory in inventories)
            {
                foreach (GameObject obj in Inventories.QuickFind <GameObject>(inventory))
                {
                    if ((obj is INotTransferableOnDeath) || (obj is IHiddenInInventory))
                    {
                        continue;
                    }

                    if (!obj.CanBeSoldBase())
                    {
                        continue;
                    }

                    Item list;
                    if (!stack.TryGetValue(obj.CatalogName, out list))
                    {
                        list = new Item(obj.CatalogName, obj.GetThumbnailKey());
                        stack.Add(obj.CatalogName, list);
                    }

                    list.Add(obj);
                }
            }

            stack.Add("All", new Item("(" + Common.LocalizeEAString("Ui/Caption/ObjectPicker:All") + ")", ThumbnailKey.kInvalidThumbnailKey));

            List <Item> selection = new List <Item>(new CommonSelection <Item>(title, subTitle, stack.Values).SelectMultiple());

            if (selection.Count == 0)
            {
                return(false);
            }

            bool all = false;

            foreach (Item item in selection)
            {
                if (item.Thumbnail == ThumbnailKey.kInvalidThumbnailKey)
                {
                    all = true;
                    break;
                }
            }

            if (all)
            {
                selection = new List <Item>(stack.Values);
            }

            foreach (Item item in selection)
            {
                int count = 1;
                if (all)
                {
                    count = item.Count;
                }
                else if (item.Count > 1)
                {
                    string text = StringInputDialog.Show(title, Common.Localize("SellItem:Prompt", false, new object[] { item.Name }), item.Count.ToString());
                    if ((text == null) || (text == ""))
                    {
                        return(false);
                    }

                    if (!int.TryParse(text, out count))
                    {
                        SimpleMessageDialog.Show(title, Common.Localize("Numeric:Error"));
                        return(false);
                    }
                }

                if (count > item.Count)
                {
                    count = item.Count;
                }

                for (int i = 0; i < count; i++)
                {
                    Inventory source;
                    if (Inventories.TryToRemove(item.Value[i], out source))
                    {
                        int value = item.Value[i].Value;

                        Household house = null;

                        Sim sourceSim = source.Owner as Sim;
                        if (sourceSim != null)
                        {
                            house = sourceSim.Household;

                            Consignments.NotifySell(sourceSim.SimDescription, item.Value[i], value);
                        }
                        else
                        {
                            SharedFamilyInventory familyInventory = source.Owner as SharedFamilyInventory;
                            if (familyInventory != null)
                            {
                                house = familyInventory.OwnerHousehold;
                            }
                            else if (source.Owner.LotCurrent != null)
                            {
                                house = source.Owner.LotCurrent.Household;
                            }
                        }

                        item.Value[i].Destroy();

                        if (house != null)
                        {
                            house.ModifyFamilyFunds(value);
                        }
                    }
                }
            }

            return(true);
        }
Пример #6
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("FixConsignment");

            Consignments.Cleanup(Overwatch.Log);
        }