48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
export class DnDCharacter {
|
|
private _strength: number;
|
|
private _dexterity: number;
|
|
private _constituion: number;
|
|
private _intelligence: number;
|
|
private _wisdom: number;
|
|
private _charisma: number;
|
|
|
|
constructor() {
|
|
this._strength = DnDCharacter.generateAbilityScore();
|
|
this._dexterity = DnDCharacter.generateAbilityScore();
|
|
this._constituion = DnDCharacter.generateAbilityScore();
|
|
this._intelligence = DnDCharacter.generateAbilityScore();
|
|
this._wisdom = DnDCharacter.generateAbilityScore();
|
|
this._charisma = DnDCharacter.generateAbilityScore();
|
|
}
|
|
|
|
public static generateAbilityScore(): number {
|
|
return Math.floor(3 + Math.random() * (18 - 3));
|
|
}
|
|
|
|
public static getModifierFor(abilityValue: number): number {
|
|
return Math.floor((abilityValue - 10) / 2);
|
|
}
|
|
|
|
get hitpoints(): number {
|
|
return 10 + DnDCharacter.getModifierFor(this._constituion);
|
|
}
|
|
get strength(): number {
|
|
return this._strength;
|
|
}
|
|
get dexterity(): number {
|
|
return this._dexterity;
|
|
}
|
|
get constitution(): number {
|
|
return this._constituion;
|
|
}
|
|
get intelligence(): number {
|
|
return this._intelligence;
|
|
}
|
|
get wisdom(): number {
|
|
return this._wisdom;
|
|
}
|
|
get charisma(): number {
|
|
return this._charisma;
|
|
}
|
|
}
|