forked from unimatrix/web
Open a shared political Decisions screen from NPCs and the journal
This commit is contained in:
parent
13df172a7e
commit
897fc46489
1 changed files with 72 additions and 27 deletions
|
|
@ -38,7 +38,7 @@ final class QuestMenus implements Listener {
|
|||
}
|
||||
private void show(Player p,Panel screen){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,screen.title,screen.description,List.copyOf(screen.choices));return;}if(MCGUIMenus.show(p,screen.title,screen.description,screen.inventory,screen.actions,screen.gate))return;p.openInventory(screen.inventory);Bukkit.getScheduler().runTaskLater(plugin,screen.gate::expire,2400L);}
|
||||
void close(){pending.clear();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Panel)p.closeInventory();}
|
||||
void open(Player p){roleScope.remove(p.getUniqueId());var screen=panel(p,"Mission journal");put(screen,20,"Personal Experience","Your personal mission branches",Material.BOOK,()->load(p,"personal",null,null,0));put(screen,24,"Reputation","Your Reputation mission branches",Material.ENCHANTED_BOOK,()->load(p,"pol",null,null,0));put(screen,45,"Website Mentat Report","Open your full online journal",Material.MAP,()->website(p));put(screen,49,"Back","Imperial Codex",Material.ARROW,()->back.accept(p));show(p,screen);}
|
||||
void open(Player p){roleScope.remove(p.getUniqueId());var screen=panel(p,"Mission journal");put(screen,20,"Personal Experience","Your personal mission branches",Material.BOOK,()->load(p,"personal",null,null,0));put(screen,24,"Reputation","Your Reputation mission branches",Material.ENCHANTED_BOOK,()->load(p,"pol",null,null,0));put(screen,31,"Political decisions","Decisions available to your current offices",Material.WRITABLE_BOOK,()->openDecisions(p,0));put(screen,45,"Website Mentat Report","Open your full online journal",Material.MAP,()->website(p));put(screen,49,"Back","Imperial Codex",Material.ARROW,()->back.accept(p));show(p,screen);}
|
||||
void starterJournal(Player p){roleScope.remove(p.getUniqueId());load(p,"personal","h",null,0);}
|
||||
void openRole(Player p,PolQuestNpc.Role role){roleScope.put(p.getUniqueId(),role);if(role.branches().contains("prologue")){housePrologue(p,role);return;}load(p,"pol",null,null,0);}
|
||||
private void housePrologue(Player p,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","read");input.addProperty("kind","personal");input.addProperty("npcRole",role.key());request(p,input,data->{var screen=panel(p,"NPC turn-in · "+role.name());roleAvatar(screen,data,role);var state=data.has("housePrologue")&&data.get("housePrologue").isJsonObject()?data.getAsJsonObject("housePrologue"):new JsonObject();screen.description=text(state,"dialogue","");if(!yes(state,"required")){put(screen,13,"Welcome back","Your established preparation is retained. Use the existing Guild Navigator for passage.",Material.COMPASS,null);}else if(!role.key().equals(text(state,"mentor",""))){put(screen,13,"Choose your House","Meet the adviser of your current House. Visit the existing account and House selection flow.",Material.BOOK,null);put(screen,31,"Open account and House selection","Complete your account and select a House before returning.",Material.MAP,()->{p.closeInventory();p.sendMessage(Component.text("Open your account and House selection →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl("https://cp.dunerealms.com/")));});}else{put(screen,13,"House Prologue","Account setup: "+(yes(state,"onboarding")?"Verified":"Pending")+"\nProfile: "+(yes(state,"profile")?"Verified":"Pending")+"\nMentat introduction: "+(yes(state,"introduced")?"Verified":"Pending")+"\nStarter equipment: "+(yes(state,"kit")?"Verified":"Pending"),Material.WRITABLE_BOOK,null);if(!yes(state,"introduced"))put(screen,31,"Acknowledge House introduction","Record this matching Mentat interaction. Rewards are issued automatically on verification.",Material.LIME_DYE,()->{try{bridge.houseMentorIntroduction(p,role.key());p.sendMessage("Introduction recorded. Reopen this contact to refresh your verified progress.");}catch(Exception error){p.sendMessage("Return to your matching House Mentat.");}});else if(!yes(state,"kit"))put(screen,31,"Your starter equipment","Open the existing starter objective; retain your original shovel and kit.",Material.WOODEN_SHOVEL,()->{p.closeInventory();p.performCommand("start");});else if(yes(state,"ready"))put(screen,31,"Your first passage is unlocked","Use the existing Guild Navigator to travel to your native world.",Material.COMPASS,null);else put(screen,31,"Finish account preparation","Complete the existing website profile and first sign-in requirements.",Material.MAP,()->{p.closeInventory();p.sendMessage(Component.text("Open your account →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl("https://cp.dunerealms.com/")));});}put(screen,49,"Refresh","Check your actual progress and automatically recorded rewards",Material.ARROW,()->housePrologue(p,role));show(p,screen);});}
|
||||
|
|
@ -51,21 +51,41 @@ final class QuestMenus implements Listener {
|
|||
int slot=9;for(var q:ordered){if(slot>=45)break;String status=Set.of("active","completed").contains(text(q,"state",""))?"Progress: "+text(q,"progress","0")+" / "+text(q,"target","1"):"Eligible to accept";put(screen,slot++,text(q,"title","Mission"),status+"\n"+text(q,"id","")+" · "+text(q,"objective",""),Material.WRITABLE_BOOK,()->roleSelected(p,data,role,q));}
|
||||
if(ordered.isEmpty())put(screen,13,"No eligible missions","Read the website journal for the full record.",Material.MAP,null);
|
||||
if(role.key().equals("esmar_tuek"))put(screen,47,role.world().equals("guild_lobby")?"Personal smuggler passage":"Smuggler return",role.world().equals("guild_lobby")?"Opt in with Esmar or board your paid one-hour personal route.":"Return to the Guild from your confirmed smuggler arrival.",Material.COMPASS,()->{if(role.world().equals("guild_lobby"))smugglerMenu(p,data,role);else try{bridge.returnSmuggler(p);}catch(Exception failure){p.sendMessage("Meet Esmar Tuek on Arrakis to return.");}});
|
||||
if(Set.of("thufir_hawat","piter_de_vries","hasimir_fenring","roma_atani","imperial_attendant","stilgar","jessica_atreides","gaius_helen_mohiam","alia_atreides","edric","guild_navigator","duncan_idaho").contains(role.key()))put(screen,48,"POL decisions","See only current executable political decisions",Material.BOOK,()->roleDecisionDashboard(p,data,role));put(screen,49,"Website journal","Full mission choices and history",Material.MAP,()->website(p));show(p,screen);
|
||||
if(Set.of("thufir_hawat","piter_de_vries","hasimir_fenring","roma_atani","imperial_attendant","stilgar","jessica_atreides","gaius_helen_mohiam","alia_atreides","edric","guild_navigator","duncan_idaho").contains(role.key()))put(screen,48,"POL decisions","See only current executable political decisions",Material.BOOK,()->openDecisions(p,0));put(screen,49,"Website journal","Full mission choices and history",Material.MAP,()->website(p));show(p,screen);
|
||||
}
|
||||
private void smugglerRequest(Player p,JsonObject input,Consumer<JsonObject> callback){try{bridge.questCharacterNpc(p,"esmar_tuek");}catch(Exception unavailable){p.sendMessage("Meet Esmar Tuek first.");return;}UUID id=p.getUniqueId(),world=p.getWorld().getUID(),operation=UUID.randomUUID();if(pending.putIfAbsent(id,operation)!=null)return;p.closeInventory();Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{if(text(input,"action","").equals("smuggler_board")&&!bridge.worldOnline("arrakis"))throw new IllegalStateException("Arrakis is currently unavailable.");result=bridge.guild(id,input);}catch(Exception failure){error=failure.getMessage();}var response=result;String message=error;Bukkit.getScheduler().runTask(plugin,()->{if(!pending.remove(id,operation)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The smuggler passage is unavailable.":message);return;}callback.accept(response);});});}
|
||||
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,"Confirm paid 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);});}
|
||||
private void roleDecisionDashboard(Player p,JsonObject contact,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","read");input.addProperty("npcRole",role.key());decisionRequest(p,role,input,data->{var screen=panel(p,"NPC dashboard decision · "+role.name());screen.description="Choose a decision you currently have the authority to execute.";roleAvatar(screen,contact,role);int slot=9;for(var e:data.getAsJsonArray("decisions")){var row=e.getAsJsonObject();if(slot>=45)break;put(screen,slot++,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\n"+(text(row,"kind","").equals("website")?"Continue through the verified website workflow.":(row.has("fundingRequired")&&!yes(row,"fundingRequired")?"Review the parameter and confirm.":"Review funding and confirm.")),Material.BOOK,()->roleDecisionDetails(p,contact,role,row,null,null));}if(slot==9)put(screen,13,"No executable decisions","Your current office, authority and cooldown determine what appears here.",Material.MAP,null);put(screen,48,"Back","Mission dashboard",Material.ARROW,()->load(p,"pol",null,null,0));put(screen,49,"Website","Full decision definitions and history",Material.MAP,()->decisionWebsite(p));show(p,screen);});}
|
||||
void openDecisions(Player p,int page){
|
||||
var input=new JsonObject();input.addProperty("action","read");
|
||||
request(p,input,data->{
|
||||
var screen=panel(p,"NPC dashboard decision · Political decisions");
|
||||
screen.description="Decisions available to your current political offices and mandates.";
|
||||
var decisions=data.getAsJsonArray("decisions");
|
||||
int pageSize=27,last=Math.max(0,(decisions.size()-1)/pageSize),current=Math.min(page,last),slot=9;
|
||||
for(int index=current*pageSize;index<Math.min(decisions.size(),(current+1)*pageSize);index++){
|
||||
var row=decisions.get(index).getAsJsonObject();
|
||||
var contact=PolQuestNpc.decisionContact(text(row,"npcRole",""));
|
||||
if(contact==null)continue;
|
||||
put(screen,slot++,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\n"+contact.name(),Material.BOOK,()->roleDecisionDetails(p,new JsonObject(),contact,row,null,null));
|
||||
}
|
||||
if(slot==9)put(screen,13,"No available decisions","Your current authority and cooldown determine what appears here.",Material.MAP,null);
|
||||
if(current>0)put(screen,45,"Previous page","Earlier decisions",Material.ARROW,()->openDecisions(p,current-1));
|
||||
if(current<last)put(screen,53,"Next page","More decisions",Material.ARROW,()->openDecisions(p,current+1));
|
||||
put(screen,48,"Back","Mission journal",Material.ARROW,()->open(p));
|
||||
put(screen,49,"Website","Decision definitions and history",Material.MAP,()->decisionWebsite(p));
|
||||
show(p,screen);
|
||||
},true);
|
||||
}
|
||||
private void decisionWebsite(Player p){decisionWebsite(p,null);}
|
||||
private void decisionWebsite(Player p,String decision){p.closeInventory();String url="https://clans.dunerealms.com/#quests/quests?xp=pol&view=decisions";if(decision!=null&&decision.matches("[A-Z0-9-]{1,32}"))url+="&decision="+decision;p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl(url)));}
|
||||
private void roleDecisionDetails(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,String account,String parameter){var screen=panel(p,"NPC turn-in decision · "+role.name());screen.description=dialogue(row,"introduction","");roleAvatar(screen,contact,role);String kind=text(row,"kind","");String fee=text(row,"feeMinor","0");String amount;try{amount=new java.math.BigDecimal(fee).movePointLeft(2).toPlainString()+" DM";}catch(NumberFormatException invalid){amount="—";}put(screen,13,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\nBase cost: "+amount+"\nAward: "+text(row,"reputation","—")+" Reputation",Material.BOOK,null);
|
||||
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,"Confirmed selection",(account==null?"No separate funding required":"Funding account "+account)+(parameter==null?"":"\nParameter: "+parameterLabel),Material.GOLD_INGOT,null);UUID requestId=UUID.randomUUID();put(screen,31,"Confirm and execute","Commit the reviewed decision once through J.A.R.V.I.S.",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));});}
|
||||
put(screen,49,"Back","Current executable decisions",Material.ARROW,()->roleDecisionDashboard(p,contact,role));show(p,screen);
|
||||
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,"Confirmed selection",(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));});}
|
||||
put(screen,49,"Back","Current executable decisions",Material.ARROW,()->openDecisions(p,0));show(p,screen);
|
||||
}
|
||||
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,()->roleDecisionDashboard(p,contact,role));put(screen,49,"Later","Return to the contact dashboard",Material.ARROW,()->load(p,"pol",null,null,0));show(p,screen);}
|
||||
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<JsonObject> 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);}
|
||||
private void roleIntro(Player p,JsonObject data,PolQuestNpc.Role role,JsonObject row){var screen=panel(p,"NPC next quest · "+role.name());screen.description=dialogue(row,"introduction","");roleAvatar(screen,data,role);put(screen,13,text(row,"title","Next mission"),text(row,"objective","")+"\nReputation: "+text(row,"xp","—"),Material.WRITABLE_BOOK,null);put(screen,30,"Accept","Accept exactly this mission",Material.LIME_DYE,()->act(p,"pol",text(row,"branch",""),0,row,"start"));put(screen,32,"Later","Return to the contact's mission dashboard",Material.ARROW,()->roleJournal(p,data,role,null));show(p,screen);}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff