| 1 | import { JewelryItemId } from "../definitions/jewelryItems.js"; |
| 2 | import { EQUIPMENT_SLOT, itemDefinition } from "../definitions/items.js"; |
| 3 | import { AttackType, MAGIC_ELEMENT_ORDER } from "../definitions/attackTypes.js"; |
| 4 | import { ALL_SKILL_IDS, skillLevel } from "../definitions/skills.js"; |
| 5 | import { tierMinSkillLevel } from "../definitions/materialTiers.js"; |
| 6 | import { EquipmentKind } from "../definitions/equipmentKinds.js"; |
| 7 | |
| 8 | /** Torch block range; opal bracelet uses the same radius at half intensity. */ |
| 9 | export const OPAL_NIGHT_VISION_RANGE_TILES = 8; |
| 10 | export const OPAL_NIGHT_VISION_INTENSITY = 0.5; |
| 11 | |
| 12 | export const JEWELRY_TELEPORT_MS = 3000; |
| 13 | export const JADEITE_FAIRY_RESPAWN_MS = 60_000; |
| 14 | export const JADEITE_FAIRY_LEASH_TILES = 8; |
| 15 | export const JADEITE_FAIRY_LEVEL_FRACTION = 0.6; |
| 16 | |
| 17 | function slotItemId (equipment, slot) |
| 18 | { |
| 19 | return equipment?.slots?.[slot]?.itemId ?? null; |
| 20 | } |
| 21 | |
| 22 | export function wornJewelryIds (equipment) |
| 23 | { |
| 24 | return { |
| 25 | ring: slotItemId(equipment, EQUIPMENT_SLOT.ring), |
| 26 | bracelet: slotItemId(equipment, EQUIPMENT_SLOT.bracelet), |
| 27 | amulet: slotItemId(equipment, EQUIPMENT_SLOT.amulet) |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | export function isWearingJewelry (equipment, itemId) |
| 32 | { |
| 33 | const worn = wornJewelryIds(equipment); |
| 34 | return worn.ring === itemId || worn.bracelet === itemId || worn.amulet === itemId; |
| 35 | } |
| 36 | |
| 37 | /** Combat level required to wear a jewellery piece (same tier curve as Magic gates). */ |
| 38 | export function jewelryMinCombatLevel (itemDef) |
| 39 | { |
| 40 | const equipment = itemDef?.equipment; |
| 41 | if (!equipment || equipment.kind !== EquipmentKind.jewelry) |
| 42 | { return null; } |
| 43 | return equipment.minCombatLevel ?? tierMinSkillLevel(equipment.tier); |
| 44 | } |
| 45 | |
| 46 | export function passiveHpRegenMultiplier (equipment) |
| 47 | { |
| 48 | return isWearingJewelry(equipment, JewelryItemId.tourmalineRing) ? 2 : 1; |
| 49 | } |
| 50 | |
| 51 | export function passiveStaminaRegenMultiplier (equipment) |
| 52 | { |
| 53 | return isWearingJewelry(equipment, JewelryItemId.tourmalineBracelet) ? 2 : 1; |
| 54 | } |
| 55 | |
| 56 | /** Double XP only for the wearer's current lowest skill. */ |
| 57 | export function skillXpMultiplier (equipment, skills, skillId) |
| 58 | { |
| 59 | if (!isWearingJewelry(equipment, JewelryItemId.tourmalineAmulet)) |
| 60 | { return 1; } |
| 61 | let lowest = Infinity; |
| 62 | let lowestIds = []; |
| 63 | for (const id of ALL_SKILL_IDS) |
| 64 | { |
| 65 | const level = skillLevel(skills, id); |
| 66 | if (level < lowest) |
| 67 | { |
| 68 | lowest = level; |
| 69 | lowestIds = [id]; |
| 70 | } |
| 71 | else if (level === lowest) |
| 72 | { lowestIds.push(id); } |
| 73 | } |
| 74 | return lowestIds.includes(skillId) ? 2 : 1; |
| 75 | } |
| 76 | |
| 77 | export function craftDurationMultiplier (equipment) |
| 78 | { |
| 79 | return isWearingJewelry(equipment, JewelryItemId.alexandriteBracelet) ? 0.5 : 1; |
| 80 | } |
| 81 | |
| 82 | export function gatherDurationMultiplier (equipment) |
| 83 | { |
| 84 | return isWearingJewelry(equipment, JewelryItemId.alexandriteAmulet) ? 0.5 : 1; |
| 85 | } |
| 86 | |
| 87 | export function harvestYieldMultiplier (equipment) |
| 88 | { |
| 89 | return isWearingJewelry(equipment, JewelryItemId.jadeiteRing) ? 2 : 1; |
| 90 | } |
| 91 | |
| 92 | export function maxHealthMultiplier (equipment) |
| 93 | { |
| 94 | return isWearingJewelry(equipment, JewelryItemId.rubyBracelet) ? 1.1 : 1; |
| 95 | } |
| 96 | |
| 97 | export function hitSkillBonus (equipment) |
| 98 | { |
| 99 | return isWearingJewelry(equipment, JewelryItemId.emeraldAmulet) ? 1 : 0; |
| 100 | } |
| 101 | |
| 102 | export function damageReflectFraction (equipment) |
| 103 | { |
| 104 | return isWearingJewelry(equipment, JewelryItemId.opalAmulet) ? 0.1 : 0; |
| 105 | } |
| 106 | |
| 107 | export function autoLootOnKill (equipment) |
| 108 | { |
| 109 | return isWearingJewelry(equipment, JewelryItemId.diamondAmulet); |
| 110 | } |
| 111 | |
| 112 | export function dropAmuletInsteadOfCoins (equipment) |
| 113 | { |
| 114 | return isWearingJewelry(equipment, JewelryItemId.rubyAmulet); |
| 115 | } |
| 116 | |
| 117 | export function ignoresNonBossAggro (equipment) |
| 118 | { |
| 119 | return isWearingJewelry(equipment, JewelryItemId.jadeiteBracelet); |
| 120 | } |
| 121 | |
| 122 | export function summonsJadeiteFairy (equipment) |
| 123 | { |
| 124 | return isWearingJewelry(equipment, JewelryItemId.jadeiteAmulet); |
| 125 | } |
| 126 | |
| 127 | export function canTeleportToChurch (equipment) |
| 128 | { |
| 129 | return isWearingJewelry(equipment, JewelryItemId.emeraldBracelet); |
| 130 | } |
| 131 | |
| 132 | export function canTeleportToBank (equipment) |
| 133 | { |
| 134 | return isWearingJewelry(equipment, JewelryItemId.rubyRing); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Lucky attacker rolls (diamond bracelet): bias toward high outcomes. |
| 139 | * Unlucky defender-facing rolls (emerald ring): bias enemy to-hit toward low. |
| 140 | */ |
| 141 | export function attackerToHitRng (equipment, rng = Math.random) |
| 142 | { |
| 143 | if (!isWearingJewelry(equipment, JewelryItemId.diamondBracelet)) |
| 144 | { return rng; } |
| 145 | return () => 1 - Math.pow(1 - rng(), 2); |
| 146 | } |
| 147 | |
| 148 | export function attackerSpellCastRng (equipment, rng = Math.random) |
| 149 | { |
| 150 | return attackerToHitRng(equipment, rng); |
| 151 | } |
| 152 | |
| 153 | export function enemyToHitRngAgainst (defenderEquipment, rng = Math.random) |
| 154 | { |
| 155 | if (!isWearingJewelry(defenderEquipment, JewelryItemId.emeraldRing)) |
| 156 | { return rng; } |
| 157 | return () => Math.pow(rng(), 1.75); |
| 158 | } |
| 159 | |
| 160 | /** Affinity map merged onto the wearer's defence (resistant = half damage). */ |
| 161 | export function jewelryDamageAffinities (equipment) |
| 162 | { |
| 163 | const affinities = {}; |
| 164 | if (isWearingJewelry(equipment, JewelryItemId.alexandriteRing)) |
| 165 | { |
| 166 | for (const element of MAGIC_ELEMENT_ORDER) |
| 167 | { affinities[element] = "resistant"; } |
| 168 | } |
| 169 | if (isWearingJewelry(equipment, JewelryItemId.opalRing)) |
| 170 | { affinities[AttackType.piercing] = "resistant"; } |
| 171 | if (isWearingJewelry(equipment, JewelryItemId.diamondRing)) |
| 172 | { |
| 173 | affinities[AttackType.blunt] = "resistant"; |
| 174 | affinities[AttackType.slashing] = "resistant"; |
| 175 | affinities[AttackType.crushing] = "resistant"; |
| 176 | affinities[AttackType.chopping] = "resistant"; |
| 177 | } |
| 178 | return affinities; |
| 179 | } |
| 180 | |
| 181 | export function mergeAffinities (...maps) |
| 182 | { |
| 183 | const out = {}; |
| 184 | for (const map of maps) |
| 185 | { |
| 186 | if (!map) |
| 187 | { continue; } |
| 188 | for (const [key, value] of Object.entries(map)) |
| 189 | { |
| 190 | if (value === "weak" || (value === "resistant" && out[key] !== "weak")) |
| 191 | { out[key] = value; } |
| 192 | else if (!out[key]) |
| 193 | { out[key] = value; } |
| 194 | } |
| 195 | } |
| 196 | return out; |
| 197 | } |
| 198 | |
| 199 | export function nightVisionLight (equipment) |
| 200 | { |
| 201 | if (!isWearingJewelry(equipment, JewelryItemId.opalBracelet)) |
| 202 | { return null; } |
| 203 | return { |
| 204 | lightRadiusTiles: OPAL_NIGHT_VISION_RANGE_TILES, |
| 205 | lightIntensity: OPAL_NIGHT_VISION_INTENSITY |
| 206 | }; |
| 207 | } |
| 208 | |
| 209 | export function jewelryEffectsFromEquipment (equipment) |
| 210 | { |
| 211 | return { |
| 212 | passiveHpRegenMult: passiveHpRegenMultiplier(equipment), |
| 213 | passiveStaminaRegenMult: passiveStaminaRegenMultiplier(equipment), |
| 214 | craftDurationMult: craftDurationMultiplier(equipment), |
| 215 | gatherDurationMult: gatherDurationMultiplier(equipment), |
| 216 | harvestYieldMult: harvestYieldMultiplier(equipment), |
| 217 | maxHealthMult: maxHealthMultiplier(equipment), |
| 218 | hitBonus: hitSkillBonus(equipment), |
| 219 | reflectFraction: damageReflectFraction(equipment), |
| 220 | autoLoot: autoLootOnKill(equipment), |
| 221 | keepCoinsDropAmulet: dropAmuletInsteadOfCoins(equipment), |
| 222 | ignoreNonBossAggro: ignoresNonBossAggro(equipment), |
| 223 | jadeiteFairy: summonsJadeiteFairy(equipment), |
| 224 | teleportChurch: canTeleportToChurch(equipment), |
| 225 | teleportBank: canTeleportToBank(equipment), |
| 226 | affinities: jewelryDamageAffinities(equipment), |
| 227 | nightVision: nightVisionLight(equipment) |
| 228 | }; |
| 229 | } |