private Toil MineStuffFromMine()
        {
            return(new Toil()
            {
                tickAction = delegate
                {
                    Building building = (Building)pawn.CurJob.targetA.Thing;
                    CompMineShaft comp = building.GetComp <CompMineShaft>();

                    if (ticksToPickHit < -100)
                    {
                        ResetTicksToPickHit();
                    }
                    if (pawn.skills != null)
                    {
                        pawn.skills.Learn(SkillDefOf.Mining, 0.11f, false);
                    }
                    ticksToPickHit--;

                    if (ticksToPickHit <= 0)
                    {
                        if (effecter == null)
                        {
                            effecter = EffecterDefOf.Mine.Spawn();
                        }
                        effecter.Trigger(pawn, building);

                        ResetTicksToPickHit();
                    }
                },
                defaultDuration = (int)Mathf.Clamp(OreSettingsHelper.ModSettings.WorkDuration / pawn.GetStatValue(StatDefOf.MiningSpeed, true), 800, 16000),
                defaultCompleteMode = ToilCompleteMode.Delay,
                handlingFacing = true
            }.WithProgressBarToilDelay(TargetIndex.B, false, -0.5f));
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(false);
            }
            Building building = t as Building;

            if (building == null)
            {
                return(false);
            }
            if (building.IsForbidden(pawn))
            {
                return(false);
            }
            LocalTargetInfo target = building;

            if (!pawn.CanReserve(target, 1, -1, null, forced))
            {
                return(false);
            }
            CompMineShaft compMiningPlatform = building.TryGetComp <CompMineShaft>();

            return(compMiningPlatform.CanMine() && building.Map.designationManager.DesignationOn(building, DesignationDefOf.Deconstruct) == null && !building.IsBurning());
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompMineShaft compMiningPlatform = this.job.targetA.Thing.TryGetComp <CompMineShaft>();

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            this.FailOnThingHavingDesignation(TargetIndex.A, DesignationDefOf.Deconstruct);
            this.FailOn(delegate()
            {
                return(!compMiningPlatform.CanMine());
            });

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            yield return(MineStuffFromMine());

            if (compMiningPlatform.ProspectMode)
            {
                yield return(ProspectFirst());
            }
            else
            {
                yield return(MineShaftYieldStuff());
            }
            yield return(ApplyHeDiff());
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            this.FailOnThingHavingDesignation(TargetIndex.A, DesignationDefOf.Deconstruct);
            this.FailOn(delegate()
            {
                CompMineShaft compMiningPlatform = this.job.targetA.Thing.TryGetComp <CompMineShaft>();
                return(!compMiningPlatform.CanMine());
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil work = new Toil();

            work.tickAction = delegate()
            {
                Pawn          actor    = work.actor;
                Building      building = (Building)actor.CurJob.targetA.Thing;
                CompMineShaft comp     = building.GetComp <CompMineShaft>();

                var hungerOnPawn = work.actor?.health?.hediffSet?.GetFirstHediffOfDef(OreDefOf.MinersHunger);

                if (hungerOnPawn == null)
                {
                    Hediff hediff = HediffMaker.MakeHediff(OreDefOf.MinersHunger, work.actor, null);
                    hediff.Severity = 0.01f;
                    work.actor.health.AddHediff(hediff, null, null);
                }
                else
                {
                    hungerOnPawn.Severity += 0.01f;
                }

                /*
                 * if (comp.ProspectMode)
                 * {
                 *  comp.Prospecting(actor);
                 * }
                 * else
                 * {
                 *  comp.MiningWorkDone(actor);
                 * }
                 */
                actor.skills.Learn(SkillDefOf.Mining, 0.065f, false);
            };


            work.defaultCompleteMode = ToilCompleteMode.Never;
            work.WithEffect(EffecterDefOf.Drill, TargetIndex.A);
            work.WithEffect(EffecterDefOf.Mine, TargetIndex.B);
            work.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            work.activeSkill = (() => SkillDefOf.Mining);
            yield return(work);

            yield break;
        }
 private Toil MineShaftYieldStuff()
 {
     return(new Toil()
     {
         initAction = delegate
         {
             Building building = (Building)pawn.CurJob.targetA.Thing;
             CompMineShaft comp = building.GetComp <CompMineShaft>();
             comp.MiningWorkDone(pawn);
         }
     });
 }
 private Toil ProspectFirst()
 {
     return(new Toil()
     {
         initAction = delegate
         {
             Building building = (Building)pawn.CurJob.targetA.Thing;
             CompMineShaft comp = building.GetComp <CompMineShaft>();
             comp.TryFinishProspecting();
         }
     });
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            this.FailOnThingHavingDesignation(TargetIndex.A, DesignationDefOf.Deconstruct);
            this.FailOn(delegate()
            {
                CompMineShaft compMiningPlatform = this.job.targetA.Thing.TryGetComp <CompMineShaft>();
                return(!compMiningPlatform.CanMine());
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil work = new Toil();

            work.tickAction = delegate()
            {
                Pawn          actor    = work.actor;
                Building      building = (Building)actor.CurJob.targetA.Thing;
                CompMineShaft comp     = building.GetComp <CompMineShaft>();
                if (comp.ProspectMode)
                {
                    comp.Prospecting(actor);
                }
                else
                {
                    comp.MiningWorkDone(actor);
                }
                actor.skills.Learn(SkillDefOf.Mining, 0.065f, false);
            };
            work.defaultCompleteMode = ToilCompleteMode.Never;
            work.WithEffect(EffecterDefOf.Drill, TargetIndex.A);
            work.WithEffect(EffecterDefOf.Mine, TargetIndex.B);
            work.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            work.activeSkill = (() => SkillDefOf.Mining);
            yield return(work);

            yield break;
        }