/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Character.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/19 16:40:56 by bchanot #+# #+# */ /* Updated: 2025/12/26 01:10:15 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "Character.hpp" #include "AMateria.hpp" /* ** ------------------------------- CONSTRUCTOR -------------------------------- */ Character::Character() : _name("Noname") { for (int i = 0; i < 4; i++) this->_items[i] = NULL; } Character::Character( std::string const & name ) : _name(name) { for (int i = 0; i < 4; i++) this->_items[i] = NULL; } Character::Character( const Character & src ) : _name(src._name) { for (int i = 0; i < 4; i++) this->_items[i] = src._items[i]->clone(); } /* ** -------------------------------- DESTRUCTOR -------------------------------- */ Character::~Character() { for (int i = 0; i < 4; i++) this->unequip(i); } /* ** --------------------------------- OVERLOAD --------------------------------- */ Character & Character::operator=( Character const & rhs ) { if ( this != &rhs ) { this->_name = rhs._name; for (int i = 0; i < 4; i++) { this->unequip(i); this->_items[i] = rhs._items[i]->clone(); } } return *this; } std::ostream & operator<<( std::ostream & o, Character const & i ) { o << i.getName(); return o; } /* ** --------------------------------- METHODS ---------------------------------- */ void Character::equip(AMateria* m) { if (m) { for (int i = 0; i < 4; i++) { if (!this->_items[i]) { this->_items[i] = m; return ; } } } } void Character::unequip(int idx) { if (this->_items[idx]) { // delete this->_items[idx]; this->_items[idx] = NULL; } } void Character::use(int idx, ICharacter& target) { if (this->_items[idx]) { this->_items[idx]->use(target); } } /* ** --------------------------------- ACCESSOR --------------------------------- */ std::string const & Character::getName() const { return this->_name; } /* ************************************************************************** */