34 LOG_INFO(
"Character constructor called for " + this->name);
35 for (
int i = 0; i < 4; ++i)
36 this->inventory[i] = NULL;
47 LOG_INFO(
"Character copy constructor called for " + this->name);
48 for (
int i = 0; i < 4; ++i)
49 this->inventory[i] = NULL;
50 for (
int i = 0; i < 4; ++i) {
51 if (other.inventory[i])
65 LOG_INFO(
"Character copy assignment operator called for " + other.name);
67 this->name = other.name;
69 for (
int i = 0; i < 4; ++i) {
70 if (this->inventory[i])
71 delete this->inventory[i];
72 this->inventory[i] = NULL;
75 for (
int i = 0; i < 4; ++i) {
76 if (other.inventory[i])
89 LOG_INFO(
"Character destructor called for " + this->name);
90 for (
int i = 0; i < 4; ++i) {
91 if (this->inventory[i])
92 delete this->inventory[i];
111 for (
int i = 0; i < 4; ++i) {
112 if (!this->inventory[i]) {
113 this->inventory[i] = m;
114 oss << this->name <<
" equipped " << m->
getType() <<
" at slot " << i;
120 oss << this->name <<
"'s inventory is full, cannot equip " << m->
getType();
133 if (idx >= 0 && idx < 4 && this->inventory[idx]) {
134 oss << this->name <<
" unequips " << this->inventory[idx]->
getType() <<
" from slot " << idx;
135 this->inventory[idx] = NULL;
137 oss << this->name <<
" tried to unequip from invalid slot " << idx;
150 if (idx >= 0 && idx < 4 && this->inventory[idx]) {
151 this->inventory[idx]->
use(target);
153 oss << this->name <<
" tried to use invalid slot " << idx;
176 if (idx >= 0 && idx < 4) {
177 return this->inventory[idx];
Declares the AMateria abstract base class.
Declares the Character class.
Defines the Logger class for console-based logging.
#define LOG_INFO(msg)
Macro for logging informational messages.
Represents an abstract base class for all magical materias.
virtual AMateria * clone() const =0
std::string const & getType() const
Gets the type of the materia.
virtual void use(ICharacter &target)
Uses the materia on a target character. This is a virtual function with a base implementation that pr...
Represents a character capable of equipping and using Materias.
Character & operator=(const Character &other)
Copy assignment operator for Character. Assigns values from another Character object,...
bool isMateriaEquipped(int idx) const
Checks if a Materia is equipped at a specific inventory slot.
void unequip(int idx)
Unequips a Materia from a specific inventory slot. The Materia object itself is NOT deleted,...
virtual ~Character()
Destroys the Character object. Deallocates all dynamically allocated Materia objects currently in the...
Character(std::string const &name)
Constructs a Character object with a given name. Initializes the character's name and sets all invent...
AMateria * getMateriaAtSlot(int idx) const
Gets a pointer to the Materia at a specific inventory slot.
void use(int idx, ICharacter &target)
Uses the Materia at a specific inventory slot on a target character. Performs bounds checking and che...
std::string const & getName() const
Gets the name of the character.
void equip(AMateria *m)
Equips a Materia into the first available inventory slot (0-3). If the inventory is full,...
An interface for any character that can interact with Materias.