From 2c7a3c77cadacf7dd9febcd99c0fa8c1aaf021a5 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Fri, 17 May 2024 14:24:24 +0200 Subject: [PATCH] Fix: add effect.times check for effect.usable getter Closes #58 --- netcode/Effect.ts | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/netcode/Effect.ts b/netcode/Effect.ts index 4ba45d8..dd10f04 100644 --- a/netcode/Effect.ts +++ b/netcode/Effect.ts @@ -1,5 +1,5 @@ import { GameObjectRegister } from "." -import type { Card } from "./Card" +import { CardType, type Card } from "./Card" import type { GameObjectNetcode } from "./GameObject" export enum CardEffects { @@ -23,7 +23,8 @@ export 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" + PER_CARD_OF_SAME_FACTION = "per_card_of_same_faction", + PER_OTHER_CARD_OF_SAME_FACTION = "per_other_card_of_same_faction" } export enum EffectType { @@ -42,7 +43,7 @@ export interface EffectNetcode extends GameObjectNetcode { times?: EffectTimes } -export type Effect = Omit & { +export type Effect = Omit & { sub_effects: { [key: string]: Effect } mutex: { [key: string]: Effect } card: Card @@ -60,20 +61,28 @@ export function create_effect(input: EffectNetcode, register: GameObjectRegister return Object.fromEntries(Object.entries(register.effects).filter(([i, v]) => i in target.mutex)) } if (prop == "usable") { - if (target.effect_type === EffectType.FACTION_COMBO) { - if (!register.self) { return false } - // ugly bastard - let cardLocked = register.self.value?.turn.cards_locked - if(!cardLocked) { return false } - let cardList = Object.values(cardLocked) - const card = cardList.find(c => c.effects.map(e => e.uuid).includes(effect.uuid)) + // ugly bastard + if (!register.self) { return false } - if (!card) { return false } - return cardList.some(c => c !== card && c.faction === card.faction) + let cardLocked = register.self.value?.turn?.cards_locked + if (!cardLocked) { return false } + let cardList = Object.values(cardLocked) + const card = cardList.find(c => c.effects.map(e => e.uuid).includes(effect.uuid)) + if (!card) { return false } + + if (target.effect_type === EffectType.FACTION_COMBO) { + if (!cardList.some(c => c !== card && c.faction === card.faction)) { return false } + } + if (target.times === EffectTimes.PER_OTHER_CARD_OF_SAME_FACTION) { + if (!cardList.some(c => c !== card && c.faction === card.faction)) { return false } + } else if (target.times === EffectTimes.PER_OTHER_CHAMPION) { + if (!cardList.some(c => c !== card && c.card_type === CardType.CHAMPION)) { return false } + } else if (target.times === EffectTimes.PER_OTHER_GUARD) { + if (!cardList.some(c => c !== card && c.guard)) { return false } } return true } - if (prop == "card"){ + if (prop == "card") { return register.cards.get(target.card) } return Reflect.get(target, prop, reciever);