ManaPlus
mercenaryhandler.cpp
Go to the documentation of this file.
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 
23 
24 #include "being/playerinfo.h"
25 
26 #include "net/serverfeatures.h"
27 
28 #include "net/eathena/messageout.h"
30 
31 #include "debug.h"
32 
33 namespace EAthena
34 {
35 
37 {
38  mercenaryHandler = this;
39 }
40 
42 {
43  mercenaryHandler = nullptr;
44 }
45 
47 {
48  createOutPacket(CMSG_MERCENARY_ACTION);
49  outMsg.writeInt8(2, "action"); // delete
50 }
51 
53 {
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 {
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 {
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 {
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
int BeingId
Definition: beingid.h:30
const BeingId BeingId_zero
Definition: beingid.h:30
#define CAST_U16
Definition: cast.h:29
#define CAST_S8
Definition: cast.h:26
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
void move(const int x, const int y) const
void setDirection(const unsigned char type) const
void emote(const uint8_t emoteId) const
void talk(const std::string &text) const
void attack(const BeingId targetId, const Keep keep) const
static unsigned char toServerDirection(unsigned char direction) A_CONST
Definition: messageout.cpp:253
virtual bool haveMovePet() const =0
const bool Keep_true
Definition: keep.h:30
bool Keep
Definition: keep.h:30
#define restrict
Definition: localconsts.h:165
Net::MercenaryHandler * mercenaryHandler
Definition: net.cpp:118
#define createOutPacket(name)
Definition: messageout.h:37
bool msg(InputEvent &event)
Definition: chat.cpp:39
BeingId getMercenaryId()
Definition: playerinfo.cpp:613
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101