Redeem ready quests and make empty mission branches explicit
This commit is contained in:
parent
f54ac3f41a
commit
6418e229fd
4 changed files with 116 additions and 5 deletions
|
|
@ -80,7 +80,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
if("server".equals(centralSettings.getString("delivery")))new CentralItemModels(this);
|
||||
|
||||
sidebar=new PersonalSidebar(this);nameplates=new PublicNameplates(this);
|
||||
for(String command:List.of("start","spice","sellall","exchange","house","mentat","drgui","drscoreboard","guildtravel","clan","company","polgui"))Objects.requireNonNull(getCommand(command)).setExecutor(this);
|
||||
for(String command:List.of("quest","start","spice","sellall","exchange","house","mentat","drgui","drscoreboard","guildtravel","clan","company","polgui"))Objects.requireNonNull(getCommand(command)).setExecutor(this);
|
||||
try{guild=new ExistingGuildService(p->spice.open(p),(p,world)->openGuild(p,world),p->exchange.open(p),p->quests.open(p),p->organisations.console(p),p->{if(!sidebar.enabled(p))sidebar.toggle(p);refreshSidebar(p);p.sendMessage("Your central bank balance appears in your personal scoreboard.");});getLogger().info("Spacing Guild lobby entry connected to current House keys and twenty-minute boarding windows.");}catch(RuntimeException unavailable){getLogger().warning("Spacing Guild travel consumer unavailable; no journeys can be booked.");}
|
||||
getServer().getPluginManager().registerEvents(this,this);
|
||||
departure=Bukkit.createBossBar("Spacing Guild · next Imperial departure",BarColor.YELLOW,BarStyle.SOLID);
|
||||
|
|
@ -107,6 +107,10 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
if(!(sender instanceof Player p))return true;
|
||||
if(command.getName().equals("rosterkey")){if(args.length!=1)p.sendMessage("Use /rosterkey <team invite code>");else warMenus.accept(p,args[0]);return true;}
|
||||
if(command.getName().equals("warmuster")){warMenus.open(p);return true;}
|
||||
if(command.getName().equals("quest")){
|
||||
if(args.length==1&&args[0].equalsIgnoreCase("redeem"))quests.redeemReady(p);else p.sendMessage("Use /quest redeem to claim ready rewards.");
|
||||
return true;
|
||||
}
|
||||
if(command.getName().equals("start")){quests.starterJournal(p);return true;}
|
||||
if(command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("organisations")){organisations.open(p,null);return true;}
|
||||
if(command.getName().equals("drgui")&&args.length==1&&args[0].equalsIgnoreCase("pack")){
|
||||
|
|
|
|||
|
|
@ -38,8 +38,67 @@ 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,22,"Claim all ready rewards","Claim verified rewards from your Personal and Reputation journals",Material.CHEST,()->redeemReady(p));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);}
|
||||
private record ClaimBatch(int recorded,int previouslyRecorded,boolean refreshKits,List<String> issues){}
|
||||
void redeemReady(Player player){
|
||||
UUID owner=player.getUniqueId(),operation=UUID.randomUUID();
|
||||
if(pending.putIfAbsent(owner,operation)!=null){player.sendMessage("A mission request is already in progress.");return;}
|
||||
player.closeInventory();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{
|
||||
ClaimBatch result=claimReady(owner);
|
||||
if(!plugin.isEnabled())return;
|
||||
Bukkit.getScheduler().runTask(plugin,()->{
|
||||
if(!pending.remove(owner,operation)||!player.isOnline())return;
|
||||
if(result.recorded()>0)player.sendMessage(result.recorded()+" quest reward(s) recorded. Item rewards may still be queued for delivery.");
|
||||
if(result.previouslyRecorded()>0)player.sendMessage(result.previouslyRecorded()+" quest reward(s) were already recorded.");
|
||||
for(String issue:result.issues())player.sendMessage(issue);
|
||||
if(result.recorded()==0&&result.previouslyRecorded()==0&&result.issues().isEmpty())player.sendMessage("No in-game quest rewards are ready to claim.");
|
||||
if(result.refreshKits())try{bridge.refreshKits(player);}catch(Exception unavailable){player.sendMessage("Your intact replacement remains queued for delivery.");}
|
||||
});
|
||||
});
|
||||
}
|
||||
private ClaimBatch claimReady(UUID player){
|
||||
int recorded=0,replayed=0;
|
||||
boolean refreshKits=false;
|
||||
List<String> issues=new ArrayList<>();
|
||||
for(String kind:List.of("personal","pol")){
|
||||
var read=new JsonObject();read.addProperty("action","read");read.addProperty("kind",kind);
|
||||
JsonObject journal;
|
||||
try{journal=bridge.quests(player,read);}
|
||||
catch(Exception failure){issues.add((kind.equals("pol")?"Reputation":"Personal")+" rewards could not be checked. Try /quest redeem again.");continue;}
|
||||
if(journal==null||!yes(journal,"ok")||!journal.has("quests")||!journal.get("quests").isJsonArray()){
|
||||
issues.add((kind.equals("pol")?"Reputation":"Personal")+" rewards could not be checked.");continue;
|
||||
}
|
||||
String season=journal.has("season")&&journal.get("season").isJsonObject()?text(journal.getAsJsonObject("season"),"id",""):"";
|
||||
Set<String> seen=new HashSet<>();
|
||||
for(var entry:journal.getAsJsonArray("quests")){
|
||||
if(!entry.isJsonObject())continue;
|
||||
var row=entry.getAsJsonObject();
|
||||
String id=text(row,"id","");
|
||||
if(id.isBlank()||!yes(row,"canClaim")||!seen.add(id))continue;
|
||||
String title=text(row,"title",id);
|
||||
if("website".equals(text(row,"channel",""))||website(row)){issues.add(title+" is ready in your online mission journal.");continue;}
|
||||
try{
|
||||
var input=readyClaim(player,kind,season,row);
|
||||
var result=bridge.quests(player,input);
|
||||
if(result==null||!yes(result,"ok")||text(result,"keyId","").isBlank())throw new IllegalStateException();
|
||||
if(yes(result,"replayed"))replayed++;else recorded++;
|
||||
refreshKits|=id.equals("S1-H-02");
|
||||
}catch(Exception failure){issues.add(title+" could not be confirmed. Retry /quest redeem or open the mission.");}
|
||||
}
|
||||
}
|
||||
return new ClaimBatch(recorded,replayed,refreshKits,List.copyOf(issues));
|
||||
}
|
||||
static JsonObject readyClaim(UUID player,String kind,String season,JsonObject row){
|
||||
String id=text(row,"id","");
|
||||
long revision=row.get("revision").getAsLong();
|
||||
String binding=String.join("|","quest-redeem-v1",player.toString(),kind,season,id,Long.toString(revision),text(row,"cooldownUntil",""));
|
||||
var input=new JsonObject();input.addProperty("action","claim");input.addProperty("kind",kind);
|
||||
input.addProperty("definitionId",id);input.addProperty("confirmed",true);input.addProperty("revision",revision);
|
||||
input.addProperty("requestId",UUID.nameUUIDFromBytes(binding.getBytes(java.nio.charset.StandardCharsets.UTF_8)).toString());
|
||||
return input;
|
||||
}
|
||||
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);});}
|
||||
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",""))));}
|
||||
|
|
@ -152,14 +211,27 @@ final class QuestMenus implements Listener {
|
|||
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);}
|
||||
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));}
|
||||
if(branches.isEmpty())screen.description="There are no mission branches available for your current character.";
|
||||
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);
|
||||
}
|
||||
static List<JsonObject> branchMissions(JsonObject journal,String branch){
|
||||
var rows=new ArrayList<JsonObject>();
|
||||
if(!journal.has("quests")||!journal.get("quests").isJsonArray())return rows;
|
||||
for(var entry:journal.getAsJsonArray("quests"))
|
||||
if(entry.isJsonObject()&&branch.equals(text(entry.getAsJsonObject(),"branch","")))rows.add(entry.getAsJsonObject());
|
||||
return rows;
|
||||
}
|
||||
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));}
|
||||
var rows=branchMissions(data,branch);
|
||||
int offset=Math.max(0,Math.min(page,Math.max(0,(rows.size()-1)/36)))*36;
|
||||
String branchTitle=branch;
|
||||
if(data.has("branches")&&data.get("branches").isJsonArray())for(var value:data.getAsJsonArray("branches")){
|
||||
if(value.isJsonObject()&&branch.equals(text(value.getAsJsonObject(),"id",""))){branchTitle=text(value.getAsJsonObject(),"title",branch);break;}
|
||||
}
|
||||
var screen=panel(p,"Missions · "+branchTitle);if(rows.isEmpty())screen.description="No missions are available in this branch for your current character.";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,offset/36,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);
|
||||
put(screen,45,"Branches","Choose another branch",Material.ARROW,()->branches(p,kind,data));int currentPage=offset/36;if(currentPage>0)put(screen,47,"Previous","Previous missions",Material.PAPER,()->quests(p,kind,data,branch,currentPage-1));put(screen,49,"Refresh","Read current verified quest records",Material.CLOCK,()->load(p,kind,branch,null,currentPage));if(offset+36<rows.size())put(screen,51,"Next","More missions",Material.PAPER,()->quests(p,kind,data,branch,currentPage+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");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ api-version: '1.21.8'
|
|||
depend: [JarvisTranslator]
|
||||
softdepend: [Citizens, MCGUI, DecentHolograms, DuneLobby, DuneCore, DuneEss, DuneNPC, Vault, floodgate, ViaVersion]
|
||||
commands:
|
||||
quest:
|
||||
description: Claim all ready in-game quest rewards
|
||||
usage: /quest redeem
|
||||
rosterkey:
|
||||
description: Accept a team war roster invitation
|
||||
usage: /rosterkey <code>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class QuestJournalRoutesTest {
|
||||
@Test void branchUsesCentralIdRatherThanDisplayName() {
|
||||
var journal=JsonParser.parseString("""
|
||||
{"branches":[{"id":"fremen","title":"Fremen"}],
|
||||
"quests":[{"id":"FREMEN-01","branch":"fremen"},{"id":"OTHER-01","branch":"other"}]}
|
||||
""").getAsJsonObject();
|
||||
var quests=QuestMenus.branchMissions(journal,"fremen");
|
||||
assertEquals(1,quests.size());
|
||||
assertEquals("FREMEN-01",quests.getFirst().get("id").getAsString());
|
||||
assertTrue(QuestMenus.branchMissions(journal,"unavailable").isEmpty());
|
||||
}
|
||||
@Test void retryKeepsOriginalReferenceAndNewEpisodeGetsNewReference() {
|
||||
var player=UUID.fromString("12345678-0000-4000-8000-000000000001");
|
||||
var row=JsonParser.parseString("""
|
||||
{"id":"RPT-FREMEN-01","revision":2,"cooldownUntil":1000}
|
||||
""").getAsJsonObject();
|
||||
var input=QuestMenus.readyClaim(player,"pol","S01",row);
|
||||
assertEquals(input,QuestMenus.readyClaim(player,"pol","S01",row));
|
||||
assertTrue(input.get("confirmed").getAsBoolean());
|
||||
assertEquals(2,input.get("revision").getAsInt());
|
||||
row.addProperty("id","RPT-FREMEN-02");
|
||||
assertNotEquals(input.get("requestId"),QuestMenus.readyClaim(player,"pol","S01",row).get("requestId"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff