Browse Source

Added "clear" for item group
* It is: <IG>,clear,0,0

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>

Cydh Ramdh 10 years ago
parent
commit
72a831aa2f
1 changed files with 17 additions and 20 deletions
  1. 17 20
      src/map/itemdb.c

+ 17 - 20
src/map/itemdb.c

@@ -556,13 +556,15 @@ static bool itemdb_read_itemavail(char* str[], int columns, int current) {
 	return true;
 	return true;
 }
 }
 
 
+static int itemdb_group_free(DBKey key, DBData *data, va_list ap);
+
 /** Read item group data
 /** Read item group data
 * Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,GUID,isBound,isNamed}
 * Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,GUID,isBound,isNamed}
 */
 */
 static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 {
 {
 	FILE *fp;
 	FILE *fp;
-	int ln=0, entries=0;
+	int ln = 0, entries = 0;
 	char line[1024];
 	char line[1024];
 
 
 	if ((fp=fopen(filename,"r")) == NULL) {
 	if ((fp=fopen(filename,"r")) == NULL) {
@@ -571,6 +573,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 	}
 	}
 	
 	
 	while (fgets(line,sizeof(line),fp)) {
 	while (fgets(line,sizeof(line),fp)) {
+		DBData data;
 		int group_id = -1;
 		int group_id = -1;
 		unsigned int j, prob = 1;
 		unsigned int j, prob = 1;
 		uint8 rand_group = 1;
 		uint8 rand_group = 1;
@@ -623,6 +626,13 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 			continue;
 			continue;
 		}
 		}
 
 
+		// Remove from DB
+		if (strcmpi(str[1], "clear") == 0 && itemdb_group->remove(itemdb_group, db_ui2key(group_id), &data)) {
+			itemdb_group_free(db_ui2key(group_id), &data, 0);
+			ShowNotice("Item Group '%s' has been cleared.\n", str[0]);
+			continue;
+		}
+
 		// Checking sub group
 		// Checking sub group
 		prob = atoi(str[2]);
 		prob = atoi(str[2]);
 		if (str[4] != NULL)
 		if (str[4] != NULL)
@@ -639,10 +649,8 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 
 
 		// Checking item
 		// Checking item
 		trim(str[1]);
 		trim(str[1]);
-		if (ISDIGIT(str[1][0])) {
-			if (itemdb_exists((entry.nameid = atoi(str[1]))))
-				found = true;
-		}
+		if (ISDIGIT(str[1][0]) && ISDIGIT(str[1][1]) && itemdb_exists((entry.nameid = atoi(str[1]))))
+			found = true;
 		else {
 		else {
 			struct item_data *id = itemdb_searchname(str[1]);
 			struct item_data *id = itemdb_searchname(str[1]);
 			if (id) {
 			if (id) {
@@ -650,6 +658,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 				found = true;
 				found = true;
 			}
 			}
 		}
 		}
+
 		if (!found) {
 		if (!found) {
 			ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
 			ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
 			continue;
 			continue;
@@ -672,14 +681,8 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 
 
 		// Must item (rand_group == 0), place it here
 		// Must item (rand_group == 0), place it here
 		if (!rand_group) {
 		if (!rand_group) {
-			uint16 idx = group->must_qty;
-			if (!idx)
-				CREATE(group->must, struct s_item_group_entry, 1);
-			else
-				RECREATE(group->must, struct s_item_group_entry, idx+1);
-
-			group->must[idx] = entry;
-			group->must_qty++;
+			RECREATE(group->must, struct s_item_group_entry, group->must_qty+1);
+			group->must[group->must_qty++] = entry;
 
 
 			// If 'must' item isn't set as random item, skip the next process
 			// If 'must' item isn't set as random item, skip the next process
 			if (!prob) {
 			if (!prob) {
@@ -693,13 +696,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
 
 
 		random = &group->random[rand_group];
 		random = &group->random[rand_group];
 
 
-		// Check, if the entry for this random group already created or not
-		if (!random->data_qty) {
-			CREATE(random->data, struct s_item_group_entry, prob);
-			random->data_qty = 0;
-		}
-		else
-			RECREATE(random->data, struct s_item_group_entry, random->data_qty+prob);
+		RECREATE(random->data, struct s_item_group_entry, random->data_qty+prob);
 
 
 		// Put the entry to its rand_group
 		// Put the entry to its rand_group
 		for (j = random->data_qty; j < random->data_qty+prob; j++)
 		for (j = random->data_qty; j < random->data_qty+prob; j++)