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