koishipro-core.js 1.2.2 → 1.2.4
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/README.md +75 -0
- package/dist/index.cjs +159 -40
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +156 -39
- package/dist/index.mjs.map +4 -4
- package/dist/src/advancors/combined-advancor.d.ts +2 -0
- package/dist/src/advancors/index.d.ts +9 -0
- package/dist/src/advancors/limit-advancor.d.ts +4 -0
- package/dist/src/advancors/map-advancor.d.ts +8 -0
- package/dist/src/advancors/no-effect-advancor.d.ts +1 -0
- package/dist/src/advancors/player-view-advancor.d.ts +3 -0
- package/dist/src/advancors/select-card-advancor.d.ts +7 -0
- package/dist/src/advancors/slient-advancor.d.ts +2 -0
- package/dist/src/advancors/static-advancor.d.ts +2 -0
- package/dist/src/advancors/summon-place-advancor.d.ts +5 -0
- package/dist/src/advancors/types.d.ts +2 -0
- package/dist/src/ocgcore-duel.d.ts +2 -0
- package/dist/src/play-yrp.d.ts +1 -8
- package/dist/src/types/card-location.d.ts +5 -0
- package/dist/src/types/index.d.ts +1 -0
- package/index.ts +1 -0
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -136,7 +136,10 @@ function normalizeStartDuelOptions(options) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// src/ocgcore-duel.ts
|
|
139
|
-
import {
|
|
139
|
+
import {
|
|
140
|
+
YGOProMessages,
|
|
141
|
+
YGOProMsgRetry
|
|
142
|
+
} from "ygopro-msg-encode";
|
|
140
143
|
var OcgcoreDuel = class {
|
|
141
144
|
constructor(ocgcoreWrapper, duelPtr) {
|
|
142
145
|
this.ocgcoreWrapper = ocgcoreWrapper;
|
|
@@ -203,6 +206,22 @@ var OcgcoreDuel = class {
|
|
|
203
206
|
message: parsedMessage
|
|
204
207
|
};
|
|
205
208
|
}
|
|
209
|
+
*advance(advancor) {
|
|
210
|
+
while (true) {
|
|
211
|
+
const res = this.process();
|
|
212
|
+
yield res;
|
|
213
|
+
if (res.status === 2 || res.message instanceof YGOProMsgRetry) {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (res.status === 1 && res.raw.length > 0) {
|
|
217
|
+
const response = advancor?.(res.message);
|
|
218
|
+
if (!response) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
this.setResponse(response);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
206
225
|
newCard(card) {
|
|
207
226
|
this.ocgcoreWrapper.ocgcoreModule._new_card(
|
|
208
227
|
this.duelPtr,
|
|
@@ -1107,6 +1126,7 @@ async function DirCardReader(sqljs, ...baseDirs) {
|
|
|
1107
1126
|
|
|
1108
1127
|
// src/play-yrp.ts
|
|
1109
1128
|
import { YGOProYrp } from "ygopro-yrp-encode";
|
|
1129
|
+
import { YGOProMsgRetry as YGOProMsgRetry2 } from "ygopro-msg-encode";
|
|
1110
1130
|
var { LOCATION_DECK, LOCATION_EXTRA, POS_FACEDOWN_DEFENSE } = OcgcoreScriptConstants;
|
|
1111
1131
|
function normalizeYrp(input) {
|
|
1112
1132
|
if (input instanceof YGOProYrp) {
|
|
@@ -1206,45 +1226,19 @@ function createDuelFromYrp(wrapper, yrpInput) {
|
|
|
1206
1226
|
duel.startDuel(yrp.opt >>> 0);
|
|
1207
1227
|
return { yrp, duel };
|
|
1208
1228
|
}
|
|
1209
|
-
function consumeResponseFromOcgcoreProcess(duel, result, responses) {
|
|
1210
|
-
if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
1211
|
-
throw new Error("Got MSG_RETRY");
|
|
1212
|
-
}
|
|
1213
|
-
if (result.status === 0) {
|
|
1214
|
-
return false;
|
|
1215
|
-
}
|
|
1216
|
-
if (result.status === 1) {
|
|
1217
|
-
if (result.raw.length === 0) {
|
|
1218
|
-
return false;
|
|
1219
|
-
}
|
|
1220
|
-
const response = responses.shift();
|
|
1221
|
-
if (!response) {
|
|
1222
|
-
return true;
|
|
1223
|
-
}
|
|
1224
|
-
duel.setResponse(response);
|
|
1225
|
-
return false;
|
|
1226
|
-
}
|
|
1227
|
-
return true;
|
|
1228
|
-
}
|
|
1229
|
-
function* processYrpDuelStep(duel, yrp) {
|
|
1230
|
-
const responses = yrp.responses.slice();
|
|
1231
|
-
while (true) {
|
|
1232
|
-
const result = duel.process();
|
|
1233
|
-
yield {
|
|
1234
|
-
duel,
|
|
1235
|
-
result,
|
|
1236
|
-
responses
|
|
1237
|
-
};
|
|
1238
|
-
if (consumeResponseFromOcgcoreProcess(duel, result, responses)) {
|
|
1239
|
-
break;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
1229
|
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
1244
1230
|
const { yrp, duel } = createDuelFromYrp(ocgcoreWrapper, yrpInput);
|
|
1231
|
+
const responses = yrp.responses.slice();
|
|
1245
1232
|
try {
|
|
1246
|
-
for (const
|
|
1247
|
-
yield
|
|
1233
|
+
for (const result of duel.advance(() => responses.shift())) {
|
|
1234
|
+
yield {
|
|
1235
|
+
duel,
|
|
1236
|
+
result,
|
|
1237
|
+
responses
|
|
1238
|
+
};
|
|
1239
|
+
if (result.message instanceof YGOProMsgRetry2) {
|
|
1240
|
+
throw new Error("Got MSG_RETRY");
|
|
1241
|
+
}
|
|
1248
1242
|
}
|
|
1249
1243
|
} finally {
|
|
1250
1244
|
duel.endDuel();
|
|
@@ -1301,11 +1295,127 @@ function testCard(ocgcoreWrapper, ...ids) {
|
|
|
1301
1295
|
return logs;
|
|
1302
1296
|
}
|
|
1303
1297
|
|
|
1298
|
+
// src/advancors/slient-advancor.ts
|
|
1299
|
+
var SlientAdvancor = () => {
|
|
1300
|
+
return (msg) => {
|
|
1301
|
+
return msg.defaultResponse();
|
|
1302
|
+
};
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/advancors/static-advancor.ts
|
|
1306
|
+
import { makeArray } from "nfkit";
|
|
1307
|
+
var StaticAdvancor = (items) => {
|
|
1308
|
+
const _items = makeArray(items).slice();
|
|
1309
|
+
return () => _items.shift();
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
// src/advancors/no-effect-advancor.ts
|
|
1313
|
+
import { YGOProMsgSelectChain } from "ygopro-msg-encode";
|
|
1314
|
+
|
|
1315
|
+
// src/advancors/map-advancor.ts
|
|
1316
|
+
var MapAdvancorHandler = (msgClass, cb) => ({
|
|
1317
|
+
msgClass,
|
|
1318
|
+
cb
|
|
1319
|
+
});
|
|
1320
|
+
var MapAdvancor = (...handlers) => {
|
|
1321
|
+
const handlerMap = /* @__PURE__ */ new Map();
|
|
1322
|
+
for (const handleObj of handlers) {
|
|
1323
|
+
handlerMap.set(handleObj.msgClass, handleObj.cb);
|
|
1324
|
+
}
|
|
1325
|
+
return (msg) => {
|
|
1326
|
+
const cb = handlerMap.get(
|
|
1327
|
+
msg.constructor
|
|
1328
|
+
);
|
|
1329
|
+
if (cb != null) {
|
|
1330
|
+
const res = cb(msg);
|
|
1331
|
+
if (res != null) {
|
|
1332
|
+
return res;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
return void 0;
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
// src/advancors/no-effect-advancor.ts
|
|
1340
|
+
var NoEffectAdvancor = () => MapAdvancor(
|
|
1341
|
+
MapAdvancorHandler(YGOProMsgSelectChain, (msg) => {
|
|
1342
|
+
if (msg.chains.length) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
return msg.prepareResponse(void 0);
|
|
1346
|
+
})
|
|
1347
|
+
);
|
|
1348
|
+
|
|
1349
|
+
// src/advancors/combined-advancor.ts
|
|
1350
|
+
var CombinedAdvancor = (...advancors) => {
|
|
1351
|
+
return (msg) => {
|
|
1352
|
+
for (const advancor of advancors) {
|
|
1353
|
+
const res = advancor(msg);
|
|
1354
|
+
if (res != null) {
|
|
1355
|
+
return res;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
return void 0;
|
|
1359
|
+
};
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// src/advancors/limit-advancor.ts
|
|
1363
|
+
var LimitAdvancor = (a, limit = 1) => {
|
|
1364
|
+
let called = 0;
|
|
1365
|
+
return (msg) => {
|
|
1366
|
+
if (called >= limit) {
|
|
1367
|
+
return void 0;
|
|
1368
|
+
}
|
|
1369
|
+
const res = a(msg);
|
|
1370
|
+
if (res !== void 0) {
|
|
1371
|
+
called++;
|
|
1372
|
+
}
|
|
1373
|
+
return res;
|
|
1374
|
+
};
|
|
1375
|
+
};
|
|
1376
|
+
var OnceAdvancor = (a) => LimitAdvancor(a, 1);
|
|
1377
|
+
|
|
1378
|
+
// src/advancors/player-view-advancor.ts
|
|
1379
|
+
var PlayerViewAdvancor = (player, a) => (msg) => {
|
|
1380
|
+
if (msg.responsePlayer() === player) {
|
|
1381
|
+
return a(msg);
|
|
1382
|
+
}
|
|
1383
|
+
return void 0;
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
// src/advancors/summon-place-advancor.ts
|
|
1387
|
+
import {
|
|
1388
|
+
YGOProMsgSelectPlace,
|
|
1389
|
+
YGOProMsgSelectPosition
|
|
1390
|
+
} from "ygopro-msg-encode";
|
|
1391
|
+
var SummonPlaceAdvancor = (placeAndPosition = {}) => MapAdvancor(
|
|
1392
|
+
MapAdvancorHandler(YGOProMsgSelectPlace, (msg) => {
|
|
1393
|
+
const places = msg.getSelectablePlaces().filter(
|
|
1394
|
+
(p) => (placeAndPosition.player == null || p.player === placeAndPosition.player) && (placeAndPosition.location == null || p.location === placeAndPosition.location) && (placeAndPosition.sequence == null || p.sequence === placeAndPosition.sequence)
|
|
1395
|
+
).slice(0, msg.count);
|
|
1396
|
+
return msg.prepareResponse(places);
|
|
1397
|
+
}),
|
|
1398
|
+
MapAdvancorHandler(YGOProMsgSelectPosition, (msg) => {
|
|
1399
|
+
if (placeAndPosition.position) {
|
|
1400
|
+
return msg.prepareResponse(placeAndPosition.position);
|
|
1401
|
+
}
|
|
1402
|
+
const possiblePositions = msg.positions;
|
|
1403
|
+
for (let i = 0; i < 8; i++) {
|
|
1404
|
+
const value = 1 << i;
|
|
1405
|
+
if ((possiblePositions & value) !== 0) {
|
|
1406
|
+
return msg.prepareResponse(value);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return void 0;
|
|
1410
|
+
})
|
|
1411
|
+
);
|
|
1412
|
+
|
|
1304
1413
|
// index.ts
|
|
1305
1414
|
if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
1306
1415
|
globalThis.Buffer = Buffer2;
|
|
1307
1416
|
}
|
|
1308
1417
|
export {
|
|
1418
|
+
CombinedAdvancor,
|
|
1309
1419
|
DirCardReader,
|
|
1310
1420
|
DirReader,
|
|
1311
1421
|
DirScriptReader,
|
|
@@ -1313,21 +1423,29 @@ export {
|
|
|
1313
1423
|
LEN_EMPTY,
|
|
1314
1424
|
LEN_FAIL,
|
|
1315
1425
|
LEN_HEADER,
|
|
1426
|
+
LimitAdvancor,
|
|
1316
1427
|
MESSAGE_BUFFER_SIZE,
|
|
1428
|
+
MapAdvancor,
|
|
1429
|
+
MapAdvancorHandler,
|
|
1317
1430
|
MapReader,
|
|
1318
1431
|
MapScriptReader,
|
|
1432
|
+
NoEffectAdvancor,
|
|
1319
1433
|
OcgcoreDuel,
|
|
1320
1434
|
OcgcoreDuelOptionFlag,
|
|
1321
1435
|
OcgcoreDuelRule,
|
|
1322
1436
|
OcgcoreMessageType,
|
|
1323
1437
|
OcgcoreWrapper,
|
|
1438
|
+
OnceAdvancor,
|
|
1439
|
+
PlayerViewAdvancor,
|
|
1324
1440
|
QUERY_BUFFER_SIZE,
|
|
1325
1441
|
REGISTRY_BUFFER_SIZE,
|
|
1442
|
+
SlientAdvancor,
|
|
1326
1443
|
SqljsCardReader,
|
|
1444
|
+
StaticAdvancor,
|
|
1445
|
+
SummonPlaceAdvancor,
|
|
1327
1446
|
ZipReader,
|
|
1328
1447
|
ZipScriptReader,
|
|
1329
1448
|
vendor_exports as _OcgcoreConstants,
|
|
1330
|
-
consumeResponseFromOcgcoreProcess,
|
|
1331
1449
|
createDuelFromYrp,
|
|
1332
1450
|
createOcgcoreWrapper,
|
|
1333
1451
|
createSqljsCardReader,
|
|
@@ -1339,7 +1457,6 @@ export {
|
|
|
1339
1457
|
parseRegistryKeys,
|
|
1340
1458
|
playYrp,
|
|
1341
1459
|
playYrpStep,
|
|
1342
|
-
processYrpDuelStep,
|
|
1343
1460
|
testCard
|
|
1344
1461
|
};
|
|
1345
1462
|
//# sourceMappingURL=index.mjs.map
|