Skip to content

Commit 5c591bf

Browse files
Merge pull request #834 from ProjectStarlight/relic-rework
Relic rework
2 parents f9c0627 + fc2bd66 commit 5c591bf

244 files changed

Lines changed: 2365 additions & 3116 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Content/Abilities/Faewhip/Whip.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using StarlightRiver.Core.Loaders;
2+
using StarlightRiver.Core.Systems;
23
using StarlightRiver.Core.Systems.DummyTileSystem;
34
using System;
45
using Terraria.GameInput;
@@ -272,7 +273,7 @@ public override void UpdateActive()
272273

273274
public override void DrawActiveEffects(SpriteBatch spriteBatch)
274275
{
275-
if (!Active || !CustomHooks.PlayerTarget.canUseTarget)
276+
if (!Active || !PlayerTargetSystem.canUseTarget)
276277
return;
277278

278279
if (trail is null || trail.IsDisposed)

Content/CustomHooks/Mechanics.PassiveLight.cs renamed to Content/Biomes/BiomePassiveLightingSystem.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using StarlightRiver.Content.Biomes;
2-
using StarlightRiver.Content.Bosses.SquidBoss;
3-
using StarlightRiver.Content.Events;
4-
using System.Collections.Generic;
1+
using StarlightRiver.Content.Bosses.SquidBoss;
52
using Terraria.ID;
63

7-
namespace StarlightRiver.Content.CustomHooks
4+
namespace StarlightRiver.Content.Biomes
85
{
9-
class PassiveLight : ModSystem
6+
//TODO: See if splitting this across the biome classes creates a performance concern
7+
class BiomePassiveLightingSystem : ModSystem
108
{
119
private static float mult = 0;
1210
private static bool vitricLava = false;
@@ -72,9 +70,9 @@ public override void PostUpdateEverything()
7270
float progress = 0.5f + yOff / (float)StarlightWorld.vitricBiome.Height * 0.7f;
7371
progress = MathHelper.Max(0.5f, progress);
7472

75-
preComputedVitricColors[yOff].X = (0.3f + (yOff > 70 ? ((yOff - 70) * 0.006f) : 0)) * progress * mult;
76-
preComputedVitricColors[yOff].Y = (0.48f + (yOff > 70 ? ((yOff - 70) * 0.0005f) : 0)) * progress * mult;
77-
preComputedVitricColors[yOff].Z = (0.65f - (yOff > 70 ? ((yOff - 70) * 0.005f) : 0)) * progress * mult;
73+
preComputedVitricColors[yOff].X = (0.3f + (yOff > 70 ? (yOff - 70) * 0.006f : 0)) * progress * mult;
74+
preComputedVitricColors[yOff].Y = (0.48f + (yOff > 70 ? (yOff - 70) * 0.0005f : 0)) * progress * mult;
75+
preComputedVitricColors[yOff].Z = (0.65f - (yOff > 70 ? (yOff - 70) * 0.005f : 0)) * progress * mult;
7876

7977
if (yOff > 90 && mult < 1)
8078
{
@@ -84,7 +82,7 @@ public override void PostUpdateEverything()
8482
}
8583
}
8684

87-
inSquidBiome = Main.LocalPlayer.InModBiome(ModContent.GetInstance<Biomes.PermafrostTempleBiome>());
85+
inSquidBiome = Main.LocalPlayer.InModBiome(ModContent.GetInstance<PermafrostTempleBiome>());
8886

8987
if (squidDomeRect == default)
9088
{

Content/Biomes/MoonstoneBiome.cs

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
//TODO ON WORLDGEN:
2-
//Wall updates
3-
//General cleanup of post-shape stuff
4-
1+
using StarlightRiver.Content.Items.Utility;
52
using StarlightRiver.Content.Tiles.Moonstone;
63
using StarlightRiver.Core.Loaders;
4+
using StarlightRiver.Core.Systems.CameraSystem;
75
using StarlightRiver.Core.Systems.ScreenTargetSystem;
86
using System;
7+
using System.Linq;
98
using System.Reflection;
9+
using Terraria.DataStructures;
1010
using Terraria.Graphics.Effects;
1111
using Terraria.Graphics.Shaders;
12+
using Terraria.ID;
13+
using Terraria.ModLoader.IO;
1214

1315
namespace StarlightRiver.Content.Biomes
1416
{
@@ -58,6 +60,9 @@ public class MoonstoneBiomeSystem : ModSystem
5860

5961
private bool drawingBGtarget = false;
6062

63+
public bool moonstoneForced;
64+
public bool meteorForced;
65+
6166
public ParticleSystem particleSystem;
6267
public ParticleSystem particleSystemMedium;
6368
public ParticleSystem particleSystemLarge;
@@ -88,6 +93,7 @@ public override void Load()
8893

8994
On_Main.DrawBackgroundBlackFill += DrawParticleTarget;
9095
On_Main.DrawSurfaceBG += DistortBG;
96+
On_WorldGen.meteor += ReplaceMeteorWithMoonstone;
9197
}
9298

9399
public override void PostUpdateEverything()
@@ -244,6 +250,111 @@ private void DrawParticleTarget(On_Main.orig_DrawBackgroundBlackFill orig, Main
244250
Main.spriteBatch.Begin(default, default, Main.DefaultSamplerState, default, Main.Rasterizer, default, Main.GameViewMatrix.TransformationMatrix);
245251
}
246252

253+
/// <summary>
254+
/// If the next meteor-like event to spawn should me a moonstone or not
255+
/// </summary>
256+
/// <returns></returns>
257+
private bool ShouldBeMoonstone()
258+
{
259+
if (moonstoneForced)
260+
{
261+
moonstoneForced = false;
262+
return true;
263+
}
264+
265+
if (meteorForced)
266+
{
267+
meteorForced = false;
268+
return false;
269+
}
270+
271+
return Main.rand.NextBool();
272+
}
273+
274+
private bool ReplaceMeteorWithMoonstone(On_WorldGen.orig_meteor orig, int i, int j, bool ignorePlayers)
275+
{
276+
CameraSystem.shake += 80;
277+
Terraria.Audio.SoundEngine.PlaySound(SoundID.DD2_ExplosiveTrapExplode);
278+
279+
if (ShouldBeMoonstone())
280+
{
281+
var target = new Point16();
282+
283+
while (!SafeToSpawnMoonstone(target))
284+
{
285+
int x = Main.rand.Next(Main.maxTilesX);
286+
287+
for (int y = 0; y < Main.maxTilesY; y++)
288+
{
289+
if (Framing.GetTileSafely(x, y).HasTile)
290+
{
291+
target = new Point16(x, y - 20);
292+
break;
293+
}
294+
}
295+
}
296+
297+
for (int x = -10; x < 10; x++)
298+
{
299+
for (int y = -30; y < 30; y++)
300+
{
301+
if (Math.Abs(x) < 10 - Math.Abs(y) / 3 + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
302+
WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType<Tiles.Moonstone.MoonstoneOre>(), true, true);
303+
}
304+
}
305+
306+
for (int x = -15; x < 15; x++)
307+
{
308+
for (int y = 0; y < 40; y++)
309+
{
310+
if (Math.Abs(x) < 10 - Math.Abs(y) / 3 + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
311+
WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType<Tiles.Moonstone.MoonstoneOre>(), true, true);
312+
}
313+
}
314+
315+
Terraria.Chat.ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral("A shard of the moon has landed!"), new Color(107, 233, 231));
316+
317+
if (Main.netMode == NetmodeID.Server)
318+
NetMessage.SendTileSquare(Main.myPlayer, target.X - 30, target.Y - 30, 60, 70, TileChangeType.None);
319+
320+
return true;
321+
}
322+
else
323+
{
324+
return orig(i, j, ignorePlayers);
325+
}
326+
}
327+
328+
/// <summary>
329+
/// Emulates teh various safety checks vanilla uses for if a meteor can be spawned
330+
/// </summary>
331+
/// <param name="test">The center point that a moonstone is attempting to be spawned at</param>
332+
/// <returns></returns>
333+
private bool SafeToSpawnMoonstone(Point16 test)
334+
{
335+
if (test == Point16.Zero)
336+
return false;
337+
338+
for (int x = -35; x < 35; x++)
339+
{
340+
for (int y = -35; y < 35; y++)
341+
{
342+
if (WorldGen.InWorld(test.X + x, test.Y + y))
343+
{
344+
Tile tile = Framing.GetTileSafely(test + new Point16(x, y));
345+
346+
if (tile.TileType == TileID.Containers || tile.TileType == TileID.Containers2)
347+
return false;
348+
}
349+
}
350+
}
351+
352+
if (Main.npc.Any(n => n.active && n.friendly && Vector2.Distance(n.Center, test.ToVector2() * 16) <= 35 * 16))
353+
return false;
354+
else
355+
return true;
356+
}
357+
247358
protected void UpdateMoonParticles(Particle particle)
248359
{
249360
float parallax = 0.6f;
@@ -265,5 +376,17 @@ protected void UpdateMoonParticles(Particle particle)
265376
particle.Color = color * opacity * fade;
266377
particle.Timer--;
267378
}
379+
380+
public override void SaveWorldData(TagCompound tag)
381+
{
382+
tag.Add("moonstoneForced", moonstoneForced);
383+
tag.Add("meteorForced", meteorForced);
384+
}
385+
386+
public override void LoadWorldData(TagCompound tag)
387+
{
388+
moonstoneForced = tag.GetBool("moonstoneForced");
389+
meteorForced = tag.GetBool("meteorForced");
390+
}
268391
}
269392
}

