forked from unimatrix/web
Render opt-in equipment, decision detail and war muster views
This commit is contained in:
parent
4c6b947ab3
commit
f3686fb5e4
3 changed files with 68 additions and 36 deletions
|
|
@ -19,7 +19,7 @@ public interface DecisionsViewTransport {
|
|||
}
|
||||
}
|
||||
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL, CODEX, ITEM_ARCHIVE, GUILD, SPICE }
|
||||
enum Style { AUTO, ORGANISATION, EXCHANGE, EXCHANGE_CHECKOUT, HOUSE, JOURNAL, CODEX, ITEM_ARCHIVE, GUILD, SPICE, WORKSHOP, DECISION_DETAIL, WAR_MUSTER }
|
||||
record Identity(String logo, String mentat, int portrait) {}
|
||||
|
||||
record Document(String title, String description, List<Card> cards, Style style, Identity identity) {
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ 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;boolean journalView;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;DecisionsViewTransport.Style nativeStyle;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;}
|
||||
}
|
||||
QuestMenus(JavaPlugin plugin,HouseBridge bridge,Consumer<Player> back){this.plugin=plugin;this.bridge=bridge;this.back=back;Bukkit.getPluginManager().registerEvents(this,plugin);}
|
||||
void quartermaster(Player p,Runnable exchange,Runnable kits){var s=panel(p,"Gurney · Quartermaster");put(s,20,"Exchange","Buy and sell individual items",Material.EMERALD,exchange);put(s,22,"Missions & turn-ins","Collect your House T0 kit or repair its original armour.\nPrepare four parts: one iron ingot, leather, copper ingot and quartz.\nOther missions and rewards use your current central journal.",Material.WRITABLE_BOOK,()->open(p));put(s,24,"Stillsuit kits","Published clan, company and office kits",Material.NETHERITE_CHESTPLATE,kits);put(s,31,"Organisation workshop","Upgrade your held original with researched MK and rarity templates",Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE,()->workshop(p,0));put(s,34,"Gurney\u0027s missions","Current bounty, campaign and ongoing duty missions",Material.BOOK,()->openRole(p,new PolQuestNpc.Role("gurney_halleck","Gurney Halleck",p.getWorld().getName(),"*",Set.of("bounty-jobs","war-service","repeatables","rd"),0)));put(s,49,"Close","Return to the world",Material.ARROW,p::closeInventory);show(p,s);}
|
||||
void quartermaster(Player p,Runnable exchange,Runnable kits){var s=equipmentPanel(p,"Gurney · Quartermaster");put(s,20,"Exchange","Buy and sell individual items",Material.EMERALD,exchange);put(s,22,"Missions & turn-ins","Collect your House T0 kit or repair its original armour.\nPrepare four parts: one iron ingot, leather, copper ingot and quartz.\nOther missions and rewards use your current central journal.",Material.WRITABLE_BOOK,()->open(p));put(s,24,"Stillsuit kits","Published clan, company and office kits",Material.NETHERITE_CHESTPLATE,kits);put(s,31,"Organisation workshop","Upgrade your held original with researched MK and rarity templates",Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE,()->workshop(p,0));put(s,34,"Gurney\u0027s missions","Current bounty, campaign and ongoing duty missions",Material.BOOK,()->openRole(p,new PolQuestNpc.Role("gurney_halleck","Gurney Halleck",p.getWorld().getName(),"*",Set.of("bounty-jobs","war-service","repeatables","rd"),0)));put(s,49,"Close","Return to the world",Material.ARROW,p::closeInventory);show(p,s);}
|
||||
private static String text(JsonObject row,String key,String fallback){return row.has(key)&&!row.get(key).isJsonNull()?row.get(key).getAsString():fallback;}
|
||||
private static String dialogue(JsonObject row,String field,String fallback){return row.has("dialogue")&&row.get("dialogue").isJsonObject()?text(row.getAsJsonObject("dialogue"),field,fallback):fallback;}
|
||||
private static boolean yes(JsonObject row,String key){return row.has(key)&&!row.get(key).isJsonNull()&&row.get(key).getAsBoolean();}
|
||||
|
|
@ -33,7 +33,12 @@ final class QuestMenus implements Listener {
|
|||
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;
|
||||
screen.nativeStyle=DecisionsViewTransport.Style.JOURNAL;
|
||||
return screen;
|
||||
}
|
||||
private Panel equipmentPanel(Player player,String title){
|
||||
var screen=panel(player,title);
|
||||
screen.nativeStyle=DecisionsViewTransport.Style.WORKSHOP;
|
||||
return screen;
|
||||
}
|
||||
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){
|
||||
|
|
@ -305,15 +310,17 @@ final class QuestMenus implements Listener {
|
|||
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&&!screen.journalView)return false;
|
||||
String setting=decisions?"development.fullscreen-decisions-viewers":"development.fullscreen-quest-viewers";
|
||||
boolean detail=screen.title.startsWith("NPC turn-in decision · ")||screen.title.startsWith("NPC next quest decision · ");
|
||||
if(!decisions&&!detail&&!quests&&screen.nativeStyle==null)return false;
|
||||
String setting=decisions||detail?"development.fullscreen-decisions-viewers":"development.fullscreen-quest-viewers";
|
||||
String dialogue=screen.description;
|
||||
for(int index=screen.descriptionNotes.size()-1;index>=0;index--){
|
||||
String note=screen.descriptionNotes.get(index);
|
||||
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,
|
||||
screen.journalView?DecisionsViewTransport.Style.JOURNAL:DecisionsViewTransport.Style.AUTO,null);
|
||||
detail?DecisionsViewTransport.Style.DECISION_DETAIL:
|
||||
screen.nativeStyle==null?DecisionsViewTransport.Style.AUTO:screen.nativeStyle,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)));}
|
||||
|
|
@ -368,14 +375,14 @@ final class QuestMenus implements Listener {
|
|||
player.sendMessage(args.length==2?"Use /missions workshop quote <kind> <organisation-id>.":"Choose a workshop from your current authorised list.");
|
||||
});
|
||||
}
|
||||
private void workshop(Player p,int page){var input=new JsonObject();input.addProperty("action","read_refits");input.addProperty("kind","pol");request(p,input,data->{var screen=panel(p,"Organisation workshop");var owners=data.getAsJsonArray("owners");int offset=page*36;for(int i=offset;i<Math.min(owners.size(),offset+36);i++){var owner=owners.get(i).getAsJsonObject();put(screen,i-offset,text(owner,"label","Organisation"),"Use your specialist’s researched MK and rarity for this organisation",Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE,()->prepareRefit(p,owner));}if(owners.isEmpty())put(screen,22,"Specialist required","Your current organisation deed must grant equipment research authority.",Material.GRAY_DYE,null);if(page>0)put(screen,45,"Previous","Earlier organisations",Material.ARROW,()->workshop(p,page-1));if(offset+36<owners.size())put(screen,53,"Next","More organisations",Material.ARROW,()->workshop(p,page+1));put(screen,49,"Back","Mission journal",Material.ARROW,()->open(p));show(p,screen);});}
|
||||
private void workshop(Player p,int page){var input=new JsonObject();input.addProperty("action","read_refits");input.addProperty("kind","pol");request(p,input,data->{var screen=equipmentPanel(p,"Organisation workshop");var owners=data.getAsJsonArray("owners");int offset=page*36;for(int i=offset;i<Math.min(owners.size(),offset+36);i++){var owner=owners.get(i).getAsJsonObject();put(screen,i-offset,text(owner,"label","Organisation"),"Use your specialist’s researched MK and rarity for this organisation",Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE,()->prepareRefit(p,owner));}if(owners.isEmpty())put(screen,22,"Specialist required","Your current organisation deed must grant equipment research authority.",Material.GRAY_DYE,null);if(page>0)put(screen,45,"Previous","Earlier organisations",Material.ARROW,()->workshop(p,page-1));if(offset+36<owners.size())put(screen,53,"Next","More organisations",Material.ARROW,()->workshop(p,page+1));put(screen,49,"Back","Mission journal",Material.ARROW,()->open(p));show(p,screen);});}
|
||||
private void prepareRefit(Player p,JsonObject owner){prepareRefit(p,owner,true);}
|
||||
private void prepareRefit(Player p,JsonObject owner,boolean reopen){try{var input=new JsonObject();input.addProperty("action","prepare_refit");input.addProperty("kind","pol");var selected=new JsonObject();selected.add("kind",owner.get("kind"));selected.add("id",owner.get("id"));input.add("owner",selected);input.add("snapshot",bridge.refitSnapshot(p));input.addProperty("requestId",UUID.randomUUID().toString());input.addProperty("npcUuid",bridge.starterNpc(p).toString());input.addProperty("confirmed",true);request(p,input,permit->{var plan=permit.getAsJsonObject("plan");var output=plan.getAsJsonObject("output");StringBuilder cost=new StringBuilder("Surrender the held original and:");for(var token:plan.getAsJsonObject("consume").getAsJsonArray("templates"))cost.append("\n1 ").append(token.getAsJsonObject().get("id").getAsString().replace("dr_","").replace('_',' '));if(!reopen){
|
||||
refitQuotes.put(p.getUniqueId(),new RefitQuote(input.deepCopy(),p.getWorld().getUID(),System.nanoTime()+30_000_000_000L));
|
||||
p.sendMessage("Refit to MK "+text(output,"equipmentMark","")+" · "+text(output,"quality","").replace('_',' ')+".");
|
||||
p.sendMessage(cost.toString());p.sendMessage("Use /missions workshop apply within 30 seconds while holding the same original near Gurney.");
|
||||
return;
|
||||
}var screen=panel(p,"Review equipment refit");Material material=Material.matchMaterial(output.get("material").getAsString());put(screen,13,"MK "+output.get("equipmentMark").getAsString()+" · "+output.get("quality").getAsString().replace('_',' '),"Original identity, name, lore and wear retained.\nExisting enchantments scale with the next tier.\nReputation level "+plan.get("requiredReputationLevel").getAsString()+" required.\n"+cost,material==null?Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE:material,null);put(screen,30,"Refit original",cost+"\nOne minute between refits. Review expires after 30 seconds.",Material.LIME_DYE,()->confirmRefit(p,input));put(screen,32,"Back","Return without consuming anything",Material.ARROW,()->workshop(p,0));show(p,screen);});}catch(Exception failure){p.sendMessage(Component.text(failure.getMessage()==null?"Hold your original near Gurney’s quartermaster.":failure.getMessage(),NamedTextColor.RED));}}
|
||||
}long expiresAt=System.nanoTime()+30_000_000_000L;var screen=equipmentPanel(p,"Review equipment refit");Material material=Material.matchMaterial(output.get("material").getAsString());put(screen,13,"MK "+output.get("equipmentMark").getAsString()+" · "+output.get("quality").getAsString().replace('_',' '),"Original identity, name, lore and wear retained.\nExisting enchantments scale with the next tier.\nReputation level "+plan.get("requiredReputationLevel").getAsString()+" required.\n"+cost,material==null?Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE:material,null);put(screen,30,"Refit original",cost+"\nOne minute between refits. Review expires after 30 seconds.",Material.LIME_DYE,()->{if(System.nanoTime()-expiresAt>=0){p.sendMessage("The refit quote expired. Request a new one.");return;}confirmRefit(p,input);});put(screen,32,"Back","Return without consuming anything",Material.ARROW,()->workshop(p,0));show(p,screen);});}catch(Exception failure){p.sendMessage(Component.text(failure.getMessage()==null?"Hold your original near Gurney’s quartermaster.":failure.getMessage(),NamedTextColor.RED));}}
|
||||
private void confirmRefit(Player p,JsonObject input){
|
||||
try{
|
||||
if(!input.get("snapshot").equals(bridge.refitSnapshot(p))||!input.get("npcUuid").getAsString().equals(bridge.starterNpc(p).toString())){
|
||||
|
|
@ -407,7 +414,10 @@ final class QuestMenus implements Listener {
|
|||
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=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");
|
||||
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(kind.equals("personal")&&Set.of("S1-H-01","S1-H-02").contains(text(row,"id","")))
|
||||
screen.nativeStyle=DecisionsViewTransport.Style.WORKSHOP;
|
||||
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));
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ final class WarMenus implements Listener {
|
|||
private static String text(JsonObject v,String key,String fallback){return v.has(key)&&!v.get(key).isJsonNull()?v.get(key).getAsString():fallback;}
|
||||
private static boolean yes(JsonObject v,String key){return v.has(key)&&!v.get(key).isJsonNull()&&v.get(key).getAsBoolean();}
|
||||
private void put(Panel p,int slot,String title,String body,Material material,Runnable action){var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(body.split("\n")).map(x->Component.text(x,NamedTextColor.GRAY)).toList());item.setItemMeta(meta);p.inventory.setItem(slot,item);if(action!=null){p.actions.put(slot,action);p.choices.add(new BedrockForms.Choice(title,body,action));}else p.description+="\n\n"+title+"\n"+body;}
|
||||
private void show(Player p,Panel panel){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.description,List.copyOf(panel.choices));return;}if(MCGUIMenus.show(p,panel.title,panel.title.equals("War Muster Room")?panel.baseDescription:panel.description,panel.inventory,panel.actions,panel.gate))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);}
|
||||
private void show(Player p,Panel panel){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.description,List.copyOf(panel.choices));return;}if(NativeMenus.show(plugin,p,"development.fullscreen-war-viewers",panel.title,panel.baseDescription,
|
||||
panel.inventory,panel.actions,panel.gate,DecisionsViewTransport.Style.WAR_MUSTER,null))return;if(MCGUIMenus.show(p,panel.title,panel.title.equals("War Muster Room")?panel.baseDescription:panel.description,panel.inventory,panel.actions,panel.gate))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);}
|
||||
private void request(Player p,JsonObject input,Consumer<JsonObject> result){UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(!pending.add(id))return;p.closeInventory();Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject data=null;String error=null;try{data=bridge.warMuster(id,input);}catch(Exception e){error=e instanceof java.io.IOException?e.getMessage():"War muster is temporarily unavailable.";}JsonObject received=data;String message=error;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{pending.remove(id);if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(message!=null){p.sendMessage(message);return;}if(received==null||!yes(received,"ok")){p.sendMessage(received==null?"War muster unavailable.":text(received,"message","War muster unavailable."));return;}result.accept(received);});});}
|
||||
void command(Player player,String[] args){
|
||||
if(args.length==0){open(player);return;}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff