Skip to content

Commit 2c6e5f1

Browse files
committed
Working on Hints.
1 parent efd1d44 commit 2c6e5f1

File tree

6 files changed

+111
-13
lines changed

6 files changed

+111
-13
lines changed

source/archipelago/APGameState.hx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,52 @@ class APGameState {
191191
CountdownPopup.instance.updateCountdown(countdown);
192192
}
193193
});
194+
195+
_ap.onRetrieved.add(function(retrievedPacket:haxe.DynamicAccess<Dynamic>) {
196+
trace("Retrieved packet: " + retrievedPacket);
197+
for (key in retrievedPacket.keys()) {
198+
var value = retrievedPacket.get(key);
199+
if (key.indexOf("_read_hints_") != -1) {
200+
var hint:Hint = cast value;
201+
if (!hint.found) {
202+
// Grab the location and remove the -# from it.
203+
var location = hint.location;
204+
var locationName = _ap.get_location_name(location);
205+
var dashIndex = locationName.indexOf("-");
206+
if (dashIndex != -1) {
207+
locationName = locationName.substring(0, dashIndex);
208+
}
209+
210+
var findingPlayerName = _ap.get_player_alias(hint.finding_player);
211+
var receivingPlayerName = _ap.get_player_alias(hint.receiving_player);
212+
var itemName = _ap.get_item_name(hint.item, _ap.get_player_game(hint.finding_player));
213+
214+
215+
var message:String;
216+
if (hint.receiving_player == _ap.slotnr) {
217+
message = "This song is found in " + findingPlayerName + "'s World at " + locationName;
218+
} else if (hint.finding_player == _ap.slotnr) {
219+
message = "This song has " + receivingPlayerName + "'s item: " + itemName;
220+
} else {
221+
message = "Hint: " + receivingPlayerName + " will find " + itemName + " in " + findingPlayerName + "'s World at " + locationName;
222+
}
223+
224+
if (FreeplayState.hintTable.exists(locationName)) {
225+
FreeplayState.hintTable.set(locationName, FreeplayState.hintTable.get(locationName) + "\n" + message);
226+
} else {
227+
FreeplayState.hintTable.set(locationName, message);
228+
}
229+
}
230+
}
231+
}
232+
for (hint in FreeplayState.hintTable.keys()) {
233+
var message = FreeplayState.hintTable.get(hint);
234+
trace("Hint: " + hint + " - " + message);
235+
var hintSong = getSongAndMod(hint);
236+
FreeplayState.curHinted.set(hintSong.song, hintSong.mod);
237+
}
238+
});
239+
194240
// _ap.onConnect.add(function() {
195241
// _ap.clientStatus = ClientStatus.CONNECTED;
196242
// });
@@ -328,6 +374,32 @@ class APGameState {
328374
}
329375
}
330376

