From 2a8435f5391964d5206c4b9090fb2b163357ed42 Mon Sep 17 00:00:00 2001 From: Jan Stevens Date: Thu, 21 Dec 2023 12:24:15 +0100 Subject: [PATCH] fix: ensure scenario 28 special rule is applied --- next.config.js | 1 + src/data/scenarios.ts | 20 ++++---------------- src/hooks/useDecks.ts | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/next.config.js b/next.config.js index 8486f36..23dd000 100644 --- a/next.config.js +++ b/next.config.js @@ -30,6 +30,7 @@ const securityHeaders = [ const nextConfig = { reactStrictMode: true, outputFileTracing: true, + poweredByHeader: false, typescript: { ignoreBuildErrors: true, }, diff --git a/src/data/scenarios.ts b/src/data/scenarios.ts index b06e4da..419957b 100644 --- a/src/data/scenarios.ts +++ b/src/data/scenarios.ts @@ -1,13 +1,3 @@ -//special_rules should be treated with some kind of macro that recognises them and applies them when loading -export const SPECIAL_RULES = { - living_corpse_two_levels_extra: { - description: - 'All living corpses are two levels higher than the scenario level, up to a max of 7', - affected_deck: 'Living Corpse', - extra_levels: 2, - }, -}; - export const SCENARIO_DEFINITIONS = [ { name: '#1 Black Barrow', @@ -291,15 +281,13 @@ export const SCENARIO_DEFINITIONS = [ { name: 'Night Demon' }, { name: 'Sun Demon' }, ], - special_rules: [ + id: 28, + specialRules: [ { - description: - 'All living corpses are two levels higher than the scenario level, up to a max of 7', - affected_deck: 'Living Corpse', + deck: 'Living Corpse', extra_levels: 2, }, ], - id: 28, }, { name: '#29 Sanctuary of Gloom', @@ -922,4 +910,4 @@ export const SCENARIO_DEFINITIONS = [ ], id: 95, }, -] as const; +]; diff --git a/src/hooks/useDecks.ts b/src/hooks/useDecks.ts index 1bdc681..1718fee 100644 --- a/src/hooks/useDecks.ts +++ b/src/hooks/useDecks.ts @@ -33,6 +33,19 @@ export interface BossDeck { cards: (typeof DECK_DEFINITIONS)['Boss']['cards']; } +const getScenarioLevelForDeck = ( + scenario: Scenario, + level: number, + deck: DeckNames, +) => { + if (!scenario.specialRules?.length) return level; + const matchingSpecialRule = scenario.specialRules.find( + (rule) => rule.deck === deck, + ); + if (!matchingSpecialRule) return level; + return Math.min(7, matchingSpecialRule.extra_levels + level); +}; + export const useDecks = ( scenario: Scenario | undefined, level: number, @@ -58,8 +71,11 @@ export const useDecks = ( const deckName = scenarioDeck.name as Exclude; const deckClass = DECKS[deckName]?.class; const deck = DECK_DEFINITIONS[deckClass]; - - const stats = getMonsterStats(deckName as ScenarioMonsterNames, level); + const adjustedLevel = getScenarioLevelForDeck(scenario, level, deckName); + const stats = getMonsterStats( + deckName as ScenarioMonsterNames, + adjustedLevel, + ); return { name: deckName,