GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/itemrecv.cpp Lines: 0 71 0.0 %
Date: 2018-11-12 Branches: 0 22 0.0 %

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-2018  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/eathena/itemrecv.h"
24
25
#include "actormanager.h"
26
#include "itemcolormanager.h"
27
#include "logger.h"
28
29
#include "const/resources/item/cards.h"
30
31
#include "net/messagein.h"
32
33
#include "debug.h"
34
35
extern int packetVersion;
36
extern bool packets_zero;
37
38
namespace EAthena
39
{
40
41
void ItemRecv::processItemDropped(Net::MessageIn &msg)
42
{
43
    const BeingId id = msg.readBeingId("id");
44
    const int itemId = msg.readItemId("item id");
45
    ItemTypeT itemType = ItemType::Unknown;
46
    if (msg.getVersion() >= 20130000)
47
        itemType = static_cast<ItemTypeT>(msg.readInt16("type"));
48
    const Identified identified = fromInt(
49
        msg.readUInt8("identify"), Identified);
50
    const int x = msg.readInt16("x");
51
    const int y = msg.readInt16("y");
52
    const int subX = CAST_S32(msg.readInt8("subx"));
53
    const int subY = CAST_S32(msg.readInt8("suby"));
54
    const int amount = msg.readInt16("count");
55
    if (packets_zero || packetVersion >= 20180418)
56
    {
57
        msg.readUInt8("show drop effect");
58
        msg.readInt16("show effect mode");
59
    }
60
61
    if (actorManager != nullptr)
62
    {
63
        actorManager->createItem(id,
64
            itemId,
65
            x, y,
66
            itemType,
67
            amount,
68
            0,
69
            ItemColor_one,
70
            identified,
71
            Damaged_false,
72
            subX, subY,
73
            nullptr);
74
    }
75
}
76
77
void ItemRecv::processItemDropped2(Net::MessageIn &msg)
78
{
79
    const BeingId id = msg.readBeingId("id");
80
    const int itemId = msg.readInt16("item id");  // +++ need use int32
81
    const ItemTypeT itemType = static_cast<ItemTypeT>(msg.readUInt8("type"));
82
    const Identified identified = fromInt(
83
        msg.readUInt8("identify"), Identified);
84
    const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
85
    const uint8_t refine = msg.readUInt8("refine");
86
    int cards[maxCards];
87
    for (int f = 0; f < maxCards; f++)
88
        cards[f] = msg.readUInt16("card");  // ++ need use int32
89
    const int x = msg.readInt16("x");
90
    const int y = msg.readInt16("y");
91
    const int amount = msg.readInt16("amount");
92
    const int subX = CAST_S32(msg.readInt8("subx"));
93
    const int subY = CAST_S32(msg.readInt8("suby"));
94
    // +++ probably need add drop effect fields?
95
96
    if (actorManager != nullptr)
97
    {
98
        actorManager->createItem(id,
99
            itemId,
100
            x, y,
101
            itemType,
102
            amount,
103
            refine,
104
            ItemColorManager::getColorFromCards(&cards[0]),
105
            identified,
106
            damaged,
107
            subX, subY,
108
            &cards[0]);
109
    }
110
}
111
112
void ItemRecv::processItemMvpDropped(Net::MessageIn &msg)
113
{
114
    UNIMPLEMENTEDPACKET;
115
    msg.readInt16("len");
116
    msg.readUInt8("type");
117
    msg.readItemId("item id");
118
    msg.readUInt8("len");
119
    msg.readString(24, "name");
120
    msg.readUInt8("monster name len");
121
    msg.readString(24, "monster name");
122
}
123
124
void ItemRecv::processItemVisible(Net::MessageIn &msg)
125
{
126
    const BeingId id = msg.readBeingId("item object id");
127
    const int itemId = msg.readItemId("item id");
128
    const Identified identified = fromInt(
129
        msg.readUInt8("identify"), Identified);
130
    const int x = msg.readInt16("x");
131
    const int y = msg.readInt16("y");
132
    const int amount = msg.readInt16("amount");
133
    const int subX = CAST_S32(msg.readInt8("sub x"));
134
    const int subY = CAST_S32(msg.readInt8("sub y"));
135
136
    if (actorManager != nullptr)
137
    {
138
        actorManager->createItem(id,
139
            itemId,
140
            x, y,
141
            ItemType::Unknown,
142
            amount,
143
            0,
144
            ItemColor_one,
145
            identified,
146
            Damaged_false,
147
            subX, subY,
148
            nullptr);
149
    }
150
}
151
152
void ItemRecv::processItemVisible2(Net::MessageIn &msg)
153
{
154
    const BeingId id = msg.readBeingId("item object id");
155
    const int itemId = msg.readInt16("item id");  // +++ need use int32
156
    const ItemTypeT itemType = static_cast<ItemTypeT>(
157
        msg.readUInt8("type"));
158
    const Identified identified = fromInt(
159
        msg.readUInt8("identify"), Identified);
160
    const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
161
    const uint8_t refine = msg.readUInt8("refine");
162
    int cards[maxCards];
163
    for (int f = 0; f < maxCards; f++)
164
        cards[f] = msg.readUInt16("card");  // +++ need use int32
165
    const int x = msg.readInt16("x");
166
    const int y = msg.readInt16("y");
167
    const int amount = msg.readInt16("amount");
168
    const int subX = CAST_S32(msg.readInt8("sub x"));
169
    const int subY = CAST_S32(msg.readInt8("sub y"));
170
171
    if (actorManager != nullptr)
172
    {
173
        actorManager->createItem(id,
174
            itemId,
175
            x, y,
176
            itemType,
177
            amount,
178
            refine,
179
            ItemColorManager::getColorFromCards(&cards[0]),
180
            identified,
181
            damaged,
182
            subX, subY,
183
            &cards[0]);
184
    }
185
}
186
187
}  // namespace EAthena