protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            List <AfterschoolActivity> allChoices = sCareerGetAfterSchoolActivityList.Invoke <List <AfterschoolActivity> >(new object[] { Sim });

            if (allChoices == null)
            {
                allChoices = new List <AfterschoolActivity>();

                foreach (AfterschoolActivityType type in Enum.GetValues(typeof(AfterschoolActivityType)))
                {
                    if ((Sim.Child) && (!AfterschoolActivity.IsChildActivity(type)))
                    {
                        continue;
                    }

                    if ((Sim.Teen) && (!AfterschoolActivity.IsTeenActivity(type)))
                    {
                        continue;
                    }

                    GreyedOutTooltipCallback greyedOutTooltipCallback = null;
                    if (!AfterschoolActivity.MeetsCommonAfterschoolActivityRequirements(Sim.CreatedSim, type, ref greyedOutTooltipCallback))
                    {
                        continue;
                    }

                    allChoices.Add(new AfterschoolActivity(type));
                }
            }

            List <WeightedChoice> choices = new List <WeightedChoice>();

            foreach (AfterschoolActivity activity in allChoices)
            {
                float weight = 0;
                int   count  = 0;

                foreach (SkillNames actualSkill in activity.ActivitySkillNameList)
                {
                    SkillNames skill = actualSkill;
                    switch (skill)
                    {
                    case SkillNames.BassGuitar:
                    case SkillNames.Piano:
                    case SkillNames.Drums:
                        skill = SkillNames.Guitar;
                        break;
                    }

                    if (ScoringLookup.HasScoring(skill.ToString()))
                    {
                        weight += AddScoring(skill.ToString(), Sim);
                    }
                    else
                    {
                        Common.DebugNotify("AfterschoolActivity Missing " + skill.ToString());

                        weight += AddScoring("AfterschoolActivity", Sim);
                    }

                    count++;
                }

                if (weight < 0)
                {
                    continue;
                }

                if (count == 0)
                {
                    count = 1;
                }

                choices.Add(new WeightedChoice(activity.CurrentActivityType, weight / count));
            }

            if (choices.Count == 0)
            {
                IncStat("No Choices");
                return(false);
            }

            WeightedChoice choice = RandomUtil.GetWeightedRandomObjectFromList(choices);

            AfterschoolActivity.AddNewActivity(Sim.CreatedSim, choice.mType);
            return(true);
        }
示例#2
0
        protected override bool Run(SimDescription me, bool singleSelection)
        {
            if (!ApplyAll)
            {
                List <AfterSchoolActivityCriteria.Item> choices = new List <AfterSchoolActivityCriteria.Item>();

                List <AfterschoolActivity> customTypes = sCareerAfterschoolActivityList.Invoke <List <AfterschoolActivity> >(new object[] { me });

                if (customTypes != null)
                {
                    foreach (AfterschoolActivity type in customTypes)
                    {
                        choices.Add(new AfterSchoolActivityCriteria.Item(type, AfterSchoolActivityCriteria.HasActivity(me, type.CurrentActivityType) ? 1 : 0));
                    }
                }
                else
                {
                    foreach (AfterschoolActivityType type in Enum.GetValues(typeof(AfterschoolActivityType)))
                    {
                        if ((me.Child) && (AfterschoolActivity.IsChildActivity(type)))
                        {
                            choices.Add(new AfterSchoolActivityCriteria.Item(type, AfterSchoolActivityCriteria.HasActivity(me, type) ? 1 : 0));
                        }
                        else if (me.Teen && AfterschoolActivity.IsTeenActivity(type))
                        {
                            choices.Add(new AfterSchoolActivityCriteria.Item(type, AfterSchoolActivityCriteria.HasActivity(me, type) ? 1 : 0));
                        }
                    }
                }

                if (choices.Count == 0)
                {
                    SimpleMessageDialog.Show(Name, Common.Localize(GetTitlePrefix() + ":NoChoices", me.IsFemale, new object[] { me }));
                    return(false);
                }

                CommonSelection <AfterSchoolActivityCriteria.Item> .Results selection = new CommonSelection <AfterSchoolActivityCriteria.Item>(Name, choices).SelectMultiple();
                if ((selection == null) || (selection.Count == 0))
                {
                    return(false);
                }

                mSelection = selection;
            }

            foreach (AfterSchoolActivityCriteria.Item item in mSelection)
            {
                School school = me.CareerManager.School;
                if (school.AfterschoolActivities == null)
                {
                    school.AfterschoolActivities = new List <AfterschoolActivity>();
                }

                if (AfterSchoolActivityCriteria.HasActivity(me, item.Value))
                {
                    for (int i = school.AfterschoolActivities.Count - 1; i >= 0; i--)
                    {
                        if (school.AfterschoolActivities[i].CurrentActivityType == item.Value)
                        {
                            school.AfterschoolActivities.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    AfterschoolActivity newActivity = new AfterschoolActivity(item.Value);

                    AfterschoolActivity oldActivity = item.Activity;
                    if (oldActivity != null)
                    {
                        newActivity.ActivitySkillNameList = new List <Sims3.Gameplay.Skills.SkillNames>(oldActivity.ActivitySkillNameList);
                        newActivity.mDaysForActivity      = oldActivity.mDaysForActivity;
                    }

                    school.AfterschoolActivities.Add(newActivity);
                }

                me.CareerManager.UpdateCareerUI();
            }

            return(true);
        }