factorization : turn find_effect
This commit is contained in:
+13
-18
@@ -21,37 +21,32 @@ const isTurn = computed(() => goStore.self && goStore.game?.started && (goStore.
|
||||
BUY
|
||||
</button>
|
||||
<button
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.PLAY_NEXT_CARD_BOUGHT) && e.usable)!, goStore.game.gem_stack.at(-1))"
|
||||
:disabled="(goStore.self === undefined || goStore.game.gem_stack.at(-1)!.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < goStore.game.gem_stack.at(-1)!.cost!) || !goStore.self!.turn.effects_availables.some(e => (e.effect == CardEffects.PLAY_NEXT_CARD_BOUGHT) && e.usable)">
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.PLAY_NEXT_CARD_BOUGHT)!, goStore.game.gem_stack.at(-1))"
|
||||
:disabled="(goStore.self === undefined || goStore.game.gem_stack.at(-1)!.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < goStore.game.gem_stack.at(-1)!.cost!) || !goStore.self!.turn.find_effect(CardEffects.PLAY_NEXT_CARD_BOUGHT)">
|
||||
BUY IN HAND</button>
|
||||
<button
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.STACK_NEXT_CARD_BOUGHT) && e.usable)!, goStore.game.gem_stack.at(-1))"
|
||||
:disabled="(goStore.self === undefined || goStore.game.gem_stack.at(-1)?.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < (goStore.game.gem_stack.at(-1)?.cost ?? Infinity)) || !goStore.self!.turn.effects_availables.some(e => (e.effect == CardEffects.STACK_NEXT_CARD_BOUGHT) && e.usable)">
|
||||
BUY IN STACK (generic)</button>
|
||||
<!-- <button @click="buy_in_hand(props.game.gem_stack.at(-1))">
|
||||
BUY IN HAND
|
||||
</button>
|
||||
<button @click="buy_on_stack(props.game.gem_stack.at(-1))">
|
||||
BUY ON STACK
|
||||
</button> -->
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_CARD_BOUGHT)!, goStore.game.gem_stack.at(-1))"
|
||||
:disabled="(goStore.self === undefined || goStore.game.gem_stack.at(-1)?.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < (goStore.game.gem_stack.at(-1)?.cost ?? Infinity)) || !goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_CARD_BOUGHT)">
|
||||
BUY IN STACK(generic)
|
||||
</button>
|
||||
</template>
|
||||
</CardSlot>
|
||||
<div class="separator"></div>
|
||||
<CardPreview :data="c" v-for="c in goStore.game?.market" @click="c && buy(c)">
|
||||
<CardPreview :data="c" v-for=" c in goStore.game?.market " @click="c && buy(c)">
|
||||
<template v-if="isTurn && c">
|
||||
<button @click="buy(c)"
|
||||
:disabled="goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost">BUY</button>
|
||||
<button
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.PLAY_NEXT_CARD_BOUGHT) && e.usable)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.effects_availables.some(e => (e.effect == CardEffects.PLAY_NEXT_CARD_BOUGHT) && e.usable)">
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.PLAY_NEXT_CARD_BOUGHT)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.find_effect(CardEffects.PLAY_NEXT_CARD_BOUGHT)">
|
||||
BUY IN HAND</button>
|
||||
<button
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.STACK_NEXT_CARD_BOUGHT) && e.usable)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.effects_availables.some(e => (e.effect == CardEffects.STACK_NEXT_CARD_BOUGHT) && e.usable)">
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_CARD_BOUGHT)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_CARD_BOUGHT)">
|
||||
BUY IN STACK (generic)</button>
|
||||
<button v-if="c.card_type == CardType.ACTION"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.STACK_NEXT_ACTION_BOUGHT) && e.usable)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.effects_availables.some(e => (e.effect == CardEffects.STACK_NEXT_ACTION_BOUGHT) && e.usable)">
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_ACTION_BOUGHT)!, c)"
|
||||
:disabled="(goStore.self === undefined || c.cost === undefined || (goStore.self?.turn.gold_reserve ?? 0) < c.cost) || !goStore.self!.turn.find_effect(CardEffects.STACK_NEXT_ACTION_BOUGHT)">
|
||||
BUY IN STACK (actions)</button>
|
||||
</template>
|
||||
</CardPreview>
|
||||
|
||||
@@ -30,8 +30,8 @@ const discard_unwrapped = ref(false)
|
||||
Damage
|
||||
</button>
|
||||
<button v-if="props.player.team != goStore.self?.team"
|
||||
@click="useEffect(goStore.self?.turn.effects_availables.find(e => (e.effect == CardEffects.DISCARD) && e.usable)!, props.player)"
|
||||
:disabled="!goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.DISCARD) && e.usable)">
|
||||
@click="useEffect(props.player.turn.find_effect(CardEffects.DISCARD)!, props.player)"
|
||||
:disabled="!props.player.turn.find_effect(CardEffects.DISCARD)">
|
||||
make Discard</button>
|
||||
|
||||
<div id="turn_data">
|
||||
@@ -94,10 +94,9 @@ const discard_unwrapped = ref(false)
|
||||
:disabled="c.uuid in props.player.turn.cards_locked">
|
||||
LOCK
|
||||
</button>
|
||||
<button
|
||||
v-if="isSelf && isTurn && props.player.turn.effects_availables.some(e => (e.effect == CardEffects.SACRIFICE) && e.usable)"
|
||||
<button v-if="isSelf && isTurn && props.player.turn.find_effect(CardEffects.SACRIFICE)"
|
||||
:disabled="!goStore.self || !c || c.uuid in props.player.turn.cards_locked"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.SACRIFICE) && e.usable)!, c)">SACRIFICE</button>
|
||||
@click="useEffect(props.player.turn.find_effect(CardEffects.SACRIFICE)!, c)">SACRIFICE</button>
|
||||
|
||||
|
||||
<div>{{ c.health_as_champion }}</div>
|
||||
@@ -106,8 +105,8 @@ const discard_unwrapped = ref(false)
|
||||
:disabled="(goStore.self?.turn.damage_reserve ?? 0) <= 0"
|
||||
@click="damage_champion(c)">DAMAGE</button>
|
||||
<button
|
||||
v-if="!isSelf && !isTurn && goStore.self?.team == goStore.game?.current_turn && goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.STUN) && e.usable) && (c.health_as_champion ?? 0) > 0"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.STUN) && e.usable)!, c)">STUN</button>
|
||||
v-if="!isSelf && !isTurn && goStore.self?.team == props.player.turn.find_effect(CardEffects.STUN) && (c.health_as_champion ?? 0) > 0"
|
||||
@click="useEffect(props.player.turn.find_effect(CardEffects.STUN)!, c)">STUN</button>
|
||||
</CardPreview>
|
||||
</div>
|
||||
|
||||
|
||||
+14
-15
@@ -17,8 +17,8 @@ const discard_unwrapped = ref(false)
|
||||
Heal
|
||||
</button>
|
||||
<button v-if="goStore.self && goStore.self?.team != goStore.self?.team"
|
||||
@click="useEffect(goStore.self?.turn.effects_availables.find(e => (e.effect == CardEffects.DISCARD) && e.usable)!, goStore.self)"
|
||||
:disabled="!goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.DISCARD) && e.usable)">
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.DISCARD)!, goStore.self)"
|
||||
:disabled="!goStore.self!.turn.find_effect(CardEffects.DISCARD)">
|
||||
make Discard</button>
|
||||
<div id="turn_data">
|
||||
|
||||
@@ -62,7 +62,7 @@ const discard_unwrapped = ref(false)
|
||||
<span>discard_markers = {{ goStore.self?.turn.discard_markers }} <br></span>
|
||||
<span>effects_availables = <div v-for="e in goStore.self?.turn.effects_availables">
|
||||
<button @click="useEffect(e)" :disabled="!e.usable">
|
||||
{{ e.effect + ' ' + e.effect_type }}
|
||||
{{ e.effect + ' ' + e.effect_type + ' ' + e.amount }}
|
||||
</button>
|
||||
|
||||
</div></span>
|
||||
@@ -77,15 +77,14 @@ const discard_unwrapped = ref(false)
|
||||
:disabled="c.uuid in goStore.self?.turn.cards_locked">
|
||||
LOCK
|
||||
</button>
|
||||
<button
|
||||
v-if="isTurn && goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.SACRIFICE) && e.usable)"
|
||||
<button v-if="isTurn && goStore.self!.turn.find_effect(CardEffects.SACRIFICE)"
|
||||
:disabled="!goStore.self || !c || c.uuid in goStore.self?.turn.cards_locked"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.SACRIFICE) && e.usable)!, c)">SACRIFICE</button>
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.SACRIFICE)!, c)">SACRIFICE</button>
|
||||
|
||||
<button
|
||||
v-if="isTurn && goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.PREPARE) && e.usable) && c.card_type == CardType.CHAMPION"
|
||||
v-if="isTurn && goStore.self!.turn.find_effect(CardEffects.PREPARE) && c.card_type == CardType.CHAMPION"
|
||||
:disabled="!goStore.self || !c || !(c.uuid in goStore.self?.turn.cards_locked)"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.PREPARE) && e.usable)!, c)">PREPARE</button>
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.PREPARE)!, c)">PREPARE</button>
|
||||
|
||||
|
||||
<div>{{ c.health_as_champion }}</div>
|
||||
@@ -99,23 +98,23 @@ const discard_unwrapped = ref(false)
|
||||
<input type="checkbox" v-model="discard_unwrapped" />
|
||||
<div class="cards_container">
|
||||
|
||||
<template v-for="c in goStore.self?.discard_pile ">
|
||||
<template v-for="c in goStore.self?.discard_pile ">
|
||||
<CardPreview :data="c" :wrapped="!discard_unwrapped">
|
||||
<!-- <button v-if="isSelf && isTurn" @click="play_from_discard(c)">DRAW</button>
|
||||
<button v-if="isSelf && isTurn" @click="put_on_stack_from_discard(c)">PUT ON STACK</button>
|
||||
-->
|
||||
<button v-if="isTurn && c.card_type == CardType.CHAMPION"
|
||||
:disabled="!goStore.self || !c || !goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.RESTACK_DISCARDED_CHAMPION) && e.usable)"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.RESTACK_DISCARDED_CHAMPION) && e.usable)!, c)">RESTACK
|
||||
:disabled="!goStore.self || !c || !goStore.self!.turn.find_effect(CardEffects.RESTACK_DISCARDED_CHAMPION)"
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.RESTACK_DISCARDED_CHAMPION)!, c)">RESTACK
|
||||
(champion)</button>
|
||||
|
||||
<button v-if="isTurn"
|
||||
:disabled="!goStore.self || !c || !goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.RESTACK_DISCARDED_CARD) && e.usable)"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.RESTACK_DISCARDED_CARD) && e.usable)!, c)">RESTACK
|
||||
:disabled="!goStore.self || !c || !goStore.self!.turn.find_effect(CardEffects.RESTACK_DISCARDED_CARD)"
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.RESTACK_DISCARDED_CARD)!, c)">RESTACK
|
||||
(card)</button>
|
||||
<button v-if="isTurn"
|
||||
:disabled="!goStore.self || !c || !goStore.self?.turn.effects_availables.some(e => (e.effect == CardEffects.SACRIFICE) && e.usable)"
|
||||
@click="useEffect(goStore.self!.turn.effects_availables.find(e => (e.effect == CardEffects.SACRIFICE) && e.usable)!, c)">SACRIFICE</button>
|
||||
:disabled="!goStore.self || !c || !goStore.self!.turn.find_effect(CardEffects.SACRIFICE)"
|
||||
@click="useEffect(goStore.self!.turn.find_effect(CardEffects.SACRIFICE)!, c)">SACRIFICE</button>
|
||||
</CardPreview>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
+9
-2
@@ -1,6 +1,6 @@
|
||||
import { type GameObjectRegister } from "."
|
||||
import type { Card } from "./Card"
|
||||
import { type Effect } from "./Effect"
|
||||
import { type Effect, CardEffects } from "./Effect"
|
||||
import type { GameObjectNetcode } from "./GameObject"
|
||||
export interface TurnNetcode extends GameObjectNetcode {
|
||||
cards_locked: Array<string>
|
||||
@@ -17,9 +17,10 @@ export type Turn = Omit<TurnNetcode, 'cards_locked' | 'effects_availables' | 'ch
|
||||
cards_locked: { [key: string]: Card }
|
||||
effects_availables: Array<Effect>
|
||||
champions_health: Map<string, number>
|
||||
find_effect: (card_effect: CardEffects) => Effect | undefined
|
||||
}
|
||||
export function create_turn(input: TurnNetcode, register: GameObjectRegister) {
|
||||
return new Proxy<any>(input, {
|
||||
const turn = new Proxy<any>(input, {
|
||||
get(target: TurnNetcode, prop, reciever) {
|
||||
if (prop == "cards_locked") {
|
||||
return Object.fromEntries(target.cards_locked.map(e => [e, register.cards.get(e)]))
|
||||
@@ -34,10 +35,16 @@ export function create_turn(input: TurnNetcode, register: GameObjectRegister) {
|
||||
}
|
||||
return healths
|
||||
}
|
||||
if (prop == "find_effect") {
|
||||
return (card_effect: CardEffects) => {
|
||||
return turn.effects_availables.find(e => (e.effect == card_effect) && e.usable)
|
||||
}
|
||||
}
|
||||
return Reflect.get(target, prop, reciever);
|
||||
},
|
||||
set(target, prop, val, receiver) {
|
||||
return Reflect.set(target, prop, val, receiver);
|
||||
}
|
||||
}) as Turn
|
||||
return turn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user