ManaPlus
pethandler.cpp
Go to the documentation of this file.
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"
30 
31 #include "resources/item/item.h"
32 
33 #include "debug.h"
34 
35 extern int packetVersion;
36 
37 namespace EAthena
38 {
39 
41 {
42  petHandler = this;
43 }
44 
46 {
47  petHandler = nullptr;
48 }
49 
50 void PetHandler::move(const int x,
51  const int y) const
52 {
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 
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 
101 {
102  createOutPacket(CMSG_PET_MENU_ACTION);
103  outMsg.writeInt8(2, "action"); // performance
104 }
105 
107 {
108  createOutPacket(CMSG_PET_MENU_ACTION);
109  outMsg.writeInt8(3, "action");
110  PlayerInfo::setPet(nullptr);
111 }
112 
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 } // namespace EAthena
#define CAST_S16
Definition: cast.h:28
BeingId getId() const
Definition: actorsprite.h:64
Definition: being.h:96
void evolution(const Item *const item) const
Definition: pethandler.cpp:131
void emote(const uint8_t emoteId)
Definition: pethandler.cpp:61
void dropLoot() const
Definition: pethandler.cpp:100
void move(const int x, const int y) const
Definition: pethandler.cpp:50
void setName(const std::string &name) const
Definition: pethandler.cpp:82
void feed() const
Definition: pethandler.cpp:94
void sendPetMessage(const int data) const
Definition: pethandler.cpp:76
void requestStatus() const
Definition: pethandler.cpp:88
void catchPet(const Being *const being) const
Definition: pethandler.cpp:67
void unequip() const
Definition: pethandler.cpp:113
void setDirection(const unsigned char type) const
Definition: pethandler.cpp:119
void returnToEgg() const
Definition: pethandler.cpp:106
Definition: item.h:50
int getId() const
Definition: item.h:81
static unsigned char toServerDirection(unsigned char direction) A_CONST
Definition: messageout.cpp:253
virtual bool haveMovePet() const =0
int packetVersion
Definition: client.cpp:125
uint32_t data
#define createOutPacket(name)
Definition: messageout.h:37
void setPet(PetInfo *const info)
Definition: playerinfo.cpp:554
Net::PetHandler * petHandler
Definition: net.cpp:95
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101