import type { GameObjectRegister } from "." import type { Effect } from "./Effect" import type { GameObjectNetcode } from "./GameObject" import type { Turn } from "./Turn" enum CardRole { PERSONAL = "personal", MARKET = "market", FIRE_GEM = "fire_gem" } export enum CardType { HERO = "hero", HERO_ABILITY = "hero_ability", CURRENCY = "currency", WEAPON = "weapon", CHAMPION = "champion", ACTION = "action", ITEM = "item" } enum CardFaction { BASE = "base", BLUE = "blue", RED = "red", GREEN = "green", YELLOW = "yellow" } export interface CardNetcode extends GameObjectNetcode { card_id: number sprite: string name: string cost?: number role: CardRole card_type: CardType faction: CardFaction effects: Array defense?: number guard?: boolean } export type Card = Omit & { effects: Array health_as_champion?: number } export function create_card(input: CardNetcode, register: GameObjectRegister) { const card = new Proxy(input, { get(target: CardNetcode, prop, reciever) { if (prop == "effects") { return target.effects.map((e) => register.effects.get(e)) } if (prop == "health_as_champion") { return Array.from(register.turns.values()).find(e => e.champions_health.has(card.uuid))?.champions_health.get(card.uuid) } return Reflect.get(target, prop, reciever); }, set(target, prop, val, receiver) { return Reflect.set(target, prop, val, receiver); } }) as Card return card }