Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Content/Abilities/Faewhip/Whip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StarlightRiver.Core.Loaders;
using StarlightRiver.Core.Systems.DummyTileSystem;
using StarlightRiver.Core.Systems;
using System;
using Terraria.GameInput;
using static Terraria.ModLoader.ModContent;
Expand Down Expand Up @@ -272,7 +273,7 @@ public override void UpdateActive()

public override void DrawActiveEffects(SpriteBatch spriteBatch)
{
if (!Active || !CustomHooks.PlayerTarget.canUseTarget)
if (!Active || !PlayerTargetSystem.canUseTarget)
return;

if (trail is null || trail.IsDisposed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using StarlightRiver.Content.Biomes;
using StarlightRiver.Content.Bosses.SquidBoss;
using StarlightRiver.Content.Events;
using System.Collections.Generic;
using StarlightRiver.Content.Bosses.SquidBoss;
using Terraria.ID;

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

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

if (yOff > 90 && mult < 1)
{
Expand All @@ -84,7 +82,7 @@ public override void PostUpdateEverything()
}
}

inSquidBiome = Main.LocalPlayer.InModBiome(ModContent.GetInstance<Biomes.PermafrostTempleBiome>());
inSquidBiome = Main.LocalPlayer.InModBiome(ModContent.GetInstance<PermafrostTempleBiome>());

if (squidDomeRect == default)
{
Expand Down
131 changes: 127 additions & 4 deletions Content/Biomes/MoonstoneBiome.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//TODO ON WORLDGEN:
//Wall updates
//General cleanup of post-shape stuff

using StarlightRiver.Content.Items.Utility;
using StarlightRiver.Content.Tiles.Moonstone;
using StarlightRiver.Core.Loaders;
using StarlightRiver.Core.Systems.CameraSystem;
using StarlightRiver.Core.Systems.ScreenTargetSystem;
using System;
using System.Linq;
using System.Reflection;
using Terraria.DataStructures;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader.IO;

namespace StarlightRiver.Content.Biomes
{
Expand Down Expand Up @@ -58,6 +60,9 @@ public class MoonstoneBiomeSystem : ModSystem

private bool drawingBGtarget = false;

public bool moonstoneForced;
public bool meteorForced;

public ParticleSystem particleSystem;
public ParticleSystem particleSystemMedium;
public ParticleSystem particleSystemLarge;
Expand Down Expand Up @@ -88,6 +93,7 @@ public override void Load()

On_Main.DrawBackgroundBlackFill += DrawParticleTarget;
On_Main.DrawSurfaceBG += DistortBG;
On_WorldGen.meteor += ReplaceMeteorWithMoonstone;
}

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

/// <summary>
/// If the next meteor-like event to spawn should me a moonstone or not
/// </summary>
/// <returns></returns>
private bool ShouldBeMoonstone()
{
if (moonstoneForced)
{
moonstoneForced = false;
return true;
}

if (meteorForced)
{
meteorForced = false;
return false;
}

return Main.rand.NextBool();
}

private bool ReplaceMeteorWithMoonstone(On_WorldGen.orig_meteor orig, int i, int j, bool ignorePlayers)
{
CameraSystem.shake += 80;
Terraria.Audio.SoundEngine.PlaySound(SoundID.DD2_ExplosiveTrapExplode);

if (ShouldBeMoonstone())
{
var target = new Point16();

while (!SafeToSpawnMoonstone(target))
{
int x = Main.rand.Next(Main.maxTilesX);

for (int y = 0; y < Main.maxTilesY; y++)
{
if (Framing.GetTileSafely(x, y).HasTile)
{
target = new Point16(x, y - 20);
break;
}
}
}

for (int x = -10; x < 10; x++)
{
for (int y = -30; y < 30; y++)
{
if (Math.Abs(x) < 10 - Math.Abs(y) / 3 + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType<Tiles.Moonstone.MoonstoneOre>(), true, true);
}
}

for (int x = -15; x < 15; x++)
{
for (int y = 0; y < 40; y++)
{
if (Math.Abs(x) < 10 - Math.Abs(y) / 3 + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType<Tiles.Moonstone.MoonstoneOre>(), true, true);
}
}

Terraria.Chat.ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral("A shard of the moon has landed!"), new Color(107, 233, 231));

if (Main.netMode == NetmodeID.Server)
NetMessage.SendTileSquare(Main.myPlayer, target.X - 30, target.Y - 30, 60, 70, TileChangeType.None);

return true;
}
else
{
return orig(i, j, ignorePlayers);
}
}

/// <summary>
/// Emulates teh various safety checks vanilla uses for if a meteor can be spawned
/// </summary>
/// <param name="test">The center point that a moonstone is attempting to be spawned at</param>
/// <returns></returns>
private bool SafeToSpawnMoonstone(Point16 test)
{
if (test == Point16.Zero)
return false;

for (int x = -35; x < 35; x++)
{
for (int y = -35; y < 35; y++)
{
if (WorldGen.InWorld(test.X + x, test.Y + y))
{
Tile tile = Framing.GetTileSafely(test + new Point16(x, y));

if (tile.TileType == TileID.Containers || tile.TileType == TileID.Containers2)
return false;
}
}
}

if (Main.npc.Any(n => n.active && n.friendly && Vector2.Distance(n.Center, test.ToVector2() * 16) <= 35 * 16))
return false;
else
return true;
}

protected void UpdateMoonParticles(Particle particle)
{
float parallax = 0.6f;
Expand All @@ -265,5 +376,17 @@ protected void UpdateMoonParticles(Particle particle)
particle.Color = color * opacity * fade;
particle.Timer--;
}

public override void SaveWorldData(TagCompound tag)
{
tag.Add("moonstoneForced", moonstoneForced);
tag.Add("meteorForced", meteorForced);
}

public override void LoadWorldData(TagCompound tag)
{
moonstoneForced = tag.GetBool("moonstoneForced");
meteorForced = tag.GetBool("meteorForced");
}
}
}
72 changes: 67 additions & 5 deletions Content/Bosses/SquidBoss/NPCs.ArenaActor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using MonoMod.Cil;
using StarlightRiver.Content.Biomes;
using StarlightRiver.Content.CustomHooks;
using StarlightRiver.Content.Configs;
using StarlightRiver.Content.Items.Permafrost;
using StarlightRiver.Content.NPCs.BaseTypes;
using StarlightRiver.Content.Tiles.Permafrost;
using StarlightRiver.Core.Loaders;
using StarlightRiver.Core.Systems;
using StarlightRiver.Core.Systems.CutawaySystem;
using StarlightRiver.Core.Systems.LightingSystem;
using System;
Expand All @@ -21,7 +24,7 @@ class ArenaActor : ModNPC
private readonly List<NPC> platforms = new();

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

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

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

