forked from UriBuilder/AQMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAQTile.cs
202 lines (188 loc) · 6.89 KB
/
AQTile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using AQMod.Common;
using AQMod.Tiles;
using AQMod.Tiles.CrabCrevice;
using AQMod.Tiles.ExporterQuest;
using AQMod.Tiles.Herbs;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace AQMod
{
public class AQTile : GlobalTile
{
internal const byte Slope_BottomLeft = 1;
internal const byte Slope_BottomRight = 2;
internal const byte Slope_TopLeft = 3;
internal const byte Slope_TopRight = 4;
public sealed class Sets
{
public static Sets Instance;
public HashSet<ushort> CanFixWaterOnType { get; private set; }
public HashSet<ushort> ExporterQuestFurniture { get; private set; }
public Sets()
{
CanFixWaterOnType = new HashSet<ushort>()
{
TileID.Grass,
TileID.CorruptGrass,
TileID.FleshGrass,
TileID.SnowBlock,
TileID.IceBlock,
TileID.Sand,
};
ExporterQuestFurniture = new HashSet<ushort>()
{
(ushort)ModContent.TileType<JeweledChandlierTile>(),
(ushort)ModContent.TileType<JeweledCandelabraTile>(),
(ushort)ModContent.TileType<JeweledChaliceTile>(),
};
}
}
private bool TryPlaceHerb(int i, int j, int[] validTile, int tile)
{
for (int y = j - 1; y > 20; y--)
{
if (Main.tile[i, j] == null)
{
Main.tile[i, j] = new Tile();
continue;
}
if (!Main.tile[i, y].active() && Main.tile[i, y + 1].active())
{
for (int k = 0; k < validTile.Length; k++)
{
if (Main.tile[i, y + 1].type == validTile[k] && CheckForType(new Rectangle(i - 6, y - 6, 12, 12).KeepInWorld(20), tile))
{
WorldGen.PlaceTile(i, y, tile, mute: true, forced: true);
return Framing.GetTileSafely(i, y).type == tile;
}
}
}
}
return false;
}
public override void RandomUpdate(int i, int j, int type)
{
if (Main.tile[i, j] == null)
Main.tile[i, j] = new Tile();
if (!WorldDefeats.DownedDemonSiege && WorldGen.genRand.NextBool(10000) && GoreNest.TryGrowGoreNest(i, j, true, true))
{
return;
}
switch (type)
{
case TileID.Cloud:
case TileID.RainCloud:
case TileID.SnowCloud:
if (WorldDefeats.DownedGaleStreams && j < Main.rockLayer && WorldGen.genRand.NextBool(10))
{
//TryPlaceHerb(i, j, new int[] { TileID.Cloud, TileID.RainCloud, TileID.SnowCloud, }, ModContent.TileType<Crepe>());
}
break;
case TileID.Meteorite:
if (WorldDefeats.DownedStarite && j < Main.rockLayer && WorldGen.genRand.NextBool(25))
{
TryPlaceHerb(i, j, new int[] { TileID.Meteorite, }, ModContent.TileType<Moonflower>());
}
break;
case TileID.Stone:
if (j > Main.rockLayer && WorldGen.genRand.NextBool(300))
{
if (NobleMushroomsNew.Place(i, j))
return;
}
break;
}
if (WorldGen.genRand.NextBool(3000) && j > 200 && !Main.tile[i, j].active() && Framing.GetTileSafely(i, j + 1).active()
&& Main.tileSolid[Main.tile[i, j + 1].type] && Main.tile[i, j].liquid > 0 && !Main.tile[i, j].lava() && !Main.tile[i, j].honey())
{
Main.tile[i, j].active(active: true);
Main.tile[i, j].halfBrick(halfBrick: false);
Main.tile[i, j].slope(slope: 0);
Main.tile[i, j].type = (ushort)ModContent.TileType<ExoticCoralNew>();
Main.tile[i, j].frameX = (short)(22 * ExoticCoralNew.GetRandomStyle(WorldGen.genRand.Next(3)));
Main.tile[i, j].frameY = 0;
return;
}
}
public static bool ProtectedTile(int i, int j)
{
var tile = Main.tile[i, j];
if (tile.type > Main.maxTileSets && Main.tileFrameImportant[tile.type])
{
bool blockDamaged = false;
if (TileLoader.GetTile(tile.type).mod.Name == "AQMod")
{
if (!TileLoader.CanKillTile(i, j, tile.type, ref blockDamaged))
return true;
}
}
return false;
}
public override bool CanKillTile(int i, int j, int type, ref bool blockDamaged)
{
if (j > 1)
{
if (ProtectedTile(i, j - 1))
return false;
}
return true;
}
public override bool CanExplode(int i, int j, int type)
{
if (j > 1)
{
if (ProtectedTile(i, j - 1))
return false;
}
return true;
}
public override bool Slope(int i, int j, int type)
{
if (j > 1)
{
if (ProtectedTile(i, j - 1))
return false;
}
return true;
}
public static bool CheckForType(Rectangle rect, AQUtils.ArrayInterpreter<int> type)
{
return CheckTiles(rect, (i, j, tile) => type.Arr.Contains(tile.type));
}
public static bool CheckTiles(Rectangle rect, Func<int, int, Tile, bool> function)
{
for (int i = rect.X; i < rect.X + rect.Width; i++)
{
for (int j = rect.Y; j < rect.Y + rect.Height; j++)
{
if (Main.tile[i, j] == null)
{
Main.tile[i, j] = new Tile();
continue;
}
if (!function(i, j, Main.tile[i, j]))
{
return false;
}
}
}
return true;
}
public static class WindFXHelper
{
public static bool WindBlocked(int i, int j)
{
return WindBlocked(Main.tile[i, j]);
}
public static bool WindBlocked(Tile tile)
{
return tile.wall != 0;
}
}
}
}