<!-- SOLID-PLAYTIME · part 166 -->
if(this.trialIndex===null)return;let e=this.hero.position;for(let i of this.enemies){if(!i.alive)continue;let s=this.tempDirection.subVectors(e,i.group.position);if(s.length()>3.4)i.group.position.addScaledVector(s.normalize(),i.speed*t);else if(Math.sin(this.t*3+i.phase)>0.92)this.damageHero(0.08);let r=i.group.userData.rig;if(r?.leftArm&&r.rightArm&&r.leftLeg&&r.rightLeg)r.leftArm.rotation.x=Math.sin(this.t*5+i.phase)*0.55,r.rightArm.rotation.x=-r.leftArm.rotation.x,r.leftLeg.rotation.x=-r.leftArm.rotation.x*0.7,r.rightLeg.rotation.x=r.leftArm.rotation.x*0.7;i.group.lookAt(this.x,i.group.position.y,this.z)}if(!this.enemies.some((i)=>i.alive)&&this.boss?.alive){let i=this.tempDirection.subVectors(e,this.boss.group.position);if(i.length()>5.6)this.boss.group.position.addScaledVector(i.normalize(),this.boss.speed*t);else if(Math.sin(this.t*(2.3+this.boss.phase*0.35))>0.9)this.damageHero(0.11+this.boss.phase*0.025);this.boss.group.rotation.y+=t*(0.4+this.boss.phase*0.18)}if(this.hazardClock+=t,this.hazardClock>4.6-Math.min(2,this.trialIndex*0.25)){this.hazardClock=0;let i=this.trialIndex%3;if(i===0&&Math.hypot(this.x,this.z)>26)this.damageHero(0.18);if(i===1&&Math.abs(Math.sin(this.x*0.22)+Math.cos(this.z*0.2))<0.35)this.damageHero(0.15);if(i===2&&!this.grounded)this.damageHero(0.13);this.onEvent({type:"message",text:["THE EDGE BURNS","THE BLACK WATER RISES","THE VERSE BREAKS BENEATH YOU"][i]??"THE NIGHTMARE MOVES"})}}damageHero(t){if(this.health-=t,this.health<=0)this.health=1,this.radiance=Math.max(this.radiance,0.5),this.x=0,this.z=24,this.y=0.15,this.onEvent({type:"message",text:"THE LIGHT RETURNS"})}updateWorld(){if(this.trialIndex!==null)return;if(this.nearby=null,Math.hypot(this.x,this.z)<24)this.nearby={kind:"castle"};else if(Math.hypot(this.x,this.z-210)<20)this.nearby={kind:"haven"};else{let t=22;le.forEach((e,n)=>{let i=Math.hypot(this.x-e.x,this.z-e.z);if(i<t)t=i,this.nearby={kind:"palace",index:n}})}if(this.progress.cleared===le.length)for(let t=0;t<2;t+=1){let e=(Math.sin(this.t*0.7+t*2)+1)*0.5,n=this.palaceGroups[le.length-1];if(n)n.rotation.y=Math.sin(this.t*0.18)*0.06}}collectSecrets(){if(!this.vision)return;if(this.radiance=Math.max(0,this.radiance-0.0011666666666666668),this.radiance<=0.02)this.setVision(!1);this.shards.forEach((t,e)=>{if(t.visible&&t.position.distanceTo(this.hero.position)<4.2){let n=AM[e]??"STAR SHARD";if(t.visible=!1,!this.progress.shards.includes(n))this.progress.shards.push(n);if(!this.progress.chest.includes("STAR SHARD"))this.progress.chest.push("STAR SHARD");this.radiance=1,this.onEvent({type:"message",text:`${n} FOUND`}),this.syncProgress()}}),this.updateShardInstances()}stepSimulation(t){if(this.t+=t,this.journeyTime+=t,this.attackClock=Math.max(0,this.attackClock-t),this.updateMovement(t),this.updateEnemies(t),this.updateWorld(),this.collectSecrets(),!this.vision)this.radiance=Math.min(1,this.radiance+t*0.028);for(let e=this.sparks.length-1;e>=0;e-=1){let n=this.sparks[e];if(!n)continue;if(n.life-=t,n.life<=0)this.sparks.splice(e,1);else n.velocity.y-=14*t,n.position.addScaledVector(n.velocity,t)}if(!this.progress.proclamationHeard&&this.trialIndex===null&&this.journeyTime>=112&&this.hasMoved&&this.hasJumped&&this.distanceTravelled>=70)this.progress.proclamationHeard=!0,this.syncProgress(),this.onEvent({type:"proclamation"})}updateHeroTrail(){if(!this.heroTrail)return;if(Math.hypot(this.velX,this.velZ)>1.8&&Math.floor(this.t*30)%2===0){let e=this.heroTrailCursor%27,n=e*6,i=Math.sin(this.t*7+e)*0.9;this.heroTrailPositions[n]=this.x+i,this.heroTrailPositions[n+1]=this.y+2.2,this.heroTrailPositions[n+2]=this.z,this.heroTrailPositions[n+3]=this.x-this.velX*0.4+i*1.8,this.heroTrailPositions[n+4]=this.y+1.2+Math.sin(e)*0.5,this.heroTrailPositions[n+5]=this.z-this.velZ*0.4,this.heroTrailCursor+=1;let s=this.heroTrailGeometry.getAttribute("position");s.needsUpdate=!0,this.heroTrailGeometry.setDrawRange(0,Math.min(this.heroTrailCursor,27)*2)}}updateSparkBuffer(){let t=this.sparkGeometry.getAttribute("position"),e=this.sparkGeometry.getAttribute("color"),n=Math.min(this.sparks.length,this.sparkCapacity);for(let i=0;i<n;i+=1){let s=this.sparks[i];if(!s)continue;t.setXYZ(i,s.position.x,s.position.y,s.position.z);let a=Math.max(0.18,s.life/s.maxLife);e.setXYZ(i,s.color.r*a,s.color.g*a,s.color.b*a)}t.needsUpdate=!0,e.needsUpdate=!0,this.sparkGeometry.setDrawRange(0,n)}updateAdaptiveQuality(t){this.qualityFrames+=1;let e=t-this.qualityWindowStart;if(e<1500)return;let n=this.qualityFrames*1000/e;if(this.qualityFrames=0,this.qualityWindowStart=t,n<48){if(this.slowWindows+=1,this.fastWindows=0,this.slowWindows>=2&&this.qualityLevel<3)this.applyQuality(this.qualityLevel+1),this.slowWindows=0}else if(n>57){if(this.fastWindows+=1,this.slowWindows=0,this.fastWindows>=6&&this.qualityLevel>0)this.applyQuality(this.qualityLevel-1),this.fastWindows=0}else this.slowWindows=0,this.fastWindows=0}applyQuality(t){this.qualityLevel=t;let e=[1,0.82,0.72,0.68]