Port NPC-bound meat and supply turn-ins to the mission journal
This commit is contained in:
parent
97d958609d
commit
be5500d1eb
4 changed files with 84 additions and 3 deletions
|
|
@ -31,7 +31,8 @@ public interface Backend {
|
|||
record Org(String name, String role, int members, Long vaultMinor, String id, String revision, String warKey) {}
|
||||
record Member(UUID id, String name, String role) {}
|
||||
/** state is one of ACTIVE, AVAILABLE, DONE. */
|
||||
record Mission(String id, String title, Material icon, String state, int percent, boolean claimable, String summary, Long revision) {}
|
||||
record TurnIn(String action, String role, String metric, String label, int quantity) {}
|
||||
record Mission(String id, String title, Material icon, String state, int percent, boolean claimable, String summary, Long revision, TurnIn turnIn) {}
|
||||
record Spice(int carried, int guildCount, int smugglerCount, boolean guildEnabled, boolean smugglerEnabled, int pendingCount) {}
|
||||
/** roster has 8 entries; blank = empty slot. */
|
||||
record War(String title, List<String> roster, List<String> status, boolean canLaunch, boolean editable, UUID draftId) {}
|
||||
|
|
@ -70,6 +71,7 @@ public interface Backend {
|
|||
default CompletableFuture<Result> orgAction(Player p, String kind, String action, Org shown) { return na(); }
|
||||
// ---- missions ----
|
||||
default CompletableFuture<List<Mission>> missions(Player p) { return na(); }
|
||||
default CompletableFuture<Result> missionTurnIn(Player p, Mission mission) { return na(); }
|
||||
default CompletableFuture<Result> missionAction(Player p, Mission mission, boolean claim) { return na(); }
|
||||
// ---- spice (channel is "guild" | "smuggler") ----
|
||||
default CompletableFuture<Spice> spice(Player p) { return na(); }
|
||||
|
|
|
|||
|
|
@ -600,12 +600,73 @@ final class JarvisBackend implements Backend, Listener {
|
|||
long progress = row.has("progress") ? row.get("progress").getAsLong() : 0;
|
||||
int percent = target <= 0 ? 0 : (int)Math.max(0, Math.min(100, Math.round(progress * 100d / target)));
|
||||
result.add(new Mission(kind+":"+text(row,"id"), display(row,"title"), Material.WRITABLE_BOOK,
|
||||
state, percent, claim, display(row,"objective"), revision(row)));
|
||||
state, percent, claim, display(row,"objective"), revision(row), kind.equals("pol") ? turnIn(row) : null));
|
||||
}
|
||||
return List.copyOf(result);
|
||||
});
|
||||
}
|
||||
|
||||
static TurnIn turnIn(JsonObject row) {
|
||||
String state=text(row,"state");
|
||||
if(websiteOnly(row)||yes(row,"canClaim")||state.equals("claimed")||!(yes(row,"canStart")||state.equals("active")))return null;
|
||||
var supply=row.get("supply");
|
||||
if(supply!=null&&supply.isJsonObject()){
|
||||
var requirement=supply.getAsJsonObject();
|
||||
String role=text(requirement,"role"), item=text(requirement,"item");
|
||||
if(role.isBlank()||item.isBlank()||!requirement.has("quantity"))return null;
|
||||
int quantity=requirement.get("quantity").getAsInt();
|
||||
if(quantity<1)return null;
|
||||
return new TurnIn("prepare_pol_supply",role,item,display(requirement,"label"),quantity);
|
||||
}
|
||||
String metric=text(row,"metric");
|
||||
if(Set.of("pol-jerboa-meat-25","pol-jerboa-meat-50").contains(metric))
|
||||
return new TurnIn("prepare_husbandry_turnin","shadout_mapes",metric,"cooked Jerboa meat",0);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public CompletableFuture<Result> missionTurnIn(Player player, Mission mission) {
|
||||
TurnIn shown=mission.turnIn();
|
||||
if(shown==null||!mission.id().startsWith("pol:"))return CompletableFuture.completedFuture(Result.no("This turn-in is unavailable."));
|
||||
UUID owner=player.getUniqueId();
|
||||
return once(player,()->{
|
||||
UUID npc;
|
||||
try { npc=jarvis.questCharacterNpc(player,shown.role()); }
|
||||
catch(RuntimeException failure){return CompletableFuture.completedFuture(Result.no("Stand near the assigned mission contact."));}
|
||||
String id=mission.id().substring(4);
|
||||
return remote(player,()->{
|
||||
for(var entry:quests(owner,"pol")){
|
||||
var row=entry.getAsJsonObject();
|
||||
if(!id.equals(text(row,"id")))continue;
|
||||
if(!shown.equals(turnIn(row))||!java.util.Objects.equals(mission.revision(),revision(row)))
|
||||
throw new IOException("The mission changed. Reopen your journal.");
|
||||
var request=action(shown.action());
|
||||
request.addProperty("kind","pol");
|
||||
request.addProperty("definitionId",id);
|
||||
request.addProperty("npcUuid",npc.toString());
|
||||
request.addProperty("confirmed",true);
|
||||
request.addProperty("requestId",UUID.randomUUID().toString());
|
||||
return accepted(jarvis.requestQuests(owner,request));
|
||||
}
|
||||
throw new IOException("The mission is no longer available.");
|
||||
}).thenApply(permit->{
|
||||
try {
|
||||
if(!npc.equals(jarvis.questCharacterNpc(player,shown.role())))
|
||||
return Result.no("Return to the original mission contact.");
|
||||
if(shown.action().equals("prepare_husbandry_turnin"))jarvis.husbandryTurnin(player,permit);
|
||||
else {
|
||||
if(!shown.role().equals(text(permit,"role"))||!shown.metric().equals(text(permit,"item"))
|
||||
||permit.get("quantity").getAsInt()!=shown.quantity())
|
||||
return Result.no("Mission supplies changed. Reopen your journal.");
|
||||
jarvis.polSupplyTurnin(player,permit);
|
||||
}
|
||||
return Result.yes("Turn-in recorded.");
|
||||
}catch(Exception failure){
|
||||
return Result.no(failure.getMessage()==null?"The turn-in could not be recorded.":failure.getMessage());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override public CompletableFuture<Result> missionAction(Player player, Mission mission, boolean claim) {
|
||||
UUID owner = player.getUniqueId();
|
||||
return once(player, () -> remote(player, () -> {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,12 @@ final class MissionsMenu extends Menu {
|
|||
put(base + 1 + i, Ui.pane(i < filled ? Material.LIME_STAINED_GLASS_PANE : Material.GRAY_STAINED_GLASS_PANE));
|
||||
if (m.claimable())
|
||||
put(base + 8, Ui.glow(Ui.item(Material.EMERALD, "<green><b>Claim reward</b> <gray>· " + m.title())), t -> act(backend().missionAction(player, m, true)));
|
||||
else if (m.state().equals("AVAILABLE"))
|
||||
else if (m.turnIn() != null) {
|
||||
var turnIn = m.turnIn();
|
||||
String items = (turnIn.quantity() > 0 ? turnIn.quantity() + " " : "") + turnIn.label();
|
||||
put(base + 8, Ui.item(Material.CHEST, "<gold>Surrender " + items,
|
||||
"<gray>Visit " + turnIn.role().replace('_', ' ')), click -> act(backend().missionTurnIn(player, m)));
|
||||
} else if (m.state().equals("AVAILABLE"))
|
||||
put(base + 8, Ui.item(Material.LIME_DYE, "<green><b>Start</b> <gray>· " + m.title()), t -> act(backend().missionAction(player, m, false)));
|
||||
else if (m.state().equals("DONE"))
|
||||
put(base + 8, Ui.item(Material.GREEN_STAINED_GLASS_PANE, "<green>Done"));
|
||||
|
|
|
|||
|
|
@ -88,4 +88,17 @@ class JarvisBackendTest {
|
|||
assertSame(chosen, JarvisBackend.selectOrganisation(rows, "clan:11"));
|
||||
rows.remove(chosen);
|
||||
assertThrows(java.io.IOException.class, () -> JarvisBackend.selectOrganisation(rows, "clan:11"));
|
||||
} @Test void nativeTurnInKeepsExactSupplyAndContactAndDisappearsWhenClaimable() {
|
||||
var row = new JsonObject();
|
||||
row.addProperty("state", "active");
|
||||
var supply = new JsonObject();
|
||||
supply.addProperty("role", "stilgar");
|
||||
supply.addProperty("item", "jerboa_water_vial");
|
||||
supply.addProperty("label", "Water Vials");
|
||||
supply.addProperty("quantity", 6);
|
||||
row.add("supply", supply);
|
||||
assertEquals(new Backend.TurnIn("prepare_pol_supply","stilgar","jerboa_water_vial","Water Vials",6),
|
||||
JarvisBackend.turnIn(row));
|
||||
row.addProperty("canClaim", true);
|
||||
assertNull(JarvisBackend.turnIn(row));
|
||||
}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff