summaryrefslogtreecommitdiff
path: root/src/map/atcommand.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-09-30 15:47:01 +0200
committerHaru <haru@dotalux.com>2015-09-30 15:50:18 +0200
commit3da7b91954625050c0e82f843e88b45c169d6dd5 (patch)
tree6800fd4ac2b2fa9c044dcc0494b8885fafcfaf47 /src/map/atcommand.c
parentd52dde700d0f1a598ebea87844007ff610352114 (diff)
downloadhercules-3da7b91954625050c0e82f843e88b45c169d6dd5.tar.gz
hercules-3da7b91954625050c0e82f843e88b45c169d6dd5.tar.bz2
hercules-3da7b91954625050c0e82f843e88b45c169d6dd5.tar.xz
hercules-3da7b91954625050c0e82f843e88b45c169d6dd5.zip
Refactored ACMD(jobchange)
- Follow-up to 7064ec3. - Fixes a logic issue issue preventing the command's help message to be shown when no arguments are specified. - Fixes #759, thanks to theultramage. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r--src/map/atcommand.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index beeccaddd..37f50dc5e 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -967,65 +967,64 @@ ACMD(hide) {
/*==========================================
* Changes a character's class
*------------------------------------------*/
-ACMD(jobchange) {
+ACMD(jobchange)
+{
int job = 0, upper = 0;
- const char* text;
-
- if (!*message || sscanf(message, "%12d %12d", &job, &upper) < 1) {
- upper = 0;
-
- if (*message) {
- int i;
- bool found = false;
+ bool found = false;
- // Normal Jobs
- for( i = JOB_NOVICE; i < JOB_MAX_BASIC && !found; i++ ) {
- if (strncmpi(message, pc->job_name(i), 16) == 0) {
- job = i;
- found = true;
- }
- }
+ if (*message == '\0') { // No message, just show the list
+ found = false;
+ } else if (sscanf(message, "%12d %12d", &job, &upper) >= 1) { // Numeric job ID
+ found = true;
+ } else { // Job name
+ int i;
- // High Jobs, Babies and Third
- for( i = JOB_NOVICE_HIGH; i < JOB_MAX && !found; i++ ){
- if (strncmpi(message, pc->job_name(i), 16) == 0) {
- job = i;
- found = true;
- }
+ // Normal Jobs
+ for (i = JOB_NOVICE; !found && i < JOB_MAX_BASIC; i++) {
+ if (strncmpi(message, pc->job_name(i), 16) == 0) {
+ job = i;
+ found = true;
+ break;
}
+ }
- if (!found) {
- text = atcommand_help_string(info);
- if (text)
- clif->messageln(fd, text);
- return false;
+ // High Jobs, Babies and Third
+ for (i = JOB_NOVICE_HIGH; !found && i < JOB_MAX; i++) {
+ if (strncmpi(message, pc->job_name(i), 16) == 0) {
+ job = i;
+ found = true;
+ break;
}
}
}
- /* WHY DO WE LIST THEM THEN? */
+
+ if (!found || !pc->db_checkid(job)) {
+ const char *text = atcommand_help_string(info);
+ if (text)
+ clif->messageln(fd, text);
+ return false;
+ }
+
// Deny direct transformation into dummy jobs
- if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2 || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER
- || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2 || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2 || job == JOB_STAR_GLADIATOR2
- || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
+ if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2
+ || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER
+ || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2
+ || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2
+ || job == JOB_STAR_GLADIATOR2
+ || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2)
+ || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
) {
+ /* WHY DO WE LIST THEM THEN? */
clif->message(fd, msg_fd(fd,923)); //"You can not change to this job by command."
return true;
}
- if (pc->db_checkid(job)) {
- if (pc->jobchange(sd, job, upper) == 0)
- clif->message(fd, msg_fd(fd,12)); // Your job has been changed.
- else {
- clif->message(fd, msg_fd(fd,155)); // You are unable to change your job.
- return false;
- }
- } else {
- text = atcommand_help_string(info);
- if (text)
- clif->messageln(fd, text);
+ if (pc->jobchange(sd, job, upper) != 0) {
+ clif->message(fd, msg_fd(fd,155)); // You are unable to change your job.
return false;
}
+ clif->message(fd, msg_fd(fd,12)); // Your job has been changed.
return true;
}