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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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/petrecv.h"
22
23
#include "actormanager.h"
24
#include "notifymanager.h"
25
26
#include "being/petinfo.h"
27
#include "being/playerinfo.h"
28
29
#include "const/net/inventory.h"
30
31
#include "enums/resources/notifytypes.h"
32
33
#include "gui/windows/eggselectiondialog.h"
34
35
#include "gui/widgets/createwidget.h"
36
37
#include "net/inventoryhandler.h"
38
#include "net/messagein.h"
39
40
#include "net/eathena/menu.h"
41
42
#include "debug.h"
43
44
namespace EAthena
45
{
46
47
void PetRecv::processPetMessage(Net::MessageIn &msg)
48
{
49
    // techinally this is hercules pet emote,
50
    // but it may send also hungry level on connect
51
    // for both exists other packets.
52
    msg.readBeingId("pet id");
53
    msg.readInt32("param");
54
}
55
56
void PetRecv::processPetRoulette(Net::MessageIn &msg)
57
{
58
    const uint8_t data = msg.readUInt8("data");
59
    switch (data)
60
    {
61
        case 0:
62
            NotifyManager::notify(NotifyTypes::PET_CATCH_FAILED);
63
            break;
64
        case 1:
65
            NotifyManager::notify(NotifyTypes::PET_CATCH_SUCCESS);
66
            break;
67
        default:
68
            NotifyManager::notify(NotifyTypes::PET_CATCH_UNKNOWN, data);
69
            break;
70
    }
71
}
72
73
void PetRecv::processEggsList(Net::MessageIn &msg)
74
{
75
    const int count = (msg.readInt16("len") - 4) / 2;
76
    const Inventory *const inv = PlayerInfo::getInventory();
77
    if (inv == nullptr)
78
        return;
79
    menu = MenuType::Eggs;
80
81
    if (count == 1)
82
    {
83
        const int index = msg.readInt16("index") - INVENTORY_OFFSET;
84
        const Item *const item = inv->getItem(index);
85
        inventoryHandler->selectEgg(item);
86
        return;
87
    }
88
    SellDialog *const dialog = CREATEWIDGETR0(EggSelectionDialog);
89
90
    for (int f = 0; f < count; f ++)
91
    {
92
        const int index = msg.readInt16("index") - INVENTORY_OFFSET;
93
        const Item *const item = inv->getItem(index);
94
95
        if (item != nullptr)
96
            dialog->addItem(item, 0);
97
    }
98
}
99
100
void PetRecv::processPetData(Net::MessageIn &msg)
101
{
102
    if (actorManager == nullptr)
103
        return;
104
    const int cmd = msg.readUInt8("type");
105
    const BeingId id = msg.readBeingId("pet id");
106
    Being *const dstBeing = actorManager->findBeing(id);
107
    const int data = msg.readInt32("data");
108
    if (cmd == 0)  // pre init
109
    {
110
        PetInfo *const info = new PetInfo;
111
        info->id = id;
112
        PlayerInfo::setPet(info);
113
        PlayerInfo::setPetBeing(dstBeing);
114
        return;
115
    }
116
    PetInfo *const info = PlayerInfo::getPet();
117
    if (info == nullptr)
118
        return;
119
    switch (cmd)
120
    {
121
        case 1:  // intimacy
122
            info->intimacy = data;
123
            break;
124
        case 2:  // hunger
125
            info->hungry = data;
126
            break;
127
        case 3:  // accesory
128
            info->equip = data;
129
            break;
130
        case 4:  // performance
131
            info->performance = data;
132
            break;
133
        case 5:  // hair style
134
            info->hairStyle = data;
135
            break;
136
        default:
137
            break;
138
    }
139
}
140
141
void PetRecv::processPetStatus(Net::MessageIn &msg)
142
{
143
    const std::string name = msg.readString(24, "pet name");
144
    msg.readUInt8("rename flag");
145
    const int level = msg.readInt16("level");
146
    const int hungry = msg.readInt16("hungry");
147
    const int intimacy = msg.readInt16("intimacy");
148
    const int equip = msg.readInt16("equip");  // look like always int16
149
150
//    Being *const being = PlayerInfo::getPetBeing();
151
//    if (being)
152
//        being->setLevel(level);
153
154
    PetInfo *const info = PlayerInfo::getPet();
155
    if (info == nullptr)
156
        return;
157
    info->name = name;
158
    info->level = level;
159
    info->hungry = hungry;
160
    info->intimacy = intimacy;
161
    info->equip = equip;
162
    if (msg.getVersion() >= 20081126)
163
        info->race = msg.readInt16("class");
164
    else
165
        info->race = 0;
166
}
167
168
void PetRecv::processPetFood(Net::MessageIn &msg)
169
{
170
    const int result = msg.readUInt8("result");
171
    msg.readItemId("food id");
172
    if (result != 0)
173
        NotifyManager::notify(NotifyTypes::PET_FEED_OK);
174
    else
175
        NotifyManager::notify(NotifyTypes::PET_FEED_ERROR);
176
}
177
178
void PetRecv::processPetCatchProcess(Net::MessageIn &msg A_UNUSED)
179
{
180
    NotifyManager::notify(NotifyTypes::PET_CATCH_PROCESS);
181
}
182
183
void PetRecv::processPetEvolution(Net::MessageIn &msg)
184
{
185
    UNIMPLEMENTEDPACKET;
186
    msg.readUInt8("result");
187
}
188
189
}  // namespace EAthena