/
JobDriver_Vomit.cs
81 lines (76 loc) · 1.85 KB
/
JobDriver_Vomit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Verse;
using Verse.AI;
namespace RimWorld
{
public class JobDriver_Vomit : JobDriver
{
private int ticksLeft;
public override void SetInitialPosture()
{
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look<int>(ref this.ticksLeft, "ticksLeft", 0, false);
}
public override bool TryMakePreToilReservations(bool errorOnFailed)
{
return true;
}
[DebuggerHidden]
protected override IEnumerable<Toil> MakeNewToils()
{
Toil to = new Toil();
to.initAction = delegate
{
this.$this.ticksLeft = Rand.Range(300, 900);
int num = 0;
IntVec3 c;
while (true)
{
c = this.$this.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
num++;
if (num > 12)
{
break;
}
if (c.InBounds(this.$this.pawn.Map) && c.Standable(this.$this.pawn.Map))
{
goto IL_A1;
}
}
c = this.$this.pawn.Position;
IL_A1:
this.$this.job.targetA = c;
this.$this.pawn.pather.StopDead();
};
to.tickAction = delegate
{
if (this.$this.ticksLeft % 150 == 149)
{
FilthMaker.MakeFilth(this.$this.job.targetA.Cell, this.$this.Map, ThingDefOf.Filth_Vomit, this.$this.pawn.LabelIndefinite(), 1);
if (this.$this.pawn.needs.food.CurLevelPercentage > 0.1f)
{
this.$this.pawn.needs.food.CurLevel -= this.$this.pawn.needs.food.MaxLevel * 0.04f;
}
}
this.$this.ticksLeft--;
if (this.$this.ticksLeft <= 0)
{
this.$this.ReadyForNextToil();
TaleRecorder.RecordTale(TaleDefOf.Vomited, new object[]
{
this.$this.pawn
});
}
};
to.defaultCompleteMode = ToilCompleteMode.Never;
to.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
to.PlaySustainerOrSound(() => SoundDefOf.Vomit);
yield return to;
}
}
}