Elin Modding Docs Doc
Loading...
Searching...
No Matches
TaskDump.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.CompilerServices;
5
6// Token: 0x02000261 RID: 609
7public class TaskDump : Task
8{
9 // Token: 0x06001129 RID: 4393 RVA: 0x0007734E File Offset: 0x0007554E
10 public override bool CanManualCancel()
11 {
12 return true;
13 }
14
15 // Token: 0x0600112A RID: 4394 RVA: 0x00077351 File Offset: 0x00075551
16 public override IEnumerable<AIAct.Status> Run()
17 {
18 List<Thing> containers = new List<Thing>();
19 EClass._map.things.ForEach(delegate(Thing t)
20 {
21 if (this.IsValidContainer(t))
22 {
23 containers.Add(t);
24 }
25 });
26 while (containers.Count > 0)
27 {
28 bool flag = true;
29 int num = TaskDump.<Run>g__SortVal|1_1(containers.First<Thing>());
30 using (List<Thing>.Enumerator enumerator = containers.GetEnumerator())
31 {
32 while (enumerator.MoveNext())
33 {
34 if (TaskDump.<Run>g__SortVal|1_1(enumerator.Current) != num)
35 {
36 flag = false;
37 break;
38 }
39 }
40 }
41 if (flag)
42 {
43 containers.Sort((Thing a, Thing b) => EClass.pc.Dist(b) - EClass.pc.Dist(a));
44 }
45 else
46 {
47 containers.Sort((Thing a, Thing b) => TaskDump.<Run>g__SortVal|1_1(a) - TaskDump.<Run>g__SortVal|1_1(b));
48 }
49 Thing c = containers.LastItem<Thing>();
50 containers.RemoveAt(containers.Count - 1);
51 if (this.IsValidContainer(c))
52 {
53 EClass.ui.CloseLayers();
54 Point pos = c.pos.Copy();
55 if (c.IsMultisize)
56 {
57 int minDist = 999;
58 c.ForeachPoint(delegate(Point p, bool isCenter)
59 {
60 if (!p.IsValid || !p.IsInBounds)
61 {
62 return;
63 }
64 PathProgress pathProgress = PathManager.Instance.RequestPathImmediate(EClass.pc.pos, p, EClass.pc, PathManager.MoveType.Default, -1, 1);
65 if (pathProgress.HasPath && pathProgress.nodes.Count < minDist)
66 {
67 minDist = pathProgress.nodes.Count;
68 pos = p.Copy();
69 }
70 });
71 }
72 yield return base.DoGoto(pos, 1, false, () => AIAct.Status.Running);
73 if (this.IsValidContainer(c))
74 {
75 if (!c.ExistsOnMap)
76 {
77 Msg.Say("dump_noExist", c, null, null, null);
78 }
79 else if (EClass.pc.Dist(c) > 1)
80 {
81 Msg.Say("dump_tooFar", c, null, null, null);
82 }
83 else
84 {
85 List<Thing> list = this.ListThingsToPut(c);
86 int num2 = 0;
87 if (c.trait is TraitShippingChest)
88 {
89 c = EClass.game.cards.container_shipping;
90 }
91 foreach (Thing thing in list)
92 {
93 if (!c.things.IsFull(thing, true, true) && !thing.isDestroyed)
94 {
95 thing.PlaySoundDrop(false);
96 if (c.parent is Card)
97 {
98 (c.parent as Card).SetDirtyWeight();
99 }
100 Msg.Say("dump_item", thing, c, null, null);
101 c.AddCard(thing);
102 num2++;
103 }
104 }
105 if (num2 > 0)
106 {
107 Msg.Say("dump_dumped", num2.ToString() ?? "", c.Name, null, null);
108 }
109 c = null;
110 }
111 }
112 }
113 }
114 yield break;
115 }
116
117 // Token: 0x0600112B RID: 4395 RVA: 0x00077361 File Offset: 0x00075561
118 public override void OnCancelOrSuccess()
119 {
120 Msg.Say("dump_end");
121 SE.Play("auto_dump");
122 }
123
124 // Token: 0x0600112C RID: 4396 RVA: 0x00077378 File Offset: 0x00075578
125 public bool IsValidContainer(Thing c)
126 {
127 if ((!c.ExistsOnMap && !c.IsInstalled) || !c.CanSearchContents)
128 {
129 return false;
130 }
131 if (c.trait is TraitShippingChest)
132 {
133 c = EClass.game.cards.container_shipping;
134 }
135 return c.GetWindowSaveData() != null && c.GetWindowSaveData().autodump != AutodumpFlag.none && this.ListThingsToPut(c).Count != 0;
136 }
137
138 // Token: 0x0600112D RID: 4397 RVA: 0x000773E8 File Offset: 0x000755E8
139 public List<Thing> ListThingsToPut(Thing c)
140 {
141 TaskDump.<>c__DisplayClass4_0 CS$<>8__locals1 = new TaskDump.<>c__DisplayClass4_0();
142 CS$<>8__locals1.list = new List<Thing>();
143 if (c.trait is TraitShippingChest)
144 {
145 c = EClass.game.cards.container_shipping;
146 }
147 CS$<>8__locals1.data = c.GetWindowSaveData();
148 if (CS$<>8__locals1.data == null)
149 {
150 return CS$<>8__locals1.list;
151 }
152 switch (CS$<>8__locals1.data.autodump)
153 {
154 case AutodumpFlag.existing:
155 using (List<Thing>.Enumerator enumerator = c.things.GetEnumerator())
156 {
157 while (enumerator.MoveNext())
158 {
159 Thing ct = enumerator.Current;
160 EClass.pc.things.Foreach(delegate(Thing t)
161 {
162 if (CS$<>8__locals1.<ListThingsToPut>g__ExcludeDump|0(t))
163 {
164 return;
165 }
166 if (!t.CanStackTo(ct))
167 {
168 return;
169 }
170 CS$<>8__locals1.list.Add(t);
171 }, true);
172 }
173 goto IL_17B;
174 }
175 break;
176 case AutodumpFlag.sameCategory:
177 break;
178 case AutodumpFlag.none:
179 goto IL_17B;
180 case AutodumpFlag.distribution:
181 EClass.pc.things.Foreach(delegate(Thing t)
182 {
183 if (base.<ListThingsToPut>g__ExcludeDump|0(t))
184 {
185 return;
186 }
187 if (CS$<>8__locals1.data.advDistribution)
188 {
189 using (HashSet<int>.Enumerator enumerator2 = CS$<>8__locals1.data.cats.GetEnumerator())
190 {
191 while (enumerator2.MoveNext())
192 {
193 int num = enumerator2.Current;
194 if (t.category.uid == num)
195 {
196 CS$<>8__locals1.list.Add(t);
197 break;
198 }
199 }
200 return;
201 }
202 }
203 ContainerFlag containerFlag = t.category.GetRoot().id.ToEnum(true);
204 if (containerFlag == ContainerFlag.none)
205 {
206 containerFlag = ContainerFlag.other;
207 }
208 if (!CS$<>8__locals1.data.flag.HasFlag(containerFlag))
209 {
210 CS$<>8__locals1.list.Add(t);
211 }
212 }, true);
213 goto IL_17B;
214 default:
215 goto IL_17B;
216 }
217 if (c.things.Count != 0)
218 {
219 HashSet<SourceCategory.Row> cats = new HashSet<SourceCategory.Row>();
220 foreach (Thing thing in c.things)
221 {
222 cats.Add(thing.category);
223 }
224 EClass.pc.things.Foreach(delegate(Thing t)
225 {
226 if (CS$<>8__locals1.<ListThingsToPut>g__ExcludeDump|0(t))
227 {
228 return;
229 }
230 if (!cats.Contains(t.category))
231 {
232 return;
233 }
234 CS$<>8__locals1.list.Add(t);
235 }, true);
236 }
237 IL_17B:
238 return CS$<>8__locals1.list;
239 }
240
241 // Token: 0x0600112F RID: 4399 RVA: 0x0007759C File Offset: 0x0007579C
242 [CompilerGenerated]
243 internal static int <Run>g__SortVal|1_1(Thing t)
244 {
245 Window.SaveData windowSaveData = t.GetWindowSaveData();
246 if (windowSaveData != null)
247 {
248 return windowSaveData.priority;
249 }
250 return 0;
251 }
252}
Definition AIAct.cs:7
Definition Card.cs:13
Definition Msg.cs:7
Definition Point.cs:11
Definition Task.cs:6
Definition Thing.cs:10