From 95fc41ba7d03c570e9305e2e4dfd35c83598fb89 Mon Sep 17 00:00:00 2001 From: eaac Date: Thu, 4 May 2006 20:21:02 +0000 Subject: git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6476 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 88 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 23 deletions(-) (limited to 'src/map/atcommand.c') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 92b27e103..6655ac862 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -7735,33 +7735,75 @@ atcommand_changeleader( *------------------------------------------ *by Upa-Kun */ -int -atcommand_autoloot( - const int fd, struct map_session_data* sd, - const char* command, const char* message) +int atcommand_autoloot(const int fd, struct map_session_data* sd, const char* command, const char* message) { - int rate; - double drate; nullpo_retr(-1, sd); - if (!message || !*message) { - if (sd->state.autoloot) - rate = 0; - else - rate = 10000; - } else { - drate = atof(message); - rate = (int)(drate*100); + + // autoloot command without value + if(!message || !*message) + { + // autoloot on -> off + if(sd->state.autoloot) + { + clif_displaymessage(fd, "Autoloot is now off."); + sd->state.autoloot = 0; + return 0; + // autoloot off -> on + } else { + clif_displaymessage(fd, "Autoloot is now on."); + sd->state.autoloot = 10000; + return 0; + } } - if (rate < 0) rate = 0; - + + // autoloot command with value + unsigned int rate; + + // get maximum droprate limit + rate = atoi(message) * 100; + + // check for invalid value + if(rate < 0 || rate > 10000) + { + clif_displaymessage(fd, "Invalid value. Choose value between 0 and 100."); + return 0; + } + + // autoloot value is 0, turn autoloot off + if(rate == 0) + { + if(sd->state.autoloot == 0) + { + clif_displaymessage(fd, "Autoloot is already off."); + return 0; + } else { + clif_displaymessage(fd, "Autoloot is now off."); + sd->state.autoloot = 0; + return 0; + } + } + + // autoloot value is 100, turn autoloot on + if(rate == 10000) + { + if(sd->state.autoloot == 10000) + { + clif_displaymessage(fd, "Autoloot is already on."); + return 0; + } else { + clif_displaymessage(fd, "Autoloot is now on."); + sd->state.autoloot = 10000; + return 0; + } + } + + // autoloot value is between 0 and 100 + snprintf(atcmd_output, sizeof atcmd_output, "Autolooting items with drop rates of %d percent and below.", (rate / 100)); + clif_displaymessage(fd, atcmd_output); sd->state.autoloot = rate; - if (sd->state.autoloot) { - snprintf(atcmd_output, sizeof atcmd_output, "Autolooting items with drop rates of %0.02f%% and below.",((double)sd->state.autoloot)/100.); - clif_displaymessage(fd, atcmd_output); - }else - clif_displaymessage(fd, "Autoloot is now off."); - return 0; -} + + return 0; +} /*========================================== -- cgit v1.2.3-70-g09d2