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