Basic draft library #19
6 changed files with 70 additions and 6 deletions
|
@ -1,6 +1,5 @@
|
|||
import { Card } from "../types";
|
||||
import { Card, getCards } from "@/mlpccg";
|
||||
import { Pack, PackSchema, AlternateProvider } from "./types";
|
||||
import { getCards } from "../database";
|
||||
|
||||
/*
|
||||
|
||||
|
|
9
src/mlpccg/draft/bot.ts
Normal file
9
src/mlpccg/draft/bot.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Card } from "@/mlpccg";
|
||||
|
||||
export class DraftBot {
|
||||
pick(picks: Card[]) {
|
||||
// For now, pick a random card
|
||||
const idx = Math.floor(Math.random() * picks.length);
|
||||
return picks[idx];
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
import { Card } from "../types";
|
||||
import { getCards, cardFromIDs } from "../database";
|
||||
import axios from "axios";
|
||||
import { Card, cardFromIDs } from "@/mlpccg";
|
||||
import { PackSchema } from "./types";
|
||||
import axios from "axios";
|
||||
|
||||
export class Cube {
|
||||
private pool: Card[];
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export * from "./cube";
|
||||
export * from "./booster";
|
||||
export * from "./types";
|
||||
export * from "./session";
|
||||
export * from "./bot";
|
||||
|
|
29
src/mlpccg/draft/session.ts
Normal file
29
src/mlpccg/draft/session.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { PackBuilder, Cube, DraftOptions } from ".";
|
||||
|
||||
export class Session {
|
||||
private options: DraftOptions;
|
||||
private factory: PackBuilder;
|
||||
|
||||
constructor(options: DraftOptions, factory: PackBuilder) {
|
||||
this.options = options;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
static async create(options: DraftOptions): Promise<Session> {
|
||||
switch (options.type) {
|
||||
case "set": {
|
||||
const factory = await PackBuilder.fromSet(options.set);
|
||||
return new Session(options, factory);
|
||||
}
|
||||
case "block":
|
||||
throw new Error("not implemented");
|
||||
case "cube": {
|
||||
const cube = await Cube.fromURL(options.url);
|
||||
const factory = new PackBuilder(cube.schema());
|
||||
return new Session(options, factory);
|
||||
}
|
||||
case "i8pcube":
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { Card } from "../types";
|
||||
import { Card } from "@/mlpccg";
|
||||
|
||||
export type Provider = Iterator<Card>;
|
||||
|
||||
|
@ -18,3 +18,29 @@ export interface AlternateProvider {
|
|||
probability: number;
|
||||
provider: Provider;
|
||||
}
|
||||
|
||||
export interface SetDraftOptions {
|
||||
type: "set";
|
||||
set: string;
|
||||
}
|
||||
|
||||
export interface BlockDraftOptions {
|
||||
type: "block";
|
||||
block: string;
|
||||
}
|
||||
|
||||
export interface CubeDraftOptions {
|
||||
type: "cube";
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface I8PCubeDraftOptions {
|
||||
type: "i8pcube";
|
||||
url: string;
|
||||
}
|
||||
|
||||
export type DraftOptions =
|
||||
| SetDraftOptions
|
||||
| BlockDraftOptions
|
||||
| CubeDraftOptions
|
||||
| I8PCubeDraftOptions;
|
||||
|
|
Loading…
Reference in a new issue