forked from Werebearguy/AssortedCrazyThings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssortedCrazyThings.cs
396 lines (351 loc) · 10.8 KB
/
AssortedCrazyThings.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
using AssortedCrazyThings.Base;
using AssortedCrazyThings.Effects;
using AssortedCrazyThings.Items.Accessories.Vanity;
using AssortedCrazyThings.Items.Weapons;
using AssortedCrazyThings.NPCs.DropConditions;
using AssortedCrazyThings.NPCs.Harvester;
using AssortedCrazyThings.Projectiles.Pets;
using AssortedCrazyThings.Tiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.Chat;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
namespace AssortedCrazyThings
{
class AssortedCrazyThings : Mod
{
//Soul item animated textures
public const int animatedSoulFrameCount = 6;
public static Asset<Texture2D>[] animatedSoulTextures;
/// <summary>
/// Soul NPC spawn blacklist
/// </summary>
public static int[] soulBuffBlacklist;
/// <summary>
/// The cached type of the Harvester boss, 0 if not loaded
/// </summary>
public static int harvester;
/// <summary>
/// The cached type of the left talon of the Harvester boss, 0 if not loaded
/// </summary>
public static int harvesterTalonLeft;
/// <summary>
/// The cached type of the right talon of the Harvester boss, 0 if not loaded
/// </summary>
public static int harvesterTalonRight;
//Mod Helpers compat
public static string GithubUserName { get { return "Werebearguy"; } }
public static string GithubProjectName { get { return "AssortedCrazyThings"; } }
private void LoadSoulBuffBlacklist()
{
List<int> tempList = new List<int>
{
NPCID.Bee,
NPCID.BeeSmall,
NPCID.BlueSlime,
NPCID.BlazingWheel,
NPCID.EaterofWorldsHead,
NPCID.EaterofWorldsBody,
NPCID.EaterofWorldsTail,
NPCID.Creeper,
NPCID.GolemFistLeft,
NPCID.GolemFistRight,
NPCID.PlanterasHook,
NPCID.PlanterasTentacle,
NPCID.Probe,
NPCID.ServantofCthulhu,
NPCID.SlimeSpiked,
NPCID.SpikeBall,
NPCID.TheHungry,
NPCID.TheHungryII,
};
soulBuffBlacklist = tempList.ToArray();
}
/// <summary>
/// Assuming this is called after InitSoulBuffBlacklist.
/// Adds NPC types to soulBuffBlacklist manually
/// </summary>
private void AddToSoulBuffBlacklist()
{
if (!ContentConfig.Instance.Bosses)
{
return;
}
//assuming this is called after InitSoulBuffBlacklist
List<int> tempList = new List<int>(soulBuffBlacklist)
{
ModContent.NPCType<DungeonSoul>(),
ModContent.NPCType<DungeonSoulFreed>(),
};
soulBuffBlacklist = tempList.ToArray();
Array.Sort(soulBuffBlacklist);
}
/// <summary>
/// Fills isModdedWormBodyOrTail with types of modded NPCs which names are ending with Body or Tail (indicating they are part of something)
/// </summary>
private void LoadWormList()
{
List<int> tempList = new List<int>();
for (int i = NPCID.Count; i < NPCLoader.NPCCount; i++)
{
ModNPC modNPC = NPCLoader.GetNPC(i);
if (modNPC != null && (modNPC.GetType().Name.EndsWith("Body") || modNPC.GetType().Name.EndsWith("Tail")))
{
tempList.Add(modNPC.NPC.type);
}
}
AssUtils.isModdedWormBodyOrTail = tempList.ToArray();
Array.Sort(AssUtils.isModdedWormBodyOrTail);
}
private void LoadHarvesterTypes()
{
if (!ContentConfig.Instance.Bosses)
{
return;
}
harvester = ModContent.NPCType<HarvesterBoss>();
harvesterTalonLeft = ModContent.NPCType<HarvesterTalonLeft>();
harvesterTalonRight = ModContent.NPCType<HarvesterTalonRight>();
}
private void LoadMisc()
{
if (!Main.dedServ && ContentConfig.Instance.Bosses)
{
animatedSoulTextures = new Asset<Texture2D>[2];
animatedSoulTextures[0] = Assets.Request<Texture2D>("Items/CaughtDungeonSoulAnimated");
animatedSoulTextures[1] = Assets.Request<Texture2D>("Items/CaughtDungeonSoulFreedAnimated");
}
//Needs to be initialized early since it's used outside of its own condition
string category = $"DropConditions.";
MatchAppearanceCondition.DescriptionText = Language.GetOrRegister(ModContent.GetInstance<AssortedCrazyThings>().GetLocalizationKey($"{category}{typeof(MatchAppearanceCondition).Name}.Description"));
}
private void UnloadMisc()
{
animatedSoulTextures = null;
PetEaterofWorldsBase.wormTypes = null;
PetDestroyerBase.wormTypes = null;
}
public override void Load()
{
ConfigurationSystem.Load();
ShaderManager.Load();
LoadHarvesterTypes();
LoadSoulBuffBlacklist();
LoadMisc();
}
public override void Unload()
{
ConfigurationSystem.Unload();
ShaderManager.Unload();
UnloadMisc();
GitgudData.Unload();
EverhallowedLantern.DoUnload();
}
public override void PostSetupContent()
{
//for things that have to be called after Load() because of Main.projFrames[projectile.type] calls (and similar)
LoadWormList();
GitgudData.Load();
DroneController.DoLoad();
EverhallowedLantern.DoLoad();
AddToSoulBuffBlacklist();
if (ContentConfig.Instance.DroppedPets)
{
PetEaterofWorldsBase.wormTypes = new int[]
{
ModContent.ProjectileType<PetEaterofWorldsHead>(),
ModContent.ProjectileType<PetEaterofWorldsBody1>(),
ModContent.ProjectileType<PetEaterofWorldsBody2>(),
ModContent.ProjectileType<PetEaterofWorldsTail>()
};
PetDestroyerBase.wormTypes = new int[]
{
ModContent.ProjectileType<PetDestroyerHead>(),
ModContent.ProjectileType<PetDestroyerBody1>(),
ModContent.ProjectileType<PetDestroyerBody2>(),
ModContent.ProjectileType<PetDestroyerTail>()
};
}
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
AssMessageType msgType = (AssMessageType)reader.ReadByte();
byte playerNumber;
byte npcNumber;
AssPlayer aPlayer;
PetPlayer petPlayer;
byte changes;
byte index;
switch (msgType)
{
case AssMessageType.SyncPlayerVanity:
playerNumber = reader.ReadByte();
petPlayer = Main.player[playerNumber].GetModPlayer<PetPlayer>();
//no "changes" packet
petPlayer.RecvSyncPlayerVanitySub(reader);
break;
case AssMessageType.ClientChangesVanity:
//client and server
//getmodplayer error
playerNumber = reader.ReadByte();
petPlayer = Main.player[playerNumber].GetModPlayer<PetPlayer>();
changes = reader.ReadByte();
index = reader.ReadByte();
petPlayer.RecvClientChangesPacketSub(reader, changes, index);
//server transmits to others
if (Main.netMode == NetmodeID.Server)
{
petPlayer.SendClientChangesPacketSub(changes, index, toClient: -1, ignoreClient: playerNumber);
}
break;
case AssMessageType.SyncAssPlayer:
playerNumber = reader.ReadByte();
aPlayer = Main.player[playerNumber].GetModPlayer<AssPlayer>();
aPlayer.ReceiveSyncPlayer(reader);
break;
case AssMessageType.ClientChangesAssPlayer:
//client and server
//getmodplayer error
playerNumber = reader.ReadByte();
aPlayer = Main.player[playerNumber].GetModPlayer<AssPlayer>();
aPlayer.shieldDroneReduction = reader.ReadByte();
aPlayer.droneControllerUnlocked = (DroneType)reader.ReadByte();
aPlayer.selectedSillyBalloonType = (BalloonType)reader.ReadByte();
//server transmits to others
if (Main.netMode == NetmodeID.Server)
{
aPlayer.SendClientChangesPacket(toClient: -1, ignoreClient: playerNumber);
}
break;
case AssMessageType.ConvertInertSoulsInventory:
if (Main.netMode == NetmodeID.MultiplayerClient)
{
//convert souls in local inventory
aPlayer = Main.LocalPlayer.GetModPlayer<AssPlayer>();
aPlayer.ConvertInertSoulsInventory();
}
break;
case AssMessageType.GitgudLoadCounters:
if (Main.netMode == NetmodeID.Server)
{
GitgudData.RecvCounters(reader);
}
break;
case AssMessageType.GitgudChangeCounters:
if (Main.netMode == NetmodeID.MultiplayerClient)
{
//GitgudData.RecvReset(Main.myPlayer, reader);
GitgudData.RecvChangeCounter(reader);
}
break;
case AssMessageType.ResetEmpoweringTimerpvp:
//client and server
playerNumber = reader.ReadByte();
aPlayer = Main.player[playerNumber].GetModPlayer<AssPlayer>();
aPlayer.ResetEmpoweringTimer(fromServer: true);
//server transmits to others
if (Main.netMode == NetmodeID.Server)
{
ModPacket packet = GetPacket();
packet.Write((byte)AssMessageType.ResetEmpoweringTimerpvp);
packet.Write((byte)playerNumber);
packet.Send(playerNumber); //send to client
}
break;
case AssMessageType.WyvernCampfireKill:
npcNumber = reader.ReadByte();
if (npcNumber < 0 || npcNumber >= Main.maxNPCs) break;
NPC npc = Main.npc[npcNumber];
if (npc.type == NPCID.WyvernHead)
{
DungeonSoulBase.KillInstantly(npc);
if (npcNumber < Main.maxNPCs)
{
NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npcNumber);
}
}
else
{
for (int k = 0; k < Main.maxNPCs; k++)
{
NPC other = Main.npc[k];
if (other.active && other.type == NPCID.WyvernHead)
{
DungeonSoulBase.KillInstantly(other);
NetMessage.SendData(MessageID.SyncNPC, number: k);
break;
}
}
}
break;
case AssMessageType.SlainBoss:
int type = reader.Read7BitEncodedInt();
if (Main.netMode == NetmodeID.MultiplayerClient)
{
Main.LocalPlayer.GetModPlayer<AssPlayer>().SlainBoss(type);
}
break;
case AssMessageType.HarvesterSpawnFromCage:
playerNumber = reader.ReadByte();
Vector2 spawnPos = reader.ReadVector2();
bool resend = Main.netMode == NetmodeID.Server;
AntiqueCageUnlockedTile.SpawnFromCage(Main.player[playerNumber], spawnPos, resend);
break;
case AssMessageType.RequestChatMessage:
NetworkText text = NetworkText.Deserialize(reader);
Color color = reader.ReadRGB();
if (Main.netMode == NetmodeID.Server)
{
ChatHelper.BroadcastChatMessage(text, color);
}
break;
default:
Logger.Debug("Unknown Message type: " + msgType);
break;
}
}
//Credit to jopojelly
/// <summary>
/// Makes alpha on .png textures actually properly rendered
/// </summary>
public static void PremultiplyTexture(Texture2D texture)
{
Color[] buffer = new Color[texture.Width * texture.Height];
texture.GetData(buffer);
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] = Color.FromNonPremultiplied(buffer[i].R, buffer[i].G, buffer[i].B, buffer[i].A);
}
texture.SetData(buffer);
}
}
public enum AssMessageType : byte
{
ClientChangesVanity,
SyncPlayerVanity,
ClientChangesAssPlayer,
SyncAssPlayer,
ConvertInertSoulsInventory,
GitgudLoadCounters,
GitgudChangeCounters,
ResetEmpoweringTimerpvp,
WyvernCampfireKill,
SlainBoss,
HarvesterSpawnFromCage,
RequestChatMessage
}
public enum PetPlayerChanges : byte
{
None,
All,
Slots,
PetTypes
}
}