-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpiritMod.cs
363 lines (335 loc) · 14.8 KB
/
SpiritMod.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
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.Initializers;
using Terraria.IO;
using Terraria.GameContent;
using Terraria.ModLoader;
using SpiritMod.NPCs.Boss.Overseer;
namespace SpiritMod
{
class SpiritMod : Mod
{
public static int customEvent;
public static int MyWorld;
public const string customEventName = "The Tide";
public static ModHotKey SpecialKey;
public static ModHotKey GoreKey;
public static ModHotKey IchorKey;
public SpiritMod()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true,
AutoloadBackgrounds = true
};
}
public override void Load()
{
{
InvasionHandler.AddInvasion(out SpiritMod.customEvent, new InvasionInfo(customEventName,
"The depths are stirring!", "The Tide has waned!",
delegate ()
{
int amountOfPlayers = 0;
int maxAmountOfPlayers = 6;
for (int i = 0; i < 255; ++i)
{
if (Main.player[i].active && Main.player[i].statLifeMax >= 400)
{
amountOfPlayers++;
if (amountOfPlayers == maxAmountOfPlayers)
break;
}
}
if (amountOfPlayers > 0)
{
InvasionWorld.invasionSize = 120 + (30 * amountOfPlayers);
InvasionWorld.invasionX = Main.spawnTileX;
}
return false;
}));
}
SpecialKey = RegisterHotKey("Cosmic Wrath", "G");
GoreKey = RegisterHotKey("Ichor Rage", "T");
IchorKey = RegisterHotKey("Ichor Guard", "C");
if (!Main.dedServ)
{
Filters.Scene["SpiritMod:Overseer"] = new Filter(new SeerScreenShaderData("FilterMiniTower").UseColor(0f, 0.3f, 1f).UseOpacity(0.75f), EffectPriority.VeryHigh);
SkyManager.Instance["SpiritMod:Overseer"] = new SeerSky();
Filters.Scene["SpiritMod:IlluminantMaster"] = new Filter(new SeerScreenShaderData("FilterMiniTower").UseColor(1.2f, 0.1f, 1f).UseOpacity(0.75f), EffectPriority.VeryHigh);
SkyManager.Instance["SpiritMod:IlluminantMasterr"] = new SeerSky();
}
}
public override void UpdateMusic(ref int music)
{
int[] NoOverride = {MusicID.Boss1, MusicID.Boss2, MusicID.Boss3, MusicID.Boss4, MusicID.Boss5,
MusicID.LunarBoss, MusicID.PumpkinMoon, MusicID.TheTowers, MusicID.FrostMoon, MusicID.GoblinInvasion,
MusicID.PirateInvasion, GetSoundSlot(SoundType.Music, "Sounds/Music/Overseer")};
bool playMusic = true;
foreach (int n in NoOverride)
{
if (music == n) playMusic = false;
}
if (Main.myPlayer != -1 && !Main.gameMenu)
{
}
if (Main.player[Main.myPlayer].active && Main.player[Main.myPlayer].GetModPlayer<MyPlayer>(this).ZoneSpirit && (Main.player[Main.myPlayer].position.Y / 16) < WorldGen.rockLayer && playMusic)
{
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/SpiritOverworld");
}
if (Main.player[Main.myPlayer].active && Main.player[Main.myPlayer].GetModPlayer<MyPlayer>(this).ZoneSpirit && (Main.player[Main.myPlayer].position.Y / 16) >= WorldGen.rockLayer && playMusic)
{
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/SpiritUnderground");
}
if (Main.player[Main.myPlayer].active && Main.player[Main.myPlayer].GetModPlayer<MyPlayer>(this).ZoneVerdant && playMusic)
{
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/VerdantMusic");
}
if (InvasionWorld.invasionType == SpiritMod.customEvent)
{
music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/DepthInvasion");
}
}
public override void PostSetupContent()
{
{
Mod bossChecklist = ModLoader.GetMod("BossChecklist");
if (bossChecklist != null)
{
// 14 is moolord, 12 is duke fishron
bossChecklist.Call("AddBoss", "Scarabeus", 0.8f);
bossChecklist.Call("AddBoss", "Ancient Flier", 4.2f);
bossChecklist.Call("AddBoss", "Atlas", 5.4f);
bossChecklist.Call("AddBoss", "Infernon", 6.5f);
bossChecklist.Call("AddBoss", "Dusking", 7.3f);
bossChecklist.Call("AddBoss", "IlluminantMaster", 10.1f);
bossChecklist.Call("AddBoss", "Overseer", 14.2f);
}
}
{
LoadReferences();
Item ccoutfit = new Item();
ccoutfit.SetDefaults(ItemType("CandyCopterOutfit"));
Mounts.CandyCopter._outfit = ccoutfit.legSlot;
}
}
/// <summary>
/// Scans all classes deriving from any Mod type
/// for a field called _ref
/// and populates it, if it exists.
/// </summary>
private void LoadReferences()
{
foreach (Type type in Code.GetTypes())
{
if (type.IsAbstract)
{
continue;
}
System.Reflection.FieldInfo field = type.GetField("_ref");
if (field == null || !field.IsStatic)
{
continue;
}
if (type.IsSubclassOf(typeof(ModItem)))
{
if (field.FieldType == typeof(ModItem))
{
field.SetValue(null, GetItem(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModNPC)))
{
if (field.FieldType == typeof(ModNPC))
{
field.SetValue(null, GetNPC(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModProjectile)))
{
if (field.FieldType == typeof(ModProjectile))
{
field.SetValue(null, GetProjectile(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModDust)))
{
if (field.FieldType == typeof(ModDust))
{
field.SetValue(null, GetDust(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModTile)))
{
if (field.FieldType == typeof(ModTile))
{
field.SetValue(null, GetTile(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModWall)))
{
if (field.FieldType == typeof(ModWall))
{
field.SetValue(null, GetWall(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModBuff)))
{
if (field.FieldType == typeof(ModBuff))
{
field.SetValue(null, GetBuff(type.Name));
}
} else if (type.IsSubclassOf(typeof(ModMountData)))
{
if (field.FieldType == typeof(ModMountData))
{
field.SetValue(null, GetMount(type.Name));
}
}
}
}
public override void HotKeyPressed(string name)
{
if(name == "Concentration_Hotkey")
{
MyPlayer mp = Main.player[Main.myPlayer].GetModPlayer<MyPlayer>(this);
if(mp.leatherSet && !mp.concentrated && mp.concentratedCooldown <= 0)
{
mp.concentrated = true;
}
}
}
public override void PostDrawInterface(SpriteBatch spriteBatch)
{
if (InvasionWorld.invasionType <= 0 || InvasionWorld.invasionProgress == -1)
return;
if (InvasionHandler.currentInvasion == null || InvasionHandler.currentInvasion != InvasionHandler.GetInvasionInfo(InvasionWorld.invasionType))
{
InvasionHandler.currentInvasion = InvasionHandler.GetInvasionInfo(InvasionWorld.invasionType);
if (Main.netMode == 0)
{
Main.NewText(InvasionHandler.currentInvasion.beginMessage, 175, 75, 255, false);
return;
}
if (Main.netMode == 2)
{
NetMessage.SendData(25, -1, -1, InvasionHandler.currentInvasion.beginMessage, 255, 175f, 75f, 255f, 0, 0, 0);
}
}
if (!Main.gamePaused && InvasionHandler.invasionProgressDisplayLeft > 0)
{
InvasionHandler.invasionProgressDisplayLeft--;
}
if (InvasionHandler.invasionProgressDisplayLeft > 0)
{
InvasionHandler.invasionProgressAlpha += 0.05f;
}
else
{
InvasionHandler.invasionProgressAlpha -= 0.05f;
}
if (InvasionHandler.invasionProgressAlpha < 0f)
{
InvasionHandler.invasionProgressAlpha = 0f;
}
if (InvasionHandler.invasionProgressAlpha > 1f)
{
InvasionHandler.invasionProgressAlpha = 1f;
}
if (InvasionHandler.invasionProgressAlpha > 0)
{
float num = 0.5f + InvasionHandler.invasionProgressAlpha * 0.5f;
string text = InvasionHandler.currentInvasion.name;
Color c = new Color(64, 109, 164) * 0.5f;
int num7 = (int)(200f * num);
int num8 = (int)(45f * num);
Vector2 vector3 = new Vector2((float)(Main.screenWidth - 120), (float)(Main.screenHeight - 40));
Rectangle r2 = new Rectangle((int)vector3.X - num7 / 2, (int)vector3.Y - num8 / 2, num7, num8);
Utils.DrawInvBG(spriteBatch, r2, new Color(63, 65, 151, 255) * 0.785f);
string text3;
if (InvasionWorld.invasionProgressMax == 0)
{
text3 = InvasionWorld.invasionProgress.ToString();
}
else
{
text3 = ((int)((float)InvasionWorld.invasionProgress * 100f / (float)InvasionWorld.invasionProgressMax)).ToString() + "%";
}
text3 = "Cleared " + text3;
Texture2D texture2D4 = Main.colorBarTexture;
Texture2D texture2D5 = Main.colorBlipTexture;
if (InvasionWorld.invasionProgressMax != 0)
{
spriteBatch.Draw(texture2D4, vector3, null, Color.White * InvasionHandler.invasionProgressAlpha, 0f, new Vector2((float)(texture2D4.Width / 2), 0f), num, SpriteEffects.None, 0f);
float num9 = MathHelper.Clamp((float)InvasionWorld.invasionProgress / (float)InvasionWorld.invasionProgressMax, 0f, 1f);
float num10 = 169f * num;
float num11 = 8f * num;
Vector2 vector4 = vector3 + Vector2.UnitY * num11 + Vector2.UnitX * 1f;
Utils.DrawBorderString(Main.spriteBatch, text3, vector4, Color.White * InvasionHandler.invasionProgressAlpha, num, 0.5f, 1f, -1);
vector4 += Vector2.UnitX * (num9 - 0.5f) * num10;
spriteBatch.Draw(Main.magicPixel, vector4, new Rectangle?(new Rectangle(0, 0, 1, 1)), new Color(255, 241, 51) * InvasionHandler.invasionProgressAlpha, 0f, new Vector2(1f, 0.5f), new Vector2(num10 * num9, num11), SpriteEffects.None, 0f);
spriteBatch.Draw(Main.magicPixel, vector4, new Rectangle?(new Rectangle(0, 0, 1, 1)), new Color(255, 165, 0, 127) * InvasionHandler.invasionProgressAlpha, 0f, new Vector2(1f, 0.5f), new Vector2(2f, num11), SpriteEffects.None, 0f);
spriteBatch.Draw(Main.magicPixel, vector4, new Rectangle?(new Rectangle(0, 0, 1, 1)), Color.Black * InvasionHandler.invasionProgressAlpha, 0f, new Vector2(0f, 0.5f), new Vector2(num10 * (1f - num9), num11), SpriteEffects.None, 0f);
}
Vector2 center = new Vector2((Main.screenWidth - 120), (Main.screenHeight - 80));
Vector2 value = Main.fontItemStack.MeasureString(text);
Rectangle r3 = Utils.CenteredRectangle(center, (value + new Vector2((float)(20), 10f)) * num);
Utils.DrawInvBG(Main.spriteBatch, r3, c);
Utils.DrawBorderString(spriteBatch, text, r3.Right() + Vector2.UnitX * num * -8f, Color.White * InvasionHandler.invasionProgressAlpha, num * 0.9f, 1f, 0.4f, -1);
}
}
const int ShakeLength = 5;
int ShakeCount = 0;
float previousRotation = 0;
float targetRotation = 0;
float previousOffsetX = 0;
float previousOffsetY = 0;
float targetOffsetX = 0;
float targetOffsetY = 0;
public static float shittyModTime;
public override Matrix ModifyTransformMatrix(Matrix Transform)
{
shittyModTime--;
if (!Main.gameMenu)
{
if (shittyModTime > 0)
{
if (shittyModTime % ShakeLength == 0)
{
ShakeCount = 0;
previousRotation = targetRotation;
previousOffsetX = targetOffsetX;
previousOffsetY = targetOffsetY;
targetRotation = (Main.rand.NextFloat() - .5f) * MathHelper.ToRadians(5);
targetOffsetX = Main.rand.Next(20) - 10;
targetOffsetY = Main.rand.Next(10) - 5;
if (shittyModTime == ShakeLength)
{
targetRotation = 0;
targetOffsetX = 0;
targetOffsetY = 0;
}
}
float transX = Main.screenWidth / 2;
float transY = Main.screenHeight / 2;
float lerp = (float)(ShakeCount) / ShakeLength;
float rotation = MathHelper.Lerp(previousRotation, targetRotation, lerp);
float offsetX = MathHelper.Lerp(previousOffsetX, targetOffsetX, lerp);
float offsetY = MathHelper.Lerp(previousOffsetY, targetOffsetY, lerp);
shittyModTime--;
ShakeCount++;
return Transform
* Matrix.CreateTranslation(-transX, -transY, 0f)
* Matrix.CreateRotationZ(rotation)
* Matrix.CreateTranslation(transX, transY, 0f)
* Matrix.CreateTranslation(offsetX, offsetY, 0f);
}
}
return Transform;
}
}
}