| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* Character.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* 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;
- }
- /* ************************************************************************** */
|