ManaPlus
mercenaryrecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-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 
23 
24 #include "actormanager.h"
25 #include "notifymanager.h"
26 
27 #include "being/localplayer.h"
28 #include "being/mercenaryinfo.h"
29 #include "being/playerinfo.h"
30 
32 
34 
35 #include "net/messagein.h"
36 
37 #include "net/eathena/sp.h"
38 
39 #include "utils/checkutils.h"
40 
41 #include "debug.h"
42 
43 namespace EAthena
44 {
45 
46 #define setMercStat(sp, stat) \
47  case sp: \
48  PlayerInfo::setStatBase(stat, \
49  val, \
50  Notify_true); \
51  break
52 
54 {
55  const int sp = msg.readInt16("type");
56  const int val = msg.readInt32("value");
57  switch (sp)
58  {
73  default:
74  reportAlways("Unknown mercenary stat %d",
75  sp)
76  break;
77  }
78 }
79 
81 {
82  if (actorManager == nullptr)
83  return;
84  // +++ need create if need mercenary being and update stats
85  Being *const dstBeing = actorManager->findBeing(
86  msg.readBeingId("being id"));
88  msg.readInt16("atk"),
89  Notify_true);
91  msg.readInt16("matk"),
92  Notify_true);
94  msg.readInt16("hit"),
95  Notify_true);
97  msg.readInt16("crit/10"),
98  Notify_true);
100  msg.readInt16("def"),
101  Notify_true);
103  msg.readInt16("mdef"),
104  Notify_true);
106  msg.readInt16("flee"),
107  Notify_true);
109  msg.readInt16("attack speed"),
110  Notify_true);
111  const std::string name = msg.readString(24, "name");
112  const int level = msg.readInt16("level");
114  level,
115  Notify_true);
117  msg.readInt32("hp"),
118  Notify_true);
120  msg.readInt32("max hp"),
121  Notify_true);
123  msg.readInt32("sp"),
124  Notify_true);
126  msg.readInt32("max sp"),
127  Notify_true);
129  msg.readInt32("expire time"),
130  Notify_true);
132  msg.readInt16("faith"),
133  Notify_true);
135  msg.readInt32("calls"),
136  Notify_true);
138  msg.readInt32("kills"),
139  Notify_true);
140  const int range = msg.readInt16("attack range");
142  range,
143  Notify_true);
145 
146  if ((dstBeing != nullptr) && (localPlayer != nullptr))
147  {
148  MercenaryInfo *const mercenary = new MercenaryInfo;
149  mercenary->id = dstBeing->getId();
150  mercenary->name = name;
151  mercenary->level = level;
152  mercenary->range = range;
153  PlayerInfo::setMercenary(mercenary);
155  }
156 }
157 
159 {
160  if (skillDialog != nullptr)
162  const int count = (msg.readInt16("len") - 4) / 37;
163  for (int f = 0; f < count; f ++)
164  {
165  const int skillId = msg.readInt16("skill id");
166  const SkillType::SkillType inf = static_cast<SkillType::SkillType>(
167  msg.readInt32("inf"));
168  const int level = msg.readInt16("skill level");
169  const int sp = msg.readInt16("sp");
170  const int range = msg.readInt16("range");
171  const std::string name = msg.readString(24, "skill name");
172  const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable);
173  PlayerInfo::setSkillLevel(skillId, level);
174  if (skillDialog != nullptr)
175  {
176  if (!skillDialog->updateSkill(skillId, range, up, inf, sp))
177  {
179  skillId, name, level, range, up, inf, sp);
180  }
181  }
182  }
183  if (skillDialog != nullptr)
185 }
186 
188 {
189  PlayerInfo::setMercenary(nullptr);
190  if (skillDialog != nullptr)
191  {
194  }
195 
196  switch (cmd)
197  {
198  case 0:
200  break;
201  case 1:
203  break;
204  case 2:
206  break;
207  case 3:
209  break;
210  default:
212  break;
213  }
214 }
215 
216 } // namespace EAthena
ActorManager * actorManager
#define fromBool(val, name)
Definition: booldefines.h:49
#define reportAlways(...)
Definition: checkutils.h:253
Being * findBeing(const BeingId id) const
BeingId getId() const
Definition: actorsprite.h:64
Definition: being.h:96
bool updateSkill(const int id, const int range, const Modifiable modifiable, const SkillType::SkillType type, const int sp)
void updateModels()
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 hideSkills(const SkillOwner::Type owner)
LocalPlayer * localPlayer
#define setMercStat(sp, stat)
bool Modifiable
Definition: modifiable.h:30
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ MERC_ATTACK_RANGE
Definition: attributes.h:96
@ MERC_ATTACK_DELAY
Definition: attributes.h:95
void processMercenaryInfo(Net::MessageIn &msg)
void processMercenarySkills(Net::MessageIn &msg)
void processMercenaryUpdate(Net::MessageIn &msg)
void handleMercenaryMessage(const int cmd)
void notify(const unsigned int message)
void setMercenaryBeing(Being *const being)
Definition: playerinfo.cpp:526
void setSkillLevel(const int id, const int value)
Definition: playerinfo.cpp:128
void updateAttrs()
Definition: playerinfo.cpp:420
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:143
void setMercenary(MercenaryInfo *const info)
Definition: playerinfo.cpp:520
@ MERCKILLS
Definition: sp.h:107
@ MERCFLEE
Definition: sp.h:105
@ MERCFAITH
Definition: sp.h:108
@ MAXSP
Definition: sp.h:39
@ DEF1
Definition: sp.h:76
@ MATK1
Definition: sp.h:74
@ CRITICAL
Definition: sp.h:83
@ ASPD
Definition: sp.h:84
@ MDEF1
Definition: sp.h:78
@ ATK1
Definition: sp.h:72
@ SP
Definition: sp.h:38
@ HIT
Definition: sp.h:80
@ HP
Definition: sp.h:36
@ MAXHP
Definition: sp.h:37
const bool Notify_true
Definition: notify.h:30
SkillDialog * skillDialog
Definition: skilldialog.cpp:66
std::string name
Definition: mercenaryinfo.h:41