Connect Guild and Smuggler Navigator routes to JARVIS

This commit is contained in:
unimatrixgit 2026-11-29 23:36:14 +01:00
commit 4da7c00ffe

View file

@ -1,5 +1,8 @@
package com.dunerealms.gui;
import com.google.gson.JsonObject;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
final class GuildRoutes {
record Route(String house,String world,String name,String sigil){}
static final List<Route> ALL=List.of(
@ -12,4 +15,20 @@ final class GuildRoutes {
static Route home(String house){return ALL.stream().filter(r->r.house().equals(house)).findFirst().orElse(null);}
static boolean allowed(String house,String world){Route route=home(house);return route!=null&&route.world().equals(world);}
static boolean candidate(String house,String world){return home(house)!=null&&(allowed(house,world)||"arrakis".equals(world));}
record Offer(String server,String name,boolean available,String reason,long fareMinor){}
static Map<String,Offer> catalog(JsonObject quote){
Map<String,Offer> result=new LinkedHashMap<>();
if(!quote.has("routes")||!quote.get("routes").isJsonArray())return result;
for(var value:quote.getAsJsonArray("routes")){
if(!value.isJsonObject())continue;
var row=value.getAsJsonObject();
if(!row.has("server")||!row.has("name")||!row.has("available")||!row.has("fareMinor"))continue;
String server=row.get("server").getAsString();
if(ALL.stream().noneMatch(route->route.world().equals(server)))continue;
String reason=row.has("reason")&&!row.get("reason").isJsonNull()?row.get("reason").getAsString():"Passage unavailable";
result.putIfAbsent(server,new Offer(server,row.get("name").getAsString(),row.get("available").getAsBoolean(),reason,row.get("fareMinor").getAsLong()));
}
return result;
}
}