@@ -33,20 +33,35 @@ export class ClassicPlayer extends Player {
33
33
//the username of the player that this player is nominating during the trial
34
34
private _vote : string = "" ;
35
35
private _finalVote : string = FinalVote . abstain ;
36
+ //! Important: Roles are immutable, so to keep track of uses of abilities etc, a deep copy of abilities is made.
37
+ //! This deep copy is accessible by .abilities. Whenever role is updated, _abilities must be updated too.
38
+ //! The setter for roles will do this automatically.
39
+ //! TLDR: don't use this._role, use this.role instead.
36
40
private _role : Role ;
41
+ private _abilities : Array < { ability : Ability ; uses ?: number } > = [ ] ;
37
42
private _winLynchTarget : ClassicPlayer | undefined = undefined ;
43
+ //the abilities of this player
38
44
constructor ( user : User , role : Role ) {
39
45
super ( user ) ;
40
46
this . _role = role ;
47
+ this . _abilities = Array . from ( role . abilities ) as Array < { ability : Ability ; uses ?: number } > ;
41
48
}
42
49
public get alive ( ) {
43
50
return this . _alive ;
44
51
}
45
52
public get role ( ) {
46
53
return this . _role ;
47
54
}
55
+ public set role ( role : Role ) {
56
+ this . _role = role ;
57
+ //give the player their abilities
58
+ this . _abilities = Array . from ( role . abilities ) as Array < { ability : Ability ; uses ?: number } > ;
59
+ }
60
+ public get abilities ( ) {
61
+ return this . _abilities ;
62
+ }
48
63
public upgradeToGodfather ( ) {
49
- this . _role = Roles . godfather ;
64
+ this . role = Roles . godfather ;
50
65
this . user . send ( "You have been promoted to godfather - now you get final say on who to kill." ) ;
51
66
}
52
67
get winLynchTarget ( ) {
@@ -62,13 +77,13 @@ export class ClassicPlayer extends Player {
62
77
this . _hanged = true ;
63
78
}
64
79
public get alignment ( ) : Alignment {
65
- return this . _role . alignment ;
80
+ return this . role . alignment ;
66
81
}
67
82
public get roleName ( ) : string {
68
- return this . _role . roleName ;
83
+ return this . role . roleName ;
69
84
}
70
85
public isRole ( role : Role ) : boolean {
71
- return this . _role . roleName == role . roleName ;
86
+ return this . role . roleName == role . roleName ;
72
87
}
73
88
public set target ( target : string ) {
74
89
this . _target = target ;
@@ -80,13 +95,13 @@ export class ClassicPlayer extends Player {
80
95
this . _target = "" ;
81
96
}
82
97
public get winCondition ( ) {
83
- return this . _role . winCondition ;
98
+ return this . role . winCondition ;
84
99
}
85
100
public resetAfterNight ( ) {
86
101
this . clearTarget ( ) ;
87
102
this . _healed = false ;
88
103
this . _mafiaVotes = 0 ;
89
- this . _roleBlocked = false ;
104
+ this . roleBlocked = false ;
90
105
}
91
106
public resetAfterTrial ( ) {
92
107
this . _vote = "" ;
@@ -99,7 +114,7 @@ export class ClassicPlayer extends Player {
99
114
return this . _healed ;
100
115
}
101
116
public roleBlock ( ) {
102
- this . _roleBlocked = true ;
117
+ this . roleBlocked = true ;
103
118
}
104
119
get roleBlocked ( ) {
105
120
return this . _roleBlocked ;
@@ -146,10 +161,4 @@ export class ClassicPlayer extends Player {
146
161
public get finalVote ( ) {
147
162
return this . _finalVote ;
148
163
}
149
- public get abilities ( ) : Array < {
150
- ability : Ability ;
151
- uses ?: number | undefined ;
152
- } > {
153
- return this . _role . abilities ;
154
- }
155
164
}
0 commit comments