GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/petrecv.cpp Lines: 0 86 0.0 %
Date: 2017-11-29 Branches: 0 43 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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/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
    const int cmd = msg.readUInt8("type");
103
    const BeingId id = msg.readBeingId("pet id");
104
    Being *const dstBeing = actorManager->findBeing(id);
105
    const int data = msg.readInt32("data");
106
    if (cmd == 0)  // pre init
107
    {
108
        PetInfo *const info = new PetInfo;
109
        info->id = id;
110
        PlayerInfo::setPet(info);
111
        PlayerInfo::setPetBeing(dstBeing);
112
        return;
113
    }
114
    PetInfo *const info = PlayerInfo::getPet();
115
    if (info == nullptr)
116
        return;
117
    switch (cmd)
118
    {
119
        case 1:  // intimacy
120
            info->intimacy = data;
121
            break;
122
        case 2:  // hunger
123
            info->hungry = data;
124
            break;
125
        case 3:  // accesory
126
            info->equip = data;
127
            break;
128
        case 4:  // performance
129
            info->performance = data;
130
            break;
131
        case 5:  // hair style
132
            info->hairStyle = data;
133
            break;
134
        default:
135
            break;
136
    }
137
}
138
139
void PetRecv::processPetStatus(Net::MessageIn &msg)
140
{
141
    const std::string name = msg.readString(24, "pet name");
142
    msg.readUInt8("rename flag");
143
    const int level = msg.readInt16("level");
144
    const int hungry = msg.readInt16("hungry");
145
    const int intimacy = msg.readInt16("intimacy");
146
    const int equip = msg.readInt16("equip");
147
148
//    Being *const being = PlayerInfo::getPetBeing();
149
//    if (being)
150
//        being->setLevel(level);
151
152
    PetInfo *const info = PlayerInfo::getPet();
153
    if (info == nullptr)
154
        return;
155
    info->name = name;
156
    info->level = level;
157
    info->hungry = hungry;
158
    info->intimacy = intimacy;
159
    info->equip = equip;
160
    if (msg.getVersion() >= 20081126)
161
        info->race = msg.readInt16("class");
162
    else
163
        info->race = 0;
164
}
165
166
void PetRecv::processPetFood(Net::MessageIn &msg)
167
{
168
    const int result = msg.readUInt8("result");
169
    msg.readInt16("food id");
170
    if (result != 0)
171
        NotifyManager::notify(NotifyTypes::PET_FEED_OK);
172
    else
173
        NotifyManager::notify(NotifyTypes::PET_FEED_ERROR);
174
}
175
176
void PetRecv::processPetCatchProcess(Net::MessageIn &msg A_UNUSED)
177
{
178
    NotifyManager::notify(NotifyTypes::PET_CATCH_PROCESS);
179
}
180
181
}  // namespace EAthena