Exemple #1
0
        private void CheckLeaveJoinableLordBecauseJobIssued(ThinkResult result)
        {
            if (!result.IsValid || result.SourceNode == null)
            {
                return;
            }
            Lord lord = pawn.GetLord();

            if (lord == null || !(lord.LordJob is LordJob_VoluntarilyJoinable))
            {
                return;
            }
            bool      flag      = false;
            ThinkNode thinkNode = result.SourceNode;

            do
            {
                if (thinkNode.leaveJoinableLordIfIssuesJob)
                {
                    flag = true;
                    break;
                }
                thinkNode = thinkNode.parent;
            }while (thinkNode != null);
            if (flag)
            {
                lord.Notify_PawnLost(pawn, PawnLostCondition.LeftVoluntarily);
            }
        }
 public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
 {
     if (this.matchedTrees == null)
     {
         this.matchedTrees = new List <ThinkTreeDef>();
         foreach (ThinkTreeDef thinkTreeDef in DefDatabase <ThinkTreeDef> .AllDefs)
         {
             if (thinkTreeDef.insertTag == this.insertTag)
             {
                 this.matchedTrees.Add(thinkTreeDef);
             }
         }
         this.matchedTrees = (from tDef in this.matchedTrees
                              orderby tDef.insertPriority descending
                              select tDef).ToList <ThinkTreeDef>();
     }
     for (int i = 0; i < this.matchedTrees.Count; i++)
     {
         ThinkResult result = this.matchedTrees[i].thinkRoot.TryIssueJobPackage(pawn, jobParams);
         if (result.IsValid)
         {
             return(result);
         }
     }
     return(ThinkResult.NoJob);
 }
Exemple #3
0
        private void TryFindAndStartJob()
        {
            if (pawn.thinker == null)
            {
                Log.ErrorOnce(string.Concat(pawn, " did TryFindAndStartJob but had no thinker."), 8573261);
                return;
            }
            if (curJob != null)
            {
                Log.Warning(string.Concat(pawn, " doing TryFindAndStartJob while still having job ", curJob));
            }
            if (debugLog)
            {
                DebugLogEvent("TryFindAndStartJob");
            }
            if (!CanDoAnyJob())
            {
                if (debugLog)
                {
                    DebugLogEvent("   CanDoAnyJob is false. Clearing queue and returning");
                }
                ClearQueuedJobs();
                return;
            }
            ThinkTreeDef thinkTree;
            ThinkResult  result = DetermineNextJob(out thinkTree);

            if (result.IsValid)
            {
                CheckLeaveJoinableLordBecauseJobIssued(result);
                StartJob(result.Job, JobCondition.None, result.SourceNode, resumeCurJobAfterwards: false, cancelBusyStances: false, thinkTree, result.Tag, result.FromQueue);
            }
        }
        private void CheckLeaveJoinableLordBecauseJobIssued(ThinkResult result)
        {
            if (result.IsValid && result.SourceNode != null)
            {
                Lord lord = this.pawn.GetLord();
                if (lord != null && lord.LordJob is LordJob_VoluntarilyJoinable)
                {
                    bool      flag      = false;
                    ThinkNode thinkNode = result.SourceNode;
                    while (!thinkNode.leaveJoinableLordIfIssuesJob)
                    {
                        thinkNode = thinkNode.parent;
                        if (thinkNode == null)
                        {
IL_7C:
                            if (flag)
                            {
                                lord.Notify_PawnLost(this.pawn, PawnLostCondition.LeftVoluntarily);
                                return;
                            }
                            return;
                        }
                    }
                    flag = true;
                    goto IL_7C;
                }
            }
        }
        private ThinkResult DetermineNextJob(out ThinkTreeDef thinkTree)
        {
            ThinkResult thinkResult = this.DetermineNextConstantThinkTreeJob();
            ThinkResult result;

            if (thinkResult.Job != null)
            {
                thinkTree = this.pawn.thinker.ConstantThinkTree;
                result    = thinkResult;
            }
            else
            {
                ThinkResult thinkResult2 = ThinkResult.NoJob;
                try
                {
                    Profiler.BeginSample("Determine next job (main)");
                    thinkResult2 = this.pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(this.pawn, default(JobIssueParams));
                }
                catch (Exception exception)
                {
                    JobUtility.TryStartErrorRecoverJob(this.pawn, this.pawn.ToStringSafe <Pawn>() + " threw exception while determining job (main)", exception, null);
                    thinkTree = null;
                    return(ThinkResult.NoJob);
                }
                finally
                {
                    Profiler.EndSample();
                }
                thinkTree = this.pawn.thinker.MainThinkTree;
                result    = thinkResult2;
            }
            return(result);
        }
