ManaPlus
pethandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2018 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/pethandler.h"
22 
23 #include "being/playerinfo.h"
24 
25 #include "net/serverfeatures.h"
26 
27 #include "net/eathena/messageout.h"
29 
30 #include "debug.h"
31 
32 namespace EAthena
33 {
34 
36 {
37  petHandler = this;
38 }
39 
41 {
42  petHandler = nullptr;
43 }
44 
45 void PetHandler::move(const int x,
46  const int y) const
47 {
49  return;
51  outMsg.writeInt32(0, "pet id");
52  outMsg.writeInt16(CAST_S16(x), "x");
53  outMsg.writeInt16(CAST_S16(y), "y");
54 }
55 
56 void PetHandler::emote(const uint8_t emoteId)
57 {
59  outMsg.writeInt8(emoteId, "emote id");
60 }
61 
62 void PetHandler::catchPet(const Being *const being) const
63 {
64  if (being == nullptr)
65  return;
66 
68  outMsg.writeBeingId(being->getId(), "monster id");
69 }
70 
71 void PetHandler::sendPetMessage(const int data) const
72 {
74  outMsg.writeInt32(data, "param");
75 }
76 
77 void PetHandler::setName(const std::string &name) const
78 {
80  outMsg.writeString(name, 24, "name");
81 }
82 
84 {
86  outMsg.writeInt8(0, "action");
87 }
88 
89 void PetHandler::feed() const
90 {
92  outMsg.writeInt8(1, "action");
93 }
94 
96 {
98  outMsg.writeInt8(2, "action"); // performance
99 }
100 
102 {
104  outMsg.writeInt8(3, "action");
105  PlayerInfo::setPet(nullptr);
106 }
107 
109 {
111  outMsg.writeInt8(4, "action");
112 }
113 
114 void PetHandler::setDirection(const unsigned char type) const
115 {
116  if (!serverFeatures->haveMovePet())
117  return;
119  outMsg.writeInt32(0, "pet id");
120  outMsg.writeInt8(0, "head direction");
121  outMsg.writeInt8(0, "unused");
122  outMsg.writeInt8(MessageOut::toServerDirection(type),
123  "pet direction");
124 }
125 
126 } // namespace EAthena
static unsigned char toServerDirection(unsigned char direction) A_CONST
Definition: messageout.cpp:230
Net::PetHandler * petHandler
Definition: net.cpp:91
BeingId getId() const
Definition: actorsprite.h:63
void dropLoot() const
Definition: pethandler.cpp:95
void returnToEgg() const
Definition: pethandler.cpp:101
void requestStatus() const
Definition: pethandler.cpp:83
void catchPet(const Being *const being) const
Definition: pethandler.cpp:62
Net::ServerFeatures * serverFeatures
Definition: net.cpp:97
void setDirection(const unsigned char type) const
Definition: pethandler.cpp:114
virtual bool haveMovePet() const =0
uint32_t data
int CMSG_PET_CATCH
void setName(const std::string &name) const
Definition: pethandler.cpp:77
void feed() const
Definition: pethandler.cpp:89
#define createOutPacket(name)
Definition: messageout.h:36
void move(const int x, const int y) const
Definition: pethandler.cpp:45
void unequip() const
Definition: pethandler.cpp:108
int CMSG_PET_SEND_MESSAGE
int CMSG_PET_EMOTE
int CMSG_PET_MENU_ACTION
void emote(const uint8_t emoteId)
Definition: pethandler.cpp:56
int CMSG_PET_SET_NAME
void sendPetMessage(const int data) const
Definition: pethandler.cpp:71
#define CAST_S16
Definition: cast.h:27
Definition: being.h:93
int CMSG_PET_MOVE_TO
void setPet(PetInfo *const info)
Definition: playerinfo.cpp:550
int CMSG_PET_DIRECTION