Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            base.PrivateUpdate(frame);

            List <NectarMaker> choices = new List <NectarMaker>();
            NectarMaker        best = null, broken = null;

            foreach (Lot lot in ManagerLot.GetOwnedLots(Sim))
            {
                foreach (NectarMaker maker in lot.GetObjects <NectarMaker>())
                {
                    if (!maker.Repairable.Broken)
                    {
                        choices.Add(maker);
                        if (maker.Inventory.IsFull())
                        {
                            best = maker;
                        }
                    }
                    else
                    {
                        broken = maker;
                    }

                    foreach (NectarBottle bottle in maker.mBottles)
                    {
                        Inventories.TryToMove(bottle, Sim.CreatedSim);
                    }

                    AddStat("Collected Bottles", maker.mBottles.Count);

                    maker.mBottles.Clear();
                }
            }

            List <NectarRack> racks = new List <NectarRack>();

            foreach (Lot lot in ManagerLot.GetOwnedLots(Sim))
            {
                foreach (NectarRack rack in lot.GetObjects <NectarRack>())
                {
                    if (rack.HasTreasure())
                    {
                        continue;
                    }

                    if (rack.Buyable)
                    {
                        continue;
                    }

                    if (rack.Tasteable)
                    {
                        continue;
                    }

                    if (rack.Inventory.IsFull())
                    {
                        continue;
                    }

                    racks.Add(rack);
                }
            }

            if (racks.Count > 0)
            {
                List <NectarBottle> bottles = new List <NectarBottle>(Inventories.InventoryFindAll <NectarBottle>(Sim));
                foreach (NectarBottle bottle in bottles)
                {
                    if (!bottle.CanBeSold())
                    {
                        continue;
                    }

                    NectarRack rack = RandomUtil.GetRandomObjectFromList(racks);

                    IncStat("Rack Stored");
                    rack.Inventory.TryToMove(bottle);

                    if (rack.Inventory.IsFull())
                    {
                        racks.Remove(rack);
                        if (racks.Count == 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (best != null)
            {
                choices.Clear();
                choices.Add(best);
            }

            if (choices.Count == 0)
            {
                if (broken != null)
                {
                    IncStat("Attempt Repair");

                    Add(frame, new ScheduledRepairScenario(Sim, broken), ScenarioResult.Start);
                }
                else
                {
                    IncStat("No Choice");
                }
                return(false);
            }

            NectarMaker choice = RandomUtil.GetRandomObjectFromList(choices);

            if (!choice.Inventory.IsFull())
            {
                List <Ingredient> list = new List <Ingredient>(Inventories.InventoryFindAll <Ingredient>(Sim));

                while (list.Count > 0)
                {
                    Ingredient ingredient = RandomUtil.GetRandomObjectFromList(list);
                    list.Remove(ingredient);

                    if (!choice.CanAddToInventory(ingredient))
                    {
                        continue;
                    }

                    if (choice.Inventory.TryToMove(ingredient))
                    {
                        IncStat("Added: " + ingredient.CatalogName);
                    }

                    if (choice.Inventory.IsFull())
                    {
                        break;
                    }
                }
            }

            if (choice.Inventory.IsFull())
            {
                if ((ManagerCareer.HasSkillCareer(Sim, SkillNames.Nectar)) ||
                    (!ManagerCareer.HasSkillCareer(Sim.Household, SkillNames.Nectar)))
                {
                    int skillLevel = Sim.SkillManager.GetSkillLevel(SkillNames.Nectar);

                    List <NectarMaker.MakeNectarStyle> styles = new List <NectarMaker.MakeNectarStyle>();

                    styles.Add(NectarMaker.MakeNectarStyle.Basic);

                    if (skillLevel >= NectarMaker.kConcentratedUnlockLevel)
                    {
                        styles.Add(NectarMaker.MakeNectarStyle.Concentrated);
                    }
                    if (skillLevel >= NectarMaker.kMassProduceUnlockLevel)
                    {
                        styles.Add(NectarMaker.MakeNectarStyle.MassProduce);
                    }
                    if (skillLevel >= NectarMaker.kExtendedNectarationUnlockLevel)
                    {
                        styles.Add(NectarMaker.MakeNectarStyle.ExtendedNectaration);
                    }

                    return(Situations.PushInteraction(this, Sim, choice, new MakeNectarEx.Definition(RandomUtil.GetRandomObjectFromList(styles))));
                }
                else
                {
                    IncStat("Not Job");
                    return(false);
                }
            }
            else
            {
                IncStat("Not Full");
                return(false);
            }
        }
Esempio n. 3
0
 public Definition(NectarMaker.MakeNectarStyle style)
     : base(style)
 { }