-
Notifications
You must be signed in to change notification settings - Fork 2
/
PrismWorld.cs
274 lines (232 loc) · 11 KB
/
PrismWorld.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
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.GameContent.Generation;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using prismmod.NPCs.WaterTown;
using prismmod.Tiles.Blox;
using prismmod.Walls;
using static prismmod.PrismHelper;
using Terraria.ModLoader.IO;
using Microsoft.Xna.Framework;
namespace prismmod
{
internal class PrismWorld : ModWorld
{
public static int moistChiseledStoneCount = 0;
public bool downedGargantuanTortoise;
public bool downedPrismachine;
public bool accessedWaterTown;
public int gatesY;
public int gatesX;
public int bsb;
public override void Initialize()
{
downedGargantuanTortoise = false;
downedPrismachine = false;
accessedWaterTown = false;
}
public override void Load(TagCompound tag)
{
var downed = tag.GetList<string>("downed");
downedPrismachine = downed.Contains("Prismachine");
downedGargantuanTortoise = downed.Contains("GargantuanTortoise");
var accessed = tag.GetList<string>("accessed");
accessedWaterTown = accessed.Contains("WaterTown");
}
public override TagCompound Save()
{
var downed = new List<string>();
if (downedPrismachine)
downed.Add("Prismachine");
if (downedGargantuanTortoise)
{
downed.Add("GargantuanTortoise");
}
var accessed = new List<string>();
if (accessedWaterTown)
accessed.Add("WaterTown");
return new TagCompound
{
["downed"] = downed,
["accessed"] = accessed
};
}
public override void NetSend(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = downedGargantuanTortoise;
flags[1] = downedPrismachine;
writer.Write(flags);
}
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
downedGargantuanTortoise = flags[0];
downedPrismachine = flags[1];
}
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
/*int genIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
if (genIndex != -1)
{
tasks.Insert(genIndex + 1, new PassLegacy("Reserved Prismmod Test Space", delegate (GenerationProgress progress)
{
progress.Message = "Test Code Here ;)";
}));
}*/
int genIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Pots"));
if (genIndex != -1)
{
tasks.Insert(genIndex + 1, new PassLegacy("Generate Water Town", delegate (GenerationProgress progress)
{
int operation = 1;
bool wtRight;
int startXTunnel;
if (WorldGen.dungeonX < Main.maxTilesX / 2)
{
wtRight = true;
operation = -1;
startXTunnel = Main.maxTilesX - 75;
}
else
{
wtRight = false;
operation = 1;
startXTunnel = 69;
}
progress.Message = "Finding some Sand";
int baseSandBlock = 0;
for (int y = 0; y < Main.maxTilesY; y++)
{
Tile tile = Framing.GetTileSafely(startXTunnel, y);
if (tile.active() && tile.liquid == 0)
{
baseSandBlock = y;
break;
}
}
bsb = baseSandBlock;
int gateBlock = ModContent.TileType<UnbreakableGate>();
bool placedGate = false;//used to check if gateX and gateY should be set
int gateY = 0;
int gateX;
int activeBlock = ModContent.TileType<CityWall>();
/*
Step 1- Create Initial Tunnel
Step 2- Create gate
Step 3- Create Main Biome body
Notes:
- operation stores left or right (+1 on left, -1 on right), controls direction easily
*/
int tunnelDepth = 35;
int tunnelWidth = 9;
int biomeDepth = 95;
int biomeWidth = 200;
int endXTunnel = startXTunnel + (operation * tunnelWidth);
int endXBiome = startXTunnel + (operation * biomeWidth);
progress.Message = "Tunneling";
for (int y = bsb; y <= (bsb + tunnelDepth); y++)//start at base sand block and go until desired tunnel depth has been reached
{
for (int x = (startXTunnel - operation); x != (endXTunnel + operation + operation); x += operation)
{
Tile tile = Framing.GetTileSafely(x, y);
tile.ClearTile();
tile.liquidType(0);
tile.liquid = 255;
WorldGen.PlaceWall(x, y, ModContent.WallType<Placeholder>());
tile.wall = (ushort)ModContent.WallType<Placeholder>();
}
}
progress.Message = "Digging Main Biome";
for (int y = bsb + tunnelDepth-1; y <= (bsb + tunnelDepth + biomeDepth+1); y++)//start at base sand block and go until desired tunnel depth has been reached
{
for (int x = (startXTunnel - operation); x != (startXTunnel + (biomeWidth * operation)+operation+operation); x += operation)
{
Tile tile = Framing.GetTileSafely(x, y);
tile.ClearTile();
tile.liquidType(0);
tile.liquid = 255;
WorldGen.PlaceWall(x, y, ModContent.WallType<Placeholder>());
tile.wall = (ushort)ModContent.WallType<Placeholder>();
}
}
progress.Message = "Building Initial Tunnel Walls";
for (int y = bsb; y <= (bsb + tunnelDepth); y++)
{
for (int x = (startXTunnel - operation); x != (endXTunnel + operation + operation); x += operation)
{
if (x == startXTunnel || x == endXTunnel)
{
WorldGen.PlaceTile(x, y, activeBlock);
WorldGen.PlaceTile(x - 1, y, activeBlock);
WorldGen.PlaceTile(x + 1, y, activeBlock);
}
}
}
progress.Message = "Placing Main Biome Walls";
for (int y = bsb + tunnelDepth; y <= (bsb + tunnelDepth + biomeDepth+1); y++)
{
for (int x = (startXTunnel - operation - operation); x != (startXTunnel + (biomeWidth * operation)+operation+operation); x += operation)
{
if (y==bsb+tunnelDepth && (x*operation>endXTunnel*operation))//top layer
{
WorldGen.PlaceTile(x, y, activeBlock);
WorldGen.PlaceTile(x, y+1, activeBlock);
WorldGen.PlaceTile(x, y-1, activeBlock);
}
if (x == startXTunnel || x == (endXBiome))//sides
{
WorldGen.PlaceTile(x, y, activeBlock);
WorldGen.PlaceTile(x-1, y, activeBlock);
WorldGen.PlaceTile(x+1, y, activeBlock);
}
if (y==bsb + tunnelDepth + biomeDepth)
{
WorldGen.PlaceTile(x, y, activeBlock);
WorldGen.PlaceTile(x, y + 1, activeBlock);
WorldGen.PlaceTile(x, y - 1, activeBlock);
}
}
}
progress.Message = "Placing Gate";
for (int x = startXTunnel; x != endXTunnel; x += operation)
{
WorldGen.PlaceTile(x, bsb, ModContent.TileType<UnbreakableGate>());
}
List <Point> spawnPoints = new List<Point>();
int leftX=0;
int rightX=0;
if (wtRight)
{
leftX = endXBiome;
rightX = startXTunnel;
}
if (!wtRight)
{
leftX = startXTunnel;
rightX = endXBiome;
}
int topY = bsb + tunnelDepth;
int botY = bsb + tunnelDepth + biomeDepth;
//house drawing
spawnPoints.Add(PrismHelper.drawBaseFishHouse(leftX+3, topY+30, 8, 15, ModContent.TileType<MoistChiseledStone>(), 'l'));
PrismHelper.drawGroundFromWall(leftX + 2, topY + 30, 5, 25, TileID.Stone, 'l');
spawnPoints.Add(PrismHelper.drawBaseFishHouse(startXTunnel + (startXTunnel - endXBiome) + 10, topY + 50, 8, 15, ModContent.TileType<MoistChiseledStone>(), 'r'));
PrismHelper.drawIsland(startXTunnel + (startXTunnel - endXBiome) / 2, topY + 50, 5, 25, TileID.Stone);
progress.Message = "Importing Fish People";
Point[] spawnPointsArray = spawnPoints.ToArray();
NPC.NewNPC(spawnPointsArray[0].X*16,spawnPointsArray[0].Y*16, ModContent.NPCType<FishBlue>());
NPC.NewNPC(spawnPointsArray[1].X * 16, spawnPointsArray[1].Y * 16, ModContent.NPCType<FishRainbow>());
progress.Message = "Populating Passives";
}));
}
}
public override void TileCountsAvailable(int[] tileCounts)
{
moistChiseledStoneCount = tileCounts[ModContent.TileType<Tiles.Blox.CityWall>()]; //Change back to chiseled stone
}
}
}