|
@@ -0,0 +1,768 @@
|
|
1
|
+class baseCharacter{
|
|
2
|
+
|
|
3
|
+ constructor( aRole, skills, gender, name, experience, gempukku ){
|
|
4
|
+ if( aRole in roleSkills )
|
|
5
|
+ this.role = aRole;
|
|
6
|
+ else
|
|
7
|
+ this.role = randomFromAssociative(roleSkills);
|
|
8
|
+
|
|
9
|
+ this.gempukku = gempukku || 0;
|
|
10
|
+ this.stamina = (this.rank() < 1)? 1 : 2 ;
|
|
11
|
+ this.willpower = (this.rank() < 1)? 1 : 2 ;
|
|
12
|
+ this.perception = (this.rank() < 1)? 1 : 2 ;
|
|
13
|
+ this.strength = (this.rank() < 1)? 1 : 2 ;
|
|
14
|
+ this.reflexes = (this.rank() < 1)? 1 : 2 ;
|
|
15
|
+ this.awarness = (this.rank() < 1)? 1 : 2 ;
|
|
16
|
+ this.agility = (this.rank() < 1)? 1 : 2 ;
|
|
17
|
+ this.intelligence = (this.rank() < 1)? 1 : 2 ;
|
|
18
|
+ this.void = (this.rank() < 1)? 1 : 2 ;
|
|
19
|
+
|
|
20
|
+ this.skills = ( typeof skills === "object")? skills : {};
|
|
21
|
+ this.gender = (typeof gender !== "undefined")? gender : r_gender();
|
|
22
|
+ this.name = (name !== "undefined")? { "name" : name, "gender" : gender}: names.randomFromFilters([{ filter : "gender", value : this.gender },{ filter : "gender", value : "n" }]) ;
|
|
23
|
+ this.experience = (typeof experience === "undefined")? 25 : experience ;
|
|
24
|
+ this.expandedExperience = 0;
|
|
25
|
+ this.malus = 0 ;
|
|
26
|
+ this.actualizeWounds();
|
|
27
|
+ this.currentWounds = this.maxWounds;
|
|
28
|
+
|
|
29
|
+ this.actions[ 'attack' ] = { actionType : "complex" };
|
|
30
|
+ this.actions[ 'unarmed attack' ] = { actionType : "complex" };
|
|
31
|
+ this.actions[ 'move' ] = { actionType : "simple" };
|
|
32
|
+ this.actions[ 'draw small' ] = { actionType : "free" };
|
|
33
|
+ this.actions[ 'draw medium' ] = { actionType : "simple" };
|
|
34
|
+ this.actions[ 'draw large' ] = { actionType : "simple" };
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ actions = new Array();
|
|
38
|
+ tatoos = new Array();
|
|
39
|
+
|
|
40
|
+ earth () { return ( this.stamina < this.willpower)? this.stamina : this.willpower ;}
|
|
41
|
+ water () { return ( this.strength < this.perception)? this.strength : this.perception ;}
|
|
42
|
+ air () { return ( this.reflexes < this.awarness)? this.reflexes : this.awarness ;}
|
|
43
|
+ fire () { return ( this.agility < this.intelligence)? this.agility : this.intelligence ;}
|
|
44
|
+
|
|
45
|
+ insight(){
|
|
46
|
+ let resultat = (this.earth() + this.water() + this.air() + this.fire() + this.void) * 10 ;
|
|
47
|
+
|
|
48
|
+ if(typeof this.skills == "object")
|
|
49
|
+ for(let i in this.skills)
|
|
50
|
+ resultat += parseInt(this.skills[i]);
|
|
51
|
+ return resultat;
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ rank(){
|
|
55
|
+ let insight = this.insight();
|
|
56
|
+ switch( insight ){
|
|
57
|
+ case( !this.gempukku ):
|
|
58
|
+ return 0;
|
|
59
|
+ break;
|
|
60
|
+ case ( insight > 150 ):
|
|
61
|
+ return 1;
|
|
62
|
+ default :
|
|
63
|
+ return Math.round((insight - 125)/25);
|
|
64
|
+ }
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ skills = {};
|
|
68
|
+ skillsFromAction(){
|
|
69
|
+
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ actionPoints = 2 ;
|
|
73
|
+ freeAction = false;
|
|
74
|
+
|
|
75
|
+ complexAction(){
|
|
76
|
+ if (this.actionPoints >= 2){
|
|
77
|
+ this.actionPoints -= 2 ;
|
|
78
|
+ return true;
|
|
79
|
+ }
|
|
80
|
+ return false;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ simpleAction(){
|
|
84
|
+ if(this.actionPoints > 1){
|
|
85
|
+ this.actionPoints -= 1;
|
|
86
|
+ return true
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ freeAction(){
|
|
91
|
+ if( this.freeAction ){
|
|
92
|
+ return false;
|
|
93
|
+ }else{
|
|
94
|
+ return this.freeAction = true ;
|
|
95
|
+ }
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ chooseTatoo(){
|
|
99
|
+
|
|
100
|
+ };
|
|
101
|
+
|
|
102
|
+ weapons = {
|
|
103
|
+ "wakizachi" : weapons["wakizachi"]
|
|
104
|
+ };
|
|
105
|
+
|
|
106
|
+ armors = [];
|
|
107
|
+ equippedArmor = "kimono";
|
|
108
|
+
|
|
109
|
+ equippedArrow = "willow leaf";
|
|
110
|
+
|
|
111
|
+ rollMade = {};
|
|
112
|
+
|
|
113
|
+ baseGetTN(){
|
|
114
|
+ let armorTN = 0;
|
|
115
|
+ let modifier = 0;
|
|
116
|
+
|
|
117
|
+ switch(this.stance){
|
|
118
|
+ case "full attack":
|
|
119
|
+ modifier = -10;
|
|
120
|
+ break;
|
|
121
|
+ case "full defense":
|
|
122
|
+ modifier = this.rollMade["defense"];
|
|
123
|
+ break;
|
|
124
|
+ case "defense":
|
|
125
|
+ modifier = this.air() + this.getSkillRank( 'defense' );
|
|
126
|
+ break;
|
|
127
|
+ }
|
|
128
|
+ if ( typeof armors[ this.equippedArmor ].TN !== "undefined")
|
|
129
|
+ armorTN = armors[ this.equippedArmor ].TN;
|
|
130
|
+
|
|
131
|
+ return 5 + armorTN + (this.reflexes * 5) + modifier;
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ naturalDR = 0;
|
|
135
|
+
|
|
136
|
+ getName(){
|
|
137
|
+ return capitalize( this.name.familly ) + " " + capitalize( this.name.name );
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ dr(){
|
|
141
|
+ let armorDR = 0;
|
|
142
|
+ for (var armor in this.equippedArmor)
|
|
143
|
+ if ( typeof armor.DR !== "undefined")
|
|
144
|
+ armorDR = armor.DR;
|
|
145
|
+
|
|
146
|
+ return this.naturalDR + armorDR;
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ addWeapon( weapon ){
|
|
150
|
+ if( typeof this.weapons[ weapon ] === "objects" )
|
|
151
|
+ return null;
|
|
152
|
+ this.weapons[ weapon ] = weapons[ weapon ];
|
|
153
|
+ };
|
|
154
|
+
|
|
155
|
+ advantages = [];
|
|
156
|
+ addAdvantages ( newAdvantage ){
|
|
157
|
+ if( typeof this.advantages.find(element => element == newAdvantage ) === "undefined" ){
|
|
158
|
+ return null;
|
|
159
|
+ }
|
|
160
|
+ let cost;
|
|
161
|
+ for( advantage in advantages[ newAdvantage ] )
|
|
162
|
+ if( this.name.familly in advantages[ newAdvantage ] ){
|
|
163
|
+ cost = advantages[ newAdvantage ][ this.name.familly ];
|
|
164
|
+ } else if ( this.clan in advantages[ newAdvantage ] ){
|
|
165
|
+ advantages[ newAdvantage ][ this.clan ];
|
|
166
|
+ } else if ( this.clan in advantages[ newAdvantage ] ){
|
|
167
|
+ advantages[ newAdvantage ][ this.role ];
|
|
168
|
+ } else {
|
|
169
|
+ cost = advantages[ newAdvantage ][ "default" ];
|
|
170
|
+ }
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ hasAdvantage( advantage){
|
|
174
|
+ if( typeof this.advantages.find(element => element == advantage ) === "undefined" ){
|
|
175
|
+ return 0;
|
|
176
|
+ }
|
|
177
|
+ return 1;
|
|
178
|
+ }
|
|
179
|
+
|
|
180
|
+ act( action ){
|
|
181
|
+ if( this.actions.indexOf( action ) == -1){
|
|
182
|
+ return this.complexAction();
|
|
183
|
+ }else{
|
|
184
|
+ return this[ actions[ action ].actionType + 'Action' ]();
|
|
185
|
+ }
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ baseAttack( attackType ){
|
|
189
|
+ let modifier_r = 0;
|
|
190
|
+ let modifier_k = 0;
|
|
191
|
+ if( this.stance = "full attack"){
|
|
192
|
+ modifier_r = 2;
|
|
193
|
+ modifier_k = 1;
|
|
194
|
+ };
|
|
195
|
+
|
|
196
|
+ if( typeof attackType !== "undefined" ){
|
|
197
|
+
|
|
198
|
+ }else if( (typeof defaultAttacks === "undefined") ||
|
|
199
|
+ (typeof defaultAttacks.expandedExperience === "undefined") ||
|
|
200
|
+ (defaultAttacks.expandedExperience < this.expandedExperience)){
|
|
201
|
+
|
|
202
|
+ let attack = Object.keys(this.updateAttacks())[0];
|
|
203
|
+ if( attack == "jiujutsu" ){
|
|
204
|
+ return {"r" : this.strength + modifier_r, "k" : 1 + modifier_k};
|
|
205
|
+ }else{
|
|
206
|
+ let skill = 0;
|
|
207
|
+ if((skill = this.skills[ this.weapons[ attack ].skill ]) in this.skills){
|
|
208
|
+ return {"r" : skill[0] + modifier_r, "k" : skill[1] + modifier_k};
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ return {"r" : this[skills[weapons[ attack ].skill].trait] + modifier_r, "k" : this[skills[weapons[ attack ].skill].trait] + modifier_k, "x" : 11};
|
|
212
|
+ }
|
|
213
|
+ }
|
|
214
|
+ return { "r" : this.defaultAttacks[ Object.keys(this.defaultAttacks)[0] ]['attack'].r + modifier_r,
|
|
215
|
+ "k" : this.defaultAttacks[ Object.keys(this.defaultAttacks)[0] ]['attack'].k + modifier_k };
|
|
216
|
+ }
|
|
217
|
+
|
|
218
|
+ attackFromWeapon( weapon ){
|
|
219
|
+ let trait = parseInt( this[skills[ this.weapons[weapon].skill ].trait], 10);
|
|
220
|
+ let skill = parseInt( this.skills[ this.weapons[weapon].skill ], 10) || 0;
|
|
221
|
+ return({ "r" : trait + skill, "k" : trait, "x" : (skill)? 10: 11});
|
|
222
|
+ }
|
|
223
|
+
|
|
224
|
+ damageFromWeapon( weapon ){
|
|
225
|
+ if( weapons[ weapon ].type == "bow"){
|
|
226
|
+ let arrow = arrows[ this.equippedArrow ];
|
|
227
|
+ return {
|
|
228
|
+ "r" : arrow.r + ( weapon.strength <= this.strength )? weapon.strength : this.strength,
|
|
229
|
+ "k" : arrow.k}
|
|
230
|
+ }
|
|
231
|
+ return({ "r" : parseInt(this.strength, 10) + parseInt(weapons[ weapon ].damage.split("G")[0], 10) ,
|
|
232
|
+ "k" : parseInt(weapons[ weapon ].damage.split("G")[1], 10) });
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ damage(){
|
|
236
|
+ if( (typeof defaultAttacks === "undefined") ||
|
|
237
|
+ (typeof defaultAttacks.expandedExperience === "undefined") ||
|
|
238
|
+ (defaultAttacks.expandedExperience < this.expandedExperience)){
|
|
239
|
+
|
|
240
|
+ let weapon = Object.keys(this.updateAttacks())[0]
|
|
241
|
+
|
|
242
|
+ if( weapon == "jiujutsu")
|
|
243
|
+ return {"r" : this.strength, "k" : 1};
|
|
244
|
+ else if( weapon.type == "bow"){
|
|
245
|
+ let arrow = arrows[ this.equippedArrow ];
|
|
246
|
+ return {
|
|
247
|
+ "r" : arrow.r + ( bow_strength <= this.strength )? weapon.strength : this.strength,
|
|
248
|
+ "k" : arrow.k
|
|
249
|
+ }
|
|
250
|
+ }else{
|
|
251
|
+ let damage = weapons[ weapon ]['damage'].split("G");
|
|
252
|
+ return {"r" :damage[0], "k" : damage[1]};
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ return this.defaultAttacks[ (Object.keys( this.defaultAttacks)[0]) ];
|
|
257
|
+ }
|
|
258
|
+
|
|
259
|
+ initiative(){
|
|
260
|
+ return { "r" : this.rank() + this.reflexes , "k" : this.reflexes };
|
|
261
|
+ }
|
|
262
|
+
|
|
263
|
+ getAttack(){
|
|
264
|
+ let roll = this.attack();
|
|
265
|
+ let modifier_r = 0;
|
|
266
|
+ let modifier_k = 0;
|
|
267
|
+ if( this.stance = "full attack"){
|
|
268
|
+ modifier_r = 2;
|
|
269
|
+ modifier_k = 1;
|
|
270
|
+ }
|
|
271
|
+ return RNG.rk10(roll.r, roll.k, this.malus);
|
|
272
|
+ }
|
|
273
|
+
|
|
274
|
+ getInitiative(){
|
|
275
|
+ let roll = this.initiative();
|
|
276
|
+ return RNG.rk10(roll.r, roll.k);
|
|
277
|
+ }
|
|
278
|
+
|
|
279
|
+ getDamage(){
|
|
280
|
+ let roll = this.damage();
|
|
281
|
+ return RNG.rk10(roll.r, roll.k);
|
|
282
|
+ }
|
|
283
|
+
|
|
284
|
+ getSkillRank( aSkill ){
|
|
285
|
+ return this.skills[ aSkill ] || 0;
|
|
286
|
+ }
|
|
287
|
+
|
|
288
|
+ allAttacks(){
|
|
289
|
+ let result = {};
|
|
290
|
+ if( "jiujutsu" in this.skills ){
|
|
291
|
+ result['jiujutsu'] = { "attack" : { "r" : parseInt(this.agility, 10) + parseInt(this.skills[ 'jiujutsu' ], 10), "k": this.agility }, "damage" : { "r" : this.strength, "k" : 1} };
|
|
292
|
+ }
|
|
293
|
+ for(let i in this.weapons){
|
|
294
|
+ result[ i ] = { "attack" : this.attackFromWeapon( i ), "damage" : this.damageFromWeapon( i ) };
|
|
295
|
+ }
|
|
296
|
+ /*(result)*/
|
|
297
|
+ return result;
|
|
298
|
+ }
|
|
299
|
+
|
|
300
|
+ attacking( charac ){
|
|
301
|
+ if( this.getAttack() > charac.getTN()){
|
|
302
|
+ charac.getWounded ( this.getDamage() );
|
|
303
|
+ }
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ defaultAttacks = {};
|
|
307
|
+ attacks(){
|
|
308
|
+ if( (typeof defaultAttacks === "undefined") ||
|
|
309
|
+ (typeof defaultAttacks.expandedExperience === "undefined") ||
|
|
310
|
+ (defaultAttacks.expandedExperience < this.expandedExperience))
|
|
311
|
+ return this.updateAttacks();
|
|
312
|
+ return this.defaultAttacks[1]['attack'];
|
|
313
|
+ }
|
|
314
|
+
|
|
315
|
+ updateAttacks(){
|
|
316
|
+ let bestAttack = 0;
|
|
317
|
+ let bestDamage = 0;
|
|
318
|
+ let attacks = this.allAttacks();
|
|
319
|
+
|
|
320
|
+ for(let i in attacks){
|
|
321
|
+ if( !bestAttack )
|
|
322
|
+ bestAttack = i ;
|
|
323
|
+ if( (attacks[i].k > attacks[ bestAttack ].k ) ||
|
|
324
|
+ ((attacks[i].k = attacks[ bestAttack ]) && (attacks[i].r < attacks[ bestAttack ].r )) ||
|
|
325
|
+ ( attacks[i].r < (attacks[ bestAttack ].r + 2 ))){
|
|
326
|
+ bestAttack = i ;
|
|
327
|
+ };
|
|
328
|
+ if( !bestDamage )
|
|
329
|
+ bestDamage = i ;
|
|
330
|
+ if( (attacks[i].k > attacks[ bestDamage ].k ) ||
|
|
331
|
+ ((attacks[i].k = attacks[ bestDamage ]) && (attacks[i].r < attacks[ bestDamage ]).r ) ||
|
|
332
|
+ ( attacks[i].r < (attacks[ bestDamage ].r + 2 ))){
|
|
333
|
+ bestDamage = i ;
|
|
334
|
+ };
|
|
335
|
+ if( !bestDamage )
|
|
336
|
+ bestDamage = i ;
|
|
337
|
+ }
|
|
338
|
+ this.defaultAttacks[bestAttack] = attacks[ bestAttack ];
|
|
339
|
+ this.defaultAttacks[bestDamage] = attacks[ bestDamage ];
|
|
340
|
+ this.defaultAttacks['expandedExperience'] = this.expandedExperience;
|
|
341
|
+
|
|
342
|
+ return this.defaultAttacks;
|
|
343
|
+ }
|
|
344
|
+
|
|
345
|
+ expanseExperience( value ){
|
|
346
|
+ if(!this.experience){
|
|
347
|
+ this.experience = 0;
|
|
348
|
+ return 0;
|
|
349
|
+ }else if ( value > this.experience){
|
|
350
|
+ return 0;
|
|
351
|
+ }
|
|
352
|
+
|
|
353
|
+ if( typeof value == "undefined"){
|
|
354
|
+ this.experience = this.experience - 1;
|
|
355
|
+ this.expandedExperience = this.expandedExperience + 1;
|
|
356
|
+ }else{
|
|
357
|
+ this.experience = this.experience - value;
|
|
358
|
+ this.expandedExperience = this.expandedExperience + value;
|
|
359
|
+ }
|
|
360
|
+ return value || 1;
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+ increaseSkill( skill ){
|
|
364
|
+ if(( typeof this.skills[ skill ] === "number" ) && ( this.skills[ skill ] < 10 )){
|
|
365
|
+ var cost = this.skills[ skill ] + 1;
|
|
366
|
+ if( (this.experience - cost) >= 0 ){
|
|
367
|
+ this.expanseExperience( cost );
|
|
368
|
+ return this.skills[ skill ]++;
|
|
369
|
+ }
|
|
370
|
+ } else {
|
|
371
|
+ if( this.experience > 0){
|
|
372
|
+ this.expanseExperience();
|
|
373
|
+ return this.skills[ skill ] = 1;
|
|
374
|
+ }
|
|
375
|
+ }
|
|
376
|
+ return 0;
|
|
377
|
+ }
|
|
378
|
+
|
|
379
|
+ increaseTrait( trait ){
|
|
380
|
+ let factor = ( trait == "void")? 12 : 6 ;
|
|
381
|
+ let cost = (this[ trait ] + 1) * factor;
|
|
382
|
+ this.actualizeWounds();
|
|
383
|
+
|
|
384
|
+ if(this.expanseExperience( cost ))
|
|
385
|
+ this[ trait ]++;
|
|
386
|
+ };
|
|
387
|
+
|
|
388
|
+ actualizeWounds(){
|
|
389
|
+ this.maxWounds = 17 * this.earth();
|
|
390
|
+ return this.fullHeal;
|
|
391
|
+ };
|
|
392
|
+
|
|
393
|
+ fullHeal(){
|
|
394
|
+ return this.currentWounds = this.maxWounds;
|
|
395
|
+ }
|
|
396
|
+
|
|
397
|
+ actualizeMalus(){
|
|
398
|
+ switch(this.state){
|
|
399
|
+ case "healthy" :
|
|
400
|
+ this.malus = 0;
|
|
401
|
+ break;
|
|
402
|
+ case "nicked" :
|
|
403
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 0 : 3 ;
|
|
404
|
+ break;
|
|
405
|
+ case "grazed" :
|
|
406
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 2 : 5 ;
|
|
407
|
+ break;
|
|
408
|
+ case "hurt" :
|
|
409
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 7 : 10 ;
|
|
410
|
+ break;
|
|
411
|
+ case "injured" :
|
|
412
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 12 : 15 ;
|
|
413
|
+ break;
|
|
414
|
+ case "crippled" :
|
|
415
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 17 : 20 ;
|
|
416
|
+ break;
|
|
417
|
+ case "down" :
|
|
418
|
+ this.malus = ( this.hasAdvantage( "strength of the earth" ) )? 37 : 40 ;
|
|
419
|
+ break;
|
|
420
|
+ case "out" :
|
|
421
|
+ this.malus = 100 ;
|
|
422
|
+ break;
|
|
423
|
+ case "dead" :
|
|
424
|
+ this.malus = 1000 ;
|
|
425
|
+ break;
|
|
426
|
+ }
|
|
427
|
+ };
|
|
428
|
+
|
|
429
|
+ getWounded( wounds ){
|
|
430
|
+ let inflicted = wounds - this.dr();
|
|
431
|
+ this.currentWounds = this.currentWounds - inflicted;
|
|
432
|
+ if( this.currentWounds < 1 )
|
|
433
|
+ this.state = "dead";
|
|
434
|
+ else if( this.currentWounds < (5 * this.earth()) )
|
|
435
|
+ this.state = "out";
|
|
436
|
+ else if( this.currentWounds < (7 * this.earth()) )
|
|
437
|
+ this.state = "down";
|
|
438
|
+ else if( this.currentWounds < (9 * this.earth()) )
|
|
439
|
+ this.state = "crippled";
|
|
440
|
+ else if( this.currentWounds < (11 * this.earth()) )
|
|
441
|
+ this.state = "injured";
|
|
442
|
+ else if( this.currentWounds < (13 * this.earth()) )
|
|
443
|
+ this.state = "hurt";
|
|
444
|
+ else if( this.currentWounds < (15 * this.earth()) )
|
|
445
|
+ this.state = "grazed";
|
|
446
|
+ else if( this.currentWounds < (17 * this.earth()) )
|
|
447
|
+ this.state = "nicked";
|
|
448
|
+ else if( this.currentWounds < (7 * this.earth()) )
|
|
449
|
+ this.state = "healthy";
|
|
450
|
+ this.actualizeMalus();
|
|
451
|
+
|
|
452
|
+ return inflicted;
|
|
453
|
+ }
|
|
454
|
+
|
|
455
|
+ getHeal( value ){
|
|
456
|
+ this.currentWounds = ( value < this.maxWounds)? this.currentWounds + value : this.maxWounds;
|
|
457
|
+ this.actualizeMalus();
|
|
458
|
+ }
|
|
459
|
+
|
|
460
|
+ fullHeal(){
|
|
461
|
+ this.currentWounds = this.maxWounds;
|
|
462
|
+ this.actualizeMalus();
|
|
463
|
+ }
|
|
464
|
+
|
|
465
|
+ generate( level, role ){
|
|
466
|
+ this.role =( typeof role === "undefined" )? this.role : role ;
|
|
467
|
+ this.experience = 25 + Math.round(level * 30 + Math.pow(15, level/10));
|
|
468
|
+ this.randomTraits( level );
|
|
469
|
+ this.randomSkill( level );
|
|
470
|
+ this.armedFromSkills();
|
|
471
|
+ }
|
|
472
|
+
|
|
473
|
+ getWeaponsKeyword( keyword ){
|
|
474
|
+ let result = [];
|
|
475
|
+ for(let i = 0; i < weapons.length ; i++){
|
|
476
|
+ if( keyword in weapons[i].keyword )
|
|
477
|
+ result.push( weapons[i] );
|
|
478
|
+ }
|
|
479
|
+ return result ;
|
|
480
|
+ }
|
|
481
|
+
|
|
482
|
+ getWeaponKeyword( keyword ){
|
|
483
|
+ let weapons = getWeaponsKeyword( keyword );
|
|
484
|
+ let hasIt = 1;
|
|
485
|
+ while( hasIt ){
|
|
486
|
+ let index = random( weapons.length );
|
|
487
|
+ hasIt = this.weapons[ weapons[ index ] ];
|
|
488
|
+ if( !hasIt )
|
|
489
|
+ this.weapons.push( weapons[ index ] );
|
|
490
|
+ }
|
|
491
|
+ }
|
|
492
|
+
|
|
493
|
+ getRandomWeaponFromSkill( skill ){
|
|
494
|
+ if( typeof skill == "unsigned") return null;
|
|
495
|
+ let results = {};
|
|
496
|
+ let atLeastOne = false;
|
|
497
|
+ for(let weapon in weapons){
|
|
498
|
+ if((typeof weapon != "undefined") && (typeof weapons[weapon].skill != "undefined")){
|
|
499
|
+ if(weapons[weapon].skill == skill){
|
|
500
|
+ atLeastOne = true;
|
|
501
|
+ results[weapon] = weapons[weapon];
|
|
502
|
+ }
|
|
503
|
+ }
|
|
504
|
+ }
|
|
505
|
+ return ( atLeastOne)? randomFromAssociative( results ) : null ;
|
|
506
|
+ }
|
|
507
|
+
|
|
508
|
+ getWeaponsFromSkills( skills ){
|
|
509
|
+ let result = {};
|
|
510
|
+ for(let skill in skills){
|
|
511
|
+ let weapon = this.getRandomWeaponFromSkill( skill );
|
|
512
|
+ if(weapon)
|
|
513
|
+ Object.assign( result, weapon );
|
|
514
|
+ }
|
|
515
|
+ return result;
|
|
516
|
+ }
|
|
517
|
+
|
|
518
|
+ armedFromSkills(){
|
|
519
|
+ Object.assign( this.weapons, this.getWeaponsFromSkills( this.skills )) ;
|
|
520
|
+ }
|
|
521
|
+
|
|
522
|
+ allSkills(){
|
|
523
|
+ let skillList = roleSkills[ this.role ];
|
|
524
|
+ for(let skill in skillList){
|
|
525
|
+ skillList[skill].occurrence *= 10;
|
|
526
|
+ }
|
|
527
|
+ return Object.assign({}, skillList, skills);
|
|
528
|
+ }
|
|
529
|
+
|
|
530
|
+ randomSkill(){
|
|
531
|
+ let hasMain = 0;
|
|
532
|
+ let skill ;
|
|
533
|
+ let skillList = this.allSkills();
|
|
534
|
+
|
|
535
|
+ while( this.experience > 2 ){
|
|
536
|
+ skill = randomFromWeight( skillList );
|
|
537
|
+
|
|
538
|
+ if( hasMain ){
|
|
539
|
+ if( skill == hasMain ){
|
|
540
|
+ if(!this.increaseSkill( Object.keys(skill)[0] )){
|
|
541
|
+ skill = Object.keys( randomFromWeight( skillList ))[0];
|
|
542
|
+
|
|
543
|
+ for(let i = 0 ; !this.increaseSkill( skill ) && (i < arrayLength( skillList)); i++ ){
|
|
544
|
+ skill = Object.keys( randomFromWeight( skillList ))[0];
|
|
545
|
+ };
|
|
546
|
+ };
|
|
547
|
+ }
|
|
548
|
+ } else if(( typeof skill !== "undefined" ) && ( skill !== null )){
|
|
549
|
+ if( typeof skill.main !== "undefined"){
|
|
550
|
+ hasMain = skill;
|
|
551
|
+ this.increaseSkill( Object.keys(skill)[0] ) ;
|
|
552
|
+ }
|
|
553
|
+ } else {
|
|
554
|
+ this.increaseSkill( Object.keys(skill)[0] ) ;
|
|
555
|
+ }
|
|
556
|
+ }
|
|
557
|
+ }
|
|
558
|
+
|
|
559
|
+ randomFromWeight( skills ){
|
|
560
|
+ let weight = [];
|
|
561
|
+
|
|
562
|
+ for(skill in skills)
|
|
563
|
+ if(typeof skill.occurence !== "undefined")
|
|
564
|
+ /*size +=*/;
|
|
565
|
+ }
|
|
566
|
+
|
|
567
|
+ randomTraits( level ){
|
|
568
|
+ let pass = level * random(2) + random(2);
|
|
569
|
+ switch( this.role ){
|
|
570
|
+ case "bushi" :
|
|
571
|
+ while(pass){
|
|
572
|
+ let asset = random(3);
|
|
573
|
+ switch( asset ){
|
|
574
|
+ case 0 :
|
|
575
|
+ if( this.experience >= ((6 * this.increaseTrait("stamina") + (6 * this.increaseTrait("willpower"))))){
|
|
576
|
+ this.increaseTrait("willpower");
|
|
577
|
+ this.increaseTrait("stamina");
|
|
578
|
+ }else
|
|
579
|
+ this.increaseTrait("void")
|
|
580
|
+ break;
|
|
581
|
+ case 1 :
|
|
582
|
+ this.increaseTrait("strength") ;
|
|
583
|
+ break;
|
|
584
|
+ case 2 :
|
|
585
|
+ this.increaseTrait("reflexes");
|
|
586
|
+ break;
|
|
587
|
+ case 3 :
|
|
588
|
+ this.increaseTrait("agility");
|
|
589
|
+ break;
|
|
590
|
+ };
|
|
591
|
+ pass--;
|
|
592
|
+ }
|
|
593
|
+ break;
|
|
594
|
+ case "shugenja" :
|
|
595
|
+ switch( random(3) ){
|
|
596
|
+ case 0 :
|
|
597
|
+ while(pass){
|
|
598
|
+ this.increaseTrait("stamina") ;
|
|
599
|
+ this.increaseTrait("willpower");}
|
|
600
|
+ break;
|
|
601
|
+ case 1 :
|
|
602
|
+ while(pass){
|
|
603
|
+ this.increaseTrait("perception");
|
|
604
|
+ this.increaseTrait("strength") ;}
|
|
605
|
+ break;
|
|
606
|
+ case 2 :
|
|
607
|
+ while(pass){
|
|
608
|
+ this.increaseTrait("reflexes") ;
|
|
609
|
+ this.increaseTrait("awarness") ;}
|
|
610
|
+ break;
|
|
611
|
+ case 3 :
|
|
612
|
+ while(pass){
|
|
613
|
+ this.increaseTrait("intelligence") ;
|
|
614
|
+ this.increaseTrait("agility") ;}
|
|
615
|
+ break;
|
|
616
|
+ }
|
|
617
|
+ break;
|
|
618
|
+ case "monk" :
|
|
619
|
+ while(pass){
|
|
620
|
+ let asset = random(3);
|
|
621
|
+ switch( asset ){
|
|
622
|
+ case 0 :
|
|
623
|
+ this.increaseTrait("void") ;
|
|
624
|
+ break;
|
|
625
|
+ case 1 :
|
|
626
|
+ this.increaseTrait("strength") ;
|
|
627
|
+ this.increaseTrait("agility");
|
|
628
|
+ break;
|
|
629
|
+ case 2 :
|
|
630
|
+ this.increaseTrait("awarness");
|
|
631
|
+ this.increaseTrait("reflexes");
|
|
632
|
+ break;
|
|
633
|
+ case 3 :
|
|
634
|
+ this.increaseTrait("void");
|
|
635
|
+ this.increaseTrait("strength");
|
|
636
|
+ break;
|
|
637
|
+ };
|
|
638
|
+ pass--;
|
|
639
|
+ }
|
|
640
|
+ break;
|
|
641
|
+ case "scout" :
|
|
642
|
+ while(pass){
|
|
643
|
+ let asset = random(2);
|
|
644
|
+ switch( asset ){
|
|
645
|
+ case 0 :
|
|
646
|
+ this.increaseTrait("perception");
|
|
647
|
+ this.increaseTrait("strength");
|
|
648
|
+ break;
|
|
649
|
+ case 1 :
|
|
650
|
+ this.increaseTrait("agility");
|
|
651
|
+ break;
|
|
652
|
+ case 2 :
|
|
653
|
+ this.increaseTrait("reflexes");
|
|
654
|
+ break;
|
|
655
|
+ };
|
|
656
|
+ pass--;
|
|
657
|
+ }
|
|
658
|
+ break;
|
|
659
|
+ case "ninja" :
|
|
660
|
+ while(pass){
|
|
661
|
+ let asset = random(2);
|
|
662
|
+ switch( asset ){
|
|
663
|
+ case 0 :
|
|
664
|
+ this.increaseTrait("void")
|
|
665
|
+ break;
|
|
666
|
+ case 1 :
|
|
667
|
+ this.increaseTrait("agility") ;
|
|
668
|
+ break;
|
|
669
|
+ case 2 :
|
|
670
|
+ this.increaseTrait("reflexes");
|
|
671
|
+ break;
|
|
672
|
+ };
|
|
673
|
+ pass--;
|
|
674
|
+ }
|
|
675
|
+ break;
|
|
676
|
+ }
|
|
677
|
+ this.actualizeWounds();
|
|
678
|
+ }
|
|
679
|
+
|
|
680
|
+ getWounds(){
|
|
681
|
+ return this.currentWounds ;
|
|
682
|
+ }
|
|
683
|
+
|
|
684
|
+ stance = "attack";
|
|
685
|
+
|
|
686
|
+ switchStance( aStance ){
|
|
687
|
+ if( stances.includes( aStance ) ){
|
|
688
|
+ this.stance = aStance;
|
|
689
|
+ }else if( typeof aStance === "undefined" ){
|
|
690
|
+ let nextStanceIndex = stances.indexOf( this.stance ) + 1;
|
|
691
|
+ nextStanceIndex = (nextStanceIndex >= stances.length )? 0 : nextStanceIndex;
|
|
692
|
+ this.stance = stances[ nextStanceIndex ];
|
|
693
|
+ }
|
|
694
|
+ if( this.stance == "full defense")
|
|
695
|
+ this.rollMade["defense"] = this.skillRoll( "defense" ) ;
|
|
696
|
+ }
|
|
697
|
+
|
|
698
|
+ skillRoll( skill ){
|
|
699
|
+ let skillRank = this.getSkillRank( "defense" );
|
|
700
|
+ let traitRank = this[ skills[skill].trait ];
|
|
701
|
+ return RNG.rk10( traitRank + skillRank, traitRank );
|
|
702
|
+ }
|
|
703
|
+}
|
|
704
|
+
|
|
705
|
+class Character extends baseCharacter{
|
|
706
|
+
|
|
707
|
+ constructor( aRole, skills, gender, name, experience, gempukku ){
|
|
708
|
+ super( aRole, skills, gender, name, experience, gempukku );
|
|
709
|
+ }
|
|
710
|
+
|
|
711
|
+ getTN(){
|
|
712
|
+ return this.baseGetTN();
|
|
713
|
+ }
|
|
714
|
+
|
|
715
|
+ attack(){
|
|
716
|
+ return this.baseAttack();
|
|
717
|
+ }
|
|
718
|
+}
|
|
719
|
+
|
|
720
|
+class Samourai extends Character {
|
|
721
|
+ constructor( aRole, gender, name, familly, school, experience, gempukku, skills){
|
|
722
|
+ super( aRole, skills, gender, name, experience, gempukku );
|
|
723
|
+
|
|
724
|
+ this.setFamilly( familly );
|
|
725
|
+ this.setBasicSchool( school );
|
|
726
|
+ this.autoWearArmor();
|
|
727
|
+ }
|
|
728
|
+
|
|
729
|
+ setFamilly( familly_name ){
|
|
730
|
+ let familly = famillies[ familly_name ];
|
|
731
|
+ this[ familly.trait ]++;
|
|
732
|
+ this.name['familly'] = familly_name;
|
|
733
|
+ }
|
|
734
|
+
|
|
735
|
+ setBasicSchool( school_name ){
|
|
736
|
+ let school = basicSchool[ school_name ];
|
|
737
|
+ this[ school.trait ]++;
|
|
738
|
+ for(let i = 0 ; i < school.outfit.weapon.length ; i++){
|
|
739
|
+ let weapon = (school.outfit.weapon[ i ] == "any")? Object.keys( randomFromAssociative( weapons ) ) : school.outfit.weapon[ i ];
|
|
740
|
+
|
|
741
|
+ if( !(weapon in this.weapons) )
|
|
742
|
+ this.weapons[ weapon ] = weapons[ weapon ];
|
|
743
|
+ }
|
|
744
|
+ this.armors = school.outfit.armor || this.armors;
|
|
745
|
+
|
|
746
|
+ for( let i = 0; i < school.skills.length ; i++ ){
|
|
747
|
+ if( !(school.skills[i] in this.skills) )
|
|
748
|
+ this.skills[ school.skills[i] ] = 1;
|
|
749
|
+ }
|
|
750
|
+ }
|
|
751
|
+
|
|
752
|
+ autoWearArmor(){
|
|
753
|
+ let maxArmor = "kimono";
|
|
754
|
+ for(let i = 0 ; i < this.armors.length ; i++){
|
|
755
|
+ if( armors[ this.armors[ i ] ].TN > armors[ maxArmor ].TN ){
|
|
756
|
+ maxArmor = this.armors[i];
|
|
757
|
+ }
|
|
758
|
+ };
|
|
759
|
+ this.equippedArmor = maxArmor;
|
|
760
|
+ }
|
|
761
|
+}
|
|
762
|
+
|
|
763
|
+class People extends Samourai {
|
|
764
|
+ constructor( gender, name, familly, school, experience, skills){
|
|
765
|
+ super( "people", gender, name, familly, school, experience, 0, skills );
|
|
766
|
+ }
|
|
767
|
+
|
|
768
|
+}
|