Exemple #6
0
        private ThinkResult DetermineNextJob(out ThinkTreeDef thinkTree)
        {
            ThinkResult result = DetermineNextConstantThinkTreeJob();

            if (result.Job != null)
            {
                thinkTree = pawn.thinker.ConstantThinkTree;
                return(result);
            }
            ThinkResult result2 = ThinkResult.NoJob;

            try
            {
                result2 = pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(pawn, default(JobIssueParams));
            }
            catch (Exception exception)
            {
                JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
                thinkTree = null;
                return(ThinkResult.NoJob);
            }
            finally
            {
            }
            thinkTree = pawn.thinker.MainThinkTree;
            return(result2);
        }
Exemple #7
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            JobQueue jobQueue = pawn.jobs.jobQueue;
            bool     flag     = pawn.Downed || jobQueue.AnyCanBeginNow(pawn, this.inBedOnly);

            if (flag)
            {
                while (jobQueue.Count > 0 && !jobQueue.Peek().job.CanBeginNow(pawn, this.inBedOnly))
                {
                    QueuedJob queuedJob = jobQueue.Dequeue();
                    pawn.ClearReservationsForJob(queuedJob.job);
                    if (pawn.jobs.debugLog)
                    {
                        pawn.jobs.DebugLogEvent("   Throwing away queued job that I cannot begin now: " + queuedJob.job);
                    }
                }
            }
            ThinkResult result;

            if (jobQueue.Count > 0 && jobQueue.Peek().job.CanBeginNow(pawn, this.inBedOnly))
            {
                QueuedJob queuedJob2 = jobQueue.Dequeue();
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent("   Returning queued job: " + queuedJob2.job);
                }
                result = new ThinkResult(queuedJob2.job, this, queuedJob2.tag, true);
            }
            else
            {
                result = ThinkResult.NoJob;
            }
            return(result);
        }
Exemple #8
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            int count = this.subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                ThinkResult result = ThinkResult.NoJob;
                try
                {
                    result = this.subNodes[i].TryIssueJobPackage(pawn, jobParams);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Exception in ",
                        base.GetType(),
                        " TryIssueJobPackage: ",
                        ex.ToString()
                    }), false);
                }
                if (result.IsValid)
                {
                    return(result);
                }
            }
            return(ThinkResult.NoJob);
        }
Exemple #9
0
        private ThinkResult DetermineNextJob(out ThinkTreeDef thinkTree)
        {
            ThinkResult result = this.DetermineNextConstantThinkTreeJob();

            if (result.Job != null)
            {
                thinkTree = this.pawn.thinker.ConstantThinkTree;
                return(result);
            }
            ThinkResult result2 = ThinkResult.NoJob;

            try
            {
                result2 = this.pawn.thinker.MainThinkNodeRoot.TryIssueJobPackage(this.pawn, default(JobIssueParams));
            }
            catch (Exception ex)
            {
                this.StartErrorRecoverJob(this.pawn + " threw exception while determining job (main): " + ex.ToString());
                thinkTree = null;
                return(ThinkResult.NoJob);
            }
            finally
            {
            }
            thinkTree = this.pawn.thinker.MainThinkTree;
            return(result2);
        }
