Skip to content

Commit

Permalink
fix: language specializations always cost 1 AP and are multi-buyable
Browse files Browse the repository at this point in the history
Fixes #1082
  • Loading branch information
elyukai committed May 7, 2021
1 parent 3ceeadb commit 0a59d9e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 50 deletions.
31 changes: 13 additions & 18 deletions src/App/Utilities/Activatable/activatableInactiveUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -546,7 +546,7 @@ const modifySelectOptions =
const available_langs =

// Pair: fst = sid, snd = current_level
maybe (List<Pair<number, number>> ())
maybe (List<number> ())
(pipe (
ADA.active,
foldr ((obj: Record<ActiveObject>) =>
Expand All @@ -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<List<Pair<number, number>>>
ident as ident<List<number>>
)
))
(List ())
Expand All @@ -577,21 +573,20 @@ const modifySelectOptions =
))

const filterLanguages =
foldr (isNoRequiredOrActiveSelection
foldr (isNoRequiredSelection
(e => {
const lang =
find ((l: Pair<number, number>) =>
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)
}

Expand Down
28 changes: 22 additions & 6 deletions src/App/Utilities/Activatable/activatableInactiveViewUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)),
)),
),
})
)
Expand Down
27 changes: 1 addition & 26 deletions src/App/Utilities/AdventurePoints/activatableCostUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<string> (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:
Expand Down

0 comments on commit 0a59d9e

Please sign in to comment.