diff --git a/src/lib/DamageCalculator.svelte b/src/lib/DamageCalculator.svelte index 760db15..db081e4 100644 --- a/src/lib/DamageCalculator.svelte +++ b/src/lib/DamageCalculator.svelte @@ -60,13 +60,15 @@ // 攻撃側タイプ // TODO: try catchでエラーハンドリング atk_type: JSON.parse(attacker.types), // 配列なのでjson parse + atk_terastype : JSON.parse(attacker.terastype), // 防御側タイプ def_type: JSON.parse(defender.types), + def_terastype : JSON.parse(defender.terastype), + // 技タイプ move_type: JSON.parse(attackData.types), // 範囲の計算で使用する }; - // 計算 /* memo:計算用テストデータ @@ -107,22 +109,55 @@ // 急所補正 // 乱数補正 data.minDamage = getMinDamage(data); - // タイプ一致補正 - let type_match = false; - for (let i = 0; i < data.atk_type.length && !type_match; i++) { - for (let j = 0; j < data.move_type.length && !type_match; j++) { - if (data.atk_type[i] === data.move_type[j]) { - // タイプ一致したら判定終了 - type_match = true; - data.maxDamage = Math.trunc(data.maxDamage * 1.5); - data.minDamage = Math.trunc(data.minDamage * 1.5); - } - } + // タイプ一致などの倍率 + let magnification = 1 // タイプ相性倍率 + let magnification_terastype = 1 // タイプ一致補正 テラスタル含む + + // ポケモンのタイプとテラスタルのタイプ一致の判定 + let is_terastype = data.atk_terastype !== 0 + let terastype_match = false + if (is_terastype){ + terastype_match = data.atk_type.includes(data.atk_terastype) } + // ポケモンのタイプと技のタイプの判定 + // 1. テラスタルしてるなら、テラスタルのタイプで判定 + // 2. テラスタルしていないなら、元のタイプで判定 + let atk_type + if (is_terastype){ + atk_type = data.atk_terastype; + } else { + atk_type = data.atk_type + } + let type_match = data.atk_type.findIndex((type) => type === data.move_type[0]) > -1 + // Note: + // フライングプレスだけ格闘と飛行の2属性があるが、タイプ一致補正は格闘にだけ補正が掛かる + // data.move_type[0] = 7で格闘が取れるのでOK + + // 技のタイプとテラスタルのタイプの一致判定 + let movetype_match = false + if (is_terastype){ + movetype_match = data.move_type.includes(data.atk_terastype) + } + + // 技のタイプ一致倍率(技のタイプが一致するかどうか) + // 本来のタイプ テラスタルタイプ 倍率 + if ( type_match && is_terastype && terastype_match){ + // 1. 一致する 一致する => x2 + magnification_terastype = 2 + } else if ((type_match && is_terastype && !terastype_match) || (type_match && !is_terastype) || (!type_match && is_terastype && movetype_match)){ + // 2. 一致する 一致しない => x1.5 + // 3. 一致する テラスタルなし => x1.5 + // 4. 一致しない 一致する => x1.5 NG + magnification_terastype =1.5 + } + // 5. 一致しない 一致しない 1 + // 6. 一致しない テラスタルなし 1 + // そのままなので特に処理なし + // 相性補正 - // 相性の計算の関数をとってくる - data = getCompatibility(data) + // 相性補正の倍率を計算 + magnification = getCompatibility(data) // やけど補正 // 壁補正 @@ -139,6 +174,13 @@ // 半減木の実補正 // その他ダメージ補正(M twice) // ダイマックス技などの軽減(M protect) + + // 最後に倍率かける + data.maxDamage = Math.trunc(data.maxDamage * magnification_terastype) + data.minDamage = Math.trunc(data.minDamage * magnification_terastype) + data.maxDamage = Math.trunc(data.maxDamage * magnification) + data.minDamage = Math.trunc(data.minDamage * magnification) + return data; } // 乱数補正 @@ -150,7 +192,10 @@ return Math.trunc((data.maxDamage * 85) / 100); } // 相性計算 + // 倍率だけ返す function getCompatibility(data){ + let type_magnification = 1 + // 技のタイプの相性倍率とりだす // attack_types の json の index と move_type の数字が1つずれてる let compatibility = attack_types[data.move_type-1] @@ -158,11 +203,9 @@ // 相手のタイプ毎に倍率計算 for (let i = 0; i < data.def_type.length; i++){ // 倍率 - let magnification = compatibility[data.def_type[i]-1] // ここもindexずれる - data.maxDamage *= magnification - data.minDamage *= magnification + type_magnification *= compatibility[data.def_type[i]-1] // ここもindexずれる } - return data + return type_magnification } async function getItems(keyword) { try {