|
|
@@ -0,0 +1,97 @@
|
|
|
+/* ************************************************************************** */
|
|
|
+/* */
|
|
|
+/* ::: :::::::: */
|
|
|
+/* 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;
|
|
|
+}
|
|
|
+
|
|
|
+/* ************************************************************************** */
|