/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* MateriaSource.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/24 15:47:01 by bchanot #+# #+# */ /* Updated: 2025/12/24 15:49:20 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "MateriaSource.hpp" #include /* ** ------------------------------- CONSTRUCTOR -------------------------------- */ MateriaSource::MateriaSource() { for (int i = 0; i < 4; i++) this->_items[i] = NULL; } MateriaSource::MateriaSource( const MateriaSource & src ) { for (int i = 0; i < 4; i++) this->_items[i] = src._items[i]->clone(); } /* ** -------------------------------- DESTRUCTOR -------------------------------- */ MateriaSource::~MateriaSource() { } /* ** --------------------------------- OVERLOAD --------------------------------- */ MateriaSource & MateriaSource::operator=( MateriaSource const & rhs ) { if ( this != &rhs ) { for (int i = 0; i < 4; i++) { this->_items[i] = rhs._items[i]->clone(); } } return *this; } std::ostream & operator<<( std::ostream & o, MateriaSource const & i ) { (void)i; //o << "Value = " << i.getValue(); return o; } /* ** --------------------------------- METHODS ---------------------------------- */ void MateriaSource::learnMateria(AMateria* source) { if (source) { for (int i = 0; i < 4; i++) { if (!this->_items[i]) { this->_items[i] = source->clone(); return ; } } } } AMateria* MateriaSource::createMateria(std::string const & type){ for (int i = 0; i < 4; i++) { if (this->_items[i] && !type.compare(this->_items[i]->getType())) { return this->_items[i]->clone(); } } return NULL; } /* ** --------------------------------- ACCESSOR --------------------------------- */ /* ************************************************************************** */