diff --git a/packages/website/src/blitzkit/computeCharacteristics.ts b/packages/website/src/blitzkit/computeCharacteristics.ts new file mode 100644 index 000000000..1bcbf78fb --- /dev/null +++ b/packages/website/src/blitzkit/computeCharacteristics.ts @@ -0,0 +1,5 @@ +export function computeCharacteristics() { + const characteristics = {}; + + return characteristics; +} diff --git a/packages/website/src/config/characteristics.ts b/packages/website/src/config/characteristics.ts new file mode 100644 index 000000000..ef6073fdc --- /dev/null +++ b/packages/website/src/config/characteristics.ts @@ -0,0 +1,68 @@ +import { + CharacteristicType, + type Characteristic, +} from "../types/characteristics"; + +export const characteristics = { + gun_type: { + type: CharacteristicType.Enum, + compute({ gun }) { + return gun.gun_type!.$case; + }, + }, + + clip_size: { + type: CharacteristicType.Number, + + should_render({ gun }) { + return gun.gun_type!.$case !== "regular"; + }, + + compute({ gun }) { + if (gun.gun_type!.$case === "regular") return 1; + return gun.gun_type!.value.shell_count; + }, + }, + + assault_damage_coefficient: { + type: CharacteristicType.Number, + + compute({ gun, shell, assault_distance }) { + if ( + !gun.assault_ranges || + !gun.assault_ranges.types.includes(shell.type) + ) { + return 1; + } + + return ( + gun.assault_ranges.ranges.find( + ({ distance }) => distance >= assault_distance, + )?.factor ?? 0 + ); + }, + }, + + armor_damage_coefficient: { + type: CharacteristicType.Number, + + compute() { + let coefficient = 1; + + return coefficient; + }, + }, + + damage: { + type: CharacteristicType.Number, + compute({ characteristic, shell, equalizer }) { + let coefficient = 1; + + coefficient *= characteristic("armor_damage_coefficient") as number; + coefficient *= characteristic("assault_damage_coefficient") as number; + coefficient *= equalizer.damage; + + return coefficient * shell.armor_damage; + }, + }, +} satisfies Record; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/_index.tsx index 1b8a2d226..67b85b72d 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/_index.tsx +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/_index.tsx @@ -1,8 +1,10 @@ import { useMemo } from "react"; import { api } from "../../../../../blitzkit/api"; +import { computeCharacteristics } from "../../../../../blitzkit/computeCharacteristics"; import { withErrorWrapper } from "../../../../../hocs/withErrorWrapper"; import { withLocale } from "../../../../../hocs/withLocale"; import { useAwait } from "../../../../../hooks/useAwait"; +import { useEquipment } from "../../../../../hooks/useEquipment"; import { Tankopedia } from "../../../../../stores/tankopedia"; import styles from "./_index.module.css"; @@ -19,13 +21,8 @@ export const Page = withErrorWrapper( const protagonist = Tankopedia.use((state) => state.protagonist); const protagonistEquipment = useEquipment(protagonistTank.tank!); - const { characteristics, parameters } = useMemo( - () => - computeCharacteristics( - protagonistTank, - protagonistEquipment, - protagonist, - ), + const characteristics = useMemo( + () => computeCharacteristics(), [protagonist], ); diff --git a/packages/website/src/types/characteristics.ts b/packages/website/src/types/characteristics.ts new file mode 100644 index 000000000..07c176d34 --- /dev/null +++ b/packages/website/src/types/characteristics.ts @@ -0,0 +1,33 @@ +import type { Equalizer, GunDefinition, ShellDefinition } from "@blitzkit/core"; +import { characteristics } from "../config/characteristics"; + +export type Characteristic = { + should_render?(context: CharacteristicContext): boolean; +} & ( + | { + type: CharacteristicType.Enum; + compute(context: CharacteristicContext): string; + } + | { + type: CharacteristicType.Number; + compute(context: CharacteristicContext): number; + } +); + +interface CharacteristicContext { + gun: GunDefinition; + shell: ShellDefinition; + + equalizer: Equalizer; + + assault_distance: number; + + characteristic( + name: keyof typeof characteristics, + ): ReturnType; +} + +export enum CharacteristicType { + Enum, + Number, +}