import React from 'react'; import './CreateCharacter.css' import {useForm} from "react-hook-form"; import {Faj, FajDescription, FajLabel, FajSpecials} from "../domain-models/faj"; import {Osztaly, OsztalyDescription, OsztalyLabel, OsztalyProperties} from "../domain-models/osztaly" function getRandomInt(max: number) { return Math.floor(Math.random() * max) + 1; } function rollAbility() { let min = 6; let sum = 0; let rolls: number[] = [] for (let i = 0; i < 4; i++) { const roll = getRandomInt(6); if (roll < min) { min = roll; } sum += roll; rolls = [...rolls, roll] } const result = sum - min; console.log("Rolled: " + rolls + " got: " + result) return result; } const modifier = (val : number) => Math.floor(val / 3) - 3 const fajiEroModosito = (faj: Faj) => [Faj.Felork, Faj.Osember, Faj.Eszaki].includes(faj) ? +1 : [Faj.Gnom, Faj.Felszerzet].includes(faj) ? -1 : 0 const fajiUgyModosito = (faj: Faj) => [Faj.Elf, Faj.Felszerzet].includes(faj) ? +1 : 0 const fajiEgsModosito = (faj: Faj) => [Faj.Etuniai, Faj.Osember, Faj.Felork, Faj.Torpe].includes(faj) ? +1 : [Faj.Birodalmi, Faj.Elf].includes(faj) ? -1 : 0 const fajiIntModosito = (faj: Faj) => [Faj.Gnom, Faj.Birodalmi].includes(faj) ? +1 : [Faj.Osember].includes(faj) ? -1 : 0 const fajiBolModosito = (faj: Faj) => [Faj.Osember, Faj.Eszaki, Faj.Etuniai].includes(faj) ? -1 : 0 const fajiKarModosito = (faj: Faj) => [Faj.Torpe].includes(faj) ? -1 : [Faj.Felork].includes(faj) ? -2 : 0 function signedNumberToText(val: number) : string { return val > 0 ? '+'+val : val.toString() } function fajiModositoText(faj: Faj, szamolas: (f: Faj) => number) : string { const mod = szamolas(faj) return (mod !== 0) ? signedNumberToText(mod) + ' (' + FajLabel(faj) + ')' : '' } function rollAllAbilities(setValue: (ability: string, value: number) => void) { setValue('ero', rollAbility()) setValue('ugy', rollAbility()) setValue('egs', rollAbility()) setValue('int', rollAbility()) setValue('bol', rollAbility()) setValue('kar', rollAbility()) } function CreateCharacterPage() { const { register, handleSubmit, setValue, watch, formState: {errors} } = useForm() const sendForm = (data: any) => console.log(data) const currentFaj = () => watch().faj || Faj.Ember const currentOsztaly = () => watch().osztaly || Osztaly.Harcos return (