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.mjs
CHANGED
|
@@ -499,6 +499,7 @@ var OcgcoreDuel = class {
|
|
|
499
499
|
this.duelPtr = duelPtr;
|
|
500
500
|
this.returnPtr = 0;
|
|
501
501
|
this.returnSize = 512;
|
|
502
|
+
this.ended = false;
|
|
502
503
|
}
|
|
503
504
|
startDuel(options) {
|
|
504
505
|
if (!this.returnPtr) {
|
|
@@ -508,6 +509,8 @@ var OcgcoreDuel = class {
|
|
|
508
509
|
this.ocgcoreWrapper.ocgcoreModule._start_duel(this.duelPtr, optionValue);
|
|
509
510
|
}
|
|
510
511
|
endDuel() {
|
|
512
|
+
if (this.ended) return;
|
|
513
|
+
this.ended = true;
|
|
511
514
|
this.ocgcoreWrapper.ocgcoreModule._end_duel(this.duelPtr);
|
|
512
515
|
if (this.returnPtr) {
|
|
513
516
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
@@ -628,6 +631,10 @@ var OcgcoreDuel = class {
|
|
|
628
631
|
this.ocgcoreWrapper.ocgcoreModule._set_responsei(this.duelPtr, value);
|
|
629
632
|
}
|
|
630
633
|
setResponse(response) {
|
|
634
|
+
if (typeof response === "number") {
|
|
635
|
+
this.setResponseInt(response);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
631
638
|
if (response.length > this.returnSize) {
|
|
632
639
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
633
640
|
this.returnPtr = this.ocgcoreWrapper.malloc(response.length);
|
|
@@ -2372,14 +2379,6 @@ function normalizeYrp(input) {
|
|
|
2372
2379
|
}
|
|
2373
2380
|
return new YGOProYrp().fromYrp(input);
|
|
2374
2381
|
}
|
|
2375
|
-
function createReplayDuel(wrapper, yrp) {
|
|
2376
|
-
const header = yrp.header;
|
|
2377
|
-
const seedSequence = header?.seedSequence ?? [];
|
|
2378
|
-
if (seedSequence.length > 0) {
|
|
2379
|
-
return wrapper.createDuelV2(seedSequence);
|
|
2380
|
-
}
|
|
2381
|
-
return wrapper.createDuel(header?.seed ?? 0);
|
|
2382
|
-
}
|
|
2383
2382
|
function loadDeck(duel, deck, owner, player) {
|
|
2384
2383
|
if (!deck) return;
|
|
2385
2384
|
for (const code of deck.main ?? []) {
|
|
@@ -2423,87 +2422,97 @@ function loadTagDeck(duel, deck, owner) {
|
|
|
2423
2422
|
function setRegistryValue(duel, key, value) {
|
|
2424
2423
|
duel.setRegistryValue(key, value);
|
|
2425
2424
|
}
|
|
2426
|
-
function
|
|
2425
|
+
function createDuelFromYrp(wrapper, yrpInput) {
|
|
2427
2426
|
const yrp = normalizeYrp(yrpInput);
|
|
2428
|
-
const
|
|
2429
|
-
const
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2427
|
+
const header = yrp.header;
|
|
2428
|
+
const seedSequence = header?.seedSequence ?? [];
|
|
2429
|
+
const duel = seedSequence.length > 0 ? wrapper.createDuelV2(seedSequence) : wrapper.createDuel(header?.seed ?? 0);
|
|
2430
|
+
setRegistryValue(duel, "duel_mode", yrp.isTag ? "tag" : "single");
|
|
2431
|
+
setRegistryValue(duel, "start_lp", String(yrp.startLp));
|
|
2432
|
+
setRegistryValue(duel, "start_hand", String(yrp.startHand));
|
|
2433
|
+
setRegistryValue(duel, "draw_count", String(yrp.drawCount));
|
|
2434
|
+
const playerNames = yrp.isTag ? [
|
|
2435
|
+
yrp.hostName,
|
|
2436
|
+
yrp.tagHostName ?? "",
|
|
2437
|
+
yrp.tagClientName ?? "",
|
|
2438
|
+
yrp.clientName
|
|
2439
|
+
] : [yrp.hostName, yrp.clientName];
|
|
2440
|
+
for (let i = 0; i < playerNames.length; i++) {
|
|
2441
|
+
setRegistryValue(duel, `player_name_${i}`, playerNames[i] ?? "");
|
|
2442
|
+
}
|
|
2443
|
+
setRegistryValue(duel, "player_type_0", "0");
|
|
2444
|
+
setRegistryValue(duel, "player_type_1", "1");
|
|
2445
|
+
duel.setPlayerInfo({
|
|
2446
|
+
player: 0,
|
|
2447
|
+
lp: yrp.startLp,
|
|
2448
|
+
startHand: yrp.startHand,
|
|
2449
|
+
drawCount: yrp.drawCount
|
|
2450
|
+
});
|
|
2451
|
+
duel.setPlayerInfo({
|
|
2452
|
+
player: 1,
|
|
2453
|
+
lp: yrp.startLp,
|
|
2454
|
+
startHand: yrp.startHand,
|
|
2455
|
+
drawCount: yrp.drawCount
|
|
2456
|
+
});
|
|
2457
|
+
duel.preloadScript("./script/patches/entry.lua");
|
|
2458
|
+
duel.preloadScript("./script/special.lua");
|
|
2459
|
+
duel.preloadScript("./script/init.lua");
|
|
2460
|
+
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2461
|
+
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2462
|
+
} else if (yrp.isTag) {
|
|
2463
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2464
|
+
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2465
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2466
|
+
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2467
|
+
} else {
|
|
2468
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2469
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2470
|
+
}
|
|
2471
|
+
duel.startDuel(yrp.opt >>> 0);
|
|
2472
|
+
return { yrp, duel };
|
|
2473
|
+
}
|
|
2474
|
+
function consumeResponseFromOcgcoreProcess(duel, result, responses) {
|
|
2475
|
+
if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
2476
|
+
throw new Error("Got MSG_RETRY");
|
|
2477
|
+
}
|
|
2478
|
+
if (result.status === 0) {
|
|
2479
|
+
return false;
|
|
2480
|
+
}
|
|
2481
|
+
if (result.status === 1) {
|
|
2482
|
+
if (result.raw.length === 0) {
|
|
2483
|
+
return false;
|
|
2449
2484
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
player: 0,
|
|
2454
|
-
lp: yrp.startLp,
|
|
2455
|
-
startHand: yrp.startHand,
|
|
2456
|
-
drawCount: yrp.drawCount
|
|
2457
|
-
});
|
|
2458
|
-
duel.setPlayerInfo({
|
|
2459
|
-
player: 1,
|
|
2460
|
-
lp: yrp.startLp,
|
|
2461
|
-
startHand: yrp.startHand,
|
|
2462
|
-
drawCount: yrp.drawCount
|
|
2463
|
-
});
|
|
2464
|
-
duel.preloadScript("./script/patches/entry.lua");
|
|
2465
|
-
duel.preloadScript("./script/special.lua");
|
|
2466
|
-
duel.preloadScript("./script/init.lua");
|
|
2467
|
-
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2468
|
-
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2469
|
-
} else if (yrp.isTag) {
|
|
2470
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2471
|
-
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2472
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2473
|
-
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2474
|
-
} else {
|
|
2475
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2476
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2485
|
+
const response = responses.shift();
|
|
2486
|
+
if (!response) {
|
|
2487
|
+
return true;
|
|
2477
2488
|
}
|
|
2478
|
-
duel.
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
if (result.raw.length === 0) {
|
|
2494
|
-
continue;
|
|
2495
|
-
}
|
|
2496
|
-
const response = responses.shift();
|
|
2497
|
-
if (!response) {
|
|
2498
|
-
break;
|
|
2499
|
-
}
|
|
2500
|
-
duel.setResponse(response);
|
|
2501
|
-
continue;
|
|
2502
|
-
}
|
|
2489
|
+
duel.setResponse(response);
|
|
2490
|
+
return false;
|
|
2491
|
+
}
|
|
2492
|
+
return true;
|
|
2493
|
+
}
|
|
2494
|
+
function* processYrpDuelStep(duel, yrp) {
|
|
2495
|
+
const responses = yrp.responses.slice();
|
|
2496
|
+
while (true) {
|
|
2497
|
+
const result = duel.process();
|
|
2498
|
+
yield {
|
|
2499
|
+
duel,
|
|
2500
|
+
result,
|
|
2501
|
+
responses
|
|
2502
|
+
};
|
|
2503
|
+
if (consumeResponseFromOcgcoreProcess(duel, result, responses)) {
|
|
2503
2504
|
break;
|
|
2504
2505
|
}
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
2509
|
+
const { yrp, duel } = createDuelFromYrp(ocgcoreWrapper, yrpInput);
|
|
2510
|
+
try {
|
|
2511
|
+
for (const stepResult of processYrpDuelStep(duel, yrp)) {
|
|
2512
|
+
yield stepResult;
|
|
2513
|
+
}
|
|
2505
2514
|
} finally {
|
|
2506
|
-
endDuel();
|
|
2515
|
+
duel.endDuel();
|
|
2507
2516
|
}
|
|
2508
2517
|
}
|
|
2509
2518
|
var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
@@ -2585,6 +2594,8 @@ export {
|
|
|
2585
2594
|
SqljsCardReader,
|
|
2586
2595
|
ZipReader,
|
|
2587
2596
|
ZipScriptReader,
|
|
2597
|
+
consumeResponseFromOcgcoreProcess,
|
|
2598
|
+
createDuelFromYrp,
|
|
2588
2599
|
createOcgcoreWrapper,
|
|
2589
2600
|
createSqljsCardReader,
|
|
2590
2601
|
normalizeStartDuelOptions,
|
|
@@ -2595,6 +2606,7 @@ export {
|
|
|
2595
2606
|
parseRegistryKeys,
|
|
2596
2607
|
playYrp,
|
|
2597
2608
|
playYrpStep,
|
|
2609
|
+
processYrpDuelStep,
|
|
2598
2610
|
testCard
|
|
2599
2611
|
};
|
|
2600
2612
|
//# sourceMappingURL=index.mjs.map
|