ygocore-interface
v0.3.2
Published
[WIP] ygocore interface (message definitions, constants, api signatures)
Downloads
23
Readme
ygocore-interface
WIP ygopro-core(https://github.com/moecube/ygopro-core) api wrapper
Install
npm install ygocore-interface
npm install ygocore # for core engine
How to use
import { engine } from 'ygocore';
import { Duel, DEFAULT_DUEL_OPTIONS } from 'ygocore-interface';
import { inspect } from 'util';
// initialize the engine, see http://github.com/ghlin/node-ygocore
//
// engine.registerCard(/* ... */);
// engine.registerScript(/* ... */);
// create the duel
const duel = new Duel(engine, {
players: [
/* player 1 */{ main: [ /* main deck */ ], extra: [ /* extra deck */ ] },
/* player 2 */{ main: [ /* main deck */ ], extra: [ /* extra deck */ ] }
],
seed: 0, /* random seed */
options: DEFAULT_DUEL_OPTIONS /* master rule 4 */
});
while (true) {
const todo = duel.step();
if (todo.tag === 'DUEL_FINISHED') {
if (todo.why.tag === 'REASON_WIN') {
// the winner is:
const winner = todo.why.message.player;
}
// duel finished.
break;
}
if (todo.tag === 'ASK_QUESTION') {
const playerResponse = await getResponse(todo.question.player, todo.question);
duel.feed(playerResponse);
console.log(`ask player ${todo.question.player} about: ${inspect(todo.question, false, null, true)}`}
continue;
}
// todo.tag === 'DISPATCH_PACKET'
for (const { whom, what } of todo.packets) {
// message 'what' will be sent to player 'whom'
await sendMessage(whom, what);
console.log(`tell player ${whom}: ${inspect(what, false, null, true)}`);
}
}
// end duel
duel.release();
Constants defined in ocgcore/common.h
are also exported:
import { DUEL, LOCATION, POS, TYPE, QUERY, LINK_MARKER /* ... */ } from 'ygocore-interface';
// e.g. LOCATION.HAND => LOCATION_HAND (in common.h)
TODOs
- [ ] A playable demo
- [ ] Handle response time-out
- [ ] TAG duel
- [ ] Parse replay file (.yrp)
- [ ] Type definitions for user response
- [ ] Documentation?