Exemple #1
0
        public static void OnAccepted(Sim actor, Sim target, string interaction, ActiveTopic topic, InteractionInstance i)
        {
            try
            {
                OccupationNames careerName = actor.Occupation.Guid;

                bool success = false;

                if (target.Occupation == null)
                {
                    Career career = CareerManager.GetStaticCareer(careerName);
                    if (career == null)
                    {
                        return;
                    }

                    string branch = actor.Occupation.CurLevelBranchName;

                    CareerLocation location = Career.FindClosestCareerLocation(target.SimDescription, careerName);
                    if (location == null)
                    {
                        return;
                    }

                    if (target.SimDescription.AcquireOccupation(new AcquireOccupationParameters(location, false, false)))
                    {
                        success = true;
                    }
                }
                else
                {
                    int level = 1;
                    if (target.Occupation.Guid == actor.Occupation.Guid)
                    {
                        Career actorCareer = actor.Occupation as Career;

                        CareerLevel curLevel = actorCareer.CurLevel;

                        while (curLevel.LastLevel != null)
                        {
                            curLevel = curLevel.LastLevel;
                            if (curLevel.NextLevels.Count > 1)
                            {
                                break;
                            }
                        }

                        if (curLevel != null)
                        {
                            level = curLevel.Level;
                        }
                    }

                    Career staticCareer = CareerManager.GetStaticCareer(careerName);
                    if ((target.Occupation != null) && (careerName != OccupationNames.Undefined) && (actor.Occupation.CurLevelBranchName != null) && (staticCareer != null))
                    {
                        target.Occupation.LeaveJob(Career.LeaveJobReason.kTransfered);

                        CareerLocation location = Career.FindClosestCareerLocation(target.SimDescription, staticCareer.Guid);
                        if (location != null)
                        {
                            CareerLevel careerLevel = null;
                            if (actor.Occupation.CurLevelBranchName != null)
                            {
                                Dictionary <int, CareerLevel> dictionary = null;
                                if (staticCareer.CareerLevels.TryGetValue(actor.Occupation.CurLevelBranchName, out dictionary))
                                {
                                    dictionary.TryGetValue(level, out careerLevel);
                                }
                            }

                            if (careerLevel == null)
                            {
                                foreach (Dictionary <int, CareerLevel> dictionary2 in staticCareer.CareerLevels.Values)
                                {
                                    if (dictionary2.TryGetValue(level, out careerLevel))
                                    {
                                        break;
                                    }
                                }
                            }

                            if (careerLevel != null)
                            {
                                Occupation staticOccupation = CareerManager.GetStaticOccupation(actor.Occupation.Guid);
                                if (staticOccupation != null)
                                {
                                    staticOccupation.DoTransferOfOccupation(target.SimDescription, careerLevel.BranchName, careerLevel.Level);
                                    success = true;
                                }
                            }
                        }
                    }
                }

                if (success)
                {
                    OmniCareer job = actor.Occupation as OmniCareer;
                    if (job != null)
                    {
                        job.AddToRecruits();
                    }
                }
            }
            catch (Exception e)
            {
                Common.Exception(actor, target, e);
            }
        }
Exemple #2
0
        public override void OnTimePassed(InteractionInstance interactionInstance, float totalTime, float deltaTime)
        {
            try
            {
                foreach (MetricRate rate in mMetrics)
                {
                    float hoursElapsed = SimClock.ElapsedTime(TimeUnit.Hours) - rate.mStartTime;

                    if (hoursElapsed < rate.mHoursUntilChange)
                    {
                        continue;
                    }

                    rate.mStartTime = SimClock.ElapsedTime(TimeUnit.Hours);

                    switch (rate.mMetric)
                    {
                    case MetricRate.MetricType.ConcertsPerformed:
                        Music music = OmniCareer.Career <Music>(Career);
                        if (music != null)
                        {
                            music.ConcertsPerformed += rate.mRate;
                        }
                        break;

                    case MetricRate.MetricType.Journals:
                        OmniCareer journals = Career as OmniCareer;
                        if (journals != null)
                        {
                            journals.FinishedJournal();
                        }
                        break;

                    case MetricRate.MetricType.Recruitment:
                        OmniCareer recruit = Career as OmniCareer;
                        if (recruit != null)
                        {
                            recruit.AddToRecruits();
                        }
                        break;

                    case MetricRate.MetricType.Reports:
                        LawEnforcement law = OmniCareer.Career <LawEnforcement>(Career);
                        if (law != null)
                        {
                            law.ReportsCompltetedToday += rate.mRate;
                        }
                        break;

                    case MetricRate.MetricType.StoriesAndReviews:
                        Journalism journalism = OmniCareer.Career <Journalism>(Career);
                        if (journalism != null)
                        {
                            journalism.StoriesWrittenToday += rate.mRate;
                        }
                        break;

                    case MetricRate.MetricType.WinLossRecord:
                        ProSports proSports = OmniCareer.Career <ProSports>(Career);
                        if (proSports != null)
                        {
                            if (rate.mRate > 0)
                            {
                                proSports.mWinRecord += rate.mRate;
                                proSports.mTotalWins += rate.mRate;
                            }
                            else
                            {
                                proSports.mLossRecord -= rate.mRate;
                                proSports.mTotalLoss  -= rate.mRate;
                            }
                        }
                        break;

                    case MetricRate.MetricType.MeetingsHeld:
                        Business business = OmniCareer.Career <Business>(Career);
                        if (business != null)
                        {
                            business.MeetingsHeldToday += rate.mRate;
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Common.Exception(Career.OwnerDescription, e);
            }
        }