public override void Load()
{
bubblesSystem = new(AssetDirectory.SquidBoss + "Bubble", UpdateBubblesBody);

if (!Main.dedServ)
IL_Main.DoDraw_WallsTilesNPCs += RenderArenaLayers;
}

public override void SetStaticDefaults()
{
DisplayName.SetDefault("");
Expand Down Expand Up @@ -69,6 +80,14 @@ public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestia
database.Entries.Remove(bestiaryEntry);
}

private void RenderArenaLayers(ILContext il)
{
var c = new ILCursor(il);
c.TryGotoNext(n => n.MatchLdfld<Main>("DrawCacheNPCsBehindNonSolidTiles"));

c.EmitDelegate(RenderArenaLayersInner);
}

public override bool NeedSaving()
{
return true;
Expand Down Expand Up @@ -314,6 +333,49 @@ private void RegeneratePlatforms()
platforms.Add(Main.npc[i]);
}

public static void RenderArenaLayersInner()
{
if (!Main.LocalPlayer.InModBiome<PermafrostTempleBiome>())
return;

Main.spriteBatch.End();
Main.spriteBatch.Begin(default, default, SamplerState.PointClamp, default, Main.Rasterizer, default, Main.GameViewMatrix.TransformationMatrix);

NPC npc = latestActor?.NPC;

if (npc != null && npc.active)
{
if (BackgroundReflectionSystem.canUseTarget || !ModContent.GetInstance<GraphicsConfig>().ReflectionConfig.ReflectionsOn)
(npc.ModNPC as ArenaActor).DrawBigWindow(Main.spriteBatch);

int boss = -1;
var drawCache = new List<NPC>();

for (int k = 0; k < Main.maxNPCs; k++) //draw NPCs and find boss
{
NPC NPC2 = Main.npc[k];

if (NPC2.active && NPC2.ModNPC is IUnderwater)
{
if (NPC2.type == ModContent.NPCType<SquidBoss>())
boss = k;
else
drawCache.Add(NPC2);
}
}

drawCache.ForEach(n => (n.ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 0));

foreach (Projectile proj in Main.projectile.Where(n => n.active && n.ModProjectile is IUnderwater)) //draw all Projectiles
(proj.ModProjectile as IUnderwater).DrawUnderWater(Main.spriteBatch, 0);

if (boss != -1 && Main.npc[boss].ModNPC is IUnderwater)
(Main.npc[boss].ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 0); //draw boss ontop if extant

drawCache.ForEach(n => (n.ModNPC as IUnderwater).DrawUnderWater(Main.spriteBatch, 1)); //draw layer for NPCs over bosses, used for the front part of tentacles
}
}

public void DrawWater(SpriteBatch spriteBatch)
{
Texture2D tex = Assets.Bosses.SquidBoss.CathedralWater.Value;
Expand Down Expand Up @@ -529,9 +591,9 @@ private void DrawReflections(SpriteBatch spriteBatch)
Color tintColor = Color.White;
tintColor.A = (byte)(NPC.AnyNPCs(NPCType<SquidBoss>()) ? 25 : 75);

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);
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);
ReflectionTarget.isDrawReflectablesThisFrame = true;
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);
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);
BackgroundReflectionSystem.isDrawReflectablesThisFrame = true;
}

private void SpawnPlatform(int x, int y, bool small = false)
Expand Down
Loading
Loading