GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/mercenaryhandler.cpp Lines: 0 53 0.0 %
Date: 2017-11-29 Branches: 0 68 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/mercenaryhandler.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
MercenaryHandler::MercenaryHandler()
36
{
37
    mercenaryHandler = this;
38
}
39
40
MercenaryHandler::~MercenaryHandler()
41
{
42
    mercenaryHandler = nullptr;
43
}
44
45
void MercenaryHandler::fire() const
46
{
47
    createOutPacket(CMSG_MERCENARY_ACTION);
48
    outMsg.writeInt8(2, "action");  // delete
49
}
50
51
void MercenaryHandler::moveToMaster() const
52
{
53
    const BeingId id = PlayerInfo::getMercenaryId();
54
    if (id == BeingId_zero)
55
        return;
56
    createOutPacket(CMSG_HOMMERC_MOVE_TO_MASTER);
57
    outMsg.writeBeingId(id, "mercenary id");
58
}
59
60
void MercenaryHandler::move(const int x, const int y) const
61
{
62
    const BeingId id = PlayerInfo::getMercenaryId();
63
    if (id == BeingId_zero)
64
        return;
65
    createOutPacket(CMSG_HOMMERC_MOVE_TO);
66
    outMsg.writeBeingId(id, "mercenary id");
67
    outMsg.writeCoordinates(CAST_U16(x),
68
        CAST_U16(y),
69
        1U, "position");
70
}
71
72
void MercenaryHandler::attack(const BeingId targetId,
73
                              const Keep keep) const
74
{
75
    const BeingId id = PlayerInfo::getMercenaryId();
76
    if (id == BeingId_zero)
77
        return;
78
    createOutPacket(CMSG_HOMMERC_ATTACK);
79
    outMsg.writeBeingId(id, "mercenary id");
80
    outMsg.writeBeingId(targetId, "target id");
81
    outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
82
}
83
84
void MercenaryHandler::talk(const std::string &restrict text) const
85
{
86
    if (!serverFeatures->haveMovePet())
87
        return;
88
    if (text.empty())
89
        return;
90
    std::string msg = text;
91
    if (msg.size() > 500)
92
        msg = msg.substr(0, 500);
93
    const size_t sz = msg.size();
94
95
    createOutPacket(CMSG_HOMMERC_TALK);
96
    outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
97
    outMsg.writeString(msg, CAST_S32(sz), "message");
98
    outMsg.writeInt8(0, "zero byte");
99
}
100
101
void MercenaryHandler::emote(const uint8_t emoteId) const
102
{
103
    if (!serverFeatures->haveMovePet())
104
        return;
105
    createOutPacket(CMSG_HOMMERC_EMOTE);
106
    outMsg.writeInt8(emoteId, "emote id");
107
}
108
109
void MercenaryHandler::setDirection(const unsigned char type) const
110
{
111
    if (!serverFeatures->haveMovePet())
112
        return;
113
    createOutPacket(CMSG_HOMMERC_DIRECTION);
114
    outMsg.writeInt32(0, "pet id");
115
    outMsg.writeInt8(0, "head direction");
116
    outMsg.writeInt8(0, "unused");
117
    outMsg.writeInt8(MessageOut::toServerDirection(type),
118
        "pet direction");
119
}
120
121
}  // namespace EAthena