コード例 #1
0
ファイル: CommonMethods.cs プロジェクト: yakoder/NRaas
        /// <summary>
        /// Returns a list of items from the store's inventory
        /// </summary>
        /// <param name="sim"></param>
        /// <returns></returns>
        public static List <GameObject> ItemDictionary(Sim actor, RegisterType type, Lot lot)
        {
            //Nuutti
            //Get all treasure boxes on this lot
            List <GameObject>    list  = new List <GameObject>();
            List <TreasureChest> tList = ReturnTreasureChests(actor, lot);

            foreach (TreasureChest tChest in tList)
            {
                List <GameObject> cInventoryItems = tChest.Inventory.FindAll <GameObject>(false);

                //Go through list and filter
                foreach (var item in cInventoryItems)
                {
                    ItemType  itemType  = ItemType.General;
                    DriedFood driedFood = item as DriedFood;
                    Morsel    _morsel   = item as Morsel;

                    if (driedFood != null || _morsel != null || item.GetType() == typeof(Morsel) || item.GetType() == typeof(PlateServing) ||
                        item.GetType() == typeof(Ingredient) ||
                        item.GetType() == typeof(Cake) ||
                        item.GetType() == typeof(Fish))
                    {
                        itemType = ItemType.Food;
                    }
                    else
                    {
                        NectarBottle nectar = item as NectarBottle;
                        Book         book   = item as Book;
                        if (book != null)
                        {
                            itemType = ItemType.Book;
                        }
                        else if (nectar != null)
                        {
                            itemType = ItemType.Nectar;
                        }
                    }

                    //Add only to the correct type of register
                    if (type == RegisterType.Food && itemType == ItemType.Food)
                    {
                        list.Add(item);
                    }
                    else if (type == RegisterType.Books && itemType == ItemType.Book)
                    {
                        list.Add(item);
                    }
                    else if (type == RegisterType.General && (itemType == ItemType.General || AddMenuItem.ReturnSellIngInGeneralRegister()))
                    {
                        list.Add(item);
                    }
                    else if (type == RegisterType.Nectar && itemType == ItemType.Nectar)
                    {
                        list.Add(item);
                    }
                }
            }

            return(list);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: MakeNectarEx.cs プロジェクト: yakoder/NRaas
        protected void FinishedMakingNectarCallback()
        {
            string msg = null;

            try
            {
                List <Ingredient> fruitsUsed = Inventories.QuickFind <Ingredient>(Target.Inventory);
                foreach (GameObject obj2 in fruitsUsed)
                {
                    Target.Inventory.SetNotInUse(obj2);
                }

                msg += "1";

                if (((fruitsUsed != null) && (fruitsUsed.Count > 0x0)) && (Target.mLastSimToMake != null))
                {
                    float num        = 0f;
                    float num2       = (((float)RandomGen.NextDouble()) * (NectarMaker.kMaxGlobalValueVariance - NectarMaker.kMinGlobalValueVariance)) + NectarMaker.kMinGlobalValueVariance;
                    int   skillLevel = Target.mLastSimToMake.SkillManager.GetSkillLevel(SkillNames.Nectar);
                    float num4       = ((NectarMaker.kLevel10Multiplier - NectarMaker.kLevel0Multiplier) * (((float)skillLevel) / 10f)) + NectarMaker.kLevel0Multiplier;
                    fruitsUsed.Sort();
                    string     str        = "";
                    bool       flag       = true;
                    Ingredient ingredient = fruitsUsed[0x0];
                    string     key        = "";
                    Dictionary <string, int> ingredients = new Dictionary <string, int>();
                    if (ingredient != null)
                    {
                        key = ingredient.Data.Key;
                    }

                    msg += "2";

                    float num5 = 0f;
                    foreach (Ingredient ingredient2 in fruitsUsed)
                    {
                        if (flag && !key.Equals(ingredient2.Data.Key))
                        {
                            flag = false;
                        }
                        str = str + ingredient2.Data.Key;
                        if (!ingredients.ContainsKey(ingredient2.Data.Key))
                        {
                            ingredients.Add(ingredient2.Data.Key, 0x1);
                        }
                        else
                        {
                            ingredients[ingredient2.Data.Key]++;
                        }
                        num  += ingredient2.Data.NectarValue;
                        num5 += (float)ingredient2.GetQuality();
                        Target.Inventory.TryToRemove(ingredient2);
                    }

                    msg += "3";

                    num5 /= (float)fruitsUsed.Count;
                    uint  hash = ResourceUtils.HashString32(str);
                    float num7 = 1f;
                    if (!flag)
                    {
                        num7 = NectarMaker.CalculateHashMultiplier(hash);
                    }

                    msg += "4";

                    float       makeStyleValueModifier  = Target.GetMakeStyleValueModifier(Target.mLastUsedMakeStyle);
                    int         makeStyleBottleModifier = Target.GetMakeStyleBottleModifier(Target.mLastUsedMakeStyle);
                    float       baseValue  = ((((((num * num2) * num4) * Target.mFlavorMultiplier) * num7) * NectarMaker.kQualityLevelMultiplier[((int)num5) - 0x1]) * Target.mMultiplierFromFeet) * makeStyleValueModifier;
                    int         numBottles = (NectarMaker.kNumBottlesPerBatch + Target.mBottleDifference) + makeStyleBottleModifier;
                    NectarSkill skill      = Target.mLastSimToMake.SkillManager.GetSkill <NectarSkill>(SkillNames.Nectar);
                    if ((skill != null) && skill.IsNectarMaster())
                    {
                        numBottles += NectarSkill.kExtraBottlesNectarMaster;
                    }

                    msg += "5";

                    List <NectarMaker.IngredientNameCount> list2 = new List <NectarMaker.IngredientNameCount>();
                    foreach (string str3 in ingredients.Keys)
                    {
                        list2.Add(new NectarMaker.IngredientNameCount(str3, ((float)ingredients[str3]) / ((float)fruitsUsed.Count)));
                    }

                    msg += "6";

                    list2.Sort();
                    string str4 = "";
                    string str5 = "";
                    if (list2.Count > 0x0)
                    {
                        str4 = IngredientData.NameToDataMap[list2[0x0].IngredientName].Name;
                    }
                    if (list2.Count > 0x1)
                    {
                        str5 = IngredientData.NameToDataMap[list2[0x1].IngredientName].Name;
                    }

                    msg += "7";

                    List <NectarSkill.NectarBottleInfo> topNectarsMade = new List <NectarSkill.NectarBottleInfo>();
                    if (skill != null)
                    {
                        topNectarsMade = skill.mTopNectarsMade;
                    }

                    msg += "8";

                    string defaultEntryText = "";
                    if (string.IsNullOrEmpty(str5))
                    {
                        defaultEntryText = Common.LocalizeEAString(false, "Gameplay/Objects/CookingObjects/NectarBottle:NectarNameOneFruit", new object[] { str4 });
                    }
                    else
                    {
                        defaultEntryText = Common.LocalizeEAString(false, "Gameplay/Objects/CookingObjects/NectarBottle:NectarName", new object[] { str4, str5 });
                        if (defaultEntryText.Length > 0x28)
                        {
                            defaultEntryText = Common.LocalizeEAString(false, "Gameplay/Objects/CookingObjects/NectarBottle:NectarNameOneFruit", new object[] { str4 });
                        }
                    }

                    msg += "9";

                    bool nameFound = false;
                    foreach (NectarSkill.NectarBottleInfo info in topNectarsMade)
                    {
                        if (info.mFruitHash == hash)
                        {
                            defaultEntryText = info.mBottleName;
                            nameFound        = true;
                        }
                    }

                    msg += "A";

                    bool promptName = false;

                    string entryKey = "Gameplay/Objects/HobbiesSkills/NectarMaker:";
                    if (flag)
                    {
                        entryKey = entryKey + "NameBottleDialogJustOneFruit";
                    }
                    else if (num7 < NectarMaker.kPoorComboThreshold)
                    {
                        entryKey = entryKey + "NameBottleDialogTerribly";
                    }
                    else if (num7 < NectarMaker.kWellComboThreshold)
                    {
                        entryKey = entryKey + "NameBottleDialogPoor";
                    }
                    else if (num7 < NectarMaker.kGreatComboThreshold)
                    {
                        entryKey = entryKey + "NameBottleDialogWell";
                    }
                    else if (num7 < NectarMaker.kAmazingComboThreshold)
                    {
                        entryKey   = entryKey + "NameBottleDialogGreat";
                        promptName = true;
                    }
                    else
                    {
                        entryKey   = entryKey + "NameBottleDialogAmazing";
                        promptName = true;
                    }

                    msg += "B";

                    string name = defaultEntryText;

                    if (promptName)
                    {
                        if ((!nameFound) && (NRaas.StoryProgression.Main.GetValue <NectarPushScenario.NameGreatNectarOption, bool>()))
                        {
                            name = StringInputDialog.Show(Actor.SimDescription.FullName, Common.LocalizeEAString(entryKey), defaultEntryText, 0x28, StringInputDialog.Validation.ObjectRequireName);
                        }
                        else
                        {
                            List <object> parameters = StoryProgression.Main.Stories.AddGenderNouns(Actor.SimDescription);
                            parameters.Add(defaultEntryText);

                            Common.Notify(Common.Localize("MadeNectar:Results", Actor.IsFemale, parameters.ToArray()), Actor.ObjectId);
                        }
                    }

                    msg += "C";

                    bool flag2 = false;
                    if (skill != null)
                    {
                        skill.MadeXBottles(numBottles);
                        skill.UsedFruits(fruitsUsed);
                        skill.NectarTypeMade(new NectarSkill.NectarBottleInfo(hash, name, ingredients, (int)baseValue));
                        flag2 = skill.ReachedMaxLevel();
                    }

                    msg += "D";

                    int dateNum = ((int)SimClock.ConvertFromTicks(GameStates.TimeInHomeworld.Ticks, TimeUnit.Weeks)) + 0x1;
                    for (int i = 0x0; i < numBottles; i++)
                    {
                        NectarBottle item = GlobalFunctions.CreateObjectOutOfWorld("NectarBottle", null, new NectarBottleObjectInitParams(hash, name, list2, "Gameplay/Objects/HobbiesSkills/NectarMaker:Weeks", dateNum, baseValue, baseValue, Target.mLastSimToMake, flag2)) as NectarBottle;
                        Target.mBottles.Add(item);
                        EventTracker.SendEvent(EventTypeId.kMadeNectar, Target.mLastSimToMake.CreatedSim, item);
                    }
                    if (Target.mBottles.Count > 0x0)
                    {
                        Target.mCurrentStateMachine.SetActor("nectarBottle", Target.mBottles[0x0]);
                    }

                    msg += "E";

                    Target.mCurrentStateMachine.RequestState("nectarMaker", "Exit");
                    Target.mCurrentStateMachine.Dispose();
                    Target.mCurrentStateMachine = null;
                    Target.mMultiplierFromFeet  = 1f;
                    Target.mLastUsedMakeStyle   = NectarMaker.MakeNectarStyle.Basic;
                    Target.mLastSimToMake       = null;
                    Target.CurrentState         = NectarMaker.NectarMakerState.FruitAddable;

                    msg += "F";
                }
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, msg, e);
            }
        }