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 {
165 }
166 
168 {
169 }
170 
171 void PlayerHandler::changeCart(const int type A_UNUSED) const
172 {
173 }
174 
176 {
177 }
178 
179 void PlayerHandler::updateStatus(const uint8_t status A_UNUSED) const
180 {
181 }
182 
184  const uint8_t type A_UNUSED,
185  const int id A_UNUSED,
186  const int level A_UNUSED) const
187 {
188 }
189 
191 {
192 }
193 
195 {
196 }
197 
199 {
200 }
201 
203 {
204 }
205 
206 void PlayerHandler::shortcutShiftRow(const int row A_UNUSED) const
207 {
208 }
209 
211  const int data A_UNUSED) const
212 {
213 }
214 
215 #define setStatComplex(stat) \
216  PlayerInfo::setStatBase(stat, CAST_S32(base), notify); \
217  if (mod != NoStat) \
218  PlayerInfo::setStatMod(stat, mod, Notify_true)
219 
221  const int type,
222  const int64_t base,
223  const int mod,
224  const Notify notify) const
225 {
226  switch (type)
227  {
228  case Sp::SPEED:
231  CAST_S32(base),
232  Notify_true);
234  0,
235  Notify_true);
236  break;
237  case Sp::BASEEXP:
239  base,
240  Notify_true);
241  break;
242  case Sp::JOBEXP:
244  base,
245  Notify_true);
246  break;
247  case Sp::KARMA:
249  CAST_S32(base),
250  Notify_true);
252  0,
253  Notify_true);
254  break;
255  case Sp::MANNER:
257  CAST_S32(base),
258  Notify_true);
260  0,
261  Notify_true);
262  break;
263  case Sp::HP:
265  base,
266  Notify_true);
267  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
268  {
269  PartyMember *const m = Party::getParty(1)
271  if (m != nullptr)
272  {
273  m->setHp(CAST_S32(base));
276  }
277  }
278  break;
279  case Sp::MAXHP:
281  base,
282  Notify_true);
283 
284  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
285  {
286  PartyMember *const m = Party::getParty(1)->getMember(
287  localPlayer->getId());
288  if (m != nullptr)
289  {
291  m->setMaxHp(CAST_S32(base));
292  }
293  }
294  break;
295  case Sp::SP:
297  base,
298  Notify_true);
299  break;
300  case Sp::MAXSP:
302  base,
303  Notify_true);
304  break;
305  case Sp::STATUSPOINT:
307  base,
308  Notify_true);
309  break;
310  case Sp::BASELEVEL:
312  base,
313  Notify_true);
314  if (localPlayer != nullptr)
315  {
316  localPlayer->setLevel(CAST_S32(base));
318  }
319  break;
320  case Sp::SKILLPOINT:
322  base,
323  Notify_true);
324  if (skillDialog != nullptr)
325  skillDialog->update();
326  break;
327  case Sp::STR:
329  break;
330  case Sp::AGI:
332  break;
333  case Sp::VIT:
335  break;
336  case Sp::INT:
338  break;
339  case Sp::DEX:
341  break;
342  case Sp::LUK:
344  break;
345  case Sp::ZENY:
346  {
347  const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
348  const int newMoney = CAST_S32(base);
349  if (newMoney > oldMoney)
350  {
352  UnitsDb::formatCurrency(newMoney - oldMoney));
353  }
354  else if (newMoney < oldMoney)
355  {
357  UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
358  }
359 
361  newMoney,
362  Notify_true);
363  break;
364  }
365  case Sp::NEXTBASEEXP:
367  base,
368  Notify_true);
369  break;
370  case Sp::JOB_MOD:
372  base,
373  Notify_true);
374  break;
375  case Sp::WEIGHT:
377  base,
378  Notify_true);
379  break;
380  case Sp::MAXWEIGHT:
382  base,
383  Notify_true);
384  break;
385  case Sp::USTR:
387  CAST_S32(base));
388  break;
389  case Sp::UAGI:
391  CAST_S32(base));
392  break;
393  case Sp::UVIT:
395  CAST_S32(base));
396  break;
397  case Sp::UINT:
399  CAST_S32(base));
400  break;
401  case Sp::UDEX:
403  CAST_S32(base));
404  break;
405  case Sp::ULUK:
407  CAST_S32(base));
408  break;
409  case Sp::ATK1:
411  CAST_S32(base),
412  Notify_true);
414  break;
415  case Sp::ATK2:
417  CAST_S32(base),
418  Notify_true);
420  break;
421  case Sp::MATK1:
423  CAST_S32(base),
424  Notify_true);
425  break;
426  case Sp::MATK2:
428  CAST_S32(base),
429  Notify_true);
430  break;
431  case Sp::DEF1:
433  CAST_S32(base),
434  Notify_true);
435  break;
436  case Sp::DEF2:
438  CAST_S32(base),
439  Notify_true);
440  break;
441  case Sp::MDEF1:
443  CAST_S32(base),
444  Notify_true);
445  break;
446  case Sp::MDEF2:
448  CAST_S32(base),
449  Notify_true);
450  break;
451  case Sp::HIT:
453  CAST_S32(base),
454  Notify_true);
455  break;
456  case Sp::FLEE1:
458  CAST_S32(base),
459  Notify_true);
460  break;
461  case Sp::FLEE2:
463  CAST_S32(base),
464  Notify_true);
465  break;
466  case Sp::CRITICAL:
468  CAST_S32(base),
469  Notify_true);
470  break;
471  case Sp::ASPD:
474  CAST_S32(base),
475  Notify_true);
477  0,
478  Notify_true);
480  break;
481  case Sp::JOBLEVEL:
483  base,
484  Notify_true);
485  break;
486  case Sp::GM_LEVEL:
488  break;
489 
490  default:
492  break;
493  }
494 }
495 
496 #undef setStatComplex
497 
498 void PlayerHandler::selectStyle(const int headColor A_UNUSED,
499  const int headStyle A_UNUSED,
500  const int bodyColor A_UNUSED,
501  const int topStyle A_UNUSED,
502  const int middleStyle A_UNUSED,
503  const int bottomStyle A_UNUSED,
504  const int bodyStyle A_UNUSED) const
505 {
506 }
507 
508 } // namespace TmwAthena
void shortcutShiftRow(const int row) const
Net::PlayerHandler * playerHandler
Definition: net.cpp:92
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 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:417
Definition: sp.h:30
Definition: sp.h:77
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:151
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)