ManaPlus
mercenaryrecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-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 
22 
23 #include "actormanager.h"
24 #include "notifymanager.h"
25 
26 #include "being/localplayer.h"
27 #include "being/mercenaryinfo.h"
28 #include "being/playerinfo.h"
29 
31 
33 
34 #include "net/messagein.h"
35 
36 #include "net/eathena/sp.h"
37 
38 #include "utils/checkutils.h"
39 
40 #include "debug.h"
41 
42 namespace EAthena
43 {
44 
45 #define setMercStat(sp, stat) \
46  case sp: \
47  PlayerInfo::setStatBase(stat, \
48  val, \
49  Notify_true); \
50  break;
51 
53 {
54  const int sp = msg.readInt16("type");
55  const int val = msg.readInt32("value");
56  switch (sp)
57  {
72  default:
73  reportAlways("Unknown mercenary stat %d",
74  sp);
75  break;
76  }
77 }
78 
80 {
81  if (actorManager == nullptr)
82  return;
83  // +++ need create if need mercenary being and update stats
84  Being *const dstBeing = actorManager->findBeing(
85  msg.readBeingId("being id"));
87  msg.readInt16("atk"),
88  Notify_true);
90  msg.readInt16("matk"),
91  Notify_true);
93  msg.readInt16("hit"),
94  Notify_true);
96  msg.readInt16("crit/10"),
97  Notify_true);
99  msg.readInt16("def"),
100  Notify_true);
102  msg.readInt16("mdef"),
103  Notify_true);
105  msg.readInt16("flee"),
106  Notify_true);
108  msg.readInt16("attack speed"),
109  Notify_true);
110  const std::string name = msg.readString(24, "name");
111  const int level = msg.readInt16("level");
113  level,
114  Notify_true);
116  msg.readInt32("hp"),
117  Notify_true);
119  msg.readInt32("max hp"),
120  Notify_true);
122  msg.readInt32("sp"),
123  Notify_true);
125  msg.readInt32("max sp"),
126  Notify_true);
128  msg.readInt32("expire time"),
129  Notify_true);
131  msg.readInt16("faith"),
132  Notify_true);
134  msg.readInt32("calls"),
135  Notify_true);
137  msg.readInt32("kills"),
138  Notify_true);
139  const int range = msg.readInt16("attack range");
141  range,
142  Notify_true);
144 
145  if ((dstBeing != nullptr) && (localPlayer != nullptr))
146  {
147  MercenaryInfo *const mercenary = new MercenaryInfo;
148  mercenary->id = dstBeing->getId();
149  mercenary->name = name;
150  mercenary->level = level;
151  mercenary->range = range;
152  PlayerInfo::setMercenary(mercenary);
154  }
155 }
156 
158 {
159  if (skillDialog != nullptr)
161  const int count = (msg.readInt16("len") - 4) / 37;
162  for (int f = 0; f < count; f ++)
163  {
164  const int skillId = msg.readInt16("skill id");
165  const SkillType::SkillType inf = static_cast<SkillType::SkillType>(
166  msg.readInt32("inf"));
167  const int level = msg.readInt16("skill level");
168  const int sp = msg.readInt16("sp");
169  const int range = msg.readInt16("range");
170  const std::string name = msg.readString(24, "skill name");
171  const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable);
172  PlayerInfo::setSkillLevel(skillId, level);
173  if (skillDialog != nullptr)
174  {
175  if (!skillDialog->updateSkill(skillId, range, up, inf, sp))
176  {
178  skillId, name, level, range, up, inf, sp);
179  }
180  }
181  }
182  if (skillDialog != nullptr)
184 }
185 
187 {
188  PlayerInfo::setMercenary(nullptr);
189  if (skillDialog != nullptr)
190  {
193  }
194 
195  switch (cmd)
196  {
197  case 0:
199  break;
200  case 1:
202  break;
203  case 2:
205  break;
206  case 3:
208  break;
209  default:
211  break;
212  }
213 }
214 
215 } // namespace EAthena
void processMercenaryUpdate(Net::MessageIn &msg)
#define setMercStat(sp, stat)
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
Definition: sp.h:73
void updateModels()
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:141
BeingId getId() const
Definition: actorsprite.h:63
std::string name
Definition: mercenaryinfo.h:40
void handleMercenaryMessage(const int cmd)
bool updateSkill(const int id, const int range, const Modifiable modifiable, const SkillType::SkillType type, const int sp)
bool msg(InputEvent &event)
Definition: chat.cpp:38
void processMercenarySkills(Net::MessageIn &msg)
void notify(const unsigned int message)
void updateAttrs()
Definition: playerinfo.cpp:417
Definition: sp.h:77
void hideSkills(const SkillOwner::Type owner)
bool Modifiable
Definition: modifiable.h:29
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
#define fromBool(val, name)
Definition: booldefines.h:48
LocalPlayer * localPlayer
Being * findBeing(const BeingId id) const
void processMercenaryInfo(Net::MessageIn &msg)
Definition: sp.h:35
Definition: sp.h:71
void setMercenary(MercenaryInfo *const info)
Definition: playerinfo.cpp:516
void setSkillLevel(const int id, const int value)
Definition: playerinfo.cpp:126
Definition: sp.h:37
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
Definition: sp.h:38
Definition: sp.h:36
Definition: sp.h:83
void addSkill(const SkillOwner::Type owner, const int id, const std::string &name, const int level, const int range, const Modifiable modifiable, const SkillType::SkillType type, const int sp)
void setMercenaryBeing(Being *const being)
Definition: playerinfo.cpp:522
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:367
int32_t readInt32(const char *const str)
Definition: messagein.cpp:174
Definition: being.h:93
#define reportAlways(...)
Definition: checkutils.h:252
Definition: sp.h:79
const bool Notify_true
Definition: notify.h:29
ActorManager * actorManager
Definition: sp.h:75