Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Actions.cs
Go to the documentation of this file.
1using System;
7
9
10public static class Actions
11{
13 {
15
20
21 public override bool Apply(Point origin, int x, int y, params object[] args)
22 {
23 _action.Apply(origin, x, y, args);
24 return UnitApply(origin, x, y, args);
25 }
26 }
27
28 public class Count : GenAction
29 {
31
33 {
34 _count = count;
35 }
36
37 public override bool Apply(Point origin, int x, int y, params object[] args)
38 {
39 _count.Value++;
40 return UnitApply(origin, x, y, args);
41 }
42 }
43
44 public class Scanner : GenAction
45 {
47
49 {
50 _count = count;
51 }
52
53 public override bool Apply(Point origin, int x, int y, params object[] args)
54 {
55 _count.Value++;
56 return UnitApply(origin, x, y, args);
57 }
58 }
59
60 public class TileScanner : GenAction
61 {
62 private ushort[] _tileIds;
63
65
66 public TileScanner(params ushort[] tiles)
67 {
70 for (int i = 0; i < tiles.Length; i++)
71 {
72 _tileCounts[_tileIds[i]] = 0;
73 }
74 }
75
76 public override bool Apply(Point origin, int x, int y, params object[] args)
77 {
78 Tile tile = GenBase._tiles[x, y];
79 if (tile.active() && _tileCounts.ContainsKey(tile.type))
80 {
81 _tileCounts[tile.type]++;
82 }
83 return UnitApply(origin, x, y, args);
84 }
85
87 {
89 for (int i = 0; i < _tileIds.Length; i++)
90 {
92 {
93 _tileCounts[_tileIds[i]] = 0;
94 }
95 }
96 return this;
97 }
98
100 {
101 return _tileCounts;
102 }
103
104 public int GetCount(ushort tileId)
105 {
107 {
108 return -1;
109 }
110 return _tileCounts[tileId];
111 }
112 }
113
114 public class Blank : GenAction
115 {
116 public override bool Apply(Point origin, int x, int y, params object[] args)
117 {
118 return UnitApply(origin, x, y, args);
119 }
120 }
121
122 public class Custom : GenAction
123 {
124 private CustomPerUnitAction _perUnit;
125
126 public Custom(CustomPerUnitAction perUnit)
127 {
129 }
130
131 public override bool Apply(Point origin, int x, int y, params object[] args)
132 {
133 return _perUnit(x, y, args) | UnitApply(origin, x, y, args);
134 }
135 }
136
138 {
139 public override bool Apply(Point origin, int x, int y, params object[] args)
140 {
141 GenBase._tiles[x, y].ClearMetadata();
142 return UnitApply(origin, x, y, args);
143 }
144 }
145
146 public class Clear : GenAction
147 {
148 public override bool Apply(Point origin, int x, int y, params object[] args)
149 {
150 GenBase._tiles[x, y].ClearEverything();
151 return UnitApply(origin, x, y, args);
152 }
153 }
154
155 public class ClearTile : GenAction
156 {
157 private bool _frameNeighbors;
158
159 public ClearTile(bool frameNeighbors = false)
160 {
162 }
163
164 public override bool Apply(Point origin, int x, int y, params object[] args)
165 {
167 return UnitApply(origin, x, y, args);
168 }
169 }
170
171 public class ClearWall : GenAction
172 {
173 private bool _frameNeighbors;
174
175 public ClearWall(bool frameNeighbors = false)
176 {
178 }
179
180 public override bool Apply(Point origin, int x, int y, params object[] args)
181 {
183 return UnitApply(origin, x, y, args);
184 }
185 }
186
187 public class HalfBlock : GenAction
188 {
189 private bool _value;
190
191 public HalfBlock(bool value = true)
192 {
193 _value = value;
194 }
195
196 public override bool Apply(Point origin, int x, int y, params object[] args)
197 {
198 GenBase._tiles[x, y].halfBrick(_value);
199 return UnitApply(origin, x, y, args);
200 }
201 }
202
203 public class SetTile : GenAction
204 {
205 private ushort _type;
206
207 private bool _doFraming;
208
209 private bool _doNeighborFraming;
210
211 public SetTile(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
212 {
213 _type = type;
216 }
217
218 public override bool Apply(Point origin, int x, int y, params object[] args)
219 {
220 GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
221 GenBase._tiles[x, y].type = _type;
222 GenBase._tiles[x, y].active(active: true);
223 if (_doFraming)
224 {
226 }
227 return UnitApply(origin, x, y, args);
228 }
229 }
230
232 {
233 private ushort _type;
234
235 private bool _doFraming;
236
237 private bool _doNeighborFraming;
238
239 public SetTileKeepWall(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
240 {
241 _type = type;
244 }
245
246 public override bool Apply(Point origin, int x, int y, params object[] args)
247 {
248 ushort wall = GenBase._tiles[x, y].wall;
249 int wallFrameX = GenBase._tiles[x, y].wallFrameX();
250 int wallFrameY = GenBase._tiles[x, y].wallFrameY();
251 GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
252 GenBase._tiles[x, y].type = _type;
253 GenBase._tiles[x, y].active(active: true);
254 if (wall > 0)
255 {
256 GenBase._tiles[x, y].wall = wall;
257 GenBase._tiles[x, y].wallFrameX(wallFrameX);
258 GenBase._tiles[x, y].wallFrameY(wallFrameY);
259 }
260 if (_doFraming)
261 {
263 }
264 return UnitApply(origin, x, y, args);
265 }
266 }
267
268 public class DebugDraw : GenAction
269 {
270 private Color _color;
271
273
274 public DebugDraw(SpriteBatch spriteBatch, Color color = default(Color))
275 {
276 _spriteBatch = spriteBatch;
277 _color = color;
278 }
279
280 public override bool Apply(Point origin, int x, int y, params object[] args)
281 {
282 _spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((x << 4) - (int)Main.screenPosition.X, (y << 4) - (int)Main.screenPosition.Y, 16, 16), _color);
283 return UnitApply(origin, x, y, args);
284 }
285 }
286
287 public class SetSlope : GenAction
288 {
289 private int _slope;
290
291 public SetSlope(int slope)
292 {
293 _slope = slope;
294 }
295
296 public override bool Apply(Point origin, int x, int y, params object[] args)
297 {
299 return UnitApply(origin, x, y, args);
300 }
301 }
302
303 public class SetHalfTile : GenAction
304 {
305 private bool _halfTile;
306
308 {
310 }
311
312 public override bool Apply(Point origin, int x, int y, params object[] args)
313 {
314 GenBase._tiles[x, y].halfBrick(_halfTile);
315 return UnitApply(origin, x, y, args);
316 }
317 }
318
320 {
321 public override bool Apply(Point origin, int x, int y, params object[] args)
322 {
324 GenBase._tiles[x, y].color(paintIDForPosition);
325 GenBase._tiles[x, y].wallColor(paintIDForPosition);
326 return UnitApply(origin, x, y, args);
327 }
328
329 private byte GetPaintIDForPosition(int x, int y)
330 {
331 int num = x % 52 + y % 52;
332 num %= 26;
333 if (num > 12)
334 {
335 num = 12 - (num - 12);
336 }
337 num = Math.Min(12, Math.Max(1, num));
338 return (byte)(12 + num);
339 }
340 }
341
342 public class PlaceTile : GenAction
343 {
344 private ushort _type;
345
346 private int _style;
347
348 public PlaceTile(ushort type, int style = 0)
349 {
350 _type = type;
351 _style = style;
352 }
353
354 public override bool Apply(Point origin, int x, int y, params object[] args)
355 {
356 WorldGen.PlaceTile(x, y, _type, mute: true, forced: false, -1, _style);
357 return UnitApply(origin, x, y, args);
358 }
359 }
360
361 public class RemoveWall : GenAction
362 {
363 public override bool Apply(Point origin, int x, int y, params object[] args)
364 {
365 GenBase._tiles[x, y].wall = 0;
366 return UnitApply(origin, x, y, args);
367 }
368 }
369
370 public class PlaceWall : GenAction
371 {
372 private ushort _type;
373
374 private bool _neighbors;
375
376 public PlaceWall(ushort type, bool neighbors = true)
377 {
378 _type = type;
380 }
381
382 public override bool Apply(Point origin, int x, int y, params object[] args)
383 {
384 GenBase._tiles[x, y].wall = _type;
386 if (_neighbors)
387 {
388 WorldGen.SquareWallFrame(x + 1, y);
389 WorldGen.SquareWallFrame(x - 1, y);
390 WorldGen.SquareWallFrame(x, y - 1);
391 WorldGen.SquareWallFrame(x, y + 1);
392 }
393 return UnitApply(origin, x, y, args);
394 }
395 }
396
397 public class SetLiquid : GenAction
398 {
399 private int _type;
400
401 private byte _value;
402
403 public SetLiquid(int type = 0, byte value = byte.MaxValue)
404 {
405 _value = value;
406 _type = type;
407 }
408
409 public override bool Apply(Point origin, int x, int y, params object[] args)
410 {
411 GenBase._tiles[x, y].liquidType(_type);
412 GenBase._tiles[x, y].liquid = _value;
413 return UnitApply(origin, x, y, args);
414 }
415 }
416
418 {
419 private ushort _type;
420
421 public SwapSolidTile(ushort type)
422 {
423 _type = type;
424 }
425
426 public override bool Apply(Point origin, int x, int y, params object[] args)
427 {
428 Tile tile = GenBase._tiles[x, y];
429 if (WorldGen.SolidTile(tile))
430 {
431 tile.ResetToType(_type);
432 return UnitApply(origin, x, y, args);
433 }
434 return Fail();
435 }
436 }
437
438 public class SetFrames : GenAction
439 {
440 private bool _frameNeighbors;
441
442 public SetFrames(bool frameNeighbors = false)
443 {
445 }
446
447 public override bool Apply(Point origin, int x, int y, params object[] args)
448 {
450 return UnitApply(origin, x, y, args);
451 }
452 }
453
454 public class Smooth : GenAction
455 {
456 private bool _applyToNeighbors;
457
458 public Smooth(bool applyToNeighbors = false)
459 {
461 }
462
463 public override bool Apply(Point origin, int x, int y, params object[] args)
464 {
466 return UnitApply(origin, x, y, args);
467 }
468 }
469
471 {
472 for (int i = 0; i < actions.Length - 1; i++)
473 {
474 actions[i].NextAction = actions[i + 1];
475 }
476 return actions[0];
477 }
478
480 {
481 return new ContinueWrapper(action);
482 }
483}
void Draw(Texture2D texture, Vector2 position, Color color)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static Asset< Texture2D > MagicPixel
static Vector2 screenPosition
Definition Main.cs:1715
T Value
Definition Ref.cs:5
static void SmoothSlope(int x, int y, bool applyToNeighbors=true, bool sync=false)
Definition Tile.cs:759
void ResetToType(ushort type)
Definition Tile.cs:266
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:116
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:139
ClearTile(bool frameNeighbors=false)
Definition Actions.cs:159
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:164
ClearWall(bool frameNeighbors=false)
Definition Actions.cs:175
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:180
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:148
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:21
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:37
Custom(CustomPerUnitAction perUnit)
Definition Actions.cs:126
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:131
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:280
DebugDraw(SpriteBatch spriteBatch, Color color=default(Color))
Definition Actions.cs:274
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:196
PlaceTile(ushort type, int style=0)
Definition Actions.cs:348
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:354
PlaceWall(ushort type, bool neighbors=true)
Definition Actions.cs:376
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:382
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:363
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:53
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:447
SetFrames(bool frameNeighbors=false)
Definition Actions.cs:442
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:312
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:409
SetLiquid(int type=0, byte value=byte.MaxValue)
Definition Actions.cs:403
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:296
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:321
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:246
SetTileKeepWall(ushort type, bool setSelfFrames=false, bool setNeighborFrames=true)
Definition Actions.cs:239
SetTile(ushort type, bool setSelfFrames=false, bool setNeighborFrames=true)
Definition Actions.cs:211
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:218
Smooth(bool applyToNeighbors=false)
Definition Actions.cs:458
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:463
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:426
TileScanner Output(Dictionary< ushort, int > resultsOutput)
Definition Actions.cs:86
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:76
TileScanner(params ushort[] tiles)
Definition Actions.cs:66
Dictionary< ushort, int > _tileCounts
Definition Actions.cs:64
Dictionary< ushort, int > GetResults()
Definition Actions.cs:99
static GenAction Chain(params GenAction[] actions)
Definition Actions.cs:470
static GenAction Continue(GenAction action)
Definition Actions.cs:479
bool UnitApply(Point origin, int x, int y, params object[] args)
Definition GenAction.cs:15
bool Apply(Point origin, int x, int y, params object[] args)
static void TileFrame(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:61
static void ClearTile(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:37
static void ClearWall(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:49
static bool SolidTile(Tile testTile)
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static void SquareWallFrame(int i, int j, bool resetFrame=true)
static bool SlopeTile(int i, int j, int slope=0, bool noEffects=false)