Mana
Loading...
Searching...
No Matches
inventoryhandler.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana 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#pragma once
23
24#include "eventlistener.h"
25
27
29
30#include "utils/xml.h"
31
32#include <map>
33#include <vector>
34
35namespace ManaServ {
36
37class EquipBackend final : public Equipment::Backend, public EventListener
38{
39 public:
41
42 Item *getEquipment(int slotIndex) const override;
43 std::string getSlotName(int slotIndex) const override;
44 void clear() override;
45
46 void equip(int inventorySlot, int equipmentSlot);
47 void unequip(int inventorySlot);
48
49 void event(Event::Channel channel, const Event &event) override;
50
51 int getSlotNumber() const override
52 { return mSlots.size(); }
53
54 unsigned int getVisibleSlotsNumber() const
55 { return mVisibleSlots; }
56
57 void triggerUnequip(int slotIndex) const override;
58
59 bool isWeaponSlot(int slotTypeId) const;
60 bool isAmmoSlot(int slotTypeId) const;
61
62 Position getBoxPosition(unsigned int slotIndex) const;
63
64 const std::string &getBoxIcon(unsigned int slotIndex) const;
65
66 private:
67 void readEquipFile() override;
68
69 void readBoxNode(XML::Node slotNode);
70
71 struct Slot {
72 // Generic info
73 std::string name;
74
76
77 // Manaserv specific info
78
79 // Used to know which (server-side) slot id it is.
80 unsigned int slotTypeId = 0;
81 // Static part
82 // The sub id is used to know in which order the slots are
83 // when the slotType has more than one slot capacity:
84 // I.e.: capacity = 6, subId will be between 1 and 6
85 // for each slots in the map.
86 // This is used to sort the multimap along with the slot id.
87 unsigned int subId = 0;
88
89 // Tell whether the slot is a weapon slot
90 bool weaponSlot = false;
91
92 // Tell whether the slot is an ammo slot
93 bool ammoSlot = false;
94 };
95
96 unsigned int mVisibleSlots;
97
98 // slot client index, slot info
99 std::map<unsigned int, Slot> mSlots;
100 std::vector<Position> mBoxPositions;
101 std::vector<std::string> mBoxIcons;
102};
103
105 public EventListener
106{
107 public:
109
110 void handleMessage(MessageIn &msg) override;
111
112 void event(Event::Channel channel, const Event &event) override;
113
114 size_t getSize(int type) const override;
115
116 bool isWeaponSlot(unsigned int slotTypeId) const override
117 { return mEquipBackend.isWeaponSlot(slotTypeId); }
118
119 bool isAmmoSlot(unsigned int slotTypeId) const override
120 { return mEquipBackend.isAmmoSlot(slotTypeId); }
121
122 unsigned int getVisibleSlotsNumber() const override
124
127
128 Position getBoxPosition(unsigned int slotIndex) const override
129 { return mEquipBackend.getBoxPosition(slotIndex); }
130
131 const std::string& getBoxIcon(unsigned int slotIndex) const override
132 { return mEquipBackend.getBoxIcon(slotIndex); }
133
134 private:
136};
137
138} // namespace ManaServ
Definition event.h:42
Channel
Definition event.h:45
Represents one or more instances of a certain item type.
Definition item.h:35
std::string getSlotName(int slotIndex) const override
int getSlotNumber() const override
Position getBoxPosition(unsigned int slotIndex) const
void event(Event::Channel channel, const Event &event) override
std::map< unsigned int, Slot > mSlots
bool isWeaponSlot(int slotTypeId) const
unsigned int getVisibleSlotsNumber() const
std::vector< std::string > mBoxIcons
std::vector< Position > mBoxPositions
void unequip(int inventorySlot)
const std::string & getBoxIcon(unsigned int slotIndex) const
void equip(int inventorySlot, int equipmentSlot)
void readBoxNode(XML::Node slotNode)
bool isAmmoSlot(int slotTypeId) const
Item * getEquipment(int slotIndex) const override
void triggerUnequip(int slotIndex) const override
size_t getSize(int type) const override
const std::string & getBoxIcon(unsigned int slotIndex) const override
Equipment::Backend * getEquipmentBackend() override
unsigned int getVisibleSlotsNumber() const override
bool isAmmoSlot(unsigned int slotTypeId) const override
bool isWeaponSlot(unsigned int slotTypeId) const override
Position getBoxPosition(unsigned int slotIndex) const override
void event(Event::Channel channel, const Event &event) override
void handleMessage(MessageIn &msg) override
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
A position along a being's path.
Definition position.h:31