Character.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Character.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/19 16:40:56 by bchanot #+# #+# */
  9. /* Updated: 2025/12/20 04:06:23 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Character.hpp"
  13. /*
  14. ** ------------------------------- CONSTRUCTOR --------------------------------
  15. */
  16. Character::Character() : _name("Noname")
  17. {
  18. for (int i = 0; i < 4; i++)
  19. this->_items[i] = NULL;
  20. }
  21. Character::Character( const Character & src ) : _name(src._name)
  22. {
  23. for (int i = 0; i < 4; i++)
  24. this->_items[i] = src._items[i]->clone();
  25. }
  26. /*
  27. ** -------------------------------- DESTRUCTOR --------------------------------
  28. */
  29. Character::~Character()
  30. {
  31. }
  32. /*
  33. ** --------------------------------- OVERLOAD ---------------------------------
  34. */
  35. Character & Character::operator=( Character const & rhs )
  36. {
  37. if ( this != &rhs )
  38. {
  39. for (int i = 0; i < 4; i++)
  40. this->_items[i] = rhs._items[i]->clone();
  41. }
  42. return *this;
  43. }
  44. std::ostream & operator<<( std::ostream & o, Character const & i )
  45. {
  46. o << i.getName();
  47. return o;
  48. }
  49. /*
  50. ** --------------------------------- METHODS ----------------------------------
  51. */
  52. void Character::equip(AMateria* m) {
  53. for (int i = 0; i < 4; i++)
  54. if (!this->_items[i]) {
  55. this->_items[i] = m;
  56. }
  57. }
  58. void Character::unequip(int idx) {
  59. if (this->_items[idx]) {
  60. delete this->_items[idx];
  61. this->_items[idx] = NULL;
  62. }
  63. }
  64. void Character::use(int idx, ICharacter& target) {
  65. if (this->_items[idx]) {
  66. this->_items[idx]->AMateria::use(target);
  67. }
  68. }
  69. /*
  70. ** --------------------------------- ACCESSOR ---------------------------------
  71. */
  72. std::string const & Character::getName() const {
  73. return this->_name;
  74. }
  75. /* ************************************************************************** */