Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
TaskBuild.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3using UnityEngine;
4
5public class TaskBuild : TaskBaseBuild
6{
7 [JsonProperty]
8 public Recipe recipe;
9
10 [JsonProperty]
11 public int dir;
12
13 [JsonProperty]
14 public int bridgeHeight;
15
16 [JsonProperty]
17 public int altitude;
18
19 [JsonProperty]
20 public List<Thing> resources = new List<Thing>();
21
22 [JsonProperty]
23 public int[] reqs;
24
25 public Card held;
26
27 public float fx;
28
29 public float fy;
30
31 public bool freePos;
32
33 public bool disableRotateBlock;
34
35 public Card target;
36
37 public Point lastPos;
38
39 public override int destDist => 1;
40
41 public override bool CanPressRepeat
42 {
43 get
44 {
45 if (useHeld)
46 {
47 if (EClass.pc.held != null)
48 {
50 }
51 return false;
52 }
53 return false;
54 }
55 }
56
57 public override bool HasProgress => false;
58
60
61 public bool useHeld => held != null;
62
63 public override int W => recipe.W;
64
65 public override int H => recipe.H;
66
67 public override bool isBlock => recipe.IsBlock;
68
69 public override bool CanManualCancel()
70 {
71 return true;
72 }
73
74 public bool CanRotateBlock()
75 {
77 {
78 disableRotateBlock = false;
79 }
80 if (useHeld && EClass.pc.held != null)
81 {
83 {
84 return false;
85 }
87 {
88 return false;
89 }
91 {
92 return false;
93 }
95 {
96 return true;
97 }
98 }
99 return false;
100 }
101
102 public override string GetText(string str = "")
103 {
104 if (CanRotateBlock())
105 {
106 return "actRotateWall".lang();
107 }
108 if (useHeld && EClass.pc.held != null)
109 {
110 if (EClass.pc.held.category.id == "seed")
111 {
112 return "actInstallSeed".lang();
113 }
114 if (EClass.pc.held.id == "fertilizer")
115 {
116 return "actInstallFertilizer".lang();
117 }
118 }
119 return base.GetText(str);
120 }
121
122 public override bool _CanPerformTask(Chara chara, int radius)
123 {
124 Recipe.Ingredient ingredient = recipe.ingredients[0];
125 if (!ingredient.IsThingSpecified && ingredient.thing == null)
126 {
127 ingredient.thing = EClass._map.Stocked.Find(ingredient.id, ingredient.mat, ingredient.refVal);
128 if (ingredient.thing == null)
129 {
130 TryLater();
131 return false;
132 }
133 }
134 return true;
135 }
136
137 public override void OnAdd()
138 {
139 if (reqs == null)
140 {
141 reqs = new int[recipe.ingredients.Count];
142 for (int i = 0; i < recipe.ingredients.Count; i++)
143 {
144 reqs[i] = recipe.ingredients[i].req;
145 }
146 }
147 }
148
149 public override HitResult GetHitResult()
150 {
152 {
153 return HitResult.Invalid;
154 }
155 if (recipe == null)
156 {
157 Debug.Log("recipe is null");
158 return HitResult.Invalid;
159 }
160 if (useHeld)
161 {
162 if (EClass.pc.held == null || EClass.pc.held.GetRootCard() != EClass.pc || EClass.pc.held != held)
163 {
164 return HitResult.Invalid;
165 }
167 {
168 return HitResult.Invalid;
169 }
170 if (CanRotateBlock())
171 {
172 return HitResult.Valid;
173 }
175 {
176 recipe.SetDir((pos.cell.blockDir != 0) ? 1 : 0);
177 }
179 {
181 {
182 return HitResult.Invalid;
183 }
185 {
186 return HitResult.Invalid;
187 }
188 }
189 }
190 if (lastPos != null)
191 {
192 if (recipe.IsBlock && lastPos.x != pos.x && lastPos.z != pos.z)
193 {
194 return HitResult.Invalid;
195 }
196 if (recipe.IsWallOrFence && ((recipe._dir == 0 && pos.z != lastPos.z) || (recipe._dir == 1 && pos.x != lastPos.x)))
197 {
198 return HitResult.Invalid;
199 }
200 }
202 {
203 return HitResult.Default;
204 }
205 if (recipe.IsThing)
206 {
207 if (recipe.renderRow is CardRow cardRow && !CanPlaceCard(pos, cardRow.model))
208 {
209 return HitResult.Invalid;
210 }
211 if (recipe.MultiSize && useHeld)
212 {
213 Point point = new Point();
214 for (int i = 0; i < H; i++)
215 {
216 for (int j = 0; j < W; j++)
217 {
218 point.Set(pos.x - j, pos.z + i);
219 if (!point.IsValid)
220 {
221 return HitResult.Invalid;
222 }
223 HitResult hitResult = _GetHitResult(point);
224 if (hitResult != HitResult.Valid && hitResult != HitResult.Warning)
225 {
226 return HitResult.Invalid;
227 }
228 }
229 }
230 return HitResult.Valid;
231 }
232 }
234 {
235 return HitResult.Valid;
236 }
238 {
239 return HitResult.Valid;
240 }
242 {
243 return HitResult.Valid;
244 }
245 return _GetHitResult(pos);
246 }
247
249 {
250 if (useHeld)
251 {
252 if (EClass.pc.held == null || EClass.pc.held.isDestroyed)
253 {
254 return HitResult.Invalid;
255 }
256 if (p.Installed != null)
257 {
259 {
260 return HitResult.Invalid;
261 }
262 if (EClass.pc.held.trait is TraitFertilizer && p.Things.LastItem().trait is TraitFertilizer)
263 {
264 return HitResult.Invalid;
265 }
267 {
268 foreach (Thing thing in p.Things)
269 {
270 if (thing.trait is TraitSeed)
271 {
272 return HitResult.Invalid;
273 }
274 }
275 }
276 }
277 }
279 }
280
281 public override void OnProgressComplete()
282 {
283 if (useHeld)
284 {
285 if (EClass.pc.held == null || EClass.pc.held.GetRootCard() != EClass.pc || pos.Distance(EClass.pc.pos) > 1 || !pos.IsInBounds)
286 {
287 return;
288 }
289 if (CanRotateBlock())
290 {
291 SE.Rotate();
293 disableRotateBlock = true;
294 return;
295 }
296 disableRotateBlock = true;
299 target = (EClass.pc.held.category.installOne ? EClass.pc.held.Split(1) : EClass.pc.held);
300 if (target.trait is TraitTile)
301 {
302 target.ModNum(-1);
303 }
304 dir = recipe._dir;
306 EClass.pc.renderer.PlayAnime(AnimeID.Attack_Place, pos);
307 if (target.id == "statue_weird")
308 {
309 EClass.pc.Say("statue_install");
310 }
311 }
312 lastPos = pos.Copy();
313 if (ActionMode.Build.IsActive && ActionMode.Build.IsFillMode())
314 {
315 if (recipe.IsBridge)
316 {
319 altitude = 0;
320 }
321 else if (recipe.IsFloor)
322 {
324 }
325 else if (recipe.IsBlock)
326 {
328 }
329 }
330 else
331 {
332 Effect.Get("smoke").Play(pos);
333 Effect.Get("mine").Play(pos).SetParticleColor(recipe.GetColorMaterial().GetColor())
334 .Emit(10 + EClass.rnd(10));
336 {
338 {
339 pos.cell.blockDir = 2;
340 EClass.pc.PlaySound(pos.matBlock.GetSoundImpact());
342 return;
343 }
344 if (pos.sourceRoofBlock.tileType.IsWallOrFence && pos.cell._roofBlockDir % 4 != 2 && pos.cell._roofBlockDir % 4 != recipe._dir)
345 {
346 pos.cell._roofBlockDir = (byte)(pos.cell._roofBlockDir / 4 * 4 + 2);
347 EClass.pc.PlaySound(pos.matBlock.GetSoundImpact());
349 return;
350 }
351 }
352 }
353 if (bridgeHeight > 150)
354 {
355 bridgeHeight = 150;
356 }
357 recipe.Build(this);
358 resources.Clear();
363 EClass.pc.renderer.SetFirst(first: true);
364 if (recipe.IsFloor)
365 {
366 foreach (Card item in pos.ListThings<TraitNewZone>())
367 {
368 _ = (item.trait as TraitNewZone).IsDownstairs;
369 }
370 }
372 {
373 return;
374 }
375 pos.ForeachMultiSize(recipe.W, recipe.H, delegate(Point p, bool center)
376 {
377 if (p.IsBlocked && p.HasChara)
378 {
379 foreach (Chara item2 in p.ListCharas())
380 {
381 EClass.pc.Kick(item2, ignoreSelf: true, karmaLoss: false, show: false);
382 }
383 }
384 });
385 }
386
387 public override void OnDestroy()
388 {
389 foreach (Thing resource in resources)
390 {
392 }
393 }
394
395 public override void DrawMarker(int x, int z, RenderParam p)
396 {
397 recipe.OnRenderMarker(Point.shared.Set(x, z), owner != null, HitResult.Default, x == pos.x && z == pos.z, dir, bridgeHeight + altitude);
398 }
399}
AnimeID
Definition: AnimeID.cs:2
HitResult
Definition: HitResult.cs:2
new Chara owner
Definition: AIAct.cs:14
Definition: AM_Adv.cs:6
static int actCount
Definition: AM_Adv.cs:101
int bridgeHeight
Definition: AM_Build.cs:6
override bool IsFillMode()
Definition: AM_Build.cs:92
override bool IsRoofEditMode(Card c=null)
Definition: AM_Build.cs:87
void FixBridge(Point point, Recipe recipe)
Definition: AM_Build.cs:230
virtual bool IsRoofEditMode(Card c=null)
Definition: ActionMode.cs:311
static AM_Build Build
Definition: ActionMode.cs:49
bool pressing
Definition: ButtonState.cs:35
void PlayAnime(AnimeID id, bool force)
virtual void SetFirst(bool first, Vector3 pos)
Definition: Card.cs:11
bool isDestroyed
Definition: Card.cs:71
Thing Split(int a)
Definition: Card.cs:3231
string id
Definition: Card.cs:31
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5404
TileType TileType
Definition: Card.cs:2011
Point pos
Definition: Card.cs:55
Trait trait
Definition: Card.cs:49
Card GetRootCard()
Definition: Card.cs:3173
SourceCategory.Row category
Definition: Card.cs:1925
void ModNum(int a, bool notify=true)
Definition: Card.cs:3262
CardRenderer renderer
Definition: Card.cs:57
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6046
byte _roofBlockDir
Definition: Cell.cs:54
int floorDir
Definition: Cell.cs:922
void RotateBlock(int a)
Definition: Cell.cs:1435
byte bridgeHeight
Definition: Cell.cs:74
int blockDir
Definition: Cell.cs:898
Definition: Chara.cs:10
Card held
Definition: Chara.cs:67
void Kick(Point p, bool ignoreSelf=false)
Definition: Chara.cs:5174
bool IsHostile()
Definition: Chara.cs:5884
override void LookAt(Card c)
Definition: Chara.cs:3219
bool ignoreBuildRule
Definition: CoreDebug.cs:184
Definition: EClass.cs:5
static Scene scene
Definition: EClass.cs:30
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
Definition: EInput.cs:8
static ButtonState rightMouse
Definition: EInput.cs:351
Definition: Effect.cs:7
static Effect Get(Effect original)
Definition: Effect.cs:85
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:100
void RefreshFOV(int x, int z, int radius=6, bool recalculate=false)
Definition: Map.cs:923
PropsStocked Stocked
Definition: Map.cs:121
void RefreshShadow(int x, int z)
Definition: Map.cs:1787
void OnBuild(Recipe r)
Definition: Player.cs:553
Flags flags
Definition: Player.cs:895
Definition: Point.cs:9
Thing Installed
Definition: Point.cs:303
static Point shared
Definition: Point.cs:20
SourceMaterial.Row matBlock
Definition: Point.cs:55
static Point Invalid
Definition: Point.cs:28
void ForeachMultiSize(int w, int h, Action< Point, bool > action)
Definition: Point.cs:1349
Point Copy()
Definition: Point.cs:467
Point Set(int _x, int _z)
Definition: Point.cs:479
bool IsBlocked
Definition: Point.cs:339
List< Thing > Things
Definition: Point.cs:314
int x
Definition: Point.cs:36
bool HasWallOrFence
Definition: Point.cs:155
void RefreshTile()
Definition: Point.cs:1245
bool IsInBoundsPlus
Definition: Point.cs:116
int z
Definition: Point.cs:39
List< Chara > ListCharas()
Definition: Point.cs:1135
bool IsValid
Definition: Point.cs:88
int Distance(Point p)
Definition: Point.cs:953
Chara FirstChara
Definition: Point.cs:264
bool HasBlock
Definition: Point.cs:141
bool IsInBounds
Definition: Point.cs:104
Cell cell
Definition: Point.cs:51
bool HasChara
Definition: Point.cs:226
SourceBlock.Row sourceRoofBlock
Definition: Point.cs:61
Thing Find(int uid)
Definition: Props.cs:357
bool IsThingSpecified
Definition: Recipe.cs:45
Definition: Recipe.cs:7
virtual void OnRenderMarker(Point point, bool active, HitResult result, bool main, int dir, int bridgeHeight)
Definition: Recipe.cs:688
bool HasSameTile(Point point, int dir, int altitude, int bridgeHeight)
Definition: Recipe.cs:560
virtual Card Mold
Definition: Recipe.cs:237
virtual void SetDir(int d)
Definition: Recipe.cs:868
virtual TileType tileType
Definition: Recipe.cs:198
virtual RenderRow renderRow
Definition: Recipe.cs:193
List< Ingredient > ingredients
Definition: Recipe.cs:164
virtual void Build(TaskBuild task)
Definition: Recipe.cs:605
virtual bool IsFloorOrBridge
Definition: Recipe.cs:209
virtual bool IsBlock
Definition: Recipe.cs:229
virtual int H
Definition: Recipe.cs:252
virtual bool IsThing
Definition: Recipe.cs:235
bool IsFloor
Definition: Recipe.cs:225
bool IsWallOrFence
Definition: Recipe.cs:231
bool MultiSize
Definition: Recipe.cs:266
int _dir
Definition: Recipe.cs:175
bool IsBridge
Definition: Recipe.cs:233
virtual SourceMaterial.Row GetColorMaterial()
Definition: Recipe.cs:481
virtual int W
Definition: Recipe.cs:240
ActionMode actionMode
Definition: Scene.cs:77
virtual bool IsRegion
Definition: Spatial.cs:501
bool CanPlaceCard(Point pos, Card c)
Definition: TaskBaseBuild.cs:3
override void DrawMarker(int x, int z, RenderParam p)
Definition: TaskBuild.cs:395
Card held
Definition: TaskBuild.cs:25
float fy
Definition: TaskBuild.cs:29
float fx
Definition: TaskBuild.cs:27
override int destDist
Definition: TaskBuild.cs:39
int altitude
Definition: TaskBuild.cs:17
Recipe recipe
Definition: TaskBuild.cs:8
bool CanRotateBlock()
Definition: TaskBuild.cs:74
override bool isBlock
Definition: TaskBuild.cs:67
Card target
Definition: TaskBuild.cs:35
override void OnAdd()
Definition: TaskBuild.cs:137
int bridgeHeight
Definition: TaskBuild.cs:14
override int W
Definition: TaskBuild.cs:63
bool useHeld
Definition: TaskBuild.cs:61
override bool CanManualCancel()
Definition: TaskBuild.cs:69
override int H
Definition: TaskBuild.cs:65
int dir
Definition: TaskBuild.cs:11
HitResult _GetHitResult(Point p)
Definition: TaskBuild.cs:248
override void OnProgressComplete()
Definition: TaskBuild.cs:281
Point lastPos
Definition: TaskBuild.cs:37
override HitResult GetHitResult()
Definition: TaskBuild.cs:149
override void OnDestroy()
Definition: TaskBuild.cs:387
override bool _CanPerformTask(Chara chara, int radius)
Definition: TaskBuild.cs:122
override string GetText(string str="")
Definition: TaskBuild.cs:102
override bool HasProgress
Definition: TaskBuild.cs:57
List< Thing > resources
Definition: TaskBuild.cs:20
override bool CanPressRepeat
Definition: TaskBuild.cs:42
bool freePos
Definition: TaskBuild.cs:31
int[] reqs
Definition: TaskBuild.cs:23
override bool destIgnoreConnection
Definition: TaskBuild.cs:59
bool disableRotateBlock
Definition: TaskBuild.cs:33
Point pos
Definition: TaskPoint.cs:11
void TryLater(int min=30)
Definition: Task.cs:26
Definition: Thing.cs:8
virtual bool IsDoor
Definition: TileType.cs:193
virtual bool IsBlockPass
Definition: TileType.cs:149
HitResult _HitTest(Point pos, Card target, bool canIgnore=true)
Definition: TileType.cs:287
virtual bool CanExtendBuild
Definition: Trait.cs:161
virtual bool CanBuildInTown
Definition: Trait.cs:258
virtual bool IsDoor
Definition: Trait.cs:56
virtual bool CanBeOnlyBuiltInHome
Definition: Trait.cs:255
bool IsPCFactionOrTent
Definition: Zone.cs:467
virtual bool RestrictBuild
Definition: Zone.cs:283
bool IsPCFaction
Definition: Zone.cs:464
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893