container.h

main 81 lines · 2.8 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#ifndef CONTAINER_H
24#define CONTAINER_H
25
26#include "declarations.h"
27#include "item.h"
28
29#include <framework/luaengine/luaobject.h>
30
31// @bindclass
32class Container : public LuaObject
33{
34protected:
35 Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent, bool isUnlocked, bool hasPages, int containerSize, int firstIndex);
36
37public:
38 ItemPtr getItem(int slot);
39 std::deque<ItemPtr> getItems() { return m_items; }
40 int getItemsCount() { return m_items.size(); }
41 Position getSlotPosition(int slot) { return Position(0xffff, m_id | 0x40, slot); }
42 int getId() { return m_id; }
43 int getCapacity() { return m_capacity; }
44 ItemPtr getContainerItem() { return m_containerItem; }
45 std::string getName() { return m_name; }
46 bool hasParent() { return m_hasParent; }
47 bool isClosed() { return m_closed; }
48 bool isUnlocked() { return m_unlocked; }
49 bool hasPages() { return m_hasPages; }
50 int getSize() { return m_size; }
51 int getFirstIndex() { return m_firstIndex; }
52 ItemPtr findItemById(uint itemId, int subType);
53
54protected:
55 void onOpen(const ContainerPtr& previousContainer);
56 void onClose();
57 void onAddItem(const ItemPtr& item, int slot);
58 void onAddItems(const std::vector<ItemPtr>& items);
59 void onUpdateItem(int slot, const ItemPtr& item);
60 void onRemoveItem(int slot, const ItemPtr& lastItem);
61
62 friend class Game;
63
64private:
65 void updateItemsPositions();
66
67 int m_id;
68 int m_capacity;
69 ItemPtr m_containerItem;
70 std::string m_name;
71 bool m_hasParent;
72 bool m_closed;
73 bool m_unlocked;
74 bool m_hasPages;
75 int m_size;
76 int m_firstIndex;
77 std::deque<ItemPtr> m_items;
78};
79
80#endif
81
Top