Gestion de personnage et de pool de personnage en javascript vanilla
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

character.js 24KB

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