Content/Bosses/SquidBoss/NPCs.ArenaActor.cs

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
using MonoMod.Cil;
12
using StarlightRiver.Content.Biomes;
2-
using StarlightRiver.Content.CustomHooks;
3+
using StarlightRiver.Content.Configs;
34
using StarlightRiver.Content.Items.Permafrost;
5+
using StarlightRiver.Content.NPCs.BaseTypes;
46
using StarlightRiver.Content.Tiles.Permafrost;
57
using StarlightRiver.Core.Loaders;
8+
using StarlightRiver.Core.Systems;
69
using StarlightRiver.Core.Systems.CutawaySystem;
710
using StarlightRiver.Core.Systems.LightingSystem;
811
using System;
@@ -21,7 +24,7 @@ class ArenaActor : ModNPC
2124
private readonly List<NPC> platforms = new();
2225

2326
public int waterfallWidth = 0;
24-
ParticleSystem bubblesSystem = new(AssetDirectory.SquidBoss + "Bubble", UpdateBubblesBody);
27+
public static ParticleSystem bubblesSystem;
2528
private Vector2 domeOffset = new(0, -886);
2629

2730
private static VertexPositionColorTexture[] verticies;
@@ -41,6 +44,14 @@ class ArenaActor : ModNPC
4144

4245
private int WhitelistID => WallType<AuroraBrickWall>();
4346

