-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompScuttlable.cs
113 lines (101 loc) · 3.7 KB
/
CompScuttlable.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using RimWorld;
using System.Linq;
using System.Collections.Generic;
using Verse;
using UnityEngine;
namespace BlackFuelNative
{
class CompScuttlable : ThingComp
{
private int ticker = 0;
private List<IntVec3> cachedAdjCellsCardinal;
private CompRefuelable compRefuelable;
private List<IntVec3> AdjCellsCardinalInBounds
{
get
{
if (this.cachedAdjCellsCardinal == null)
{
this.cachedAdjCellsCardinal = (from c in GenAdj.CellsAdjacentCardinal(parent)
where c.InBounds(parent.Map)
select c).ToList<IntVec3>();
}
return this.cachedAdjCellsCardinal;
}
}
public override void CompTick()
{
base.CompTick();
ticker++;
if (ticker >= Props.scuttlePollInTicks)
{
ticker = 0;
if (compRefuelable == null)
compRefuelable = parent.TryGetComp<CompRefuelable>();
if (compRefuelable == null || !BlackFuelUtil.CarbonThingsExist || compRefuelable.IsFull)
return;
if (parent.IsForbidden(parent.Faction))
return;
CompFlickable compFlickable = parent.GetComp<CompFlickable>();
if (compFlickable != null && !compFlickable.SwitchIsOn)
return;
if (!compRefuelable.ShouldAutoRefuelNow)
return;
Thing fuelThing = FindFuelInAnyScuttle();
if (fuelThing != null)
{
// should I check if the item is forbidden first? Core hopper logic doesn't seem to...
int fuelNeeded = compRefuelable.GetFuelCountToFullyRefuel();
int fuelThingValue = fuelThing.stackCount;
if (BlackFuelUtil.IsCarbonThing(fuelThing))
{
fuelNeeded /= 3;
fuelThingValue *= 3;
}
if (fuelThingValue <= fuelNeeded)
{
compRefuelable.Refuel(fuelThingValue);
fuelThing.Destroy();
} else
{
compRefuelable.Refuel(fuelThingValue);
fuelThing.stackCount -= fuelNeeded;
}
}
}
}
protected virtual Thing FindFuelInAnyScuttle()
{
for (int i = 0; i < this.AdjCellsCardinalInBounds.Count; i++)
{
Thing thing = null;
Thing thing2 = null;
List<Thing> thingList = this.AdjCellsCardinalInBounds[i].GetThingList(parent.Map);
for (int j = 0; j < thingList.Count; j++)
{
Thing thingInThisCell = thingList[j];
if (compRefuelable.Props.fuelFilter.Allows(thingInThisCell))
{
thing = thingInThisCell;
}
if (thingInThisCell.def.defName.Equals("CoalScuttle"))
{
thing2 = thingInThisCell;
}
}
if (thing != null && thing2 != null)
{
return thing;
}
}
return null;
}
public CompProperties_Scuttlable Props
{
get
{
return (CompProperties_Scuttlable)this.props;
}
}
}
}