That's amazing. And here I was trying to solve a problem that already had a solution. Thank's for pointing this out

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menuusing System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Verse;
using Verse.AI;
using RimWorld;
namespace FinerThings
{
public class JobGiver_SeekOtherDrugs : ThinkNode_JobGiver
{
public static ThingDef RandomDrug()
{
return GenCollection.RandomElement<ThingDef>(Enumerable.Where<ThingDef>(DefDatabase<ThingDef>.AllDefs, (Func<ThingDef, bool>)(def =>
{
if (def.category == EntityCategory.Item)
{
return def.ingestible.isPleasureDrug;
}
else
{
return false;
}
})));
}
public static class DrugThingDefOf
{
public static ThingDef Coffee;
public static ThingDef Espresso;
public static ThingDef Cigar;
public static ThingDef Cigarillos;
}
private static readonly SimpleCurve DrugUseIntervalFactorCurve_Mood = new SimpleCurve()
{
new CurvePoint(20f, 0.4f),
new CurvePoint(60f, 1f)
};
private static readonly SimpleCurve DrugUseIntervalFactorCurve_Drunkness = new SimpleCurve()
{
new CurvePoint(0.0f, 1f),
new CurvePoint(1f, 4f)
};
private const int BaseDrugUseInterval = 60000;
private const int DrugUseIntervalBinging = 600;
protected override Job TryGiveTerminalJob(Pawn pawn)
{
int num1 = pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire);
if (num1 < 0)
{
return (Job)null;
}
int num2;
if (pawn.mindState.broken.CurStateDef != null && pawn.mindState.broken.CurStateDef == BrokenStateDefOf.BingingAlcohol)
{
return (Job) null;
}
else
{
num2 = (int)(60000.0 * (double)JobGiver_SeekOtherDrugs.DrugUseIntervalFactorCurve_Mood.Evaluate(pawn.needs.mood.CurLevel));
if (num1 == 1)
num2 = (int) ((double) num2 * 0.5);
else if (num1 > 1)
num2 = (int) ((double) num2 * 0.280000001192093);
}
if (Find.TickManager.TicksGame - pawn.mindState.lastPleasureDrugUseTick > num2)
{
Job job = JobGiver_SeekOtherDrugs.ConsumeDrug(pawn);
if (job != null)
{
return job;
}
}
return (Job) null;
}
private static Job ConsumeDrug(Pawn pawn)
{
Thing thing = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(RandomDrug()), PathMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, true), 9999f, (Predicate<Thing>)null, (IEnumerable<Thing>)null, -1);
if (thing == null)
return (Job)null;
return new Job(JobDefOf.Ingest, (TargetInfo) thing)
{
maxNumToCarry = Mathf.Min(thing.stackCount, thing.def.ingestible.maxNumToIngestAtOnce),
};
}
}
}