diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-17 02:53:14 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-17 17:42:15 +0200 |
commit | cc685bfe02b42b592987117fa008a4461785f53c (patch) | |
tree | 625c1c9573b178e574bb70cac042c35da4036cf1 /resources/js/formula.js | |
parent | 717fde1c48c7221da986ac02d2b806b2fee6f2d5 (diff) |
refactorrefactor
Diffstat (limited to 'resources/js/formula.js')
-rw-r--r-- | resources/js/formula.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/resources/js/formula.js b/resources/js/formula.js new file mode 100644 index 0000000..5a3433f --- /dev/null +++ b/resources/js/formula.js @@ -0,0 +1,93 @@ +/** + * @param {Technique} technique + * @param {Monster} user + * @param {Monster} target + * + * @returns {number} + */ +function simpleDamageCalculation (technique, user, target) { + if (technique.power === 0) { + return 0; + } + + let userBaseStrength = user.level + 7; + let userStrength = 1; + let targetResist = 1; + + if (technique.range === TechniqueRange.melee) { + userStrength = userBaseStrength * user.stats.melee; + targetResist = target.stats.armour; + } + else if (technique.range === TechniqueRange.touch) { + userStrength = userBaseStrength * user.stats.melee; + targetResist = target.stats.dodge; + } + else if (technique.range === TechniqueRange.ranged) { + userStrength = userBaseStrength * user.stats.ranged; + targetResist = target.stats.dodge; + } + else if (technique.range === TechniqueRange.reach) { + userStrength = userBaseStrength * user.stats.ranged; + targetResist = target.stats.armour; + } + else if (technique.range === TechniqueRange.reliable) { + userStrength = userBaseStrength; + targetResist = 1; + } + + const multiplier = simpleDamageMultiplier(technique.types, target.types); + const moveStrength = technique.power * multiplier; + const damage = Math.floor((userStrength * moveStrength) / targetResist); + + return Math.max(damage, 1); +} + +/** + * @param {(ElementType[]|string[])} techniqueTypes + * @param {(ElementType[]|string[])} targetTypes + * + * @returns {number} + */ +function simpleDamageMultiplier (techniqueTypes, targetTypes) { + let multiplier = 1; + + for (const techniqueType of techniqueTypes) { + if (techniqueType === ElementType.aether) { + continue; + } + + for (const targetType of targetTypes) { + if (targetType === ElementType.aether) { + continue; + } + + multiplier *= DB.elements[techniqueType].types.find((type) => type.against === targetType).multiplier; + } + } + + return Math.max(0.25, Math.min(multiplier, 4)); +} + +/** + * @param {Monster} opposingMonster + * @param {Monster[]} participants + * + * @returns {number[]} + */ +function calculateAwardedExperience (opposingMonster, participants) { + const awardedExperienceDistribution = []; + + for (const participantIndex in participants) { + const participant = participants[participantIndex]; + const awardedExperience = Math.max( + Math.floor( + opposingMonster.getExperienceRequired(-1) / opposingMonster.level * opposingMonster.experienceModifier / participant.level + ), + 1 + ); + + awardedExperienceDistribution[participantIndex] = awardedExperience; + } + + return awardedExperienceDistribution; +} |