GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/cashshoprecv.cpp Lines: 1 83 1.2 %
Date: 2018-09-20 Branches: 0 58 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "net/eathena/cashshoprecv.h"
22
23
#include "notifymanager.h"
24
25
#include "const/resources/currency.h"
26
27
#include "enums/resources/notifytypes.h"
28
29
#include "gui/windows/buydialog.h"
30
31
#include "gui/widgets/createwidget.h"
32
33
#include "net/messagein.h"
34
35
#include "net/eathena/npcrecv.h"
36
37
#include "resources/beinginfo.h"
38
39
#include "resources/db/npcdb.h"
40
41
#include "debug.h"
42
43
extern int packetVersion;
44
extern int itemIdLen;
45
46
namespace EAthena
47
{
48
49
namespace CashShopRecv
50
{
51
    BuyDialog *mBuyDialog;
52
}  // namespace CashShopRecv
53
54
void CashShopRecv::processCashShopOpen(Net::MessageIn &msg)
55
{
56
    int count;
57
    int blockSize = 11;
58
    if (itemIdLen == 4)
59
        blockSize += 2;
60
    if (packetVersion >= 20070711)
61
        count = (msg.readInt16("len") - 12) / blockSize;
62
    else
63
        count = (msg.readInt16("len") - 8) / blockSize;
64
65
    const BeingTypeId npcId = NpcRecv::mNpcTypeId;
66
    std::string currency;
67
68
    if (npcId != BeingTypeId_zero)
69
    {
70
        const BeingInfo *const info = NPCDB::get(npcId);
71
        if (info != nullptr)
72
            currency = info->getCurrency();
73
        else
74
            currency = DEFAULT_CURRENCY;
75
    }
76
    else
77
    {
78
        currency = DEFAULT_CURRENCY;
79
    }
80
    CREATEWIDGETV(mBuyDialog, BuyDialog,
81
        fromInt(BuyDialog::Cash, BeingId),
82
        currency);
83
    const int points = msg.readInt32("cash points");
84
85
    mBuyDialog->setMoney(points);
86
87
    if (packetVersion >= 20070711)
88
        msg.readInt32("kafra points");
89
    for (int f = 0; f < count; f ++)
90
    {
91
        msg.readInt32("price");
92
        const int value = msg.readInt32("discount price");
93
        const ItemTypeT type = static_cast<ItemTypeT>(
94
            msg.readUInt8("item type"));
95
        const int itemId = msg.readItemId("item id");
96
        const ItemColor color = ItemColor_one;
97
        mBuyDialog->addItem(itemId, type, color, 0, value);
98
    }
99
    mBuyDialog->sort();
100
}
101
102
void CashShopRecv::processCashShopBuyAck(Net::MessageIn &msg)
103
{
104
    msg.readInt32("cash points");
105
    if (packetVersion >= 20070711)
106
        msg.readInt32("kafra points");
107
    const uint16_t res = msg.readInt16("error");
108
    switch (res)
109
    {
110
        case 0:
111
            NotifyManager::notify(NotifyTypes::BUY_DONE);
112
            break;
113
        case 1:
114
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NPC_NOT_FOUND);
115
            break;
116
        case 2:
117
            NotifyManager::notify(NotifyTypes::BUY_FAILED_SYSTEM_ERROR);
118
            break;
119
        case 3:
120
            NotifyManager::notify(NotifyTypes::BUY_FAILED_OVERWEIGHT);
121
            break;
122
        case 4:
123
            NotifyManager::notify(NotifyTypes::BUY_TRADE_FAILED);
124
            break;
125
        case 5:
126
            NotifyManager::notify(NotifyTypes::BUY_FAILED_WRONG_ITEM);
127
            break;
128
        case 6:
129
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NO_MONEY);
130
            break;
131
        default:
132
            UNIMPLEMENTEDPACKETFIELD(res);
133
            break;
134
    }
135
}
136
137
void CashShopRecv::processCashShopPoints(Net::MessageIn &msg)
138
{
139
    UNIMPLEMENTEDPACKET;
140
    msg.readInt32("cash points");
141
    msg.readInt32("kafra points");
142
}
143
144
void CashShopRecv::processCashShopBuy(Net::MessageIn &msg)
145
{
146
    UNIMPLEMENTEDPACKET;
147
    msg.readInt32("id");
148
    msg.readInt16("result");
149
    msg.readInt32("cash points");
150
    msg.readInt32("kafra points");
151
}
152
153
void CashShopRecv::processCashShopTabPriceList(Net::MessageIn &msg)
154
{
155
    UNIMPLEMENTEDPACKET;
156
    const int count = (msg.readInt16("len") - 10) / 6;
157
    msg.readInt32("tab");
158
    const int itemsCount = msg.readInt16("count");
159
    if (count != itemsCount)
160
        logger->log("error: wrong list count");
161
162
    for (int f = 0; f < count; f ++)
163
    {
164
        msg.readInt16("item id");  // item id size always 16 bit
165
        msg.readInt32("price");
166
    }
167
}
168
169
void CashShopRecv::processCashShopSchedule(Net::MessageIn &msg)
170
{
171
    UNIMPLEMENTEDPACKET;
172
    int blockSize = 6;
173
    if (itemIdLen == 4)
174
        blockSize += 2;
175
    const int count = (msg.readInt16("len") - 8) / blockSize;
176
    const int itemsCount = msg.readInt16("count");
177
    msg.readInt16("tab");
178
    if (count != itemsCount)
179
        logger->log("error: wrong list count");
180
181
    for (int f = 0; f < count; f ++)
182
    {
183
        msg.readItemId("item id");
184
        msg.readInt32("price");
185
    }
186
}
187
188
2
}  // namespace EAthena