From 0a59d9e5e571e87525b18d0b25035e73f7cd87bf Mon Sep 17 00:00:00 2001 From: Lukas Obermann Date: Sat, 8 May 2021 01:04:16 +0200 Subject: [PATCH] fix: language specializations always cost 1 AP and are multi-buyable Fixes #1082 --- .../Activatable/activatableInactiveUtils.ts | 31 ++++++++----------- .../activatableInactiveViewUtils.tsx | 28 +++++++++++++---- .../AdventurePoints/activatableCostUtils.ts | 27 +--------------- 3 files changed, 36 insertions(+), 50 deletions(-) diff --git a/src/App/Utilities/Activatable/activatableInactiveUtils.ts b/src/App/Utilities/Activatable/activatableInactiveUtils.ts index 811d21137..b6ee79628 100644 --- a/src/App/Utilities/Activatable/activatableInactiveUtils.ts +++ b/src/App/Utilities/Activatable/activatableInactiveUtils.ts @@ -18,7 +18,7 @@ import { add, gt, gte, inc, multiply } from "../../../Data/Num" import { alter, elems, foldrWithKey, isOrderedMap, lookup, lookupF, member, OrderedMap } from "../../../Data/OrderedMap" import { Record, RecordI } from "../../../Data/Record" import { filterMapListT, filterT, mapT } from "../../../Data/Transducer" -import { fst, Pair, snd, Tuple } from "../../../Data/Tuple" +import { Tuple } from "../../../Data/Tuple" import { traceShowId } from "../../../Debug/Trace" import { Aspect, CombatTechniqueGroupId, MagicalTradition, SkillGroup, SpecialAbilityGroup } from "../../Constants/Groups" import { AdvantageId, DisadvantageId, SkillId, SpecialAbilityId } from "../../Constants/Ids.gen" @@ -546,7 +546,7 @@ const modifySelectOptions = const available_langs = // Pair: fst = sid, snd = current_level - maybe (List> ()) + maybe (List ()) (pipe ( ADA.active, foldr ((obj: Record) => @@ -558,14 +558,10 @@ const modifySelectOptions = guard (is3or4 (current_level)), thenF (AOA.sid (obj)), misNumberM, - fmap (current_sid => - consF (Pair ( - current_sid, - current_level - ))) + fmap (consF) )), fromMaybe ( - ident as ident>> + ident as ident> ) )) (List ()) @@ -577,21 +573,20 @@ const modifySelectOptions = )) const filterLanguages = - foldr (isNoRequiredOrActiveSelection + foldr (isNoRequiredSelection (e => { const lang = - find ((l: Pair) => - fst (l) === SOA.id (e)) + find ((l: number) => l === SOA.id (e)) (available_langs) - if (isJust (lang)) { - const isMotherTongue = - snd (fromJust (lang)) === 4 - - if (isMotherTongue) { - return consF (set (SOL.cost) (Just (0)) (e)) - } + // a language must provide either a set of + // possible specializations or an input where a + // custom specialization can be entered. + const provides_specific_or_input = + Maybe.any (notNull) (SOA.specializations (e)) + || isJust (SOA.specializationInput (e)) + if (isJust (lang) && provides_specific_or_input) { return consF (e) } diff --git a/src/App/Utilities/Activatable/activatableInactiveViewUtils.tsx b/src/App/Utilities/Activatable/activatableInactiveViewUtils.tsx index ce172eaa2..c051c94b4 100644 --- a/src/App/Utilities/Activatable/activatableInactiveViewUtils.tsx +++ b/src/App/Utilities/Activatable/activatableInactiveViewUtils.tsx @@ -480,6 +480,19 @@ export const getIdSpecificAffectedAndDispatchProps = const mspec_input = bind (moption) (SOA.specializationInput) + const active_specializations_for_language = pipe_ ( + entry, + IAA.heroEntry, + liftM2 ((language_id: string | number) => pipe ( + ADA.active, + mapMaybe (ao => Maybe.elem (language_id) (AOA.sid (ao)) + ? pipe_ (ao, AOA.sid2, misNumberM) + : Nothing) + )) + (mselected), + fromMaybe (List ()) + ) + return Pair ( ActivatableActivationOptions ({ id, @@ -499,12 +512,15 @@ export const getIdSpecificAffectedAndDispatchProps = pipe_ ( moption, bindF (SOA.specializations), - fmap (imap (i => name => SelectOption ({ - id: i + 1, - name, - src: pipe_ (entry, IAA.wikiEntry, SAAL.src), - errata: Nothing, - }))) + fmap (pipe ( + imap (i => name => SelectOption ({ + id: i + 1, + name, + src: pipe_ (entry, IAA.wikiEntry, SAAL.src), + errata: Nothing, + })), + filter (so => List.notElem (SOA.id (so)) (active_specializations_for_language)), + )), ), }) ) diff --git a/src/App/Utilities/AdventurePoints/activatableCostUtils.ts b/src/App/Utilities/AdventurePoints/activatableCostUtils.ts index 1e6096868..aaf4b49ad 100644 --- a/src/App/Utilities/AdventurePoints/activatableCostUtils.ts +++ b/src/App/Utilities/AdventurePoints/activatableCostUtils.ts @@ -11,7 +11,7 @@ import { cnst, flip, ident } from "../../../Data/Function" import { fmap, fmapF } from "../../../Data/Functor" import { over, set } from "../../../Data/Lens" -import { appendStr, countWith, filter, find, foldl, ifoldr, isList, List, map, notElem, notNull, subscript, subscriptF, sum } from "../../../Data/List" +import { appendStr, countWith, filter, foldl, ifoldr, isList, List, map, notElem, notNull, subscript, subscriptF, sum } from "../../../Data/List" import { any, bind, bindF, elem, elemF, ensure, fromJust, fromMaybe, isJust, isNothing, joinMaybeList, Just, liftM2, listToMaybe, mapMaybe, Maybe, maybe, Nothing } from "../../../Data/Maybe" import { add, dec, gt, multiply, negate } from "../../../Data/Num" import { lookup, lookupF } from "../../../Data/OrderedMap" @@ -354,31 +354,6 @@ const getEntrySpecificCost = )) } - case SpecialAbilityId.LanguageSpecializations: { - if (isNothing (mcurrent_sid)) { - return Nothing - } - - const current_sid = fromJust (mcurrent_sid) - - return pipe ( - HA.specialAbilities, - lookup (SpecialAbilityId.Language), - bindF (pipe ( - ActivatableDependent.A.active, - - // Get the `ActiveObject` for the corresponding language - find (pipe (ActiveObject.A.sid, elem (current_sid))) - )), - bindF (ActiveObject.A.tier), - - // If it's a native language, it costs nothing, otherwise - // the default SA's AP - bindF (level => level === 4 ? Nothing : misNumberM (mcurrent_cost)) - ) - (hero) - } - case SpecialAbilityId.Handwerkskunst: case SpecialAbilityId.KindDerNatur: case SpecialAbilityId.KoerperlichesGeschick: