fix: improvement cost handling for some traditions

The refactoring resulted in no spells being available to intuitive mages.

In general, comparing improvement costs directly did not work.
This commit is contained in:
Lukas Obermann
2022-07-22 23:30:16 +02:00
parent d28667a935
commit c52fc26a1b
3 changed files with 42 additions and 17 deletions
@@ -28,7 +28,7 @@ import { getBlessedTradition, mapBlessedTradIdToNumId } from "../Utilities/Activ
import { composeL } from "../Utilities/compose"
import { createMaybeSelector } from "../Utilities/createMaybeSelector"
import { filterAndSortRecordsBy } from "../Utilities/filterAndSortBy"
import { getAPForActivatation, ImprovementCost } from "../Utilities/ImprovementCost"
import { compare, getAPForActivatation, ImprovementCost } from "../Utilities/ImprovementCost"
import { getAspectsOfTradition, isLCDecreasable, isLCIncreasable, isOwnTradition } from "../Utilities/Increasable/liturgicalChantUtils"
import { pipe, pipe_ } from "../Utilities/pipe"
import { filterByAvailability } from "../Utilities/RulesUtils"
@@ -230,7 +230,7 @@ const additionalInactiveListFilter = (
notElem (1) (LCA.tradition (wiki_entry))
&& fullCheck (chant)
const isICValid = LCA.ic (wiki_entry) <= ImprovementCost.C
const isICValid = compare (LCA.ic (wiki_entry), ImprovementCost.C) <= 0
return mapReplace (LCA.id (wiki_entry))
(guard (isTraditionValid && isICValid))
+35 -10
View File
@@ -98,22 +98,47 @@ export const icToIx = (ic: ImprovementCost): number => {
export const strToIcUnsafe = (x: string): ImprovementCost => {
switch (x) {
case "A": return { tag: "A" }
case "B": return { tag: "B" }
case "C": return { tag: "C" }
case "D": return { tag: "D" }
case "E": return { tag: "E" }
case "A": return ImprovementCost.A
case "B": return ImprovementCost.B
case "C": return ImprovementCost.C
case "D": return ImprovementCost.D
case "E": return ImprovementCost.E
default: throw new TypeError (`strToIc: ${x} is not an Improvement Cost`)
}
}
export const strToIc = (x: "A" | "B" | "C" | "D" | "E"): ImprovementCost => {
switch (x) {
case "A": return { tag: "A" }
case "B": return { tag: "B" }
case "C": return { tag: "C" }
case "D": return { tag: "D" }
case "E": return { tag: "E" }
case "A": return ImprovementCost.A
case "B": return ImprovementCost.B
case "C": return ImprovementCost.C
case "D": return ImprovementCost.D
case "E": return ImprovementCost.E
default: return assertUnreachable (x)
}
}
/**
* Negative value means `x1 < x2` and positive value means `x1 > x2`. Comparing
* the result with `0` mirrors the sign:
*
* - `x1 < x2` ≈ `compare(x1, x2) < 0`
* - `x1 >= x2` ≈ `compare(x1, x2) >= 0`
* - `x1 === x2` ≈ `compare(x1, x2) === 0`
*/
export const compare = (x1: ImprovementCost, x2: ImprovementCost): number => {
const toInt = (x: ImprovementCost): number => {
switch (x.tag) {
case "A": return 1
case "B": return 2
case "C": return 3
case "D": return 4
case "E": return 5
default: return assertUnreachable (x)
}
}
return toInt (x1) - toInt (x2)
}
export const equals = (x1: ImprovementCost, x2: ImprovementCost): boolean => x1.tag === x2.tag
+5 -5
View File
@@ -37,7 +37,7 @@ import { mapMagicalTradIdToNumId } from "../Activatable/traditionUtils"
import { flattenDependencies } from "../Dependencies/flattenDependencies"
import { getExperienceLevelAtStart } from "../ELUtils"
import { ifElse } from "../ifElse"
import { ImprovementCost } from "../ImprovementCost"
import { compare, ImprovementCost } from "../ImprovementCost"
import { pipe, pipe_ } from "../pipe"
import { areSpellPrereqisitesMet } from "../Prerequisites/validatePrerequisitesUtils"
import { isNumber, misNumberM } from "../typeCheckUtils"
@@ -464,7 +464,7 @@ const isAnySpellActiveWithImpCostC =
ASDA.id,
lookupF (wiki_spells),
maybe (false)
(pipe (SA.ic, equals (ImprovementCost.C)))
(s => compare (SA.ic (s), ImprovementCost.C) === 0)
)
)
@@ -495,11 +495,11 @@ const isInactiveValidForIntuitiveMage =
&& Maybe.all (notP (ASDA.active)) (mhero_entry)
// No spells with IC D
&& SA.ic (wiki_entry) < ImprovementCost.D
&& compare (SA.ic (wiki_entry), ImprovementCost.D) < 0
// Only one spell with IC C
&& !(
SA.ic (wiki_entry) === ImprovementCost.C
compare (SA.ic (wiki_entry), ImprovementCost.C) === 0
&& isAnySpellActiveWithImpCostC (SDA.spells (wiki)) (HA.spells (hero))
)
@@ -518,7 +518,7 @@ const isInactiveValidForSchelme =
&& Maybe.all (notP (ASDA.active)) (mhero_entry)
// No spells with IC D or C
&& SA.ic (wiki_entry) < ImprovementCost.C
&& compare (SA.ic (wiki_entry), ImprovementCost.C) < 0
// No property Demonic
&& SA.property (wiki_entry) !== Property.Demonic