calc damaga
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
let attack_direction = "p1p2";
|
let attack_direction = "p1p2";
|
||||||
let attack_type = "attack";
|
let attack_type = "attack";
|
||||||
let attack_power = 0;
|
let attack_power = 0;
|
||||||
let total_damage = 0;
|
let total_max_damage = 0;
|
||||||
|
let total_min_damage = 0;
|
||||||
function calculate_damage() {
|
function calculate_damage() {
|
||||||
let attacker;
|
let attacker;
|
||||||
let defender;
|
let defender;
|
||||||
@@ -25,7 +26,70 @@
|
|||||||
atk_value = attacker.spatk;
|
atk_value = attacker.spatk;
|
||||||
def_value = defender.spdef;
|
def_value = defender.spdef;
|
||||||
}
|
}
|
||||||
total_damage = Math.floor(Math.random() * 150);
|
// 計算で使用する値をひとまとめにしてみる
|
||||||
|
let data = {
|
||||||
|
level: 50, // 対戦時は基本的にレベル50なのでconstでも良さそう
|
||||||
|
attack_power: attack_power,
|
||||||
|
atk_value: atk_value,
|
||||||
|
def_value: def_value,
|
||||||
|
|
||||||
|
// 最大ダメージと最小ダメージ
|
||||||
|
maxDamage: 0,
|
||||||
|
minDamage: 0
|
||||||
|
// この辺はあとまわしで
|
||||||
|
// 攻撃側タイプ
|
||||||
|
// 防御側タイプ
|
||||||
|
// 範囲の計算で使用する
|
||||||
|
}
|
||||||
|
let d = damage(data);
|
||||||
|
|
||||||
|
total_max_damage = d.maxDamage;
|
||||||
|
total_min_damage = d.minDamage;
|
||||||
|
}
|
||||||
|
function damage(data){
|
||||||
|
// 基本の計算
|
||||||
|
var step1 = Math.trunc(data.level * 2 / 5 + 2);
|
||||||
|
var step2 = Math.trunc(step1 * data.attack_power * data.atk_value / data.def_value);
|
||||||
|
data.maxDamage = Math.trunc(step2 / 50 + 2); // この時点の計算結果は最大ダメージ
|
||||||
|
|
||||||
|
// 各種補正かけた結果を返す
|
||||||
|
return modify(data)
|
||||||
|
}
|
||||||
|
// 全部一気にやると大変なので、一旦基本計算から
|
||||||
|
function modify(data){
|
||||||
|
// 範囲補正
|
||||||
|
// 親子愛補正
|
||||||
|
// ※svでおやこあいの特性はないのでスキップする
|
||||||
|
// 天気補正
|
||||||
|
// 急所補正
|
||||||
|
// 乱数補正
|
||||||
|
data.minDamage = getMinDamage(data)
|
||||||
|
// タイプ一致補正
|
||||||
|
// 相性補正
|
||||||
|
// やけど補正
|
||||||
|
// 壁補正
|
||||||
|
// ブレインフォース補正
|
||||||
|
// スナイパー補正
|
||||||
|
// いろめがね補正
|
||||||
|
// もふもふ(ほのお)補正
|
||||||
|
// ダメージ半減特性の補正(M half)
|
||||||
|
// 効果抜群を軽減する特性の補正(M filter)
|
||||||
|
// フレンドガード補正
|
||||||
|
// 達人の帯補正
|
||||||
|
// メトロノーム補正
|
||||||
|
// 命の珠補正
|
||||||
|
// 半減木の実補正
|
||||||
|
// その他ダメージ補正(M twice)
|
||||||
|
// ダイマックス技などの軽減(M protect)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
// 乱数補正
|
||||||
|
// ダメージは、乱数で0.85~1.00をかけた値の範囲で変動する
|
||||||
|
// 1.00はそのままの値なので、
|
||||||
|
// 0.85をかけた最小ダメージだけを計算する
|
||||||
|
// 少数切り捨て
|
||||||
|
function getMinDamage(data){
|
||||||
|
return Math.trunc(data.maxDamage * 85/100);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<div class="calculator">
|
<div class="calculator">
|
||||||
@@ -43,7 +107,7 @@
|
|||||||
<td><input type="radio" name="type" value="special" bind:group={attack_type}> Special</td>
|
<td><input type="radio" name="type" value="special" bind:group={attack_type}> Special</td>
|
||||||
<td>Attack Power: <input type="text" bind:value={attack_power}></td>
|
<td>Attack Power: <input type="text" bind:value={attack_power}></td>
|
||||||
<td><input type="button" value="Calculate" on:click={calculate_damage}></td>
|
<td><input type="button" value="Calculate" on:click={calculate_damage}></td>
|
||||||
<td>Total Damage: {total_damage}</td>
|
<td>Total Damage: {total_min_damage} ~ {total_max_damage}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{JSON.stringify(player1Data)} -
|
{JSON.stringify(player1Data)} -
|
||||||
|
|||||||
Reference in New Issue
Block a user