-
Notifications
You must be signed in to change notification settings - Fork 10
/
LaugicalityWorld.cs
356 lines (326 loc) · 13.4 KB
/
LaugicalityWorld.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
using System;
using System.IO;
using System.Collections.Generic;
using Laugicality.Tiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;
using Terraria.ModLoader.IO;
namespace Laugicality
{
public partial class LaugicalityWorld : ModWorld
{
public static bool downedAnnihilator = false;
public static bool downedSlybertron = false;
public static bool downedSteamTrain = false;
public static bool downedDuneSharkron = false;
public static bool downedHypothema = false;
public static bool downedRagnar = false;
public static bool obsidiumHeart = false;
public static bool downedRocks = false;
public static bool downedEtheria = false;
public static bool downedTrueEtheria = false;
public static bool downedDioritus = false;
public static bool downedAndesia = false;
public static bool downedAnDio = false;
public static bool downedNecrodon = false;
public static int obsidiumTiles = 0;
public static int power = 0;
public static bool obEnf = false; //obsidiumEnfused
public static bool bysmal = false;
public static int obsidiumPosition = 0;
public static int ObsidiumHeartGrowth { get; set; } = 0;
public static int sizeMult = (int)(Math.Round(Main.maxTilesY / 1200f)); //Small = 1; Medium = 1.5; Large = 2;
public static int zawarudo = 0;
public static int dungeonSide = 1;
public override void Initialize()
{
sizeMult = (int)(Math.Floor(Main.maxTilesY / 1200f));
power = 0;
downedAnnihilator = false;
downedSlybertron = false;
downedSteamTrain = false;
downedDuneSharkron = false;
downedHypothema = false;
downedRagnar = false;
downedRocks = false;
downedEtheria = false;
downedTrueEtheria = false;
downedDioritus = false;
downedAndesia = false;
downedAnDio = false;
downedNecrodon = false;
zawarudo = 0;
obEnf = false;
obsidiumHeart = false;
bysmal = false;
obsidiumPosition = 0;
ObsidiumHeartGrowth = 0;
}
public override void PostUpdate()
{
zawarudo = Laugicality.zaWarudo;
if (downedEtheria)
{
Main.dayTime = false;
Main.time = 16200.0;
}
}
public override TagCompound Save()
{
List<string> downed = new List<string>();
bool obs = false;
int pwr = 0;
if (downedAnnihilator) downed.Add("annihilator");
if (downedSlybertron) downed.Add("slybertron");
if (downedSteamTrain) downed.Add("steamtrain");
if (downedDuneSharkron) downed.Add("dunesharkron");
if (downedHypothema) downed.Add("hypothema");
if (downedRagnar) downed.Add("ragnar");
if (downedRocks) downed.Add("rocks");
if (downedTrueEtheria) downed.Add("trueetheria");
if (downedDioritus) downed.Add("dioritus");
if (downedAndesia) downed.Add("andesia");
if (downedAnDio) downed.Add("andio");
if (downedNecrodon) downed.Add("necrodon");
if (obEnf) obs = true;
pwr = power;
return new TagCompound {
{"downed", downed},
{"etherial", downedEtheria},
{"obsidium", obs },
{"obsidiumHeart", obsidiumHeart },
{"bysmal", bysmal },
{"power", pwr }
};
}
public override void Load(TagCompound tag)
{
IList<string> downed = tag.GetList<string>("downed");
downedAnnihilator = downed.Contains("annihilator");
downedSlybertron = downed.Contains("slybertron");
downedSteamTrain = downed.Contains("steamtrain");
downedDuneSharkron = downed.Contains("dunesharkron");
downedHypothema = downed.Contains("hypothema");
downedRagnar = downed.Contains("ragnar");
downedRocks = downed.Contains("rocks");
downedTrueEtheria = downed.Contains("trueetheria");
downedDioritus = downed.Contains("dioritus");
downedAndesia = downed.Contains("andesia");
downedAnDio = downed.Contains("andio");
downedNecrodon = downed.Contains("necrodon");
obEnf = tag.GetBool("obsidium");
downedEtheria = tag.GetBool("etherial");
obsidiumHeart = tag.GetBool("obsidiumHeart");
bysmal = tag.GetBool("bysmal");
power = tag.GetInt("power");
DryTheObsidium();
}
public override void LoadLegacy(BinaryReader reader)
{
int loadVersion = reader.ReadInt32();
if (loadVersion == 0)
{
BitsByte flags = reader.ReadByte();
downedAnnihilator = flags[0];
downedSlybertron = flags[1];
downedSteamTrain = flags[2];
downedDuneSharkron = flags[3];
downedHypothema = flags[4];
downedRagnar = flags[5];
downedEtheria = flags[6];
downedTrueEtheria = flags[7];
BitsByte flags2 = reader.ReadByte();
downedRocks = flags2[0];
downedDioritus = flags2[1];
downedAndesia = flags2[2];
downedAnDio = flags2[3];
obEnf = flags2[4];
obsidiumHeart = flags2[5];
bysmal = flags2[6];
}
else
{
ErrorLogger.Log("Enigma: Unknown loadVersion: " + loadVersion);
}
}
public override void NetSend(BinaryWriter writer)
{
BitsByte flags = new BitsByte();
flags[0] = downedAnnihilator;
flags[1] = downedSlybertron;
flags[2] = downedSteamTrain;
flags[3] = downedDuneSharkron;
flags[4] = downedHypothema;
flags[5] = downedRagnar;
flags[6] = downedEtheria;
flags[7] = downedTrueEtheria;
BitsByte flags2 = new BitsByte();
flags2[0] = downedRocks;
flags2[1] = downedDioritus;
flags2[2] = downedAndesia;
flags2[3] = downedAnDio;
flags2[4] = obEnf;
flags2[5] = obsidiumHeart;
flags2[6] = bysmal;
writer.Write(flags);
writer.Write(flags2);
//int zTime = Laugicality.zaWarudo;
//writer.Write(zTime);
}
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
downedAnnihilator = flags[0];
downedSlybertron = flags[1];
downedSteamTrain = flags[2];
downedDuneSharkron = flags[3];
downedHypothema = flags[4];
downedRagnar = flags[5];
downedEtheria = flags[6];
downedTrueEtheria = flags[7];
BitsByte flags2 = reader.ReadByte();
downedRocks = flags2[0];
downedDioritus = flags2[1];
downedAndesia = flags2[2];
downedAnDio = flags2[3];
obEnf = flags2[4];
obsidiumHeart = flags2[5];
bysmal = flags2[6];
//int zTime = reader.ReadInt32();
//zaWarudo = (int)zTime;
}
public override void ResetNearbyTileEffects()
{
obsidiumTiles = 0;
}
public override void TileCountsAvailable(int[] tileCounts)
{
obsidiumTiles = tileCounts[56] + tileCounts[ModContent.TileType<Tiles.ObsidiumCore>()] + tileCounts[ModContent.TileType<Tiles.ObsidiumRock>()] + tileCounts[ModContent.TileType<Tiles.ObsidiumOreBlock>()] + tileCounts[ModContent.TileType<Lycoris>()] + tileCounts[ModContent.TileType<Tiles.Radiata>()];
}
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int genIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
int xO = Main.maxTilesX / 2;
int yO = (int)(Main.maxTilesY * .7f);
tasks.Insert(genIndex + 1, new PassLegacy("Generating Obsidian Cavern", delegate (GenerationProgress progress)
{
progress.Message = "Obsidification";
GenerateObsidium(xO, yO);
}));
int genIndex2 = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
tasks.Insert(genIndex2 + 2, new PassLegacy("Obsidium Features", delegate (GenerationProgress progress)
{
progress.Message = "Obsidium Core";
GenerateObsidiumStructures(xO, yO);
}));
}
private void PlaceTile(int x, int y, int tileType)
{
WorldGen.KillTile(x, y);
WorldGen.KillWall(x, y);
Main.tile[x, y].liquid = 0;
WorldGen.PlaceTile(x, y, tileType, true, true);
}
private void PlaceTile(int x, int y, int tileType, int wallType)
{
WorldGen.KillTile(x, y);
WorldGen.KillWall(x, y);
Main.tile[x, y].liquid = 0;
WorldGen.PlaceTile(x, y, tileType, true, true);
WorldGen.PlaceWall(x, y, wallType, true);
}
private static bool TileCheckSafe(int i, int j)
{
if (i > 0 && i < Main.tile.GetLength(0) - 1 && j > 0 && j < Main.tile.GetLength(1) - 1)
{
if (Main.tile[i, j] == null)
return false;
if (TileID.Sets.BasicChest[Main.tile[i, j].type])
return false;
return true;
}
return false;
}
public static float Distance(double x1, double y1, double x2, double y2)
{
return (float)(Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
private static void ClearSpaceForChest(int x, int y, ushort floorType)
{
WorldGen.KillTile(x, y);
WorldGen.KillTile(x, y - 1);
WorldGen.KillTile(x + 1, y - 1);
WorldGen.KillTile(x + 1, y);
WorldGen.PlaceTile(x + 1, y + 1, floorType, true, true);
WorldGen.PlaceTile(x, y + 1, floorType, true, true);
Main.tile[x, y].liquid = 0;
Main.tile[x + 1, y].liquid = 0;
Main.tile[x, y + 1].liquid = 0;
Main.tile[x + 1, y + 1].liquid = 0;
}
private static void FillChest(int chestIndex, int[] itemsToPlaceInChests, int[] itemCounts)
{
if (chestIndex < Main.chest.GetLength(0) && chestIndex >= 0)
{
Chest chest = Main.chest[chestIndex];
if (chest != null)
{
for (int inventoryIndex = 0; inventoryIndex < 40; inventoryIndex++)
{
if (chest.item[inventoryIndex].type == 0 && inventoryIndex < itemsToPlaceInChests.GetLength(0))
{
chest.item[inventoryIndex].SetDefaults(itemsToPlaceInChests[inventoryIndex]);
chest.item[inventoryIndex].stack = itemCounts[inventoryIndex];
}
}
}
}
}
public static int GetCurseCount()
{
if (downedNecrodon)
return 0;
int count = 0;
int numBosses = CountDownedBosses();
if (numBosses >= 5)
count++;
if (numBosses >= 10)
count++;
if (numBosses >= 15)
count++;
if (numBosses >= 20)
count++;
return count;
}
public static int CountDownedBosses()
{
int count = 0;
if (NPC.downedSlimeKing) count++;
if (NPC.downedBoss1) count++;
if (downedDuneSharkron) count++;
if (NPC.downedBoss2) count++;
if (downedHypothema) count++;
if (NPC.downedQueenBee) count++;
if (downedRagnar) count++;
if (NPC.downedBoss3) count++;
if (downedAnDio) count++;
if (Main.hardMode) count++;
if (NPC.downedMechBoss2) count++;
if (NPC.downedMechBoss1) count++;
if (NPC.downedMechBoss3) count++;
if (downedAnnihilator) count++;
if (downedSlybertron) count++;
if (downedSteamTrain) count++;
if (NPC.downedPlantBoss) count++;
if (NPC.downedGolemBoss) count++;
if (NPC.downedFishron) count++;
if (downedEtheria || downedTrueEtheria) count++;
if (NPC.downedMoonlord) count++;
return count;
}
public static bool Ameldera { get; private set; }
}
}