GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/pethandler.cpp Lines: 1 56 1.8 %
Date: 2018-07-14 Branches: 0 72 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/pethandler.h"
22
23
#include "being/playerinfo.h"
24
25
#include "net/serverfeatures.h"
26
27
#include "net/eathena/messageout.h"
28
#include "net/eathena/protocolout.h"
29
30
#include "resources/item/item.h"
31
32
#include "debug.h"
33
34
extern int packetVersion;
35
36
namespace EAthena
37
{
38
39
PetHandler::PetHandler()
40
{
41
    petHandler = this;
42
}
43
44
PetHandler::~PetHandler()
45
{
46
    petHandler = nullptr;
47
}
48
49
void PetHandler::move(const int x,
50
                      const int y) const
51
{
52
    if (!serverFeatures->haveMovePet())
53
        return;
54
    createOutPacket(CMSG_PET_MOVE_TO);
55
    outMsg.writeInt32(0, "pet id");
56
    outMsg.writeInt16(CAST_S16(x), "x");
57
    outMsg.writeInt16(CAST_S16(y), "y");
58
}
59
60
void PetHandler::emote(const uint8_t emoteId)
61
{
62
    createOutPacket(CMSG_PET_EMOTE);
63
    outMsg.writeInt8(emoteId, "emote id");
64
}
65
66
void PetHandler::catchPet(const Being *const being) const
67
{
68
    if (being == nullptr)
69
        return;
70
71
    createOutPacket(CMSG_PET_CATCH);
72
    outMsg.writeBeingId(being->getId(), "monster id");
73
}
74
75
void PetHandler::sendPetMessage(const int data) const
76
{
77
    createOutPacket(CMSG_PET_SEND_MESSAGE);
78
    outMsg.writeInt32(data, "param");
79
}
80
81
void PetHandler::setName(const std::string &name) const
82
{
83
    createOutPacket(CMSG_PET_SET_NAME);
84
    outMsg.writeString(name, 24, "name");
85
}
86
87
void PetHandler::requestStatus() const
88
{
89
    createOutPacket(CMSG_PET_MENU_ACTION);
90
    outMsg.writeInt8(0, "action");
91
}
92
93
void PetHandler::feed() const
94
{
95
    createOutPacket(CMSG_PET_MENU_ACTION);
96
    outMsg.writeInt8(1, "action");
97
}
98
99
void PetHandler::dropLoot() const
100
{
101
    createOutPacket(CMSG_PET_MENU_ACTION);
102
    outMsg.writeInt8(2, "action");  // performance
103
}
104
105
void PetHandler::returnToEgg() const
106
{
107
    createOutPacket(CMSG_PET_MENU_ACTION);
108
    outMsg.writeInt8(3, "action");
109
    PlayerInfo::setPet(nullptr);
110
}
111
112
void PetHandler::unequip() const
113
{
114
    createOutPacket(CMSG_PET_MENU_ACTION);
115
    outMsg.writeInt8(4, "action");
116
}
117
118
void PetHandler::setDirection(const unsigned char type) const
119
{
120
    if (!serverFeatures->haveMovePet())
121
        return;
122
    createOutPacket(CMSG_PET_DIRECTION);
123
    outMsg.writeInt32(0, "pet id");
124
    outMsg.writeInt8(0, "head direction");
125
    outMsg.writeInt8(0, "unused");
126
    outMsg.writeInt8(MessageOut::toServerDirection(type),
127
        "pet direction");
128
}
129
130
void PetHandler::evolution(const Item *const item) const
131
{
132
    if (packetVersion < 20140122 ||
133
        item == nullptr)
134
    {
135
        return;
136
    }
137
    createOutPacket(CMSG_PET_EVOLUTION);
138
    outMsg.writeInt16(CAST_S16(item->getId()), "egg id");
139
}
140
141
2
}  // namespace EAthena