refactoring in progress checkpoint reached
goal: remove class by breaking it up into smaller functions
This commit is contained in:
@@ -110,5 +110,4 @@ export function FajSpecials(faj : Faj) : string[] {
|
||||
"Szintkorlátok: Harcos 9, Pap 9, Tolvaj 6, Varázsló 4",
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {Faj} from "./faj";
|
||||
import {Osztaly} from "./osztaly";
|
||||
import {KarakterTulajdonsagok, Modifier} from "./tulajdonsag";
|
||||
import {KarakterTulajdonsagok, Modifier, TulajdonsagModosito} from "./tulajdonsag";
|
||||
import {Kepzettseg, Kepzettsegek, KepzettsegId} from "./kepzettsegek";
|
||||
import TamadasBonuszTabla from './tamadas_bonus_tabla.json';
|
||||
import {ElsodlegesMento, MasodlagosMento, Mentok, MentoTipus} from "./mentok";
|
||||
import {ElsodlegesMento, MasodlagosMento, Mentok, MentokAlap, MentoModositok, MentoTipus} from "./mentok";
|
||||
import {CelzoTB, KozelharciTB} from "./tamadas_bonusz";
|
||||
|
||||
export interface Karakter {
|
||||
Name: string
|
||||
@@ -27,6 +28,29 @@ export interface Karakter {
|
||||
TolvajKepzettsegek: Kepzettseg[]
|
||||
}
|
||||
|
||||
export interface KarakterPdfView {
|
||||
Name: string
|
||||
Nem: string
|
||||
Kor: number
|
||||
Isten: string
|
||||
Faj: Faj
|
||||
Osztaly: Osztaly
|
||||
Tulajdonsagok: KarakterTulajdonsagok,
|
||||
TulajdonsagModositok: KarakterTulajdonsagok,
|
||||
Szint: number
|
||||
HP: number
|
||||
VO: number
|
||||
Mozgas: number
|
||||
Kezdemenyezes: number
|
||||
KozelharciTB: number[]
|
||||
CelzoTB: number[]
|
||||
MentokAlap: Mentok
|
||||
MentoModositok: Mentok
|
||||
MentokModositokkal: Mentok
|
||||
Kepzettsegek: Kepzettseg[]
|
||||
TolvajKepzettsegek: Kepzettseg[]
|
||||
}
|
||||
|
||||
export interface KarakterInputs {
|
||||
name: string,
|
||||
nem?: string,
|
||||
@@ -41,6 +65,81 @@ export interface KarakterInputs {
|
||||
HProlls: number[],
|
||||
}
|
||||
|
||||
function BaseHP(osztaly: Osztaly) {
|
||||
let base = 4;
|
||||
switch (osztaly){
|
||||
case Osztaly.Barbar:
|
||||
base = 12
|
||||
break;
|
||||
case Osztaly.Amazon:
|
||||
case Osztaly.Ijasz:
|
||||
case Osztaly.Kaloz:
|
||||
case Osztaly.Harcos:
|
||||
base = 10;
|
||||
break
|
||||
case Osztaly.Pap:
|
||||
base = 8;
|
||||
break;
|
||||
case Osztaly.Tolvaj:
|
||||
base = 6;
|
||||
break;
|
||||
case Osztaly.Varazslo:
|
||||
case Osztaly.Illuzionista:
|
||||
base = 4;
|
||||
break;
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
export function HP(osztaly: Osztaly, egeszsegModifier: number, hpRolls: number[]): number {
|
||||
return BaseHP(osztaly) + egeszsegModifier + hpRolls
|
||||
// https://lfg.hu/forum/topic/15079-kard-es-magia/page/219/#comment-2218333
|
||||
.map(hp => Math.max(1, hp + egeszsegModifier))
|
||||
.reduce((sum, val) => sum + val, 0)
|
||||
}
|
||||
|
||||
|
||||
export function KarakterInputToPdfView(input: KarakterInputs): KarakterPdfView {
|
||||
const tulajdonsagModositok = TulajdonsagModosito(input.tulajdonsagok)
|
||||
const hp = HP(input.osztaly, tulajdonsagModositok.t_egs, input.HProlls)
|
||||
const vo = 10 + tulajdonsagModositok.t_ugy // TODO: kaloz, amazon!
|
||||
const mozgas = input.faj === Faj.Torpe ? 20 : 30
|
||||
const kezdemenyezes = tulajdonsagModositok.t_ugy + (input.osztaly === Osztaly.Tolvaj ? 4 : 0)
|
||||
|
||||
const mentok = MentokAlap(input.osztaly, input.szint)
|
||||
const mentoModositok = MentoModositok(tulajdonsagModositok)
|
||||
|
||||
return {
|
||||
Faj: input.faj,
|
||||
Isten: input.isten || "",
|
||||
Kor: input.kor,
|
||||
Name: input.name,
|
||||
Nem: input.nem || "",
|
||||
Tulajdonsagok: input.tulajdonsagok,
|
||||
Osztaly: input.osztaly,
|
||||
Szint: input.szint,
|
||||
Kepzettsegek: input.kepzettsegek.map(id => Kepzettsegek[id]),
|
||||
TolvajKepzettsegek: input.tolvajKepzettsegek?.map(id => Kepzettsegek[id]) || [],
|
||||
TulajdonsagModositok: tulajdonsagModositok,
|
||||
|
||||
HP: hp,
|
||||
VO: vo,
|
||||
Mozgas: mozgas,
|
||||
Kezdemenyezes: kezdemenyezes,
|
||||
KozelharciTB: KozelharciTB(input),
|
||||
CelzoTB: CelzoTB(input),
|
||||
|
||||
MentoModositok: mentoModositok,
|
||||
MentokAlap: mentok,
|
||||
MentokModositokkal: {
|
||||
kitartas: mentok.kitartas + mentoModositok.kitartas,
|
||||
akaratero: mentok.akaratero + mentoModositok.akaratero,
|
||||
reflex: mentok.reflex + mentoModositok.reflex,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// deprecated
|
||||
export class KarakterClass implements Karakter {
|
||||
|
||||
public Name : string
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
export function getRandomInt(max: number) {
|
||||
return Math.floor(Math.random() * max) + 1;
|
||||
export function dAny(sides: number) {
|
||||
return Math.floor(Math.random() * sides) + 1;
|
||||
}
|
||||
|
||||
export function d6() {
|
||||
return getRandomInt(6)
|
||||
return dAny(6)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {Osztaly} from "./osztaly";
|
||||
import {KarakterTulajdonsagok} from "./tulajdonsag";
|
||||
|
||||
export interface Mentok {
|
||||
kitartas: number
|
||||
reflex: number
|
||||
@@ -6,19 +9,14 @@ export interface Mentok {
|
||||
export type MentoTipus = keyof Mentok
|
||||
|
||||
export function MentoTipusLabel(tipus: MentoTipus): string {
|
||||
let label: string | null = null
|
||||
switch (tipus) {
|
||||
case "akaratero":
|
||||
label = "Akaraterő";
|
||||
break;
|
||||
return "Akaraterő";
|
||||
case "kitartas":
|
||||
label = "Kitartás";
|
||||
break;
|
||||
return "Kitartás";
|
||||
case "reflex":
|
||||
label = "Reflex";
|
||||
break;
|
||||
return "Reflex";
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
export function ElsodlegesMento(szint: number): number {
|
||||
@@ -27,4 +25,45 @@ export function ElsodlegesMento(szint: number): number {
|
||||
|
||||
export function MasodlagosMento(szint: number): number {
|
||||
return Math.floor(szint / 3)
|
||||
}
|
||||
|
||||
export function ElsodlegesMentok(osztaly: Osztaly) : MentoTipus[] {
|
||||
let t: MentoTipus[] = []
|
||||
switch (osztaly){
|
||||
case Osztaly.Barbar:
|
||||
case Osztaly.Amazon:
|
||||
case Osztaly.Ijasz:
|
||||
case Osztaly.Kaloz:
|
||||
case Osztaly.Harcos:
|
||||
t = ['kitartas'];
|
||||
break;
|
||||
case Osztaly.Pap:
|
||||
t = ['kitartas', 'akaratero'];
|
||||
break;
|
||||
case Osztaly.Tolvaj:
|
||||
t = ['reflex'];
|
||||
break;
|
||||
case Osztaly.Varazslo:
|
||||
case Osztaly.Illuzionista:
|
||||
t = ['akaratero']
|
||||
break;
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
export function MentokAlap(osztaly: Osztaly, szint: number = 1) {
|
||||
const elsodlegesek = ElsodlegesMentok(osztaly)
|
||||
return {
|
||||
kitartas: elsodlegesek.includes('kitartas') ? ElsodlegesMento(szint) : MasodlagosMento(szint),
|
||||
reflex: elsodlegesek.includes('reflex') ? ElsodlegesMento(szint) : MasodlagosMento(szint),
|
||||
akaratero: elsodlegesek.includes('akaratero') ? ElsodlegesMento(szint) : MasodlagosMento(szint),
|
||||
}
|
||||
}
|
||||
|
||||
export function MentoModositok(tulajdonsagModositok: KarakterTulajdonsagok) {
|
||||
return {
|
||||
kitartas: tulajdonsagModositok.t_egs,
|
||||
reflex: tulajdonsagModositok.t_ugy,
|
||||
akaratero: tulajdonsagModositok.t_bol,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {Osztaly} from "./osztaly";
|
||||
import TamadasBonuszTabla from "./tamadas_bonus_tabla.json";
|
||||
import {Modifier} from "./tulajdonsag";
|
||||
import {KarakterInputs} from "./karakter";
|
||||
|
||||
export function TamadasBonusz(osztaly: Osztaly, szint: number = 1) : number[] {
|
||||
let base = []
|
||||
switch (osztaly){
|
||||
case Osztaly.Barbar:
|
||||
case Osztaly.Amazon:
|
||||
case Osztaly.Ijasz:
|
||||
case Osztaly.Kaloz:
|
||||
case Osztaly.Harcos:
|
||||
base = TamadasBonuszTabla['elsodleges'];
|
||||
break;
|
||||
case Osztaly.Pap:
|
||||
case Osztaly.Tolvaj:
|
||||
base = TamadasBonuszTabla['ketharmados'];
|
||||
break;
|
||||
case Osztaly.Varazslo:
|
||||
case Osztaly.Illuzionista:
|
||||
base = TamadasBonuszTabla['feles'];
|
||||
break;
|
||||
}
|
||||
return base[szint-1]
|
||||
}
|
||||
|
||||
export function KozelharciTB(karakter : Pick<KarakterInputs, 'szint' | 'tulajdonsagok' | 'osztaly'>): number[] {
|
||||
const base = TamadasBonusz(karakter.osztaly, karakter.szint);
|
||||
let modifier = Modifier(karakter.tulajdonsagok.t_ero)
|
||||
if (karakter.osztaly === Osztaly.Kaloz && karakter.tulajdonsagok.t_ugy > karakter.tulajdonsagok.t_ero) {
|
||||
modifier = Modifier(karakter.tulajdonsagok.t_ugy)
|
||||
}
|
||||
return base.map(v => v + modifier)
|
||||
}
|
||||
export function CelzoTB(karakter : Pick<KarakterInputs, 'szint' | 'tulajdonsagok' | 'osztaly'>): number[] {
|
||||
let base = TamadasBonusz(karakter.osztaly, karakter.szint)
|
||||
if (karakter.osztaly === Osztaly.Ijasz) {
|
||||
base = [base[0], ...base]
|
||||
}
|
||||
return base.map(v => v + Modifier(karakter.tulajdonsagok.t_ugy))
|
||||
}
|
||||
@@ -53,7 +53,16 @@ export function RollAllAbilities(setValue: (newValue: KarakterTulajdonsagok) =>
|
||||
|
||||
export const Modifier = (val : number) => Math.floor(val / 3) - 3
|
||||
|
||||
/* eslint-disable */ /* tslint:disable */
|
||||
export function TulajdonsagModosito(tulajdonsagok: KarakterTulajdonsagok): KarakterTulajdonsagok {
|
||||
let response: KarakterTulajdonsagok = { ...tulajdonsagok }
|
||||
const keys = Object.keys(tulajdonsagok) as (keyof KarakterTulajdonsagok)[]
|
||||
for (const key of keys) {
|
||||
response[key] = Modifier(tulajdonsagok[key])
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// noinspection OverlyComplexFunctionJS,FunctionTooLongJS
|
||||
function tulajdonsagModositokPerFaj(tul: Tulajdonsag, faj: Faj) : number {
|
||||
switch (faj) {
|
||||
case Faj.Birodalmi: switch (tul) {
|
||||
|
||||
Reference in New Issue
Block a user