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 
210 void PlayerHandler::setViewEquipment(const bool allow A_UNUSED) const
211 {
212 }
213 
214 #define setStatComplex(stat) \
215  PlayerInfo::setStatBase(stat, base, notify); \
216  if (mod != NoStat) \
217  PlayerInfo::setStatMod(stat, mod, Notify_true)
218 
220  const int type,
221  const int64_t base,
222  const int mod,
223  const Notify notify) const
224 {
225  switch (type)
226  {
227  case Sp::SPEED:
228  localPlayer->setWalkSpeed(base);
230  base,
231  Notify_true);
233  0,
234  Notify_true);
235  break;
236  case Sp::BASEEXP:
238  base,
239  Notify_true);
240  break;
241  case Sp::JOBEXP:
243  base,
244  Notify_true);
245  break;
246  case Sp::KARMA:
248  base,
249  Notify_true);
251  0,
252  Notify_true);
253  break;
254  case Sp::MANNER:
256  base,
257  Notify_true);
259  0,
260  Notify_true);
261  break;
262  case Sp::HP:
264  base,
265  Notify_true);
266  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
267  {
268  PartyMember *const m = Party::getParty(1)
270  if (m != nullptr)
271  {
272  m->setHp(base);
275  }
276  }
277  break;
278  case Sp::MAXHP:
280  base,
281  Notify_true);
282 
283  if (localPlayer->isInParty() && (Party::getParty(1) != nullptr))
284  {
285  PartyMember *const m = Party::getParty(1)->getMember(
286  localPlayer->getId());
287  if (m != nullptr)
288  {
290  m->setMaxHp(base);
291  }
292  }
293  break;
294  case Sp::SP:
296  base,
297  Notify_true);
298  break;
299  case Sp::MAXSP:
301  base,
302  Notify_true);
303  break;
304  case Sp::STATUSPOINT:
306  base,
307  Notify_true);
308  break;
309  case Sp::BASELEVEL:
311  base,
312  Notify_true);
313  if (localPlayer != nullptr)
314  {
315  localPlayer->setLevel(base);
317  }
318  break;
319  case Sp::SKILLPOINT:
321  base,
322  Notify_true);
323  if (skillDialog != nullptr)
324  skillDialog->update();
325  break;
326  case Sp::STR:
328  break;
329  case Sp::AGI:
331  break;
332  case Sp::VIT:
334  break;
335  case Sp::INT:
337  break;
338  case Sp::DEX:
340  break;
341  case Sp::LUK:
343  break;
344  case Sp::ZENY:
345  {
346  const int oldMoney = PlayerInfo::getAttribute(Attributes::MONEY);
347  const int newMoney = base;
348  if (newMoney > oldMoney)
349  {
351  UnitsDb::formatCurrency(newMoney - oldMoney));
352  }
353  else if (newMoney < oldMoney)
354  {
356  UnitsDb::formatCurrency(oldMoney - newMoney).c_str());
357  }
358 
360  newMoney,
361  Notify_true);
362  break;
363  }
364  case Sp::NEXTBASEEXP:
366  base,
367  Notify_true);
368  break;
369  case Sp::JOB_MOD:
371  base,
372  Notify_true);
373  break;
374  case Sp::WEIGHT:
376  base,
377  Notify_true);
378  break;
379  case Sp::MAXWEIGHT:
381  base,
382  Notify_true);
383  break;
384  case Sp::USTR:
386  break;
387  case Sp::UAGI:
389  break;
390  case Sp::UVIT:
392  break;
393  case Sp::UINT:
395  break;
396  case Sp::UDEX:
398  break;
399  case Sp::ULUK:
401  break;
402  case Sp::ATK1:
404  base,
405  Notify_true);
407  break;
408  case Sp::ATK2:
410  base,
411  Notify_true);
413  break;
414  case Sp::MATK1:
416  base,
417  Notify_true);
418  break;
419  case Sp::MATK2:
421  base,
422  Notify_true);
423  break;
424  case Sp::DEF1:
426  base,
427  Notify_true);
428  break;
429  case Sp::DEF2:
431  base,
432  Notify_true);
433  break;
434  case Sp::MDEF1:
436  base,
437  Notify_true);
438  break;
439  case Sp::MDEF2:
441  base,
442  Notify_true);
443  break;
444  case Sp::HIT:
446  base,
447  Notify_true);
448  break;
449  case Sp::FLEE1:
451  base,
452  Notify_true);
453  break;
454  case Sp::FLEE2:
456  base,
457  Notify_true);
458  break;
459  case Sp::CRITICAL:
461  base,
462  Notify_true);
463  break;
464  case Sp::ASPD:
467  base,
468  Notify_true);
470  0,
471  Notify_true);
473  break;
474  case Sp::JOBLEVEL:
476  base,
477  Notify_true);
478  break;
479  case Sp::GM_LEVEL:
480  localPlayer->setGroupId(base);
481  break;
482 
483  default:
485  break;
486  }
487 }
488 
489 #undef setStatComplex
490 
491 } // namespace TmwAthena
void shortcutShiftRow(const int row) const
Net::PlayerHandler * playerHandler
Definition: net.cpp:89
Definition: sp.h:48
void changeCart(const int type) const
void setAttackSpeed(const int speed)
Definition: being.h:457
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
void setViewEquipment(const bool allow) const
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:445
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
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
static Party * getParty(const int16_t id)
Definition: party.cpp:313
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:99
Definition: sp.h:64
Definition: sp.h:50
bool isInParty() const
Definition: being.h:314
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:3399
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
void pickUp(const FloorItem *const floorItem) const
#define A_UNUSED
Definition: localconsts.h:171
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
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:594
Definition: sp.h:75
void changeAction(const BeingActionT &action) const
void setPointsNeeded(const AttributesT id, const int needed)