forked from GabeHasWon/spritersguildwip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarlightRiver.cs
464 lines (412 loc) · 20.7 KB
/
StarlightRiver.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
using Terraria;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.UI;
using StarlightRiver.GUI;
using System.IO;
using StarlightRiver.Abilities;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Linq;
using StarlightRiver.Items.CursedAccessories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using On.Terraria.GameContent.UI.Elements;
using System;
using Terraria.GameContent.UI.Elements;
using System.Reflection;
using UICharacter = Terraria.GameContent.UI.Elements.UICharacter;
//using On.Terraria;
//using On.Terraria;
namespace StarlightRiver
{
public class StarlightRiver : Mod
{
public Stamina stamina;
public Collection collection;
public Overlay overlay;
public Infusion infusion;
public Cooking cooking;
public LinkHP linkhp;
public UserInterface customResources;
public UserInterface customResources2;
public UserInterface customResources3;
public UserInterface customResources4;
public UserInterface customResources5;
public UserInterface customResources6;
public static ModHotKey Dash;
public static ModHotKey Superdash;
public static ModHotKey Smash;
public static ModHotKey Float;
public static ModHotKey Purify;
public static StarlightRiver Instance { get; set; }
public StarlightRiver()
{
Instance = this;
}
public override void UpdateMusic(ref int music, ref MusicPriority priority)
{
if (Main.myPlayer != -1 && !Main.gameMenu && Main.LocalPlayer.active)
{
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneGlass)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/GlassPassive");
priority = MusicPriority.BiomeMedium;
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneVoidPre)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/VoidPre");
priority = MusicPriority.BossLow;
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleCorrupt)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/JungleCorrupt");
priority = MusicPriority.BiomeHigh;
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleBloody)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/WhipAndNaenae");
priority = MusicPriority.BiomeHigh;
}
if (Main.LocalPlayer.GetModPlayer<BiomeHandler>().ZoneJungleHoly)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/WhipAndNaenae");
priority = MusicPriority.BiomeHigh;
}
if (Main.LocalPlayer.ZoneOverworldHeight && LegendWorld.starfall)
{
music = GetSoundSlot(SoundType.Music, "Sounds/Music/Starlight");
priority = MusicPriority.BiomeHigh;
}
}
return;
}
public override void Load()
{
Dash = RegisterHotKey("Dash", "LeftShift");
Superdash = RegisterHotKey("Void Dash", "Q");
Smash = RegisterHotKey("Smash", "Z");
Float = RegisterHotKey("Float", "F");
Purify = RegisterHotKey("Purify", "N");
if (!Main.dedServ)
{
customResources = new UserInterface();
customResources2 = new UserInterface();
customResources3 = new UserInterface();
customResources4 = new UserInterface();
customResources5 = new UserInterface();
customResources6 = new UserInterface();
stamina = new Stamina();
collection = new Collection();
overlay = new Overlay();
infusion = new Infusion();
cooking = new Cooking();
linkhp = new LinkHP();
customResources.SetState(stamina);
customResources2.SetState(collection);
customResources3.SetState(overlay);
customResources4.SetState(infusion);
customResources5.SetState(cooking);
customResources6.SetState(linkhp);
}
// Cursed Accessory Control Override
On.Terraria.UI.ItemSlot.LeftClick_ItemArray_int_int += NoClickCurse;
On.Terraria.UI.ItemSlot.Draw_SpriteBatch_ItemArray_int_int_Vector2_Color += DrawSpecial;
On.Terraria.UI.ItemSlot.RightClick_ItemArray_int_int += NoSwapCurse;
//Character Slot Addons
On.Terraria.GameContent.UI.Elements.UICharacterListItem.DrawSelf += DrawSpecialCharacter;
//Link mode healthbar
On.Terraria.Main.DrawInterface_Resources_Life += LinkModeHealth;
//Vitrick background
On.Terraria.Main.DrawBackgroundBlackFill += drawVitricBackground;
}
internal static readonly List<BootlegDust> VitricBackgroundDust = new List<BootlegDust>();
internal static readonly List<BootlegDust> VitricForegroundDust = new List<BootlegDust>();
private void drawVitricBackground(On.Terraria.Main.orig_DrawBackgroundBlackFill orig, Terraria.Main self)
{
orig(self);
Player player = Main.LocalPlayer;
VitricBackgroundDust.ForEach(BootlegDust => BootlegDust.Update());
VitricBackgroundDust.RemoveAll(BootlegDust => BootlegDust.time <= 0);
VitricForegroundDust.ForEach(BootlegDust => BootlegDust.Update());
VitricForegroundDust.RemoveAll(BootlegDust => BootlegDust.time <= 0);
if (Main.playerLoaded && player.GetModPlayer<BiomeHandler>().ZoneGlass)
{
Vector2 basepoint = (LegendWorld.vitricTopLeft != null) ? LegendWorld.vitricTopLeft * 16 + new Vector2(-2000, 1000) : Vector2.Zero;
for (int k = 5; k >= 0; k--)
{
drawLayer(basepoint, ModContent.GetTexture("StarlightRiver/Backgrounds/Glass" + k), k + 1);
if (k == 5)
{
VitricBackgroundDust.ForEach(BootlegDust => BootlegDust.Draw(Main.spriteBatch));
}
if (k == 2)
{
VitricForegroundDust.ForEach(BootlegDust => BootlegDust.Draw(Main.spriteBatch));
}
}
for (int k = (int)(player.position.X - basepoint.X) - (int)(Main.screenWidth * 1.5f); k <= (int)(player.position.X - basepoint.X) + (int)(Main.screenWidth * 1.5f); k += 30)
{
if (Main.rand.Next(500) == 0)
{
BootlegDust dus = new VitricDust(ModContent.GetTexture("StarlightRiver/GUI/Light"), basepoint + new Vector2(-2000, 1000), k, 1.5f, 0.3f, 0.1f);
VitricBackgroundDust.Add(dus);
}
if (Main.rand.Next(400) == 0)
{
BootlegDust dus2 = new VitricDust(ModContent.GetTexture("StarlightRiver/GUI/Light"), basepoint + new Vector2(-2000, 1000), k, 2.25f, 1f, 0.4f);
VitricForegroundDust.Add(dus2);
}
}
for (int i = -2 + (int)(player.position.X - Main.screenWidth / 2) / 16; i <= 2 + (int)(player.position.X + Main.screenWidth / 2) / 16; i++)
{
for (int j = -2 + (int)(player.position.Y - Main.screenHeight) / 16; j <= 2 + (int)(player.position.Y + Main.screenHeight) / 16; j++)
{
if (Lighting.Brightness(i,j) == 0 || ((Main.tile[i, j].active() && Main.tile[i, j].collisionType == 1) || Main.tile[i, j].wall != 0))
{
Color color = Color.Black * (1 - Lighting.Brightness(i, j) * 2);
Main.spriteBatch.Draw(Main.blackTileTexture, new Vector2(i * 16, j * 16) - Main.screenPosition, color);
}
else if (i % 4 == 0 && j % 4 == 0 && Main.tile[i,j].wall == 0)
{
Lighting.AddLight(new Vector2(i * 16, j * 16), new Vector3(0.3f, 0.35f, 0.4f) * 2.1f);
}
}
}
}
}
public void drawLayer(Vector2 basepoint, Texture2D texture, int parallax)
{
for (int k = 0; k <= 5; k++)
{
Main.spriteBatch.Draw(texture,
new Vector2(basepoint.X + (k * 739 * 4) + getParallaxOffset(basepoint.X, parallax * 0.1f) - (int)Main.screenPosition.X, basepoint.Y - (int)Main.screenPosition.Y),
new Rectangle(0, 0, 2956, 1528), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
}
}
public int getParallaxOffset(float startpoint, float factor)
{
return (int)((Main.LocalPlayer.position.X - startpoint) * factor);
}
private void LinkModeHealth(On.Terraria.Main.orig_DrawInterface_Resources_Life orig)
{
if (LinkMode.Enabled)
{
return;
}
else
{
orig();
}
}
private void DrawSpecialCharacter(On.Terraria.GameContent.UI.Elements.UICharacterListItem.orig_DrawSelf orig, Terraria.GameContent.UI.Elements.UICharacterListItem self, SpriteBatch spriteBatch)
{
orig(self, spriteBatch);
Vector2 origin = new Vector2(self.GetDimensions().X, self.GetDimensions().Y);
Rectangle box = new Rectangle((int)(origin + new Vector2(86, 66)).X, (int)(origin + new Vector2(86, 66)).Y, 80, 25);
int playerStamina = 0;
//horray double reflection, fuck you vanilla
Type typ = self.GetType();
FieldInfo playerInfo = typ.GetField("_playerPanel", BindingFlags.NonPublic | BindingFlags.Instance);
UICharacter character = (UICharacter)playerInfo.GetValue(self);
Type typ2 = character.GetType();
FieldInfo playerInfo2 = typ2.GetField("_player", BindingFlags.NonPublic | BindingFlags.Instance);
Player player = (Player)playerInfo2.GetValue(character);
AbilityHandler mp = player.GetModPlayer<AbilityHandler>();
playerStamina = mp.staminamax + mp.permanentstamina;
Texture2D wind = mp.unlock[0] == 1 ? ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Wind1") : ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Wind0");
Texture2D wisp = mp.unlock[1] == 1 ? ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Wisp1") : ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Wisp0");
Texture2D pure = mp.unlock[2] == 1 ? ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Purity1") : ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Purity0");
Texture2D smash = mp.unlock[3] == 1 ? ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Smash1") : ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Smash0");
Texture2D shadow = mp.unlock[4] == 1 ? ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Cloak1") : ModContent.GetTexture("StarlightRiver/NPCs/Pickups/Cloak0");
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/box"), box, Color.White); //Stamina box
if (mp.unlock.Any(k => k > 0))//Draw stamina if unlocked
{
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/Stamina"), origin + new Vector2(91, 68), Color.White);
Utils.DrawBorderString(spriteBatch, playerStamina + " SP", origin + new Vector2(118, 68), Color.White);
}
else//Myserious if locked
{
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/Stamina3"), origin + new Vector2(91, 68), Color.White);
Utils.DrawBorderString(spriteBatch,"???", origin + new Vector2(118, 68), Color.White);
}
//Draw ability Icons
spriteBatch.Draw(wind, origin + new Vector2(390, 62), Color.White);
spriteBatch.Draw(wisp, origin + new Vector2(426, 62), Color.White);
spriteBatch.Draw(pure, origin + new Vector2(462, 62), Color.White);
spriteBatch.Draw(smash, origin + new Vector2(498, 62), Color.White);
spriteBatch.Draw(shadow, origin + new Vector2(534, 62), Color.White);
if (player.statLifeMax > 400) //why vanilla dosent do this I dont know
{
spriteBatch.Draw(Main.heart2Texture, origin + new Vector2(80, 37), Color.White);
}
}
private void NoClickCurse(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Terraria.Item[] inv, int context, int slot)
{
if(inv[slot].modItem is CursedAccessory && context == 10)
{
return;
}
orig(inv, context, slot);
}
private void NoSwapCurse(On.Terraria.UI.ItemSlot.orig_RightClick_ItemArray_int_int orig, Terraria.Item[] inv, int context, int slot)
{
Player player = Main.player[Main.myPlayer];
for (int i = 0; i < player.armor.Length; i++)
{
if (player.armor[i].modItem is CursedAccessory && ItemSlot.ShiftInUse && inv[slot].accessory)
{
return;
}
}
orig(inv, context, slot);
}
private void DrawSpecial(On.Terraria.UI.ItemSlot.orig_Draw_SpriteBatch_ItemArray_int_int_Vector2_Color orig, SpriteBatch sb, Terraria.Item[] inv, int context, int slot, Vector2 position, Color color)
{
if ((inv[slot].modItem is CursedAccessory || inv[slot].modItem is BlessedAccessory) && context == 10)
{
Texture2D back = inv[slot].modItem is CursedAccessory ? ModContent.GetTexture("StarlightRiver/GUI/CursedBack") : ModContent.GetTexture("StarlightRiver/GUI/BlessedBack");
Color backcolor = (!Main.expertMode && slot == 8) ? Color.White * 0.25f : Color.White * 0.75f;
sb.Draw(back, position, null, backcolor, 0f, default(Vector2), Main.inventoryScale, SpriteEffects.None, 0f);
//Zoinked from vanilla code
Item item = inv[slot];
Vector2 vector = back.Size() * Main.inventoryScale;
Texture2D texture2D3 = ModContent.GetTexture("StarlightRiver/Items/CursedAccessories/"+inv[slot].modItem.Name);
Rectangle rectangle2 = (texture2D3.Frame(1, 1, 0, 0));
Color currentColor = color;
float scale3 = 1f;
ItemSlot.GetItemLight(ref currentColor, ref scale3, item, false);
float num8 = 1f;
if (rectangle2.Width > 32 || rectangle2.Height > 32)
{
num8 = ((rectangle2.Width <= rectangle2.Height) ? (32f / (float)rectangle2.Height) : (32f / (float)rectangle2.Width));
}
num8 *= Main.inventoryScale;
Vector2 position2 = position + vector / 2f - rectangle2.Size() * num8 / 2f;
Vector2 origin = rectangle2.Size() * (scale3 / 2f - 0.5f);
if (ItemLoader.PreDrawInInventory(item, sb, position2, rectangle2, item.GetAlpha(currentColor), item.GetColor(color), origin, num8 * scale3))
{
sb.Draw(texture2D3, position2, rectangle2, Color.White, 0f, origin, num8 * scale3, SpriteEffects.None, 0f);
}
ItemLoader.PostDrawInInventory(item, sb, position2, rectangle2, item.GetAlpha(currentColor), item.GetColor(color), origin, num8 * scale3);
//End zoink
}
else
{
orig(sb, inv, context, slot, position, color);
}
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int MouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
if (MouseTextIndex != -1)
{
layers.Insert(MouseTextIndex, new LegacyGameInterfaceLayer("[PH]MODNAME: Cooldown",
delegate
{
if (Stamina.visible)
{
customResources.Update(Main._drawInterfaceGameTime);
stamina.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
layers.Insert(MouseTextIndex + 1, new LegacyGameInterfaceLayer("[PH]MODNAME: Collection",
delegate
{
if (Collection.visible)
{
customResources2.Update(Main._drawInterfaceGameTime);
collection.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
layers.Insert(0, new LegacyGameInterfaceLayer("[PH]MODNAME: Overlay",
delegate
{
if (Overlay.visible)
{
customResources3.Update(Main._drawInterfaceGameTime);
overlay.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
layers.Insert(MouseTextIndex + 2, new LegacyGameInterfaceLayer("[PH]MODNAME: Infusions",
delegate
{
if (Infusion.visible)
{
customResources4.Update(Main._drawInterfaceGameTime);
infusion.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
layers.Insert(MouseTextIndex + 3, new LegacyGameInterfaceLayer("[PH]MODNAME: Cooking",
delegate
{
if (Cooking.visible)
{
customResources5.Update(Main._drawInterfaceGameTime);
cooking.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
layers.Insert(MouseTextIndex + 4, new LegacyGameInterfaceLayer("[PH]MODNAME: LinkHP",
delegate
{
if (LinkHP.visible)
{
customResources6.Update(Main._drawInterfaceGameTime);
linkhp.Draw(Main.spriteBatch);
}
return true;
}, InterfaceScaleType.UI));
}
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
// var target = new Abilities.Ability(0);
//var ms = new MemoryStream(Encoding.UTF8.GetBytes(reader.ReadString()));
// var ser = new DataContractJsonSerializer(target.GetType());
//target = ser.ReadObject(ms) as Abilities.Ability;
//Main.player[whoAmI].GetModPlayer<AbilityHandler>().ability = target;
LinkMode.Enabled = reader.ReadBoolean();
LinkMode.MaxWorldHP = reader.ReadInt32();
LinkMode.WorldHP = reader.ReadInt32();
//Main.NewText("Packet Recieved!", 100, 100, 255);
Console.WriteLine("Server Packet Recieved!");
}
public override void Unload()
{
if (!Main.dedServ)
{
customResources = null;
customResources2 = null;
customResources3 = null;
customResources4 = null;
customResources5 = null;
customResources6 = null;
stamina = null;
collection = null;
overlay = null;
infusion = null;
cooking = null;
linkhp = null;
VitricBackgroundDust.Clear();
VitricForegroundDust.Clear();
CursedAccessory.Bootlegdust.Clear();
BlessedAccessory.Bootlegdust.Clear();
BlessedAccessory.Bootlegdust2.Clear();
Collection.Bootlegdust.Clear();
Overlay.Bootlegdust.Clear();
Instance = null;
Dash = null;
Superdash = null;
Float = null;
Smash = null;
Purify = null;
}
}
}
}