Exemple #10
0
 public virtual void JobTrackerTick()
 {
     jobsGivenThisTick        = 0;
     jobsGivenThisTickTextual = "";
     if (pawn.IsHashIntervalTick(30))
     {
         ThinkResult thinkResult = DetermineNextConstantThinkTreeJob();
         if (thinkResult.IsValid)
         {
             if (ShouldStartJobFromThinkTree(thinkResult))
             {
                 CheckLeaveJoinableLordBecauseJobIssued(thinkResult);
                 StartJob(thinkResult.Job, JobCondition.InterruptForced, thinkResult.SourceNode, resumeCurJobAfterwards: false, cancelBusyStances: false, pawn.thinker.ConstantThinkTree, thinkResult.Tag);
             }
             else if (thinkResult.Job != curJob && !jobQueue.Contains(thinkResult.Job))
             {
                 JobMaker.ReturnToPool(thinkResult.Job);
             }
         }
     }
     if (curDriver != null)
     {
         if (curJob.expiryInterval > 0 && (Find.TickManager.TicksGame - curJob.startTick) % curJob.expiryInterval == 0 && Find.TickManager.TicksGame != curJob.startTick)
         {
             if (!curJob.expireRequiresEnemiesNearby || PawnUtility.EnemiesAreNearby(pawn, 25))
             {
                 if (debugLog)
                 {
                     DebugLogEvent("Job expire");
                 }
                 if (!curJob.checkOverrideOnExpire)
                 {
                     EndCurrentJob(JobCondition.Succeeded);
                 }
                 else
                 {
                     CheckForJobOverride();
                 }
                 FinalizeTick();
                 return;
             }
             if (debugLog)
             {
                 DebugLogEvent("Job expire skipped because there are no enemies nearby");
             }
         }
         curDriver.DriverTick();
     }
     if (curJob == null && !pawn.Dead && pawn.mindState.Active && CanDoAnyJob())
     {
         if (debugLog)
         {
             DebugLogEvent("Starting job from Tick because curJob == null.");
         }
         TryFindAndStartJob();
     }
     FinalizeTick();
 }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            ThinkResult result = base.TryIssueJobPackage(pawn, jobParams);

            if (result.IsValid && result.Tag == null)
            {
                result = new ThinkResult(result.Job, result.SourceNode, new JobTag?(this.tagToGive), false);
            }
            return(result);
        }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            ThinkNode_PrioritySorter.workingNodes.Clear();
            int count = base.subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                ThinkNode_PrioritySorter.workingNodes.Insert(Rand.Range(0, ThinkNode_PrioritySorter.workingNodes.Count - 1), base.subNodes[i]);
            }
            while (ThinkNode_PrioritySorter.workingNodes.Count > 0)
            {
                float num  = 0f;
                int   num2 = -1;
                for (int j = 0; j < ThinkNode_PrioritySorter.workingNodes.Count; j++)
                {
                    float num3 = 0f;
                    try
                    {
                        num3 = ThinkNode_PrioritySorter.workingNodes[j].GetPriority(pawn);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception in " + base.GetType() + " GetPriority: " + ex.ToString());
                    }
                    if (!(num3 <= 0.0) && !(num3 < this.minPriority) && num3 > num)
                    {
                        num  = num3;
                        num2 = j;
                    }
                }
                if (num2 != -1)
                {
                    ThinkResult result = ThinkResult.NoJob;
                    try
                    {
                        result = ThinkNode_PrioritySorter.workingNodes[num2].TryIssueJobPackage(pawn, jobParams);
                    }
                    catch (Exception ex2)
                    {
                        Log.Error("Exception in " + base.GetType() + " TryIssueJobPackage: " + ex2.ToString());
                    }
                    if (result.IsValid)
                    {
                        return(result);
                    }
                    ThinkNode_PrioritySorter.workingNodes.RemoveAt(num2);
                    continue;
                }
                break;
            }
            return(ThinkResult.NoJob);
        }
 public virtual void JobTrackerTick()
 {
     this.jobsGivenThisTick        = 0;
     this.jobsGivenThisTickTextual = "";
     if (this.pawn.IsHashIntervalTick(30))
     {
         ThinkResult thinkResult = this.DetermineNextConstantThinkTreeJob();
         if (thinkResult.IsValid && this.ShouldStartJobFromThinkTree(thinkResult))
         {
             this.CheckLeaveJoinableLordBecauseJobIssued(thinkResult);
             this.StartJob(thinkResult.Job, JobCondition.InterruptForced, thinkResult.SourceNode, false, false, this.pawn.thinker.ConstantThinkTree, thinkResult.Tag, false);
         }
     }
     if (this.curDriver != null)
     {
         if (this.curJob.expiryInterval > 0 && (Find.TickManager.TicksGame - this.curJob.startTick) % this.curJob.expiryInterval == 0 && Find.TickManager.TicksGame != this.curJob.startTick)
         {
             if (!this.curJob.expireRequiresEnemiesNearby || PawnUtility.EnemiesAreNearby(this.pawn, 25, false))
             {
                 if (this.debugLog)
                 {
                     this.DebugLogEvent("Job expire");
                 }
                 if (!this.curJob.checkOverrideOnExpire)
                 {
                     this.EndCurrentJob(JobCondition.Succeeded, true);
                 }
                 else
                 {
                     this.CheckForJobOverride();
                 }
                 this.FinalizeTick();
                 return;
             }
             if (this.debugLog)
             {
                 this.DebugLogEvent("Job expire skipped because there are no enemies nearby");
             }
         }
         this.curDriver.DriverTick();
     }
     if (this.curJob == null && !this.pawn.Dead && this.pawn.mindState.Active && this.CanDoAnyJob())
     {
         if (this.debugLog)
         {
             this.DebugLogEvent("Starting job from Tick because curJob == null.");
         }
         this.TryFindAndStartJob();
     }
     this.FinalizeTick();
 }
