diff --git a/src/mlpccg/draft/booster.ts b/src/mlpccg/draft/booster.ts index 26627a3..e1123b4 100644 --- a/src/mlpccg/draft/booster.ts +++ b/src/mlpccg/draft/booster.ts @@ -1,6 +1,5 @@ -import { Card } from "../types"; +import { Card, getCards } from "@/mlpccg"; import { Pack, PackSchema, AlternateProvider } from "./types"; -import { getCards } from "../database"; /* diff --git a/src/mlpccg/draft/bot.ts b/src/mlpccg/draft/bot.ts new file mode 100644 index 0000000..b6e9ee5 --- /dev/null +++ b/src/mlpccg/draft/bot.ts @@ -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]; + } +} diff --git a/src/mlpccg/draft/cube.ts b/src/mlpccg/draft/cube.ts index b92338e..fc6d4c1 100644 --- a/src/mlpccg/draft/cube.ts +++ b/src/mlpccg/draft/cube.ts @@ -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[]; diff --git a/src/mlpccg/draft/index.ts b/src/mlpccg/draft/index.ts index cb4f17a..5dee001 100644 --- a/src/mlpccg/draft/index.ts +++ b/src/mlpccg/draft/index.ts @@ -1,3 +1,5 @@ export * from "./cube"; export * from "./booster"; export * from "./types"; +export * from "./session"; +export * from "./bot"; diff --git a/src/mlpccg/draft/session.ts b/src/mlpccg/draft/session.ts new file mode 100644 index 0000000..d9f2bf3 --- /dev/null +++ b/src/mlpccg/draft/session.ts @@ -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 { + 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"); + } + } +} diff --git a/src/mlpccg/draft/types.ts b/src/mlpccg/draft/types.ts index 62be937..58f4ae7 100644 --- a/src/mlpccg/draft/types.ts +++ b/src/mlpccg/draft/types.ts @@ -1,4 +1,4 @@ -import { Card } from "../types"; +import { Card } from "@/mlpccg"; export type Provider = Iterator; @@ -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;