GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/petrecv.cpp Lines: 0 82 0.0 %
Date: 2021-03-17 Branches: 0 45 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "net/eathena/petrecv.h"
23
24
#include "actormanager.h"
25
#include "notifymanager.h"
26
27
#include "being/petinfo.h"
28
#include "being/playerinfo.h"
29
30
#include "const/net/inventory.h"
31
32
#include "enums/resources/notifytypes.h"
33
34
#include "gui/windows/eggselectiondialog.h"
35
36
#include "gui/widgets/createwidget.h"
37
38
#include "net/inventoryhandler.h"
39
#include "net/messagein.h"
40
41
#include "net/eathena/menu.h"
42
43
#include "debug.h"
44
45
namespace EAthena
46
{
47
48
void PetRecv::processPetMessage(Net::MessageIn &msg)
49
{
50
    // techinally this is hercules pet emote,
51
    // but it may send also hungry level on connect
52
    // for both exists other packets.
53
    msg.readBeingId("pet id");
54
    msg.readInt32("param");
55
}
56
57
void PetRecv::processPetRoulette(Net::MessageIn &msg)
58
{
59
    const uint8_t data = msg.readUInt8("data");
60
    switch (data)
61
    {
62
        case 0:
63
            NotifyManager::notify(NotifyTypes::PET_CATCH_FAILED);
64
            break;
65
        case 1:
66
            NotifyManager::notify(NotifyTypes::PET_CATCH_SUCCESS);
67
            break;
68
        default:
69
            NotifyManager::notify(NotifyTypes::PET_CATCH_UNKNOWN, data);
70
            break;
71
    }
72
}
73
74
void PetRecv::processEggsList(Net::MessageIn &msg)
75
{
76
    const int count = (msg.readInt16("len") - 4) / 2;
77
    const Inventory *const inv = PlayerInfo::getInventory();
78
    if (inv == nullptr)
79
        return;
80
    menu = MenuType::Eggs;
81
82
    if (count == 1)
83
    {
84
        const int index = msg.readInt16("index") - INVENTORY_OFFSET;
85
        const Item *const item = inv->getItem(index);
86
        inventoryHandler->selectEgg(item);
87
        return;
88
    }
89
    SellDialog *const dialog = CREATEWIDGETR0(EggSelectionDialog);
90
91
    for (int f = 0; f < count; f ++)
92
    {
93
        const int index = msg.readInt16("index") - INVENTORY_OFFSET;
94
        const Item *const item = inv->getItem(index);
95
96
        if (item != nullptr)
97
            dialog->addItem(item, 0);
98
    }
99
}
100
101
void PetRecv::processPetData(Net::MessageIn &msg)
102
{
103
    if (actorManager == nullptr)
104
        return;
105
    const int cmd = msg.readUInt8("type");
106
    const BeingId id = msg.readBeingId("pet id");
107
    Being *const dstBeing = actorManager->findBeing(id);
108
    const int data = msg.readInt32("data");
109
    if (cmd == 0)  // pre init
110
    {
111
        PetInfo *const info = new PetInfo;
112
        info->id = id;
113
        PlayerInfo::setPet(info);
114
        PlayerInfo::setPetBeing(dstBeing);
115
        return;
116
    }
117
    PetInfo *const info = PlayerInfo::getPet();
118
    if (info == nullptr)
119
        return;
120
    switch (cmd)
121
    {
122
        case 1:  // intimacy
123
            info->intimacy = data;
124
            break;
125
        case 2:  // hunger
126
            info->hungry = data;
127
            break;
128
        case 3:  // accesory
129
            info->equip = data;
130
            break;
131
        case 4:  // performance
132
            info->performance = data;
133
            break;
134
        case 5:  // hair style
135
            info->hairStyle = data;
136
            break;
137
        default:
138
            break;
139
    }
140
}
141
142
void PetRecv::processPetStatus(Net::MessageIn &msg)
143
{
144
    const std::string name = msg.readString(24, "pet name");
145
    msg.readUInt8("rename flag");
146
    const int level = msg.readInt16("level");
147
    const int hungry = msg.readInt16("hungry");
148
    const int intimacy = msg.readInt16("intimacy");
149
    const int equip = msg.readInt16("equip");  // look like always int16
150
151
//    Being *const being = PlayerInfo::getPetBeing();
152
//    if (being)
153
//        being->setLevel(level);
154
155
    PetInfo *const info = PlayerInfo::getPet();
156
    if (info == nullptr)
157
        return;
158
    info->name = name;
159
    info->level = level;
160
    info->hungry = hungry;
161
    info->intimacy = intimacy;
162
    info->equip = equip;
163
    if (msg.getVersion() >= 20081126)
164
        info->race = msg.readInt16("class");
165
    else
166
        info->race = 0;
167
}
168
169
void PetRecv::processPetFood(Net::MessageIn &msg)
170
{
171
    const int result = msg.readUInt8("result");
172
    msg.readItemId("food id");
173
    if (result != 0)
174
        NotifyManager::notify(NotifyTypes::PET_FEED_OK);
175
    else
176
        NotifyManager::notify(NotifyTypes::PET_FEED_ERROR);
177
}
178
179
void PetRecv::processPetCatchProcess(Net::MessageIn &msg A_UNUSED)
180
{
181
    NotifyManager::notify(NotifyTypes::PET_CATCH_PROCESS);
182
}
183
184
void PetRecv::processPetEvolution(Net::MessageIn &msg)
185
{
186
    UNIMPLEMENTEDPACKET;
187
    msg.readUInt8("result");
188
}
189
190
}  // namespace EAthena