diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java index 5a1b83c2..7760b6cc 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java @@ -161,6 +161,7 @@ final class QuestMenus implements Listener { private void smugglerMenu(Player p,JsonObject data,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","smuggler_quote");smugglerRequest(p,input,quote->{var screen=panel(p,"NPC turn-in · "+role.name());screen.description="A personal smuggler passage is distinct from sanctioned Guild travel. Unsanctioned arrival may carry the existing in-game bounty.";roleAvatar(screen,data,role);if(!yes(quote,"eligible")){put(screen,13,"Ordinary Guild passage","Your current lawful route is available. Use the normal Guild Navigator.",Material.COMPASS,null);}else if(!yes(quote,"allowed")){put(screen,13,"Personal passage","Opt in with Esmar if ordinary Arrakis passage is unavailable. One hour from the verified introduction.",Material.COMPASS,null);put(screen,31,"Opt in to smuggling","Register the existing smuggler introduction and personal permission.",Material.LIME_DYE,()->{var introduction=data.getAsJsonArray("quests").asList().stream().map(JsonElement::getAsJsonObject).filter(q->text(q,"id","").equals("POL-SMUGGLERS-01")).findFirst().orElse(null);if(introduction==null){p.sendMessage("The current smuggler mission is unavailable.");return;}Runnable emit=()->{try{bridge.smugglerIntroduction(p);p.sendMessage("Introduction recorded. Reopen personal passage after J.A.R.V.I.S. verifies it.");}catch(Exception error){p.sendMessage("Meet Esmar Tuek in the Guild lobby.");}};if(yes(introduction,"canStart")&&!Set.of("active","completed","claimed").contains(text(introduction,"state",""))){var start=new JsonObject();start.addProperty("action","start");start.addProperty("kind","pol");start.addProperty("definitionId","POL-SMUGGLERS-01");start.addProperty("requestId",UUID.randomUUID().toString());start.addProperty("confirmed",true);request(p,start,ignored->emit.run());}else emit.run();});}else{long expiry=quote.get("permitExpiresAt").getAsLong();int price=quote.get("fareMinor").getAsInt();put(screen,13,"Personal passage to Arrakis","Fare: "+String.format(Locale.ROOT,"%.2f DM",price/100.0)+"\nPermission expires: "+java.time.Instant.ofEpochMilli(expiry)+"\nExisting unsanctioned-arrival rules apply.",Material.COMPASS,null);if(yes(quote,"affordable"))put(screen,31,"Book passage","Reserve this exact fare; payment settles only after arrival.",Material.LIME_DYE,()->{var board=new JsonObject();board.addProperty("action","smuggler_board");board.addProperty("requestId",UUID.randomUUID().toString());board.add("keyId",quote.get("keyId"));board.add("version",quote.get("version"));board.add("fareMinor",quote.get("fareMinor"));board.addProperty("destination","arrakis");smugglerRequest(p,board,ticket->{try{bridge.dispatchGuild(p,ticket);}catch(Exception error){p.sendMessage("The transfer was not dispatched; unused reservation expires.");}});});else put(screen,31,"Insufficient funds","Your personal central bank account must cover the fare.",Material.CLOCK,null);}put(screen,33,"Starter spice shovel","Open the existing starter objective for your original shovel; no duplicate issue.",Material.WOODEN_SHOVEL,()->{p.closeInventory();p.performCommand("start");});put(screen,49,"Back","Return to Esmar's missions",Material.ARROW,()->load(p,"pol",null,null,0));show(p,screen);});} void decisionCommand(Player player,String[] args){ if(args.length==0){openDecisions(player,0);return;} + if(args[0].equalsIgnoreCase("enact")){enactDecisionCommand(player,args);return;} if(args.length!=1||!args[0].matches("[A-Za-z0-9-]{1,32}")){player.sendMessage("Use /decisions [list|decision-id].");return;} String requested=args[0].toUpperCase(Locale.ROOT); var input=new JsonObject();input.addProperty("action","read"); @@ -176,6 +177,14 @@ final class QuestMenus implements Listener { String fee=text(decision,"feeMinor",""); if(fee.matches("[0-9]+"))player.sendMessage("Base cost: "+new java.math.BigDecimal(fee).movePointLeft(2).toPlainString()+" DM"); var contact=PolQuestNpc.decisionContact(text(decision,"npcRole","")); + if(decision.has("accounts"))for(var entry:decision.getAsJsonArray("accounts")){ + var account=entry.getAsJsonObject(); + player.sendMessage("Account: "+text(account,"name","Funding account")+" · "+text(account,"id","")); + } + if(decision.has("parameters"))for(var entry:decision.getAsJsonArray("parameters")){ + var option=entry.getAsJsonObject(); + player.sendMessage("Parameter: "+text(option,"label","")+" · "+text(option,"value","")); + } if(text(decision,"kind","").equals("website"))decisionWebsite(player,requested); else if(contact!=null)player.sendMessage("Contact: "+contact.name()); return; @@ -192,6 +201,43 @@ final class QuestMenus implements Listener { } },true); } + private void enactDecisionCommand(Player player,String[] args){ + if(args.length<2||args.length>4||!args[1].matches("[A-Za-z0-9-]{1,32}")){ + player.sendMessage("Use /decisions enact [account-id] [parameter].");return; + } + var input=new JsonObject();input.addProperty("action","read"); + request(player,input,data->{ + for(var value:data.getAsJsonArray("decisions")){ + var row=value.getAsJsonObject(); + if(!args[1].equalsIgnoreCase(text(row,"id","")))continue; + if(text(row,"kind","").equals("website")){decisionWebsite(player,text(row,"id",""));return;} + var role=PolQuestNpc.decisionContact(text(row,"npcRole","")); + if(role==null){player.sendMessage("No current decision contact is available.");return;} + boolean funding=!row.has("fundingRequired")||yes(row,"fundingRequired"); + boolean parameterRequired=row.has("parameters"); + if(args.length!=2+(funding?1:0)+(parameterRequired?1:0)){ + player.sendMessage("Review /decisions "+args[1]+" for the required account and options.");return; + } + String account=funding?args[2]:null; + String parameter=parameterRequired?args[funding?3:2]:null; + if(funding&&row.getAsJsonArray("accounts").asList().stream().map(JsonElement::getAsJsonObject) + .noneMatch(a->account.equals(text(a,"id",""))&&hasDecisionFunds(a,row))){ + player.sendMessage("Choose an eligible account with enough available funds.");return; + } + if(parameterRequired&&row.getAsJsonArray("parameters").asList().stream().map(JsonElement::getAsJsonObject) + .noneMatch(option->parameter.equals(text(option,"value","")))){ + player.sendMessage("Choose a current decision parameter.");return; + } + submitDecision(player,new JsonObject(),role,row,account,parameter,UUID.randomUUID(),false); + return; + } + player.sendMessage("That decision is not currently available to you."); + },true); + } + private static boolean hasDecisionFunds(JsonObject account,JsonObject row){ + try{return new java.math.BigInteger(text(account,"availableMinor","0")).compareTo(new java.math.BigInteger(text(row,"feeMinor","0")))>=0;} + catch(NumberFormatException invalid){return false;} + } void openDecisions(Player p,int page){ var input=new JsonObject();input.addProperty("action","read"); request(p,input,data->{ @@ -219,9 +265,20 @@ final class QuestMenus implements Listener { if(kind.equals("website")){put(screen,31,"Open website workflow","This decision requires the existing website controls.",Material.MAP,()->decisionWebsite(p,text(row,"id","")));} else if(account==null&&(!row.has("fundingRequired")||yes(row,"fundingRequired"))){int slot=18;for(var e:row.getAsJsonArray("accounts")){var a=e.getAsJsonObject();if(slot>=35)break;String id=text(a,"id","");try{if(new java.math.BigInteger(text(a,"availableMinor","0")).compareTo(new java.math.BigInteger(fee))<0)continue;}catch(NumberFormatException invalid){continue;}put(screen,slot++,text(a,"name","Funding account"),"Account "+text(a,"number","")+" · available "+new java.math.BigDecimal(text(a,"availableMinor","0")).movePointLeft(2).toPlainString()+" DM",Material.GOLD_INGOT,()->roleDecisionDetails(p,contact,role,row,id,parameter));}} else if(row.has("parameters")&¶meter==null){int slot=18;for(var item:row.getAsJsonArray("parameters")){var value=item.getAsJsonObject();if(slot>=35)break;put(screen,slot++,text(value,"label","Parameter"),"Select this exact parameter",Material.PAPER,()->roleDecisionDetails(p,contact,role,row,account,text(value,"value","")));}} - else{String parameterLabel=parameter;if(parameter!=null&&row.has("parameters"))for(var entry:row.getAsJsonArray("parameters")){var option=entry.getAsJsonObject();if(parameter.equals(text(option,"value",""))){parameterLabel=text(option,"label",parameter);break;}}put(screen,22,"Decision terms",(account==null?"No separate funding required":"Funding account "+account)+(parameter==null?"":"\nParameter: "+parameterLabel),Material.GOLD_INGOT,null);UUID requestId=UUID.randomUUID();put(screen,31,"Enact decision","Record this decision through J.A.R.V.I.S. at "+role.name(),Material.LIME_DYE,()->{var input=new JsonObject();input.addProperty("action","execute");input.addProperty("npcRole",role.key());input.addProperty("decisionId",text(row,"id",""));input.addProperty("requestId",requestId.toString());if(account!=null)input.addProperty("sourceAccount",account);input.addProperty("confirmed",true);if(parameter!=null)input.addProperty("parameter",parameter);decisionRequest(p,role,input,result->roleDecisionResult(p,contact,role,row,result));});} + else{String parameterLabel=parameter;if(parameter!=null&&row.has("parameters"))for(var entry:row.getAsJsonArray("parameters")){var option=entry.getAsJsonObject();if(parameter.equals(text(option,"value",""))){parameterLabel=text(option,"label",parameter);break;}}put(screen,22,"Decision terms",(account==null?"No separate funding required":"Funding account "+account)+(parameter==null?"":"\nParameter: "+parameterLabel),Material.GOLD_INGOT,null);UUID requestId=UUID.randomUUID();put(screen,31,"Enact decision","Record this decision through J.A.R.V.I.S. at "+role.name(),Material.LIME_DYE,()->submitDecision(p,contact,role,row,account,parameter,requestId,true));} put(screen,49,"Back","Current executable decisions",Material.ARROW,()->openDecisions(p,0));show(p,screen); } + private void submitDecision(Player player,JsonObject contact,PolQuestNpc.Role role,JsonObject row,String account,String parameter,UUID requestId,boolean reopen){ + var input=new JsonObject();input.addProperty("action","execute");input.addProperty("npcRole",role.key()); + input.addProperty("decisionId",text(row,"id",""));input.addProperty("requestId",requestId.toString()); + if(account!=null)input.addProperty("sourceAccount",account); + if(parameter!=null)input.addProperty("parameter",parameter); + input.addProperty("confirmed",true); + decisionRequest(player,role,input,result->{ + if(reopen)roleDecisionResult(player,contact,role,row,result); + else player.sendMessage("Decision recorded · "+text(result,"keyId","J.A.R.V.I.S.")); + }); + } private void roleDecisionResult(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,JsonObject result){var screen=panel(p,"NPC next quest decision · "+role.name());screen.description=dialogue(row,"turnIn","");roleAvatar(screen,contact,role);put(screen,13,text(row,"title","Decision"),"Reference: "+text(result,"keyId","Recorded")+"\nReputation: "+text(result,"xp","—"),Material.LIME_DYE,null);put(screen,31,"Next decision","See the remaining current eligible decisions",Material.BOOK,()->openDecisions(p,0));put(screen,49,"Later","Return to the contact dashboard",Material.ARROW,()->load(p,"pol",null,null,0));show(p,screen);} private void decisionRequest(Player p,PolQuestNpc.Role role,JsonObject input,Consumer callback){try{bridge.questCharacterNpc(p,role.key());request(p,input,callback,true);}catch(Exception unavailable){p.sendMessage("Return to this political quest contact.");}} private void roleSelected(Player p,JsonObject data,PolQuestNpc.Role role,JsonObject row){if(website(row)){details(p,"pol",data,text(row,"branch",""),0,row);return;}if(!Set.of("active","completed").contains(text(row,"state",""))){roleIntro(p,data,role,row);return;}details(p,"pol",data,text(row,"branch",""),0,row);}