Share registered contact portraits between web profiles and native roleplay dialogue screens
This commit is contained in:
parent
ebbb895c12
commit
7b2c3914f4
1 changed files with 54 additions and 15 deletions
|
|
@ -42,7 +42,7 @@ final class QuestMenus implements Listener {
|
|||
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);load(p,"pol",null,null,0);}
|
||||
private boolean roleAllowed(JsonObject data,PolQuestNpc.Role role,JsonObject q){String branch=text(q,"branch","");boolean contact=q.has("dossier")&&!q.get("dossier").isJsonNull()&&role.key().equals(text(q.getAsJsonObject("dossier"),"role",""))||q.has("cargo")&&!q.get("cargo").isJsonNull()&&role.key().equals(text(q.getAsJsonObject("cargo"),"role",""));return data.has("npcContact")&&!data.get("npcContact").isJsonNull()&&(role.faction().equals("*")||role.faction().equals(text(data,"npcFaction",""))||branch.equals("company")&&role.key().equals("roma_atani"))&&(contact||role.branches().contains(branch)&&role.key().equals(text(q,"npcRole",text(q,"issuer",""))));}
|
||||
private void roleAvatar(Panel screen,JsonObject data,PolQuestNpc.Role role){if(!data.has("npcContact")||data.get("npcContact").isJsonNull())return;var contact=data.getAsJsonObject("npcContact");int cell=contact.getAsJsonObject("avatar").get("cell").getAsInt();if(cell<0||cell>7)return;put(screen,4,text(contact,"name",role.name()),text(contact,"role","Quest contact"),Material.PLAYER_HEAD,null);var item=screen.inventory.getItem(4);var meta=item.getItemMeta();meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,"npc_avatar_"+cell);item.setItemMeta(meta);screen.inventory.setItem(4,item);var art=new ItemStack(Material.PAPER);var artMeta=art.getItemMeta();artMeta.displayName(Component.text("Realm artwork",NamedTextColor.GOLD));artMeta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,"npc_world_"+(role.key().equals("imperial_attendant")?"imperial":role.world()));art.setItemMeta(artMeta);screen.inventory.setItem(8,art); }
|
||||
private void roleAvatar(Panel screen,JsonObject data,PolQuestNpc.Role role){if(!data.has("npcContact")||data.get("npcContact").isJsonNull())return;var contact=data.getAsJsonObject("npcContact");var portrait=contact.getAsJsonObject("avatar");int cell=portrait.get("cell").getAsInt();boolean extended=text(portrait,"atlas","").equals("https://cp.dunerealms.com/assets/quest-contact-portraits-v1.png");if(cell<0||cell>(extended?11:7))return;put(screen,4,text(contact,"name",role.name()),text(contact,"role","Quest contact"),Material.PLAYER_HEAD,null);var item=screen.inventory.getItem(4);var meta=item.getItemMeta();meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,(extended?"npc_contact_":"npc_avatar_")+cell);item.setItemMeta(meta);screen.inventory.setItem(4,item);var art=new ItemStack(Material.PAPER);var artMeta=art.getItemMeta();artMeta.displayName(Component.text("Realm artwork",NamedTextColor.GOLD));artMeta.getPersistentDataContainer().set(new NamespacedKey("dunerealms","menu_art"),org.bukkit.persistence.PersistentDataType.STRING,"npc_world_"+(role.key().equals("imperial_attendant")?"imperial":role.world()));art.setItemMeta(artMeta);screen.inventory.setItem(8,art); }
|
||||
private void roleJournal(Player p,JsonObject data,PolQuestNpc.Role role,String selected){
|
||||
var available=new ArrayList<JsonObject>();for(var e:data.getAsJsonArray("quests")){var q=e.getAsJsonObject();if(roleAllowed(data,role,q)&&!text(q,"state","").equals("claimed")&&(Set.of("active","completed").contains(text(q,"state",""))||yes(q,"canStart")))available.add(q);}
|
||||
if(selected!=null){var row=available.stream().filter(q->selected.equals(text(q,"id",""))).findFirst().orElse(null);if(row!=null){roleSelected(p,data,role,row);return;}}
|
||||
|
|
@ -51,16 +51,16 @@ final class QuestMenus implements Listener {
|
|||
if(ordered.isEmpty())put(screen,13,"No eligible missions","Read the website journal for the full record.",Material.MAP,null);
|
||||
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);
|
||||
}
|
||||
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 · "+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.":"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);});}
|
||||
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.":"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);});}
|
||||
private void decisionWebsite(Player p){p.closeInventory();p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl("https://clans.dunerealms.com/#quests/quests")));}
|
||||
private void roleDecisionDetails(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,String account,String parameter){var screen=panel(p,"NPC turn-in · "+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);
|
||||
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));}
|
||||
else if(account==null){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{put(screen,22,"Confirmed selection","Funding account "+account+(parameter==null?"":"\nParameter: "+parameter),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());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);
|
||||
}
|
||||
private void roleDecisionResult(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,JsonObject result){var screen=panel(p,"NPC next quest · "+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,()->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 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