90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import type { Uma } from './data/uma';
|
|
import { AptitudeLevel, Mood, RunningStyle } from './race';
|
|
import * as alpha123Umalator from './alpha123Umalator';
|
|
|
|
/**
|
|
* Race runner, i.e. a trained horse.
|
|
*/
|
|
export interface Runner {
|
|
name: string;
|
|
|
|
chara_card_id: number;
|
|
style: RunningStyle;
|
|
mood: Mood;
|
|
|
|
speed: number;
|
|
stamina: number;
|
|
power: number;
|
|
guts: number;
|
|
wit: number;
|
|
|
|
sprint: AptitudeLevel;
|
|
mile: AptitudeLevel;
|
|
medium: AptitudeLevel;
|
|
long: AptitudeLevel;
|
|
front: AptitudeLevel;
|
|
pace: AptitudeLevel;
|
|
late: AptitudeLevel;
|
|
end: AptitudeLevel;
|
|
turf: AptitudeLevel;
|
|
dirt: AptitudeLevel;
|
|
|
|
skills: number[];
|
|
unique_level: number;
|
|
}
|
|
|
|
/**
|
|
* Create a new runner with baseline stats.
|
|
* @param name Name to apply to the runner
|
|
* @param base_uma Character card (trainee or uma) to use for aptitudes; otherwise all aptitudes are A
|
|
* @returns Baseline runner
|
|
*/
|
|
export function newRunner(name?: string, base_uma?: Uma): Runner {
|
|
return {
|
|
name: name ?? '',
|
|
chara_card_id: base_uma?.chara_card_id ?? 0,
|
|
// TODO(zeph): default running style
|
|
style: RunningStyle.FrontRunner,
|
|
mood: Mood.Normal,
|
|
speed: 1200,
|
|
stamina: 1200,
|
|
power: 1200,
|
|
guts: 1200,
|
|
wit: 1200,
|
|
sprint: base_uma?.sprint ?? AptitudeLevel.A,
|
|
mile: base_uma?.mile ?? AptitudeLevel.A,
|
|
medium: base_uma?.medium ?? AptitudeLevel.A,
|
|
long: base_uma?.long ?? AptitudeLevel.A,
|
|
front: base_uma?.front ?? AptitudeLevel.A,
|
|
pace: base_uma?.pace ?? AptitudeLevel.A,
|
|
late: base_uma?.late ?? AptitudeLevel.A,
|
|
end: base_uma?.end ?? AptitudeLevel.A,
|
|
turf: base_uma?.turf ?? AptitudeLevel.A,
|
|
dirt: base_uma?.dirt ?? AptitudeLevel.A,
|
|
skills: base_uma != null ? [base_uma.unique] : [],
|
|
unique_level: 4,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Import a runner from an external source.
|
|
* @param obj Decoded object to import
|
|
* @param name Name or memo to apply to the runner
|
|
* @returns Imported runner, or null if import was not possible
|
|
*/
|
|
export function importRunner(obj: unknown, name?: string): Runner | null {
|
|
// TODO(zeph): check for keys that identify the uma source
|
|
if (typeof obj === 'object') {
|
|
try {
|
|
const r = alpha123Umalator.load(obj as alpha123Umalator.ImportUma, name);
|
|
// TODO(zeph): validate?
|
|
return r;
|
|
} catch (exc) {
|
|
console.warn('failed to import', obj, 'as alpha123 umalator:', exc);
|
|
return null;
|
|
}
|
|
}
|
|
console.warn('no guess on how to import', obj);
|
|
return null;
|
|
}
|