47+
public override void Load()
48+
{
49+
bubblesSystem = new(AssetDirectory.SquidBoss + "Bubble", UpdateBubblesBody);
50+
51+
if (!Main.dedServ)
52+
IL_Main.DoDraw_WallsTilesNPCs += RenderArenaLayers;
53+
}
54+
4455
public override void SetStaticDefaults()
4556
{
4657
DisplayName.SetDefault("");
@@ -69,6 +80,14 @@ public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestia
6980
database.Entries.Remove(bestiaryEntry);
7081
}
7182

83+
private void RenderArenaLayers(ILContext il)
84+
{
85+
var c = new ILCursor(il);
86+
c.TryGotoNext(n => n.MatchLdfld<Main>("DrawCacheNPCsBehindNonSolidTiles"));
87+
88+
c.EmitDelegate(RenderArenaLayersInner);
89+
}
90+
7291
public override bool NeedSaving()
7392
{
7493
return true;
@@ -314,6 +333,49 @@ private void RegeneratePlatforms()
314333
platforms.Add(Main.npc[i]);
315334
}
316335

336+
public static void RenderArenaLayersInner()
337+
{
338+
if (!Main.LocalPlayer.InModBiome<PermafrostTempleBiome>())
339+
return;
340+
341+
Main.spriteBatch.End();
342+
Main.spriteBatch.Begin(default, default, SamplerState.PointClamp, default, Main.Rasterizer, default, Main.GameViewMatrix.TransformationMatrix);
343+
344+
NPC npc = latestActor?.NPC;
345+
346+
if (npc != null && npc.active)
347+
{
348+
if (BackgroundReflectionSystem.canUseTarget || !ModContent.GetInstance<GraphicsConfig>().ReflectionConfig.ReflectionsOn)
349+
(npc.ModNPC as ArenaActor).DrawBigWindow(Main.spriteBatch);
350+
351+
int boss = -1;
352+
var drawCache = new List<NPC>();
353+
354+
for (int k = 0; k < Main.maxNPCs; k++) //draw NPCs and find boss
355+
{
356+
NPC NPC2 = Main.npc[k];
357+
358+
if (NPC2.active && NPC2.ModNPC is IUnderwater)
359+
{
360+
if (NPC2.type == ModContent.NPCType<SquidBoss>())
361+
boss = k;
362+
else
363+
drawCache.Add(NPC2);
364+
}
365+
}
366+
367+
drawCache.ForEach(n => (n.ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 0));
368+
369+
foreach (Projectile proj in Main.projectile.Where(n => n.active && n.ModProjectile is IUnderwater)) //draw all Projectiles
370+
(proj.ModProjectile as IUnderwater).DrawUnderWater(Main.spriteBatch, 0);
371+
372+
if (boss != -1 && Main.npc[boss].ModNPC is IUnderwater)
373+
(Main.npc[boss].ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 0); //draw boss ontop if extant
374+
375+
drawCache.ForEach(n => (n.ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 1)); //draw layer for NPCs over bosses, used for the front part of tentacles
376+
}
377+
}
378+
317379
public void DrawWater(SpriteBatch spriteBatch)
318380
{
319381
Texture2D tex = Assets.Bosses.SquidBoss.CathedralWater.Value;
@@ -529,9 +591,9 @@ private void DrawReflections(SpriteBatch spriteBatch)
529591
Color tintColor = Color.White;
530592
tintColor.A = (byte)(NPC.AnyNPCs(NPCType<SquidBoss>()) ? 25 : 75);
531593

532-
ReflectionTarget.DrawReflection(spriteBatch, screenPos: NPC.Center - reflectionMap.Size() / 2 + new Vector2(0, -7 * 16 - 3) - Main.screenPosition, normalMap: reflectionMap, flatOffset: new Vector2(-0.0075f, 0.05f), offsetScale: 0.04f, tintColor: tintColor, restartSpriteBatch: false);
533-
ReflectionTarget.DrawReflection(spriteBatch, screenPos: NPC.Center - domeMap.Size() / 2 + domeOffset - Main.screenPosition, normalMap: domeMap, flatOffset: new Vector2(0f, 0.15f), offsetScale: 0.08f, tintColor: tintColor, restartSpriteBatch: false);
534-
ReflectionTarget.isDrawReflectablesThisFrame = true;
594+
BackgroundReflectionSystem.DrawReflection(spriteBatch, screenPos: NPC.Center - reflectionMap.Size() / 2 + new Vector2(0, -7 * 16 - 3) - Main.screenPosition, normalMap: reflectionMap, flatOffset: new Vector2(-0.0075f, 0.05f), offsetScale: 0.04f, tintColor: tintColor, restartSpriteBatch: false);
595+
BackgroundReflectionSystem.DrawReflection(spriteBatch, screenPos: NPC.Center - domeMap.Size() / 2 + domeOffset - Main.screenPosition, normalMap: domeMap, flatOffset: new Vector2(0f, 0.15f), offsetScale: 0.08f, tintColor: tintColor, restartSpriteBatch: false);
596+
BackgroundReflectionSystem.isDrawReflectablesThisFrame = true;
535597
}
536598

537599
private void SpawnPlatform(int x, int y, bool small = false)

0 commit comments

Comments
 (0)