Elin Modding Docs Doc
Loading...
Searching...
No Matches
AI_UseCrafter.cs
1using System;
2using System.Collections.Generic;
3using System.Runtime.CompilerServices;
4using UnityEngine;
5
6// Token: 0x020001F2 RID: 498
7public class AI_UseCrafter : AIAct
8{
9 // Token: 0x170003A8 RID: 936
10 // (get) Token: 0x06000E42 RID: 3650 RVA: 0x0006BB63 File Offset: 0x00069D63
11 public override int LeftHand
12 {
13 get
14 {
15 return 1001;
16 }
17 }
18
19 // Token: 0x170003A9 RID: 937
20 // (get) Token: 0x06000E43 RID: 3651 RVA: 0x0006BB6A File Offset: 0x00069D6A
21 public override int RightHand
22 {
23 get
24 {
25 return 1002;
26 }
27 }
28
29 // Token: 0x06000E44 RID: 3652 RVA: 0x0006BB71 File Offset: 0x00069D71
30 public override bool CanManualCancel()
31 {
32 return this.layer && this.layer.CanCancelAI;
33 }
34
35 // Token: 0x06000E45 RID: 3653 RVA: 0x0006BB8D File Offset: 0x00069D8D
36 public override void OnStart()
37 {
38 if (this.crafter.Icon != Emo.none)
39 {
40 this.owner.ShowEmo(this.crafter.Icon, 0f, true);
41 }
42 }
43
44 // Token: 0x06000E46 RID: 3654 RVA: 0x0006BBB8 File Offset: 0x00069DB8
45 public override void OnSuccess()
46 {
47 this.OnEnd();
48 }
49
50 // Token: 0x06000E47 RID: 3655 RVA: 0x0006BBC0 File Offset: 0x00069DC0
51 public override void OnCancel()
52 {
53 this.OnEnd();
54 if (this.layer)
55 {
56 this.layer.Close();
57 }
58 }
59
60 // Token: 0x06000E48 RID: 3656 RVA: 0x0006BBE0 File Offset: 0x00069DE0
61 public void OnEnd()
62 {
63 foreach (Thing thing in this.ings)
64 {
65 if (thing != null && thing.ExistsOnMap)
66 {
67 thing.isHidden = false;
68 EClass.pc.Pick(thing, true, true);
69 }
70 }
71 if (this.crafter.AutoTurnOff && this.crafter.owner.isOn)
72 {
73 this.crafter.Toggle(false, false);
74 }
75 if (!this.crafter.idSoundBG.IsEmpty())
76 {
77 EClass.Sound.Stop(this.crafter.idSoundBG, 0f);
78 }
79 if (this.layer)
80 {
81 this.layer.OnEndCraft();
82 }
83 }
84
85 // Token: 0x06000E49 RID: 3657 RVA: 0x0006BCBC File Offset: 0x00069EBC
86 public override IEnumerable<AIAct.Status> Run()
87 {
88 for (;;)
89 {
90 AI_UseCrafter.<>c__DisplayClass14_0 CS$<>8__locals1 = new AI_UseCrafter.<>c__DisplayClass14_0();
91 CS$<>8__locals1.<>4__this = this;
92 if (this.crafter.owner.isDestroyed || !this.layer)
93 {
94 yield return base.Success(null);
95 }
96 if (!this.crafter.idSoundBG.IsEmpty())
97 {
98 SE.Play(this.crafter.idSoundBG);
99 }
100 List<Thing> targets = this.layer.GetTargets();
101 CS$<>8__locals1.blessed = BlessedState.Normal;
102 int num;
103 for (int i = 0; i < targets.Count; i = num + 1)
104 {
105 Thing t = targets[i];
106 if (!this.<Run>g__IsIngValid|14_0(t, i))
107 {
108 if (i == 0)
109 {
110 this.layer.ClearButtons();
111 }
112 else
113 {
114 this.layer.RefreshCurrentGrid();
115 }
116 yield return base.Success(null);
117 }
118 num = i;
119 }
120 if (!this.crafter.IsFuelEnough(this.num, targets, true))
121 {
122 Msg.Say("notEnoughFuel");
123 this.layer.RefreshCurrentGrid();
124 yield return base.Success(null);
125 }
126 this.ings = new List<Thing>();
127 for (int j = 0; j < targets.Count; j++)
128 {
129 Thing thing = targets[j].Split(this.layer.GetReqIngredient(j));
130 this.ings.Add(thing);
131 if (thing.blessedState <= BlessedState.Cursed && CS$<>8__locals1.blessed > thing.blessedState)
132 {
133 CS$<>8__locals1.blessed = thing.blessedState;
134 }
135 if (thing.blessedState > BlessedState.Normal && CS$<>8__locals1.blessed == BlessedState.Normal)
136 {
137 CS$<>8__locals1.blessed = thing.blessedState;
138 }
139 if (this.crafter.IsConsumeIng)
140 {
141 Card card = EClass._zone.AddCard(thing, this.crafter.owner.ExistsOnMap ? this.crafter.owner.pos : this.owner.pos);
142 if (this.crafter.animeType == TraitCrafter.AnimeType.Microwave)
143 {
144 card.isHidden = true;
145 }
146 }
147 }
148 if (LayerDragGrid.Instance)
149 {
150 LayerDragGrid.Instance.Redraw();
151 }
152 CS$<>8__locals1.requireOn = (this.crafter.IsRequireFuel || this.crafter.ToggleType > ToggleType.None);
153 if (CS$<>8__locals1.requireOn && !this.crafter.owner.isOn)
154 {
155 this.crafter.Toggle(true, false);
156 }
157 CS$<>8__locals1.costSP = this.crafter.GetCostSp(this);
158 CS$<>8__locals1.duration = this.crafter.GetDuration(this, CS$<>8__locals1.costSP);
159 Progress_Custom progress = new Progress_Custom
160 {
161 canProgress = delegate()
162 {
163 if (CS$<>8__locals1.requireOn && !CS$<>8__locals1.<>4__this.crafter.owner.isOn)
164 {
165 return false;
166 }
167 foreach (Thing thing2 in CS$<>8__locals1.<>4__this.ings)
168 {
169 if (thing2.isDestroyed || (CS$<>8__locals1.<>4__this.crafter.IsConsumeIng && !thing2.ExistsOnMap))
170 {
171 return false;
172 }
173 }
174 if (LayerDragGrid.Instance)
175 {
176 InvOwnerDraglet owner = LayerDragGrid.Instance.owner;
177 for (int k = 0; k < owner.numDragGrid; k++)
178 {
179 if (owner.buttons[k].Card == null)
180 {
181 return false;
182 }
183 }
184 if (owner.numDragGrid == 2 && CS$<>8__locals1.<>4__this.ings[0] == CS$<>8__locals1.<>4__this.ings[1] && CS$<>8__locals1.<>4__this.ings[0].Num == 1)
185 {
186 return false;
187 }
188 }
189 return !CS$<>8__locals1.<>4__this.crafter.owner.isDestroyed;
190 },
191 onProgress = delegate(Progress_Custom p)
192 {
193 if (this.crafter.owner.ExistsOnMap && !this.owner.pos.Equals(this.crafter.owner.pos))
194 {
195 this.owner.LookAt(this.crafter.owner);
196 }
197 this.owner.PlaySound(this.crafter.idSoundProgress, 1f, true);
198 if (this.crafter.owner.ExistsOnMap)
199 {
200 TraitCrafter.AnimeType animeType = this.crafter.animeType;
201 if (animeType - TraitCrafter.AnimeType.Microwave <= 1)
202 {
203 this.crafter.owner.renderer.PlayAnime(this.crafter.IdAnimeProgress, default(Vector3), false);
204 }
205 }
206 foreach (Thing thing2 in this.ings)
207 {
208 thing2.renderer.PlayAnime(this.crafter.IdAnimeProgress, default(Vector3), false);
209 }
210 },
211 onProgressComplete = delegate()
212 {
213 if (CS$<>8__locals1.<>4__this.crafter.StopSoundProgress)
214 {
215 EClass.Sound.Stop(CS$<>8__locals1.<>4__this.crafter.idSoundProgress, 0f);
216 }
217 CS$<>8__locals1.<>4__this.owner.PlaySound(CS$<>8__locals1.<>4__this.crafter.idSoundComplete, 1f, true);
218 ElementContainer elements = CS$<>8__locals1.<>4__this.owner.elements;
219 TraitCrafter traitCrafter = CS$<>8__locals1.<>4__this.crafter;
220 Recipe recipe = CS$<>8__locals1.<>4__this.recipe;
221 Element orCreateElement = elements.GetOrCreateElement(traitCrafter.IDReqEle(((recipe != null) ? recipe.source : null) ?? null));
222 if (CS$<>8__locals1.<>4__this.recipe != null)
223 {
224 for (int k = 0; k < CS$<>8__locals1.<>4__this.num; k++)
225 {
226 CS$<>8__locals1.<>4__this.recipe.Craft(CS$<>8__locals1.blessed, k == 0, CS$<>8__locals1.<>4__this.ings, false);
227 }
228 EClass.Sound.Play("craft");
229 Point from = CS$<>8__locals1.<>4__this.crafter.owner.ExistsOnMap ? CS$<>8__locals1.<>4__this.crafter.owner.pos : CS$<>8__locals1.<>4__this.owner.pos;
230 Effect.Get("smoke").Play(from, 0f, null, null);
231 Effect.Get("mine").Play(from, 0f, null, null).SetParticleColor(CS$<>8__locals1.<>4__this.recipe.GetColorMaterial().GetColor()).Emit(10 + EClass.rnd(10));
232 CS$<>8__locals1.<>4__this.owner.renderer.PlayAnime(AnimeID.JumpSmall, default(Vector3), false);
233 }
234 else
235 {
236 Thing thing2 = CS$<>8__locals1.<>4__this.crafter.Craft(CS$<>8__locals1.<>4__this);
237 if (thing2 != null)
238 {
239 if (thing2.category.ignoreBless == 0)
240 {
241 thing2.SetBlessedState(CS$<>8__locals1.blessed);
242 }
243 thing2.PlaySoundDrop(false);
244 EClass._zone.AddCard(thing2, EClass.pc.pos);
245 thing2.Identify(false, IDTSource.Identify);
246 CS$<>8__locals1.<>4__this.owner.Pick(thing2, true, true);
247 }
248 }
249 for (int l = 0; l < CS$<>8__locals1.<>4__this.ings.Count; l++)
250 {
251 if (CS$<>8__locals1.<>4__this.crafter.ShouldConsumeIng(CS$<>8__locals1.<>4__this.crafter.GetSource(CS$<>8__locals1.<>4__this), l))
252 {
253 CS$<>8__locals1.<>4__this.ings[l].Destroy();
254 }
255 }
256 foreach (Thing thing3 in CS$<>8__locals1.<>4__this.ings)
257 {
258 if (thing3.ExistsOnMap)
259 {
260 CS$<>8__locals1.<>4__this.owner.Pick(thing3, true, true);
261 }
262 }
263 if (CS$<>8__locals1.<>4__this.crafter.IsRequireFuel)
264 {
265 CS$<>8__locals1.<>4__this.crafter.owner.ModCharge(-CS$<>8__locals1.<>4__this.crafter.FuelCost * CS$<>8__locals1.<>4__this.num, false);
266 if (CS$<>8__locals1.<>4__this.crafter.owner.c_charges <= 0)
267 {
268 CS$<>8__locals1.<>4__this.crafter.owner.c_charges = 0;
269 CS$<>8__locals1.<>4__this.crafter.Toggle(false, false);
270 }
271 }
272 for (int m = 0; m < CS$<>8__locals1.<>4__this.num; m++)
273 {
274 CS$<>8__locals1.<>4__this.owner.RemoveCondition<ConInvulnerable>();
275 CS$<>8__locals1.<>4__this.owner.elements.ModExp(orCreateElement.id, CS$<>8__locals1.costSP * 12 * (100 + CS$<>8__locals1.duration * 2) / 100, false);
276 CS$<>8__locals1.<>4__this.owner.stamina.Mod(-CS$<>8__locals1.costSP);
277 if (CS$<>8__locals1.<>4__this.owner == null || CS$<>8__locals1.<>4__this.owner.isDead)
278 {
279 break;
280 }
281 }
282 }
283 }.SetDuration(CS$<>8__locals1.duration, 5);
284 this.owner.SetTempHand(-1, -1);
285 if (EClass.debug.godCraft)
286 {
287 progress.SetDuration(1, 1);
288 }
289 yield return base.Do(progress, null);
290 if (progress.status == AIAct.Status.Fail)
291 {
292 yield return this.Cancel();
293 }
294 if (this.crafter.CloseOnComplete)
295 {
296 yield return this.Cancel();
297 }
298 if (!this.crafter.IsConsumeIng)
299 {
300 break;
301 }
302 if (!this.layer || !this.layer.RepeatAI)
303 {
304 goto IL_4A2;
305 }
306 CS$<>8__locals1 = null;
307 targets = null;
308 progress = null;
309 }
310 this.layer.ClearButtons();
311 IL_4A2:
312 yield break;
313 }
314
315 // Token: 0x06000E4B RID: 3659 RVA: 0x0006BCE8 File Offset: 0x00069EE8
316 [CompilerGenerated]
317 private bool <Run>g__IsIngValid|14_0(Thing t, int i)
318 {
319 if (t == null || t.isDestroyed)
320 {
321 return false;
322 }
323 Card rootCard = t.GetRootCard();
324 return (rootCard == null || !rootCard.isChara || rootCard.IsPC) && (this.crafter.IsFactory || this.crafter.IsCraftIngredient(t, i));
325 }
326
327 // Token: 0x04000D43 RID: 3395
328 public LayerBaseCraft layer;
329
330 // Token: 0x04000D44 RID: 3396
331 public TraitCrafter crafter;
332
333 // Token: 0x04000D45 RID: 3397
334 public Recipe recipe;
335
336 // Token: 0x04000D46 RID: 3398
337 public int num = 1;
338
339 // Token: 0x04000D47 RID: 3399
340 public List<Thing> ings = new List<Thing>();
341}
Definition AIAct.cs:7
Definition Card.cs:13
Definition Msg.cs:7
Definition Point.cs:11
Definition Thing.cs:10