/// <summary> ///Returns a list of items from the store's inventory, this method is used when paying /// </summary> /// <param name="actor"></param> /// <returns></returns> public static List <StorageInventory> ReturnStorageInventory(Sim actor, Lot lotCurrent) { //Catalogue the inventory List <StorageInventory> storeInventory = new List <StorageInventory>(); List <TreasureChest> tList = ReturnTreasureChests(actor, lotCurrent); foreach (TreasureChest tChest in tList) { List <GameObject> cInventoryItems = tChest.Inventory.FindAll <GameObject>(false); foreach (IGameObject inventoryItem in cInventoryItems) { StorageInventory si = new StorageInventory(); si.StorageGuid = tChest.ObjectId; si.ItemGuid = inventoryItem.ObjectId; storeInventory.Add(si); } } return(storeInventory); }
/// <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)); } }
/// <summary> ///Returns a list of items from the store's inventory, this method is used when paying /// </summary> /// <param name="actor"></param> /// <returns></returns> public static List<StorageInventory> ReturnStorageInventory(Sim actor, Lot lotCurrent) { //Catalogue the inventory List<StorageInventory> storeInventory = new List<StorageInventory>(); List<TreasureChest> tList = ReturnTreasureChests(actor, lotCurrent); foreach (TreasureChest tChest in tList) { List<GameObject> cInventoryItems = tChest.Inventory.FindAll<GameObject>(false); foreach (IGameObject inventoryItem in cInventoryItems) { StorageInventory si = new StorageInventory(); si.StorageGuid = tChest.ObjectId; si.ItemGuid = inventoryItem.ObjectId; storeInventory.Add(si); } } return storeInventory; }