|
@@ -6,11 +6,12 @@
|
|
|
/* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
|
|
/* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
/* Created: 2025/12/19 16:40:56 by bchanot #+# #+# */
|
|
/* Created: 2025/12/19 16:40:56 by bchanot #+# #+# */
|
|
|
-/* Updated: 2025/12/20 04:06:23 by bchanot ### ########.fr */
|
|
|
|
|
|
|
+/* Updated: 2025/12/26 01:10:15 by bchanot ### ########.fr */
|
|
|
/* */
|
|
/* */
|
|
|
/* ************************************************************************** */
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "Character.hpp"
|
|
#include "Character.hpp"
|
|
|
|
|
+#include "AMateria.hpp"
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
** ------------------------------- CONSTRUCTOR --------------------------------
|
|
** ------------------------------- CONSTRUCTOR --------------------------------
|
|
@@ -22,6 +23,12 @@ Character::Character() : _name("Noname")
|
|
|
this->_items[i] = NULL;
|
|
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)
|
|
Character::Character( const Character & src ) : _name(src._name)
|
|
|
{
|
|
{
|
|
|
for (int i = 0; i < 4; i++)
|
|
for (int i = 0; i < 4; i++)
|
|
@@ -35,6 +42,8 @@ Character::Character( const Character & src ) : _name(src._name)
|
|
|
|
|
|
|
|
Character::~Character()
|
|
Character::~Character()
|
|
|
{
|
|
{
|
|
|
|
|
+ for (int i = 0; i < 4; i++)
|
|
|
|
|
+ this->unequip(i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -47,8 +56,11 @@ Character & Character::operator=( Character const & rhs )
|
|
|
{
|
|
{
|
|
|
if ( this != &rhs )
|
|
if ( this != &rhs )
|
|
|
{
|
|
{
|
|
|
- for (int i = 0; i < 4; i++)
|
|
|
|
|
|
|
+ this->_name = rhs._name;
|
|
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
|
|
+ this->unequip(i);
|
|
|
this->_items[i] = rhs._items[i]->clone();
|
|
this->_items[i] = rhs._items[i]->clone();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
@@ -66,22 +78,26 @@ std::ostream & operator<<( std::ostream & o, Character const & i )
|
|
|
|
|
|
|
|
|
|
|
|
|
void Character::equip(AMateria* m) {
|
|
void Character::equip(AMateria* m) {
|
|
|
- for (int i = 0; i < 4; i++)
|
|
|
|
|
- if (!this->_items[i]) {
|
|
|
|
|
- this->_items[i] = m;
|
|
|
|
|
|
|
+ if (m) {
|
|
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
|
|
+ if (!this->_items[i]) {
|
|
|
|
|
+ this->_items[i] = m;
|
|
|
|
|
+ return ;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Character::unequip(int idx) {
|
|
void Character::unequip(int idx) {
|
|
|
if (this->_items[idx]) {
|
|
if (this->_items[idx]) {
|
|
|
- delete this->_items[idx];
|
|
|
|
|
|
|
+// delete this->_items[idx];
|
|
|
this->_items[idx] = NULL;
|
|
this->_items[idx] = NULL;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Character::use(int idx, ICharacter& target) {
|
|
void Character::use(int idx, ICharacter& target) {
|
|
|
if (this->_items[idx]) {
|
|
if (this->_items[idx]) {
|
|
|
- this->_items[idx]->AMateria::use(target);
|
|
|
|
|
|
|
+ this->_items[idx]->use(target);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|