1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2013-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/pethandler.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 "resources/item/item.h" |
32 |
|
|
|
33 |
|
|
#include "debug.h" |
34 |
|
|
|
35 |
|
|
extern int packetVersion; |
36 |
|
|
|
37 |
|
|
namespace EAthena |
38 |
|
|
{ |
39 |
|
|
|
40 |
|
|
PetHandler::PetHandler() |
41 |
|
|
{ |
42 |
|
|
petHandler = this; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
PetHandler::~PetHandler() |
46 |
|
|
{ |
47 |
|
|
petHandler = nullptr; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
void PetHandler::move(const int x, |
51 |
|
|
const int y) const |
52 |
|
|
{ |
53 |
|
|
if (!serverFeatures->haveMovePet()) |
54 |
|
|
return; |
55 |
|
|
createOutPacket(CMSG_PET_MOVE_TO); |
56 |
|
|
outMsg.writeInt32(0, "pet id"); |
57 |
|
|
outMsg.writeInt16(CAST_S16(x), "x"); |
58 |
|
|
outMsg.writeInt16(CAST_S16(y), "y"); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void PetHandler::emote(const uint8_t emoteId) |
62 |
|
|
{ |
63 |
|
|
createOutPacket(CMSG_PET_EMOTE); |
64 |
|
|
outMsg.writeInt8(emoteId, "emote id"); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
void PetHandler::catchPet(const Being *const being) const |
68 |
|
|
{ |
69 |
|
|
if (being == nullptr) |
70 |
|
|
return; |
71 |
|
|
|
72 |
|
|
createOutPacket(CMSG_PET_CATCH); |
73 |
|
|
outMsg.writeBeingId(being->getId(), "monster id"); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
void PetHandler::sendPetMessage(const int data) const |
77 |
|
|
{ |
78 |
|
|
createOutPacket(CMSG_PET_SEND_MESSAGE); |
79 |
|
|
outMsg.writeInt32(data, "param"); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
void PetHandler::setName(const std::string &name) const |
83 |
|
|
{ |
84 |
|
|
createOutPacket(CMSG_PET_SET_NAME); |
85 |
|
|
outMsg.writeString(name, 24, "name"); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
void PetHandler::requestStatus() const |
89 |
|
|
{ |
90 |
|
|
createOutPacket(CMSG_PET_MENU_ACTION); |
91 |
|
|
outMsg.writeInt8(0, "action"); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
void PetHandler::feed() const |
95 |
|
|
{ |
96 |
|
|
createOutPacket(CMSG_PET_MENU_ACTION); |
97 |
|
|
outMsg.writeInt8(1, "action"); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
void PetHandler::dropLoot() const |
101 |
|
|
{ |
102 |
|
|
createOutPacket(CMSG_PET_MENU_ACTION); |
103 |
|
|
outMsg.writeInt8(2, "action"); // performance |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
void PetHandler::returnToEgg() const |
107 |
|
|
{ |
108 |
|
|
createOutPacket(CMSG_PET_MENU_ACTION); |
109 |
|
|
outMsg.writeInt8(3, "action"); |
110 |
|
|
PlayerInfo::setPet(nullptr); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
void PetHandler::unequip() const |
114 |
|
|
{ |
115 |
|
|
createOutPacket(CMSG_PET_MENU_ACTION); |
116 |
|
|
outMsg.writeInt8(4, "action"); |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
void PetHandler::setDirection(const unsigned char type) const |
120 |
|
|
{ |
121 |
|
|
if (!serverFeatures->haveMovePet()) |
122 |
|
|
return; |
123 |
|
|
createOutPacket(CMSG_PET_DIRECTION); |
124 |
|
|
outMsg.writeInt32(0, "pet id"); |
125 |
|
|
outMsg.writeInt8(0, "head direction"); |
126 |
|
|
outMsg.writeInt8(0, "unused"); |
127 |
|
|
outMsg.writeInt8(MessageOut::toServerDirection(type), |
128 |
|
|
"pet direction"); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
void PetHandler::evolution(const Item *const item) const |
132 |
|
|
{ |
133 |
|
|
if (packetVersion < 20140122 || |
134 |
|
|
item == nullptr) |
135 |
|
|
{ |
136 |
|
|
return; |
137 |
|
|
} |
138 |
|
|
createOutPacket(CMSG_PET_EVOLUTION); |
139 |
|
|
outMsg.writeItemId(item->getId(), "egg id"); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
2 |
} // namespace EAthena |