Commit 7afae354 authored by nanahira's avatar nanahira

ocgcore worker

parent 921e5a62
Pipeline #43157 failed with stages
in 2 minutes and 13 seconds
...@@ -22,13 +22,15 @@ ...@@ -22,13 +22,15 @@
"pino-pretty": "^13.1.3", "pino-pretty": "^13.1.3",
"rxjs": "^7.8.2", "rxjs": "^7.8.2",
"typed-reflector": "^1.0.14", "typed-reflector": "^1.0.14",
"typed-struct": "^2.7.1",
"ws": "^8.19.0", "ws": "^8.19.0",
"yaml": "^2.8.2", "yaml": "^2.8.2",
"ygopro-cdb-encode": "^1.0.1", "ygopro-cdb-encode": "^1.0.1",
"ygopro-deck-encode": "^1.0.15", "ygopro-deck-encode": "^1.0.15",
"ygopro-lflist-encode": "^1.0.3", "ygopro-lflist-encode": "^1.0.3",
"ygopro-msg-encode": "^1.1.9", "ygopro-msg-encode": "^1.1.9",
"ygopro-yrp-encode": "^1.0.1" "ygopro-yrp-encode": "^1.0.1",
"yuzuthread": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^30.0.0", "@types/jest": "^30.0.0",
...@@ -6955,6 +6957,32 @@ ...@@ -6955,6 +6957,32 @@
"reflect-metadata": "^0.1.13" "reflect-metadata": "^0.1.13"
} }
}, },
"node_modules/typed-struct": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/typed-struct/-/typed-struct-2.7.1.tgz",
"integrity": "sha512-GluzA9kYlHjATJmzBDA2X9G9237Md5zsJsc8uEkmpvUFeuUvt+e7Sq11/nQnVB2VZIfKNR1CrwTCgpJVz52pAA==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
"peerDependencies": {
"buffer": "^6.0.3",
"debug": "^4.3.3",
"iconv-lite": "^0.6.3"
},
"peerDependenciesMeta": {
"buffer": {
"optional": true
},
"debug": {
"optional": true
},
"iconv-lite": {
"optional": true
}
}
},
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.9.3", "version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
...@@ -7453,6 +7481,19 @@ ...@@ -7453,6 +7481,19 @@
"funding": { "funding": {
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
},
"node_modules/yuzuthread": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/yuzuthread/-/yuzuthread-1.0.8.tgz",
"integrity": "sha512-9TKDHnvtDKwTSAPCVsgdMbOmc02e+17M0ZpnaUPuk10QoSS+X9JE/diflKwENzGEPVEu4bZtVW759O1flU6/6g==",
"license": "MIT",
"dependencies": {
"nfkit": "^1.0.21",
"typed-reflector": "^1.0.14"
},
"peerDependencies": {
"typed-struct": "^2.7.1"
}
} }
} }
} }
import YGOProDeck from 'ygopro-deck-encode';
import { HostInfo } from 'ygopro-msg-encode';
import { TransportType } from 'yuzuthread';
export class OcgcoreWorkerOptions {
ygoproPaths: string[];
extraScriptPaths: string[];
seed: number[];
hostinfo: HostInfo;
@TransportType(() => [YGOProDeck])
decks: YGOProDeck[];
isTag?: boolean;
playerNames?: string[];
registry?: Record<string, string>;
}
This diff is collapsed.
...@@ -40,6 +40,7 @@ import { DefaultHostInfoProvider } from './default-hostinfo-provder'; ...@@ -40,6 +40,7 @@ import { DefaultHostInfoProvider } from './default-hostinfo-provder';
import { CardReaderFinalized } from 'koishipro-core.js'; import { CardReaderFinalized } from 'koishipro-core.js';
import { YGOProResourceLoader } from './ygopro-resource-loader'; import { YGOProResourceLoader } from './ygopro-resource-loader';
import { blankLFList } from '../utility/blank-lflist'; import { blankLFList } from '../utility/blank-lflist';
import { calculateDuelOptions } from '../utility/calculate-duel-options';
import { Client } from '../client/client'; import { Client } from '../client/client';
import { RoomMethod } from '../utility/decorators'; import { RoomMethod } from '../utility/decorators';
import { YGOProCtosDisconnect } from '../utility/ygopro-ctos-disconnect'; import { YGOProCtosDisconnect } from '../utility/ygopro-ctos-disconnect';
...@@ -85,17 +86,7 @@ export class Room { ...@@ -85,17 +86,7 @@ export class Room {
} }
get opt() { get opt() {
const DUEL_PSEUDO_SHUFFLE = 16; return calculateDuelOptions(this.hostinfo, this.isTag);
const DUEL_TAG_MODE = 32;
// duel_rule is stored in high 16 bits
let opt = this.hostinfo.duel_rule << 16;
if (this.hostinfo.no_shuffle_deck) {
opt |= DUEL_PSEUDO_SHUFFLE;
}
if (this.isTag) {
opt |= DUEL_TAG_MODE;
}
return opt;
} }
players = new Array<Client | undefined>(this.hostinfo.mode === 2 ? 4 : 2); players = new Array<Client | undefined>(this.hostinfo.mode === 2 ? 4 : 2);
......
import { HostInfo } from 'ygopro-msg-encode';
import { OcgcoreDuelOptionFlag } from 'koishipro-core.js';
/**
* Calculate duel options from HostInfo
* @param hostinfo HostInfo from ygopro-msg-encode
* @param isTag Whether this is a tag duel
* @returns Duel options number
*/
export function calculateDuelOptions(
hostinfo: HostInfo,
isTag: boolean = false,
): number {
// duel_rule is stored in high 16 bits
let opt = hostinfo.duel_rule << 16;
if (hostinfo.no_shuffle_deck) {
opt |= OcgcoreDuelOptionFlag.PseudoShuffle;
}
if (isTag) {
opt |= OcgcoreDuelOptionFlag.TagMode;
}
return opt;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment