Exemple #1
0
        public override bool Run()
        {
            try
            {
                int num;
                if (!Actor.RouteToSlotList(Target, Target.GetRoutingSlots(), out num))
                {
                    return(false);
                }

                StandardEntry();
                EnterStateMachine("junkpile", "Enter", "x", "JunkPile");
                AnimateSim("DigThroughLoop");
                BeginCommodityUpdates();

                bool succeeded = false;
                try
                {
                    float          kMinutesBetweenReceivingScrap = JunkPile.kMinutesBetweenReceivingScrap;
                    InventingSkill skill = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                    if ((skill != null) && skill.OppTheScrapperCompleted)
                    {
                        kMinutesBetweenReceivingScrap *= JunkPile.kTimeMultiplierIfTheScrapper;
                    }
                    if (Autonomous)
                    {
                        kMinutesBetweenReceivingScrap = RandomUtil.RandomFloatGaussianDistribution(0f, (float)JunkPile.kMinutesSimsShouldAutonomouslyDigThrough);
                    }

                    succeeded = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), new Interaction <Sim, JunkPile> .InsideLoopFunction(DigThroughLoopCallback), mCurrentStateMachine, kMinutesBetweenReceivingScrap);
                }
                finally
                {
                    EndCommodityUpdates(succeeded);
                }

                AnimateSim("Exit");
                StandardExit();
                return(succeeded);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
                return(false);
            }
        }
