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 (

Karakter létrehozása

{errors.nev && A karaktered nem mászkálhat névtelenül a világban!}

{FajDescription(currentFaj())}

    {FajSpecials(currentFaj()).map(((special) => (
  • {special}
  • )))}

Tulajdonságok
{fajiModositoText(currentFaj(), fajiEroModosito)} Összesen: { (Number((watch('ero') || 10)) + (fajiEroModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('ero') || 10)) + fajiEroModosito(currentFaj()))) } {Number(watch('ero')) < 3 && ( Túl gyenge vagy, nem bírtad felemelni a kezed a jelentkezéshez!)} {Number(watch('ero')) > 18 && ( Szét szakadtak az izmaid!)}
{fajiModositoText(currentFaj(), fajiUgyModosito)} Összesen: { (Number((watch('ugy') || 10)) + (fajiUgyModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('ugy') || 10)) + fajiUgyModosito(currentFaj()))) } {errors.ugy && Number(watch('ugy')) < 3 && ( Orrabuktál jelentkezés helyett!)} {errors.ugy && Number(watch('ugy')) > 18 && ( Emberfeletti zsonglörködésedre záptojással válaszoltak a helyiek!)}
{fajiModositoText(currentFaj(), fajiEgsModosito)} Összesen: { (Number((watch('egs') || 10)) + (fajiEgsModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('egs') || 10)) + fajiEgsModosito(currentFaj()))) } {errors.egs && Number(watch('egs')) < 3 && ( Túl beteg vagy ahhoz, hogy kalandozni menj!)} {errors.egs && Number(watch('egs')) > 18 && ( Kicsattanó egészségedet csak a diambroid állíthatja meg, minő véletlen, hogy pont az arcodba robbant...)}
{fajiModositoText(currentFaj(), fajiIntModosito)} Összesen: { (Number((watch('int') || 10)) + (fajiIntModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('int') || 10)) + fajiIntModosito(currentFaj()))) } {errors.int && Number(watch('int')) < 3 && ( Elfelejtetted, hogy mikor is kéne kalandozni indulni!)} {errors.int && Number(watch('int')) > 18 && ( Ilyen tudás és logika birtokában mi szükséged van új információkra? Mindent le tudsz vezetni a már meglévő ismereteidből, és ezt azonnal beláttad.)}
{fajiModositoText(currentFaj(), fajiBolModosito)} Összesen: { (Number((watch('bol') || 10)) + (fajiBolModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('bol') || 10)) + fajiBolModosito(currentFaj()))) } {errors.bol && Number(watch('bol')) < 3 && ( Nem bírtál ellenállni a kíváncsiságodnak, hogy közelebbről is megvizsgáld a tőr hegyét, nagyon közelről...)} {errors.bol && Number(watch('bol')) > 18 && ( Hatalmas bölcsességedben beláttad a kalandozás veszélyeit és inkább más tevékenységbe fogtál.)}
{fajiModositoText(currentFaj(), fajiKarModosito)} Összesen: { (Number((watch('kar') || 10)) + (fajiKarModosito(currentFaj()))).toString() } Módosító: { signedNumberToText(modifier(Number((watch('kar') || 10)) + fajiKarModosito(currentFaj()))) } {errors.kar && Number(watch('kar')) < 3 && ( Mintha taszítanád az embereket, sose sikerült kalandozó csapatot találnod.)} {errors.kar && Number(watch('kar')) > 18 && ( Az ellenkező nem tagjai nem engedték, hogy útnak indulj.)}

{OsztalyDescription(currentOsztaly())}

    {OsztalyProperties(currentOsztaly()).map(((special) => (
  • {special}
  • )))}
); } export default CreateCharacterPage;