-
Notifications
You must be signed in to change notification settings - Fork 62
/
FargoGlobalTile.cs
282 lines (254 loc) · 11.1 KB
/
FargoGlobalTile.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace FargowiltasSouls
{
public class FargoGlobalTile : GlobalTile
{
internal static Point16 PlayerCenterTile(Player player) => new Point16((int)(player.Center.X / 16), (int)(player.Center.Y / 16));
internal static int PlayerCenterTileX(Player player) => (int)(player.Center.X / 16);
internal static int PlayerCenterTileY(Player player) => (int)(player.Center.Y / 16);
internal static bool InGameWorldLeft(int x) => x > 39;
internal static bool InGameWorldRight(int x) => x < Main.maxTilesX - 39;
internal static bool InGameWorldTop(int y) => y > 39;
internal static bool InGameWorldBottom(int y) => y < Main.maxTilesY - 39;
internal static bool InGameWorld(int x, int y) => x > 39 && x < Main.maxTilesX - 39 && y > 39 && y < Main.maxTilesY - 39;
internal static bool InWorldLeft(int x) => x >= 0;
internal static bool InWorldRight(int x) => x < Main.maxTilesX;
internal static bool InWorldTop(int y) => y >= 0;
internal static bool InWorldBottom(int y) => y < Main.maxTilesY;
internal static bool InWorld(int x, int y) => x >= 0 && x < Main.maxTilesX && y >= 0 && y < Main.maxTilesY;
internal static bool PlaceGrassTileCheck(int x, int y) => (y > 0 && !WorldGen.SolidTile(x, y - 1))
|| (x > 0 && !WorldGen.SolidTile(x - 1, y))
|| (x < Main.maxTilesX - 1 && !WorldGen.SolidTile(x + 1, y));
internal static void DestroyChest(int x, int y) => DestroyChest(Chest.FindChest(x, y), x, y);
internal static void DestroyChest(int chest, int x, int y)
{
int chestType = 1;
if (chest != -1)
{
for (int i = 0; i < 40; i++)
Main.chest[chest].item[i] = new Item();
Main.chest[chest] = null;
if (Main.tile[x, y].type == TileID.Containers2)
chestType = 5;
if (Main.tile[x, y].type >= TileID.Count)
chestType = 101;
}
for (int i = x; i < x + 2; i++)
for (int j = y; j < y + 2; j++)
ClearTile(i, j);
if (Main.netMode != 0)
{
if (chest != -1)
NetMessage.SendData(34, -1, -1, null, chestType, x, y, 0f, chest, Main.tile[x, y].type, 0);
NetMessage.SendTileSquare(-1, x, y, 3);
}
}
internal static int FindChestSafe(int x, int y)
{
if (Main.tile[x, y] != null)
{
Point16 pos = FindChestTopLeft(x, y, false);
return Chest.FindChest(pos.X, pos.Y);
}
return Chest.FindChestByGuessing(x, y);
}
internal static Point16 FindChestTopLeft(int x, int y, bool destroy)
{
if (TileID.Sets.BasicChest[Main.tile[x, y].type])
{
if (Main.tile[x, y]?.frameX % 36 != 0)
x--;
if (Main.tile[x, y]?.frameY % 36 != 0)
y--;
if (!destroy)
return new Point16(x, y);
DestroyChest(x, y);
return new Point16(x, y);
}
return Point16.NegativeOne;
}
internal static void ClearLiquid(int x, int y) => ClearLiquid(Main.tile[x, y], x, y);
internal static void ClearLiquid(Tile tile, int x, int y)
{
tile.liquid = 0;
tile.lava(false);
tile.honey(false);
if (Main.netMode == 2)
NetMessage.sendWater(x, y);
}
internal static void ClearTile(int x, int y) => ClearTile(Main.tile[x, y]);
internal static void ClearTile(Tile tile)
{
tile.type = 0;
tile.sTileHeader = 0;
tile.frameX = 0;
tile.frameY = 0;
}
internal static void ClearWall(int x, int y) => ClearWall(Main.tile[x, y]);
internal static void ClearWall(Tile tile)
{
tile.wall = 0;
tile.bTileHeader = 0;
tile.bTileHeader2 = 0;
tile.bTileHeader3 = 0;
}
internal static void ClearEverything(int x, int y)
{
//FindChestTopLeft(x, y, true);
Tile tile = Main.tile[x, y];
if (tile != null)
{
ClearTile(tile);
ClearWall(tile);
ClearLiquid(tile, x, y);
}
}
internal static void ClearTileWithNet(int x, int y)
{
ClearTile(x, y);
SquareUpdate(x, y);
}
internal static void ClearWallWithNet(int x, int y)
{
ClearWall(x, y);
SquareUpdate(x, y);
}
internal static void ClearEverythingWithNet(int x, int y)
{
ClearEverything(x, y);
SquareUpdate(x, y);
}
internal static void SquareUpdate(int x, int y)
{
if (Main.netMode != 0)
NetMessage.SendTileSquare(-1, x, y, 1);
}
internal static bool NoDungeon(int x, int y) => NoBlueDungeon(x, y) && NoGreenDungeon(x, y) && NoPinkDungeon(x, y);
internal static bool NoBlueDungeon(int x, int y)
{
Tile tile = Main.tile[x, y];
return tile.type != TileID.BlueDungeonBrick && tile.wall != WallID.BlueDungeonSlabUnsafe
&& tile.wall != WallID.BlueDungeonTileUnsafe && tile.wall != WallID.BlueDungeonUnsafe;
}
internal static bool NoGreenDungeon(int x, int y)
{
Tile tile = Main.tile[x, y];
return tile.type != TileID.GreenDungeonBrick && tile.wall != WallID.GreenDungeonSlabUnsafe
&& tile.wall != WallID.GreenDungeonTileUnsafe && tile.wall != WallID.GreenDungeonUnsafe;
}
internal static bool NoPinkDungeon(int x, int y)
{
Tile tile = Main.tile[x, y];
return tile.type != TileID.PinkDungeonBrick && tile.wall != WallID.PinkDungeonSlabUnsafe
&& tile.wall != WallID.PinkDungeonTileUnsafe && tile.wall != WallID.PinkDungeonUnsafe;
}
internal static bool NoUndergroundDesert(int x, int y)
{
int wall = Main.tile[x, y].wall;
return wall != WallID.Sandstone && wall != WallID.CorruptSandstone && wall != WallID.CrimsonSandstone && wall != WallID.HallowSandstone;
}
internal static bool PlanteraBulb(int x, int y) => Main.tile[x, y].type == TileID.PlanteraBulb;
internal static bool NoTemple(int x, int y)
{
Tile tile = Main.tile[x, y];
return tile.wall != WallID.LihzahrdBrickUnsafe && tile.type != TileID.LihzahrdBrick
&& !(tile.type == TileID.ClosedDoor && tile.frameY >= 594 && tile.frameY <= 646);
}
internal static bool Temple(int x, int y) => !NoTemple(x, y);
internal static bool TempleAndGolemIsDead(int x, int y) => !NoTemple(x, y) && NPC.downedGolemBoss;
internal static bool NoTempleOrGolemIsDead(int x, int y) => NoTemple(x, y) || NPC.downedGolemBoss;
internal static bool NoOrbOrAltar(int x, int y) => Main.tile[x, y].type != TileID.ShadowOrbs && Main.tile[x, y].type != TileID.DemonAltar;
internal static int CoordsX(int x) => x * 2 - Main.maxTilesX;
internal static int CoordsY(int y) => y * 2 - (int)Main.worldSurface * 2;
internal static string CoordsString(int x, int y)
{
x = x * 2 - Main.maxTilesX;
y = y * 2 - (int)Main.worldSurface * 2;
string xCoord = x < 0 ? " west, " : " east, ";
string yCoord = y < 0 ? " surface." : " underground.";
x = x < 0 ? x * -1 : x;
y = y < 0 ? y * -1 : y;
return x + xCoord + y + yCoord;
}
internal static void MakeTileSafe(int x, int y)
{
if (Main.tile[x, y] == null)
Main.tile[x, y] = new Tile();
}
internal static void MakeTileSafe(ref Tile tile)
{
if (tile == null)
tile = new Tile();
}
internal static bool TileIsNull(int x, int y) => Main.tile[x, y] == null;
internal static bool SolidTile(int x, int y)
{
Tile tile = Main.tile[x, y];
return !TileIsNull(x, y) && tile.active() && Main.tileSolid[tile.type] && !Main.tileSolidTop[tile.type] && !tile.halfBrick()
&& tile.slope() == 0 && !tile.inActive();
}
public override int[] AdjTiles(int type)
{
if (type == mod.TileType("CrucibleCosmosSheet"))
{
Main.LocalPlayer.adjHoney = true;
Main.LocalPlayer.adjLava = true;
}
return base.AdjTiles(type);
}
public override bool CanExplode(int i, int j, int type)
{
if (type == TileID.Meteorite && FargoSoulsWorld.MasochistMode && !NPC.downedBoss3)
return false;
return true;
}
public override void KillTile(int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem)
{
switch(type)
{
case TileID.ShadowOrbs:
if (FargoSoulsWorld.MasochistMode && Main.invasionType == 0 && !NPC.downedGoblins)
{
int p = Player.FindClosest(new Vector2(i * 16, j * 16), 0, 0);
if (p != -1 && Main.player[p].statLifeMax2 >= 200)
{
if (Main.netMode != 1)
{
Main.invasionDelay = 0;
Main.StartInvasion(1);
}
else
{
NetMessage.SendData(61, -1, -1, null, p, -1f);
}
}
}
break;
case TileID.DemonAltar:
if (FargoSoulsWorld.MasochistMode && Main.invasionType == 0 && !NPC.downedPirates)
{
int p = Player.FindClosest(new Vector2(i * 16, j * 16), 0, 0);
if (p != -1 && Main.player[p].statLifeMax2 >= 200)
{
if (Main.netMode != 1)
{
Main.invasionDelay = 0;
Main.StartInvasion(3);
}
else
{
NetMessage.SendData(61, -1, -1, null, p, -1f);
}
}
}
break;
default:
break;
}
}
}
}