Exemple #2
0
        public static bool AdoptFrankenSim(Sim creator, Sim frankenSim)
        {
            //if (creator.Household.CanAddSpeciesToHousehold(CASAgeGenderFlags.Human))
            {
                string         str   = "AdoptFrankenSim";
                InventingSkill skill = creator.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                if ((skill != null) && skill.OppKnowFrankensimRecipeCompleted)
                {
                    str = "AdoptFrankenSimAgain";
                }

                SimDescription simDescription = frankenSim.SimDescription;
                if (TwoButtonDialog.Show(Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:" + str, new object[] { creator }), Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:AdoptFrankenSimYes", new object[0x0]), Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:AdoptFrankenSimNo", new object[0x0])))
                {
                    VisitSituation situation = VisitSituation.FindVisitSituationInvolvingGuest(frankenSim);
                    if (situation != null)
                    {
                        situation.Exit();
                    }

                    Household.NpcHousehold.Remove(simDescription);
                    creator.Household.Add(simDescription);
                    string str2 = StringInputDialog.Show(Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:AdoptFrankenSimNameTitle", new object[0x0]), Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:AdoptFrankenSimNamePrompt", new object[] { creator }), frankenSim.FirstName);
                    if (!string.IsNullOrEmpty(str2))
                    {
                        simDescription.FirstName = str2;
                    }

                    frankenSim.OnBecameSelectable();
                    return(true);
                }

                Household.NpcHousehold.Remove(simDescription);
                Household household = Household.Create();
                household.Name = simDescription.LastName;
                household.Add(simDescription);
                household.FindSuitableVirtualHome();
                creator.ShowTNSIfSelectable(Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:SimBotNotAdopted", new object[] { creator }), StyledNotification.NotificationStyle.kGameMessagePositive, frankenSim.ObjectId);
                Sim.MakeSimGoHome(frankenSim, false);
                return(false);
            }

            /*
             * string message = Localization.LocalizeString("Gameplay/Objects/HobbiesSkills/Inventing/InventionWorkbench:AdoptFrankenFullHousehold", new object[] { creator });
             * creator.ShowTNSIfSelectable(message, StyledNotification.NotificationStyle.kGameMessageNegative);
             * Sim.MakeSimGoHome(frankenSim, false);
             * return false;
             */
        }
Exemple #3
0
        // Methods
        public new void DigThroughLoopCallback(StateMachineClient smc, Interaction <Sim, JunkPile> .LoopData ld)
        {
            try
            {
                EventTracker.SendEvent(EventTypeId.kLootAJunkPile, Actor, Target);
                if (!Autonomous)
                {
                    int            numScraps = 0x1;
                    InventingSkill skill     = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                    if ((skill != null) && skill.OppTheScrapperCompleted)
                    {
                        numScraps += (int)Math.Ceiling((double)(numScraps * InventingSkill.kTheScraperScrapMultiplier));
                    }
                    ScrapInitParameters initData = new ScrapInitParameters(numScraps);
                    Scrap scrap = GlobalFunctions.CreateObject("scrapPile", ProductVersion.EP2, Vector3.Origin, 0x0, Vector3.UnitZ, null, initData) as Scrap;

                    if (Inventories.TryToMove(scrap, Actor))
                    {
                        mScrapCollected++;
                    }

                    Target.DecrementScrapAmount();
                    if (Target.IsEmpty)
                    {
                        Actor.AddExitReason(ExitReason.Finished);
                    }
                }
                else
                {
                    Actor.AddExitReason(ExitReason.Finished);
                }
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
            }
        }
Exemple #4
0
        private static void CreateInventionAndAddToInventory(InventionData data, Sim Actor, bool isCheapToy, out GameObject invention)
        {
            Simulator.ObjectInitParameters initData = null;
            InventingSkill skill            = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
            bool           isImprovedWidget = false;

            if (data.InventType == InventionType.Widget)
            {
                Widget.Awesomeness standard = Widget.Awesomeness.Standard;
                if (skill.OppMasterInventorCompleted)
                {
                    standard = Widget.Awesomeness.Masterful;
                }
                else if (skill.OppWidgetWonderCompleted)
                {
                    standard = Widget.Awesomeness.Improved;
                }
                else
                {
                    float chance = 0f;
                    if (skill.SkillLevel >= InventionWorkbench.kLevelCanMakeImprovedWidget)
                    {
                        chance += InventionWorkbench.kChanceOfImprovedWidget;
                        if (Actor.HasTrait(TraitNames.Eccentric))
                        {
                            chance += InventionWorkbench.kChanceOfImprovedWidgetEccentric;
                        }
                        if (RandomUtil.RandomChance01(chance))
                        {
                            standard = Widget.Awesomeness.Improved;
                        }
                    }
                }
                isImprovedWidget = standard == Widget.Awesomeness.Improved;
                initData         = new WidgetInitParameters(standard, Actor.SimDescription, data.InventType, data.MedatorName);
            }

            if ((data.InventType == InventionType.Invention) || (data.InventType == InventionType.Toy))
            {
                initData = new CraftedToyInitParameters(skill.OppMasterInventorCompleted, Actor.SimDescription, data.InventType, isCheapToy);
            }

            invention = GlobalFunctions.CreateObject(data.MedatorName, data.ProdVersion, Vector3.OutOfWorld, 0x0, Vector3.UnitZ, null, initData) as GameObject;
            if (invention != null)
            {
                skill.RegisterInventionMade(data);
                if (data.PutInFamilyInventory)
                {
                    if (!Actor.Household.SharedFamilyInventory.Inventory.TryToAdd(invention))
                    {
                        invention.Destroy();
                        invention = null;
                    }
                }
                else if (!Inventories.TryToMove(invention, Actor))
                {
                    invention.Destroy();
                    invention = null;
                }
                if (invention != null)
                {
                    EventTracker.SendEvent(new CreatedInventionEvent(EventTypeId.kCreatedInvention, Actor, invention, data.InventType, isImprovedWidget));
                    if (data.InventType == InventionType.Widget)
                    {
                        EventTracker.SendEvent(EventTypeId.kInventorMadeWidget, Actor);
                    }
                    if (invention is TimeMachine)
                    {
                        EventTracker.SendEvent(EventTypeId.kInventorMadeTimeMachine, Actor);
                    }
                }
            }
        }
Exemple #5
0
        public static void NotifySell(SimDescription sim, GameObject obj, int value)
        {
            try
            {
                obj.SoldFor(value);

                if (obj.CanBeSold())
                {
                    if (IsCollectable(obj))
                    {
                        foreach (SimDescription member in sim.Household.AllSimDescriptions)
                        {
                            Collecting skill = member.SkillManager.GetSkill <Collecting>(SkillNames.Collecting);
                            if (skill != null)
                            {
                                skill.UpdateXpForEarningMoney(value);
                            }
                        }
                    }

                    if (obj.HasFlags(GameObject.FlagField.WasHarvested))
                    {
                        Gardening gardening = sim.SkillManager.GetSkill <Gardening>(SkillNames.Gardening);
                        if (gardening != null)
                        {
                            gardening.HarvestableSold(value);
                        }
                        foreach (SimDescription member in sim.Household.AllSimDescriptions)
                        {
                            gardening = member.SkillManager.GetSkill <Gardening>(SkillNames.Gardening);
                            if (gardening != null)
                            {
                                gardening.UpdateXpForEarningMoney(value);
                            }
                        }
                    }

                    if (obj is INectarBottle)
                    {
                        INectarBottle bottle = obj as INectarBottle;

                        NectarSkill skill = sim.SkillManager.GetSkill <NectarSkill>(SkillNames.Nectar);
                        if (skill != null)
                        {
                            skill.SellNectarBottle(value);
                        }

                        if ((bottle.Creator != null) && (bottle.Creator.IsValid))
                        {
                            skill = bottle.Creator.SkillManager.GetSkill <NectarSkill>(SkillNames.Nectar);
                            if (skill != null)
                            {
                                skill.UpdateXpForEarningMoney(value);
                            }
                        }
                    }

                    if (obj is IInvention)
                    {
                        IInvention invention = obj as IInvention;

                        SimDescription inventor = invention.Inventor;

                        if ((inventor != null) && (inventor.IsValid))
                        {
                            InventingSkill skill2 = inventor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                            if (skill2 != null)
                            {
                                skill2.UpdateXpForEarningMoney(value);
                            }
                        }
                    }

                    if (obj is IScubaCollectible)
                    {
                        ScubaDivingSkill skill3 = sim.SkillManager.AddElement(SkillNames.ScubaDiving) as ScubaDivingSkill;
                        if (skill3 != null)
                        {
                            skill3.SimoleonsFromSellingCollectibles += value;
                            skill3.UpdateXpForEarningMoney(value);
                        }
                    }

                    if (sim.CreatedSim != null)
                    {
                        obj.SendObjectSoldEvent(sim.CreatedSim);
                    }
                }
            }
            catch (Exception e)
            {
                Common.DebugException(sim.CreatedSim, obj, e);
            }
        }
Exemple #6
0
        public override bool Run()
        {
            try
            {
                string str;
                mTimeTravelDef = InteractionDefinition as Definition;
                if (!Target.RouteToMachine(Actor, false, null))
                {
                    return(false);
                }

                if (!TimePortalTravelEx.PreTimeTravel1(this))
                {
                    return(false);
                }

                if (!TimePortalTravelEx.PreTimeTravel2(this))
                {
                    return(false);
                }

                Actor.SimDescription.Contactable = false;
                EnterStateMachine("TimeMachine", "Enter", "x");
                SetActor("timeMachine", Target);
                SetParameter("isFuture", mTimeTravelDef.TimePeriod == TimeMachine.TravelTimePeriod.Future);
                AddOneShotScriptEventHandler(0x3ee, OnEnterAnimationEvent);
                AddOneShotScriptEventHandler(0x66, ToggleHiddenAnimationEvent);
                AnimateSim("GetIn");
                Target.EnableRoutingFootprint(Actor);

                mTimeTravelAlarm = AlarmManager.Global.AddAlarmRepeating(RandomUtil.GetFloat(TimeMachine.kMinutesBetweenAdventureTNSMin, TimeMachine.kMinutesBetweenAdventureTNSMax), TimeUnit.Minutes, new AlarmTimerCallback(TimeTravelCallback), RandomUtil.GetFloat(TimeMachine.kMinutesBetweenAdventureTNSMin, TimeMachine.kMinutesBetweenAdventureTNSMax), TimeUnit.Minutes, "Time Travel Alarm For:" + Actor.SimDescription.FullName, AlarmType.AlwaysPersisted, Actor);
                Target.SetMaterial("InUse");

                bool succeeded = true;
                if (!GameUtils.IsFutureWorld())
                {
                    // Custom
                    succeeded = TimePortalEx.TravelToFuture(null, Actor, new List <Sim>(), new List <ulong>());
                }

                succeeded = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached));

                EndCommodityUpdates(succeeded);
                Target.PickExitStateAndSound(mTimeTravelDef.TimePeriod, out str, out mExitSound);
                AddOneShotScriptEventHandler(0x3e9, OnExitAnimationEvent);
                AddOneShotScriptEventHandler(0x3ef, OnExitAnimationEvent);
                AddOneShotScriptEventHandler(0x67, ToggleHiddenAnimationEvent);
                AnimateSim(str);

                if (!TimePortalTravelEx.PostTimeTravel1(this, succeeded))
                {
                    return(false);
                }

                Target.SetMaterial("default");
                AnimateSim("Exit");
                if (!string.IsNullOrEmpty(mTravelSummary))
                {
                    Actor.ShowTNSIfSelectable(mTravelSummary, StyledNotification.NotificationStyle.kGameMessagePositive, Target.ObjectId, Actor.ObjectId);
                }

                StandardExit();
                Target.Repairable.UpdateBreakage(Actor);
                InventingSkill skill = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                if (succeeded && (skill != null))
                {
                    skill.RegisterTimeTravelDone();
                }

                if (GameUtils.IsFutureWorld())
                {
                    EventTracker.SendEvent(EventTypeId.kTravelToPresent, Actor);

                    // Custom
                    GameStatesEx.UpdateTelemetryAndTriggerTravelBackToHomeWorld();
                }

                return(succeeded);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
                return(false);
            }
            finally
            {
                TravelUtil.PlayerMadeTravelRequest = false;
            }
        }
