forked from unimatrix/web
Render the player mission journal in the opt-in fullscreen viewer
This commit is contained in:
parent
a7448814de
commit
f3e6fe29b0
2 changed files with 54 additions and 11 deletions
|
|
@ -19,7 +19,7 @@ public interface DecisionsViewTransport {
|
|||
}
|
||||
}
|
||||
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE }
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL }
|
||||
record Identity(String logo, String mentat, int portrait) {}
|
||||
|
||||
record Document(String title, String description, List<Card> cards, Style style, Identity identity) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ final class QuestMenus implements Listener {
|
|||
private final Map<UUID,UUID> pending=new HashMap<>();
|
||||
private final Map<UUID,PolQuestNpc.Role> roleScope=new HashMap<>();
|
||||
private static final class Panel implements DuneMenuInventory {
|
||||
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final List<BedrockForms.Choice> choices=new ArrayList<>();final List<String> descriptionNotes=new ArrayList<>();final Inventory inventory;final String title;String description="Your current J.A.R.V.I.S. mission journal";
|
||||
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final List<BedrockForms.Choice> choices=new ArrayList<>();final List<String> descriptionNotes=new ArrayList<>();final Inventory inventory;final String title;boolean journalView;String description="Your current J.A.R.V.I.S. mission journal";
|
||||
Panel(Player p,String title){owner=p.getUniqueId();gate=new GuiSession(owner);this.title=title;inventory=Bukkit.createInventory(this,54,Component.text(title,NamedTextColor.GOLD));}
|
||||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
|
|
@ -31,12 +31,17 @@ final class QuestMenus implements Listener {
|
|||
private static boolean yes(JsonObject row,String key){return row.has(key)&&!row.get(key).isJsonNull()&&row.get(key).getAsBoolean();}
|
||||
private static boolean website(JsonObject row){return row.has("executionRequirements")&&!row.get("executionRequirements").isJsonNull()&&yes(row.getAsJsonObject("executionRequirements"),"website")&&!yes(row.getAsJsonObject("executionRequirements"),"minecraft");}
|
||||
private Panel panel(Player p,String title){var screen=new Panel(p,title);var filler=new ItemStack(Material.GRAY_STAINED_GLASS_PANE);var meta=filler.getItemMeta();meta.displayName(Component.empty());filler.setItemMeta(meta);for(int i=0;i<54;i++)screen.inventory.setItem(i,filler);return screen;}
|
||||
private Panel journalPanel(Player player,String title){
|
||||
var screen=panel(player,title);
|
||||
screen.journalView=true;
|
||||
return screen;
|
||||
}
|
||||
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){
|
||||
var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(description.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());item.setItemMeta(meta);panel.inventory.setItem(slot,item);
|
||||
if(action==null){String note="\n\n"+title+"\n"+description;panel.description+=note;panel.descriptionNotes.add(note);}
|
||||
if(action!=null){panel.actions.put(slot,action);panel.choices.add(new BedrockForms.Choice(title,description,action));}
|
||||
}
|
||||
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(showDevelopmentRoleplay(p,screen))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);}
|
||||
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(showDevelopmentView(p,screen))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();}
|
||||
private record RefitQuote(JsonObject input,UUID world,long expires){}
|
||||
private final Map<UUID,RefitQuote> refitQuotes=new HashMap<>();
|
||||
|
|
@ -179,7 +184,7 @@ final class QuestMenus implements Listener {
|
|||
}
|
||||
player.sendMessage("That NPC step is unavailable for this mission.");
|
||||
}
|
||||
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 open(Player p){roleScope.remove(p.getUniqueId());var screen=journalPanel(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);});}
|
||||
|
|
@ -296,11 +301,11 @@ final class QuestMenus implements Listener {
|
|||
show(p,screen);
|
||||
},true);
|
||||
}
|
||||
private boolean showDevelopmentRoleplay(Player player,Panel screen){
|
||||
private boolean showDevelopmentView(Player player,Panel screen){
|
||||
boolean decisions=screen.title.startsWith("NPC dashboard decision · ");
|
||||
boolean quests=screen.title.startsWith("NPC dashboard · ")||screen.title.startsWith("NPC turn-in · ")||
|
||||
screen.title.startsWith("NPC next quest · ");
|
||||
if(!decisions&&!quests)return false;
|
||||
if(!decisions&&!quests&&!screen.journalView)return false;
|
||||
String setting=decisions?"development.fullscreen-decisions-viewers":"development.fullscreen-quest-viewers";
|
||||
String dialogue=screen.description;
|
||||
for(int index=screen.descriptionNotes.size()-1;index>=0;index--){
|
||||
|
|
@ -308,7 +313,7 @@ final class QuestMenus implements Listener {
|
|||
if(dialogue.endsWith(note))dialogue=dialogue.substring(0,dialogue.length()-note.length());
|
||||
}
|
||||
return NativeMenus.show(plugin,player,setting,screen.title,dialogue,screen.inventory,screen.actions,screen.gate,
|
||||
DecisionsViewTransport.Style.AUTO,null);
|
||||
screen.journalView?DecisionsViewTransport.Style.JOURNAL:DecisionsViewTransport.Style.AUTO,null);
|
||||
}
|
||||
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)));}
|
||||
|
|
@ -390,19 +395,19 @@ final class QuestMenus implements Listener {
|
|||
}
|
||||
private void load(Player p,String kind,String branch,String selected,int page){var input=new JsonObject();input.addProperty("action","read");input.addProperty("kind",kind);var contact=roleScope.get(p.getUniqueId());if(contact!=null&&kind.equals("pol"))input.addProperty("npcRole",contact.key());request(p,input,data->{if(!"active".equals(text(data,"state",""))){p.sendMessage("No active quest season is available.");open(p);return;}var role=roleScope.get(p.getUniqueId());if(role!=null&&kind.equals("pol")){roleJournal(p,data,role,selected);return;}if(branch==null)branches(p,kind,data);else if(selected==null)quests(p,kind,data,branch,page);else{JsonObject row=null;for(var entry:data.getAsJsonArray("quests"))if(selected.equals(text(entry.getAsJsonObject(),"id","")))row=entry.getAsJsonObject();if(row==null)quests(p,kind,data,branch,page);else details(p,kind,data,branch,page,row);}});}
|
||||
private void branches(Player p,String kind,JsonObject data){
|
||||
var screen=panel(p,kind.equals("pol")?"Reputation branches":"Personal mission branches");var branches=new LinkedHashMap<String,String>();for(var entry:data.getAsJsonArray("quests")){String id=text(entry.getAsJsonObject(),"branch","missions");branches.putIfAbsent(id,id);}
|
||||
var screen=journalPanel(p,kind.equals("pol")?"Reputation branches":"Personal mission branches");var branches=new LinkedHashMap<String,String>();for(var entry:data.getAsJsonArray("quests")){String id=text(entry.getAsJsonObject(),"branch","missions");branches.putIfAbsent(id,id);}
|
||||
if(data.has("branches"))for(var entry:data.getAsJsonArray("branches")){var branch=entry.getAsJsonObject();String id=text(branch,"id","");if(branches.containsKey(id))branches.put(id,text(branch,"title",id));}
|
||||
int slot=0;for(var branch:branches.entrySet()){if(slot>=45)break;String id=branch.getKey();put(screen,slot++,branch.getValue(),"Open this mission branch",Material.WRITABLE_BOOK,()->quests(p,kind,data,id,0));}put(screen,49,"Back","Mission journal",Material.ARROW,()->open(p));show(p,screen);
|
||||
}
|
||||
private void quests(Player p,String kind,JsonObject data,String branch,int page){
|
||||
var rows=new ArrayList<JsonObject>();for(var entry:data.getAsJsonArray("quests")){var row=entry.getAsJsonObject();if(branch.equals(text(row,"branch","")))rows.add(row);}
|
||||
int offset=page*36;var screen=panel(p,"Missions · "+branch);for(int i=offset;i<Math.min(rows.size(),offset+36);i++){var row=rows.get(i);boolean web=website(row);put(screen,i-offset,text(row,"title","Quest"),text(row,"state","Pending")+"\n"+(web?"Website quest":"Minecraft / website quest")+"\n"+text(row,"progress","0")+" / "+text(row,"target","0"),web?Material.WRITABLE_BOOK:Material.LIGHT_BLUE_DYE,()->details(p,kind,data,branch,page,row));}
|
||||
int offset=page*36;var screen=journalPanel(p,"Missions · "+branch);for(int i=offset;i<Math.min(rows.size(),offset+36);i++){var row=rows.get(i);boolean web=website(row);put(screen,i-offset,text(row,"title","Quest"),text(row,"state","Pending")+"\n"+(web?"Website quest":"Minecraft / website quest")+"\n"+text(row,"progress","0")+" / "+text(row,"target","0"),web?Material.WRITABLE_BOOK:Material.LIGHT_BLUE_DYE,()->details(p,kind,data,branch,page,row));}
|
||||
if(kind.equals("personal")&&branch.equals("e")){put(screen,36,"Official Spice Harvesting","Reputation careers · genuine harvested spice",Material.ORANGE_DYE,()->load(p,"pol","spice-harvesting",null,0));put(screen,38,"Smuggling Jobs","Native roaming smuggler contracts",Material.CHEST,()->load(p,"pol","smugglers",null,0));put(screen,40,"Bounty Jobs","Accept and complete an actual bounty",Material.MAP,()->load(p,"pol","bounty-jobs",null,0));}
|
||||
if(kind.equals("pol")&&branch.equals("bounty-jobs"))put(screen,40,"View active bounties","Open /dune bounty on Arrakis",Material.PAPER,()->{p.closeInventory();p.performCommand("dune bounty");});
|
||||
put(screen,45,"Branches","Choose another branch",Material.ARROW,()->branches(p,kind,data));if(page>0)put(screen,47,"Previous","Previous missions",Material.PAPER,()->quests(p,kind,data,branch,page-1));put(screen,49,"Refresh","Read current verified quest records",Material.CLOCK,()->load(p,kind,branch,null,page));if(offset+36<rows.size())put(screen,51,"Next","More missions",Material.PAPER,()->quests(p,kind,data,branch,page+1));show(p,screen);
|
||||
}
|
||||
private void details(Player p,String kind,JsonObject data,String branch,int page,JsonObject row){
|
||||
var role=roleScope.get(p.getUniqueId());var screen=panel(p,role!=null&&kind.equals("pol")?"NPC turn-in · "+role.name():"Quest dossier");if(role!=null&&kind.equals("pol")){screen.description=yes(row,"canClaim")?dialogue(row,"turnIn",""):dialogue(row,"context","");roleAvatar(screen,data,role);}String title=text(row,"title","Quest"),state=text(row,"state","Pending"),description=text(row,"objective","Complete the verified objective.")+"\nProgress: "+text(row,"progress","0")+" / "+text(row,"target","0")+"\nState: "+state+"\n"+(kind.equals("pol")?"Reputation: ":"XP: ")+text(row,"xp","Not configured");
|
||||
var role=roleScope.get(p.getUniqueId());var screen=role!=null&&kind.equals("pol")?panel(p,"NPC turn-in · "+role.name()):journalPanel(p,"Quest dossier");if(role!=null&&kind.equals("pol")){screen.description=yes(row,"canClaim")?dialogue(row,"turnIn",""):dialogue(row,"context","");roleAvatar(screen,data,role);}String title=text(row,"title","Quest"),state=text(row,"state","Pending"),description=text(row,"objective","Complete the verified objective.")+"\nProgress: "+text(row,"progress","0")+" / "+text(row,"target","0")+"\nState: "+state+"\n"+(kind.equals("pol")?"Reputation: ":"XP: ")+text(row,"xp","Not configured");
|
||||
if(row.has("personalXP")&&!row.get("personalXP").isJsonNull())description+="\nBase Personal XP: "+row.get("personalXP").getAsInt();if(row.has("baseDMMinor")&&!row.get("baseDMMinor").isJsonNull())description+="\nBase funded reward: "+String.format(Locale.ROOT,"%.2f DM",row.get("baseDMMinor").getAsLong()/100.0);
|
||||
put(screen,13,title,description,website(row)?Material.WRITABLE_BOOK:Material.LIGHT_BLUE_DYE,null);
|
||||
if(website(row))put(screen,31,"Open website journal","This objective belongs to the website",Material.MAP,()->website(p));
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff