#include "Character.hpp" #include Character::Character(char *n, int l, int e, int h, int m, int a, int d) { this->level = l; this->experience = e; this->maxHP = h; this->curHP = maxHP; this->maxMP = m; this->curMP = maxMP; this->atk = a; this->def = d; strcpy(this->name, n); this->name[15] = 0; } Character::Character(const char *n, int l, int e, int h, int m, int a, int d) { this->level = l; this->experience = e; this->maxHP = h; this->curHP = maxHP; this->maxMP = m; this->curMP = maxMP; this->atk = a; this->def = d; strcpy(this->name, n); } char *Character::getName() { return this->name; } int Character::getLevel() { return this->level; } int Character::getExperience() { return this->experience; } int Character::getMaxHP() { return this->maxHP; } int Character::getCurHP() { return this->curHP; } int Character::getMaxMP() { return this->maxMP; } int Character::getCurMP() { return this->curMP; } int Character::getAtk() { return this->atk; } int Character::getDef() { return this->def; } void Character::levelUp() { if ((this->level <= maxLevel) && this->readytoLevelUp()) { this->experience -= this->toNextLevel(); this->level++; this->maxHP += 10; this->maxMP += 5; this->curHP = this->maxHP; this->curMP = this->maxMP; } } void Character::restoreHP(int n) { this->curHP += n; if (this->curHP > this->maxHP) { this->curHP = this->maxHP; } } void Character::restoreMP(int n) { this->curMP += n; if (this->curMP > this->maxMP) { this->curMP = this->maxMP; } } void Character::reduceHP(int n) { this->curHP -= n; } void Character::reduceMP(int n) { this->curMP -= n; } bool Character::isAlive() { return this->curHP > 0; } int Character::toNextLevel() { return (this->level + 1) * (this->level + 1); } bool Character::readytoLevelUp() { return (this->toNextLevel() <= this->experience); } void Character::increaseExperience(int n) { this->experience += n; if (this->experience > maxEperience) { this->experience = maxEperience; } while (this->readytoLevelUp()) { this->levelUp(); } } bool Character::canCastSpell(Spell *s) { return this->curMP >= s->getCost(); } void Character::castSpell(Spell *s, Character *t) { this->reduceMP(s->getCost()); t->reduceHP(s->getAmount()); } void Character::rest() { this->curHP = this->maxHP; this->curMP = this->maxMP; } void Character::kill() { this->curHP = 0; } void Character::revive() { if (this->curHP <= 0) { this->curHP = 1; } }