1+ package archipelago ;
2+
3+ import archipelago .PacketTypes .NetworkItem ;
4+
5+ class APNote extends objects. Note {
6+ var APItem : NetworkItem ;
7+ public var APItemLocation : Null <Int > = null ;
8+ public var index : Int = 0 ;
9+
10+ public function new (note : objects. Note , location : Int , ? item : NetworkItem = null ) {
11+ super (note .strumTime , note .noteData , note .prevNote , note .isSustainNote );
12+ this .ignoreNote = note .ignoreNote ;
13+ this .noteType = note .noteType ;
14+ this .isCheck = true ;
15+ // Set a unique RGBShader color for APNotes
16+ this .rgbShader .r = 0x3380CC ;
17+ this .rgbShader .g = 0x3380CC ;
18+ this .rgbShader .b = 0x3380CC ;
19+ // Copy the properties from the original note to this new note, via reflection
20+ trace (" Copying properties from original note to new note..." );
21+ for (field in Reflect .fields (note )) {
22+ if (field != " ignoreNote" && field != " noteType" && field != " strumTime" && field != " noteData" && field != " prevNote" && field != " isSustainNote" ) {
23+ try {
24+ Reflect .setField (this , field , Reflect .field (note , field ));
25+ } catch (e : Dynamic ) {
26+ trace (' Failed to copy field: ' + field + ' with error: ' + e );
27+ }
28+ }
29+ }
30+ // note.destroy();
31+ trace (" Properties copied. Destroying original note..." );
32+
33+ APItem = item ;
34+ APItemLocation = location ;
35+
36+ this .checkInfo = {note : this , loc : location }; // Set the checkInfo for the new note
37+ }
38+
39+ // Replace notes with a certain amount of locations.
40+ public static function replaceNotes (notes : Array <objects. Note >, locations : Array <Int >, ? ignoreNonEmptyNoteType : Bool = true ) { // This needs to stay, since this will be useful for regular engines.
41+ var newNotes : Array <APNote > = [];
42+ var randomIndices : Array <Int > = [];
43+ var isAprilFools : Bool = yutautil. AprilFools .allowAF ;
44+
45+ // Generate a list of random unique indices
46+ while (randomIndices .length < Math .min (locations .length , notes .length )) {
47+ var randomIndex = Std .random (notes .length );
48+ var note = notes [randomIndex ];
49+
50+ var shouldIgnore : Bool = (note .ignoreNote || note .hitCausesMiss || note .isSustainNote || (ignoreNonEmptyNoteType && ! note .noteType .isEmpty ()) || ! note .mustPress );
51+
52+ if (isAprilFools ) {
53+ // On April Fools, allow sustainNotes and rarely ignoreNotes or non-empty noteTypes
54+ if (note .isSustainNote && Std .random (100 ) < 20 ) shouldIgnore = false ; // 20% chance to allow sustainNotes
55+ if (note .ignoreNote && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow ignoreNotes
56+ if (! note .noteType .isEmpty () && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow non-empty noteTypes
57+ }
58+
59+ if (shouldIgnore || randomIndices .contains (randomIndex )) continue ; // Skip if the note should be ignored or already selected
60+
61+ randomIndices .push (randomIndex );
62+ }
63+
64+ for (i in 0 ... randomIndices .length ) {
65+ var note : objects. Note = notes [randomIndices [i ]];
66+ var location : Int = locations [i % locations .length ];
67+ var apNote = new APNote (note , location , null ); // Create a new APNote with the location
68+ // apNote.noteIndex = note.noteIndex;
69+ newNotes .push (apNote );
70+
71+ // Replace the original note with the APNote
72+ notes [randomIndices [i ]].rgbShader .r = 0x3380CC ;
73+ notes [randomIndices [i ]].rgbShader .g = 0x3380CC ;
74+ notes [randomIndices [i ]].rgbShader .b = 0x3380CC ;
75+ notes [randomIndices [i ]] = apNote ;
76+
77+ apNote .index = i ; // Set the index for the new note
78+
79+ // Set the checkInfo for the new note
80+ apNote .checkInfo = {note : apNote , loc : location };
81+ }
82+ return newNotes ; // Return the new notes
83+ }
84+
85+ var curNote : objects. Note ;
86+ public static function replaceInQueue (notes : Array <Array <objects. Note . PreloadedChartNote >>, locations : Array <Int >, ? ignoreNonEmptyNoteType : Bool = true ) {
87+ var newNotes : Array <APNote > = [];
88+ var flatNotes : Array <{lane : Int , index : Int , note : objects. Note . PreloadedChartNote }> = [];
89+ var isAprilFools : Bool = yutautil. AprilFools .allowAF ;
90+
91+ // Flatten the notes array into a single array with lane and index information
92+ for (lane in 0 ... notes .length ) {
93+ for (index in 0 ... notes [lane ].length ) {
94+ var note = notes [lane ][index ];
95+ flatNotes .push ({lane : lane , index : index , note : note });
96+ }
97+ }
98+
99+ var randomIndices : Array <Int > = [];
100+ var availableNotes : Array <Int > = [];
101+
102+ if (flatNotes .length == 0 ) {
103+ trace (" No notes available to replace." );
104+ trace (archipelago. APEntryState .apGame .info ().LocationChecks (locations ));
105+ trace (" Couldn't place any notes, so we're just sending the checks." );
106+ return newNotes ; // Return an empty array if there are no notes
107+ }
108+
109+ if (flatNotes .length < locations .length ) {
110+ // Take the difference and pop some locations out of the array.
111+ trace (" Not enough notes available to replace. Reducing locations." );
112+ for (i in 0 ... locations .length ) {
113+ if (locations [i ] >= flatNotes .length ) {
114+ locations .splice (i , 1 ); // Remove the location if it exceeds the available notes
115+ // i--;
116+ }
117+ }
118+ }
119+
120+ // Check for available notes based on the ignoreNonEmptyNoteType rule
121+ for (i in 0 ... flatNotes .length ) {
122+ var note = flatNotes [i ].note ;
123+ var shouldIgnore : Bool = (note .ignoreNote || note .hitCausesMiss || note .isSustainNote || (ignoreNonEmptyNoteType && ! note .noteType .isEmpty ()) || ! note .mustPress );
124+
125+ if (isAprilFools ) {
126+ // On April Fools, allow sustainNotes and rarely ignoreNotes or non-empty noteTypes
127+ if (note .isSustainNote && Std .random (100 ) < 20 ) shouldIgnore = false ; // 20% chance to allow sustainNotes
128+ if (note .ignoreNote && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow ignoreNotes
129+ if (! note .noteType .isEmpty () && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow non-empty noteTypes
130+ }
131+
132+ if (! shouldIgnore ) {
133+ availableNotes .push (i );
134+ }
135+ }
136+
137+ // If there aren't enough available notes, make an exception for the ignoreNonEmptyNoteType rule
138+ if (availableNotes .length < locations .length ) {
139+ trace (" Not enough available notes, ignoring non-empty note type rule." );
140+ ignoreNonEmptyNoteType = false ;
141+ }
142+
143+ // Generate a list of random unique indices across all notes
144+ while (randomIndices .length < Math .min (locations .length , flatNotes .length )) {
145+ var randomIndex = Std .random (flatNotes .length );
146+ var noteData = flatNotes [randomIndex ];
147+ var note = noteData .note ;
148+
149+ var shouldIgnore : Bool = (note .ignoreNote || note .hitCausesMiss || note .isSustainNote || (ignoreNonEmptyNoteType && ! note .noteType .isEmpty ()) || ! note .mustPress );
150+
151+ if (isAprilFools ) {
152+ // On April Fools, allow sustainNotes and rarely ignoreNotes or non-empty noteTypes
153+ if (note .isSustainNote && Std .random (100 ) < 20 ) shouldIgnore = false ; // 20% chance to allow sustainNotes
154+ if (note .ignoreNote && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow ignoreNotes
155+ if (! note .noteType .isEmpty () && Std .random (100 ) < 10 ) shouldIgnore = false ; // 10% chance to allow non-empty noteTypes
156+ }
157+
158+ if (shouldIgnore || randomIndices .contains (randomIndex )) continue ; // Skip if the note should be ignored or already selected
159+
160+ randomIndices .push (randomIndex );
161+ }
162+
163+ for (i in 0 ... randomIndices .length ) {
164+ var randomIndex = randomIndices [i ];
165+ var noteData = flatNotes [randomIndex ];
166+ var lane = noteData .lane ;
167+ var index = noteData .index ;
168+ var location : Int = locations [i % locations .length ];
169+
170+ // Replace the original note with the APNote
171+ /* @:privateAccess{
172+ notes[lane][index].isCheck = true;
173+ notes[lane][index].checkInfo = {note: notes[lane][index], loc: location};
174+ notes[lane][index].texture = ''; // For consistancy sake
175+ notes[lane][index].rgbShader.enabled = true; // because mods sometimes turn this off for their noteskins
176+ notes[lane][index].rgbShader.r = 0xFF313131;
177+ notes[lane][index].rgbShader.g = 0xFFFFFFFF;
178+ notes[lane][index].rgbShader.b = 0xFFB4B4B4;
179+ }*/
180+ }
181+ trace (" Successfully generated [" + randomIndices .length + " ] APNotes." );
182+
183+ // Recolor other notes with the same note indexes as the new notes.
184+ /* for (noteData in flatNotes)
185+ for (note in newNotes)
186+ if (noteData.note.noteIndex == note.noteIndex) {
187+ notes[noteData.lane][noteData.index].rgbShader.r = 0xFF313131; // Reset the color of the original note
188+ notes[noteData.lane][noteData.index].rgbShader.g = 0xFFFFFFFF;
189+ notes[noteData.lane][noteData.index].rgbShader.b = 0xFFB4B4B4;
190+ }*/
191+
192+ return newNotes ; // Return the new notes
193+ }
194+ }
0 commit comments