depotchest.cpp

main 83 lines · 2.3 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include "otpch.h"
21
22#include "depotchest.h"
23#include "tools.h"
24
25DepotChest::DepotChest(uint16_t type) :
26 Container(type), maxDepotItems(1500) {}
27
28ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t count,
29 uint32_t flags, Creature* actor/* = nullptr*/) const
30{
31 const Item* item = thing.getItem();
32 if (item == nullptr) {
33 return RETURNVALUE_NOTPOSSIBLE;
34 }
35
36 bool skipLimit = hasBitSet(FLAG_NOLIMIT, flags);
37 if (!skipLimit) {
38 int32_t addCount = 0;
39
40 if ((item->isStackable() && item->getItemCount() != count)) {
41 addCount = 1;
42 }
43
44 if (item->getTopParent() != this) {
45 if (const Container* container = item->getContainer()) {
46 addCount = container->getItemHoldingCount() + 1;
47 } else {
48 addCount = 1;
49 }
50 }
51
52 if (getItemHoldingCount() + addCount > maxDepotItems) {
53 return RETURNVALUE_DEPOTISFULL;
54 }
55 }
56
57 return Container::queryAdd(index, thing, count, flags, actor);
58}
59
60void DepotChest::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
61{
62 Cylinder* parent = getParent();
63 if (parent != nullptr) {
64 parent->postAddNotification(thing, oldParent, index, LINK_PARENT);
65 }
66}
67
68void DepotChest::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
69{
70 Cylinder* parent = getParent();
71 if (parent != nullptr) {
72 parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
73 }
74}
75
76Cylinder* DepotChest::getParent() const
77{
78 if (parent) {
79 return parent->getParent();
80 }
81 return nullptr;
82}
83
Top