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