Exemple #14
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            workingNodes.Clear();
            int count = subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                workingNodes.Insert(Rand.Range(0, workingNodes.Count - 1), subNodes[i]);
            }
            while (workingNodes.Count > 0)
            {
                float num  = 0f;
                int   num2 = -1;
                for (int j = 0; j < workingNodes.Count; j++)
                {
                    float num3 = 0f;
                    try
                    {
                        num3 = workingNodes[j].GetPriority(pawn);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Concat("Exception in ", GetType(), " GetPriority: ", ex.ToString()));
                    }
                    if (!(num3 <= 0f) && !(num3 < minPriority) && num3 > num)
                    {
                        num  = num3;
                        num2 = j;
                    }
                }
                if (num2 == -1)
                {
                    break;
                }
                ThinkResult result = ThinkResult.NoJob;
                try
                {
                    result = workingNodes[num2].TryIssueJobPackage(pawn, jobParams);
                }
                catch (Exception ex2)
                {
                    Log.Error(string.Concat("Exception in ", GetType(), " TryIssueJobPackage: ", ex2.ToString()));
                }
                if (result.IsValid)
                {
                    return(result);
                }
                workingNodes.RemoveAt(num2);
            }
            return(ThinkResult.NoJob);
        }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            Job         job = this.TryGiveJob(pawn);
            ThinkResult result;

            if (job == null)
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                result = new ThinkResult(job, this, null, false);
            }
            return(result);
        }
        public void CheckForJobOverride()
        {
            if (this.debugLog)
            {
                this.DebugLogEvent("CheckForJobOverride");
            }
            ThinkTreeDef thinkTree;
            ThinkResult  thinkResult = this.DetermineNextJob(out thinkTree);

            if (this.ShouldStartJobFromThinkTree(thinkResult))
            {
                this.CheckLeaveJoinableLordBecauseJobIssued(thinkResult);
                this.StartJob(thinkResult.Job, JobCondition.InterruptOptional, thinkResult.SourceNode, false, false, thinkTree, thinkResult.Tag, thinkResult.FromQueue);
            }
        }
Exemple #17
0
        public void CheckForJobOverride()
        {
            if (debugLog)
            {
                DebugLogEvent("CheckForJobOverride");
            }
            ThinkTreeDef thinkTree;
            ThinkResult  thinkResult = DetermineNextJob(out thinkTree);

            if (ShouldStartJobFromThinkTree(thinkResult))
            {
                CheckLeaveJoinableLordBecauseJobIssued(thinkResult);
                StartJob(thinkResult.Job, JobCondition.InterruptOptional, thinkResult.SourceNode, resumeCurJobAfterwards: false, cancelBusyStances: false, thinkTree, thinkResult.Tag, thinkResult.FromQueue);
            }
        }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            int count = this.subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                if (this.subNodes[i].GetPriority(pawn) > this.minPriority)
                {
                    ThinkResult result = this.subNodes[i].TryIssueJobPackage(pawn, jobParams);
                    if (result.IsValid)
                    {
                        return(result);
                    }
                }
            }
            return(ThinkResult.NoJob);
        }
