-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.ts
120 lines (99 loc) · 2.66 KB
/
Player.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { Equipment } from '../../structures/equipment/Equipment';
/**
* Creates a player with the given parameters or the default parameters.
* @category Entity
*/
export class Player {
/**
* Determines the name of the player.
*/
public name: string;
/**
* Determines how much health the player has.
*/
public health: number;
/**
* Determines how much stamina the player has.
*/
public stamina: number;
/**
* Determines how much mana the player has.
*/
public mana: number;
/**
* Determines what equipment the player has.
* @see {@link Equipment | Equipment class} for more details.
*/
public equipment: Equipment;
public constructor(name = 'Player', health = 100, stamina = 100, mana = 100, equipment = new Equipment()) {
this.equipment = equipment;
this.name = name;
this.health = this.getHealth + health;
this.stamina = this.getStamina + stamina;
this.mana = this.getMana + mana;
}
/**
* Get the damage that the player gets from the equipment
*/
public get getDamage() {
const { equipment } = this;
let damage = 0;
for (const item of equipment) {
if (item?.attributes) damage += item?.attributes.damage;
}
return damage;
}
/**
* Get the defense that the player gets from the equipment
*/
public get getDefense() {
const { equipment } = this;
let defense = 0;
for (const item of equipment) {
if (item?.attributes) defense += item?.attributes.defense;
}
return defense;
}
/**
* Get the health that the player gets from the equipment
*/
public get getHealth() {
const { equipment } = this;
let health = 0;
for (const item of equipment) {
if (item?.attributes) health += item?.attributes.health;
}
return health;
}
/**
* Get the mana that the player gets from the equipment
*/
public get getMana() {
const { equipment } = this;
let mana = 0;
for (const item of equipment) {
if (item?.attributes) mana += item?.attributes.mana;
}
return mana;
}
/**
* Get the stanina that the player gets from the equipment
*/
public get getStamina() {
const { equipment } = this;
let stamina = 0;
for (const item of equipment) {
if (item?.attributes) stamina += item?.attributes.stamina;
}
return stamina;
}
/**
* Damages the player by taking the original damage and decrease it by the defense to a minimum of 0 damage.
* @param amount - The amount to damage the player for.
*/
public injure(amount: number) {
const damage = amount - this.getDefense < 0 ? 0 : amount - this.getDefense;
this.health -= damage;
return this;
}
}