Allow unaccepted cooperative cargo invitations to be declined or withdrawn safely
This commit is contained in:
parent
2a5fca0583
commit
1669b3bc2a
3 changed files with 13 additions and 3 deletions
|
|
@ -113,7 +113,7 @@ final class QuestMenus implements Listener {
|
|||
if(kind.equals("pol")&&Set.of("pol-jerboa-meat-25","pol-jerboa-meat-50").contains(text(row,"metric",""))&&!state.equals("claimed")&&!yes(row,"canClaim")&&(yes(row,"canStart")||state.equals("active")))put(screen,33,"Surrender cooked Jerboa meat","Stand near Shadout Mapes on Arrakis.\nSurrender the required genuine cooked Jerboa meat; no reuse of previous turn-ins.",Material.COOKED_RABBIT,()->meatTurnin(p,kind,branch,page,row));
|
||||
if(kind.equals("pol")&&row.has("supply")&&!row.get("supply").isJsonNull()&&!state.equals("claimed")&&!yes(row,"canClaim")&&(yes(row,"canStart")||state.equals("active"))){var supply=row.getAsJsonObject("supply");put(screen,33,"Surrender mission supplies","Stand near "+text(supply,"contact","the mission contact")+".\nSurrender "+supply.get("quantity").getAsInt()+" genuine "+text(supply,"label","supplies")+".",Material.CHEST,()->supplyTurnin(p,kind,branch,page,row));}
|
||||
if(kind.equals("pol")&&role!=null&&row.has("dossier")&&!row.get("dossier").isJsonNull()&&!yes(row,"canClaim")&&state.equals("active")){var dossier=row.getAsJsonObject("dossier");String next=text(dossier,"role","");put(screen,22,"Mission contact",text(dossier,"dialogue","")+"\nNext: "+next.replace('_',' '),Material.WRITABLE_BOOK,null);if(role.key().equals(next)&&!yes(dossier,"complete")){int stage=dossier.get("stage").getAsInt();if(stage<2)put(screen,33,stage==0?"Record briefing":"Record witness clue","Confirm this actual NPC interaction",Material.BOOK,()->dossierStep(p,data,role,row,stage,null));else if(dossier.has("answers")){int n=0;for(var answer:dossier.getAsJsonArray("answers")){int i=n++;put(screen,34+i,answer.getAsString(),"Submit this conclusion",Material.PAPER,()->dossierStep(p,data,role,row,stage,i));}}}}
|
||||
if(kind.equals("pol")&&role!=null&&row.has("cargo")&&!row.get("cargo").isJsonNull()&&state.equals("active")&&!yes(row,"canClaim")){var cargo=row.getAsJsonObject("cargo");String phase=text(cargo,"stage",""),target=text(cargo,"role","");put(screen,22,"Assigned manifest",text(cargo,"quantity","—")+" × "+text(cargo,"item","Cargo")+"\nNext contact: "+target.replace('_',' ')+" · "+text(cargo,"server","").replace('-',' '),Material.CHEST,null);if(role.key().equals(target)&&phase.equals("seal"))put(screen,33,"Seal original cargo","Surrender the required genuine supplies into your bound parcel",Material.CHEST,()->cargoMission(p,role,row,phase));if(role.key().equals(target)&&phase.equals("pickup"))put(screen,33,"Collect sealed cargo","Receive the original company-funded parcel assigned to you",Material.CHEST,()->cargoMission(p,role,row,phase));if(role.key().equals(target)&&phase.equals("deliver")){if(yes(cargo,"routeReady"))put(screen,33,"Deliver sealed parcel","Surrender the exact original cargo after the required confirmed passage",Material.PAPER,()->cargoMission(p,role,row,phase));else put(screen,33,"Confirmed passage required","Take the assigned Guild route after sealing or collecting your parcel",Material.CLOCK,null);}if(role.key().equals(target)&&phase.equals("partner")){String partner=text(cargo,"partnerState","");if(partner.equals("choose"))put(screen,33,"Choose a mission partner","Select a player with the matching active mission and current affiliation",Material.PLAYER_HEAD,()->cargoPartners(p,data,role,row,0));else if(partner.equals("accept"))put(screen,33,"Accept cooperative assignment","Confirm the exact incoming partner assignment",Material.LIME_DYE,()->cargoPartner(p,role,row,"accept",text(cargo,"pairId","")));else put(screen,33,"Waiting for your partner","Both players must expressly accept the exact cooperative assignment",Material.CLOCK,null);}if(phase.equals("escort"))put(screen,33,"Escort the carrier","Complete your own confirmed Guild passage on the same assigned route within two minutes of your partner. The carrier delivers the parcel.",Material.COMPASS,null);if(phase.equals("wait"))put(screen,33,"Waiting for assigned carrier","The other accepted party must complete their assigned step.",Material.CLOCK,null);}
|
||||
if(kind.equals("pol")&&role!=null&&row.has("cargo")&&!row.get("cargo").isJsonNull()&&state.equals("active")&&!yes(row,"canClaim")){var cargo=row.getAsJsonObject("cargo");String phase=text(cargo,"stage",""),target=text(cargo,"role","");put(screen,22,"Assigned manifest",text(cargo,"quantity","—")+" × "+text(cargo,"item","Cargo")+"\nNext contact: "+target.replace('_',' ')+" · "+text(cargo,"server","").replace('-',' '),Material.CHEST,null);if(role.key().equals(target)&&phase.equals("seal"))put(screen,33,"Seal original cargo","Surrender the required genuine supplies into your bound parcel",Material.CHEST,()->cargoMission(p,role,row,phase));if(role.key().equals(target)&&phase.equals("pickup"))put(screen,33,"Collect sealed cargo","Receive the original company-funded parcel assigned to you",Material.CHEST,()->cargoMission(p,role,row,phase));if(role.key().equals(target)&&phase.equals("deliver")){if(yes(cargo,"routeReady"))put(screen,33,"Deliver sealed parcel","Surrender the exact original cargo after the required confirmed passage",Material.PAPER,()->cargoMission(p,role,row,phase));else put(screen,33,"Confirmed passage required","Take the assigned Guild route after sealing or collecting your parcel",Material.CLOCK,null);}if(role.key().equals(target)&&phase.equals("partner")){String partner=text(cargo,"partnerState","");if(partner.equals("choose"))put(screen,33,"Choose a mission partner","Select a player with the matching active mission and current affiliation",Material.PLAYER_HEAD,()->cargoPartners(p,data,role,row,0));else if(partner.equals("accept")){put(screen,33,"Accept cooperative assignment","Confirm the exact incoming partner assignment",Material.LIME_DYE,()->cargoPartner(p,role,row,"accept",text(cargo,"pairId","")));put(screen,34,"Decline invitation","Close the unaccepted invitation without moving any cargo",Material.RED_DYE,()->cargoPartner(p,role,row,"decline",text(cargo,"pairId","")));}else{put(screen,33,"Waiting for your partner","Both players must expressly accept the exact cooperative assignment",Material.CLOCK,null);put(screen,34,"Withdraw invitation","Close the unaccepted invitation without moving any cargo",Material.RED_DYE,()->cargoPartner(p,role,row,"withdraw",text(cargo,"pairId","")));}}if(phase.equals("escort"))put(screen,33,"Escort the carrier","Complete your own confirmed Guild passage on the same assigned route within two minutes of your partner. The carrier delivers the parcel.",Material.COMPASS,null);if(phase.equals("wait"))put(screen,33,"Waiting for assigned carrier","The other accepted party must complete their assigned step.",Material.CLOCK,null);}
|
||||
if(kind.equals("personal")&&(yes(row,"canStart")||Set.of("active","completed","claimed").contains(state))){
|
||||
if(text(row,"id","").equals("S1-H-01"))put(screen,33,"Collect House T0 kit","Available directly from /start.\nFour Common MK 0 stillsuit pieces at half durability.\nOne Uncommon MK I wooden spice shovel.\nOne original kit per account and season.",Material.NETHERITE_CHESTPLATE,()->starter(p,kind,branch,page,row,"obtain"));
|
||||
if(text(row,"id","").equals("S1-H-02")){put(screen,29,"Prepare four repair parts","Buy, craft with genuine spice or collect native 5% mob drops.\nRepair plate, Binding patch, Tool fitting, Calibration piece.\nOptional: prepare all four from the ordinary materials.",Material.IRON_INGOT,()->starter(p,kind,branch,page,row,"parts"));put(screen,33,"Surrender original kit & parts","Hand in the four original bound armour pieces\nand all four verified repair parts.\nThen claim this quest to receive the intact kit.",Material.ANVIL,()->starter(p,kind,branch,page,row,"repair"));}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import {randomUUID} from 'node:crypto';
|
||||
import {POL_CARGO_DESTINATIONS} from '../control-panel/public/cp-v2/cp-v2-pol-cargo-policy.mjs';
|
||||
import {starterIdentity} from './starter-kit-native-design.mjs';
|
||||
import {createPOLActivityEvents} from './pol-activity-events.mjs';
|
||||
|
|
@ -27,13 +28,14 @@ export function createPOLCoopCargo(db,bank,keys,{clock=Date.now}={}){
|
|||
if(row.delivered_at)return {stage:'complete',role:row.destination_role,server:row.destination,item:t.label,quantity:t.quantity};
|
||||
if(!row.sealed_at)return {stage:row.primary_id===actor.id?'seal':'wait',role:'edric',server:'lobby',item:t.label,quantity:t.quantity};
|
||||
const owner=carrier(row,t);if(t.kind==='recovery'&&!row.picked_at)return {stage:owner.id===actor.id?'pickup':'wait',role:'edric',server:'lobby',item:t.label,quantity:t.quantity};return {stage:owner.id===actor.id?'deliver':'escort',role:row.destination_role,server:row.destination,item:t.label,quantity:t.quantity,routeReady:!!row.route_id||(await routes(row,t)).length>0};}
|
||||
async function partner(actor,input,q){const t=match(q.id);if(!t||!bank||input.npcRole!=='edric'||input.server!=='lobby'||!validUuid(input.npcUuid)||!['offer','accept'].includes(input.phase))fail('Meet Edric with your currently accepted cooperative mission.');const now=clock();return db.transaction(async tx=>{
|
||||
async function partner(actor,input,q){const t=match(q.id);if(!t||!bank||input.npcRole!=='edric'||input.server!=='lobby'||!validUuid(input.npcUuid)||!['offer','accept','withdraw','decline'].includes(input.phase))fail('Meet Edric with your currently accepted cooperative mission.');const now=clock();return db.transaction(async tx=>{
|
||||
if(!await currentActivityPlayer(tx,actor.id,input.uuid.toLowerCase(),{lock:true}))fail('Current linked player required.');const active=await first(tx,"SELECT season_id FROM jarvis_pol_progression_seasons WHERE season_id='S01' AND state='active' AND starts_at<=? AND ends_at>? FOR UPDATE",[now,now]);if(!active)fail('Current POL season required.');
|
||||
if(['withdraw','decline'].includes(input.phase)){if(input.partnerId||!validUuid(input.pairId))fail('Choose the exact unaccepted invitation.');const row=await pair(tx,actor,q.id,true);if(!row||row.id!==input.pairId||row.accepted_at!==null||row.sealed_at!==null||(input.phase==='withdraw')!==(row.proposed_by===actor.id))fail('Only the appropriate party can close an unaccepted invitation.');await tx.query('INSERT INTO account_audit(id,actor_id,action,details,created_at) VALUES(?,?,?,?,?)',[randomUUID(),actor.id,'cooperative-cargo-'+input.phase,JSON.stringify({pairId:row.id,primaryKey:row.primary_key,assistantKey:row.assistant_key}),now]);await tx.query('DELETE FROM jarvis_pol_coop_cargo WHERE id=? AND accepted_at IS NULL AND sealed_at IS NULL',[row.id]);return{ok:true,pairId:row.id,cancelled:true};}
|
||||
if(input.phase==='accept'){if(input.partnerId||!validUuid(input.pairId))fail('Choose the exact invitation.');const row=await pair(tx,actor,q.id,true);if(!row||row.id!==input.pairId||row.proposed_by===actor.id)fail('That is not your incoming invitation.');const p=await character(tx,row.primary_id,row.primary_quest,true),a=await character(tx,row.assistant_id,row.assistant_quest,true);if(p?.key_id!==row.primary_key||a?.key_id!==row.assistant_key||!await compatible(tx,t,p,a))fail('Current partner qualification changed.');if(!row.accepted_at)await tx.query('UPDATE jarvis_pol_coop_cargo SET accepted_at=? WHERE id=?',[now,row.id]);return{ok:true,pairId:row.id,accepted:true};}
|
||||
if(input.pairId||!validUuid(input.partnerId)||input.partnerId===actor.id)fail('Select an eligible different partner.');const otherQuest=t.primary===q.id?t.assistant:t.primary;
|
||||
// Both existing quest records are locked in account order before any pairing.
|
||||
const ids=[actor.id,input.partnerId].sort(),locked=new Map();for(const id of ids)locked.set(id,await character(tx,id,id===actor.id?q.id:otherQuest,true));const me=locked.get(actor.id),other=locked.get(input.partnerId),primary=t.primary===q.id?me:other,assistant=primary?.id===actor.id?other:me;
|
||||
if(!await compatible(tx,t,primary,assistant)||me.minecraft_uuid!==input.uuid.toLowerCase())fail('Both players must have the matching active mission and current eligible affiliation.');if(await pair(tx,actor,q.id,true)||await pair(tx,other,otherQuest,true))fail('One of these exact missions already has a partner.');const owner=t.kind==='recovery'?assistant:primary,dest=POL_CARGO_DESTINATIONS[owner.faction],id=starterIdentity('pol-cooperative-cargo:'+primary.key_id+':'+assistant.key_id),delivery=starterIdentity('pol-cooperative-delivery:'+id),pickup=starterIdentity('pol-cooperative-pickup:'+id);
|
||||
if(!await compatible(tx,t,primary,assistant)||me.minecraft_uuid!==input.uuid.toLowerCase())fail('Both players must have the matching active mission and current eligible affiliation.');if(await pair(tx,actor,q.id,true)||await pair(tx,other,otherQuest,true))fail('One of these exact missions already has a partner.');const owner=t.kind==='recovery'?assistant:primary,dest=POL_CARGO_DESTINATIONS[owner.faction],id=randomUUID(),delivery=starterIdentity('pol-cooperative-delivery:'+id),pickup=starterIdentity('pol-cooperative-pickup:'+id);
|
||||
await tx.query('INSERT INTO jarvis_pol_coop_cargo(id,kind,primary_id,primary_uuid,primary_quest,primary_key,assistant_id,assistant_uuid,assistant_quest,assistant_key,proposed_by,created_at,destination,destination_role,delivery_id,pickup_id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',[id,t.kind,primary.id,primary.minecraft_uuid,t.primary,primary.key_id,assistant.id,assistant.minecraft_uuid,t.assistant,assistant.key_id,actor.id,now,dest.server,dest.role,delivery,pickup]);return {ok:true,pairId:id,accepted:false};
|
||||
});}
|
||||
async function prepare(actor,input,q){const t=match(q.id);if(!t||!['seal','pickup','deliver'].includes(input.phase)||!validUuid(input.npcUuid))fail('Choose your current cooperative cargo assignment.');const old=await pair(db,actor,q.id),routeOptions=old?.sealed_at&&input.phase==='deliver'?await routes(old,t):[];return db.transaction(async tx=>{if(!await currentActivityPlayer(tx,actor.id,input.uuid.toLowerCase(),{lock:true}))fail('Current linked player required.');const row=await pair(tx,actor,q.id,true);if(!row||!row.accepted_at)fail('Both players must explicitly accept this exact cooperative mission.');const p=await character(tx,row.primary_id,row.primary_quest,true),a=await character(tx,row.assistant_id,row.assistant_quest,true);if(p?.key_id!==row.primary_key||a?.key_id!==row.assistant_key||!await compatible(tx,t,p,a))fail('Current partner qualification changed.');const owner=carrier(row,t),now=clock();if(input.phase==='seal'){if(row.primary_id!==actor.id||input.server!=='lobby'||input.npcRole!=='edric'||row.delivered_at)fail('The original commissioning player must seal the cargo at Edric.');}
|
||||
|
|
|
|||
|
|
@ -148,10 +148,18 @@ test('cooperative escort requires mutual consent, both actual arrivals and one o
|
|||
await f.runtime.quests.start(f.actor,{definitionId:id});
|
||||
await assert.rejects(service.partner(f.actor,{...base,phase:'offer',partnerId:f.other.id},q),/matching active/);
|
||||
await f.runtime.quests.start(f.other,{definitionId:id});
|
||||
const abandoned=await service.partner(f.actor,{...base,phase:'offer',partnerId:f.other.id},q);
|
||||
await assert.rejects(service.partner(f.actor,{...base,phase:'decline',pairId:abandoned.pairId},q),/appropriate party/);
|
||||
await service.partner(f.other,{...base,uuid:f.otherUuid,phase:'decline',pairId:abandoned.pairId},q);
|
||||
const withdrawn=await service.partner(f.actor,{...base,phase:'offer',partnerId:f.other.id},q);
|
||||
await service.partner(f.actor,{...base,phase:'withdraw',pairId:withdrawn.pairId},q);
|
||||
const offer=await service.partner(f.actor,{...base,phase:'offer',partnerId:f.other.id},q);
|
||||
assert.notEqual(offer.pairId,abandoned.pairId);assert.notEqual(offer.pairId,withdrawn.pairId);
|
||||
await assert.rejects(service.partner(f.other,{...base,uuid:f.otherUuid,phase:'accept',pairId:abandoned.pairId},q),/incoming/);
|
||||
await assert.rejects(service.prepare(f.actor,{...base,phase:'seal'},q),/explicitly accept/);
|
||||
await assert.rejects(service.partner(f.actor,{...base,phase:'accept',pairId:offer.pairId},q),/incoming/);
|
||||
await service.partner(f.other,{...base,uuid:f.otherUuid,phase:'accept',pairId:offer.pairId},q);
|
||||
await assert.rejects(service.partner(f.actor,{...base,phase:'withdraw',pairId:offer.pairId},q),/unaccepted invitation/);
|
||||
const seal=await service.prepare(f.actor,{...base,phase:'seal'},q);
|
||||
assert.equal(seal.quantity,4);assert.equal(seal.cargoOwnerUuid,f.uuid);
|
||||
await service.record({...f.base(),kind:'cargo_seal',eventId:seal.requestId,server:'lobby'});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff