public static void JoyTickCheckEnd(Pawn pawn, JoyTickFullJoyAction fullJoyAction = JoyTickFullJoyAction.EndJob, float extraJoyGainFactor = 1f) { Job curJob = pawn.CurJob; if (curJob.def.joyKind == null) { Log.Warning("This method can only be called for jobs with joyKind."); return; } pawn.needs.joy.GainJoy(extraJoyGainFactor * curJob.def.joyGainRate * 0.000144f, curJob.def.joyKind); if (curJob.def.joySkill != null) { pawn.skills.GetSkill(curJob.def.joySkill).Learn(curJob.def.joyXpPerTick, false); } if (!curJob.ignoreJoyTimeAssignment && !pawn.GetTimeAssignment().allowJoy) { pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced); } if (pawn.needs.joy.CurLevel > 0.9999f) { if (fullJoyAction == JoyTickFullJoyAction.EndJob) { pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded); } else if (fullJoyAction == JoyTickFullJoyAction.GoToNextToil) { pawn.jobs.curDriver.ReadyForNextToil(); } } }
static bool Prefix(Pawn pawn, JoyTickFullJoyAction fullJoyAction = JoyTickFullJoyAction.EndJob, float extraJoyGainFactor = 1f, Building joySource = null) { Job curJob = pawn.CurJob; if (curJob.def.joyKind == null) { Log.Warning("This method can only be called for jobs with joyKind.", false); return(false);; } if (joySource != null) { if (joySource.def.building.joyKind != null && pawn.CurJob.def.joyKind != joySource.def.building.joyKind) { Log.ErrorOnce("Joy source joyKind and jobDef.joyKind are not the same. building=" + joySource.ToStringSafe <Building>() + ", jobDef=" + pawn.CurJob.def.ToStringSafe <JobDef>(), joySource.thingIDNumber ^ 876598732, false); } extraJoyGainFactor *= joySource.GetStatValue(StatDefOf.JoyGainFactor, true); } if (pawn.needs.joy == null) { pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced); return(false); } TimeAssignmentDef timeAssignmentDef = (pawn.timetable == null) ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment; if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef) { return(true); } pawn.needs.joy.GainJoy(extraJoyGainFactor * curJob.def.joyGainRate * 0.36f / 2500f, curJob.def.joyKind); if (curJob.def.joySkill != null) { pawn.skills.GetSkill(curJob.def.joySkill).Learn(curJob.def.joyXpPerTick, false); } if (pawn.needs.food.CurLevelPercentage < pawn.RaceProps.FoodLevelPercentageWantEat + ModSetting.eatThreshold && pawn.IsHashIntervalTick(60))//dinner饱腹值以下时结束娱乐 { bool desperate = pawn.needs.food.CurCategory == HungerCategory.Starving; Thing thing; ThingDef thingDef; if (FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out thingDef, true, true, false, true, false, pawn.IsWildMan(), false, false, FoodPreferability.Undefined)) { //Log.Message("joytickcheckend find {0}".Translate(thing.GetUniqueLoadID())); if (fullJoyAction == JoyTickFullJoyAction.EndJob) { pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded); return(false); } if (fullJoyAction == JoyTickFullJoyAction.GoToNextToil) { pawn.jobs.curDriver.ReadyForNextToil(); } } } return(false); }
public static void JoyTickCheckEnd(Pawn pawn, JoyTickFullJoyAction fullJoyAction = JoyTickFullJoyAction.EndJob, float extraJoyGainFactor = 1f, Building joySource = null) { Job curJob = pawn.CurJob; if (curJob.def.joyKind == null) { Log.Warning("This method can only be called for jobs with joyKind."); return; } if (joySource != null) { if (joySource.def.building.joyKind != null && pawn.CurJob.def.joyKind != joySource.def.building.joyKind) { Log.ErrorOnce("Joy source joyKind and jobDef.joyKind are not the same. building=" + joySource.ToStringSafe() + ", jobDef=" + pawn.CurJob.def.ToStringSafe(), joySource.thingIDNumber ^ 0x343FD5CC); } extraJoyGainFactor *= joySource.GetStatValue(StatDefOf.JoyGainFactor); } if (pawn.needs.joy == null) { pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced); return; } pawn.needs.joy.GainJoy(extraJoyGainFactor * curJob.def.joyGainRate * 0.36f / 2500f, curJob.def.joyKind); if (curJob.def.joySkill != null) { pawn.skills.GetSkill(curJob.def.joySkill).Learn(curJob.def.joyXpPerTick); } if (!curJob.ignoreJoyTimeAssignment && !pawn.GetTimeAssignment().allowJoy) { pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced); } if (pawn.needs.joy.CurLevel > 0.9999f) { switch (fullJoyAction) { case JoyTickFullJoyAction.EndJob: pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded); break; case JoyTickFullJoyAction.GoToNextToil: pawn.jobs.curDriver.ReadyForNextToil(); break; } } }
private static bool Prefix(Pawn pawn, JoyTickFullJoyAction fullJoyAction = JoyTickFullJoyAction.EndJob, float extraJoyGainFactor = 1f, Building joySource = null) { var curJob = pawn.CurJob; if (curJob.def.joyKind == null) { Log.Warning("This method can only be called for jobs with joyKind."); return(false); } if (joySource != null) { if (joySource.def.building.joyKind != null && pawn.CurJob.def.joyKind != joySource.def.building.joyKind) { Log.ErrorOnce( "Joy source joyKind and jobDef.joyKind are not the same. building=" + joySource.ToStringSafe() + ", jobDef=" + pawn.CurJob.def.ToStringSafe(), joySource.thingIDNumber ^ 876598732); } extraJoyGainFactor *= joySource.GetStatValue(StatDefOf.JoyGainFactor); } if (pawn.needs.joy == null) { pawn.jobs.curDriver.EndJobWith(JobCondition.InterruptForced); return(false); } var timeAssignmentDef = pawn.timetable == null ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment; if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef) { return(true); } pawn.needs.joy.GainJoy(extraJoyGainFactor * curJob.def.joyGainRate * 0.36f / 2500f, curJob.def.joyKind); if (curJob.def.joySkill != null) { pawn.skills.GetSkill(curJob.def.joySkill).Learn(curJob.def.joyXpPerTick); } if (!(pawn.needs.food.CurLevelPercentage < pawn.RaceProps.FoodLevelPercentageWantEat + ModSetting.eatThreshold) || !pawn.IsHashIntervalTick(60)) { return(false); } var desperate = pawn.needs.food.CurCategory == HungerCategory.Starving; if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out _, out _, true, true, false, true, false, pawn.IsWildMan())) { return(false); } if (fullJoyAction == JoyTickFullJoyAction.EndJob) { pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded); return(false); } if (fullJoyAction == JoyTickFullJoyAction.GoToNextToil) { pawn.jobs.curDriver.ReadyForNextToil(); } return(false); }