Skip to content

Commit

Permalink
* Unify handling of Elvish and Kophtanic representations
Browse files Browse the repository at this point in the history
Theoretically, any number of new representations with comparable rules could be implemented with ease now.
  • Loading branch information
kreuvf committed May 12, 2024
1 parent e75376e commit 5844855
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions Das_Schwarze_Auge_4-1/dev/js/magic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ function replaceSpellStats(spellData, stats) {
debugLog(func, spellData, stats);

let modified = false;
let replacement = { "replaceable": "", "replacer": "" };
switch (spellData["representation"]) {
case "Ach":
// Block required to encapsulate consts
{
debugLog(func, "Adapting for achaz rep");
debugLog(func, "Attempting replacement for Crystallomantic representation (Ach)");
// Replacement is not improving anything, so break
if (stats['KL'] === stats['IN']) break;

Expand Down Expand Up @@ -67,10 +68,19 @@ function replaceSpellStats(spellData, stats) {
break;
}
case "Elf":
debugLog(func, "Attempting replacement for Elvish representation (Elf)");
replacement["replaceable"] = "KL";
replacement["replacer"] = "IN";
case "Kop":
// Block required to encapsulate consts
{
debugLog(func, "Adapting for elven rep");
const replacement = { "replaceable": "KL", "replacer": "IN" };
// Prevent replacing replacement in "Elf" case
if (replacement["replaceable"] === "" && replacement["replacer"] === "")
{
debugLog(func, "Attempting replacement for Kophtanic representation (Kop)");
replacement["replaceable"] = "KL";
replacement["replacer"] = "CH";
}
if (stats[replacement["replaceable"]] >= stats[replacement["replacer"]])
{
break;
Expand Down Expand Up @@ -102,20 +112,8 @@ function replaceSpellStats(spellData, stats) {
}
break;
}
case "Kop":
debugLog(func, "Adapting for kophtan rep");
if (charData['KL'] >= charData['CH']) {
break;
}
for (let i = 0; i < 3; i++) {
if (spellStats[i] === "KL" && (spellStats[(i+1) % 3] !== "CH" || spellStats[(i + 2) % 3] !== "CH")) {
spellStats[i] = "CH";
modified = true;
break;
}
}
break;
default:
debugLog(func, "No representation suitable for replacements found:", spellData["representation"]);
break;
}
return modified;
Expand Down

0 comments on commit 5844855

Please sign in to comment.