public void AddInteractionsToChildren() { this.RemoveInteractionsFromChildren(); List <ObjectGuid> objectsICanBuyInDisplay = this.GetObjectIDsICanBuyInDisplay(null, false); for (int i = 0; i < objectsICanBuyInDisplay.Count; i++) { GameObject gameObject = GlobalFunctions.ConvertGuidToObject <GameObject>(objectsICanBuyInDisplay[i]); if (gameObject != null) { if (StoreHelperClass.AddPurchaseInteraction(null, gameObject, null, true)) { gameObject.RemoveAllInteractions(); this.mObjectsWithMyInteraction.Add(objectsICanBuyInDisplay[i]); gameObject.RemoveInteractionByType(StoreSetBase.ChildObjectPurchaseStub.Singleton); gameObject.RemoveInteractionByType(StoreSetBase.ChildObjectBrowseStub.Singleton); gameObject.AddInteraction(new StoreSetBase.ChildObjectPurchaseStub.Definition(base.ObjectId)); gameObject.AddInteraction(new StoreSetBase.ChildObjectBrowseStub.Definition(base.ObjectId)); } } } }
public override List <ObjectGuid> GetObjectIDsICanBuyInDisplay(Sim actor, bool isAutonomous) { List <ObjectGuid> list = new List <ObjectGuid>(); if (base.Charred) { return(list); } GameObject[] objectsIntersectingObject = Sims3.Gameplay.Queries.GetObjectsIntersectingObject(base.ObjectId); if (objectsIntersectingObject != null && objectsIntersectingObject.Length > 0) { //bool isRug = true; //StoreSetBase sBase = RestockItemHelperClass.ReturnStoreSetBase(objectsIntersectingObject[0], out isRug); for (int i = 0; i < objectsIntersectingObject.Length; i++) { if (StoreHelperClass.AddPurchaseInteraction(actor, objectsIntersectingObject[i], this, isAutonomous)) { objectsIntersectingObject[i].RemoveInteractionByType(StoreSetBase.ChildObjectPurchaseStub.Singleton); objectsIntersectingObject[i].RemoveInteractionByType(StoreSetBase.ChildObjectBrowseStub.Singleton); objectsIntersectingObject[i].AddInteraction(new StoreSetBase.ChildObjectPurchaseStub.Definition(base.ObjectId)); objectsIntersectingObject[i].AddInteraction(new StoreSetBase.ChildObjectBrowseStub.Definition(base.ObjectId)); list.Add(objectsIntersectingObject[i].ObjectId); } BroomStand broomStand = objectsIntersectingObject[i] as BroomStand; if (broomStand != null) { MagicBroom magicBroom = broomStand.GetContainedObject((Slot)2820733094u) as MagicBroom; if (magicBroom != null)// && base.TestIfObjectCanBeBoughtByActor(magicBroom, actor)) { list.Add(magicBroom.ObjectId); } } } } return(list); }
public static GameObject RecreateSoldObject(RestockItem restockItem, SimDescription actor) { try { IGameObject gameObject = null; bool restockBuyMode = false; bool restockCraftable = false; StoreSetRegister register = null; bool isRug; StoreSetBase shopBase = ReturnStoreSetBase(restockItem, out isRug); if (shopBase != null) { if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid) { register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent); } restockBuyMode = shopBase.Info.RestockBuyMode; restockCraftable = shopBase.Info.RestockCraftable; #region Find the slot bool slotFound = false; Slot slot = Slot.ContainmentSlot_0; if (!isRug) { Slot[] containmentSlots = shopBase.GetContainmentSlots(); if (containmentSlots != null) { for (int i = 0; i < containmentSlots.Length; i++) { GameObject o = shopBase.GetContainedObject(containmentSlots[i]) as GameObject; if (o != null && o.ObjectId == restockItem.ObjectId) { slotFound = true; slot = containmentSlots[i]; break; } } } } #endregion //Restock from inventory only, if not buy object and linked to register bool restockFromInventory = RestockFromInventory(restockItem, restockCraftable); //Restock from buy mode #region Buy Mode if (!restockFromInventory) { if (restockItem.info.Type == ItemType.Buy || restockItem.info.Type == ItemType.Craftable) { gameObject = GlobalFunctions.CreateObject(restockItem.info.Key, restockItem.Position, restockItem.mLevel, restockItem.ForwardVector); if (!(gameObject is FailureObject)) { if (!string.IsNullOrEmpty(restockItem.info.DesignPreset)) { SortedList <string, bool> enabledStencils = new SortedList <string, bool>(); SortedList <string, Complate> patterns = StoreHelperClass.ExtractPatterns(restockItem.info.DesignPreset, enabledStencils); DesignModeSwap designModeSwap = Complate.SetupDesignSwap(gameObject.ObjectId, patterns, false, enabledStencils); if (designModeSwap != null) { designModeSwap.ApplyToObject(); } } } } else { gameObject = ReturnShoppingObject(restockItem, actor, register); gameObject.AddToWorld(); gameObject.SetPosition(restockItem.Position); } #region Pay for Restock //Reduce from base owner or register's owner if (shopBase.Info.Owner != 0uL) { SimDescription sd = CMStoreSet.ReturnSim(shopBase.Info.Owner); if (sd != null) { sd.ModifyFunds(-restockItem.info.Price); } else { CMStoreSet.PrintMessage("Couldn't find owner sim"); } } else if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid) { //StoreSetRegister register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent); if (register != null && register.Info.OwnerId != 0uL) { SimDescription sd = CMStoreSet.ReturnSim(register.Info.OwnerId); if (sd != null) { sd.ModifyFunds(-restockItem.info.Price); } } } #endregion } #endregion Buy Mode #region Inventory else { //Restock from Inventory if (shopBase != null && shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid) { gameObject = ReturnRestocableObject(restockItem, shopBase.Info.RegisterId); if (gameObject != null) { gameObject.AddToWorld(); gameObject.SetPosition(restockItem.Position); gameObject.SetForward(restockItem.ForwardVector); } else { CMStoreSet.PrintMessage("Restockable object null"); } } } #endregion Inventory //Delete restock object if (restockItem != null) { restockItem.Destroy(); } //Add restocked item back to slot if (slotFound) { IGameObject io = (IGameObject)shopBase; gameObject.ParentToSlot(io, slot); } return((GameObject)gameObject); } else { return(null); } } catch (System.Exception ex) { CMStoreSet.PrintMessage("RecreateSoldObject: " + ex.Message); return(null); } }
public static GameObject ReturnShoppingObject(RestockItem rItem, SimDescription actor, StoreSetRegister register) { GameObject o = null; bool keepLooping = true; switch (rItem.info.Type) { case ItemType.Herb: case ItemType.Ingredient: foreach (KeyValuePair <string, List <StoreItem> > kvp in Grocery.mItemDictionary) { foreach (StoreItem item in kvp.Value) { if (item.Name.Equals(rItem.info.Name)) { keepLooping = false; IngredientData data = (IngredientData)item.CustomData; if (rItem.info.Type == ItemType.Ingredient) { o = Ingredient.Create(data); } else { o = Herb.Create(data); //PlantableNonIngredientData data = (PlantableNonIngredientData)item.CustomData; //o = (GameObject)PlantableNonIngredient.Create(data); } break; } } if (!keepLooping) { break; } } break; case ItemType.Fish: o = Fish.CreateFishOfRandomWeight(rItem.info.FType); break; case ItemType.Craftable: break; case ItemType.Gem: case ItemType.Metal: o = (GameObject)RockGemMetalBase.Make(rItem.info.RockData, false); break; case ItemType.Nectar: NectarBottle bottle = (NectarBottle)GlobalFunctions.CreateObjectOutOfWorld("NectarBottle"); NectarBottleObjectInitParams nectarBottleObjectInitParams = bottle.CreateAncientBottle(rItem.info.NectarAge, rItem.info.Price); if (nectarBottleObjectInitParams != null) { bottle.mBottleInfo.FruitHash = nectarBottleObjectInitParams.FruitHash; bottle.mBottleInfo.Ingredients = nectarBottleObjectInitParams.Ingredients; bottle.mBottleInfo.Name = rItem.info.Name; //nectarBottleObjectInitParams.Name; bottle.mDateString = nectarBottleObjectInitParams.DateString; bottle.mBottleInfo.DateNum = nectarBottleObjectInitParams.DateNum; bottle.mBaseValue = rItem.info.Price; // nectarBottleObjectInitParams.BaseValue; bottle.ValueModifier = (int)(nectarBottleObjectInitParams.CurrentValue - rItem.info.Price); bottle.mBottleInfo.mCreator = nectarBottleObjectInitParams.Creator; bottle.mBottleInfo.NectarQuality = Sims3.Gameplay.Objects.Quality.Neutral; //NectarBottle.GetQuality((float)rItem.info.Price); bottle.mBottleInfo.MadeByLevel10Sim = nectarBottleObjectInitParams.MadeByLevel10Sim; bottle.UpdateVisualState(); } o = bottle; break; case ItemType.AlchemyPotion: foreach (AlchemyRecipe recipe in AlchemyRecipe.GetAllAwardPotionRecipes()) { if (rItem.info.Name.Equals(recipe.Name)) { string[] array = new string[] { recipe.Key }; AlchemyRecipe randomAwardPotionRecipe = AlchemyRecipe.GetRandomAwardPotionRecipe(); PotionShopConsignmentRegister.PotionShopConsignmentRegisterData potionShopConsignmentRegisterData = new PotionShopConsignmentRegister.PotionShopConsignmentRegisterData(); potionShopConsignmentRegisterData.mParameters = array; potionShopConsignmentRegisterData.mObjectName = randomAwardPotionRecipe.MedatorName; potionShopConsignmentRegisterData.mGuid = potionShopConsignmentRegisterData.mObjectName.GetHashCode(); potionShopConsignmentRegisterData.mSellerAge = CASAgeGenderFlags.None; potionShopConsignmentRegisterData.mWeight = 100f; potionShopConsignmentRegisterData.mSellPriceMinimum = 0.75f; potionShopConsignmentRegisterData.mSellPriceMaximum = 1.25f; potionShopConsignmentRegisterData.mDepreciationAgeMinimum = 0; potionShopConsignmentRegisterData.mDepreciationAgeMaximum = 5; potionShopConsignmentRegisterData.mLifespan = 3f; string text = string.Empty; if (!string.IsNullOrEmpty(randomAwardPotionRecipe.CustomClassName)) { text = randomAwardPotionRecipe.CustomClassName; } else { text = "Sims3.Gameplay.Objects.Alchemy.AlchemyPotion"; } potionShopConsignmentRegisterData.mScriptClass = text; potionShopConsignmentRegisterData.mIsRotatable = true; PotionShopConsignmentRegister.PotionShopConsignmentRegisterObjectData potionShopConsignmentRegisterObjectData2 = PotionShopConsignmentRegister.PotionShopConsignmentRegisterObjectData.Create(potionShopConsignmentRegisterData); potionShopConsignmentRegisterObjectData2.ShowTooltip = true; o = (GameObject)potionShopConsignmentRegisterObjectData2.mObject; break; } } break; case ItemType.Bug: Terrarium t = Terrarium.Create(rItem.info.BugType); if (t != null) { t.StartVfx(); } o = t; break; case ItemType.Food: int servingPrice = 25; if (register != null) { servingPrice = register.Info.ServingPrice; } IFoodContainer container = rItem.info.cookingProcess.Recipe.CreateFinishedFood(rItem.info.cookingProcess.Quantity, rItem.info.cookingProcess.Quality); if (rItem.info.cookingProcess.Quantity == Recipe.MealQuantity.Group) { ((ServingContainerGroup)container).mPurchasedPrice = StoreHelperClass.ReturnPriceByQuality(rItem.info.cookingProcess.Quality, servingPrice * ((ServingContainerGroup)container).mNumServingsLeft); ((ServingContainerGroup)container).RemoveSpoilageAlarm(); } else { ((ServingContainerSingle)container).mPurchasedPrice = StoreHelperClass.ReturnPriceByQuality(rItem.info.cookingProcess.Quality, servingPrice); ((ServingContainerSingle)container).RemoveSpoilageAlarm(); } o = (GameObject)container; break; case ItemType.Flowers: o = Wildflower.CreateWildflowerOfType(rItem.info.TypeOfWildFlower, Wildflower.WildflowerState.InVase); break; case ItemType.BookAlchemyRecipe_: case ItemType.BookComic_: case ItemType.BookFish_: case ItemType.BookGeneral_: case ItemType.BookRecipe_: case ItemType.BookSkill_: case ItemType.BookToddler_: case ItemType.SheetMusic_: case ItemType.AcademicTextBook_: foreach (KeyValuePair <string, List <StoreItem> > kvp in Bookstore.sItemDictionary) { foreach (StoreItem item in kvp.Value) { if (item.Name.Equals(rItem.info.Name)) { keepLooping = false; if (rItem.info.Type == ItemType.BookGeneral_) { o = (GameObject)BookGeneral.CreateOutOfWorld(item.CustomData as BookGeneralData); } if (rItem.info.Type == ItemType.BookSkill_) { o = (GameObject)BookSkill.CreateOutOfWorld(item.CustomData as BookSkillData); } if (rItem.info.Type == ItemType.BookRecipe_) { o = (GameObject)BookRecipe.CreateOutOfWorld(item.CustomData as BookRecipeData); } if (rItem.info.Type == ItemType.SheetMusic_) { o = (GameObject)SheetMusic.CreateOutOfWorld(item.CustomData as SheetMusicData); } if (rItem.info.Type == ItemType.BookToddler_) { o = (GameObject)BookToddler.CreateOutOfWorld(item.CustomData as BookToddlerData); } if (rItem.info.Type == ItemType.BookFish_) { o = (GameObject)BookFish.CreateOutOfWorld(item.CustomData as BookFishData); } if (rItem.info.Type == ItemType.BookAlchemyRecipe_) { o = (GameObject)BookAlchemyRecipe.CreateOutOfWorld(item.CustomData as BookAlchemyRecipeData); } if (rItem.info.Type == ItemType.AcademicTextBook_) { o = (GameObject)AcademicTextBook.CreateOutOfWorld(item.CustomData as AcademicTextBookData, actor); } if (rItem.info.Type == ItemType.BookComic_) { o = (GameObject)BookComic.CreateOutOfWorld(item.CustomData as BookComicData); } break; } } if (!keepLooping) { break; } } break; case ItemType.JamJar: JamJar jamJar = GlobalFunctions.CreateObjectOutOfWorld("canningJarJam", ProductVersion.Store) as JamJar; if (jamJar != null) { Type tInfo = jamJar.GetType(); BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic; FieldInfo ingredientDataField = tInfo.GetField("mData", flags); FieldInfo ingredientKeyField = tInfo.GetField("mIngredientKey", flags); FieldInfo qualityField = tInfo.GetField("mQuality", flags); FieldInfo preservesField = tInfo.GetField("mIsPreserves", flags); MethodInfo materialStateMethod = tInfo.GetMethod("SetMaterialState", flags); ingredientDataField.SetValue(jamJar, rItem.info.IngData); ingredientKeyField.SetValue(jamJar, rItem.info.IngredientKey); qualityField.SetValue(jamJar, rItem.info.JamQuality); preservesField.SetValue(jamJar, rItem.info.JamIsPreserve); materialStateMethod.Invoke(jamJar, null); } o = (GameObject)jamJar; break; default: break; } return(o); }