Files
front/netcode/Card.ts
T
2024-04-26 16:08:04 +02:00

65 lines
1.6 KiB
TypeScript

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<string>
defense?: number
guard?: boolean
}
export type Card = Omit<CardNetcode, 'effects'> & {
effects: Array<Effect>
health_as_champion?: number
}
export function create_card(input: CardNetcode, register: GameObjectRegister) {
const card = new Proxy<any>(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
}