ManaPlus
Public Member Functions | Private Attributes
BeingEquipBackend Class Reference

#include <beingequipbackend.h>

Inheritance diagram for BeingEquipBackend:
Equipment::Backend

Public Member Functions

 BeingEquipBackend (Being *const being)
 
 ~BeingEquipBackend ()
 
const ItemgetEquipment (const int index) const
 
void clear ()
 
void setEquipment (const int index, const Item *const item)
 
- Public Member Functions inherited from Equipment::Backend
 Backend ()
 
virtual ~Backend ()
 

Private Attributes

const ItemmEquipment [EQUIPMENT_SIZE]
 

Detailed Description

Definition at line 33 of file beingequipbackend.h.

Constructor & Destructor Documentation

◆ BeingEquipBackend()

BeingEquipBackend::BeingEquipBackend ( Being *const  being)
explicit

Definition at line 34 of file beingequipbackend.cpp.

34  :
36  mEquipment()
37 {
38  memset(mEquipment, 0, sizeof(mEquipment));
39  if (being != nullptr)
40  {
41  const size_t sz = being->mSprites.size();
42 
43  for (size_t f = 0; f < sz; f ++)
44  {
45  const int idx = inventoryHandler->
46  convertFromServerSlot(CAST_S32(f));
47  const BeingSlot &slot = being->mSlots[f];
48  const int id = slot.spriteId;
49  if (id > 0 && idx >= 0 && idx < EQUIPMENT_SIZE)
50  {
51  Item *const item = new Item(id,
53  1,
54  0,
55  slot.colorId,
61  const CardsList &cards = slot.cardsId;
62  if (!cards.isEmpty())
63  item->setCards(&cards.cards[0], maxCards);
64  mEquipment[idx] = item;
65  }
66  }
67  }
68 }
#define maxCards
Definition: cards.h:25
#define CAST_S32
Definition: cast.h:30
const Item * mEquipment[EQUIPMENT_SIZE]
std::vector< BeingSlot > mSlots
Definition: being.h:1206
std::vector< Sprite * > mSprites
Definition: item.h:50
void setCards(const int *const cards, const int size)
Definition: item.cpp:166
static const int EQUIPMENT_SIZE
Definition: equipment.h:29
const bool Damaged_false
Definition: damaged.h:30
const bool Equipm_true
Definition: equipm.h:30
const bool Equipped_true
Definition: equipped.h:30
const bool Favorite_false
Definition: favorite.h:30
const bool Identified_true
Definition: identified.h:30
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
@ Unknown
Definition: itemtype.h:30
int spriteId
Definition: beingslot.h:45
ItemColor colorId
Definition: beingslot.h:47
CardsList cardsId
Definition: beingslot.h:46
int cards[4]
Definition: cardslist.h:68
bool isEmpty() const
Definition: cardslist.h:60

References CardsList::cards, BeingSlot::cardsId, CAST_S32, BeingSlot::colorId, Damaged_false, Equipm_true, EQUIPMENT_SIZE, Equipped_true, Favorite_false, Identified_true, inventoryHandler, CardsList::isEmpty(), MailMessageType::Item, maxCards, mEquipment, Being::mSlots, CompoundSprite::mSprites, Item::setCards(), BeingSlot::spriteId, and ItemType::Unknown.

◆ ~BeingEquipBackend()

BeingEquipBackend::~BeingEquipBackend ( )

Definition at line 70 of file beingequipbackend.cpp.

71 {
72  for (int i = 0; i < EQUIPMENT_SIZE; i++)
74 }
#define delete2(var)
Definition: delete2.h:25

References delete2, EQUIPMENT_SIZE, and mEquipment.

Member Function Documentation

◆ clear()

void BeingEquipBackend::clear ( )
virtual

Implements Equipment::Backend.

Definition at line 76 of file beingequipbackend.cpp.

77 {
78  for (int i = 0; i < EQUIPMENT_SIZE; i++)
80 }

References delete2, EQUIPMENT_SIZE, and mEquipment.

◆ getEquipment()

const Item * BeingEquipBackend::getEquipment ( const int  index) const
virtual

Implements Equipment::Backend.

Definition at line 88 of file beingequipbackend.cpp.

89 {
90  if (index < 0 || index >= EQUIPMENT_SIZE)
91  return nullptr;
92  return mEquipment[index];
93 }

References EQUIPMENT_SIZE, and mEquipment.

◆ setEquipment()

void BeingEquipBackend::setEquipment ( const int  index,
const Item *const  item 
)

Definition at line 82 of file beingequipbackend.cpp.

84 {
85  mEquipment[index] = item;
86 }

References mEquipment.

Field Documentation

◆ mEquipment

const Item* BeingEquipBackend::mEquipment[EQUIPMENT_SIZE]
private

The documentation for this class was generated from the following files: