64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import type { GameObjectRegister } from "."
|
|
import type { Effect } from "./Effect"
|
|
import type { GameObjectNetcode } from "./GameObject"
|
|
|
|
enum CardRole {
|
|
PERSONAL = "personal",
|
|
MARKET = "market",
|
|
FIRE_GEM = "fire_gem"
|
|
}
|
|
|
|
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[e])
|
|
}
|
|
if (prop == "health_as_champion") {
|
|
return Object.values(register.turns).find(e => e.champions_health.has(card))?.champions_health.get(card)
|
|
}
|
|
return Reflect.get(target, prop, reciever);
|
|
},
|
|
set(target, prop, val, receiver) {
|
|
return Reflect.set(target, prop, val, receiver);
|
|
}
|
|
}) as Card
|
|
return card
|
|
}
|