BlueGit

timfa questward

Fix spawner spell cast-chance label to use Magic vs spell tier.

Show channel success from Level-as-Magic and the selected spell's tier instead of the AI attempt percent.

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
cb48b6eae7b8407c1225a9dfc3de20be738f4754
Parent
f5867861
3 files changed +38 −7
client/src/editor/tileConfigModal.js +15 −5
@@ -10,7 +10,7 @@ import
10 10 isCentralExchangeSpawner,
11 11 spawnerEquipmentSlot
12 12 } from "/shared/definitions/mobs.js";
13 import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";
13 import { spellCastSuccessChancePercent } from "/shared/combat/magic.js";
14 14 import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
15 15 import { centralExchangeStaffCount } from "/shared/market/exchange.js";
16 16 import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
@@ -23,6 +23,15 @@ import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js"
23 23 const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);
24 24 const ITEM_SEARCH_PAGE_SIZE = 40;
25 25
26 function formatCastChancePercent (pct)
27 {
28 const n = Number(pct);
29 if (!Number.isFinite(n))
30 { return "0"; }
31 const rounded = Math.round(n * 10) / 10;
32 return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
33 }
34
26 35 /** Items that can be worn in a given equipment slot. */
27 36 export function listEquippableItemsForSlot (slot)
28 37 {
@@ -837,7 +846,7 @@ export function initTileConfigModal ({
837 846
838 847 const hint = document.createElement("p");
839 848 hint.className = "hint";
840 hint.textContent = "Cast chance is derived from the mob Level (shown as a label). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
849 hint.textContent = "Cast success uses the mob Level as Magic vs the spell tier (same contest as players). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
841 850 wrap.append(hint);
842 851
843 852 if (!Array.isArray(spellsDraft) || !spellsDraft.length)
@@ -865,7 +874,6 @@ export function initTileConfigModal ({
865 874 return;
866 875 }
867 876 const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;
868 const castChance = mobSpellCastChancePercent(level);
869 877 for (let index = 0; index < spellsDraft.length; index++)
870 878 {
871 879 const line = spellsDraft[index];
@@ -893,12 +901,14 @@ export function initTileConfigModal ({
893 901 });
894 902
895 903 const minLv = def?.minMagicLevel | 0 || 1;
904 const tier = def?.tier | 0 || 1;
905 const successPct = spellCastSuccessChancePercent(level, tier);
896 906 const chanceLabel = document.createElement("span");
897 907 chanceLabel.className = "hint";
898 chanceLabel.title = "Cast chance from mob Level";
908 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${tier * 2})`;
899 909 chanceLabel.textContent = level < minLv
900 910 ? `needs Lv.${minLv}`
901 : `cast ${castChance}%`;
911 : `cast ${formatCastChancePercent(successPct)}%`;
902 912
903 913 const remove = document.createElement("button");
904 914 remove.type = "button";
@@ -10,7 +10,7 @@ import
10 isCentralExchangeSpawner,
10 isCentralExchangeSpawner,
11 spawnerEquipmentSlot
11 spawnerEquipmentSlot
12} from "/shared/definitions/mobs.js";
12} from "/shared/definitions/mobs.js";
13import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";
13import { spellCastSuccessChancePercent } from "/shared/combat/magic.js";
14import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
14import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
15import { centralExchangeStaffCount } from "/shared/market/exchange.js";
15import { centralExchangeStaffCount } from "/shared/market/exchange.js";
16import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
16import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
@@ -23,6 +23,15 @@ import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js"
23const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);
23const DOORWAY_STATES = Object.freeze(["door", "ladder", "hole", "cave"]);
24const ITEM_SEARCH_PAGE_SIZE = 40;
24const ITEM_SEARCH_PAGE_SIZE = 40;
25
25
26function formatCastChancePercent (pct)
27{
28 const n = Number(pct);
29 if (!Number.isFinite(n))
30 { return "0"; }
31 const rounded = Math.round(n * 10) / 10;
32 return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
33}
34
26/** Items that can be worn in a given equipment slot. */
35/** Items that can be worn in a given equipment slot. */
27export function listEquippableItemsForSlot (slot)
36export function listEquippableItemsForSlot (slot)
28{
37{
@@ -837,7 +846,7 @@ export function initTileConfigModal ({
837
846
838 const hint = document.createElement("p");
847 const hint = document.createElement("p");
839 hint.className = "hint";
848 hint.className = "hint";
840 hint.textContent = "Cast chance is derived from the mob Level (shown as a label). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
849 hint.textContent = "Cast success uses the mob Level as Magic vs the spell tier (same contest as players). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
841 wrap.append(hint);
850 wrap.append(hint);
842
851
843 if (!Array.isArray(spellsDraft) || !spellsDraft.length)
852 if (!Array.isArray(spellsDraft) || !spellsDraft.length)
@@ -865,7 +874,6 @@ export function initTileConfigModal ({
865 return;
874 return;
866 }
875 }
867 const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;
876 const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;
868 const castChance = mobSpellCastChancePercent(level);
869 for (let index = 0; index < spellsDraft.length; index++)
877 for (let index = 0; index < spellsDraft.length; index++)
870 {
878 {
871 const line = spellsDraft[index];
879 const line = spellsDraft[index];
@@ -893,12 +901,14 @@ export function initTileConfigModal ({
893 });
901 });
894
902
895 const minLv = def?.minMagicLevel | 0 || 1;
903 const minLv = def?.minMagicLevel | 0 || 1;
904 const tier = def?.tier | 0 || 1;
905 const successPct = spellCastSuccessChancePercent(level, tier);
896 const chanceLabel = document.createElement("span");
906 const chanceLabel = document.createElement("span");
897 chanceLabel.className = "hint";
907 chanceLabel.className = "hint";
898 chanceLabel.title = "Cast chance from mob Level";
908 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${tier * 2})`;
899 chanceLabel.textContent = level < minLv
909 chanceLabel.textContent = level < minLv
900 ? `needs Lv.${minLv}`
910 ? `needs Lv.${minLv}`
901 : `cast ${castChance}%`;
911 : `cast ${formatCastChancePercent(successPct)}%`;
902
912
903 const remove = document.createElement("button");
913 const remove = document.createElement("button");
904 remove.type = "button";
914 remove.type = "button";
shared/combat/magic.js +21 −0
@@ -1,5 +1,6 @@
1 1 import { rollSkill } from "./rolls.js";
2 2 import { damageTypeMultiplier, MagicElement } from "../definitions/attackTypes.js";
3 import { spellDifficultyFromTier } from "../spells/constants.js";
3 4
4 5 /**
5 6 * Magic attack resolution — cast step is implemented; full combat wiring is later.
@@ -40,6 +41,26 @@ export function resolveSpellCast ({
40 41 };
41 42 }
42 43
44 /**
45 * Exact P(Magic roll ≥ difficulty roll) as a percent (0–100).
46 * Magic and difficulty dice are uniform integers in [0..level] / [0..tier×2].
47 * @param {number} magicSkillLevel
48 * @param {number} spellTier
49 */
50 export function spellCastSuccessChancePercent (magicSkillLevel, spellTier)
51 {
52 const magic = Math.max(0, Math.floor(Number(magicSkillLevel) || 0));
53 const difficulty = spellDifficultyFromTier(spellTier);
54 let successes = 0;
55 const outcomes = (magic + 1) * (difficulty + 1);
56 for (let d = 0; d <= difficulty; d++)
57 {
58 if (d <= magic)
59 { successes += magic - d + 1; }
60 }
61 return (successes / outcomes) * 100;
62 }
63
43 64 function normalizeSpellElement (element)
44 65 {
45 66 if (element === "holy")
@@ -1,5 +1,6 @@
1import { rollSkill } from "./rolls.js";
1import { rollSkill } from "./rolls.js";
2import { damageTypeMultiplier, MagicElement } from "../definitions/attackTypes.js";
2import { damageTypeMultiplier, MagicElement } from "../definitions/attackTypes.js";
3import { spellDifficultyFromTier } from "../spells/constants.js";
3
4
4/**
5/**
5 * Magic attack resolution — cast step is implemented; full combat wiring is later.
6 * Magic attack resolution — cast step is implemented; full combat wiring is later.
@@ -40,6 +41,26 @@ export function resolveSpellCast ({
40 };
41 };
41}
42}
42
43
44/**
45 * Exact P(Magic roll ≥ difficulty roll) as a percent (0–100).
46 * Magic and difficulty dice are uniform integers in [0..level] / [0..tier×2].
47 * @param {number} magicSkillLevel
48 * @param {number} spellTier
49 */
50export function spellCastSuccessChancePercent (magicSkillLevel, spellTier)
51{
52 const magic = Math.max(0, Math.floor(Number(magicSkillLevel) || 0));
53 const difficulty = spellDifficultyFromTier(spellTier);
54 let successes = 0;
55 const outcomes = (magic + 1) * (difficulty + 1);
56 for (let d = 0; d <= difficulty; d++)
57 {
58 if (d <= magic)
59 { successes += magic - d + 1; }
60 }
61 return (successes / outcomes) * 100;
62}
63
43function normalizeSpellElement (element)
64function normalizeSpellElement (element)
44{
65{
45 if (element === "holy")
66 if (element === "holy")
shared/definitions/mobCombat.js +2 −2
@@ -82,8 +82,8 @@ export function mobHealthForLevel (def, level)
82 82 }
83 83
84 84 /**
85 * Mob spell cast chance % derived from spawner/creature level (1–100).
86 * Editor shows this as a label; it is not authorable per spell.
85 * AI chance (1–100) that a fighting mob *attempts* a known spell instead of melee.
86 * Separate from channel success ({@link spellCastSuccessChancePercent}).
87 87 */
88 88 export function mobSpellCastChancePercent (level)
89 89 {
@@ -82,8 +82,8 @@ export function mobHealthForLevel (def, level)
82}
82}
83
83
84/**
84/**
85 * Mob spell cast chance % derived from spawner/creature level (1–100).
85 * AI chance (1–100) that a fighting mob *attempts* a known spell instead of melee.
86 * Editor shows this as a label; it is not authorable per spell.
86 * Separate from channel success ({@link spellCastSuccessChancePercent}).
87 */
87 */
88export function mobSpellCastChancePercent (level)
88export function mobSpellCastChancePercent (level)
89{
89{