Exemple #19
0
 public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
 {
     ThinkNode_Random.tempList.Clear();
     for (int i = 0; i < base.subNodes.Count; i++)
     {
         ThinkNode_Random.tempList.Add(base.subNodes[i]);
     }
     ThinkNode_Random.tempList.Shuffle();
     for (int j = 0; j < ThinkNode_Random.tempList.Count; j++)
     {
         ThinkResult result = ThinkNode_Random.tempList[j].TryIssueJobPackage(pawn, jobParams);
         if (result.IsValid)
         {
             return(result);
         }
     }
     return(ThinkResult.NoJob);
 }
 private bool ShouldStartJobFromThinkTree(ThinkResult thinkResult)
 {
     if (this.curJob == null)
     {
         return(true);
     }
     if (this.curJob == thinkResult.Job)
     {
         return(false);
     }
     if (thinkResult.FromQueue)
     {
         return(true);
     }
     if (thinkResult.Job.def == this.curJob.def && thinkResult.SourceNode == this.pawn.mindState.lastJobGiver && this.curDriver.IsContinuation(thinkResult.Job))
     {
         return(false);
     }
     return(true);
 }
Exemple #21
0
 private bool ShouldStartJobFromThinkTree(ThinkResult thinkResult)
 {
     if (curJob == null)
     {
         return(true);
     }
     if (curJob == thinkResult.Job)
     {
         return(false);
     }
     if (thinkResult.FromQueue)
     {
         return(true);
     }
     if (thinkResult.Job.def != curJob.def || thinkResult.SourceNode != curJob.jobGiver || !curDriver.IsContinuation(thinkResult.Job))
     {
         return(true);
     }
     return(false);
 }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            int count = base.subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                ThinkResult result = ThinkResult.NoJob;
                try
                {
                    result = base.subNodes[i].TryIssueJobPackage(pawn, jobParams);
                }
                catch (Exception ex)
                {
                    Log.Error("Exception in " + base.GetType() + " TryIssueJobPackage: " + ex.ToString());
                }
                if (result.IsValid)
                {
                    return(result);
                }
            }
            return(ThinkResult.NoJob);
        }
 private void TryFindAndStartJob()
 {
     if (this.pawn.thinker == null)
     {
         Log.ErrorOnce(this.pawn + " did TryFindAndStartJob but had no thinker.", 8573261, false);
     }
     else
     {
         if (this.curJob != null)
         {
             Log.Warning(this.pawn + " doing TryFindAndStartJob while still having job " + this.curJob, false);
         }
         if (this.debugLog)
         {
             this.DebugLogEvent("TryFindAndStartJob");
         }
         if (!this.CanDoAnyJob())
         {
             if (this.debugLog)
             {
                 this.DebugLogEvent("   CanDoAnyJob is false. Clearing queue and returning");
             }
             this.ClearQueuedJobs();
         }
         else
         {
             ThinkTreeDef thinkTreeDef;
             ThinkResult  result = this.DetermineNextJob(out thinkTreeDef);
             if (result.IsValid)
             {
                 this.CheckLeaveJoinableLordBecauseJobIssued(result);
                 Job          job        = result.Job;
                 ThinkNode    sourceNode = result.SourceNode;
                 ThinkTreeDef thinkTree  = thinkTreeDef;
                 this.StartJob(job, JobCondition.None, sourceNode, false, false, thinkTree, result.Tag, result.FromQueue);
             }
         }
     }
 }
