-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSpiritModSystem.cs
More file actions
446 lines (379 loc) · 14.9 KB
/
SpiritModSystem.cs
File metadata and controls
446 lines (379 loc) · 14.9 KB
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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpiritMod.GlobalClasses.Projectiles;
using SpiritMod.GlobalClasses.Tiles;
using SpiritMod.Items.Consumable;
using SpiritMod.Items.Sets.BismiteSet;
using SpiritMod.Items.Sets.BloodcourtSet;
using SpiritMod.Items.Sets.BowsMisc.GemBows.Emerald_Bow;
using SpiritMod.Items.Sets.BowsMisc.GemBows.Ruby_Bow;
using SpiritMod.Items.Sets.BowsMisc.GemBows.Sapphire_Bow;
using SpiritMod.Items.Sets.BowsMisc.GemBows.Topaz_Bow;
using SpiritMod.Items.Sets.BriarDrops;
using SpiritMod.Items.Sets.CoilSet;
using SpiritMod.Items.Sets.FrigidSet;
using SpiritMod.Items.Sets.HuskstalkSet;
using SpiritMod.Items.Sets.SlagSet;
using SpiritMod.Mechanics.AutoSell;
using SpiritMod.Mechanics.QuestSystem;
using SpiritMod.NPCs.AuroraStag;
using SpiritMod.NPCs.StarjinxEvent;
using SpiritMod.NPCs.Tides.Tide;
using SpiritMod.Particles;
using SpiritMod.Utilities;
using SpiritMod.Utilities.Journey;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.Graphics;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.UI;
namespace SpiritMod
{
internal class SpiritModSystem : ModSystem
{
public override void PostAddRecipes()
{
ModContent.GetInstance<TagGlobalTile>().Load(Mod);
SacrificeAutoloader.Load(Mod);
}
public override void AddRecipeGroups()
{
RecipeGroup woodGrp = RecipeGroup.recipeGroups[RecipeGroup.recipeGroupIDs["Wood"]];
woodGrp.ValidItems.Add(ModContent.ItemType<AncientBark>());
woodGrp.ValidItems.Add(ModContent.ItemType<Items.Placeable.Tiles.SpiritWoodItem>());
woodGrp.ValidItems.Add(ModContent.ItemType<Items.Sets.FloatingItems.Driftwood.DriftwoodTileItem>());
RecipeGroup butterflyGrp = RecipeGroup.recipeGroups[RecipeGroup.recipeGroupIDs["Butterflies"]];
butterflyGrp.ValidItems.Add(ModContent.ItemType<BriarmothItem>());
RecipeGroup BaseGroup(object GroupName, int[] Items)
{
string Name = "";
Name += GroupName switch
{
//modcontent items
int i => Lang.GetItemNameValue((int)GroupName),
//vanilla item ids
short s => Lang.GetItemNameValue((short)GroupName),
//custom group names
_ => GroupName.ToString(),
};
return new RecipeGroup(() => Language.GetTextValue("LegacyMisc.37") + " " + Name, Items);
}
RecipeGroup.RegisterGroup("SpiritMod:CopperBars", BaseGroup(ItemID.CopperBar, new int[]
{ ItemID.CopperBar, ItemID.TinBar }));
RecipeGroup.RegisterGroup("SpiritMod:SilverBars", BaseGroup(ItemID.SilverBar, new int[]
{ ItemID.SilverBar, ItemID.TungstenBar }));
RecipeGroup.RegisterGroup("SpiritMod:GoldBars", BaseGroup(ItemID.GoldBar, new int[]
{ ItemID.GoldBar, ItemID.PlatinumBar }));
RecipeGroup.RegisterGroup("SpiritMod:Tier3HMBar", BaseGroup(ItemID.AdamantiteBar, new int[]
{ ItemID.AdamantiteBar, ItemID.TitaniumBar }));
RecipeGroup.RegisterGroup("SpiritMod:PHMEvilMaterial", BaseGroup(ItemID.ShadowScale, new int[]
{ ItemID.ShadowScale, ItemID.TissueSample }));
RecipeGroup.RegisterGroup("SpiritMod:EvilMaterial", BaseGroup(ItemID.CursedFlame, new int[]
{ ItemID.CursedFlame, ItemID.Ichor }));
RecipeGroup.RegisterGroup("SpiritMod:EmeraldBows", BaseGroup("Emerald or Ruby Bow", new int[]
{ ModContent.ItemType<Emerald_Bow>(), ModContent.ItemType<Ruby_Bow>() }));
RecipeGroup.RegisterGroup("SpiritMod:TopazBows", BaseGroup("Sapphire or Topaz Bow", new int[]
{ ModContent.ItemType<Sapphire_Bow>(), ModContent.ItemType<Topaz_Bow>() }));
RecipeGroup.RegisterGroup("SpiritMod:AmethystStaffs", BaseGroup("Amethyst or Topaz Staff", new int[]
{ ItemID.AmethystStaff, ItemID.TopazStaff }));
RecipeGroup.RegisterGroup("SpiritMod:SapphireStaffs", BaseGroup("Sapphire or Emerald Staff", new int[]
{ ItemID.SapphireStaff, ItemID.EmeraldStaff }));
RecipeGroup.RegisterGroup("SpiritMod:RubyStaffs", BaseGroup("Ruby or Diamond Staff", new int[]
{ ItemID.RubyStaff, ItemID.DiamondStaff }));
}
public override void AddRecipes()
{
Recipe.Create(ItemID.IceTorch, 3)
.AddIngredient(ModContent.ItemType<FrigidFragment>())
.AddIngredient(ItemID.Torch, 3);
Recipe.Create(ItemID.PoisonDart, 25)
.AddIngredient(ModContent.ItemType<BismiteCrystal>());
Recipe.Create(ItemID.StinkPotion)
.AddTile(TileID.Bottles)
.AddIngredient(ModContent.ItemType<BismiteCrystal>())
.AddIngredient(ItemID.BottledWater)
.AddIngredient(ItemID.Waterleaf);
Recipe.Create(ItemID.WrathPotion)
.AddTile(TileID.Bottles).AddIngredient(ModContent.ItemType<DreamstrideEssence>(), 2)
.AddIngredient(ItemID.BottledWater)
.AddIngredient(ItemID.Deathweed);
Recipe.Create(ItemID.RagePotion)
.AddTile(TileID.Bottles)
.AddIngredient(ModContent.ItemType<DreamstrideEssence>(), 2)
.AddIngredient(ItemID.BottledWater)
.AddIngredient(ItemID.Deathweed);
Recipe.Create(ItemID.ThornsPotion)
.AddTile(TileID.Bottles).AddIngredient(ModContent.ItemType<EnchantedLeaf>())
.AddIngredient(ItemID.BottledWater)
.AddIngredient(ItemID.Deathweed)
.AddIngredient(ItemID.Waterleaf)
.AddIngredient(ItemID.Stinger)
.AddIngredient(ItemID.Cactus);
Recipe.Create(ItemID.Timer1Second)
.AddTile(TileID.Anvils)
.AddIngredient(ModContent.ItemType<TechDrive>())
.AddIngredient(ItemID.Wire);
Recipe.Create(ItemID.Timer3Second)
.AddTile(TileID.Anvils)
.AddIngredient(ModContent.ItemType<TechDrive>(), 3)
.AddIngredient(ItemID.Wire);
Recipe.Create(ItemID.Timer5Second)
.AddTile(TileID.Anvils)
.AddIngredient(ModContent.ItemType<TechDrive>(), 5)
.AddIngredient(ItemID.Wire);
Recipe.Create(ItemID.InfernoPotion)
.AddTile(TileID.Bottles)
.AddIngredient(ModContent.ItemType<CarvedRock>())
.AddIngredient(ItemID.BottledWater)
.AddIngredient(ItemID.Hellstone)
.AddIngredient(ItemID.SoulofNight);
Recipe.Create(ItemID.PoisonedKnife, 50)
.AddIngredient(ModContent.ItemType<BismiteCrystal>())
.AddIngredient(ItemID.ThrowingKnife, 50);
}
public override void ModifyLightingBrightness(ref float scale)
{
if (Main.LocalPlayer.ZoneBriar() && !Main.dayTime)
scale *= .96f;
}
public override void ModifySunLightColor(ref Color tileColor, ref Color backgroundColor)
{
if (ModContent.GetInstance<Biomes.BiomeTileCounts>().spiritCount > 0)
{
float strength = ModContent.GetInstance<Biomes.BiomeTileCounts>().spiritCount / 160f;
if (strength > MyWorld.spiritLight)
MyWorld.spiritLight += 0.01f;
if (strength < MyWorld.spiritLight)
MyWorld.spiritLight -= 0.01f;
}
else
MyWorld.spiritLight -= 0.02f;
if (MyWorld.spiritLight < 0f)
MyWorld.spiritLight = 0f;
else if (MyWorld.spiritLight > .9f)
MyWorld.spiritLight = .9f;
static int ColorAdjustment(int col, float light)
{
float val = 250f / 1.14f * light * (col / 255f);
if (val < 0)
val = 0;
return (int)val;
}
if (MyWorld.spiritLight > 0f)
{
int r = backgroundColor.R - ColorAdjustment(backgroundColor.R, MyWorld.spiritLight);
int g = backgroundColor.G - ColorAdjustment(backgroundColor.G, MyWorld.spiritLight);
int b = backgroundColor.B - ColorAdjustment(backgroundColor.B, MyWorld.spiritLight);
backgroundColor.R = (byte)r;
backgroundColor.G = (byte)g;
backgroundColor.B = (byte)b;
}
if (ModContent.GetInstance<Biomes.BiomeTileCounts>().asteroidCount > 0)
{
float strength = ModContent.GetInstance<Biomes.BiomeTileCounts>().asteroidCount / 160f;
if (strength > MyWorld.asteroidLight)
MyWorld.asteroidLight += 0.01f;
if (strength < MyWorld.asteroidLight)
MyWorld.asteroidLight -= 0.01f;
}
else
MyWorld.asteroidLight -= 0.02f;
if (MyWorld.asteroidLight < 0f)
MyWorld.asteroidLight = 0f;
else if (MyWorld.asteroidLight > 1f)
MyWorld.asteroidLight = 1f;
if (MyWorld.asteroidLight > 0f)
{
int r = backgroundColor.R - ColorAdjustment(backgroundColor.R, MyWorld.asteroidLight);
if (backgroundColor.R > r)
backgroundColor.R = (byte)r;
int g = backgroundColor.G - ColorAdjustment(backgroundColor.G, MyWorld.asteroidLight);
if (backgroundColor.G > g)
backgroundColor.G = (byte)g;
int b = backgroundColor.B - ColorAdjustment(backgroundColor.B, MyWorld.asteroidLight);
if (backgroundColor.B > b)
backgroundColor.B = (byte)b;
}
}
public override void ModifyTransformMatrix(ref SpriteViewMatrix Transform)
{
SpiritMod mod = Mod as SpiritMod;
if (!Main.gameMenu)
{
mod.screenshakeTimer++;
if (SpiritMod.tremorTime > 0 && mod.screenshakeTimer >= 20) // so it doesnt immediately decrease
SpiritMod.tremorTime -= 0.5f;
if (SpiritMod.tremorTime < 0)
SpiritMod.tremorTime = 0;
Main.screenPosition += new Vector2(SpiritMod.tremorTime * Main.rand.NextFloat(), SpiritMod.tremorTime * Main.rand.NextFloat());
}
else // dont shake on the menu
{
SpiritMod.tremorTime = 0;
mod.screenshakeTimer = 0;
}
SpiritMod.InvokeModifyTransform(Transform);
}
public override void UpdateUI(GameTime gameTime)
{
SpiritMod mod = Mod as SpiritMod;
mod.BookUserInterface?.Update(gameTime);
mod.SlotUserInterface?.Update(gameTime);
}
public override void PostUpdateEverything()
{
if (!Main.dedServ)
{
ParticleHandler.RunRandomSpawnAttempts();
ParticleHandler.UpdateAllParticles();
}
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int inventoryIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory"));
if (inventoryIndex != -1)
{
layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer(
"SpiritMod: BookUI",
delegate
{
SpiritMod.QuestHUD.Draw(Main.spriteBatch);
if (Main.playerInventory && QuestManager.QuestBookUnlocked)
{
Texture2D bookTexture = SpiritMod.Instance.Assets.Request<Texture2D>("UI/QuestUI/Textures/QuestBookInventoryButton", ReLogic.Content.AssetRequestMode.ImmediateLoad).Value;
Vector2 bookSize = new Vector2(50, 52);
QuestUtils.QuestInvLocation loc = ModContent.GetInstance<SpiritClientConfig>().QuestBookLocation;
Vector2 position = Vector2.Zero;
switch (loc)
{
case QuestUtils.QuestInvLocation.Minimap:
position = new Vector2(Main.screenWidth - Main.miniMapWidth - bookSize.X * 2.3f, Main.miniMapY + 4);
if (Main.screenWidth < 900)
position.Y -= 60;
break;
case QuestUtils.QuestInvLocation.Trashcan:
position = new Vector2(SpiritMod.AutoTrashEnabled ? 334 : 388, 258);
break;
case QuestUtils.QuestInvLocation.FarLeft:
position = new Vector2(20, Main.GameModeInfo.IsJourneyMode ? 310 : 258);
break;
}
Rectangle frame = new Rectangle(0, 0, 49, 52);
bool hover = false;
if (Main.MouseScreen.Between(position, position + bookSize))
{
hover = true;
frame.X = 50;
Main.LocalPlayer.mouseInterface = true;
if (Main.mouseLeft && Main.mouseLeftRelease)
{
Main.mouseLeftRelease = false;
QuestManager.SetBookState(SpiritMod.Instance._questBookToggle = !SpiritMod.Instance._questBookToggle);
}
}
if (hover != SpiritMod.Instance._questBookHover)
{
SpiritMod.Instance._questBookHover = hover;
SoundEngine.PlaySound(SoundID.MenuTick);
}
Main.spriteBatch.Draw(bookTexture, position, frame, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
SpiritMod.Instance.BookUserInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer(
"SpiritMod: SlotUI",
delegate
{
SpiritMod.Instance.SlotUserInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer(
"SpiritMod: SellUI",
delegate
{
if (ModContent.GetInstance<SpiritClientConfig>().QuickSell)
SpiritMod.DrawUpdateToggles();
if (AutoSellUI.visible)
{
SpiritMod.Instance.AutoSellUI_INTERFACE.Update(Main._drawInterfaceGameTime);
SpiritMod.Instance.AutoSellUI_SHORTCUT.Draw(Main.spriteBatch);
}
if (Mechanics.AutoSell.Sell_NoValue.Sell_NoValue.visible)
{
SpiritMod.Instance.SellNoValue_INTERFACE.Update(Main._drawInterfaceGameTime);
SpiritMod.Instance.SellNoValue_SHORTCUT.Draw(Main.spriteBatch);
}
if (Mechanics.AutoSell.Sell_Lock.Sell_Lock.visible)
{
SpiritMod.Instance.SellLock_INTERFACE.Update(Main._drawInterfaceGameTime);
SpiritMod.Instance.SellLock_SHORTCUT.Draw(Main.spriteBatch);
}
if (Mechanics.AutoSell.Sell_Weapons.Sell_Weapons.visible)
{
SpiritMod.Instance.SellWeapons_INTERFACE.Update(Main._drawInterfaceGameTime);
SpiritMod.Instance.SellWeapons_SHORTCUT.Draw(Main.spriteBatch);
}
return true;
},
InterfaceScaleType.UI)
);
layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer("SpiritMod: Starjinx UI", delegate
{
StarjinxUI.DrawStarjinxEventUI(Main.spriteBatch);
return true;
}, InterfaceScaleType.UI));
}
if (TideWorld.TheTide)
{
int index = layers.FindIndex(layer => layer is not null && layer.Name.Equals("Vanilla: Inventory"));
LegacyGameInterfaceLayer NewLayer = new LegacyGameInterfaceLayer("SpiritMod: Tide UI",
delegate
{
SpiritMod.Instance.DrawEventUI(Main.spriteBatch);
return true;
},
InterfaceScaleType.UI);
layers.Insert(index, NewLayer);
}
int mouseIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Item / NPC Head"));
if (mouseIndex != -1)
{
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer(
"Spirit: Stag Hover",
delegate
{
Item item = Main.mouseItem.IsAir ? Main.LocalPlayer.inventory[Main.LocalPlayer.selectedItem] : Main.mouseItem;
AuroraStag auroraStag = Main.LocalPlayer.GetModPlayer<MyPlayer>().hoveredStag;
if (item.type == ModContent.ItemType<Items.Consumable.Food.IceBerries>() && auroraStag != null && !auroraStag.NPC.immortal && auroraStag.TameAnimationTimer == 0)
{
Texture2D itemTexture = TextureAssets.Item[item.type].Value;
Vector2 itemPos = Main.MouseScreen + Vector2.UnitX * -(itemTexture.Width / 2 + 4);
Vector2 origin = new Vector2(itemTexture.Width / 2, 0);
Main.spriteBatch.Draw(itemTexture, itemPos, new Rectangle(0, 0, itemTexture.Width, itemTexture.Height / 3), Color.White, (float)Math.Sin(Main.GlobalTimeWrappedHourly * 1.5f) * 0.2f, origin, 1f, SpriteEffects.None, 0f);
}
return true;
},
InterfaceScaleType.UI)
);
}
}
public override void PreUpdateItems()
{
if (Main.netMode != NetmodeID.Server)
{
SpiritMod.TrailManager.UpdateTrails();
SpiritMod.primitives.UpdateTrails();
}
}
}
}