ManaPlus
beingequipbackend.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "beingequipbackend.h"
23 
24 #include "being/being.h"
25 
26 #include "net/inventoryhandler.h"
27 
28 #include "resources/item/item.h"
29 
30 #include "utils/delete2.h"
31 
32 #include "debug.h"
33 
35  Equipment::Backend(),
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 }
69 
71 {
72  for (int i = 0; i < EQUIPMENT_SIZE; i++)
74 }
75 
77 {
78  for (int i = 0; i < EQUIPMENT_SIZE; i++)
80 }
81 
82 void BeingEquipBackend::setEquipment(const int index,
83  const Item *const item)
84 {
85  mEquipment[index] = item;
86 }
87 
88 const Item *BeingEquipBackend::getEquipment(const int index) const
89 {
90  if (index < 0 || index >= EQUIPMENT_SIZE)
91  return nullptr;
92  return mEquipment[index];
93 }
#define maxCards
Definition: cards.h:25
#define CAST_S32
Definition: cast.h:30
const Item * mEquipment[EQUIPMENT_SIZE]
void setEquipment(const int index, const Item *const item)
const Item * getEquipment(const int index) const
BeingEquipBackend(Being *const being)
Definition: being.h:96
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
#define delete2(var)
Definition: delete2.h:25
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
Equipment * mEquipment
Definition: playerinfo.cpp:65
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