ygocore-interface
Version:
[WIP] ygocore interface (message definitions, constants, api signatures)
164 lines (163 loc) • 3.41 kB
TypeScript
/// <reference types="node" />
import { Message, MsgWin, Question } from './coremsg';
import { OCGEngine } from './engine';
/**
* there are packets to diliver.
*/
declare type STEP_DISPATCH_PACKET = 'DISPATCH_PACKET';
/**
* ocgengine is asking a duelist a question.
*/
declare type STEP_ASK_QUESTION = 'ASK_QUESTION';
/**
* duel finished.
*/
declare type STEP_DUEL_FINISHED = 'DUEL_FINISHED';
/**
* player's operation timed out.
*/
declare type FINISHED_REASON_TIMEOUT = 'REASON_TIMEOUT';
/**
* we've got a winner.
*/
declare type FINISHED_REASON_WIN = 'REASON_WIN';
/**
* something went wrong.
*/
declare type FINISHED_REASON_ERROR = 'REASON_ERROR';
interface ReasonTimeout {
tag: FINISHED_REASON_TIMEOUT;
player: number;
}
interface ReasonError {
tag: FINISHED_REASON_ERROR;
error: Error;
}
interface ReasonWin {
tag: FINISHED_REASON_WIN;
message: MsgWin;
}
export interface Packet<M> {
/**
* player id
*/
whom: number;
/**
* the message
*/
what: M;
}
/**
* duel finished
*/
export interface DuelFinished {
tag: STEP_DUEL_FINISHED;
why: ReasonError | ReasonTimeout | ReasonWin;
}
/**
* the engine says:
*/
export interface DispatchPacket {
tag: STEP_DISPATCH_PACKET;
/**
* packets to be sent to players
*/
packets: Array<Packet<Message>>;
/**
* the original message
*/
original: Message;
}
/**
* the engine wants to know:
*/
export interface AskQuestion {
tag: STEP_ASK_QUESTION;
/**
* the engine is waiting for {@param question.player}'s answer (response)
*/
question: Question;
}
export declare type StepResult = DuelFinished | DispatchPacket | AskQuestion;
export declare const DUEL_RULE_1: number;
export declare const DUEL_RULE_2: number;
export declare const DUEL_RULE_3: number;
export declare const DUEL_RULE_4: number;
/**
* @see DUEL
*/
export declare const DEFAULT_DUEL_OPTIONS: number;
/**
* params for creating duel
*/
export interface CreateDuelParams {
/**
* players, should be of size 2
*/
players: Array<{
/**
* main deck
*/
main: number[];
/**
* extra deck
*/
extra: number[];
/**
* initial LP, defaults to 8000
*/
lp?: number;
/**
* how many cards to draw before duel starts, defaults to 5
*/
start?: number;
/**
* how many cards to draw in each turn on DP, defaults to 1
*/
draw?: number;
}>;
/**
* random seed
*/
seed: number;
/**
* duel options, use DEFAULT_DUEL_OPTIONS if you have no idea.
*/
options: number;
/**
* replay mode?
*/
replay?: boolean;
}
/**
* single duel only
*
* (TAG duel is a TODO)
*/
export declare class Duel {
private state;
constructor(engine: OCGEngine<{}>, params: CreateDuelParams);
/**
* feed player's response to this duel
* @param response player's response
* @returns false for invalid response, true otherwise
*/
feed(response: Buffer): boolean;
/**
* like engine.process, see:
*
* @see StepResult
*
* @see DispatchPacket
*
* @see AskQuestion
*
* @see DuelFinished
*/
step(): StepResult;
/**
* finish the duel
*/
release(): void;
}
export {};