| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* Character.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2025/12/19 16:40:56 by bchanot #+# #+# */
- /* Updated: 2025/12/20 04:06:23 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "Character.hpp"
- /*
- ** ------------------------------- CONSTRUCTOR --------------------------------
- */
- Character::Character() : _name("Noname")
- {
- 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()
- {
- }
- /*
- ** --------------------------------- OVERLOAD ---------------------------------
- */
- Character & Character::operator=( Character 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, Character const & i )
- {
- o << i.getName();
- return o;
- }
- /*
- ** --------------------------------- METHODS ----------------------------------
- */
- void Character::equip(AMateria* m) {
- for (int i = 0; i < 4; i++)
- if (!this->_items[i]) {
- this->_items[i] = m;
- }
- }
- 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]->AMateria::use(target);
- }
- }
- /*
- ** --------------------------------- ACCESSOR ---------------------------------
- */
- std::string const & Character::getName() const {
- return this->_name;
- }
- /* ************************************************************************** */
|