Esempio n. 1
0
        private void Callback_OnJobFinished(Player_Char.Job job, bool succeeded, string message)
        {
            UnityEngine.Assertions.Assert.IsTrue(currentlyDoing == job);

            DeInitCallbacks(job);
            currentlyDoing.Owner.Value = null;
            currentlyDoing             = null;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new job for this specific PlayerChar to do.
        /// </summary>
        public void AddJob(Player_Char.Job job)
        {
            customJobs.Add(job);

            if (OnAddCustomJob != null)
            {
                OnAddCustomJob(this, job);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Finds a job to do. Returns "null" if nothing was found.
        /// Note that if it was a global job, this PlayerChar is now responsible for it
        ///     until the job ends one way or another.
        /// </summary>
        /// <param name="emergenciesOnly">Whether to only look for emergency jobs.</param>
        private Player_Char.Job TakeAJob(bool emergenciesOnly)
        {
            //There are three types of jobs:
            //  1. "Needs"-related jobs, like getting food/sleep or running from enemies.
            //  2. "Custom" jobs given specifically to this unit.
            //  3. "Global" jobs that any unit can take on.

            //Jobs are taken in this order:
            //  1. Emergency custom jobs.
            //  2. Emergency "needs" jobs.
            //  3. Emergency global jobs.
            //  4. Non-emergency "needs" jobs.
            //  5. Non-emergency custom jobs.
            //  6. Non-emergency global jobs.

            Player_Char.Job job = null;

            if (emergenciesOnly)
            {
                job = customJobs.FirstOrDefault(j => j.IsEmergency);

                if (job == null)
                {
                    job = FindNeedsJob(true);
                }

                if (job == null)
                {
                    job = ((Groups.PlayerGroup)MyGroup).TakeJob(this, true);
                }
            }
            else
            {
                //Try taking emergency jobs first.
                job = TakeAJob(true);

                if (job == null)
                {
                    job = FindNeedsJob(false);
                }

                if (job == null && customJobs.Count > 0)
                {
                    job = customJobs[0];
                }

                if (job == null)
                {
                    job = ((Groups.PlayerGroup)MyGroup).TakeJob(this, false);
                }
            }

            return(job);
        }
Esempio n. 4
0
        /// <summary>
        /// Stops this PlayerChar from doing its current job and starts the given one.
        /// Returns the job that was stopped (or "null" if it wasn't doing anything).
        /// </summary>
        /// <param name="alertOldJob">
        /// If a job was canceled to make way for this one,
        ///     it will be ended with the given message.
        /// Pass "null" for no message.
        /// </param>
        public Player_Char.Job StartDoingJob(Player_Char.Job job, string alertOldJob)
        {
            Player_Char.Job oldJob = StopDoingJob(alertOldJob);

            currentlyDoing             = job;
            currentlyDoing.Owner.Value = this;

            InitCallbacks(job);

            customJobs.Remove(job);

            return(oldJob);
        }
Esempio n. 5
0
        /// <summary>
        /// Stops this PlayerChar from doing its current job.
        /// Returns the job it was doing (or "null" if it wasn't doing anything).
        /// </summary>
        /// <param name="alert">
        /// The job's "OnJobFinished" event will be raised with this message.
        /// May be "null" if the interruption isn't important.
        /// </param>
        public Player_Char.Job StopDoingJob(string alert, bool succeeded = false)
        {
            if (currentlyDoing != null)
            {
                Player_Char.Job j = currentlyDoing;

                Callback_OnJobFinished(j, false, alert);
                j.EndJob(succeeded, alert);

                return(j);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Removes a job that was specifically given to this player.
        /// Returns whether the player actually had this job in the first place.
        /// </summary>
        /// <param name="alert">
        /// If the PlayerChar was in the middle of doing this job,
        ///     it will be ended with the given message.
        /// </param>
        public bool RemoveJob(Player_Char.Job job, string alert = "")
        {
            bool existed;

            if (currentlyDoing == job)
            {
                existed = true;
                StopDoingJob(alert);
            }
            else
            {
                existed = customJobs.Remove(job);
            }

            if (existed && OnRemoveCustomJob != null)
            {
                OnRemoveCustomJob(this, job);
            }
            return(existed);
        }
Esempio n. 7
0
        //These are the callbacks are for the currently-active job.
        private void Callback_JobOwnerChanged(Player_Char.Job job, PlayerChar oldP, PlayerChar newP)
        {
            UnityEngine.Assertions.Assert.IsTrue(currentlyDoing == job);

            StopDoingJob(Localization.Get("INTERRUPT_JOB_UNKNOWN", job.ToString()));
        }
Esempio n. 8
0
 private void DeInitCallbacks(Player_Char.Job activeJob)
 {
     activeJob.OnJobFinished   -= Callback_OnJobFinished;
     activeJob.Owner.OnChanged -= Callback_JobOwnerChanged;
 }