-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRijamsModWorld.cs
312 lines (297 loc) · 10.4 KB
/
RijamsModWorld.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
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace RijamsMod
{
public class RijamsModWorld : ModSystem
{
public static bool savedHarpy = false;
public static bool intTravArrived = false;
public static bool intTravQuestOddDevice = false;
public static bool intTravQuestBlankDisplay = false;
public static bool intTravQuestTPCore = false;
public static bool intTravQuestBreadAndJelly = false;
public static bool intTravQuestMagicOxygenizer = false;
public static bool intTravQuestPrimeThruster = false;
public static bool hellTraderArrivable = false;
public static bool boughtSnuggetPet = false;
public static int harpyJustRescued = 0; // Not important for saving.
public override void OnWorldLoad()
{
savedHarpy = false;
intTravArrived = false;
intTravQuestOddDevice = false;
intTravQuestBlankDisplay = false;
intTravQuestTPCore = false;
intTravQuestBreadAndJelly = false;
intTravQuestMagicOxygenizer = false;
intTravQuestPrimeThruster = false;
hellTraderArrivable = false;
boughtSnuggetPet = false;
harpyJustRescued = 0;
}
public override void OnWorldUnload()
{
savedHarpy = false;
intTravArrived = false;
intTravQuestOddDevice = false;
intTravQuestBlankDisplay = false;
intTravQuestTPCore = false;
intTravQuestBreadAndJelly = false;
intTravQuestMagicOxygenizer = false;
intTravQuestPrimeThruster = false;
hellTraderArrivable = false;
boughtSnuggetPet = false;
harpyJustRescued = 0;
}
public override void SaveWorldData(TagCompound tag)
{
if (savedHarpy)
{
tag["savedHarpy"] = true;
}
if (intTravArrived)
{
tag["intTravArived"] = true;
}
if (intTravQuestOddDevice)
{
tag["intTravQuestOddDevice"] = true;
}
if (intTravQuestBlankDisplay)
{
tag["intTravQuestBlankDisplay"] = true;
}
if (intTravQuestTPCore)
{
tag["intTravQuestTPCore"] = true;
}
if (intTravQuestBreadAndJelly)
{
tag["intTravQuestRyeJam"] = true;
}
if (intTravQuestMagicOxygenizer)
{
tag["intTravQuestBreathingPack"] = true;
}
if (intTravQuestPrimeThruster)
{
tag["intTravQuestPrimeThruster"] = true;
}
if (hellTraderArrivable)
{
tag["hellTraderArrivable"] = true;
}
if (boughtSnuggetPet)
{
tag["boughtSnuggetPet"] = true;
}
}
public override void LoadWorldData(TagCompound tag)
{
savedHarpy = tag.ContainsKey("savedHarpy");
intTravArrived = tag.ContainsKey("intTravArived");
intTravQuestOddDevice = tag.ContainsKey("intTravQuestOddDevice");
intTravQuestBlankDisplay = tag.ContainsKey("intTravQuestBlankDisplay");
intTravQuestTPCore = tag.ContainsKey("intTravQuestTPCore");
intTravQuestBreadAndJelly = tag.ContainsKey("intTravQuestRyeJam");
intTravQuestMagicOxygenizer = tag.ContainsKey("intTravQuestBreathingPack");
intTravQuestPrimeThruster = tag.ContainsKey("intTravQuestPrimeThruster");
hellTraderArrivable = tag.ContainsKey("hellTraderArrivable");
boughtSnuggetPet = tag.ContainsKey("boughtSnuggetPet");
}
public override void NetSend(BinaryWriter writer)
{
//Remember that Bytes/BitsByte only have 8 entries. If you have more than 8 flags you want to sync, use multiple BitsByte
var flags = new BitsByte();
flags[0] = savedHarpy;
flags[1] = intTravArrived;
flags[2] = intTravQuestOddDevice;
flags[3] = intTravQuestBlankDisplay;
flags[4] = intTravQuestTPCore;
flags[5] = intTravQuestBreadAndJelly;
flags[6] = intTravQuestMagicOxygenizer;
flags[7] = intTravQuestPrimeThruster;
writer.Write(flags);
var flags2 = new BitsByte();
flags2[0] = hellTraderArrivable;
flags2[1] = boughtSnuggetPet;
writer.Write(flags2);
}
public override void NetReceive(BinaryReader reader)
{
BitsByte flags = reader.ReadByte();
savedHarpy = flags[0];
intTravArrived = flags[1];
intTravQuestOddDevice = flags[2];
intTravQuestBlankDisplay = flags[3];
intTravQuestTPCore = flags[4];
intTravQuestBreadAndJelly = flags[5];
intTravQuestMagicOxygenizer = flags[6];
intTravQuestPrimeThruster = flags[7];
BitsByte flags2 = reader.ReadByte();
hellTraderArrivable = flags2[0];
boughtSnuggetPet = flags2[1];
}
public static void UpdateWorldBool() // from Calamity's Vanities
{
if (Main.netMode == NetmodeID.Server)
{
NetMessage.SendData(MessageID.WorldData);
}
}
public override void PostWorldGen()
{
for (int chestIndex = 0; chestIndex < Main.maxChests; chestIndex++)
{
Chest chest = Main.chest[chestIndex];
// Mod.Logger.Debug("RijamsMod: chestIndex " + chestIndex);
if (chest != null && Main.tile[chest.x, chest.y].TileType == TileID.Containers)
{
// Chest IDs are from the Tile_21 image. They can easily be found on this wiki page https://terraria.wiki.gg/wiki/Tile_IDs
// Wooden Chest (0)
if (Main.tile[chest.x, chest.y].TileFrameX == 0 * 36)
{
// Mod.Logger.Debug("RijamsMod: Wooden Chest found at: " + chest.x + " " + chest.y);
// 1 in 4 may seem super common, but it really isn't.
// If there are 40 Wooden Chests in a large world, then that means only 10 of them have the item.
// Also, a lot of Wooden Chests are in hard to reach areas underground.
// Expect about half the number of chests in a small world.
if (WorldGen.genRand.NextBool(4))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
//Mod.Logger.Debug("RijamsMod: Belt added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Weapons.Summon.Whips.Belt>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
if (WorldGen.genRand.NextBool(8))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Small Glow Ring added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Accessories.Misc.SmallGlowRing>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
}
// Locked Golden Chest (2)
if (Main.tile[chest.x, chest.y].TileFrameX == 2 * 36)
{
// Mod.Logger.Debug("RijamsMod: Locked Golden Chest found at: " + chest.x + " " + chest.y);
// Again, seems common but is not.
// If there are 20 Locked Golden Chests in a large world, only 4 of them have the item.
if (WorldGen.genRand.NextBool(5))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Cobalt Protector Cudgel added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Weapons.Summon.Cudgels.CobaltProtectorCudgel>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
if (chest.item[0].type == ItemID.Handgun) // If the first slot of the chest is a Handgun, add the StockadeCrossbow.
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Stockade Crossbow added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Weapons.Ranged.StockadeCrossbow>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
if (WorldGen.genRand.NextBool(9))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Stumble Card added in Locked Gold Chest.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Weapons.Other.StumbleCard>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
}
if (Main.tile[chest.x, chest.y].TileFrameX == 4 * 36) // Locked Shadow Chest
{
if (WorldGen.genRand.NextBool(7))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Stumble Card added in Locked Shadow Chest.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Weapons.Other.StumbleCard>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
}
if (Main.tile[chest.x, chest.y].TileFrameX == 17 * 36) // Water Chest
{
if (WorldGen.genRand.NextBool(6))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Wild Bait added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Fishing.WildBait>());
chest.item[inventoryIndex].stack = WorldGen.genRand.Next(1, 4); // 1 to 3
break;
}
}
}
if (WorldGen.genRand.NextBool(15))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Trap Bobber added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Accessories.Misc.TrapBobber>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
if (WorldGen.genRand.NextBool(15))
{
for (int inventoryIndex = 0; inventoryIndex < Chest.maxItems; inventoryIndex++)
{
if (chest.item[inventoryIndex].IsAir)
{
// Mod.Logger.Debug("RijamsMod: Spinner Bobber added.");
chest.item[inventoryIndex].SetDefaults(ModContent.ItemType<Items.Accessories.Misc.SpinnerBobber>());
chest.item[inventoryIndex].stack = 1;
break;
}
}
}
}
}
}
}
}
}