version 0.0.1
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { atBasis, fkBasis, lepMax, paBasis, computeDerived } from '$lib/engine/derived';
|
||||
import { newCharacter } from '$lib/characters/default';
|
||||
|
||||
describe('derived', () => {
|
||||
it('computes AT/PA/FK basis for default human', () => {
|
||||
const c = newCharacter({ name: 'Test', id: '00000000-0000-4000-8000-000000000001' });
|
||||
expect(atBasis(c)).toBe(Math.round((11 + 11 + 11) / 5));
|
||||
expect(paBasis(c)).toBe(Math.round((11 + 11 + 11) / 5));
|
||||
expect(fkBasis(c)).toBe(Math.round((11 + 11 + 11) / 4));
|
||||
});
|
||||
|
||||
it('includes race LeP bonus for human', () => {
|
||||
const c = newCharacter({ name: 'H', id: '00000000-0000-4000-8000-000000000002' });
|
||||
c.meta.rasse = 'Mensch';
|
||||
const ko = 12;
|
||||
const kk = 13;
|
||||
c.eigenschaften.KO = { startwert: ko, mod: 0 };
|
||||
c.eigenschaften.KK = { startwert: kk, mod: 0 };
|
||||
const base = Math.floor((2 * ko + kk) / 2);
|
||||
expect(lepMax(c)).toBe(base + 5 + c.energien.lep.mod);
|
||||
});
|
||||
|
||||
it('computeDerived returns all keys', () => {
|
||||
const c = newCharacter({ id: '00000000-0000-4000-8000-000000000003' });
|
||||
const d = computeDerived(c);
|
||||
expect(d.atBasis).toBeTypeOf('number');
|
||||
expect(d.fkBasis).toBeTypeOf('number');
|
||||
expect(d.lepMax).toBeTypeOf('number');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { exportCharacterJson, importCharacterFromText } from '$lib/storage/io';
|
||||
import { newCharacter } from '$lib/characters/default';
|
||||
|
||||
describe('io', () => {
|
||||
it('roundtrips JSON', () => {
|
||||
const c = newCharacter({ name: 'IO', id: '00000000-0000-4000-8000-0000000000aa' });
|
||||
const json = exportCharacterJson(c);
|
||||
const back = importCharacterFromText(json, 'json');
|
||||
expect(back.meta.name).toBe('IO');
|
||||
expect(back.id).toBe(c.id);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { computeRangedTarget } from '$lib/engine/ranged';
|
||||
import { newCharacter } from '$lib/characters/default';
|
||||
import type { ExtraModifierId } from '$lib/rules/modifiers-ranged';
|
||||
|
||||
const fixedId = '00000000-0000-4000-8000-000000000099';
|
||||
|
||||
function charWithBogen(taw: number) {
|
||||
const c = newCharacter({ name: 'Archer', id: fixedId });
|
||||
const kt = c.kampftalente.find((k) => k.id === 'bogen');
|
||||
if (kt) kt.taw = taw;
|
||||
return c;
|
||||
}
|
||||
|
||||
const baseSel = {
|
||||
range: 'near' as const,
|
||||
/** Zielgröße „groß“ hat Modifikator 0 in den Tabellen */
|
||||
targetSize: 'large' as const,
|
||||
visibility: 'clear' as const,
|
||||
movement: 'slow' as const,
|
||||
extras: [] as ExtraModifierId[],
|
||||
aimTurns: 0,
|
||||
targetBuild: 'biped' as const
|
||||
};
|
||||
|
||||
describe('ranged', () => {
|
||||
it('computes FK target with zero modifiers', () => {
|
||||
const c = charWithBogen(4);
|
||||
const fkBase = Math.round((11 + 11 + 11) / 4);
|
||||
const r = computeRangedTarget(c, 'shortbow', { ...baseSel, reloadState: undefined }, 'none');
|
||||
expect(r.fkBase).toBe(fkBase);
|
||||
expect(r.baseTarget).toBe(fkBase + 4);
|
||||
expect(r.finalTarget).toBe(fkBase + 4);
|
||||
});
|
||||
|
||||
it('applies distance modifier (mittel = +4 EW)', () => {
|
||||
const c = charWithBogen(0);
|
||||
const r = computeRangedTarget(
|
||||
c,
|
||||
'shortbow',
|
||||
{ ...baseSel, range: 'medium', reloadState: 'regular_shot' },
|
||||
'none'
|
||||
);
|
||||
// +4 Entfernung, +1 normaler Schuss, +0 Zielgröße „groß“
|
||||
expect(r.totalModifier).toBe(5);
|
||||
expect(r.finalTarget).toBe(r.baseTarget - 5);
|
||||
});
|
||||
|
||||
it('halves TaW for aimed shot without expertise', () => {
|
||||
const c = charWithBogen(10);
|
||||
const r = computeRangedTarget(
|
||||
c,
|
||||
'shortbow',
|
||||
{ ...baseSel, reloadState: 'aimed_shot' },
|
||||
'none'
|
||||
);
|
||||
expect(r.effectiveTaW).toBe(5);
|
||||
expect(r.baseTarget).toBe(r.fkBase + 5);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user