ManaPlus
petrecv.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/petrecv.h"
23 
24 #include "actormanager.h"
25 #include "notifymanager.h"
26 
27 #include "being/petinfo.h"
28 #include "being/playerinfo.h"
29 
30 #include "const/net/inventory.h"
31 
33 
35 
37 
38 #include "net/inventoryhandler.h"
39 #include "net/messagein.h"
40 
41 #include "net/eathena/menu.h"
42 
43 #include "debug.h"
44 
45 namespace EAthena
46 {
47 
49 {
50  // techinally this is hercules pet emote,
51  // but it may send also hungry level on connect
52  // for both exists other packets.
53  msg.readBeingId("pet id");
54  msg.readInt32("param");
55 }
56 
58 {
59  const uint8_t data = msg.readUInt8("data");
60  switch (data)
61  {
62  case 0:
64  break;
65  case 1:
67  break;
68  default:
70  break;
71  }
72 }
73 
75 {
76  const int count = (msg.readInt16("len") - 4) / 2;
77  const Inventory *const inv = PlayerInfo::getInventory();
78  if (inv == nullptr)
79  return;
81 
82  if (count == 1)
83  {
84  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
85  const Item *const item = inv->getItem(index);
87  return;
88  }
90 
91  for (int f = 0; f < count; f ++)
92  {
93  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
94  const Item *const item = inv->getItem(index);
95 
96  if (item != nullptr)
97  dialog->addItem(item, 0);
98  }
99 }
100 
102 {
103  if (actorManager == nullptr)
104  return;
105  const int cmd = msg.readUInt8("type");
106  const BeingId id = msg.readBeingId("pet id");
107  Being *const dstBeing = actorManager->findBeing(id);
108  const int data = msg.readInt32("data");
109  if (cmd == 0) // pre init
110  {
111  PetInfo *const info = new PetInfo;
112  info->id = id;
114  PlayerInfo::setPetBeing(dstBeing);
115  return;
116  }
117  PetInfo *const info = PlayerInfo::getPet();
118  if (info == nullptr)
119  return;
120  switch (cmd)
121  {
122  case 1: // intimacy
123  info->intimacy = data;
124  break;
125  case 2: // hunger
126  info->hungry = data;
127  break;
128  case 3: // accesory
129  info->equip = data;
130  break;
131  case 4: // performance
132  info->performance = data;
133  break;
134  case 5: // hair style
135  info->hairStyle = data;
136  break;
137  default:
138  break;
139  }
140 }
141 
143 {
144  const std::string name = msg.readString(24, "pet name");
145  msg.readUInt8("rename flag");
146  const int level = msg.readInt16("level");
147  const int hungry = msg.readInt16("hungry");
148  const int intimacy = msg.readInt16("intimacy");
149  const int equip = msg.readInt16("equip"); // look like always int16
150 
151 // Being *const being = PlayerInfo::getPetBeing();
152 // if (being)
153 // being->setLevel(level);
154 
155  PetInfo *const info = PlayerInfo::getPet();
156  if (info == nullptr)
157  return;
158  info->name = name;
159  info->level = level;
160  info->hungry = hungry;
161  info->intimacy = intimacy;
162  info->equip = equip;
163  if (msg.getVersion() >= 20081126)
164  info->race = msg.readInt16("class");
165  else
166  info->race = 0;
167 }
168 
170 {
171  const int result = msg.readUInt8("result");
172  msg.readItemId("food id");
173  if (result != 0)
175  else
177 }
178 
180 {
182 }
183 
185 {
187  msg.readUInt8("result");
188 }
189 
190 } // namespace EAthena
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
Being * findBeing(const BeingId id) const
Definition: being.h:96
Item * getItem(const int index) const
Definition: inventory.cpp:83
Definition: item.h:50
virtual void selectEgg(const Item *const item) const =0
void addItem(const Item *const item, const int price)
Definition: selldialog.cpp:238
static const int INVENTORY_OFFSET
Definition: inventory.h:27
#define CREATEWIDGETR0(type)
Definition: createwidget.h:39
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
#define A_UNUSED
Definition: localconsts.h:160
#define UNIMPLEMENTEDPACKET
Definition: logger.h:56
uint32_t data
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool info(InputEvent &event)
Definition: commands.cpp:57
void processPetFood(Net::MessageIn &msg)
Definition: petrecv.cpp:169
void processPetRoulette(Net::MessageIn &msg)
Definition: petrecv.cpp:57
void processPetData(Net::MessageIn &msg)
Definition: petrecv.cpp:101
void processPetCatchProcess(Net::MessageIn &msg)
Definition: petrecv.cpp:179
void processPetStatus(Net::MessageIn &msg)
Definition: petrecv.cpp:142
void processPetMessage(Net::MessageIn &msg)
Definition: petrecv.cpp:48
void processPetEvolution(Net::MessageIn &msg)
Definition: petrecv.cpp:184
void processEggsList(Net::MessageIn &msg)
Definition: petrecv.cpp:74
MenuTypeT menu
Definition: menu.cpp:28
@ Eggs
Definition: menutype.h:35
void notify(const unsigned int message)
Inventory * getInventory()
Definition: playerinfo.cpp:195
void setPetBeing(Being *const being)
Definition: playerinfo.cpp:560
void setPet(PetInfo *const info)
Definition: playerinfo.cpp:554
PetInfo * getPet()
Definition: playerinfo.cpp:576