GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/inventoryhandler.cpp Lines: 17 34 50.0 %
Date: 2021-03-17 Branches: 5 12 41.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "net/ea/inventoryhandler.h"
25
26
#include "net/ea/equipbackend.h"
27
#include "net/ea/inventoryrecv.h"
28
29
#include "utils/delete2.h"
30
31
#include "debug.h"
32
33
namespace Ea
34
{
35
36
77
InventoryHandler::InventoryHandler() :
37
154
    Net::InventoryHandler()
38
{
39
77
    InventoryRecv::mEquips.clear();
40
77
    InventoryRecv::mStorageItems.clear();
41
77
    InventoryRecv::mStorage = nullptr;
42
77
    storageWindow = nullptr;
43
77
    while (!InventoryRecv::mSentPickups.empty())
44
        InventoryRecv::mSentPickups.pop();
45
77
    InventoryRecv::mDebugInventory = true;
46
77
}
47
48
154
InventoryHandler::~InventoryHandler()
49
{
50
77
    if (storageWindow != nullptr)
51
    {
52
        storageWindow->close();
53
        storageWindow = nullptr;
54
    }
55
56
77
    delete2(InventoryRecv::mStorage)
57
77
}
58
59
77
void InventoryHandler::clear() const
60
{
61
77
    delete2(InventoryRecv::mStorage)
62
77
}
63
64
bool InventoryHandler::canSplit(const Item *const item A_UNUSED) const
65
{
66
    return false;
67
}
68
69
void InventoryHandler::splitItem(const Item *const item A_UNUSED,
70
                                 const int amount A_UNUSED) const
71
{
72
    // Not implemented for eAthena (possible?)
73
}
74
75
void InventoryHandler::moveItem(const int oldIndex A_UNUSED,
76
                                const int newIndex A_UNUSED) const
77
{
78
    // Not implemented for eAthena (possible?)
79
}
80
81
4
size_t InventoryHandler::getSize(const InventoryTypeT type) const
82
{
83
    switch (type)
84
    {
85
        case InventoryType::Inventory:
86
        case InventoryType::MailEdit:
87
            return 100;
88
        case InventoryType::Storage:
89
            return 0;  // Comes from server after items
90
        case InventoryType::Trade:
91
            return 12;
92
        case InventoryType::Npc:
93
        case InventoryType::Cart:
94
        case InventoryType::Vending:
95
        case InventoryType::Craft:
96
        case InventoryType::TypeEnd:
97
        case InventoryType::MailView:
98
        default:
99
            return 0;
100
    }
101
}
102
void InventoryHandler::destroyStorage() const
103
{
104
    BLOCK_START("InventoryHandler::closeStorage")
105
    if (storageWindow != nullptr)
106
    {
107
        InventoryWindow *const inv = storageWindow;
108
        storageWindow->close();
109
        inv->unsetInventory();
110
    }
111
    BLOCK_END("InventoryHandler::closeStorage")
112
}
113
114
void InventoryHandler::forgotStorage() const
115
{
116
    storageWindow = nullptr;
117
}
118
119
void InventoryHandler::pushPickup(const BeingId floorId)
120
{
121
    InventoryRecv::mSentPickups.push(floorId);
122
}
123
124
Inventory *InventoryHandler::getStorage() const
125
{
126
    return InventoryRecv::mStorage;
127
}
128
129
}  // namespace Ea