Exemple #7
0
 public override bool Run()
 {
     try{
         if (!Target.SimLine.WaitForTurn(this, SimQueue.WaitBehavior.DefaultEvict,
                                         ~(ExitReason.Replan |
                                           ExitReason.MidRoutePushRequested |
                                           ExitReason.ObjectStateChanged |
                                           ExitReason.PlayIdle |
                                           ExitReason.MaxSkillPointsReached), Shower.kTimeToWaitToEvict))
         {
             return(false);
         }
         try{
             mSwitchOutfitHelper = new Sim.SwitchOutfitHelper(Actor, Sim.ClothesChangeReason.GoingToBathe);
         }catch {
             return(false);
         }
         mSwitchOutfitHelper.Start();
         if (Actor.HasTrait(TraitNames.Hydrophobic))
         {
             Actor.PlayReaction(ReactionTypes.WhyMe, Target as GameObject, ReactionSpeed.ImmediateWithoutOverlay);
         }
         if (Actor.HasTrait(TraitNames.Daredevil))
         {
             TraitTipsManager.ShowTraitTip(0xb82d0015b9294260L, Actor, TraitTipsManager.TraitTipCounterIndex.Daredevil, TraitTipsManager.kDaredevilCountOfShowersTaken);
         }
         if (!Actor.RouteToSlotAndCheckInUse(Target, Slot.RoutingSlot_0))
         {
             return(false);
         }
         //    mSituation=new Shower.ShowerPrivacySituation(this);
         //if(!mSituation.Start()){
         //        return(false);
         //}
         StandardEntry();
         if (!Actor.RouteToSlot(Target, Slot.RoutingSlot_0))
         {
             if (mSituation != null)
             {
                 mSituation.Exit();
             }
             StandardExit();
             return(false);
         }
         if (Autonomous)
         {
             mPriority = new InteractionPriority(InteractionPriorityLevel.UserDirected);
         }
         mSwitchOutfitHelper.Wait(true);
         bool daredevilPerforming =
             Actor.DaredevilPerforming;
         bool flag2 = Actor.GetCurrentOutfitCategoryFromOutfitInGameObject() == OutfitCategories.Singed;
         EnterStateMachine("Shower", "Enter", "x");
         SetActor("Shower", Target);
         if (mSituation != null)
         {
             mSituation.StateMachine = mCurrentStateMachine;
         }
         SetParameter("IsShowerTub", Target.IsShowerTub);
         SetParameter("SimShouldCloseDoor", true);
         SetParameter("SimShouldClothesChange", ((!daredevilPerforming && !flag2) && !Actor.OccultManager.DisallowClothesChange()) && !Actor.BuffManager.DisallowClothesChange());
         bool paramValue = false;
         if ((Target.BoobyTrapComponent != null) && Target.BoobyTrapComponent.CanTriggerTrap(Actor.SimDescription))
         {
             paramValue = !Actor.OccultManager.DisallowClothesChange() && !Actor.BuffManager.DisallowClothesChange();
         }
         SimDescription description = ((Target.BoobyTrapComponent != null) && (Target.BoobyTrapComponent.TrapSetter != 0L)) ? SimDescription.Find(Target.BoobyTrapComponent.TrapSetter) : null;
         if (((description != null) && description.IsFairy) && Actor.BuffManager.HasElement(BuffNames.TrickedByAFairy))
         {
             paramValue = false;
         }
         SetParameter("isBoobyTrapped", paramValue);
         mSwitchOutfitHelper.AddScriptEventHandler(this);
         AddOneShotScriptEventHandler(0x3e9, EventCallbackStartShoweringSound);
         if (Actor.HasTrait(TraitNames.Virtuoso) || RandomUtil.RandomChance((float)Target.TuningShower.ChanceOfSinging))
         {
             AddOneShotScriptEventHandler(0xc8, EventCallbackStartSinging);
         }
         PetStartleBehavior.CheckForStartle(Target as GameObject, StartleType.ShowerOn);
         AnimateSim("Loop Shower");
         Actor.BuffManager.AddElement(BuffNames.SavingWater, Origin.FromShower, ProductVersion.EP2, TraitNames.EnvironmentallyConscious);
         mShowerStage.ResetCompletionTime(GetShowerTime());
         StartStages();
         if (Actor.HasTrait(TraitNames.EnvironmentallyConscious))
         {
             BeginCommodityUpdate(CommodityKind.Hygiene, Shower.kEnvironmentallyConsciousShowerSpeedMultiplier);
         }
         if (Actor.SimDescription.IsPlantSim)
         {
             ModifyCommodityUpdate(CommodityKind.Hygiene, Shower.kPlantSimHygieneModifier);
         }
         BeginCommodityUpdates();
         if (paramValue)
         {
             ApplyBoobyTrapOutfit();
             if ((description != null) && description.IsFairy)
             {
                 Actor.BuffManager.AddElement(BuffNames.TrickedByAFairy, Origin.FromFairy);
             }
         }
         bool succeeded = (false);
         try{
             try{
                 Target.SimInShower = Actor;
                 succeeded          = DoLoop(~(
                                                 ExitReason.Replan |
                                                 ExitReason.MidRoutePushRequested |
                                                 ExitReason.ObjectStateChanged |
                                                 ExitReason.PlayIdle |
                                                 ExitReason.MaxSkillPointsReached), DuringShower, null);
                 if (HavingWooHoo && Actor.HasExitReason(ExitReason.StageComplete))
                 {
                     succeeded = DoLoop(~(
                                            ExitReason.Replan |
                                            ExitReason.MidRoutePushRequested |
                                            ExitReason.ObjectStateChanged |
                                            ExitReason.PlayIdle |
                                            ExitReason.MaxSkillPointsReached |
                                            ExitReason.StageComplete), DuringShower, null);
                 }
             }finally{
                 Target.SimInShower = null;
             }
             while (HavingWooHoo)
             {
                 SpeedTrap.Sleep(10);
             }
         }finally{
             EndCommodityUpdates(succeeded);
         }
         Shower.WaitToLeaveShower(Actor, Target);
         if (succeeded)
         {
             Shower.ApplyPostShowerEffects(Actor, Target);
         }
         if (paramValue)
         {
             SetParameter("isBoobyTrapped", false);
             AddOneShotScriptEventHandler(0xc9, EventCallbackStopSinging);
             AddOneShotScriptEventHandler(0x3ea, EventCallbackStopShoweringSound);
             if ((description != null) && description.IsFairy)
             {
                 AnimateSim("TriggerFairyTrap");
             }
             else
             {
                 AnimateSim("Booby Trap Reaction");
             }
             AddOneShotScriptEventHandler(0x3e9, EventCallbackStartShoweringSound);
             AnimateSim("Loop Shower");
             RemoveBoobyTrapOutfit();
             SpeedTrap.Sleep(60);
         }
         try{
             if (flag2 && succeeded)
             {
                 mSwitchOutfitHelper.Dispose();
                 try{
                     mSwitchOutfitHelper = new Sim.SwitchOutfitHelper(Actor, Sim.ClothesChangeReason.GoingToBathe);
                     mSwitchOutfitHelper.Start();
                     mSwitchOutfitHelper.Wait(false);
                     mSwitchOutfitHelper.ChangeOutfit();
                 }catch {}
             }
             bool flag5 = (false);
             if ((flag2 && succeeded) || (!flag2 && !daredevilPerforming))
             {
                 SetParameter("SimShouldClothesChange", !Actor.OccultManager.DisallowClothesChange());
                 mSwitchOutfitHelper.Dispose();
                 try{
                     mSwitchOutfitHelper = new Sim.SwitchOutfitHelper(Actor, GetOutfitReason(Actor));
                     mSwitchOutfitHelper.Start();
                     mSwitchOutfitHelper.AddScriptEventHandler(this);
                     mSwitchOutfitHelper.Wait(false);
                 }catch {}
                 flag5 = (true);
             }
             Target.Cleanable.DirtyInc(Actor);
             AddOneShotScriptEventHandler(0xc9, EventCallbackStopSinging);
             AddOneShotScriptEventHandler(0x3ea, EventCallbackStopShoweringSound);
             if (flag5 && InventingSkill.IsBeingDetonated(Target as GameObject))
             {
                 SetParameter("SimShouldClothesChange", false);
                 mSwitchOutfitHelper.Abort();
                 mSwitchOutfitHelper.Dispose();
             }
             if (Target.Repairable.UpdateBreakage(Actor))
             {
                 Target.StartBrokenFXInAnim(mCurrentStateMachine);
                 AnimateSim("Exit Broken");
             }
             else
             {
                 AnimateSim("Exit Working");
             }
             if ((Actor.SimDescription.IsMummy || Actor.DaredevilPerforming) || (Actor.TraitManager.HasElement(TraitNames.Slob) && RandomUtil.RandomChance01(TraitTuning.SlobTraitChanceToLeavePuddle)))
             {
                 PuddleManager.AddPuddle(Actor.Position);
             }
             if (succeeded)
             {
                 Actor.BuffManager.RemoveElement(BuffNames.GotFleasHuman);
             }
         }finally{
             StandardExit();
         }
         return(succeeded);
     }catch (ResetException exception) {
         Alive.WriteLog(exception.Message + "\n\n" +
                        exception.StackTrace + "\n\n" +
                        exception.Source);
         return(false);
     }catch (Exception exception) {
         Alive.WriteLog(exception.Message + "\n\n" +
                        exception.StackTrace + "\n\n" +
                        exception.Source);
         return(false);
     }
 }
