added defender terastal and percentage

This commit is contained in:
2023-01-29 18:49:21 +09:00
parent 976da9bfca
commit 843278539c

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import AutoComplete from "simple-svelte-autocomplete"; import AutoComplete from "simple-svelte-autocomplete";
import attack_types from "../const/attack_types.json" import attack_types from "../const/attack_types.json";
export let player1Data; export let player1Data;
export let player2Data; export let player2Data;
@@ -18,6 +18,8 @@
let attack_direction = "p1p2"; let attack_direction = "p1p2";
let total_max_damage = 0; let total_max_damage = 0;
let total_min_damage = 0; let total_min_damage = 0;
let total_max_damage_percentage = 0;
let total_min_damage_percentage = 0;
function calculate_damage() { function calculate_damage() {
let attacker; let attacker;
let defender; let defender;
@@ -60,10 +62,12 @@
// 攻撃側タイプ // 攻撃側タイプ
// TODO: try catchでエラーハンドリング // TODO: try catchでエラーハンドリング
atk_type: JSON.parse(attacker.types), // 配列なのでjson parse atk_type: JSON.parse(attacker.types), // 配列なのでjson parse
atk_terastype : JSON.parse(attacker.terastype), atk_terastype: attacker.terastype,
// 防御側タイプ // 防御側タイプ
def_type: JSON.parse(defender.types), def_type:
def_terastype : JSON.parse(defender.terastype), defender.terastype[0] > 0
? defender.terastype
: JSON.parse(defender.types),
// 技タイプ // 技タイプ
move_type: JSON.parse(attackData.types), move_type: JSON.parse(attackData.types),
@@ -85,9 +89,10 @@
- タイプ一致あり等倍(半減と抜群): 76~91(これはモロバレルで計算) - タイプ一致あり等倍(半減と抜群): 76~91(これはモロバレルで計算)
*/ */
let d = damage(data); let d = damage(data);
total_max_damage = d.maxDamage; total_max_damage = d.maxDamage;
total_min_damage = d.minDamage; total_min_damage = d.minDamage;
total_max_damage_percentage = (d.maxDamage * 100) / defender.hp;
total_min_damage_percentage = (d.minDamage * 100) / defender.hp;
} }
function damage(data) { function damage(data) {
// 基本の計算 // 基本の計算
@@ -110,46 +115,51 @@
// 乱数補正 // 乱数補正
data.minDamage = getMinDamage(data); data.minDamage = getMinDamage(data);
// タイプ一致などの倍率 // タイプ一致などの倍率
let magnification = 1 // タイプ相性倍率 let magnification = 1; // タイプ相性倍率
let magnification_terastype = 1 // タイプ一致補正 テラスタル含む let magnification_terastype = 1; // タイプ一致補正 テラスタル含む
// ポケモンのタイプとテラスタルのタイプ一致の判定 // ポケモンのタイプとテラスタルのタイプ一致の判定
let is_terastype = data.atk_terastype !== 0 let is_terastype = data.atk_terastype !== 0;
let terastype_match = false let terastype_match = false;
if (is_terastype){ if (is_terastype) {
terastype_match = data.atk_type.includes(data.atk_terastype) terastype_match = data.atk_type.includes(data.atk_terastype[0]);
} }
// ポケモンのタイプと技のタイプの判定 // ポケモンのタイプと技のタイプの判定
// 1. テラスタルしてるなら、テラスタルのタイプで判定 // 1. テラスタルしてるなら、テラスタルのタイプで判定
// 2. テラスタルしていないなら、元のタイプで判定 // 2. テラスタルしていないなら、元のタイプで判定
let atk_type let atk_type;
if (is_terastype){ if (is_terastype) {
atk_type = data.atk_terastype; atk_type = data.atk_terastype;
} else { } else {
atk_type = data.atk_type atk_type = data.atk_type;
} }
let type_match = data.atk_type.findIndex((type) => type === data.move_type[0]) > -1 let type_match =
data.atk_type.findIndex((type) => type === data.move_type[0]) > -1;
// Note: // Note:
// フライングプレスだけ格闘と飛行の2属性があるが、タイプ一致補正は格闘にだけ補正が掛かる // フライングプレスだけ格闘と飛行の2属性があるが、タイプ一致補正は格闘にだけ補正が掛かる
// data.move_type[0] = 7で格闘が取れるのでOK // data.move_type[0] = 7で格闘が取れるのでOK
// 技のタイプとテラスタルのタイプの一致判定 // 技のタイプとテラスタルのタイプの一致判定
let movetype_match = false let movetype_match = false;
if (is_terastype){ if (is_terastype) {
movetype_match = data.move_type.includes(data.atk_terastype) movetype_match = data.move_type.includes(data.atk_terastype);
} }
console.log(type_match, is_terastype, terastype_match);
// 技のタイプ一致倍率(技のタイプが一致するかどうか) // 技のタイプ一致倍率(技のタイプが一致するかどうか)
// 本来のタイプ テラスタルタイプ 倍率 // 本来のタイプ テラスタルタイプ 倍率
if ( type_match && is_terastype && terastype_match){ if (type_match && is_terastype && terastype_match) {
// 1. 一致する 一致する => x2 // 1. 一致する 一致する => x2
magnification_terastype = 2 magnification_terastype = 2;
} else if ((type_match && is_terastype && !terastype_match) || (type_match && !is_terastype) || (!type_match && is_terastype && movetype_match)){ } else if (
(type_match && is_terastype && !terastype_match) ||
(type_match && !is_terastype) ||
(!type_match && is_terastype && movetype_match)
) {
// 2. 一致する 一致しない => x1.5 // 2. 一致する 一致しない => x1.5
// 3. 一致する テラスタルなし => x1.5 // 3. 一致する テラスタルなし => x1.5
// 4. 一致しない 一致する => x1.5 NG // 4. 一致しない 一致する => x1.5 NG
magnification_terastype =1.5 magnification_terastype = 1.5;
} }
// 5. 一致しない 一致しない 1 // 5. 一致しない 一致しない 1
// 6. 一致しない テラスタルなし 1 // 6. 一致しない テラスタルなし 1
@@ -157,7 +167,7 @@
// 相性補正 // 相性補正
// 相性補正の倍率を計算 // 相性補正の倍率を計算
magnification = getCompatibility(data) magnification = getCompatibility(data);
// やけど補正 // やけど補正
// 壁補正 // 壁補正
@@ -176,10 +186,10 @@
// ダイマックス技などの軽減(M protect) // ダイマックス技などの軽減(M protect)
// 最後に倍率かける // 最後に倍率かける
data.maxDamage = Math.trunc(data.maxDamage * magnification_terastype) data.maxDamage = Math.trunc(data.maxDamage * magnification_terastype);
data.minDamage = Math.trunc(data.minDamage * magnification_terastype) data.minDamage = Math.trunc(data.minDamage * magnification_terastype);
data.maxDamage = Math.trunc(data.maxDamage * magnification) data.maxDamage = Math.trunc(data.maxDamage * magnification);
data.minDamage = Math.trunc(data.minDamage * magnification) data.minDamage = Math.trunc(data.minDamage * magnification);
return data; return data;
} }
@@ -193,19 +203,19 @@
} }
// 相性計算 // 相性計算
// 倍率だけ返す // 倍率だけ返す
function getCompatibility(data){ function getCompatibility(data) {
let type_magnification = 1 let type_magnification = 1;
// 技のタイプの相性倍率とりだす // 技のタイプの相性倍率とりだす
// attack_types の json の index と move_type の数字が1つずれてる // attack_types の json の index と move_type の数字が1つずれてる
let compatibility = attack_types[data.move_type-1] let compatibility = attack_types[data.move_type - 1];
// 相手のタイプ毎に倍率計算 // 相手のタイプ毎に倍率計算
for (let i = 0; i < data.def_type.length; i++){ for (let i = 0; i < data.def_type.length; i++) {
// 倍率 // 倍率
type_magnification *= compatibility[data.def_type[i]-1] // ここもindexずれる type_magnification *= compatibility[data.def_type[i] - 1]; // ここもindexずれる
} }
return type_magnification return type_magnification;
} }
async function getItems(keyword) { async function getItems(keyword) {
try { try {
@@ -253,22 +263,25 @@
bind:value={myValue} bind:value={myValue}
/> />
</td> </td>
<td <td>
><input <input type="button" value="Calculate" on:click={calculate_damage} />
type="button" </td>
value="Calculate"
on:click={calculate_damage}
/></td
>
<td>Total Damage: {total_min_damage} ~ {total_max_damage}</td> <td>Total Damage: {total_min_damage} ~ {total_max_damage}</td>
<td>
Percentage: {total_min_damage_percentage}% ~ {total_max_damage_percentage}%
</td>
</tr> </tr>
</table> </table>
{JSON.stringify(player1Data)} - <div class="debug-data">
{JSON.stringify(player2Data)}<br /> {JSON.stringify(player1Data)} -
{attack_direction} {JSON.stringify(player2Data)}
</div>
</div> </div>
<style> <style>
.debug-data {
font-size: 10px;
}
.calculator { .calculator {
height: 100px; height: 100px;
width: 100%; width: 100%;