浏览代码

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6476 54d463be-8e91-2dee-dedb-b68131a5f0ec

eaac 19 年之前
父节点
当前提交
6366ef616f
共有 2 个文件被更改,包括 68 次插入23 次删除
  1. 3 0
      Changelog-Trunk.txt
  2. 65 23
      src/map/atcommand.c

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/05/04
+	* Improved atcommand autoloot, now displays droprate in percents and notices
+	  player if autoloot is already on or off. Also simplified the code [Harbin, Kain],
+	  commited by erKURITA
 	* Added one grace range in the mob_loot search function which should fix
 	  mob_can_reach failing when invoked with the same distance that distance_bl
 	  returned. [Skotlex]

+ 65 - 23
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;
+}
 
 
 /*==========================================