chore(release): 0.1.0
[risinglegends.git] / src / shared / player.ts
1 import { Profession } from './profession'; 
2 import { Stat } from './stats';
3 import { SkillDefinition, Skill } from './skills';
4
5 export type Player = {
6   id: string,
7   account_type: 'session' | 'auth',
8   create_date: Date,
9   profession: Profession,
10   username: string,
11   strength: number;
12   constitution: number;
13   dexterity: number;
14   intelligence: number;
15   stamina: number;
16   exp: number;
17   level: number;
18   gold: number;
19   hp: number;
20   city_id: number;
21   stat_points: number;
22 }
23
24 export type PlayerWithSkills = Player & {
25   skills: (SkillDefinition & Skill)[]
26 }
27
28 export function maxHp(constitution: number, playerLevel: number): number {
29   return Math.ceil((constitution + playerLevel) * 1.3);
30 }
31
32 export function expToLevel(level: number): number {
33   if(level < 10) {
34     return level * 10 - 10;
35   }
36   else {
37     return level * 13;
38   }
39 }
40
41
42 export type StatDisplay = {
43   id: Stat,
44   display: string;
45   abbrv: string;
46 }
47
48 export const StatDef: Map<Stat, StatDisplay> = new Map<Stat, StatDisplay>();
49
50 StatDef.set(Stat.strength, {
51   id: Stat.strength,
52   display: 'Strength',
53   abbrv: 'STR'
54 });
55
56 StatDef.set(Stat.constitution, {
57   id: Stat.constitution,
58   display: 'Constitution',
59   abbrv: 'CON'
60 });
61
62 StatDef.set(Stat.dexterity, {
63   id: Stat.dexterity,
64   display: 'Dexterity',
65   abbrv: 'DEX'
66 });
67
68 StatDef.set(Stat.intelligence, {
69   id: Stat.intelligence,
70   display: 'Intelligence',
71   abbrv: 'INT'
72 });