GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/mercenaryhandler.cpp Lines: 0 54 0.0 %
Date: 2021-03-17 Branches: 0 68 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "net/eathena/mercenaryhandler.h"
23
24
#include "being/playerinfo.h"
25
26
#include "net/serverfeatures.h"
27
28
#include "net/eathena/messageout.h"
29
#include "net/eathena/protocolout.h"
30
31
#include "debug.h"
32
33
namespace EAthena
34
{
35
36
MercenaryHandler::MercenaryHandler()
37
{
38
    mercenaryHandler = this;
39
}
40
41
MercenaryHandler::~MercenaryHandler()
42
{
43
    mercenaryHandler = nullptr;
44
}
45
46
void MercenaryHandler::fire() const
47
{
48
    createOutPacket(CMSG_MERCENARY_ACTION);
49
    outMsg.writeInt8(2, "action");  // delete
50
}
51
52
void MercenaryHandler::moveToMaster() const
53
{
54
    const BeingId id = PlayerInfo::getMercenaryId();
55
    if (id == BeingId_zero)
56
        return;
57
    createOutPacket(CMSG_HOMMERC_MOVE_TO_MASTER);
58
    outMsg.writeBeingId(id, "mercenary id");
59
}
60
61
void MercenaryHandler::move(const int x, const int y) const
62
{
63
    const BeingId id = PlayerInfo::getMercenaryId();
64
    if (id == BeingId_zero)
65
        return;
66
    createOutPacket(CMSG_HOMMERC_MOVE_TO);
67
    outMsg.writeBeingId(id, "mercenary id");
68
    outMsg.writeCoordinates(CAST_U16(x),
69
        CAST_U16(y),
70
        1U, "position");
71
}
72
73
void MercenaryHandler::attack(const BeingId targetId,
74
                              const Keep keep) const
75
{
76
    const BeingId id = PlayerInfo::getMercenaryId();
77
    if (id == BeingId_zero)
78
        return;
79
    createOutPacket(CMSG_HOMMERC_ATTACK);
80
    outMsg.writeBeingId(id, "mercenary id");
81
    outMsg.writeBeingId(targetId, "target id");
82
    outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
83
}
84
85
void MercenaryHandler::talk(const std::string &restrict text) const
86
{
87
    if (!serverFeatures->haveMovePet())
88
        return;
89
    if (text.empty())
90
        return;
91
    std::string msg = text;
92
    if (msg.size() > 500)
93
        msg = msg.substr(0, 500);
94
    const size_t sz = msg.size();
95
96
    createOutPacket(CMSG_HOMMERC_TALK);
97
    outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
98
    outMsg.writeString(msg, CAST_S32(sz), "message");
99
    outMsg.writeInt8(0, "zero byte");
100
}
101
102
void MercenaryHandler::emote(const uint8_t emoteId) const
103
{
104
    if (!serverFeatures->haveMovePet())
105
        return;
106
    createOutPacket(CMSG_HOMMERC_EMOTE);
107
    outMsg.writeInt8(emoteId, "emote id");
108
}
109
110
void MercenaryHandler::setDirection(const unsigned char type) const
111
{
112
    if (!serverFeatures->haveMovePet())
113
        return;
114
    createOutPacket(CMSG_HOMMERC_DIRECTION);
115
    outMsg.writeInt32(0, "pet id");
116
    outMsg.writeInt8(0, "head direction");
117
    outMsg.writeInt8(0, "unused");
118
    outMsg.writeInt8(MessageOut::toServerDirection(type),
119
        "pet direction");
120
}
121
122
}  // namespace EAthena