Exemple #24
0
 public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
 {
     if (matchedTrees == null)
     {
         matchedTrees = new List <ThinkTreeDef>();
         foreach (ThinkTreeDef allDef in DefDatabase <ThinkTreeDef> .AllDefs)
         {
             if (allDef.insertTag == insertTag)
             {
                 matchedTrees.Add(allDef);
             }
         }
         matchedTrees = matchedTrees.OrderByDescending((ThinkTreeDef tDef) => tDef.insertPriority).ToList();
     }
     for (int i = 0; i < matchedTrees.Count; i++)
     {
         ThinkResult result = matchedTrees[i].thinkRoot.TryIssueJobPackage(pawn, jobParams);
         if (result.IsValid)
         {
             return(result);
         }
     }
     return(ThinkResult.NoJob);
 }
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            ThinkNode_PrioritySorter.workingNodes.Clear();
            int count = this.subNodes.Count;

            for (int i = 0; i < count; i++)
            {
                ThinkNode_PrioritySorter.workingNodes.Insert(Rand.Range(0, ThinkNode_PrioritySorter.workingNodes.Count - 1), this.subNodes[i]);
            }
            while (ThinkNode_PrioritySorter.workingNodes.Count > 0)
            {
                float num  = 0f;
                int   num2 = -1;
                for (int j = 0; j < ThinkNode_PrioritySorter.workingNodes.Count; j++)
                {
                    float num3 = 0f;
                    try
                    {
                        num3 = ThinkNode_PrioritySorter.workingNodes[j].GetPriority(pawn);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Exception in ",
                            base.GetType(),
                            " GetPriority: ",
                            ex.ToString()
                        }), false);
                    }
                    if (num3 > 0f && num3 >= this.minPriority)
                    {
                        if (num3 > num)
                        {
                            num  = num3;
                            num2 = j;
                        }
                    }
                }
                if (num2 == -1)
                {
                    break;
                }
                ThinkResult result = ThinkResult.NoJob;
                try
                {
                    result = ThinkNode_PrioritySorter.workingNodes[num2].TryIssueJobPackage(pawn, jobParams);
                }
                catch (Exception ex2)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Exception in ",
                        base.GetType(),
                        " TryIssueJobPackage: ",
                        ex2.ToString()
                    }), false);
                }
                if (result.IsValid)
                {
                    return(result);
                }
                ThinkNode_PrioritySorter.workingNodes.RemoveAt(num2);
            }
            return(ThinkResult.NoJob);
        }
        public override ThinkResult TryIssueJobPackage(Pawn pawn)
        {
            Job         job     = this.TryGiveJob(pawn);
            bool        jobNull = job == null;
            ThinkResult result;

            Apparel_Toolbelt toolbelt = ToolsForHaulUtility.TryGetToolbelt(pawn);

            if (toolbelt != null)
            {
                if (PreviousPawnWeapon.ContainsKey(pawn) && PreviousPawnWeapon[pawn] != null)
                {
                    Pawn           wearer         = toolbelt.Wearer;
                    ThingWithComps previousWeapon = PreviousPawnWeapon[pawn];
                    if (previousWeapon != null && toolbelt.slotsComp.slots.Contains(previousWeapon))
                    {
                        for (int i = toolbelt.slotsComp.slots.Count - 1; i >= 0; i--)
                        {
                            var            thing = toolbelt.slotsComp.slots[i];
                            ThingWithComps item  = (ThingWithComps)thing;
                            if (item == previousWeapon)
                            {
                                if (wearer.equipment.Primary != null)
                                {
                                    toolbelt.slotsComp.SwapEquipment(item);
                                }
                                else
                                {
                                    wearer.equipment.AddEquipment(item);
                                    toolbelt.slotsComp.slots.Remove(item);
                                }
                                break;
                            }
                        }
                    }
                }
                PreviousPawnWeapon[pawn] = null;
            }

            if (jobNull)
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                if (pawn.Faction == Faction.OfPlayer && pawn.RaceProps.Humanlike && pawn.RaceProps.IsFlesh)
                {
                    if (job.def == JobDefOf.DoBill)
                    {
                        RightTools.EquipRigthTool(pawn, job.RecipeDef.workSpeedStat);
                    }

                    if (job.def == JobDefOf.FinishFrame || job.def == JobDefOf.Deconstruct || job.def == JobDefOf.Repair || job.def == JobDefOf.BuildRoof || job.def == JobDefOf.RemoveRoof || job.def == JobDefOf.RemoveFloor)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.ConstructionSpeed);
                    }
                    if (job.def == JobDefOf.SmoothFloor)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.SmoothingSpeed);
                    }

                    if (job.def == JobDefOf.Harvest)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.PlantHarvestYield);
                    }
                    if (job.def == JobDefOf.CutPlant || job.def == JobDefOf.Sow)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.PlantWorkSpeed);
                    }

                    if (job.def == JobDefOf.Mine)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.MiningSpeed);
                    }
                }

                result = new ThinkResult(job, this);
            }

            return(result);
        }
 private bool ShouldStartJobFromThinkTree(ThinkResult thinkResult)
 {
     return(this.curJob == null || (this.curJob != thinkResult.Job && (thinkResult.FromQueue || (thinkResult.Job.def != this.curJob.def || thinkResult.SourceNode != this.pawn.mindState.lastJobGiver || !this.curDriver.IsContinuation(thinkResult.Job)))));
 }