Exemple #8
0
        public override bool Run()
        {
            try
            {
                if (!Target.RouteToWorkbench(Actor))
                {
                    return(false);
                }

                mMakeFemale  = Target.mIsMakingFemaleFrankensim;
                mInventSkill = Actor.SkillManager.AddElement(SkillNames.Inventing) as InventingSkill;
                bool flag = Target.mInventionProgress > 0f;
                if (!flag)
                {
                    Definition interactionDefinition = InteractionDefinition as Definition;
                    mMakeFemale = interactionDefinition.MakeFemale;
                    Target.mIsMakingFemaleFrankensim = mMakeFemale;
                    ConsumeIngredients();
                }

                StandardEntry();
                Target.mIsMakingFrankensim      = true;
                Target.mFrankenSimInventorSimId = Actor.SimDescription.SimDescriptionId;
                StartStages();
                mTimeUntilModelSwap = GetTimeForNextModelChange();
                EnterStateMachine("WorkbenchInvention", "Enter", "x", "workstation");
                SetParameter("shouldSwipe", !flag);
                SetParameter("skillLevel", InventionWorkbench.GetSkillLevelParam(mInventSkill));
                if (!flag)
                {
                    AddSynchronousOneShotScriptEventHandler(0x67, OnAnimationEvent);
                }

                mTotalTime = GetTimeToCompletion();
                AnimateSim("Loop Invent");
                BeginCommodityUpdates();
                if (Actor.SimDescription.TeenOrAbove)
                {
                    Actor.SkillManager.StartGainWithoutSkillMeter(SkillNames.Handiness, InventionWorkbench.kHandinessSkillGainRateDuringMake, true);
                }

                bool succeeded = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), MakeLoopCallback, mCurrentStateMachine);
                if (Actor.SimDescription.TeenOrAbove)
                {
                    Actor.SkillManager.StopSkillGain(SkillNames.Handiness);
                }

                EndCommodityUpdates(succeeded);
                AnimateSim("Exit");
                if (!mRecipeKnown && !Actor.OpportunityManager.HasOpportunity(OpportunityNames.EP2_SkillInventing_Frankensim4))
                {
                    Target.ScrapCurrentInvention();
                }

                if (Target.mInventionProgress >= 1f)
                {
                    Sims3.Gameplay.Gameflow.SetGameSpeed(Sims3.Gameplay.Gameflow.GameSpeed.Normal, Sims3.Gameplay.Gameflow.SetGameSpeedContext.Gameplay);
                    RouteAwayFromTable();
                    Target.mDummyModel.UnParent();
                    Target.mDummyModel.Destroy();
                    Target.mDummyModel               = null;
                    Target.mInventionProgress        = 0f;
                    Target.mIsMakingFrankensim       = false;
                    Target.mFrankenSimInventorSimId  = 0x0L;
                    Target.mIsMakingFemaleFrankensim = false;
                    Target.mWasFinishedByGnome       = false;
                    Target.mIsMakingCheapToy         = false;
                    CASAgeGenderFlags gender = mMakeFemale ? CASAgeGenderFlags.Female : CASAgeGenderFlags.Male;
                    mFrankensim = OccultFrankenstein.CreateFrankenStein(Actor, gender);
                    mFrankensim.FadeOut(false, false, 0f);
                    mFrankensim.GreetSimOnLot(Target.LotCurrent);
                    mFrankensim.SetPosition(Target, Slot.RoutingSlot_1);
                    mFrankensim.SetForward((Vector3)(Slots.GetForwardOfSlot(Target.ObjectId, Slot.RoutingSlot_1) * -1f));
                    mFrankensim.AddToWorld();
                    InventingSkill skill = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing);
                    if (!skill.OppKnowFrankensimRecipeCompleted)
                    {
                        EventTracker.SendEvent(EventTypeId.kDiscoveredNewInvention, Actor, mFrankensim);
                    }
                    mCurrentStateMachine = StateMachineClient.Acquire(mFrankensim, "WorkbenchFrankensim", AnimationPriority.kAPDefault);
                    SetActor("workstation", Target);
                    SetActor("x", mFrankensim);
                    SetActor("y", Actor);
                    AddSynchronousOneShotScriptEventHandler(0x65, OnAnimationEvent);
                    EnterState("x", "Enter");
                    AnimateSim("Exit");
                    AdoptFrankenSim(Actor, mFrankensim);
                    skill.KnowsFrankensimRecipe = true;
                    skill.TestForNewLifetimeOpp();
                    EventTracker.SendEvent(EventTypeId.kFrankensimLearned, Actor);
                }

                StandardExit();
                return(succeeded);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
                return(false);
            }
        }
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            base.PrivateUpdate(frame);

            InventingSkill skill = Sim.SkillManager.GetElement(SkillNames.Inventing) as InventingSkill;

            List <InventionWorkbench> benches = new List <InventionWorkbench>();
            List <InventionWorkbench> empties = new List <InventionWorkbench>();

            foreach (Lot lot in ManagerLot.GetOwnedLots(Sim))
            {
                foreach (InventionWorkbench bench in lot.GetObjects <InventionWorkbench>())
                {
                    if (bench.InUse)
                    {
                        continue;
                    }

                    if (bench.mIsMakingFrankensim)
                    {
                        continue;
                    }

                    if (bench.mInventionProgress > 0)
                    {
                        if (skill == null)
                        {
                            continue;
                        }

                        if (!skill.KnownInventions.Contains(bench.mInventionKey))
                        {
                            continue;
                        }

                        benches.Add(bench);
                    }
                    else
                    {
                        empties.Add(bench);
                    }
                }
            }

            if (benches.Count == 0)
            {
                benches.AddRange(empties);

                if (benches.Count == 0)
                {
                    IncStat("No Bench");
                    return(false);
                }
            }

            int minimumScrap   = InventionWorkbench.kNumScrapsPerDiceRoll * 10;
            int inventoryScrap = Inventories.InventoryFindAll <Scrap>(Sim).Count;

            if (inventoryScrap < minimumScrap)
            {
                List <JunkPile> piles = new List <JunkPile>();
                foreach (JunkPile pile in Sims3.Gameplay.Queries.GetObjects <JunkPile>())
                {
                    if (pile.IsEmpty)
                    {
                        continue;
                    }

                    if (pile.LotCurrent == Sim.LotHome)
                    {
                        piles.Add(pile);
                    }
                    else if (pile.LotCurrent == null)
                    {
                        continue;
                    }
                    else if (pile.LotCurrent.IsCommunityLot)
                    {
                        piles.Add(pile);
                    }
                }

                bool success = false;

                while (piles.Count > 0)
                {
                    JunkPile junkChoice = RandomUtil.GetRandomObjectFromList(piles);
                    piles.Remove(junkChoice);

                    if (!Situations.PushInteraction(this, Sim, junkChoice, DigThroughEx.Singleton))
                    {
                        break;
                    }

                    IncStat("Push Dig Through");

                    success = true;
                }

                if (!success)
                {
                    Money.AdjustFunds(Sim, "BuyItem", -InventionWorkbench.Restock.GetScrapCost(minimumScrap - inventoryScrap));

                    AddStat("Buy Scrap", minimumScrap - inventoryScrap);

                    CreateScrap(Sim.CreatedSim, minimumScrap - inventoryScrap);
                }
                else
                {
                    return(true);
                }
            }

            InventionWorkbench choice = RandomUtil.GetRandomObjectFromList(benches);

            if (choice.mInventionProgress > 0)
            {
                IncStat("Try Continue");

                if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                {
                    return(true);
                }

                IncStat("Continue Fail");
                return(false);
            }
            else
            {
                if ((skill != null) && (skill.GetUndiscoveredInventions().Count == 0x0) && (skill.ReachedMaxLevel()))
                {
                    IncStat("Try Start New");

                    if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                    {
                        return(true);
                    }

                    IncStat("Start New Fail");
                    return(false);
                }
                else
                {
                    if ((skill == null) || (skill.KnownInventions.Count == 0) || (RandomUtil.RandomChance(25)))
                    {
                        IncStat("Try Invent");

                        if (Situations.PushInteraction(this, Sim, choice, new InventionWorkbench.Invent.Definition()))
                        {
                            return(true);
                        }

                        IncStat("Invent Fail");
                        return(false);
                    }
                    else
                    {
                        IncStat("Try Start New");

                        if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                        {
                            return(true);
                        }

                        IncStat("Start New Fail");
                        return(false);
                    }
                }
            }
        }