Elin Decompiled Documentation EA 23.321 Nightly Patch 1
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 (owner.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 && owner.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 && owner.held != null)
109 {
110 if (owner.held.category.id == "seed")
111 {
112 return "actInstallSeed".lang();
113 }
114 if (owner.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 }
201 {
202 return HitResult.Default;
203 }
204 }
206 {
207 return HitResult.Default;
208 }
209 if (recipe.IsThing)
210 {
211 if (recipe.renderRow is CardRow cardRow && !CanPlaceCard(pos, cardRow.model))
212 {
213 return HitResult.Invalid;
214 }
215 if (recipe.MultiSize && useHeld)
216 {
217 Point point = new Point();
218 for (int i = 0; i < H; i++)
219 {
220 for (int j = 0; j < W; j++)
221 {
222 point.Set(pos.x - j, pos.z + i);
223 if (!point.IsValid)
224 {
225 return HitResult.Invalid;
226 }
227 HitResult hitResult = _GetHitResult(point);
228 if (hitResult != HitResult.Valid && hitResult != HitResult.Warning)
229 {
230 return HitResult.Invalid;
231 }
232 }
233 }
234 return HitResult.Valid;
235 }
236 }
238 {
239 return HitResult.Valid;
240 }
242 {
243 return HitResult.Valid;
244 }
246 {
247 return HitResult.Valid;
248 }
249 return _GetHitResult(pos);
250 }
251
253 {
254 if (useHeld)
255 {
256 if (EClass.pc.held == null || EClass.pc.held.isDestroyed)
257 {
258 return HitResult.Invalid;
259 }
260 if (p.Installed != null)
261 {
263 {
264 return HitResult.Invalid;
265 }
266 if (EClass.pc.held.trait is TraitFertilizer && p.Things.LastItem().trait is TraitFertilizer)
267 {
268 return HitResult.Invalid;
269 }
271 {
272 foreach (Thing thing in p.Things)
273 {
274 if (thing.trait is TraitSeed)
275 {
276 return HitResult.Invalid;
277 }
278 }
279 }
280 }
281 }
283 }
284
285 public override void OnProgressComplete()
286 {
287 if (useHeld)
288 {
289 if (owner.held == null || owner.held.GetRootCard() != owner || pos.Distance(owner.pos) > 1 || !pos.IsInBounds)
290 {
291 return;
292 }
293 if (CanRotateBlock())
294 {
295 SE.Rotate();
297 disableRotateBlock = true;
298 return;
299 }
300 disableRotateBlock = true;
303 target = (owner.held.category.installOne ? owner.held.Split(1) : owner.held);
304 if (target.trait is TraitTile { ConsumeOnUse: not false })
305 {
306 target.ModNum(-1);
307 }
308 dir = recipe._dir;
310 owner.renderer.PlayAnime(AnimeID.Attack_Place, pos);
311 if (target.id == "statue_weird")
312 {
313 owner.Say("statue_install");
314 }
315 }
316 lastPos = pos.Copy();
317 if (ActionMode.Build.IsActive && ActionMode.Build.IsFillMode())
318 {
319 if (recipe.IsBridge)
320 {
323 altitude = 0;
324 }
325 else if (recipe.IsFloor)
326 {
328 }
329 else if (recipe.IsBlock)
330 {
332 }
333 }
334 else
335 {
336 Effect.Get("smoke").Play(pos);
337 Effect.Get("mine").Play(pos).SetParticleColor(recipe.GetColorMaterial().GetColor())
338 .Emit(10 + EClass.rnd(10));
340 {
342 {
343 pos.cell.blockDir = 2;
344 owner.PlaySound(pos.matBlock.GetSoundImpact());
346 return;
347 }
348 if (pos.sourceRoofBlock.tileType.IsWallOrFence && pos.cell._roofBlockDir % 4 != 2 && pos.cell._roofBlockDir % 4 != recipe._dir)
349 {
350 pos.cell._roofBlockDir = (byte)(pos.cell._roofBlockDir / 4 * 4 + 2);
351 owner.PlaySound(pos.matBlock.GetSoundImpact());
353 return;
354 }
355 }
356 }
357 if (bridgeHeight > 150)
358 {
359 bridgeHeight = 150;
360 }
361 Chara chara = owner;
362 recipe.Build(this);
363 owner = chara;
364 resources.Clear();
365 if (owner.IsPC)
366 {
368 }
372 owner.renderer.SetFirst(first: true);
373 if (recipe.IsFloor)
374 {
375 foreach (Card item in pos.ListThings<TraitNewZone>())
376 {
377 _ = (item.trait as TraitNewZone).IsDownstairs;
378 }
379 }
380 if (!ActionMode.Build.IsActive || !ActionMode.Build.IsRoofEditMode())
381 {
382 pos.ForeachMultiSize(recipe.W, recipe.H, delegate(Point p, bool center)
383 {
384 if (p.IsBlocked && p.HasChara)
385 {
386 foreach (Chara item2 in p.ListCharas())
387 {
388 owner.Kick(item2, ignoreSelf: true, karmaLoss: false, show: false);
389 }
390 }
391 });
392 }
394 {
396 }
397 }
398
399 public override void OnDestroy()
400 {
401 foreach (Thing resource in resources)
402 {
404 }
405 }
406
407 public override void DrawMarker(int x, int z, RenderParam p)
408 {
409 recipe.OnRenderMarker(Point.shared.Set(x, z), owner != null, HitResult.Default, x == pos.x && z == pos.z, dir, bridgeHeight + altitude);
410 }
411}
AnimeID
Definition: AnimeID.cs:2
static bool not(DramaManager dm, Dictionary< string, string > line, params string[] parameters)
HitResult
Definition: HitResult.cs:2
new Chara owner
Definition: AIAct.cs:14
Definition: AM_Adv.cs:7
static int actCount
Definition: AM_Adv.cs:102
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:78
Thing Split(int a)
Definition: Card.cs:3658
string id
Definition: Card.cs:36
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6578
void Kick(Point p, bool ignoreSelf=false, bool checkWall=true)
Definition: Card.cs:6252
TileType TileType
Definition: Card.cs:2189
Point pos
Definition: Card.cs:60
Trait trait
Definition: Card.cs:54
Card GetRootCard()
Definition: Card.cs:3600
SourceCategory.Row category
Definition: Card.cs:2101
void ModNum(int a, bool notify=true)
Definition: Card.cs:3689
CardRenderer renderer
Definition: Card.cs:64
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7256
byte _roofBlockDir
Definition: Cell.cs:56
int floorDir
Definition: Cell.cs:930
void RotateBlock(int a)
Definition: Cell.cs:1475
byte bridgeHeight
Definition: Cell.cs:82
int blockDir
Definition: Cell.cs:906
Definition: Chara.cs:10
Card held
Definition: Chara.cs:70
override bool IsPC
Definition: Chara.cs:630
bool IsHostile()
Definition: Chara.cs:6812
override void LookAt(Card c)
Definition: Chara.cs:3725
bool ignoreBuildRule
Definition: CoreDebug.cs:200
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static Scene scene
Definition: EClass.cs:31
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
Definition: EInput.cs:8
static ButtonState rightMouse
Definition: EInput.cs:362
Definition: Effect.cs:7
static Effect Get(Effect original)
Definition: Effect.cs:80
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:100
SurvivalManager survival
Definition: Game.cs:228
bool IsSurvival
Definition: Game.cs:276
void RefreshFOV(int x, int z, int radius=6, bool recalculate=false)
Definition: Map.cs:942
PropsStocked Stocked
Definition: Map.cs:121
void RefreshShadow(int x, int z)
Definition: Map.cs:1845
void OnBuild(Recipe r)
Definition: Player.cs:779
Flags flags
Definition: Player.cs:1161
Definition: Point.cs:9
Thing Installed
Definition: Point.cs:327
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:1391
Point Copy()
Definition: Point.cs:491
Point Set(int _x, int _z)
Definition: Point.cs:503
bool IsBlocked
Definition: Point.cs:363
List< Thing > Things
Definition: Point.cs:338
int x
Definition: Point.cs:36
bool HasWallOrFence
Definition: Point.cs:155
void RefreshTile()
Definition: Point.cs:1287
bool IsInBoundsPlus
Definition: Point.cs:116
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:966
List< Chara > ListCharas()
Definition: Point.cs:1177
bool IsValid
Definition: Point.cs:88
int Distance(Point p)
Definition: Point.cs:995
Chara FirstChara
Definition: Point.cs:288
bool HasBlock
Definition: Point.cs:141
bool IsInBounds
Definition: Point.cs:104
Cell cell
Definition: Point.cs:51
bool HasChara
Definition: Point.cs:238
SourceBlock.Row sourceRoofBlock
Definition: Point.cs:61
Thing Find(int uid)
Definition: Props.cs:389
bool IsThingSpecified
Definition: Recipe.cs:54
Definition: Recipe.cs:7
virtual void OnRenderMarker(Point point, bool active, HitResult result, bool main, int dir, int bridgeHeight)
Definition: Recipe.cs:730
bool HasSameTile(Point point, int dir, int altitude, int bridgeHeight)
Definition: Recipe.cs:595
virtual Card Mold
Definition: Recipe.cs:254
virtual void SetDir(int d)
Definition: Recipe.cs:910
virtual TileType tileType
Definition: Recipe.cs:215
virtual RenderRow renderRow
Definition: Recipe.cs:210
List< Ingredient > ingredients
Definition: Recipe.cs:181
virtual void Build(TaskBuild task)
Definition: Recipe.cs:640
virtual bool IsFloorOrBridge
Definition: Recipe.cs:226
virtual bool IsBlock
Definition: Recipe.cs:246
virtual int H
Definition: Recipe.cs:269
virtual bool IsThing
Definition: Recipe.cs:252
bool IsFloor
Definition: Recipe.cs:242
bool IsWallOrFence
Definition: Recipe.cs:248
bool MultiSize
Definition: Recipe.cs:283
int _dir
Definition: Recipe.cs:192
bool IsBridge
Definition: Recipe.cs:250
virtual SourceMaterial.Row GetColorMaterial()
Definition: Recipe.cs:506
virtual int W
Definition: Recipe.cs:257
ActionMode actionMode
Definition: Scene.cs:79
virtual bool IsRegion
Definition: Spatial.cs:515
void OnExpandFloor(Point pos)
bool CanPlaceCard(Point pos, Card c)
Definition: TaskBaseBuild.cs:3
override void DrawMarker(int x, int z, RenderParam p)
Definition: TaskBuild.cs:407
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:252
override void OnProgressComplete()
Definition: TaskBuild.cs:285
Point lastPos
Definition: TaskBuild.cs:37
override HitResult GetHitResult()
Definition: TaskBuild.cs:149
override void OnDestroy()
Definition: TaskBuild.cs:399
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:203
virtual bool IsBlockPass
Definition: TileType.cs:159
HitResult _HitTest(Point pos, Card target, bool canIgnore=true)
Definition: TileType.cs:307
virtual bool CanExtendBuild
Definition: Trait.cs:181
virtual bool CanBuildInTown
Definition: Trait.cs:280
virtual bool IsDoor
Definition: Trait.cs:58
virtual bool CanBeOnlyBuiltInHome
Definition: Trait.cs:277
bool IsPCFactionOrTent
Definition: Zone.cs:480
virtual bool RestrictBuild
Definition: Zone.cs:294
bool IsPCFaction
Definition: Zone.cs:477
Card AddCard(Card t, Point point)
Definition: Zone.cs:2086