Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

135 linhas
2.1 KiB

há 5 anos
  1. #include "Character.hpp"
  2. Character::Character(const char *n, int l, int e, int h, int m, int a, int d)
  3. {
  4. this->name = n;
  5. this->level = l;
  6. this->experience = e;
  7. this->maxHP = h;
  8. this->curHP = maxHP;
  9. this->maxMP = m;
  10. this->curMP = maxMP;
  11. this->atk = a;
  12. this->def = d;
  13. }
  14. const char *Character::getName()
  15. {
  16. return this->name;
  17. }
  18. int Character::getLevel()
  19. {
  20. return this->level;
  21. }
  22. int Character::getExperience()
  23. {
  24. return this->experience;
  25. }
  26. int Character::getMaxHP()
  27. {
  28. return this->maxHP;
  29. }
  30. int Character::getCurHP()
  31. {
  32. return this->curHP;
  33. }
  34. int Character::getMaxMP()
  35. {
  36. return this->maxMP;
  37. }
  38. int Character::getCurMP()
  39. {
  40. return this->curMP;
  41. }
  42. int Character::getAtk()
  43. {
  44. return this->atk;
  45. }
  46. int Character::getDef()
  47. {
  48. return this->def;
  49. }
  50. void Character::levelUp()
  51. {
  52. if ((this->level <= maxLevel) && this->readytoLevelUp())
  53. {
  54. this->level++;
  55. this->maxHP += 10;
  56. this->maxMP += 5;
  57. }
  58. this->curHP = this->maxHP;
  59. this->curMP = this->maxMP;
  60. }
  61. void Character::restoreHP(int n)
  62. {
  63. this->curHP += n;
  64. if (this->curHP > this->maxHP)
  65. {
  66. this->curHP = this->maxHP;
  67. }
  68. }
  69. void Character::restoreMP(int n)
  70. {
  71. this->curMP += n;
  72. if (this->curMP > this->maxMP)
  73. {
  74. this->curMP = this->maxMP;
  75. }
  76. }
  77. void Character::reduceHP(int n)
  78. {
  79. this->curHP -= n;
  80. }
  81. void Character::reduceMP(int n)
  82. {
  83. this->curMP -= n;
  84. }
  85. bool Character::isAlive()
  86. {
  87. return this->curHP > 0;
  88. }
  89. int Character::toNextLevel()
  90. {
  91. return (this->level <= maxLevel) ? ((this->level + 1) * (this->level + 1)) - this->getExperience() : 999999;
  92. }
  93. bool Character::readytoLevelUp()
  94. {
  95. return (this->toNextLevel() <= 0);
  96. }
  97. void Character::increaseExperience(int n)
  98. {
  99. this->experience += n;
  100. if (this->experience > maxEperience)
  101. {
  102. this->experience = maxEperience;
  103. }
  104. }
  105. bool Character::canCastSpell(Spell *s)
  106. {
  107. return this->curMP >= s->getCost();
  108. }
  109. void Character::castSpell(Spell *s, Character *t)
  110. {
  111. this->reduceMP(s->getCost());
  112. t->reduceHP(s->getAmount());
  113. }