Mana
Loading...
Searching...
No Matches
abilityhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "event.h"
25#include "log.h"
26#include "playerinfo.h"
27
28#include "gui/skilldialog.h"
29
30#include "net/tmwa/messagein.h"
31#include "net/tmwa/protocol.h"
32
33#include "utils/gettext.h"
34
36#define SKILL_BASIC 0x0001
37#define SKILL_WARP 0x001b
38#define SKILL_STEAL 0x0032
39#define SKILL_ENVENOM 0x0034
40
42#define BSKILL_TRADE 0x0000
43#define BSKILL_EMOTE 0x0001
44#define BSKILL_SIT 0x0002
45#define BSKILL_CREATECHAT 0x0003
46#define BSKILL_JOINPARTY 0x0004
47#define BSKILL_SHOUT 0x0005
48#define BSKILL_PK 0x0006 // ??
49#define BSKILL_SETALLIGN 0x0007 // ??
50
52#define RFAIL_SKILLDEP 0x00
53#define RFAIL_INSUFSP 0x01
54#define RFAIL_INSUFHP 0x02
55#define RFAIL_NOMEMO 0x03
56#define RFAIL_SKILLDELAY 0x04
57#define RFAIL_ZENY 0x05
58#define RFAIL_WEAPON 0x06
59#define RFAIL_REDGEM 0x07
60#define RFAIL_BLUEGEM 0x08
61#define RFAIL_OVERWEIGHT 0x09
62#define RFAIL_GENERIC 0x0a
63
65#define SKILL_FAILED 0x00
66
68
69namespace TmwAthena {
70
72{
73 static const Uint16 _messages[] = {
77 0
78 };
79 handledMessages = _messages;
80 abilityHandler = this;
81}
82
84{
85 switch (msg.getId())
86 {
87 case SMSG_PLAYER_SKILLS: {
88 msg.readInt16(); // length
89 const int skillCount = (msg.getLength() - 4) / 37;
90
91 for (int k = 0; k < skillCount; k++)
92 {
93 int skillId = msg.readInt16();
94 msg.readInt16(); // target type
95 msg.skip(2); // unused
96 int level = msg.readInt16();
97 msg.readInt16(); // sp
98 msg.readInt16(); // range
99 msg.skip(24); // unused
100 int up = msg.readInt8();
101
102 PlayerInfo::setStatBase(skillId, level);
103 if (skillDialog)
104 skillDialog->setModifiable(skillId, up);
105 }
106 break;
107 }
108
110 {
111 int skillId = msg.readInt16();
112 int level = msg.readInt16();
113 msg.readInt16(); // sp
114 msg.readInt16(); // range
115 int up = msg.readInt8();
116
117 PlayerInfo::setStatBase(skillId, level);
118 skillDialog->setModifiable(skillId, up);
119 }
120 break;
121
123 // Action failed (ex. sit because you have not reached the
124 // right level)
125 int skillId = msg.readInt16();
126 auto btype = msg.readInt16();
127 msg.readInt16(); // zero1
128 msg.readInt8(); // zero2
129 auto type = msg.readInt8();
130 if (btype == BSKILL_EMOTE)
131 {
132 Log::info("Action: %d", btype);
133 }
134
135 std::string msg;
136 if (skillId == SKILL_BASIC)
137 {
138 switch (btype)
139 {
140 case BSKILL_TRADE:
141 msg = _("Trade failed!");
142 break;
143 case BSKILL_EMOTE:
144 msg = _("Emote failed!");
145 break;
146 case BSKILL_SIT:
147 msg = _("Sit failed!");
148 break;
150 msg = _("Chat creating failed!");
151 break;
152 case BSKILL_JOINPARTY:
153 msg = _("Could not join party!");
154 break;
155 case BSKILL_SHOUT:
156 msg = _("Cannot shout!");
157 break;
158 }
159
160 msg += " ";
161
162 switch (type)
163 {
164 case RFAIL_SKILLDEP:
165 msg += _("You have not yet reached a high enough lvl!");
166 break;
167 case RFAIL_INSUFHP:
168 msg += _("Insufficient HP!");
169 break;
170 case RFAIL_INSUFSP:
171 msg += _("Insufficient SP!");
172 break;
173 case RFAIL_NOMEMO:
174 msg += _("You have no memos!");
175 break;
176 case RFAIL_SKILLDELAY:
177 msg += _("You cannot do that right now!");
178 break;
179 case RFAIL_ZENY:
180 msg += _("Seems you need more money... ;-)");
181 break;
182 case RFAIL_WEAPON:
183 msg += _("You cannot use this skill with that kind of weapon!");
184 break;
185 case RFAIL_REDGEM:
186 msg += _("You need another red gem!");
187 break;
188 case RFAIL_BLUEGEM:
189 msg += _("You need another blue gem!");
190 break;
191 case RFAIL_OVERWEIGHT:
192 msg += _("You're carrying to much to do this!");
193 break;
194 default:
195 msg += _("Huh? What's that?");
196 break;
197 }
198 }
199 else
200 {
201 switch (skillId)
202 {
203 case SKILL_WARP:
204 msg = _("Warp failed...");
205 break;
206 case SKILL_STEAL:
207 msg = _("Could not steal anything...");
208 break;
209 case SKILL_ENVENOM:
210 msg = _("Poison had no effect...");
211 break;
212 }
213 }
214
215 serverNotice(msg);
216 break;
217 }
218}
219
221{
222}
223
224void AbilityHandler::useOn(int id, int beingId)
225{
226}
227
228void AbilityHandler::useAt(int id, int x, int y)
229{
230}
231
232void AbilityHandler::useInDirection(int id, int direction)
233{
234}
235
236} // namespace TmwAthena
const uint16_t * handledMessages
void setModifiable(int id, bool modifiable)
void useOn(int id, int beingId) override
void handleMessage(MessageIn &msg) override
void useAt(int id, int x, int y) override
void useInDirection(int id, int direction) override
void use(int id) override
Used for parsing an incoming message from eAthena.
Definition messagein.h:35
void skip(unsigned int length)
Skips a given number of bytes.
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:57
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:46
uint16_t getId() const
Returns the message ID.
Definition messagein.h:42
unsigned int getLength() const
Returns the message length.
Definition messagein.h:47
void serverNotice(const std::string &message)
Definition event.h:319
SkillDialog * skillDialog
Definition game.cpp:97
#define _(s)
Definition gettext.h:38
Net::AbilityHandler * abilityHandler
Definition net.cpp:57
void info(const char *log_text,...) LOG_PRINTF_ATTR
void setStatBase(int id, int value, bool notify)
Changes the base value of the given stat.
Warning: buffers and other variables are shared, so there can be only one connection active at a time...
@ SMSG_PLAYER_SKILLS
Definition protocol.h:263
@ SMSG_SKILL_FAILED
Definition protocol.h:264
@ SMSG_PLAYER_SKILL_UP
Definition protocol.h:262
#define RFAIL_ZENY
#define RFAIL_BLUEGEM
#define RFAIL_SKILLDELAY
#define SKILL_BASIC
job dependend identifiers (?)
#define RFAIL_SKILLDEP
reasons why action failed
#define BSKILL_CREATECHAT
#define RFAIL_INSUFHP
#define RFAIL_REDGEM
#define SKILL_WARP
#define BSKILL_EMOTE
#define SKILL_STEAL
#define RFAIL_NOMEMO
#define BSKILL_SHOUT
#define RFAIL_OVERWEIGHT
#define BSKILL_SIT
#define BSKILL_TRADE
basic skills identifiers
#define RFAIL_INSUFSP
#define BSKILL_JOINPARTY
#define RFAIL_WEAPON
#define SKILL_ENVENOM