Fix reactive with new system

This commit is contained in:
2024-04-25 20:36:32 +02:00
parent 56cbe9bab4
commit 5f4df966c4
14 changed files with 577 additions and 228 deletions
+63
View File
@@ -0,0 +1,63 @@
import { GameObjectRegister } from "."
import type { GameObjectNetcode } from "./GameObject"
enum CardEffects {
GOLD = "gold",
DAMAGE = "damage",
HEAL = "heal",
PERPARE = "prepare",
STUN = "stun",
SACRIFICE = "sacrifice",
DRAW = "draw",
DRAW_AND_DISCARD = "draw_and_discard",
DISCARD = "discard",
RESTACK_DISCARDED_CHAMPION = "restack_discarded_champion",
RESTACK_DISCARDED_CARD = "restack_discarded_card",
STACK_NEXT_ACTION_BOUGHT = "stack_next_action_bought",
STACK_NEXT_CARD_BOUGHT = "stack_next_card_bought",
PLAY_NEXT_CARD_BOUGHT = "play_next_card_bought"
}
enum EffectTimes {
PER_CHAMPION = "per_champion",
PER_OTHER_CHAMPION = "per_other_champion",
PER_OTHER_GUARD = "per_other_guard",
PER_CARD_OF_SAME_FACTION = "per_card_of_same_faction"
}
enum EffectType {
CHAMPION_ACTION = "champion_action",
SUICIDE = "suicide",
FACTION_COMBO = "faction_combo"
}
export interface EffectNetcode extends GameObjectNetcode {
effect: CardEffects
amount: number
sub_effects: Array<EffectNetcode>
mutex: Array<string>
effect_type?: EffectType
times?: EffectTimes
}
export type Effect = Omit<EffectNetcode, 'sub_effects' | 'mutex'> & {
sub_effects: { [key: string]: Effect }
mutex: { [key: string]: Effect }
}
export function create_effect(input: EffectNetcode, register: GameObjectRegister) {
return new Proxy<any>(input, {
get(target, prop, reciever) {
if (prop == "sub_effects") {
return Object.fromEntries(Object.entries(register.effects).filter(([i, v]) => i in target.sub_effects))
}
if (prop == "mutex") {
return Object.fromEntries(Object.entries(register.effects).filter(([i, v]) => i in target.mutex))
}
return Reflect.get(target, prop, reciever);
},
set(target, prop, val, receiver) {
return Reflect.set(target, prop, val, receiver);
}
}) as Effect
}