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 "trashholder.h"
23#include "game.h"
24
25extern Game g_game;
26
27ReturnValue TrashHolder::queryAdd(int32_t, const Thing&, uint32_t, uint32_t, Creature*) const
28{
29 return RETURNVALUE_NOERROR;
30}
31
32ReturnValue TrashHolder::queryMaxCount(int32_t, const Thing&, uint32_t count, uint32_t& maxQueryCount, uint32_t) const
33{
34 maxQueryCount = std::max<uint32_t>(1, count);
35 return RETURNVALUE_NOERROR;
36}
37
38ReturnValue TrashHolder::queryRemove(const Thing&, uint32_t, uint32_t) const
39{
40 return RETURNVALUE_NOTPOSSIBLE;
41}
42
43Cylinder* TrashHolder::queryDestination(int32_t&, const Thing&, Item**, uint32_t&)
44{
45 return this;
46}
47
48void TrashHolder::addThing(Thing* thing)
49{
50 return addThing(0, thing);
51}
52
53void TrashHolder::addThing(int32_t, Thing* thing)
54{
55 Item* item = thing->getItem();
56 if (!item) {
57 return;
58 }
59
60 if (item == this || !item->hasProperty(CONST_PROP_MOVEABLE)) {
61 return;
62 }
63
64 const ItemType& it = Item::items[id];
65 if (item->isHangable() && it.isGroundTile()) {
66 Tile* tile = dynamic_cast<Tile*>(getParent());
67 if (tile && tile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) {
68 return;
69 }
70 }
71
72 g_game.internalRemoveItem(item);
73
74 if (it.magicEffect != CONST_ME_NONE) {
75 g_game.addMagicEffect(getPosition(), it.magicEffect);
76 }
77}
78
79void TrashHolder::updateThing(Thing*, uint16_t, uint32_t)
80{
81 //
82}
83
84void TrashHolder::replaceThing(uint32_t, Thing*)
85{
86 //
87}
88
89void TrashHolder::removeThing(Thing*, uint32_t)
90{
91 //
92}
93
94void TrashHolder::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
95{
96 getParent()->postAddNotification(thing, oldParent, index, LINK_PARENT);
97}
98
99void TrashHolder::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
100{
101 getParent()->postRemoveNotification(thing, newParent, index, LINK_PARENT);
102}
103