koishipro-core.js 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +98 -83
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +95 -83
- package/dist/index.mjs.map +2 -2
- package/dist/src/ocgcore-duel.d.ts +2 -1
- package/dist/src/play-yrp.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,8 @@ __export(index_exports, {
|
|
|
60
60
|
SqljsCardReader: () => SqljsCardReader,
|
|
61
61
|
ZipReader: () => ZipReader,
|
|
62
62
|
ZipScriptReader: () => ZipScriptReader,
|
|
63
|
+
consumeResponseFromOcgcoreProcess: () => consumeResponseFromOcgcoreProcess,
|
|
64
|
+
createDuelFromYrp: () => createDuelFromYrp,
|
|
63
65
|
createOcgcoreWrapper: () => createOcgcoreWrapper,
|
|
64
66
|
createSqljsCardReader: () => createSqljsCardReader,
|
|
65
67
|
normalizeStartDuelOptions: () => normalizeStartDuelOptions,
|
|
@@ -70,6 +72,7 @@ __export(index_exports, {
|
|
|
70
72
|
parseRegistryKeys: () => parseRegistryKeys,
|
|
71
73
|
playYrp: () => playYrp,
|
|
72
74
|
playYrpStep: () => playYrpStep,
|
|
75
|
+
processYrpDuelStep: () => processYrpDuelStep,
|
|
73
76
|
testCard: () => testCard
|
|
74
77
|
});
|
|
75
78
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -562,6 +565,7 @@ var OcgcoreDuel = class {
|
|
|
562
565
|
this.duelPtr = duelPtr;
|
|
563
566
|
this.returnPtr = 0;
|
|
564
567
|
this.returnSize = 512;
|
|
568
|
+
this.ended = false;
|
|
565
569
|
}
|
|
566
570
|
startDuel(options) {
|
|
567
571
|
if (!this.returnPtr) {
|
|
@@ -571,6 +575,8 @@ var OcgcoreDuel = class {
|
|
|
571
575
|
this.ocgcoreWrapper.ocgcoreModule._start_duel(this.duelPtr, optionValue);
|
|
572
576
|
}
|
|
573
577
|
endDuel() {
|
|
578
|
+
if (this.ended) return;
|
|
579
|
+
this.ended = true;
|
|
574
580
|
this.ocgcoreWrapper.ocgcoreModule._end_duel(this.duelPtr);
|
|
575
581
|
if (this.returnPtr) {
|
|
576
582
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
@@ -691,6 +697,10 @@ var OcgcoreDuel = class {
|
|
|
691
697
|
this.ocgcoreWrapper.ocgcoreModule._set_responsei(this.duelPtr, value);
|
|
692
698
|
}
|
|
693
699
|
setResponse(response) {
|
|
700
|
+
if (typeof response === "number") {
|
|
701
|
+
this.setResponseInt(response);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
694
704
|
if (response.length > this.returnSize) {
|
|
695
705
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
696
706
|
this.returnPtr = this.ocgcoreWrapper.malloc(response.length);
|
|
@@ -2457,14 +2467,6 @@ function normalizeYrp(input) {
|
|
|
2457
2467
|
}
|
|
2458
2468
|
return new import_ygopro_yrp_encode.YGOProYrp().fromYrp(input);
|
|
2459
2469
|
}
|
|
2460
|
-
function createReplayDuel(wrapper, yrp) {
|
|
2461
|
-
const header = yrp.header;
|
|
2462
|
-
const seedSequence = header?.seedSequence ?? [];
|
|
2463
|
-
if (seedSequence.length > 0) {
|
|
2464
|
-
return wrapper.createDuelV2(seedSequence);
|
|
2465
|
-
}
|
|
2466
|
-
return wrapper.createDuel(header?.seed ?? 0);
|
|
2467
|
-
}
|
|
2468
2470
|
function loadDeck(duel, deck, owner, player) {
|
|
2469
2471
|
if (!deck) return;
|
|
2470
2472
|
for (const code of deck.main ?? []) {
|
|
@@ -2508,87 +2510,97 @@ function loadTagDeck(duel, deck, owner) {
|
|
|
2508
2510
|
function setRegistryValue(duel, key, value) {
|
|
2509
2511
|
duel.setRegistryValue(key, value);
|
|
2510
2512
|
}
|
|
2511
|
-
function
|
|
2513
|
+
function createDuelFromYrp(wrapper, yrpInput) {
|
|
2512
2514
|
const yrp = normalizeYrp(yrpInput);
|
|
2513
|
-
const
|
|
2514
|
-
const
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2515
|
+
const header = yrp.header;
|
|
2516
|
+
const seedSequence = header?.seedSequence ?? [];
|
|
2517
|
+
const duel = seedSequence.length > 0 ? wrapper.createDuelV2(seedSequence) : wrapper.createDuel(header?.seed ?? 0);
|
|
2518
|
+
setRegistryValue(duel, "duel_mode", yrp.isTag ? "tag" : "single");
|
|
2519
|
+
setRegistryValue(duel, "start_lp", String(yrp.startLp));
|
|
2520
|
+
setRegistryValue(duel, "start_hand", String(yrp.startHand));
|
|
2521
|
+
setRegistryValue(duel, "draw_count", String(yrp.drawCount));
|
|
2522
|
+
const playerNames = yrp.isTag ? [
|
|
2523
|
+
yrp.hostName,
|
|
2524
|
+
yrp.tagHostName ?? "",
|
|
2525
|
+
yrp.tagClientName ?? "",
|
|
2526
|
+
yrp.clientName
|
|
2527
|
+
] : [yrp.hostName, yrp.clientName];
|
|
2528
|
+
for (let i = 0; i < playerNames.length; i++) {
|
|
2529
|
+
setRegistryValue(duel, `player_name_${i}`, playerNames[i] ?? "");
|
|
2530
|
+
}
|
|
2531
|
+
setRegistryValue(duel, "player_type_0", "0");
|
|
2532
|
+
setRegistryValue(duel, "player_type_1", "1");
|
|
2533
|
+
duel.setPlayerInfo({
|
|
2534
|
+
player: 0,
|
|
2535
|
+
lp: yrp.startLp,
|
|
2536
|
+
startHand: yrp.startHand,
|
|
2537
|
+
drawCount: yrp.drawCount
|
|
2538
|
+
});
|
|
2539
|
+
duel.setPlayerInfo({
|
|
2540
|
+
player: 1,
|
|
2541
|
+
lp: yrp.startLp,
|
|
2542
|
+
startHand: yrp.startHand,
|
|
2543
|
+
drawCount: yrp.drawCount
|
|
2544
|
+
});
|
|
2545
|
+
duel.preloadScript("./script/patches/entry.lua");
|
|
2546
|
+
duel.preloadScript("./script/special.lua");
|
|
2547
|
+
duel.preloadScript("./script/init.lua");
|
|
2548
|
+
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2549
|
+
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2550
|
+
} else if (yrp.isTag) {
|
|
2551
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2552
|
+
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2553
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2554
|
+
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2555
|
+
} else {
|
|
2556
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2557
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2558
|
+
}
|
|
2559
|
+
duel.startDuel(yrp.opt >>> 0);
|
|
2560
|
+
return { yrp, duel };
|
|
2561
|
+
}
|
|
2562
|
+
function consumeResponseFromOcgcoreProcess(duel, result, responses) {
|
|
2563
|
+
if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
2564
|
+
throw new Error("Got MSG_RETRY");
|
|
2565
|
+
}
|
|
2566
|
+
if (result.status === 0) {
|
|
2567
|
+
return false;
|
|
2568
|
+
}
|
|
2569
|
+
if (result.status === 1) {
|
|
2570
|
+
if (result.raw.length === 0) {
|
|
2571
|
+
return false;
|
|
2534
2572
|
}
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
player: 0,
|
|
2539
|
-
lp: yrp.startLp,
|
|
2540
|
-
startHand: yrp.startHand,
|
|
2541
|
-
drawCount: yrp.drawCount
|
|
2542
|
-
});
|
|
2543
|
-
duel.setPlayerInfo({
|
|
2544
|
-
player: 1,
|
|
2545
|
-
lp: yrp.startLp,
|
|
2546
|
-
startHand: yrp.startHand,
|
|
2547
|
-
drawCount: yrp.drawCount
|
|
2548
|
-
});
|
|
2549
|
-
duel.preloadScript("./script/patches/entry.lua");
|
|
2550
|
-
duel.preloadScript("./script/special.lua");
|
|
2551
|
-
duel.preloadScript("./script/init.lua");
|
|
2552
|
-
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2553
|
-
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2554
|
-
} else if (yrp.isTag) {
|
|
2555
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2556
|
-
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2557
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2558
|
-
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2559
|
-
} else {
|
|
2560
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2561
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2573
|
+
const response = responses.shift();
|
|
2574
|
+
if (!response) {
|
|
2575
|
+
return true;
|
|
2562
2576
|
}
|
|
2563
|
-
duel.
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
if (result.raw.length === 0) {
|
|
2579
|
-
continue;
|
|
2580
|
-
}
|
|
2581
|
-
const response = responses.shift();
|
|
2582
|
-
if (!response) {
|
|
2583
|
-
break;
|
|
2584
|
-
}
|
|
2585
|
-
duel.setResponse(response);
|
|
2586
|
-
continue;
|
|
2587
|
-
}
|
|
2577
|
+
duel.setResponse(response);
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
return true;
|
|
2581
|
+
}
|
|
2582
|
+
function* processYrpDuelStep(duel, yrp) {
|
|
2583
|
+
const responses = yrp.responses.slice();
|
|
2584
|
+
while (true) {
|
|
2585
|
+
const result = duel.process();
|
|
2586
|
+
yield {
|
|
2587
|
+
duel,
|
|
2588
|
+
result,
|
|
2589
|
+
responses
|
|
2590
|
+
};
|
|
2591
|
+
if (consumeResponseFromOcgcoreProcess(duel, result, responses)) {
|
|
2588
2592
|
break;
|
|
2589
2593
|
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
2597
|
+
const { yrp, duel } = createDuelFromYrp(ocgcoreWrapper, yrpInput);
|
|
2598
|
+
try {
|
|
2599
|
+
for (const stepResult of processYrpDuelStep(duel, yrp)) {
|
|
2600
|
+
yield stepResult;
|
|
2601
|
+
}
|
|
2590
2602
|
} finally {
|
|
2591
|
-
endDuel();
|
|
2603
|
+
duel.endDuel();
|
|
2592
2604
|
}
|
|
2593
2605
|
}
|
|
2594
2606
|
var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
@@ -2671,6 +2683,8 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2671
2683
|
SqljsCardReader,
|
|
2672
2684
|
ZipReader,
|
|
2673
2685
|
ZipScriptReader,
|
|
2686
|
+
consumeResponseFromOcgcoreProcess,
|
|
2687
|
+
createDuelFromYrp,
|
|
2674
2688
|
createOcgcoreWrapper,
|
|
2675
2689
|
createSqljsCardReader,
|
|
2676
2690
|
normalizeStartDuelOptions,
|
|
@@ -2681,6 +2695,7 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2681
2695
|
parseRegistryKeys,
|
|
2682
2696
|
playYrp,
|
|
2683
2697
|
playYrpStep,
|
|
2698
|
+
processYrpDuelStep,
|
|
2684
2699
|
testCard
|
|
2685
2700
|
});
|
|
2686
2701
|
//# sourceMappingURL=index.cjs.map
|