377+
public function getSongAndMod(songName:String):{ song:String, ?mod:String }
378+
{
379+
var input = songName;
380+
var modName = "";
381+
var firstParenIndex = songName.indexOf("(");
382+
var endParenIndex = songName.lastIndexOf(")");
383+
while (firstParenIndex != -1) {
384+
if (endParenIndex != -1) {
385+
modName = songName.substring(firstParenIndex + 1, endParenIndex);
386+
if (isModName(modName)) {
387+
songName = songName.substring(0, firstParenIndex).trim();
388+
break;
389+
} else {
390+
firstParenIndex = songName.indexOf("(", firstParenIndex + 1);
391+
}
392+
} else {
393+
break;
394+
}
395+
}
396+
if (firstParenIndex == -1 || !isModName(modName)) {
397+
modName = "";
398+
songName = input;
399+
}
400+
return modName != null && modName != "" ? { song: songName, mod: modName } : { song: songName };
401+
}
402+
331403
public function findSpecialItems():Map<String, Int> {
332404
var specialItems:Map<String, Int> = new Map<String, Int>();
333405
var apInfo = info();
@@ -444,7 +516,6 @@ class APGameState {
444516
// if (missing) {
445517
// states.FreeplayState.curMissing.set(itemName, modName);
446518
// }
447-
if (states.FreeplayState.instance != null) states.FreeplayState.instance.reloadSongs(true);
448519
for (song in states.FreeplayState.curUnlocked.keys())
449520
{
450521
var parts = song.split("||");
@@ -503,6 +574,7 @@ class APGameState {
503574
}
504575
isSync = false;
505576
info().casualSync = false;
577+
if (states.FreeplayState.instance != null) states.FreeplayState.instance.reloadSongs(true);
506578
}
507579

508580
// A bandage fix till we have enough brainpower to fix this properly

source/archipelago/APPlayState.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class APPlayState extends PlayState {
148148
activeItems[2] = 0;
149149
FlxG.save.flush();
150150
}
151+
PlayState.chartingMode = false;
151152
}
152153

153154
if (ogScroll != ClientPrefs.data.downScroll)

source/archipelago/Client.hx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,8 @@ class Client {
15011501
_hOnBounced(data);
15021502
// trace(data);
15031503

1504-
// BUG: "Cannot access non-static abstract field statically" on extracting "keys"
1505-
// case Retrieved(keys):
1506-
// _hOnRetrieved(keys);
1504+
case Retrieved(keys):
1505+
_hOnRetrieved(keys);
15071506

15081507
case SetReply(key, value, original_value):
15091508
_hOnSetReply(key, value, original_value);

source/states/FreeplayState.hx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class FreeplayState extends MusicBeatState
104104

105105
public static var curUnlocked:Map<String, String> = new Map<String, String>();
106106
public static var curMissing:Map<String, String> = new Map<String, String>();
107+
public static var curHinted:Map<String, String> = new Map<String, String>();
108+
public static var hintTable:Map<String, String> = new Map<String, String>();
107109
public static var trueMissing:Array<String> = [];
108110
public static var unplayedList:Array<String> = [];
109111
public static var doChange:Bool = false;
@@ -135,6 +137,10 @@ class FreeplayState extends MusicBeatState
135137
Cursor.cursorMode = Default;
136138
instance = this; // For Archipelago
137139

140+
var checker = archipelago.APGameState.instance?.info();
141+
checker.poll();
142+
checker.Get(['_read_hints_${checker.team}_${checker.slotnr}']);
143+
138144
if (APEntryState.apGame != null && APEntryState.apGame.info() != null) {
139145
APEntryState.apGame.info().Sync();
140146
APEntryState.gonnaRunSync = false;
@@ -522,6 +528,24 @@ class FreeplayState extends MusicBeatState
522528
addSong(song[0], i, song[1], FlxColor.fromRGB(colors[0], colors[1], colors[2]));
523529
}
524530
}
531+
else if (CategoryState.loadWeekForce == 'hinted')
532+
{
533+
534+
535+
var songNameThing:String = song[0];
536+
var modName:String = leWeek.folder;
537+
var locationId:Int = APEntryState.apGame.info().get_location_id(songNameThing + (modName != "" ? " (" + modName + ")" : "") + "-0");
538+
var isMissing:Bool = APEntryState.apGame.isLocationMissing(APEntryState.apGame.info().get_location_name(locationId));
539+
for (songName in curHinted.keys())
540+
{
541+
if (((songNameThing.trim().toLowerCase().replace('-', ' ') == songName.trim().toLowerCase().replace('-', ' ')) && leWeek.folder == curHinted.get(songName)) && !isMissing)
542+
addSong(song[0], i, song[1], FlxColor.fromRGB(colors[0], colors[1], colors[2]));
543+
}
544+
545+
}
546+
547+
548+
525549
else if (categoryWhaat.toLowerCase() == CategoryState.loadWeekForce || (CategoryState.loadWeekForce == "mods" && categoryWhaat == null) || CategoryState.loadWeekForce == "all")
526550
{
527551
if (APEntryState.inArchipelagoMode)
@@ -737,6 +761,8 @@ class FreeplayState extends MusicBeatState
737761
var holdTime:Float = 0;
738762
var stopMusicPlay:Bool = false;
739763

764+
// public static function addHint(song:String, item)
765+
740766
public static function forceUnlockCheck(songName:String, modName:String):Void {
741767
var locationId = songName;
742768
trace(modName);
@@ -808,13 +834,13 @@ class FreeplayState extends MusicBeatState
808834

809835
for (locationIdInt in locationIdInts)
810836
{
811-
if (locationIdInt != 0 && APEntryState.apGame.info().get_location_name(locationIdInt).trim().toLowerCase().replace(" ", "-") == APEntryState.victorySong.trim().toLowerCase().replace(" ", "-"))
812-
{
813-
archipelago.ArchPopup.startPopupCustom("You've completed your goal!", "You win!", "archipelago", function() {
814-
FlxG.sound.playMusic(Paths.sound('secret'));
815-
});
816-
APEntryState.apGame.info().set_goal();
817-
}
837+
if (locationIdInt != 0 && states.FreeplayState.isVictorySong(songName, modName))
838+
{
839+
archipelago.ArchPopup.startPopupCustom("You've completed your goal!", "You win!", "archipelago", function() {
840+
FlxG.sound.playMusic(Paths.sound('secret'));
841+
});
842+
APEntryState.apGame.info().set_goal();
843+
}
818844
}
819845
if (instance != null)
820846
instance.reloadSongs(true);

source/states/editors/ChartingState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ class ChartingState extends MusicBeatState implements PsychUIEventHandler.PsychU
10311031
{
10321032
var doCut:Bool = false;
10331033
var canContinue:Bool = true;
1034-
if(FlxG.keys.justPressed.ENTER)
1034+
if(FlxG.keys.justPressed.ENTER || archipelago.APEntryState.inArchipelagoMode)
10351035
{
10361036
goToPlayState();
10371037
return;

source/substates/PauseSubState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PauseSubState extends MusicBeatSubstate
5151
menuItems = menuItemsOG;
5252

5353
if (archipelago.APEntryState.inArchipelagoMode)
54-
menuItems.push('Skip Check');
54+
menuItemsOG.insert(3, 'Skip Check');
5555

5656
for (i in 0...Difficulty.list.length) {
5757
var diff:String = Difficulty.getString(i);

0 commit comments

Comments
 (0)