WIP node bindings for ygopro-core (the OCG script engine)
NOTE This is not Ygopro the game!!!
npm install ygocore
To use this package, you need to know how ocgcore
works.
Note
I'm not the author/contributer of
ygopro
, if my understandings onocgcore
's API are not correct, please fire me an issue. Thanks!
import { engine } from 'ygopro';
this project is writen in Typescript, each method is type-annotated.
ocgapi:
create_duel()
const duel = engine.createDuel(/* any random seed */ 0);
ocgapi:
set_player_info()
engine.setPlayerInfo(duel, { /* ... */ });
ocgapi:
new_card()
engine.newCard(duel, { /* ... */ });
ocgapi:
start_duel()
engine.startDuel(duel, options);
ocgapi:
process()
,get_message()
const { flags, data } = engine.process(duel);
data
is a buffer (of type Buffer
) contains messages returned from ocgcore
, to deserialize it, you can use ygocore-interface's parseMessage
(see below)
ocgapi:
set_responsei()
,set_responseb()
engine.setResponse(duel, response);
ocgapi:
end_duel()
engine.endDuel(duel);
ocgapi:
query_field_card
const data = engine.queryFieldCard(duel, { /* player, location, ... */ });
Again, to deserialize the message, you can use ygocore-interface's
parseFieldCardQueryResult
.
ocgapi:
query_card
const data = engine.queryCard(duel, { /* player, location, sequence, ... */ });
Again and again, to deserialize the message, you can use ygocore-interface's
parseCardQueryResult
.
ocgapi:
query_field_count
const howManyCards = engine.queryFieldCount(duel, { /* ... */ });
const { parseMessage } from 'ygocore-interface';
const messages = parseMessage(data /* from engine.process */);
for (const message of messages) {
if (message.msgtype == 'MSG_SELECT_IDLECMD') {
// message is not of type 'MsgSelectIdlecmd'
// handle MsgSelectIdlecmd here.
// refresh M zone:
const mzone = parseFieldCardQueryResult(engine.queryFieldCard(duel, {
player, location, queryFlags, useCache
});
for (const card of mzone) {
// play with card...
// type card.
// ^
// |
// nice code completion!
}
}
// handle other messages here.
}
Constants in common.h
are also exported:
import { LOCATION, QUERY } from 'ygocore-interface';
/* .... */
const location = LOCATION.HAND;
const queryFlags = /* ... + ... + */ QUERY.LSCALE + QUERY.RSCALE + QUERY.STATUS;
const hand = parseFieldCardQueryResult(engine.queryFieldCard(duel, {
player, location, queryFlags, useCache
});