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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-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/homunculushandler.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
extern int packetVersion;
33
34
namespace EAthena
35
{
36
37
HomunculusHandler::HomunculusHandler()
38
{
39
    homunculusHandler = this;
40
}
41
42
HomunculusHandler::~HomunculusHandler()
43
{
44
    homunculusHandler = nullptr;
45
}
46
47
void HomunculusHandler::setName(const std::string &name) const
48
{
49
    createOutPacket(CMSG_HOMUNCULUS_SET_NAME);
50
    outMsg.writeString(name, 24, "name");
51
}
52
53
void HomunculusHandler::moveToMaster() const
54
{
55
    const BeingId id = PlayerInfo::getHomunculusId();
56
    if (id == BeingId_zero)
57
        return;
58
    createOutPacket(CMSG_HOMMERC_MOVE_TO_MASTER);
59
    outMsg.writeBeingId(id, "homunculus id");
60
}
61
62
void HomunculusHandler::move(const int x, const int y) const
63
{
64
    const BeingId id = PlayerInfo::getHomunculusId();
65
    if (id == BeingId_zero)
66
        return;
67
    createOutPacket(CMSG_HOMMERC_MOVE_TO);
68
    outMsg.writeBeingId(id, "homunculus id");
69
    outMsg.writeCoordinates(CAST_U16(x),
70
        CAST_U16(y),
71
        1U, "position");
72
}
73
74
void HomunculusHandler::attack(const BeingId targetId,
75
                               const Keep keep) const
76
{
77
    const BeingId id = PlayerInfo::getHomunculusId();
78
    if (id == BeingId_zero)
79
        return;
80
    createOutPacket(CMSG_HOMMERC_ATTACK);
81
    outMsg.writeBeingId(id, "homunculus id");
82
    outMsg.writeBeingId(targetId, "target id");
83
    outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
84
}
85
86
void HomunculusHandler::feed() const
87
{
88
    if (packetVersion < 20050425)
89
        return;
90
    createOutPacket(CMSG_HOMUNCULUS_MENU);
91
    outMsg.writeInt16(0, "type");
92
    outMsg.writeInt8(1, "command");  // feed
93
}
94
95
void HomunculusHandler::fire() const
96
{
97
    if (packetVersion < 20050425)
98
        return;
99
    createOutPacket(CMSG_HOMUNCULUS_MENU);
100
    outMsg.writeInt16(0, "type");
101
    outMsg.writeInt8(2, "command");  // delete
102
}
103
104
void HomunculusHandler::talk(const std::string &restrict text) const
105
{
106
    if (!serverFeatures->haveMovePet())
107
        return;
108
    if (text.empty())
109
        return;
110
    std::string msg = text;
111
    if (msg.size() > 500)
112
        msg = msg.substr(0, 500);
113
    const size_t sz = msg.size();
114
115
    createOutPacket(CMSG_HOMMERC_TALK);
116
    outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
117
    outMsg.writeString(msg, CAST_S32(sz), "message");
118
    outMsg.writeInt8(0, "zero byte");
119
}
120
121
void HomunculusHandler::emote(const uint8_t emoteId) const
122
{
123
    if (!serverFeatures->haveMovePet())
124
        return;
125
    createOutPacket(CMSG_HOMMERC_EMOTE);
126
    outMsg.writeInt8(emoteId, "emote id");
127
}
128
129
void HomunculusHandler::setDirection(const unsigned char type) const
130
{
131
    if (!serverFeatures->haveMovePet())
132
        return;
133
    createOutPacket(CMSG_HOMMERC_DIRECTION);
134
    outMsg.writeInt32(0, "pet id");
135
    outMsg.writeInt8(0, "head direction");
136
    outMsg.writeInt8(0, "unused");
137
    outMsg.writeInt8(MessageOut::toServerDirection(type),
138
        "pet direction");
139
}
140
141
}  // namespace EAthena