ManaPlus
playerhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "net/tmwa/playerhandler.h"
24 
25 #include "notifymanager.h"
26 #include "party.h"
27 
28 #include "being/localplayer.h"
29 #include "being/playerinfo.h"
30 
31 #include "const/net/nostat.h"
32 
34 
37 
39 
40 #include "net/tmwa/messageout.h"
41 #include "net/tmwa/protocolout.h"
42 #include "net/tmwa/sp.h"
43 
44 #include "resources/db/unitsdb.h"
45 
46 #include "debug.h"
47 
48 namespace TmwAthena
49 {
50 
52  Ea::PlayerHandler()
53 {
54  playerHandler = this;
55 }
56 
58 {
59  playerHandler = nullptr;
60 }
61 
63  const Keep keep) const
64 {
66  outMsg.writeBeingId(id, "target id");
67  if (keep == Keep_true)
68  outMsg.writeInt8(7, "action");
69  else
70  outMsg.writeInt8(0, "action");
71 }
72 
74 {
76 }
77 
78 void PlayerHandler::emote(const uint8_t emoteId) const
79 {
81  outMsg.writeInt8(emoteId, "emote id");
82 }
83 
85  const int amount A_UNUSED) const
86 {
87  if (attr >= Attributes::PLAYER_STR && attr <= Attributes::PLAYER_LUK)
88  {
90  outMsg.writeInt16(CAST_S16(attr), "attribute id");
91  outMsg.writeInt8(1, "increment");
92  }
93 }
94 
95 void PlayerHandler::increaseSkill(const uint16_t skillId) const
96 {
98  return;
99 
101  outMsg.writeInt16(skillId, "skill id");
102 }
103 
104 void PlayerHandler::pickUp(const FloorItem *const floorItem) const
105 {
106  if (floorItem == nullptr)
107  return;
108 
110  outMsg.writeBeingId(floorItem->getId(), "object id");
112 }
113 
114 void PlayerHandler::setDirection(const unsigned char direction) const
115 {
117  outMsg.writeInt16(0, "unused");
118  outMsg.writeInt8(direction, "direction");
119 }
120 
121 void PlayerHandler::setDestination(const int x, const int y,
122  const int direction) const
123 {
125  outMsg.writeCoordinates(CAST_U16(x),
126  CAST_U16(y),
127  CAST_U8(direction), "destination");
128 }
129 
130 void PlayerHandler::changeAction(const BeingActionT &action) const
131 {
132  char type;
133  switch (action)
134  {
135  case BeingAction::SIT:
136  type = 2;
137  break;
138  case BeingAction::STAND:
140  type = 3;
141  break;
142  default:
143  case BeingAction::MOVE:
144  case BeingAction::ATTACK:
145  case BeingAction::DEAD:
146  case BeingAction::HURT:
147  case BeingAction::SPAWN:
148  case BeingAction::CAST:
149  return;
150  }
151 
153  outMsg.writeInt32(0, "unused");
154  outMsg.writeInt8(type, "action");
155 }
156 
158 {
160  outMsg.writeInt8(0, "action");
161 }
162 
164 {
166 }
167 
169 {
170 }
171 
172 void PlayerHandler::changeCart(const int type A_UNUSED) const
173 {
174 }
175 
177 {
178 }
179 
180 void PlayerHandler::updateStatus(const uint8_t status A_UNUSED) const
181 {
182 }
183 
185  const uint8_t type A_UNUSED,
186  const int id A_UNUSED,
187  const int level A_UNUSED) const
188 {
189 }
190 
192 {
193 }
194 
196 {
197 }
198 
200 {
201 }
202 
204 {
205 }
206 
207 void PlayerHandler::shortcutShiftRow(const int row A_UNUSED) const
208 {
209 }
210 
212  const int data A_UNUSED) const
213 {
214 }
215 
216 #define setStatComplex(stat) \
217  PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
218  if (mod != NoStat) \
219  PlayerInfo::setStatMod(stat, mod, Notify_true)
220 
222  const int type,
223  const int64_t base,
224  const int mod,
225  const Notify notify) const
226 {
227  switch (type)
228  {
229  case Sp::SPEED:
232  CAST_S32(base),
233  Notify_true);
235  0,
236  Notify_true);
237  break;
238  case Sp::BASEEXP:
240  base,
241  Notify_true);
242  break;
243  case Sp::JOBEXP:
245  base,
246  Notify_true);
247  break;
248  case Sp::KARMA:
250  CAST_S32(base),
251  Notify_true);
253  0,
254  Notify_true);
255  break;
256  case Sp::MANNER:
258  CAST_S32(base),
259  Notify_true);
261  0,
262  Notify_true);
263  break;
264  case Sp::HP:
266  base,
267  Notify_true);
268  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
269  {
270  PartyMember *const m = Party::getParty(1)
272  if (m != nullptr)
273  {
274  m->setHp(CAST_S32(base));
277  }
278  }
279  break;
280  case Sp::MAXHP:
282  base,
283  Notify_true);
284 
285  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
286  {
287  PartyMember *const m = Party::getParty(1)->getMember(
288  localPlayer->getId());
289  if (m != nullptr)
290  {
292  m->setMaxHp(CAST_S32(base));
293  }
294  }
295  break;
296  case Sp::SP:
298  base,
299  Notify_true);
300  break;
301  case Sp::MAXSP:
303  base,
304  Notify_true);
305  break;
306  case Sp::STATUSPOINT:
308  base,
309  Notify_true);
310  break;
311  case Sp::BASELEVEL:
313  base,
314  Notify_true);
315  if (localPlayer != nullptr)
316  {
317  localPlayer->setLevel(CAST_S32(base));
319  }
320  break;
321  case Sp::SKILLPOINT:
323  base,
324  Notify_true);
325  if (skillDialog != nullptr)
326  skillDialog->update();
327  break;
328  case Sp::STR:
330  break;
331  case Sp::AGI:
333  break;
334  case Sp::VIT:
336  break;
337  case Sp::INT:
339  break;
340  case Sp::DEX:
342  break;
343  case Sp::LUK:
345  break;
346  case Sp::ZENY:
347  {
348  const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
349  const int newMoney = CAST_S32(base);
350  if (newMoney > oldMoney)
351  {
353  UnitsDb::formatCurrency(newMoney - oldMoney));
354  }
355  else if (newMoney < oldMoney)
356  {
358  UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
359  }
360 
362  newMoney,
363  Notify_true);
364  break;
365  }
366  case Sp::NEXTBASEEXP:
368  base,
369  Notify_true);
370  break;
371  case Sp::JOB_MOD:
373  base,
374  Notify_true);
375  break;
376  case Sp::WEIGHT:
378  base,
379  Notify_true);
380  break;
381  case Sp::MAXWEIGHT:
383  base,
384  Notify_true);
385  break;
386  case Sp::USTR:
388  CAST_S32(base));
389  break;
390  case Sp::UAGI:
392  CAST_S32(base));
393  break;
394  case Sp::UVIT:
396  CAST_S32(base));
397  break;
398  case Sp::UINT:
400  CAST_S32(base));
401  break;
402  case Sp::UDEX:
404  CAST_S32(base));
405  break;
406  case Sp::ULUK:
408  CAST_S32(base));
409  break;
410  case Sp::ATK1:
412  CAST_S32(base),
413  Notify_true);
415  break;
416  case Sp::ATK2:
418  CAST_S32(base),
419  Notify_true);
421  break;
422  case Sp::MATK1:
424  CAST_S32(base),
425  Notify_true);
426  break;
427  case Sp::MATK2:
429  CAST_S32(base),
430  Notify_true);
431  break;
432  case Sp::DEF1:
434  CAST_S32(base),
435  Notify_true);
436  break;
437  case Sp::DEF2:
439  CAST_S32(base),
440  Notify_true);
441  break;
442  case Sp::MDEF1:
444  CAST_S32(base),
445  Notify_true);
446  break;
447  case Sp::MDEF2:
449  CAST_S32(base),
450  Notify_true);
451  break;
452  case Sp::HIT:
454  CAST_S32(base),
455  Notify_true);
456  break;
457  case Sp::FLEE1:
459  CAST_S32(base),
460  Notify_true);
461  break;
462  case Sp::FLEE2:
464  CAST_S32(base),
465  Notify_true);
466  break;
467  case Sp::CRITICAL:
469  CAST_S32(base),
470  Notify_true);
471  break;
472  case Sp::ASPD:
475  CAST_S32(base),
476  Notify_true);
478  0,
479  Notify_true);
481  break;
482  case Sp::JOBLEVEL:
484  base,
485  Notify_true);
486  break;
487  case Sp::GM_LEVEL:
489  break;
490 
491  default:
493  break;
494  }
495 }
496 
497 #undef setStatComplex
498 
499 void PlayerHandler::selectStyle(const int headColor A_UNUSED,
500  const int headStyle A_UNUSED,
501  const int bodyColor A_UNUSED,
502  const int topStyle A_UNUSED,
503  const int middleStyle A_UNUSED,
504  const int bottomStyle A_UNUSED,
505  const int bodyStyle A_UNUSED) const
506 {
507 }
508 
509 void PlayerHandler::setTitle(const int titleId A_UNUSED) const
510 {
511 }
512 
513 } // namespace TmwAthena
void shortcutShiftRow(const int row) const
Net::PlayerHandler * playerHandler
Definition: net.cpp:93
Definition: sp.h:48
void changeCart(const int type) const
void setAttackSpeed(const int speed)
Definition: being.h:463
int CMSG_PLAYER_CHANGE_DIR
Definition: protocolout.cpp:60
Definition: sp.h:73
static void pushPickup(const BeingId floorId)
void setStatMod(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:157
BeingAction ::T BeingActionT
Definition: beingaction.h:40
#define CAST_U8
Definition: cast.h:26
Definition: sp.h:66
int CMSG_ITEM_PICKUP
Definition: protocolout.cpp:59
void setTitle(const int titleId) const
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:141
#define setStatComplex(stat)
const bool Keep_true
Definition: keep.h:29
int CMSG_PLAYER_CHANGE_DEST
Definition: protocolout.cpp:61
BeingId getId() const
Definition: actorsprite.h:63
Definition: sp.h:45
Definition: sp.h:72
void emote(const uint8_t emoteId) const
Definition: sp.h:52
int BeingId
Definition: beingid.h:29
Definition: sp.h:81
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
Definition: sp.h:62
Definition: sp.h:46
StatusWindow * statusWindow
bool msg(InputEvent &event)
Definition: chat.cpp:38
void notify(const unsigned int message)
void setGroupId(const int id)
int CMSG_PLAYER_CHANGE_ACT
Definition: protocolout.cpp:62
void setWalkSpeed(const int speed)
Definition: being.h:451
void updateAttrs()
Definition: playerinfo.cpp:418
Definition: sp.h:30
Definition: sp.h:77
int CMSG_ONLINE_LIST
Definition: sp.h:33
void setStat(Net::MessageIn &msg, const int type, const int64_t base, const int mod, const Notify notify) const
Definition: sp.h:67
Definition: sp.h:31
#define CAST_U16
Definition: cast.h:28
Definition: sp.h:32
Definition: sp.h:43
#define CAST_S32
Definition: cast.h:29
Definition: sp.h:78
std::string update(const int id)
void updateStatus(const uint8_t status) const
Definition: sp.h:54
void setHp(const int hp)
Definition: avatar.h:92
uint32_t data
static Party * getParty(const int16_t id)
Definition: party.cpp:312
int CMSG_STAT_UPDATE_REQUEST
Definition: protocolout.cpp:48
LocalPlayer * localPlayer
void setAttribute(const AttributesT id, const int64_t value, const Notify notify)
Definition: playerinfo.cpp:108
Definition: sp.h:80
void increaseAttribute(const AttributesT attr, const int amount) const
Definition: sp.h:35
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
Definition: sp.h:64
Definition: sp.h:50
void selectStyle(const int headColor, const int headStyle, const int bodyColor, const int topStyle, const int middleStyle, const int bottomStyle, const int bodyStyle) const
bool isInParty() const
Definition: being.h:320
Definition: sp.h:71
#define createOutPacket(name)
Definition: messageout.h:36
Definition: sp.h:65
Definition: sp.h:37
void setDirection(const unsigned char direction) const
Definition: sp.h:63
void updateName()
Definition: being.cpp:3425
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
void pickUp(const FloorItem *const floorItem) const
#define A_UNUSED
Definition: localconsts.h:159
Definition: sp.h:38
int CMSG_SKILL_LEVELUP_REQUEST
Definition: protocolout.cpp:47
Definition: sp.h:36
void setShortcut(const int idx, const uint8_t type, const int id, const int level) const
Attributes ::T AttributesT
Definition: attributes.h:117
Definition: sp.h:83
void increaseSkill(const uint16_t skillId) const
Definition: sp.h:34
#define CAST_S16
Definition: cast.h:27
int CMSG_PLAYER_RESTART
Definition: protocolout.cpp:63
void setConfigOption(const int id, const int data) const
int CMSG_PLAYER_EMOTE
Definition: protocolout.cpp:64
void setMaxHp(const int maxHp)
Definition: avatar.h:98
Definition: sp.h:76
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
Definition: sp.h:47
Definition: sp.h:44
void attack(const BeingId id, const Keep keep) const
int CMSG_PLAYER_STOP_ATTACK
Definition: protocolout.cpp:65
Definition: sp.h:79
const bool Notify_true
Definition: notify.h:29
void setDestination(const int x, const int y, const int direction) const
Definition: sp.h:74
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:58
void setLevel(const int n)
Definition: being.h:600
Definition: sp.h:75
void changeAction(const BeingActionT &action) const
void setPointsNeeded(const AttributesT id, const int needed)