using System.Collections.Generic; using UnityEngine; namespace Auralis { // The crossing is a connected route of actual supports. Its first ride and // first wind landing teach safely; the known threats wait on a fixed bank. public sealed class RiverPlatformPassage:MonoBehaviour { public static RiverPlatformPassage I; public MovingLift Carrier{get;private set;} public BoxCollider2D WindLanding{get;private set;} public BoxCollider2D BattleBank{get;private set;} public BoxCollider2D CatchBank{get;private set;} public ArchiveWindField FirstWind{get;private set;} public ArchiveWindField LastWind{get;private set;} public ArchivePatrol CrossingRay{get;private set;} public RiverSeedSource WarnedSeed{get;private set;} public GardenTreasure Reward{get;private set;} public ClimbableLadder RecoveryLadder{get;private set;} public readonly List Banks=new(); public readonly List Fragile=new(); public Vector2 Start=>At(350,418); public Vector2 Summit=>At(1340,193); public Vector2 BattleLeft=>At(1126,115); public Vector2 BattleRight=>At(1256,115); public bool CombatReady=>Context; public bool Clear=>CrossingRay&&CrossingRay.Released; bool Context=>RiverWithoutBanksWorld.Area==1&&!DungeonRun.Inside&&!PocketRoom.Active; bool NearBattle { get { var g=GameSession.I;if(!g||!g.Player||!BattleBank)return false; var p=g.Player.transform.position;var b=BattleBank.bounds; return p.x>=b.min.x-1.3f&&p.x<=b.max.x+1.3f&&p.y>=b.max.y-.8f&&p.y<=b.max.y+4.0f; } } public string Guidance { get { var p=GameSession.I.Player.transform.position;float x=(p.x-70)/RiverWithoutBanksWorld.Scale+768; if(p.y=1320&&p.y1285&&p.yAt(1380,239).y+.1f)return "Letzte Fallströmung · rechts zur festen Ruhebank und zum Nesttor"; return "Rechts am ruhigen Nesttor geht es zur großen Windwende weiter"; } } RiverWithoutBanksWorld owner;Sprite middle,leftCap,rightCap; readonly List sprites=new();float settled;bool battleLanded,battleReady,answered; static Vector2 At(float x,float y)=>RiverWithoutBanksWorld.At(1,x,y); public static RiverPlatformPassage Create(RiverWithoutBanksWorld world) { var o=new GameObject("5-3 · gebaute fortlaufende Rochenquerung");o.transform.SetParent(world.RoomRoot(1),false); I=o.AddComponent();I.owner=world;I.Build();return I; } void Build() { // Reuse native wood, bindings and end pieces at one common scale. // Width is tiled, never obtained by stretching one painted room. var kit=Resources.Load("GameArt/LateRootArchitectureV1"); middle=Cut(kit,new Rect(320,1024-434,192,118),new Vector2(.5f,1)); leftCap=Cut(kit,new Rect(14,1024-434,72,118),new Vector2(.5f,1)); rightCap=Cut(kit,new Rect(1450,1024-434,72,118),new Vector2(.5f,1)); var moving=Bank("Fahrende Wurzelbank mit ruhigen Halten",554,418,92); Carrier=moving.gameObject.AddComponent();Carrier.Amplitude=0; Carrier.HorizontalTravel=(646-462)*RiverWithoutBanksWorld.Scale;Carrier.CycleSeconds=10; Carrier.ConfigureDrive();Carrier.RequestPower(true); Bank("Feste Ruhebank vor der ersten Spirale",762,418,98); FirstWind=Wind("river-passage-first-wind",748,811,422,235,4.8f); WindLanding=Bank("Breite erste Windlandung ohne Gegner",884,265,120); Fragile.Add(CrumblingPlatform.Attach(Bank("Erster rissiger Wurzeltritt",1013,224,78,true),1.35f,3.6f)); Fragile.Add(CrumblingPlatform.Attach(Bank("Zweiter rissiger Wurzeltritt",901.5f,180,83,true),1.35f,3.6f)); Fragile.Add(CrumblingPlatform.Attach(Bank("Dritter rissiger Wurzeltritt",1020,135,82,true),1.35f,3.6f)); BattleBank=Bank("Breite feste Bank für den bekannten Windrochen",1192.5f,115,185); CatchBank=Bank("Sichtbarer fester Fangweg unter den kurzen Tritten",805,592,750); Bank("Rücktritt zur ursprünglichen linken Fangbank",424,617,44); RecoveryLadder=Recovery("Feste Rückleiter zum Anfang der kurzen Spirale",749,592,418); // The final wind revisits the earned descending current. It really // carries the drop to a fixed landing rather than decorating a jump // that already reaches the next bank without using the air. LastWind=Wind("river-passage-last-wind",1286,1337,197,102,4.4f,true); Bank("Feste rechte Ruhebank nach der Fallströmung",1322,193,76); // Finish the descent before the old physical doorway. A step above // pixel 1440 would make a visible arrival miss the door's ground plane. Bank("Feste letzte Stufe zum ursprünglichen Nest",1385.5f,239,65); CrossingRay=ArchivePatrol.Create(transform,"river-ray-crossing",At(1126,85),At(1256,85),true); CrossingRay.Available=()=>CombatReady; owner.Rays.Add(CrossingRay); WarnedSeed=RiverSeedSource.Create(transform,At(1280,85),At(1110,85),"river-seed-rise",()=>CombatReady&&!Clear); Reward=GardenTreasure.Create("river-platform-ray-gift",At(1247,115),transform); Reward.FoundTitle="Der Dank des Windrochens!";Reward.Available=()=>Context&&Clear; Reward.gameObject.SetActive(Clear);answered=Clear; CampaignPopulation.Hearts(transform,"pop46-53-passage-first-landing",At(850,242),At(912,242),3,2); CampaignPopulation.Supply(transform,"pop46-53-passage-catch",At(792,567),SupplyKind.WindFeather,3); CampaignPopulation.Hearts(transform,"pop46-53-passage-ray-release",At(1140,92),At(1200,92),3,2,()=>Context&&Clear); CampaignPopulation.Hearts(transform,"pop46-53-passage-right-rest",At(1330,170),At(1376,170),3,2); QuestBeacon.Create(transform,FirstWind.Source+Vector2.up*.4f,.32f,ArtLibrary.Gold,()=>Context); QuestBeacon.Create(transform,At(1247,115)+Vector2.up*.95f,.37f,ArtLibrary.Gold,()=>Context&&Clear&&!Reward.Opened); QuestBeacon.Create(transform,LastWind.Source+Vector2.up*.3f,.32f,ArtLibrary.Teal,()=>Context&&Clear); ArchiveMemoryArt.Waymark(transform,At(901,270),"Rissige Tritte",()=>true); ArchiveMemoryArt.Waymark(transform,At(749,440),"Rückleiter",()=>true); RainFlow.Lamp("Warmes Licht auf der festen Rochenbank",At(1192,95),4.6f,ArtLibrary.Gold,.16f,transform); LastWind.SetFlow(Clear); } Sprite Cut(Texture2D texture,Rect rect,Vector2 pivot) {var s=Sprite.Create(texture,rect,pivot,100,0,SpriteMeshType.FullRect);sprites.Add(s);return s;} BoxCollider2D Bank(string title,float center,float y,float pixelWidth,bool cracked=false) { Vector2 at=At(center,y);float width=pixelWidth*RiverWithoutBanksWorld.Scale; var o=new GameObject(title);o.transform.SetParent(transform,false);o.transform.position=at;o.layer=6; var c=o.AddComponent();c.size=new Vector2(width,.18f);c.offset=Vector2.down*.09f; o.AddComponent();o.AddComponent().Material=GroundMaterial.Wood; o.AddComponent(); Banks.Add(c);owner.Banks["1-passage-"+Banks.Count]=c; RoomIntegratedPlatformArt.Dress(c,"river-ray",title.StartsWith("Fahr",System.StringComparison.Ordinal)); if(cracked) { // These small cracks belong to the bank and fall with its own art. for(int i=0;i<3;i++) { var crack=ArtLibrary.Sprite("Sichtbarer Riss im nachgebenden Holz",ArtLibrary.Solid, at+new Vector2((i-1)*.38f,-.24f-i*.055f),7,o.transform,false); crack.color=new Color(.23f,.16f,.105f,.93f);crack.transform.localScale=new Vector3(.034f,.23f,1); crack.transform.localRotation=Quaternion.Euler(0,0,i%2==0?28:-32); } } return c; } ArchiveWindField Wind(string id,float left,float right,float bottom,float top,float speed,bool down=false) { var a=At(left,bottom);var b=At(right,top); var w=ArchiveWindField.Create(transform,id,Rect.MinMaxRect(a.x,a.y,b.x,b.y),downwind:down,speed:speed); owner.Winds.Add(w);return w; } ClimbableLadder Recovery(string title,float x,float bottom,float top) { var o=new GameObject(title);o.transform.SetParent(transform,false);var l=o.AddComponent(); var foot=At(x,bottom);float head=At(x,top).y;l.Init(foot.x,foot.y,head);l.ExtendTo(head);owner.Ladders.Add(l);return l; } bool SettledOnBattle(GameSession g) { var p=g.Player;if(!p.Grounded||p.Climbing||p.Rescuing||p.EnteringDoor)return false; var b=BattleBank.bounds;var foot=p.transform.position; return foot.x>=b.min.x+.25f&&foot.x<=b.max.x-.25f&&Mathf.Abs(foot.y-b.max.y)<.10f; } void Update() { var g=GameSession.I;if(!g||!g.Playing||!g.Player||!Context)return; if(!RiverWithoutBanksWorld.CrossingDoorReady) { Vector2 door=At(1440,286),p=g.Player.transform.position; if(Mathf.Abs(p.x-door.x)<2.2f&&Mathf.Abs(p.y-door.y)<.8f) g.Hud.SetPrompt("←", "Nesttor gebunden · links oben die zwei Rochenbindungen lösen"); } if(!battleReady) { if(SettledOnBattle(g))battleLanded=true; // A real contact enables the encounter immediately. Walking or // jumping on this bank never adds a second activation delay. if(battleLanded&&NearBattle)settled+=Time.deltaTime; else{settled=0;battleLanded=false;} if(settled>0)battleReady=true; } LastWind.SetFlow(Clear); if(!answered&&Clear) { answered=true;Reward.gameObject.SetActive(true); AudioDirector.I?.Play("StarGlass",Reward.transform.position,.34f,this); WorldEffects.I?.Burst(Reward.transform.position+Vector3.up*.55f,ArtLibrary.Gold,12,.85f); g.Hud.Toast("Der Windrochen lässt eine Schatzkiste zurück. Die rechte Fallströmung führt zum Nesttor.",4.5f); } } // Include the actual rising path in anticipation. Old painted-nest edges // alone would aim below the three authored stepping stones. public Vector2 IncomingBank(Vector2 feet,int direction) { float best=float.PositiveInfinity;Vector2 next=feet; foreach(var bank in Banks) { if(!bank||!bank.enabled||bank==CatchBank||bank.GetComponent())continue; var b=bank.bounds;if(b.max.y7.5f||dy>5.8f)continue; float score=dx+Mathf.Abs(dy)*.25f;if(score>=best)continue; best=score;next=new Vector2(b.center.x,b.max.y); } return next; } void OnDisable(){settled=0;battleLanded=false;AudioDirector.I?.StopOwned(this);} void OnDestroy(){if(I==this)I=null;foreach(var s in sprites)if(s)Destroy(s);} } }