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  // +++ need create if need mercenary being and update stats
82  Being *const dstBeing = actorManager->findBeing(
83  msg.readBeingId("being id"));
85  msg.readInt16("atk"),
86  Notify_true);
88  msg.readInt16("matk"),
89  Notify_true);
91  msg.readInt16("hit"),
92  Notify_true);
94  msg.readInt16("crit/10"),
95  Notify_true);
97  msg.readInt16("def"),
98  Notify_true);
100  msg.readInt16("mdef"),
101  Notify_true);
103  msg.readInt16("flee"),
104  Notify_true);
106  msg.readInt16("attack speed"),
107  Notify_true);
108  const std::string name = msg.readString(24, "name");
109  const int level = msg.readInt16("level");
111  level,
112  Notify_true);
114  msg.readInt32("hp"),
115  Notify_true);
117  msg.readInt32("max hp"),
118  Notify_true);
120  msg.readInt32("sp"),
121  Notify_true);
123  msg.readInt32("max sp"),
124  Notify_true);
126  msg.readInt32("expire time"),
127  Notify_true);
129  msg.readInt16("faith"),
130  Notify_true);
132  msg.readInt32("calls"),
133  Notify_true);
135  msg.readInt32("kills"),
136  Notify_true);
137  const int range = msg.readInt16("attack range");
139  range,
140  Notify_true);
142 
143  if ((dstBeing != nullptr) && (localPlayer != nullptr))
144  {
145  MercenaryInfo *const mercenary = new MercenaryInfo;
146  mercenary->id = dstBeing->getId();
147  mercenary->name = name;
148  mercenary->level = level;
149  mercenary->range = range;
150  PlayerInfo::setMercenary(mercenary);
152  }
153 }
154 
156 {
157  if (skillDialog != nullptr)
159  const int count = (msg.readInt16("len") - 4) / 37;
160  for (int f = 0; f < count; f ++)
161  {
162  const int skillId = msg.readInt16("skill id");
163  const SkillType::SkillType inf = static_cast<SkillType::SkillType>(
164  msg.readInt32("inf"));
165  const int level = msg.readInt16("skill level");
166  const int sp = msg.readInt16("sp");
167  const int range = msg.readInt16("range");
168  const std::string name = msg.readString(24, "skill name");
169  const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable);
170  PlayerInfo::setSkillLevel(skillId, level);
171  if (skillDialog != nullptr)
172  {
173  if (!skillDialog->updateSkill(skillId, range, up, inf, sp))
174  {
176  skillId, name, level, range, up, inf, sp);
177  }
178  }
179  }
180  if (skillDialog != nullptr)
182 }
183 
185 {
186  PlayerInfo::setMercenary(nullptr);
187  if (skillDialog != nullptr)
188  {
191  }
192 
193  switch (cmd)
194  {
195  case 0:
197  break;
198  case 1:
200  break;
201  case 2:
203  break;
204  case 3:
206  break;
207  default:
209  break;
210  }
211 }
212 
213 } // namespace EAthena
void processMercenaryUpdate(Net::MessageIn &msg)
#define setMercStat(sp, stat)
virtual unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:74
Definition: sp.h:73
void updateModels()
virtual BeingId readBeingId(const char *const str)=0
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)
virtual int16_t readInt16(const char *const str)=0
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
#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)
virtual int32_t readInt32(const char *const str)=0
void setMercenaryBeing(Being *const being)
Definition: playerinfo.cpp:522
virtual std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:219
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