summaryrefslogtreecommitdiff
path: root/resources/js/formula.js
blob: f28ce2d4b4e2c3f82db7e19c68de411b5c928eaa (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
 * @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;
}

/**
 * @param {Monster} opposingMonster
 *
 * @returns {number}
 */
function calculateAwardedMoney (opposingMonster) {
  let money = opposingMonster.level * opposingMonster.moneyModifier;

  money = convertToCurrencyBase(money);

  return money;
}

/**
 * @param {Monster} playerMonster
 * @param {Monster} opposingMonster
 * @param {Item} ball
 *
 * @returns {boolean}
 */
function checkCapture (playerMonster, opposingMonster, ball) {
  const MAX_CATCH_RATE = 255;
  const MAX_ATTEMPT_RATE = 65536;
  const ATTEMPT_CONSTANT = 524325;

  // status effect
  let STATUS_MODIFER = 1.0;
  if (opposingMonster.statusEffect && opposingMonster.statusEffect.category === 'negative') {
    STATUS_MODIFER = 1.2;
  }

  // ball
  let BALL_MODIFIER = 1.0;
  if (ball.slug === 'tuxeball_wood') {
    if (opposingMonster.types.includes(ElementType.wood)) {
      BALL_MODIFIER = 1.5
    } else {
      BALL_MODIFIER = 0.2;
    }
  }
  else if (ball.slug === 'tuxeball_fire') {
    if (opposingMonster.types.includes(ElementType.fire)) {
      BALL_MODIFIER = 1.5
    } else {
      BALL_MODIFIER = 0.2;
    }
  }
  else if (ball.slug === 'tuxeball_earth') {
    if (opposingMonster.types.includes(ElementType.earth)) {
      BALL_MODIFIER = 1.5
    } else {
      BALL_MODIFIER = 0.2;
    }
  }
  else if (ball.slug === 'tuxeball_metal') {
    if (opposingMonster.types.includes(ElementType.metal)) {
      BALL_MODIFIER = 1.5
    } else {
      BALL_MODIFIER = 0.2;
    }
  }
  else if (ball.slug === 'tuxeball_water') {
    if (opposingMonster.types.includes(ElementType.water)) {
      BALL_MODIFIER = 1.5
    } else {
      BALL_MODIFIER = 0.2;
    }
  }

  // calculate
  const catchCheck = Math.max(
    (3 * opposingMonster.hp - 2 * playerMonster.hp)
    * opposingMonster.catch_rate
    * STATUS_MODIFER
    * BALL_MODIFIER
    / (3 * opposingMonster.hp),
    1
  );

  let attemptCheck = ATTEMPT_CONSTANT / (
    Math.sqrt(Math.sqrt(MAX_CATCH_RATE / catchCheck)) * 8
  )

  const catchResistance = Math.random() * (opposingMonster.upper_catch_resistance - opposingMonster.lower_catch_resistance) + opposingMonster.lower_catch_resistance;

  attemptCheck = attemptCheck * catchResistance;

  return Math.random() * MAX_ATTEMPT_RATE > Math.round(attemptCheck);
}