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