You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
9.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include "Battle.hpp"
  2. std::vector<Spell> Battle::SPELL_BOOK = {
  3. Spell("Blazing Storm", Spell::TYPE_DESTRUCTION, 10, 5),
  4. Spell("Energy Arrow", Spell::TYPE_DESTRUCTION, 40, 10),
  5. Spell("Pyro Strike", Spell::TYPE_DESTRUCTION, 90, 15),
  6. Spell("Seism", Spell::TYPE_DESTRUCTION, 160, 20),
  7. Spell("Teleport", Spell::TYPE_DESTRUCTION, 250, 25),
  8. Spell("Beam of Nature's Wrath", Spell::TYPE_DESTRUCTION, 360, 30),
  9. Spell("Ball of the Molten Core", Spell::TYPE_DESTRUCTION, 490, 35),
  10. Spell("Wrath of Poison", Spell::TYPE_DESTRUCTION, 640, 40),
  11. Spell("Extortion Burst", Spell::TYPE_DESTRUCTION, 810, 45),
  12. Spell("Projection of Sound", Spell::TYPE_DESTRUCTION, 1000, 50),
  13. Spell("Soul Tempest", Spell::TYPE_DESTRUCTION, 1210, 55),
  14. Spell("Mystic Nova", Spell::TYPE_DESTRUCTION, 1440, 60),
  15. Spell("Frostfire Burn", Spell::TYPE_DESTRUCTION, 1690, 65),
  16. Spell("Torrent", Spell::TYPE_DESTRUCTION, 1960, 70),
  17. Spell("Windstorm", Spell::TYPE_DESTRUCTION, 2250, 75),
  18. Spell("Barrier of Redemption", Spell::TYPE_DESTRUCTION, 2560, 80),
  19. Spell("Burst of the Angels", Spell::TYPE_DESTRUCTION, 2890, 85),
  20. Spell("Absorption of Chaos", Spell::TYPE_DESTRUCTION, 3240, 90),
  21. Spell("Decay of Light", Spell::TYPE_DESTRUCTION, 3610, 95),
  22. Spell("Dispersion of Force", Spell::TYPE_DESTRUCTION, 4000, 100),
  23. Spell("Solar Barrage", Spell::TYPE_DESTRUCTION, 4410, 105),
  24. Spell("Death Burn", Spell::TYPE_DESTRUCTION, 4840, 110),
  25. Spell("Blazing Strike", Spell::TYPE_DESTRUCTION, 5290, 115),
  26. Spell("Imitate", Spell::TYPE_DESTRUCTION, 5760, 120),
  27. Spell("Shooting Star", Spell::TYPE_DESTRUCTION, 6250, 125),
  28. Spell("Seal of Traps", Spell::TYPE_DESTRUCTION, 6760, 130),
  29. Spell("Flare of the Inferno", Spell::TYPE_DESTRUCTION, 7290, 135),
  30. Spell("Distraction of Stone", Spell::TYPE_DESTRUCTION, 7840, 140),
  31. Spell("Concentration of Glory", Spell::TYPE_DESTRUCTION, 8410, 145),
  32. Spell("Calm of Energy", Spell::TYPE_DESTRUCTION, 9000, 150),
  33. Spell("Soul Surge", Spell::TYPE_DESTRUCTION, 9610, 155),
  34. Spell("Moonlight Blaze", Spell::TYPE_DESTRUCTION, 10240, 160),
  35. Spell("Sunlight Salvo", Spell::TYPE_DESTRUCTION, 10890, 165),
  36. Spell("Banish Demon", Spell::TYPE_DESTRUCTION, 11560, 170),
  37. Spell("Hurricane", Spell::TYPE_DESTRUCTION, 12250, 175),
  38. Spell("Blast of Soul Draining", Spell::TYPE_DESTRUCTION, 12960, 180),
  39. Spell("Burst of Altered Time", Spell::TYPE_DESTRUCTION, 13690, 185),
  40. Spell("Incantation of Time", Spell::TYPE_DESTRUCTION, 14440, 190),
  41. Spell("Demolition Curse", Spell::TYPE_DESTRUCTION, 15210, 195),
  42. Spell("Protection of Phantoms", Spell::TYPE_DESTRUCTION, 16000, 200),
  43. Spell("Mage Burst", Spell::TYPE_DESTRUCTION, 16810, 205),
  44. Spell("Starfire Hail", Spell::TYPE_DESTRUCTION, 17640, 210),
  45. Spell("Ice Blitz", Spell::TYPE_DESTRUCTION, 18490, 215),
  46. Spell("Cyclone", Spell::TYPE_DESTRUCTION, 19360, 220),
  47. Spell("Charge", Spell::TYPE_DESTRUCTION, 20250, 225),
  48. Spell("Barrier of Exhaustion", Spell::TYPE_DESTRUCTION, 21160, 230),
  49. Spell("Blessing of Demon Fire", Spell::TYPE_DESTRUCTION, 22090, 235),
  50. Spell("Illusion Blast", Spell::TYPE_DESTRUCTION, 23040, 240),
  51. Spell("Fury of Poison", Spell::TYPE_DESTRUCTION, 24010, 245),
  52. Spell("Plagueing of Fire", Spell::TYPE_DESTRUCTION, 25000, 250),
  53. Spell("Fiery Eruption", Spell::TYPE_DESTRUCTION, 26010, 255),
  54. Spell("Thunder Arrow", Spell::TYPE_DESTRUCTION, 27040, 260),
  55. Spell("Infernal Bomb", Spell::TYPE_DESTRUCTION, 28090, 265),
  56. Spell("Ignite", Spell::TYPE_DESTRUCTION, 29160, 270),
  57. Spell("Solidify", Spell::TYPE_DESTRUCTION, 30250, 275),
  58. Spell("Call of Burning Embers", Spell::TYPE_DESTRUCTION, 31360, 280),
  59. Spell("Burst of Acid", Spell::TYPE_DESTRUCTION, 32490, 285),
  60. Spell("Calm of Death", Spell::TYPE_DESTRUCTION, 33640, 290),
  61. Spell("Annihilation Burst", Spell::TYPE_DESTRUCTION, 34810, 295),
  62. Spell("Absorption of Strength", Spell::TYPE_DESTRUCTION, 36000, 300),
  63. Spell("Infernal Explosion", Spell::TYPE_DESTRUCTION, 37210, 305),
  64. Spell("Lava Blast", Spell::TYPE_DESTRUCTION, 38440, 310),
  65. Spell("Pyro Spike", Spell::TYPE_DESTRUCTION, 39690, 315),
  66. Spell("Mind Blast", Spell::TYPE_DESTRUCTION, 40960, 320),
  67. Spell("Extinguish", Spell::TYPE_DESTRUCTION, 42250, 325),
  68. Spell("Spell of Obliteration", Spell::TYPE_DESTRUCTION, 43560, 330),
  69. Spell("Hymn of Havoc", Spell::TYPE_DESTRUCTION, 44890, 335),
  70. Spell("Consecration Ritual", Spell::TYPE_DESTRUCTION, 46240, 340),
  71. Spell("Distraction of Perfection", Spell::TYPE_DESTRUCTION, 47610, 345),
  72. Spell("Delusion of Vulnerabilities", Spell::TYPE_DESTRUCTION, 49000, 350),
  73. Spell("Static Blaze", Spell::TYPE_DESTRUCTION, 50410, 355),
  74. Spell("Pyro Whip", Spell::TYPE_DESTRUCTION, 51840, 360),
  75. Spell("Acid Blitz", Spell::TYPE_DESTRUCTION, 53290, 365),
  76. Spell("Daydream", Spell::TYPE_DESTRUCTION, 54760, 370),
  77. Spell("Invigorate", Spell::TYPE_DESTRUCTION, 56250, 375),
  78. Spell("Hymn of Revival", Spell::TYPE_DESTRUCTION, 57760, 380),
  79. Spell("Jinx of Health", Spell::TYPE_DESTRUCTION, 59290, 385),
  80. Spell("Division of Defense", Spell::TYPE_DESTRUCTION, 60840, 390),
  81. Spell("Abjuration Orb", Spell::TYPE_DESTRUCTION, 62410, 395),
  82. Spell("Divinity of Life", Spell::TYPE_DESTRUCTION, 64000, 400),
  83. Spell("Shadow Flash", Spell::TYPE_DESTRUCTION, 65610, 405),
  84. Spell("Mind Flare", Spell::TYPE_DESTRUCTION, 67240, 410),
  85. Spell("Unholy Explosion", Spell::TYPE_DESTRUCTION, 68890, 415),
  86. Spell("Soulburn", Spell::TYPE_DESTRUCTION, 70560, 420),
  87. Spell("Phantom Form", Spell::TYPE_DESTRUCTION, 72250, 425),
  88. Spell("Rain of Plagues", Spell::TYPE_DESTRUCTION, 73960, 430),
  89. Spell("Aura of Shifting Sands", Spell::TYPE_DESTRUCTION, 75690, 435),
  90. Spell("Purification of Heat", Spell::TYPE_DESTRUCTION, 77440, 440),
  91. Spell("Purification of Hell", Spell::TYPE_DESTRUCTION, 79210, 445),
  92. Spell("Purity of SoulsVoid Tempest", Spell::TYPE_DESTRUCTION, 81000, 450),
  93. Spell("Thunder Hail", Spell::TYPE_DESTRUCTION, 82810, 455),
  94. Spell("Acid Bolt", Spell::TYPE_DESTRUCTION, 84640, 460),
  95. Spell("Incinerate", Spell::TYPE_DESTRUCTION, 86490, 465),
  96. Spell("Slow", Spell::TYPE_DESTRUCTION, 88360, 470),
  97. Spell("Bolt of Deflection", Spell::TYPE_DESTRUCTION, 90250, 475),
  98. Spell("Beam of Shadows", Spell::TYPE_DESTRUCTION, 92160, 480),
  99. Spell("Putrefaction of Blessings", Spell::TYPE_DESTRUCTION, 94090, 485),
  100. Spell("Exploitation of Force", Spell::TYPE_DESTRUCTION, 96040, 490),
  101. Spell("Annihilation Ceremony", Spell::TYPE_DESTRUCTION, 98010, 495),
  102. Spell("Repose of Energy", Spell::TYPE_DESTRUCTION, 100000, 500),
  103. };
  104. Battle::Battle(
  105. Character &p1,
  106. Character &p2) : player1(p1), player2(p2)
  107. {
  108. this->turn = 0;
  109. }
  110. void Battle::battleStartAnnounce()
  111. {
  112. std::cout << " === BATTLE START === \n"
  113. << " " << player1.getName() << "\n"
  114. << " vs \n"
  115. << " " << player2.getName() << "\n"
  116. << " === ============ === \n"
  117. << std::flush;
  118. }
  119. void Battle::battleEndAnnouce()
  120. {
  121. std::cout << " === BATTLE END === \n"
  122. << " Winner: " << ((winner == 1) ? player1.getName() : player2.getName()) << "\n"
  123. << std::flush;
  124. }
  125. void Battle::start()
  126. {
  127. int choiceInt;
  128. char buff[64] = {0};
  129. this->battleStartAnnounce();
  130. while ((player1.isAlive() && player2.isAlive()) && this->turn <= Battle::MAX_TURN)
  131. {
  132. std::cout << "Turn " << this->turn << " of " << Battle::MAX_TURN << "\n"
  133. << "Your spell book:\n";
  134. for (size_t i = 0; i < SPELL_BOOK.size() && i <= (player1.getLevel()); i++)
  135. {
  136. std::cout << "[" << i << "] " << SPELL_BOOK.at(i).getName() << "\n";
  137. }
  138. std::cout << std::flush;
  139. choiceInt = UserInterface::getNumber(
  140. "What are you gonna cast this turn?\n>", 0,
  141. player1.getLevel() > SPELL_BOOK.size() ? SPELL_BOOK.size() : player1.getLevel());
  142. if (player1.canCastSpell(SPELL_BOOK.at(choiceInt)))
  143. {
  144. player1.castSpell(SPELL_BOOK.at(choiceInt), player2);
  145. snprintf(buff, 63, "%s cast %s...\n", player1.getName(), SPELL_BOOK.at(choiceInt).getName());
  146. UserInterface::print(buff);
  147. memset(buff, 0, 64);
  148. snprintf(buff, 63, "%s took %d damage...\n", player2.getName(), SPELL_BOOK.at(choiceInt).getPower());
  149. UserInterface::print(buff);
  150. memset(buff, 0, 64);
  151. }
  152. else
  153. {
  154. snprintf(buff, 63, "%s failed to cast %s!\n", player1.getName(), SPELL_BOOK.at(choiceInt).getName());
  155. UserInterface::print(buff);
  156. }
  157. choiceInt = (this->turn % (player2.getLevel() < SPELL_BOOK.size() ? player2.getLevel() : SPELL_BOOK.size())) + 1;
  158. if (player2.canCastSpell(SPELL_BOOK.at(choiceInt)))
  159. {
  160. player2.castSpell(SPELL_BOOK.at(choiceInt), player1);
  161. snprintf(buff, 63, "%s cast %s...\n", player2.getName(), SPELL_BOOK.at(choiceInt).getName());
  162. UserInterface::print(buff);
  163. memset(buff, 0, 64);
  164. snprintf(buff, 63, "%s took %d damage...\n", player1.getName(), SPELL_BOOK.at(choiceInt).getPower());
  165. UserInterface::print(buff);
  166. memset(buff, 0, 64);
  167. }
  168. else
  169. {
  170. snprintf(buff, 63, "%s failed to cast %s!\n", player2.getName(), SPELL_BOOK.at(choiceInt).getName());
  171. UserInterface::print(buff);
  172. }
  173. this->turn++;
  174. }
  175. this->winner = (player1.isAlive() && (player1.getCurHP() >= player2.getCurHP())) ? 1 : 2;
  176. this->battleEndAnnouce();
  177. }
  178. int Battle::getWinner()
  179. {
  180. return this->winner;
  181. }