ManaPlus
skillrecv.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/skillrecv.h"
25 
26 #include "notifymanager.h"
27 
28 #include "being/localplayer.h"
29 #include "being/playerinfo.h"
30 
31 #include "const/net/skill.h"
32 
34 
36 
37 #include "net/messagein.h"
38 
39 #include "utils/gettext.h"
40 
41 #include "debug.h"
42 
43 namespace TmwAthena
44 {
45 
47 {
48  msg.readInt16("len");
49  const int skillCount = (msg.getLength() - 4) / 37;
50  int updateSkill = 0;
51 
52  for (int k = 0; k < skillCount; k++)
53  {
54  const int skillId = msg.readInt16("skill id");
55  const SkillType::SkillType inf = static_cast<SkillType::SkillType>(
56  msg.readInt16("inf"));
57  msg.readInt16("skill pool flags");
58  const int level = msg.readInt16("skill level");
59  const int sp = msg.readInt16("sp");
60  const int range = msg.readInt16("range");
61  msg.skip(24, "unused");
62  const Modifiable up = fromBool(msg.readUInt8("up flag"), Modifiable);
63  const int oldLevel = PlayerInfo::getSkillLevel(skillId);
64  if ((oldLevel != 0) && oldLevel != level)
65  updateSkill = skillId;
66  PlayerInfo::setSkillLevel(skillId, level);
67  if (skillDialog != nullptr)
68  {
69  if (!skillDialog->updateSkill(skillId, range, up, inf, sp))
70  {
72  skillId, "", level, range, up, inf, sp);
73  }
74  }
75  }
76  if (skillDialog != nullptr)
77  {
79  if (updateSkill != 0)
80  skillDialog->playUpdateEffect(updateSkill);
81  }
82 }
83 
85 {
86  // Action failed (ex. sit because you have not reached the
87  // right level)
88  const int skillId = msg.readInt16("skill id");
89  const int16_t bskill = msg.readInt16("bskill");
90  msg.readInt16("btype");
91  const signed char success = msg.readUInt8("success");
92  const signed char reason = msg.readUInt8("reason");
93  if (success != CAST_S32(SKILL_FAILED)
94  && bskill == CAST_S32(BSKILL_EMOTE))
95  {
96  logger->log("Action: %d/%d", bskill, success);
97  }
98 
99  std::string txt;
100  if (success == CAST_S32(SKILL_FAILED)
101  && skillId == CAST_S32(SKILL_BASIC))
102  {
103  if ((localPlayer != nullptr) &&
104  bskill == CAST_S32(BSKILL_EMOTE) &&
105  reason == CAST_S32(RFAIL_SKILLDEP))
106  {
108  }
109 
110  switch (bskill)
111  {
112  case BSKILL_TRADE:
113  // TRANSLATORS: error message
114  txt = _("Trade failed!");
115  break;
116  case BSKILL_EMOTE:
117  // TRANSLATORS: error message
118  txt = _("Emote failed!");
119  break;
120  case BSKILL_SIT:
121  // TRANSLATORS: error message
122  txt = _("Sit failed!");
123  break;
124  case BSKILL_CREATECHAT:
125  // TRANSLATORS: error message
126  txt = _("Chat creating failed!");
127  break;
128  case BSKILL_JOINPARTY:
129  // TRANSLATORS: error message
130  txt = _("Could not join party!");
131  break;
132  case BSKILL_SHOUT:
133  // TRANSLATORS: error message
134  txt = _("Cannot shout!");
135  break;
136  default:
137  UNIMPLEMENTEDPACKETFIELD(bskill);
138  break;
139  }
140 
141  txt.append(" ");
142 
143  switch (reason)
144  {
145  case RFAIL_SKILLDEP:
146  // TRANSLATORS: error message
147  txt.append(_("You have not yet reached a high enough lvl!"));
148  break;
149  case RFAIL_INSUFHP:
150  // TRANSLATORS: error message
151  txt.append(_("Insufficient HP!"));
152  break;
153  case RFAIL_INSUFSP:
154  // TRANSLATORS: error message
155  txt.append(_("Insufficient SP!"));
156  break;
157  case RFAIL_NOMEMO:
158  // TRANSLATORS: error message
159  txt.append(_("You have no memos!"));
160  break;
161  case RFAIL_SKILLDELAY:
162  // TRANSLATORS: error message
163  txt.append(_("You cannot do that right now!"));
164  break;
165  case RFAIL_ZENY:
166  // TRANSLATORS: error message
167  txt.append(_("Seems you need more money... ;-)"));
168  break;
169  case RFAIL_WEAPON:
170  // TRANSLATORS: error message
171  txt.append(_("You cannot use this skill with that "
172  "kind of weapon!"));
173  break;
174  case RFAIL_REDGEM:
175  // TRANSLATORS: error message
176  txt.append(_("You need another red gem!"));
177  break;
178  case RFAIL_BLUEGEM:
179  // TRANSLATORS: error message
180  txt.append(_("You need another blue gem!"));
181  break;
182  case RFAIL_OVERWEIGHT:
183  // TRANSLATORS: error message
184  txt.append(_("You're carrying to much to do this!"));
185  break;
186  default:
187  // TRANSLATORS: error message
188  txt.append(_("Huh? What's that?"));
189  UNIMPLEMENTEDPACKETFIELD(reason);
190  break;
191  }
192  }
193  else
194  {
195  switch (skillId)
196  {
197  case SKILL_WARP :
198  // TRANSLATORS: error message
199  txt = _("Warp failed...");
200  break;
201  case SKILL_STEAL :
202  // TRANSLATORS: error message
203  txt = _("Could not steal anything...");
204  break;
205  case SKILL_ENVENOM :
206  // TRANSLATORS: error message
207  txt = _("Poison had no effect...");
208  break;
209  default:
210  UNIMPLEMENTEDPACKETFIELD(skillId);
211  break;
212  }
213  }
214 
216 }
217 
218 } // namespace TmwAthena
#define fromBool(val, name)
Definition: booldefines.h:49
#define CAST_S32
Definition: cast.h:30
void stopAdvert()
void log(const char *const log_text,...)
Definition: logger.cpp:269
bool updateSkill(const int id, const int range, const Modifiable modifiable, const SkillType::SkillType type, const int sp)
void playUpdateEffect(const int id) const
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)
std::string update(const int id)
#define _(s)
Definition: gettext.h:35
LocalPlayer * localPlayer
Logger * logger
Definition: logger.cpp:89
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
bool Modifiable
Definition: modifiable.h:30
bool msg(InputEvent &event)
Definition: chat.cpp:39
void notify(const unsigned int message)
@ SKILL_FAIL_MESSAGE
Definition: notifytypes.h:107
int getSkillLevel(const int id)
Definition: playerinfo.cpp:120
void setSkillLevel(const int id, const int value)
Definition: playerinfo.cpp:128
void processPlayerSkills(Net::MessageIn &msg)
Definition: skillrecv.cpp:46
void processSkillFailed(Net::MessageIn &msg)
Definition: skillrecv.cpp:84
static const unsigned int RFAIL_BLUEGEM
Definition: skill.h:52
static const unsigned int RFAIL_OVERWEIGHT
Definition: skill.h:53
static const unsigned int BSKILL_SIT
Definition: skill.h:38
static const unsigned int SKILL_STEAL
Definition: skill.h:32
static const unsigned int RFAIL_INSUFHP
Definition: skill.h:46
static const unsigned int RFAIL_INSUFSP
Definition: skill.h:45
static const unsigned int SKILL_ENVENOM
Definition: skill.h:33
static const unsigned int RFAIL_ZENY
Definition: skill.h:49
static const unsigned int BSKILL_TRADE
Definition: skill.h:36
static const unsigned int BSKILL_SHOUT
Definition: skill.h:41
static const unsigned int BSKILL_JOINPARTY
Definition: skill.h:40
static const unsigned int SKILL_BASIC
Definition: skill.h:30
static const unsigned int RFAIL_SKILLDELAY
Definition: skill.h:48
static const unsigned int RFAIL_REDGEM
Definition: skill.h:51
static const unsigned int SKILL_WARP
Definition: skill.h:31
static const unsigned int RFAIL_SKILLDEP
Definition: skill.h:44
static const unsigned int BSKILL_EMOTE
Definition: skill.h:37
static const unsigned int BSKILL_CREATECHAT
Definition: skill.h:39
static const unsigned int RFAIL_WEAPON
Definition: skill.h:50
static const unsigned int RFAIL_NOMEMO
Definition: skill.h:47
static const unsigned int SKILL_FAILED
Definition: skill.h:56
SkillDialog * skillDialog
Definition: skilldialog.cpp:66