示例#1
0
        // From SimDescription.Instantiate
        private static Sim Perform(SimDescription ths, Vector3 position, ResourceKey outfitKey, bool forceAlwaysAnimate, OnReset reset)
        {
            Household.HouseholdSimsChangedCallback changedCallback = null;
            Household changedHousehold = null;

            bool isChangingWorlds = GameStates.sIsChangingWorlds;

            bool isLifeEventManagerEnabled = LifeEventManager.sIsLifeEventManagerEnabled;

            Corrections.RemoveFreeStuffAlarm(ths);

            using (SafeStore store = new SafeStore(ths, SafeStore.Flag.LoadFixup | SafeStore.Flag.Selectable | SafeStore.Flag.Unselectable))
            {
                try
                {
                    // Stops the memories system from interfering
                    LifeEventManager.sIsLifeEventManagerEnabled = false;

                    // Stops UpdateInformationKnownAboutRelationships()
                    GameStates.sIsChangingWorlds = true;

                    if (ths.Household != null)
                    {
                        changedCallback = ths.Household.HouseholdSimsChanged;
                        changedHousehold = ths.Household;

                        ths.Household.HouseholdSimsChanged = null;
                    }

                    if (ths.CreatedSim != null)
                    {
                        AttemptToPutInSafeLocation(ths.CreatedSim, false);

                        if (reset != null)
                        {
                            ths.CreatedSim.SetObjectToReset();

                            reset(ths.CreatedSim, false);
                        }

                        return ths.CreatedSim;
                    }

                    if (ths.AgingState != null)
                    {
                        bool flag = outfitKey == ths.mDefaultOutfitKey;

                        ths.AgingState.SimBuilderTaskDeferred = false;

                        ths.AgingState.PreInstantiateSim(ref outfitKey);
                        if (flag)
                        {
                            ths.mDefaultOutfitKey = outfitKey;
                        }
                    }

                    int capacity = forceAlwaysAnimate ? 0x4 : 0x2;
                    Hashtable overrides = new Hashtable(capacity);
                    overrides["simOutfitKey"] = outfitKey;
                    overrides["rigKey"] = CASUtils.GetRigKeyForAgeGenderSpecies((ths.Age | ths.Gender) | ths.Species);
                    if (forceAlwaysAnimate)
                    {
                        overrides["enableSimPoseProcessing"] = 0x1;
                        overrides["animationRunsInRealtime"] = 0x1;
                    }

                    string instanceName = "GameSim";
                    ProductVersion version = ProductVersion.BaseGame;
                    if (ths.Species != CASAgeGenderFlags.Human)
                    {
                        instanceName = "Game" + ths.Species;
                        version = ProductVersion.EP5;
                    }

                    SimInitParameters initData = new SimInitParameters(ths);
                    Sim target = GlobalFunctions.CreateObjectWithOverrides(instanceName, version, position, 0x0, Vector3.UnitZ, overrides, initData) as Sim;
                    if (target != null)
                    {
                        if (target.SimRoutingComponent == null)
                        {
                            // Performed to ensure that a useful error message is produced when the Sim construction fails
                            target.OnCreation();
                            target.OnStartup();
                        }

                        target.SimRoutingComponent.EnableDynamicFootprint();
                        target.SimRoutingComponent.ForceUpdateDynamicFootprint();

                        ths.PushAgingEnabledToAgingManager();

                        /* This code is idiotic
                        if ((ths.Teen) && (target.SkillManager != null))
                        {
                            Skill skill = target.SkillManager.AddElement(SkillNames.Homework);
                            while (skill.SkillLevel < SimDescription.kTeenHomeworkSkillStartLevel)
                            {
                                skill.ForceGainPointsForLevelUp();
                            }
                        }
                        */

                        // Custom
                        OccultTypeHelper.SetupForInstantiatedSim(ths.OccultManager);

                        if (ths.IsAlien)
                        {
                            World.ObjectSetVisualOverride(target.ObjectId, eVisualOverrideTypes.Alien, null);
                        }

                        AttemptToPutInSafeLocation(target, false);

                        EventTracker.SendEvent(EventTypeId.kSimInstantiated, null, target);

                        /*
                        MiniSimDescription description = MiniSimDescription.Find(ths.SimDescriptionId);
                        if ((description == null) || (!GameStates.IsTravelling && (ths.mHomeWorld == GameUtils.GetCurrentWorld())))
                        {
                            return target;
                        }
                        description.UpdateInWorldRelationships(ths);
                        */

                        if (ths.HealthManager != null)
                        {
                            ths.HealthManager.Startup();
                        }

                        if (((ths.SkinToneKey.InstanceId == 15475186560318337848L) && !ths.OccultManager.HasOccultType(OccultTypes.Vampire)) && (!ths.OccultManager.HasOccultType(OccultTypes.Werewolf) && !ths.IsGhost))
                        {
                            World.ObjectSetVisualOverride(ths.CreatedSim.ObjectId, eVisualOverrideTypes.Genie, null);
                        }

                        if (ths.Household.IsAlienHousehold)
                        {
                            (Sims3.UI.Responder.Instance.HudModel as HudModel).OnSimCurrentWorldChanged(true, ths);
                        }

                        if (Household.RoommateManager.IsNPCRoommate(ths.SimDescriptionId))
                        {
                            Household.RoommateManager.AddRoommateInteractions(target);
                        }
                    }

                    return target;
                }
                finally
                {
                    LifeEventManager.sIsLifeEventManagerEnabled = isLifeEventManagerEnabled;

                    GameStates.sIsChangingWorlds = isChangingWorlds;

                    if ((changedHousehold != null) && (changedCallback != null))
                    {
                        changedHousehold.HouseholdSimsChanged = changedCallback;

                        if (changedHousehold.HouseholdSimsChanged != null)
                        {
                            changedHousehold.HouseholdSimsChanged(Sims3.Gameplay.CAS.HouseholdEvent.kSimAdded, ths.CreatedSim, null);
                        }
                    }
                }
            }
        }        
