瀏覽代碼

Corrected the problem with countitem2 (value wrapped-around in one case but not in the other, making comparisons fail)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10573 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 18 年之前
父節點
當前提交
bac04aa3aa
共有 2 個文件被更改,包括 64 次插入67 次删除
  1. 2 0
      Changelog-Trunk.txt
  2. 62 67
      src/map/script.c

+ 2 - 0
Changelog-Trunk.txt

@@ -3,6 +3,8 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
+2007/05/19
+	* Corrected the problem with countitem2 [ultramage]
 2007/05/14
 	* Updated sql files [Toms]
 2007/05/11

+ 62 - 67
src/map/script.c

@@ -5488,101 +5488,96 @@ BUILDIN_FUNC(viewpoint)
  */
 BUILDIN_FUNC(countitem)
 {
-	int nameid=0,count=0,i;
-	TBL_PC *sd;
-
-	struct script_data *data;
-
-	sd = script_rid2sd(st);
+	int nameid, i;
+	int count = 0;
+	struct script_data* data;
 
+	TBL_PC* sd = script_rid2sd(st);
 	if (!sd) {
 		script_pushint(st,0);
 		return 0;
 	}
 
-	data=script_getdata(st,2);
+	data = script_getdata(st,2);
 	get_val(st,data);
-	if( data_isstring(data) ){
-		const char *name=conv_str(st,data);
-		struct item_data *item_data;
-		if( (item_data = itemdb_searchname(name)) != NULL)
-			nameid=item_data->nameid;
-	}else
-		nameid=conv_num(st,data);
+	if( data_isstring(data) ) {
+		const char* name = conv_str(st,data);
+		struct item_data* item_data;
+		if((item_data = itemdb_searchname(name)) != NULL)
+			nameid = item_data->nameid;
+		else
+			nameid = 0;
+	} else
+		nameid = conv_num(st,data);
 
-	if (nameid>=500) //if no such ID then skip this iteration
-		for(i=0;i<MAX_INVENTORY;i++){
-			if(sd->status.inventory[i].nameid==nameid)
-				count+=sd->status.inventory[i].amount;
-		}
-	else{
-		if(battle_config.error_log)
-			ShowError("wrong item ID : countitem(%i)\n",nameid);
+	if (nameid < 500) {
+		if(battle_config.error_log) ShowError("wrong item ID : countitem(%i)\n", nameid);
 		script_pushint(st,0);
 		return 1;
 	}
+
+	for(i = 0; i < MAX_INVENTORY; i++)
+		if(sd->status.inventory[i].nameid == nameid)
+			count += sd->status.inventory[i].amount;
+
 	script_pushint(st,count);
 	return 0;
 }
 
 /*==========================================
  * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3)	[Lupus]
- *	returns number of items that met the conditions
- *------------------------------------------
- */
+ *	returns number of items that meet the conditions
+ *------------------------------------------*/
 BUILDIN_FUNC(countitem2)
 {
-	int nameid=0,count=0,i;
-	int iden,ref,attr,c1,c2,c3,c4;
-	TBL_PC *sd;
-
-	struct script_data *data;
-
-	sd = script_rid2sd(st);
-
+	int nameid, iden, ref, attr, c1, c2, c3, c4;
+	int count = 0;
+	int i;	
+	struct script_data* data;
+	
+	TBL_PC* sd = script_rid2sd(st);
 	if (!sd) {
 		script_pushint(st,0);
 		return 0;
 	}
-
-	data=script_getdata(st,2);
+	
+	data = script_getdata(st,2);
 	get_val(st,data);
-	if( data_isstring(data) ){
-		const char *name=conv_str(st,data);
-		struct item_data *item_data;
-		if( (item_data = itemdb_searchname(name)) != NULL)
-			nameid=item_data->nameid;
-	}else
-		nameid=conv_num(st,data);
-
-	iden=script_getnum(st,3);
-	ref=script_getnum(st,4);
-	attr=script_getnum(st,5);
-	c1=script_getnum(st,6);
-	c2=script_getnum(st,7);
-	c3=script_getnum(st,8);
-	c4=script_getnum(st,9);
-
-	if (nameid>=500) //if no such ID then skip this iteration
-		for(i=0;i<MAX_INVENTORY;i++){
-		if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
-			sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
-			sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
-			sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
-			sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
-			sd->status.inventory[i].card[3]!=c4)
-			continue;
-
-			count+=sd->status.inventory[i].amount;
-		}
-	else{
-		if(battle_config.error_log)
-			ShowError("wrong item ID : countitem2(%i)\n",nameid);
+	if( data_isstring(data) ) {
+		const char* name = conv_str(st,data);
+		struct item_data* item_data;
+		if((item_data = itemdb_searchname(name)) != NULL)
+			nameid = item_data->nameid;
+		else
+			nameid = 0;
+	} else
+		nameid = conv_num(st,data);
+	
+	iden = script_getnum(st,3);
+	ref  = script_getnum(st,4);
+	attr = script_getnum(st,5);
+	c1 = (short)script_getnum(st,6);
+	c2 = (short)script_getnum(st,7);
+	c3 = (short)script_getnum(st,8);
+	c4 = (short)script_getnum(st,9);
+	
+	if (nameid < 500) {
+		if(battle_config.error_log) ShowError("wrong item ID : countitem2(%i)\n", nameid);
 		script_pushint(st,0);
 		return 1;
 	}
-	script_pushint(st,count);
+	
+	for(i = 0; i < MAX_INVENTORY; i++)
+		if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] != NULL &&
+			sd->status.inventory[i].amount > 0 && sd->status.inventory[i].nameid == nameid &&
+			sd->status.inventory[i].identify == iden && sd->status.inventory[i].refine == ref &&
+			sd->status.inventory[i].attribute == attr && sd->status.inventory[i].card[0] == c1 &&
+			sd->status.inventory[i].card[1] == c2 && sd->status.inventory[i].card[2] ==c3 &&
+			sd->status.inventory[i].card[3] == c4
+		)
+			count += sd->status.inventory[i].amount;
 
+	script_pushint(st,count);
 	return 0;
 }