summaryrefslogtreecommitdiff
path: root/resources/js/formula.js
blob: 5a3433fa645a48596630d4444c6595db2b7833e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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;
}