public static Toil DoRecipeWork() { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor3 = toil.actor; Job curJob3 = actor3.jobs.curJob; JobDriver_DoBill jobDriver_DoBill2 = (JobDriver_DoBill)actor3.jobs.curDriver; UnfinishedThing unfinishedThing3 = curJob3.GetTarget(TargetIndex.B).Thing as UnfinishedThing; if (unfinishedThing3 != null && unfinishedThing3.Initialized) { jobDriver_DoBill2.workLeft = unfinishedThing3.workLeft; } else { jobDriver_DoBill2.workLeft = curJob3.bill.recipe.WorkAmountTotal(unfinishedThing3?.Stuff); if (unfinishedThing3 != null) { unfinishedThing3.workLeft = jobDriver_DoBill2.workLeft; } } jobDriver_DoBill2.billStartTick = Find.TickManager.TicksGame; jobDriver_DoBill2.ticksSpentDoingRecipeWork = 0; curJob3.bill.Notify_DoBillStarted(actor3); }; toil.tickAction = delegate { Pawn actor2 = toil.actor; Job curJob2 = actor2.jobs.curJob; JobDriver_DoBill jobDriver_DoBill = (JobDriver_DoBill)actor2.jobs.curDriver; UnfinishedThing unfinishedThing2 = curJob2.GetTarget(TargetIndex.B).Thing as UnfinishedThing; if (unfinishedThing2 != null && unfinishedThing2.Destroyed) { actor2.jobs.EndCurrentJob(JobCondition.Incompletable); } else { jobDriver_DoBill.ticksSpentDoingRecipeWork++; curJob2.bill.Notify_PawnDidWork(actor2); (toil.actor.CurJob.GetTarget(TargetIndex.A).Thing as IBillGiverWithTickAction)?.UsedThisTick(); if (curJob2.RecipeDef.workSkill != null && curJob2.RecipeDef.UsesUnfinishedThing) { actor2.skills.Learn(curJob2.RecipeDef.workSkill, 0.1f * curJob2.RecipeDef.workSkillLearnFactor); } float num = ((curJob2.RecipeDef.workSpeedStat == null) ? 1f : actor2.GetStatValue(curJob2.RecipeDef.workSpeedStat)); if (curJob2.RecipeDef.workTableSpeedStat != null) { Building_WorkTable building_WorkTable = jobDriver_DoBill.BillGiver as Building_WorkTable; if (building_WorkTable != null) { num *= building_WorkTable.GetStatValue(curJob2.RecipeDef.workTableSpeedStat); } } if (DebugSettings.fastCrafting) { num *= 30f; } jobDriver_DoBill.workLeft -= num; if (unfinishedThing2 != null) { unfinishedThing2.workLeft = jobDriver_DoBill.workLeft; } actor2.GainComfortFromCellIfPossible(chairsOnly: true); if (jobDriver_DoBill.workLeft <= 0f) { jobDriver_DoBill.ReadyForNextToil(); } else if (curJob2.bill.recipe.UsesUnfinishedThing) { int num2 = Find.TickManager.TicksGame - jobDriver_DoBill.billStartTick; if (num2 >= 3000 && num2 % 1000 == 0) { actor2.jobs.CheckForJobOverride(); } } } }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.WithEffect(() => toil.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A); toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking); toil.WithProgressBar(TargetIndex.A, delegate { Pawn actor = toil.actor; Job curJob = actor.CurJob; UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing; return(1f - ((JobDriver_DoBill)actor.jobs.curDriver).workLeft / curJob.bill.recipe.WorkAmountTotal(unfinishedThing?.Stuff)); }); toil.FailOn((Func <bool>) delegate { RecipeDef recipeDef = toil.actor.CurJob.RecipeDef; if (recipeDef != null && recipeDef.interruptIfIngredientIsRotting) { LocalTargetInfo target = toil.actor.CurJob.GetTarget(TargetIndex.B); if (target.HasThing && (int)target.Thing.GetRotStage() > 0) { return(true); } } return(toil.actor.CurJob.bill.suspended); }); toil.activeSkill = () => toil.actor.CurJob.bill.recipe.workSkill; return(toil); }
public static Toil DoRecipeWork() { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; JobDriver_DoBill jobDriver_DoBill = (JobDriver_DoBill)actor.jobs.curDriver; UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing; if (unfinishedThing != null && unfinishedThing.Initialized) { jobDriver_DoBill.workLeft = unfinishedThing.workLeft; } else { jobDriver_DoBill.workLeft = curJob.bill.recipe.WorkAmountTotal((unfinishedThing == null) ? null : unfinishedThing.Stuff); if (unfinishedThing != null) { unfinishedThing.workLeft = jobDriver_DoBill.workLeft; } } jobDriver_DoBill.billStartTick = Find.TickManager.TicksGame; jobDriver_DoBill.ticksSpentDoingRecipeWork = 0; curJob.bill.Notify_DoBillStarted(actor); }; toil.tickAction = delegate { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; JobDriver_DoBill jobDriver_DoBill = (JobDriver_DoBill)actor.jobs.curDriver; UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing; if (unfinishedThing != null && unfinishedThing.Destroyed) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } jobDriver_DoBill.ticksSpentDoingRecipeWork++; curJob.bill.Notify_PawnDidWork(actor); IBillGiverWithTickAction billGiverWithTickAction = toil.actor.CurJob.GetTarget(TargetIndex.A).Thing as IBillGiverWithTickAction; if (billGiverWithTickAction != null) { billGiverWithTickAction.UsedThisTick(); } if (curJob.RecipeDef.workSkill != null && curJob.RecipeDef.UsesUnfinishedThing) { actor.skills.Learn(curJob.RecipeDef.workSkill, 0.1f * curJob.RecipeDef.workSkillLearnFactor, false); } float num = (curJob.RecipeDef.workSpeedStat != null) ? actor.GetStatValue(curJob.RecipeDef.workSpeedStat, true) : 1f; if (curJob.RecipeDef.workTableSpeedStat != null) { Building_WorkTable building_WorkTable = jobDriver_DoBill.BillGiver as Building_WorkTable; if (building_WorkTable != null) { num *= building_WorkTable.GetStatValue(curJob.RecipeDef.workTableSpeedStat, true); } } if (DebugSettings.fastCrafting) { num *= 30f; } jobDriver_DoBill.workLeft -= num; if (unfinishedThing != null) { unfinishedThing.workLeft = jobDriver_DoBill.workLeft; } actor.GainComfortFromCellIfPossible(); if (jobDriver_DoBill.workLeft <= 0f) { jobDriver_DoBill.ReadyForNextToil(); } if (curJob.bill.recipe.UsesUnfinishedThing) { int num2 = Find.TickManager.TicksGame - jobDriver_DoBill.billStartTick; if (num2 >= 3000 && num2 % 1000 == 0) { actor.jobs.CheckForJobOverride(); } } }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.WithEffect(() => toil.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A); toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking); toil.WithProgressBar(TargetIndex.A, delegate { Pawn actor = toil.actor; Job curJob = actor.CurJob; UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing; return(1f - ((JobDriver_DoBill)actor.jobs.curDriver).workLeft / curJob.bill.recipe.WorkAmountTotal((unfinishedThing == null) ? null : unfinishedThing.Stuff)); }, false, -0.5f); toil.FailOn(() => toil.actor.CurJob.bill.suspended); toil.activeSkill = (() => toil.actor.CurJob.bill.recipe.workSkill); return(toil); }
public static Toil DoRecipeWork() { const int MinWorkDuration = 3000; const int CheckOverrideInterval = 1000; Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; JobDriver_DoBill driver = ((JobDriver_DoBill)actor.jobs.curDriver); UnfinishedThing uft = curJob.GetTarget(JobDriver_DoBill.IngredientInd).Thing as UnfinishedThing; //Set our work left //If we're starting from an already-initialized UnfinishedThing, just copy its workLeft into the driver //Otherwise, generate a new workLeft and copy it into the UnfinishedThing if (uft != null && uft.Initialized) { driver.workLeft = uft.workLeft; } else { driver.workLeft = curJob.bill.recipe.WorkAmountTotal(uft != null ? uft.Stuff : null); if (uft != null) { uft.workLeft = driver.workLeft; } } driver.billStartTick = Find.TickManager.TicksGame; driver.ticksSpentDoingRecipeWork = 0; curJob.bill.Notify_DoBillStarted(actor); }; toil.tickAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; JobDriver_DoBill driver = ((JobDriver_DoBill)actor.jobs.curDriver); UnfinishedThing uft = curJob.GetTarget(JobDriver_DoBill.IngredientInd).Thing as UnfinishedThing; if (uft != null && uft.Destroyed) { actor.jobs.EndCurrentJob(JobCondition.Incompletable); return; } driver.ticksSpentDoingRecipeWork++; curJob.bill.Notify_PawnDidWork(actor); //Bill giver gets notification that we're working on it var bga = toil.actor.CurJob.GetTarget(JobDriver_DoBill.BillGiverInd).Thing as IBillGiverWithTickAction; if (bga != null) { bga.UsedThisTick(); } //Learn (only if the recipe uses unfinished thing to prevent the exploit with drafting/undrafting colonists and getting unlimited xp) if (curJob.RecipeDef.workSkill != null && curJob.RecipeDef.UsesUnfinishedThing) { actor.skills.Learn(curJob.RecipeDef.workSkill, SkillTuning.XpPerTickRecipeBase * curJob.RecipeDef.workSkillLearnFactor); } //Make some progress //Apply it to both the driver's workLeft and, if it exists, the UnfinishedThing's workLeft float progress = (curJob.RecipeDef.workSpeedStat == null) ? 1f : actor.GetStatValue(curJob.RecipeDef.workSpeedStat); if (curJob.RecipeDef.workTableSpeedStat != null) { var t = driver.BillGiver as Building_WorkTable; if (t != null) { progress *= t.GetStatValue(curJob.RecipeDef.workTableSpeedStat); } } if (DebugSettings.fastCrafting) { progress *= 30; } driver.workLeft -= progress; if (uft != null) { uft.workLeft = driver.workLeft; } PawnUtility.GainComfortFromCellIfPossible(actor); //End the toil if there is no more work left if (driver.workLeft <= 0) { driver.ReadyForNextToil(); } //Allow job override periodically if (curJob.bill.recipe.UsesUnfinishedThing) { int billTicks = Find.TickManager.TicksGame - driver.billStartTick; if (billTicks >= MinWorkDuration && billTicks % CheckOverrideInterval == 0) { actor.jobs.CheckForJobOverride(); } } }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.WithEffect(() => toil.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A); toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking); toil.WithProgressBar(JobDriver_DoBill.BillGiverInd, () => { var actor = toil.actor; var curJob = actor.CurJob; var uft = curJob.GetTarget(JobDriver_DoBill.IngredientInd).Thing as UnfinishedThing; return(1f - ((JobDriver_DoBill)actor.jobs.curDriver).workLeft / curJob.bill.recipe.WorkAmountTotal(uft != null ? uft.Stuff : null)); }); toil.FailOn(() => toil.actor.CurJob.bill.suspended); toil.activeSkill = () => toil.actor.CurJob.bill.recipe.workSkill; return(toil); }