示例#2
0
        // From SimDescription.Instantiate
        private static Sim Perform(SimDescription ths, Vector3 position, ResourceKey outfitKey, bool forceAlwaysAnimate, OnReset reset)
        {
            Household.HouseholdSimsChangedCallback changedCallback = null;
            Household changedHousehold = null;

            bool isChangingWorlds = GameStates.sIsChangingWorlds;

            bool isLifeEventManagerEnabled = LifeEventManager.sIsLifeEventManagerEnabled;

            Corrections.RemoveFreeStuffAlarm(ths);

            using (SafeStore store = new SafeStore(ths, SafeStore.Flag.LoadFixup | SafeStore.Flag.Selectable | SafeStore.Flag.Unselectable))
            {
                try
                {
                    // Stops the memories system from interfering
                    LifeEventManager.sIsLifeEventManagerEnabled = false;

                    // Stops UpdateInformationKnownAboutRelationships()
                    GameStates.sIsChangingWorlds = true;

                    if (ths.Household != null)
                    {
                        changedCallback  = ths.Household.HouseholdSimsChanged;
                        changedHousehold = ths.Household;

                        ths.Household.HouseholdSimsChanged = null;
                    }

                    if (ths.CreatedSim != null)
                    {
                        AttemptToPutInSafeLocation(ths.CreatedSim, false);

                        if (reset != null)
                        {
                            ths.CreatedSim.SetObjectToReset();

                            reset(ths.CreatedSim, false);
                        }

                        return(ths.CreatedSim);
                    }

                    if (ths.AgingState != null)
                    {
                        bool flag = outfitKey == ths.mDefaultOutfitKey;

                        ths.AgingState.SimBuilderTaskDeferred = false;

                        ths.AgingState.PreInstantiateSim(ref outfitKey);
                        if (flag)
                        {
                            ths.mDefaultOutfitKey = outfitKey;
                        }
                    }

                    int       capacity  = forceAlwaysAnimate ? 0x4 : 0x2;
                    Hashtable overrides = new Hashtable(capacity);
                    overrides["simOutfitKey"] = outfitKey;
                    overrides["rigKey"]       = CASUtils.GetRigKeyForAgeGenderSpecies((ths.Age | ths.Gender) | ths.Species);
                    if (forceAlwaysAnimate)
                    {
                        overrides["enableSimPoseProcessing"] = 0x1;
                        overrides["animationRunsInRealtime"] = 0x1;
                    }

                    string         instanceName = "GameSim";
                    ProductVersion version      = ProductVersion.BaseGame;
                    if (ths.Species != CASAgeGenderFlags.Human)
                    {
                        instanceName = "Game" + ths.Species;
                        version      = ProductVersion.EP5;
                    }

                    SimInitParameters initData = new SimInitParameters(ths);
                    Sim target = GlobalFunctions.CreateObjectWithOverrides(instanceName, version, position, 0x0, Vector3.UnitZ, overrides, initData) as Sim;
                    if (target != null)
                    {
                        if (target.SimRoutingComponent == null)
                        {
                            // Performed to ensure that a useful error message is produced when the Sim construction fails
                            target.OnCreation();
                            target.OnStartup();
                        }

                        target.SimRoutingComponent.EnableDynamicFootprint();
                        target.SimRoutingComponent.ForceUpdateDynamicFootprint();

                        ths.PushAgingEnabledToAgingManager();

                        /* This code is idiotic
                         * if ((ths.Teen) && (target.SkillManager != null))
                         * {
                         *  Skill skill = target.SkillManager.AddElement(SkillNames.Homework);
                         *  while (skill.SkillLevel < SimDescription.kTeenHomeworkSkillStartLevel)
                         *  {
                         *      skill.ForceGainPointsForLevelUp();
                         *  }
                         * }
                         */

                        // Custom
                        OccultTypeHelper.SetupForInstantiatedSim(ths.OccultManager);

                        if (ths.IsAlien)
                        {
                            World.ObjectSetVisualOverride(target.ObjectId, eVisualOverrideTypes.Alien, null);
                        }

                        AttemptToPutInSafeLocation(target, false);

                        EventTracker.SendEvent(EventTypeId.kSimInstantiated, null, target);

                        /*
                         * MiniSimDescription description = MiniSimDescription.Find(ths.SimDescriptionId);
                         * if ((description == null) || (!GameStates.IsTravelling && (ths.mHomeWorld == GameUtils.GetCurrentWorld())))
                         * {
                         *  return target;
                         * }
                         * description.UpdateInWorldRelationships(ths);
                         */

                        if (ths.HealthManager != null)
                        {
                            ths.HealthManager.Startup();
                        }

                        if (((ths.SkinToneKey.InstanceId == 15475186560318337848L) && !ths.OccultManager.HasOccultType(OccultTypes.Vampire)) && (!ths.OccultManager.HasOccultType(OccultTypes.Werewolf) && !ths.IsGhost))
                        {
                            World.ObjectSetVisualOverride(ths.CreatedSim.ObjectId, eVisualOverrideTypes.Genie, null);
                        }

                        if (ths.Household.IsAlienHousehold)
                        {
                            (Sims3.UI.Responder.Instance.HudModel as HudModel).OnSimCurrentWorldChanged(true, ths);
                        }

                        if (Household.RoommateManager.IsNPCRoommate(ths.SimDescriptionId))
                        {
                            Household.RoommateManager.AddRoommateInteractions(target);
                        }
                    }

                    return(target);
                }
                finally
                {
                    LifeEventManager.sIsLifeEventManagerEnabled = isLifeEventManagerEnabled;

                    GameStates.sIsChangingWorlds = isChangingWorlds;

                    if ((changedHousehold != null) && (changedCallback != null))
                    {
                        changedHousehold.HouseholdSimsChanged = changedCallback;

                        if (changedHousehold.HouseholdSimsChanged != null)
                        {
                            changedHousehold.HouseholdSimsChanged(Sims3.Gameplay.CAS.HouseholdEvent.kSimAdded, ths.CreatedSim, null);
                        }
                    }
                }
            }
        }