BlueGit

timfa questward

Start each magic tier at 50% cast chance on unlock.

Spell difficulty is now unlock Magic level + 1 (1/10/20/… gates), so tiers open at exactly 50% and climb with the same contest math.

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
e21c7234e4d072ccb8e889147f808a9e50090e81
Parent
e5528d66
4 files changed +25 −5
client/src/editor/tileConfigModal.js +2 −1
@@ -12,6 +12,7 @@ import
12 12 } from "/shared/definitions/mobs.js";
13 13 import { spellCastSuccessChancePercent } from "/shared/combat/magic.js";
14 14 import { SPELL_DEFINITIONS, spellMinMagicLevel } from "/shared/definitions/spells.js";
15 import { spellDifficultyFromTier } from "/shared/spells/constants.js";
15 16 import { centralExchangeStaffCount } from "/shared/market/exchange.js";
16 17 import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
17 18 import { listRawFishPickerEntries, normalizeFishingSpotConfig, fishTierRankFromItemId } from "/shared/definitions/fishItems.js";
@@ -905,7 +906,7 @@ export function initTileConfigModal ({
905 906 const successPct = spellCastSuccessChancePercent(level, tier);
906 907 const chanceLabel = document.createElement("span");
907 908 chanceLabel.className = "hint";
908 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${tier * 2})`;
909 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${spellDifficultyFromTier(tier)})`;
909 910 chanceLabel.textContent = level < minLv
910 911 ? `needs Lv.${minLv}`
911 912 : `cast ${formatCastChancePercent(successPct)}%`;
@@ -12,6 +12,7 @@ import
12} from "/shared/definitions/mobs.js";
12} from "/shared/definitions/mobs.js";
13import { spellCastSuccessChancePercent } from "/shared/combat/magic.js";
13import { spellCastSuccessChancePercent } from "/shared/combat/magic.js";
14import { SPELL_DEFINITIONS, spellMinMagicLevel } from "/shared/definitions/spells.js";
14import { SPELL_DEFINITIONS, spellMinMagicLevel } from "/shared/definitions/spells.js";
15import { spellDifficultyFromTier } from "/shared/spells/constants.js";
15import { centralExchangeStaffCount } from "/shared/market/exchange.js";
16import { centralExchangeStaffCount } from "/shared/market/exchange.js";
16import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
17import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing, listAllItemPickerEntries } from "/shared/definitions/items.js";
17import { listRawFishPickerEntries, normalizeFishingSpotConfig, fishTierRankFromItemId } from "/shared/definitions/fishItems.js";
18import { listRawFishPickerEntries, normalizeFishingSpotConfig, fishTierRankFromItemId } from "/shared/definitions/fishItems.js";
@@ -905,7 +906,7 @@ export function initTileConfigModal ({
905 const successPct = spellCastSuccessChancePercent(level, tier);
906 const successPct = spellCastSuccessChancePercent(level, tier);
906 const chanceLabel = document.createElement("span");
907 const chanceLabel = document.createElement("span");
907 chanceLabel.className = "hint";
908 chanceLabel.className = "hint";
908 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${tier * 2})`;
909 chanceLabel.title = `Channel success: Magic ${level} vs tier ${tier} (difficulty ${spellDifficultyFromTier(tier)})`;
909 chanceLabel.textContent = level < minLv
910 chanceLabel.textContent = level < minLv
910 ? `needs Lv.${minLv}`
911 ? `needs Lv.${minLv}`
911 : `cast ${formatCastChancePercent(successPct)}%`;
912 : `cast ${formatCastChancePercent(successPct)}%`;
server/tests/magic.test.js +12 −1
@@ -1,6 +1,6 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast } from "../../shared/combat/magic.js";
3 import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast, spellCastSuccessChancePercent } from "../../shared/combat/magic.js";
4 4 import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
5 5 import { spellDifficultyFromTier } from "../../shared/spells/constants.js";
6 6
@@ -82,6 +82,17 @@ test("non-damage spell applies effect only after a successful cast roll", () =>
82 82 assert.equal(result.effectId, "slow");
83 83 });
84 84
85 test("spell difficulty is unlock Magic level + 1 (50% at unlock)", () =>
86 {
87 assert.equal(spellDifficultyFromTier(1), 2);
88 assert.equal(spellDifficultyFromTier(2), 11);
89 assert.equal(spellDifficultyFromTier(3), 21);
90 assert.equal(spellDifficultyFromTier(7), 91);
91 assert.equal(Math.round(spellCastSuccessChancePercent(1, 1)), 50);
92 assert.equal(Math.round(spellCastSuccessChancePercent(10, 2)), 50);
93 assert.equal(Math.round(spellCastSuccessChancePercent(90, 7)), 50);
94 });
95
85 96 test("spell definitions expose tier-based difficulty", () =>
86 97 {
87 98 const firebolt = spellDefinition(SpellId.firebolt);
@@ -1,6 +1,6 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast } from "../../shared/combat/magic.js";
3import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast, spellCastSuccessChancePercent } from "../../shared/combat/magic.js";
4import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
4import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
5import { spellDifficultyFromTier } from "../../shared/spells/constants.js";
5import { spellDifficultyFromTier } from "../../shared/spells/constants.js";
6
6
@@ -82,6 +82,17 @@ test("non-damage spell applies effect only after a successful cast roll", () =>
82 assert.equal(result.effectId, "slow");
82 assert.equal(result.effectId, "slow");
83});
83});
84
84
85test("spell difficulty is unlock Magic level + 1 (50% at unlock)", () =>
86{
87 assert.equal(spellDifficultyFromTier(1), 2);
88 assert.equal(spellDifficultyFromTier(2), 11);
89 assert.equal(spellDifficultyFromTier(3), 21);
90 assert.equal(spellDifficultyFromTier(7), 91);
91 assert.equal(Math.round(spellCastSuccessChancePercent(1, 1)), 50);
92 assert.equal(Math.round(spellCastSuccessChancePercent(10, 2)), 50);
93 assert.equal(Math.round(spellCastSuccessChancePercent(90, 7)), 50);
94});
95
85test("spell definitions expose tier-based difficulty", () =>
96test("spell definitions expose tier-based difficulty", () =>
86{
97{
87 const firebolt = spellDefinition(SpellId.firebolt);
98 const firebolt = spellDefinition(SpellId.firebolt);
shared/combat/magic.js +1 −1
@@ -43,7 +43,7 @@ export function resolveSpellCast ({
43 43
44 44 /**
45 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].
46 * Magic and difficulty dice are uniform integers in [0..level] / [0..difficulty].
47 47 * @param {number} magicSkillLevel
48 48 * @param {number} spellTier
49 49 */
@@ -43,7 +43,7 @@ export function resolveSpellCast ({
43
43
44/**
44/**
45 * Exact P(Magic roll ≥ difficulty roll) as a percent (0–100).
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].
46 * Magic and difficulty dice are uniform integers in [0..level] / [0..difficulty].
47 * @param {number} magicSkillLevel
47 * @param {number} magicSkillLevel
48 * @param {number} spellTier
48 * @param {number} spellTier
49 */
49 */
shared/spells/constants.js +10 −2
@@ -1,3 +1,5 @@
1 import { MATERIAL_TIER_ORDER, tierMinSkillLevel } from "../definitions/materialTiers.js";
2
1 3 /** Universal Chebyshev range for ranged weapons and magic (players and mobs). */
2 4 export const COMBAT_RANGE_TILES = 15;
3 5
@@ -20,10 +22,16 @@ export const LIGHT_OWNER_DISTANCE_CAP_MS = 5000;
20 22 export const CAST_FLASH_MS = 500;
21 23 export const SPELL_PROJECTILE_FRAME_MS = 250;
22 24
23 /** Magic contest die size from spell tier (tier 1 → 2, tier 2 → 4, …). */
25 /**
26 * Magic contest die size from spell tier.
27 * Difficulty = unlock Magic level + 1 so cast chance is exactly 50% at the
28 * tier unlock gate (1 / 10 / 20 / 35 / 50 / 70 / 90), then rises with Magic.
29 */
24 30 export function spellDifficultyFromTier (tier)
25 31 {
26 return Math.max(1, Math.floor(Number(tier) || 1) * 2);
32 const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1)));
33 const unlockLevel = tierMinSkillLevel(MATERIAL_TIER_ORDER[rank - 1]);
34 return Math.max(1, unlockLevel + 1);
27 35 }
28 36
29 37 /** Cast flash radius in tiles = tier / 2. */
@@ -1,3 +1,5 @@
1import { MATERIAL_TIER_ORDER, tierMinSkillLevel } from "../definitions/materialTiers.js";
2
1/** Universal Chebyshev range for ranged weapons and magic (players and mobs). */
3/** Universal Chebyshev range for ranged weapons and magic (players and mobs). */
2export const COMBAT_RANGE_TILES = 15;
4export const COMBAT_RANGE_TILES = 15;
3
5
@@ -20,10 +22,16 @@ export const LIGHT_OWNER_DISTANCE_CAP_MS = 5000;
20export const CAST_FLASH_MS = 500;
22export const CAST_FLASH_MS = 500;
21export const SPELL_PROJECTILE_FRAME_MS = 250;
23export const SPELL_PROJECTILE_FRAME_MS = 250;
22
24
23/** Magic contest die size from spell tier (tier 1 → 2, tier 2 → 4, …). */
25/**
26 * Magic contest die size from spell tier.
27 * Difficulty = unlock Magic level + 1 so cast chance is exactly 50% at the
28 * tier unlock gate (1 / 10 / 20 / 35 / 50 / 70 / 90), then rises with Magic.
29 */
24export function spellDifficultyFromTier (tier)
30export function spellDifficultyFromTier (tier)
25{
31{
26 return Math.max(1, Math.floor(Number(tier) || 1) * 2);
32 const rank = Math.max(1, Math.min(MATERIAL_TIER_ORDER.length, Math.floor(Number(tier) || 1)));
33 const unlockLevel = tierMinSkillLevel(MATERIAL_TIER_ORDER[rank - 1]);
34 return Math.max(1, unlockLevel + 1);
27}
35}
28
36
29/** Cast flash radius in tiles = tier / 2. */
37/** Cast flash radius in tiles = tier / 2. */