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