GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/cashshoprecv.cpp Lines: 1 84 1.2 %
Date: 2017-11-29 Branches: 2 58 3.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  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
45
namespace EAthena
46
{
47
48
namespace CashShopRecv
49
{
50
    BuyDialog *mBuyDialog;
51
}  // namespace CashShopRecv
52
53
void CashShopRecv::processCashShopOpen(Net::MessageIn &msg)
54
{
55
    int count;
56
    if (packetVersion >= 20070711)
57
        count = (msg.readInt16("len") - 12) / 11;
58
    else
59
        count = (msg.readInt16("len") - 8) / 11;
60
61
    const BeingTypeId npcId = NpcRecv::mNpcTypeId;
62
    std::string currency;
63
64
    if (npcId != BeingTypeId_zero)
65
    {
66
        const BeingInfo *const info = NPCDB::get(npcId);
67
        if (info != nullptr)
68
            currency = info->getCurrency();
69
        else
70
            currency = DEFAULT_CURRENCY;
71
    }
72
    else
73
    {
74
        currency = DEFAULT_CURRENCY;
75
    }
76
    CREATEWIDGETV(mBuyDialog, BuyDialog,
77
        fromInt(BuyDialog::Cash, BeingId),
78
        currency);
79
    const int points = msg.readInt32("cash points");
80
81
    mBuyDialog->setMoney(points);
82
83
    if (packetVersion >= 20070711)
84
        msg.readInt32("kafra points");
85
    for (int f = 0; f < count; f ++)
86
    {
87
        msg.readInt32("price");
88
        const int value = msg.readInt32("discount price");
89
        const ItemTypeT type = static_cast<ItemTypeT>(
90
            msg.readUInt8("item type"));
91
        const int itemId = msg.readInt16("item id");
92
        const ItemColor color = ItemColor_one;
93
        mBuyDialog->addItem(itemId, type, color, 0, value);
94
    }
95
    mBuyDialog->sort();
96
}
97
98
void CashShopRecv::processCashShopBuyAck(Net::MessageIn &msg)
99
{
100
    msg.readInt32("cash points");
101
    if (packetVersion >= 20070711)
102
        msg.readInt32("kafra points");
103
    const uint16_t res = msg.readInt16("error");
104
    switch (res)
105
    {
106
        case 0:
107
            NotifyManager::notify(NotifyTypes::BUY_DONE);
108
            break;
109
        case 1:
110
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NPC_NOT_FOUND);
111
            break;
112
        case 2:
113
            NotifyManager::notify(NotifyTypes::BUY_FAILED_SYSTEM_ERROR);
114
            break;
115
        case 3:
116
            NotifyManager::notify(NotifyTypes::BUY_FAILED_OVERWEIGHT);
117
            break;
118
        case 4:
119
            NotifyManager::notify(NotifyTypes::BUY_TRADE_FAILED);
120
            break;
121
        case 5:
122
            NotifyManager::notify(NotifyTypes::BUY_FAILED_WRONG_ITEM);
123
            break;
124
        case 6:
125
            NotifyManager::notify(NotifyTypes::BUY_FAILED_NO_MONEY);
126
            break;
127
        default:
128
            UNIMPLEMENTEDPACKETFIELD(res);
129
            break;
130
    }
131
}
132
133
void CashShopRecv::processCashShopPoints(Net::MessageIn &msg)
134
{
135
    UNIMPLEMENTEDPACKET;
136
    msg.readInt32("cash points");
137
    msg.readInt32("kafra points");
138
}
139
140
void CashShopRecv::processCashShopBuy(Net::MessageIn &msg)
141
{
142
    UNIMPLEMENTEDPACKET;
143
    msg.readInt32("id");
144
    msg.readInt16("result");
145
    msg.readInt32("cash points");
146
    msg.readInt32("kafra points");
147
}
148
149
void CashShopRecv::processCashShopTabPriceList(Net::MessageIn &msg)
150
{
151
    UNIMPLEMENTEDPACKET;
152
    const int count = (msg.readInt16("len") - 10) / 6;
153
    msg.readInt32("tab");
154
    const int itemsCount = msg.readInt16("count");
155
    if (count != itemsCount)
156
        logger->log("error: wrong list count");
157
158
    for (int f = 0; f < count; f ++)
159
    {
160
        msg.readInt16("item id");
161
        msg.readInt32("price");
162
    }
163
}
164
165
void CashShopRecv::processCashShopSchedule(Net::MessageIn &msg)
166
{
167
    UNIMPLEMENTEDPACKET;
168
    const int count = (msg.readInt16("len") - 8) / 6;
169
    const int itemsCount = msg.readInt16("count");
170
    msg.readInt16("tab");
171
    if (count != itemsCount)
172
        logger->log("error: wrong list count");
173
174
    for (int f = 0; f < count; f ++)
175
    {
176
        msg.readInt16("item id");
177
        msg.readInt32("price");
178
    }
179
}
180
181

6
}  // namespace EAthena