1+ using MonoMod . Cil ;
12using StarlightRiver . Content . Biomes ;
2- using StarlightRiver . Content . CustomHooks ;
3+ using StarlightRiver . Content . Configs ;
34using StarlightRiver . Content . Items . Permafrost ;
5+ using StarlightRiver . Content . NPCs . BaseTypes ;
46using StarlightRiver . Content . Tiles . Permafrost ;
57using StarlightRiver . Core . Loaders ;
8+ using StarlightRiver . Core . Systems ;
69using StarlightRiver . Core . Systems . CutawaySystem ;
710using StarlightRiver . Core . Systems . LightingSystem ;
811using 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