Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. //Pokéconsole Trial Libraries
  2. /*
  3. Types:
  4. 1 = Normal
  5. 2 = Fighting
  6. 3 = Flying
  7. 4 = Poison
  8. 5 = Ground
  9. 6 = Rock
  10. 7 = Bug
  11. 8 = Ghost
  12. 9 = Steel
  13. 10 = Fire
  14. 11 = Water
  15. 12 = Grass
  16. 13 = Electric
  17. 14 = Psychic
  18. 15 = Ice
  19. 16 = Dragon
  20. 17 = Dark
  21. 18 = Fairy
  22. */
  23. /*
  24. Stat Arrays:
  25. 1 = hp
  26. 2 = attack
  27. 3 = defense
  28. 4 = special attack
  29. 5 = special defense
  30. 6 = speed
  31. */
  32. /*
  33. attack Kinds:
  34. 0 = Effect
  35. 1 = Physical
  36. 2 = Special
  37. */
  38.  
  39. /*
  40. non-Volatile Status Conditions
  41. 1 = Burn
  42. 2 = Poison
  43. 3 = Frozen
  44. 4 = Paralysis
  45. 5 = Badly Poisoned
  46. */
  47.  
  48. var None = 0;
  49. var Normal = 1;
  50. var Fighting = 2;
  51. var Flying = 3;
  52. var Poison = 4;
  53. var Ground = 5;
  54. var Rock = 6;
  55. var Bug = 7;
  56. var Ghost = 8;
  57. var Steel = 9;
  58. var Fire = 10;
  59. var Water = 11;
  60. var Grass = 12;
  61. var Electric = 13;
  62. var Psychic = 14;
  63. var Ice = 15;
  64. var Dragon = 16;
  65. var Dark = 17;
  66. var Fairy = 18;
  67.  
  68. //attack Class declaration
  69. function attack(attackName, attackType, attackKind, power, accuracy, pp){
  70. this.attackName = attackName;
  71. this.attackType = attackType;
  72. this.attackKind = attackKind;
  73. this.power = power;
  74. this.accuracy = accuracy;
  75. this.pp = pp;
  76. }
  77. //attack Declaration
  78. var ember = new attack("Ember", Fire, 1, 50, 1, 35);
  79. var tackle = new attack("Tackle", Normal, 1, 50, 1, 35);
  80.  
  81. //Pokémon Class declaration
  82.  
  83. function pokemon(pokemonName, pokemonType1, pokemonType2, ability, atk, def, spAtk, spDef, spd, hp, level, nonVolStat, move_1, move_2, move_3, move_4){
  84. this.pokemonName = pokemonName;
  85. this.pokemonType = [pokemonType1, pokemonType2];
  86. this.ability = ability;
  87. this.baseStats = [hp, atk, def, spAtk, spDef, spd];
  88. this.affectedStats = [hp, atk, def, spAtk, spDef, spd];
  89. this.level = level;
  90. this.nonVolStat = nonVolStat;
  91. this.moveSet = [move_1, move_2, move_3, move_4];
  92. this.suffernonVolStat = function(){
  93. var hpLoss = undefined;
  94. if (this.nonVolStat === 1){
  95. console.log("Suffering from Burn!");
  96. this.affectedStats[0] = Math.round(this.affectedStats[0] - (this.baseStats[0]/8));
  97. hpLoss = (this.baseStats[0]/8);
  98. console.log("Lost " + hpLoss + "HP");
  99. console.log(this.pokemonName + " has " + this.affectedStats[0] + "HP remaining.");
  100. this.baseStats[1] = this.baseStats[1]/2;
  101. }
  102. else if (this.nonVolStat === 2){
  103. console.log("Suffering from Poison!");
  104. hpLoss = Math.round(this.baseStats[0] - (this.baseStats[0]/8));
  105. this.baseStats[0] = Math.round(this.baseStats[0] - (this.baseStats[0]/8));
  106. console.log("Lost " + hpLoss + "HP");
  107. console.log(this.pokemonName + " has" + this.baseStats[0] + "HP remaining.");
  108. }
  109. else if (this.nonVolStat === 3){
  110.  
  111. }
  112. }
  113.  
  114. this.useAttack = function(target, atkName){
  115. var attackDmg = undefined;
  116. if (atkName === this.moveSet[0] || this.moveSet[1] || this.moveSet[2] || this.moveSet[3]){
  117. if (atkName.attackKind === 1){
  118. attackDmg = damage(this.level, this.affectedStats[1], target.affectedStats[2], this.affectedStats[5], atkName.power, target);
  119. }
  120. else{
  121. attackDmg = damage(this.level, this.affectedStats[3], target.affectedStats[4], this.affectedStats[5], atkName.power);
  122. }
  123. console.log(this.pokemonName + " used " + atkName.attackName);
  124. var typeReading = typeEff(atkName.attackType, target.pokemonType[0], target.pokemonType[1]);
  125. switch (typeReading){
  126. case 2:
  127. console.log("It was very effective!");
  128. break;
  129. case .5:
  130. console.log("It was not very effective...");
  131. break;
  132. case 4:
  133. console.log("It was super effective!");
  134. break;
  135. }
  136. console.log(Math.round(attackDmg) + " damage dealt!");
  137. target.affectedStats[0] = target.affectedStats[0] - Math.round(attackDmg);
  138. return attackDmg;
  139. }
  140. }
  141. this.checkAbility = function(user){
  142. if (user.ability === "Blaze"){
  143. if (user.affectedStats[0] < (user.baseStats[0]/3) && user.moveSet[0].attackType === Fire){
  144. user.moveSet[0].power = user.moveSet[0].power*1.5;
  145. }
  146. }
  147. }
  148. this.checkFaint = function(){
  149. isAbleToBattle = undefined;
  150. if (this.affectedStats[0] <= 0){
  151. isAbleToBattle = false;
  152. console.log(this.pokemonName + " is no longer able to battle!");
  153. }
  154. else{
  155. isAbleToBattle = true;
  156. }
  157. return isAbleToBattle;
  158. }
  159. }
  160.  
  161. //Pokemon Declaration
  162. var charmander = new pokemon("Charmander", 10, 0, "Blaze", 223, 81, 116, 94, 251, 400, 100, 1, ember, "None", "None", "None");
  163. var squirtle = new pokemon("Squirtle", 11, 0, "Torrent", 60, 251, 94, 249, 181, 198, 100, 0, tackle, "None", "None", "None");
  164.  
  165. //Random number function
  166. function getRandom(min, max){
  167. min = Math.ceil(min);
  168. max = Math.floor(max);
  169. return Math.floor(Math.random() * (max - min + 1)) + min;
  170. }
  171. //Type Effectivity function
  172. function typeEff(mType, tType, tType2){
  173. var typeEffectivity = undefined;
  174. if (mType === Water && tType === Fire || tType2 === Fire){
  175. typeEffectivity = 2;
  176. }
  177. else if (mType === Fire && tType === Water || tType2 === Water){
  178. typeEffectivity = .5;
  179. }
  180. else if (mType === Fire && tType === Grass && tType2 === Steel){
  181. typeEffectivity = 4
  182. }
  183. return typeEffectivity;
  184. }
  185.  
  186. //Modifier Function
  187. function modifier(usrSpd, atkType, trgtType1, trgtType2){
  188. //Type effect determinating
  189. var typeMod = typeEff(atkType, trgtType1, trgtType1);
  190. //Critical Hit determinating
  191. var crit = undefined;
  192. var randCrit = getRandom(0, 255);
  193. var t = usrSpd/2;
  194. var p = t/256;
  195. if (randCrit < t){
  196. crit = 2;
  197. console.log("Critical Hit!");
  198. }
  199. else{
  200. crit = 1;
  201. }
  202. //STAB determinating
  203. var stab = undefined;
  204. if (pokemon.pokemonType === attack.attackType){
  205. stab = 1.5;
  206. }
  207. else{
  208. stab = 1.0;
  209. }
  210. //Random Value Determinating
  211. var random = getRandom(85, 100) * 0.01;
  212. var dmgMod = stab * crit * random * typeMod;
  213. return dmgMod;
  214. }
  215.  
  216. //Damage Function
  217. function damage(level, usrAtk, opDef, usrSpeed, base, targetName){
  218. var mod = modifier(usrSpeed, usrAtk.attackType, targetName.pokemonType[0], targetName.pokemonType[1]);
  219. var dmg = (((2*level+10)/250)*(usrAtk/opDef)*base+2)*mod;
  220. return dmg;
  221. }
  222.  
  223. if(squirtle.nonVolStat != 0){
  224. squirtle.suffernonVolStat();
  225. }
  226. squirtle.checkAbility(squirtle);
  227. squirtle.useAttack(charmander, tackle);
  228. console.log("---------------");
  229. if(charmander.nonVolStat !=0){
  230. charmander.suffernonVolStat();
  231. }
  232. charmander.checkAbility(charmander);
  233. charmander.useAttack(squirtle, ember);
  234. console.log("---------------");
  235. console.log("Squirtle has " + squirtle.affectedStats[0] + "HP remaining.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement