Exemplo n.º 1
0
        /// <summary>
        /// Returns all treasure chests either on this lot, or the owners lot
        /// </summary>
        /// <param name="actor"></param>
        /// <returns></returns>
        public static List <TreasureChest> ReturnTreasureChests(Sim actor, Lot lotCurrent)
        {
            //Get the lot owner
            Household ownerHousehold = CommonMethods.ReturnLotOwner(lotCurrent);
            Lot       ownerLot       = null;

            if (ownerHousehold != null)
            {
                ownerLot = ownerHousehold.LotHome;
            }

            List <TreasureChest> tList = new List <TreasureChest>(Sims3.Gameplay.Queries.GetObjects <TreasureChest>()).FindAll(
                delegate(TreasureChest t)
            {
                if (ownerLot != null)
                {
                    return(t.LotCurrent == lotCurrent || t.LotCurrent == ownerLot);
                }
                return(t.LotCurrent == lotCurrent);
            }
                );

            return(tList);
        }
Exemplo n.º 2
0
            /// <summary>
            /// Handle payments and object inventory swapping.
            /// </summary>
            /// <param name="purchasedItems"></param>
            public void HandlePurchases(List <object> purchasedItems)
            {
                try
                {
                    Boolean okToShop = true;

                    if (purchasedItems.Count > 0 && okToShop)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(CommonMethods.LocalizeString("ItemsPurchasedBySim", new object[] { base.Actor.Name }));

                        //Get the lot owner
                        Household ownerHousehold = CommonMethods.ReturnLotOwner(base.Target.LotCurrent);

                        int purchaseTotal  = 0;
                        int lotOwnerIncome = 0;

                        //Get Shop inventory
                        List <StorageInventory> storeInventory = CommonMethods.ReturnStorageInventory(base.Actor, base.Target.LotCurrent);

                        //Loop through the items that were purchased
                        foreach (GameObject item in purchasedItems)
                        {
                            StorageInventory si = storeInventory.Find(delegate(StorageInventory o) { return(o.ItemGuid == item.ObjectId); });

                            List <TreasureChest> tList = CommonMethods.ReturnTreasureChests(base.Actor, base.Target.LotCurrent);

                            int price       = 0;
                            int objectValue = (int)ReturnItemPrice(item);

                            if (si != null)
                            {
                                //Find the chest the object is in
                                TreasureChest tc = tList.Find(delegate(TreasureChest t) { return(t.ObjectId == si.StorageGuid); });

                                GameObject storageObject = null;

                                if (tc != null)
                                {
                                    storageObject = tc;
                                }

                                if (storageObject != null)
                                {
                                    //Did removing of the item succeed
                                    if (storageObject.Inventory.TryToRemove(item))
                                    {
                                        //If the product was made by a sim who is not a member of the lot owner household
                                        //Give the maker, 50% of the value

                                        SimDescription productMaker = CommonMethods.ReturnCreaotrSimDescription(item);

                                        if (productMaker != null && !productMaker.IsDead)
                                        {
                                            //Devide the earnings
                                            if (ownerHousehold != null)
                                            {
                                                price           = objectValue / 2;
                                                lotOwnerIncome += price;
                                            }
                                            else
                                            {
                                                price = objectValue;
                                            }

                                            //lotOwner.ModifyFamilyFunds(price);
                                            productMaker.Household.ModifyFamilyFunds(price);

                                            //If the owner of the pruduct is in a skill based career, and the item they sold is related to their job
                                            //Count it towards their job performance
                                            if (productMaker != null && productMaker.Occupation != null && productMaker.Occupation.IsSkillBased)
                                            {
                                                //First check that the buyer and the product maker are not in the same household
                                                if (base.Actor.Household != productMaker.Household)
                                                {
                                                    UpdateSkillBasedCareerEarning(productMaker, item, price);
                                                }
                                            }

                                            purchaseTotal += objectValue;
                                        }
                                        else
                                        {
                                            //The item doesn't have an owner
                                            //Add 30% to the price, if not the active Household
                                            price = (int)objectValue; //(int)(objectValue * 1.3);

                                            purchaseTotal += price;


                                            //If the lot is owned by a sim
                                            if (ownerHousehold != null)
                                            {
                                                lotOwnerIncome += price;

                                                //If the item was harvested, we assume it was planted by the owner or somebody in his household
                                                // lotOwner.ModifyFamilyFunds(price);

                                                //Collect all sims from the lot, and if their occupation is gardener,
                                                //devide the money earned from the purchase between them

                                                if (item.GetType() == typeof(Ingredient))
                                                {
                                                    if (((Ingredient)item).CraftType == CraftType.Fruit)
                                                    {
                                                        List <Sim> gardnerSims = new List <Sim>();
                                                        foreach (Sim sim in ownerHousehold.Sims)
                                                        {
                                                            if (sim.SimDescription.YoungAdultOrAbove && sim.SimDescription.OccupationAsSkillBasedCareer != null)
                                                            {
                                                                if (sim.SimDescription.OccupationAsSkillBasedCareer.CareerName.Equals(OccupationNames.Gardener.ToString()))
                                                                {
                                                                    gardnerSims.Add(sim);
                                                                }
                                                            }
                                                        }

                                                        if (gardnerSims != null && gardnerSims.Count > 0)
                                                        {
                                                            foreach (Sim sim in gardnerSims)
                                                            {
                                                                int simoleansEarned = (price / gardnerSims.Count) > 1 ? (price / gardnerSims.Count) : 1;
                                                                UpdateSkillBasedCareerEarning(sim.SimDescription, item, simoleansEarned);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        base.Actor.Inventory.TryToAdd(item, false);
                                        storeInventory.Remove(si);
                                        sb.Append(CommonMethods.LocalizeString("PurchasedItem", new object[] { item.CatalogName, price }));
                                    }
                                    else
                                    {
                                        StyledNotification.Show(new StyledNotification.Format("Failed to remove " + item.CatalogName, StyledNotification.NotificationStyle.kGameMessagePositive));
                                    }
                                }
                            }
                        }

                        if (purchaseTotal > 0)
                        {
                            base.Actor.ModifyFunds(-purchaseTotal);

                            sb.Append(CommonMethods.LocalizeString("PurchaseTotal", new object[] { purchaseTotal }));

                            //Give the money earned from the purchase to the owner of the lot
                            if (lotOwnerIncome > 0 && ownerHousehold != null)
                            {
                                ownerHousehold.ModifyFamilyFunds(lotOwnerIncome);
                                sb.Append(CommonMethods.LocalizeString("LotOwnerEarned", new object[] { ownerHousehold.Name, lotOwnerIncome }));
                            }

                            //Show only if wanted
                            if (AddMenuItem.ReturnShowNotifications())
                            {
                                StyledNotification.Show(new StyledNotification.Format(sb.ToString(), StyledNotification.NotificationStyle.kGameMessagePositive));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    StyledNotification.Show(new StyledNotification.Format(ex.ToString(), StyledNotification.NotificationStyle.kGameMessagePositive));
                }
            }