Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DeadMansChestBiome.cs
Go to the documentation of this file.
3using Newtonsoft.Json;
4using Terraria.ID;
7
9
11{
13 {
14 public int directionX;
15
16 public int xPush;
17
18 public int x;
19
20 public int y;
21
23
24 public Tile t;
25
27 {
28 this.position = position;
29 this.directionX = directionX;
30 this.x = x;
31 this.y = y;
32 this.xPush = xPush;
33 this.t = t;
34 }
35 }
36
38 {
40
41 public int yPush;
42
43 public int requiredHeight;
44
45 public int bestType;
46
48 {
49 this.position = position;
50 this.yPush = yPush;
51 this.requiredHeight = requiredHeight;
52 this.bestType = bestType;
53 }
54 }
55
57 {
59
60 public int dirX;
61
62 public int dirY;
63
64 public int steps;
65
67 {
68 this.position = position;
69 this.dirX = dirX;
70 this.dirY = dirY;
71 this.steps = steps;
72 }
73 }
74
76 {
78
80 {
81 this.position = position;
82 }
83 }
84
86
88
90
92
93 [JsonProperty("NumberOfDartTraps")]
95
96 [JsonProperty("NumberOfBoulderTraps")]
98
99 [JsonProperty("NumberOfStepsBetweenBoulderTraps")]
101
102 public override bool Place(Point origin, StructureMap structures)
103 {
104 if (!IsAGoodSpot(origin))
105 {
106 return false;
107 }
108 ClearCaches();
109 Point position = new Point(origin.X, origin.Y + 1);
110 FindBoulderTrapSpots(position);
111 FindDartTrapSpots(position);
112 FindExplosiveTrapSpots(position);
113 if (!AreThereEnoughTraps())
114 {
115 return false;
116 }
119 {
121 }
123 {
125 }
127 {
129 }
131 {
132 ActuallyPlaceExplosive(item.position);
133 }
135 return true;
136 }
137
138 private void PlaceWiresForExplosives(Point origin)
139 {
141 {
142 return;
143 }
144 PlaceWireLine(origin, 0, 1, _explosivePlacementAttempt[0].position.Y - origin.Y);
145 int num = _explosivePlacementAttempt[0].position.X;
146 int num2 = _explosivePlacementAttempt[0].position.X;
147 int y = _explosivePlacementAttempt[0].position.Y;
148 for (int i = 1; i < _explosivePlacementAttempt.Count; i++)
149 {
150 int x = _explosivePlacementAttempt[i].position.X;
151 if (num > x)
152 {
153 num = x;
154 }
155 if (num2 < x)
156 {
157 num2 = x;
158 }
159 }
160 PlaceWireLine(new Point(num, y), 1, 0, num2 - num);
161 }
162
163 private bool AreThereEnoughTraps()
164 {
166 {
167 return _dartTrapPlacementSpots.Count >= 1;
168 }
169 return false;
170 }
171
179
180 private void FindBoulderTrapSpots(Point position)
181 {
182 int x = position.X;
183 int num = GenBase._random.Next(_numberOfBoulderTraps);
185 x -= num / 2 * num2;
186 int num3 = position.Y - 6;
187 for (int i = 0; i <= num; i++)
188 {
190 x += num2;
191 }
193 {
194 return;
195 }
196 int num4 = _boulderPlacementSpots[0].position.X;
197 int num5 = _boulderPlacementSpots[0].position.X;
198 for (int j = 1; j < _boulderPlacementSpots.Count; j++)
199 {
200 int x2 = _boulderPlacementSpots[j].position.X;
201 if (num4 > x2)
202 {
203 num4 = x2;
204 }
205 if (num5 < x2)
206 {
207 num5 = x2;
208 }
209 }
210 if (num4 > position.X)
211 {
212 num4 = position.X;
213 }
214 if (num5 < position.X)
215 {
216 num5 = position.X;
217 }
219 _wirePlacementSpots.Add(new WirePlacementAttempt(position, 0, -1, 7));
220 }
221
222 private void FindBoulderTrapSpot(Point position)
223 {
224 int x = position.X;
225 int y = position.Y;
226 for (int i = 0; i < 50; i++)
227 {
228 if (Main.tile[x, y - i].active())
229 {
230 PlaceBoulderTrapSpot(new Point(x, y - i), i);
231 break;
232 }
233 }
234 }
235
236 private void PlaceBoulderTrapSpot(Point position, int yPush)
237 {
238 int[] array = new int[TileID.Count];
239 for (int i = position.X; i < position.X + 2; i++)
240 {
241 for (int j = position.Y - 4; j <= position.Y; j++)
242 {
243 Tile tile = Main.tile[i, j];
244 if (tile.active() && !Main.tileFrameImportant[tile.type] && Main.tileSolid[tile.type])
245 {
246 array[tile.type]++;
247 }
248 if ((tile.active() && !TileID.Sets.CanBeClearedDuringGeneration[tile.type]) || (tile.active() && TileID.Sets.IsAContainer[tile.type]))
249 {
250 return;
251 }
252 }
253 }
254 for (int k = position.X - 1; k < position.X + 2 + 1; k++)
255 {
256 for (int l = position.Y - 4 - 1; l <= position.Y - 4 + 2; l++)
257 {
258 Tile tile2 = Main.tile[k, l];
259 if (!tile2.active() || TileID.Sets.IsAContainer[tile2.type])
260 {
261 return;
262 }
263 }
264 }
265 int num = 2;
266 int num2 = position.X - num;
267 int num3 = position.Y - 4 - num;
268 int num4 = position.X + num + 1;
269 int num5 = position.Y - 4 + num + 1;
270 for (int m = num2; m <= num4; m++)
271 {
272 for (int n = num3; n <= num5; n++)
273 {
274 Tile tile3 = Main.tile[m, n];
275 if (tile3.active() && TileID.Sets.IsAContainer[tile3.type])
276 {
277 return;
278 }
279 }
280 }
281 int num6 = -1;
282 for (int num7 = 0; num7 < array.Length; num7++)
283 {
284 if (num6 == -1 || array[num6] < array[num7])
285 {
286 num6 = num7;
287 }
288 }
289 _boulderPlacementSpots.Add(new BoulderPlacementAttempt(position, yPush - 1, 4, num6));
290 }
291
292 private void FindDartTrapSpots(Point position)
293 {
294 int num = GenBase._random.Next(_numberOfDartTraps);
295 int num2 = ((GenBase._random.Next(2) != 0) ? 1 : (-1));
296 int steps = -1;
297 for (int i = 0; i < num; i++)
298 {
299 bool num3 = FindDartTrapSpotSingle(position, num2);
300 num2 *= -1;
301 position.Y--;
302 if (num3)
303 {
304 steps = i;
305 }
306 }
307 _wirePlacementSpots.Add(new WirePlacementAttempt(new Point(position.X, position.Y + num), 0, -1, steps));
308 }
309
310 private bool FindDartTrapSpotSingle(Point position, int directionX)
311 {
312 int x = position.X;
313 int y = position.Y;
314 for (int i = 0; i < 20; i++)
315 {
316 Tile tile = Main.tile[x + i * directionX, y];
317 if ((!tile.active() || tile.type < 0 || tile.type >= TileID.Count || !TileID.Sets.IsAContainer[tile.type]) && tile.active() && Main.tileSolid[tile.type])
318 {
319 if (i >= 5 && !tile.actuator() && !Main.tileFrameImportant[tile.type] && TileID.Sets.CanBeClearedDuringGeneration[tile.type])
320 {
321 _dartTrapPlacementSpots.Add(new DartTrapPlacementAttempt(position, directionX, x, y, i, tile));
322 return true;
323 }
324 return false;
325 }
326 }
327 return false;
328 }
329
330 private void FindExplosiveTrapSpots(Point position)
331 {
332 int x = position.X;
333 int y = position.Y + 3;
334 List<int> list = new List<int>();
335 if (IsGoodSpotsForExplosive(x, y))
336 {
337 list.Add(x);
338 }
339 x++;
340 if (IsGoodSpotsForExplosive(x, y))
341 {
342 list.Add(x);
343 }
344 int num = -1;
345 if (list.Count > 0)
346 {
347 num = list[GenBase._random.Next(list.Count)];
348 }
349 list.Clear();
350 x += GenBase._random.Next(2, 6);
351 int num2 = 4;
352 for (int i = x; i < x + num2; i++)
353 {
354 if (IsGoodSpotsForExplosive(i, y))
355 {
356 list.Add(i);
357 }
358 }
359 int num3 = -1;
360 if (list.Count > 0)
361 {
362 num3 = list[GenBase._random.Next(list.Count)];
363 }
364 x = position.X - num2 - GenBase._random.Next(2, 6);
365 for (int j = x; j < x + num2; j++)
366 {
368 {
369 list.Add(j);
370 }
371 }
372 int num4 = -1;
373 if (list.Count > 0)
374 {
375 num4 = list[GenBase._random.Next(list.Count)];
376 }
377 if (num4 != -1)
378 {
380 }
381 if (num != -1)
382 {
384 }
385 if (num3 != -1)
386 {
388 }
389 }
390
391 private bool IsGoodSpotsForExplosive(int x, int y)
392 {
393 Tile tile = Main.tile[x, y];
394 if (tile.active() && tile.type >= 0 && tile.type < TileID.Count && TileID.Sets.IsAContainer[tile.type])
395 {
396 return false;
397 }
398 if (tile.active() && Main.tileSolid[tile.type] && !Main.tileFrameImportant[tile.type] && !Main.tileSolidTop[tile.type])
399 {
400 return true;
401 }
402 return false;
403 }
404
406 {
407 List<int> list = new List<int>();
408 bool[] array = new bool[TileID.Sets.GeneralPlacementTiles.Length];
409 for (int i = 0; i < array.Length; i++)
410 {
411 array[i] = TileID.Sets.GeneralPlacementTiles[i];
412 }
413 array[21] = true;
414 array[467] = true;
415 for (int j = 0; j < 8000; j++)
416 {
417 Chest chest = Main.chest[j];
418 if (chest == null)
419 {
420 continue;
421 }
422 Point position = new Point(chest.x, chest.y);
423 if (IsAGoodSpot(position))
424 {
425 ClearCaches();
426 Point position2 = new Point(position.X, position.Y + 1);
429 if (AreThereEnoughTraps() && (structures == null || structures.CanPlace(new Rectangle(position.X, position.Y, 1, 1), array, 10)))
430 {
431 list.Add(j);
432 }
433 }
434 }
435 return list;
436 }
437
438 private static bool IsAGoodSpot(Point position)
439 {
440 if (!WorldGen.InWorld(position.X, position.Y, 50))
441 {
442 return false;
443 }
444 if (WorldGen.oceanDepths(position.X, position.Y))
445 {
446 return false;
447 }
448 Tile tile = Main.tile[position.X, position.Y];
449 if (tile.type != 21)
450 {
451 return false;
452 }
453 if (tile.frameX / 36 != 1)
454 {
455 return false;
456 }
457 tile = Main.tile[position.X, position.Y + 2];
459 {
460 return false;
461 }
462 if (WorldGen.countWires(position.X, position.Y, 20) > 0)
463 {
464 return false;
465 }
466 if (WorldGen.countTiles(position.X, position.Y, jungle: false, lavaOk: true) < 40)
467 {
468 return false;
469 }
470 return true;
471 }
472
474 {
475 for (int i = 0; i < 2; i++)
476 {
477 for (int j = 0; j < 2; j++)
478 {
479 int num = position.X + i;
480 int num2 = position.Y + j;
481 Tile tile = Main.tile[num, num2];
482 tile.type = 467;
483 tile.frameX = (short)(144 + i * 18);
484 tile.frameY = (short)(j * 18);
485 }
486 }
487 if (GenBase._random.Next(3) != 0)
488 {
489 return;
490 }
491 int num3 = Chest.FindChest(position.X, position.Y);
492 if (num3 <= -1)
493 {
494 return;
495 }
496 Item[] item = Main.chest[num3].item;
497 for (int num4 = item.Length - 2; num4 > 0; num4--)
498 {
499 Item item2 = item[num4];
500 if (item2.stack != 0)
501 {
502 item[num4 + 1] = item2.DeepClone();
503 }
504 }
505 item[1] = new Item();
506 item[1].SetDefaults(5007);
507 Main.chest[num3].item = item;
508 }
509
510 private void ActuallyPlaceDartTrap(Point position, int directionX, int x, int y, int xPush, Tile t)
511 {
512 t.type = 137;
513 t.frameY = 0;
514 if (directionX == -1)
515 {
516 t.frameX = 18;
517 }
518 else
519 {
520 t.frameX = 0;
521 }
522 t.slope(0);
523 t.halfBrick(halfBrick: false);
524 WorldGen.TileFrame(x, y, resetFrame: true);
525 PlaceWireLine(position, directionX, 0, xPush);
526 }
527
528 private void PlaceWireLine(Point start, int offsetX, int offsetY, int steps)
529 {
530 for (int i = 0; i <= steps; i++)
531 {
532 Main.tile[start.X + offsetX * i, start.Y + offsetY * i].wire(wire: true);
533 }
534 }
535
536 private void ActuallyPlaceBoulderTrap(Point position, int yPush, int requiredHeight, int bestType)
537 {
538 for (int i = position.X; i < position.X + 2; i++)
539 {
540 for (int j = position.Y - requiredHeight; j <= position.Y + 2; j++)
541 {
542 Tile tile = Main.tile[i, j];
543 if (j < position.Y - requiredHeight + 2)
544 {
545 tile.ClearTile();
546 }
547 else if (j <= position.Y)
548 {
549 if (!tile.active())
550 {
551 tile.active(active: true);
552 tile.type = (ushort)bestType;
553 }
554 tile.slope(0);
555 tile.halfBrick(halfBrick: false);
556 tile.actuator(actuator: true);
557 tile.wire(wire: true);
558 WorldGen.TileFrame(i, j, resetFrame: true);
559 }
560 else
561 {
562 tile.ClearTile();
563 }
564 }
565 }
566 int num = position.X + 1;
567 int num2 = position.Y - requiredHeight + 1;
568 int num3 = 3;
569 int num4 = num - num3;
570 int num5 = num2 - num3;
571 int num6 = num + num3 - 1;
572 int num7 = num2 + num3 - 1;
573 for (int k = num4; k <= num6; k++)
574 {
575 for (int l = num5; l <= num7; l++)
576 {
577 if (Main.tile[k, l].type != 138)
578 {
579 Main.tile[k, l].type = 1;
580 }
581 }
582 }
583 WorldGen.PlaceTile(num, num2, 138);
584 PlaceWireLine(position, 0, 1, yPush);
585 }
586
587 private void ActuallyPlaceExplosive(Point position)
588 {
589 Tile tile = Main.tile[position.X, position.Y];
590 tile.type = 141;
591 tile.frameX = (tile.frameY = 0);
592 tile.slope(0);
593 tile.halfBrick(halfBrick: false);
594 WorldGen.TileFrame(position.X, position.Y, resetFrame: true);
595 }
596}
void Add(TKey key, TValue value)
static int FindChest(int X, int Y)
Definition Chest.cs:546
BoulderPlacementAttempt(Point position, int yPush, int requiredHeight, int bestType)
DartTrapPlacementAttempt(Point position, int directionX, int x, int y, int xPush, Tile t)
WirePlacementAttempt(Point position, int dirX, int dirY, int steps)
void PlaceWireLine(Point start, int offsetX, int offsetY, int steps)
List< BoulderPlacementAttempt > _boulderPlacementSpots
void ActuallyPlaceDartTrap(Point position, int directionX, int x, int y, int xPush, Tile t)
override bool Place(Point origin, StructureMap structures)
void PlaceBoulderTrapSpot(Point position, int yPush)
List< ExplosivePlacementAttempt > _explosivePlacementAttempt
bool FindDartTrapSpotSingle(Point position, int directionX)
void ActuallyPlaceBoulderTrap(Point position, int yPush, int requiredHeight, int bestType)
List< DartTrapPlacementAttempt > _dartTrapPlacementSpots
List< int > GetPossibleChestsToTrapify(StructureMap structures)
static bool[] GeneralPlacementTiles
Definition TileID.cs:221
static bool[] IsAContainer
Definition TileID.cs:297
static bool[] CanBeClearedDuringGeneration
Definition TileID.cs:229
static readonly ushort Count
Definition TileID.cs:1698
static bool[] tileSolidTop
Definition Main.cs:1469
static Chest[] chest
Definition Main.cs:1699
static bool[] tileSolid
Definition Main.cs:1471
static Tile[,] tile
Definition Main.cs:1675
static bool[] tileFrameImportant
Definition Main.cs:1495
ushort type
Definition Tile.cs:8
short frameX
Definition Tile.cs:22
bool active()
Definition Tile.cs:565
byte slope()
Definition Tile.cs:684
void ClearTile()
Definition Tile.cs:151
bool actuator()
Definition Tile.cs:667
bool wire()
Definition Tile.cs:599
bool halfBrick()
Definition Tile.cs:650
static UnifiedRandom _random
Definition GenBase.cs:9
bool CanPlace(Rectangle area, int padding=0)
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static int countWires(int x, int y, int size)
Definition WorldGen.cs:5648
static bool oceanDepths(int x, int y)
Definition WorldGen.cs:7142
static void TileFrame(int i, int j, bool resetFrame=false, bool noBreak=false)
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static int countTiles(int x, int y, bool jungle=false, bool lavaOk=false)
Definition WorldGen.cs:5679