Prechádzať zdrojové kódy

Re-link monster drop data with item data
* Fixes script commands addmonsterdrop and delmonsterdrop to update the monster drop data that is stored within the item data struct.
* This refreshes atcommand whodrops and other functions that use this data.
Thanks to @technoken!

aleos 8 rokov pred
rodič
commit
d6594eefda
3 zmenil súbory, kde vykonal 34 pridanie a 23 odobranie
  1. 31 23
      src/map/itemdb.c
  2. 1 0
      src/map/itemdb.h
  3. 2 0
      src/map/script.c

+ 31 - 23
src/map/itemdb.c

@@ -1813,32 +1813,16 @@ static int itemdb_randomopt_free(DBKey key, DBData *data, va_list ap) {
 }
 
 /**
-* Reload Item DB
-*/
-void itemdb_reload(void) {
-	struct s_mapiterator* iter;
-	struct map_session_data* sd;
-
-	int i,d,k;
-
-	itemdb_group->clear(itemdb_group, itemdb_group_free);
-	itemdb_randomopt->clear(itemdb_randomopt, itemdb_randomopt_free);
-	itemdb->clear(itemdb, itemdb_final_sub);
-	db_clear(itemdb_combo);
-	if (battle_config.feature_roulette)
-		itemdb_roulette_free();
-
-	// read new data
-	itemdb_read();
-	cashshop_reloaddb();
-
-	if (battle_config.feature_roulette)
-		itemdb_parse_roulette_db();
+ * Re-link monster drop data with item data
+ * Fixes the need of a @reloadmobdb after a @reloaditemdb
+ * @author Epoque
+ */
+void itemdb_reload_itemmob_data(void) {
+	int i;
 
-	//Epoque's awesome @reloaditemdb fix - thanks! [Ind]
-	//- Fixes the need of a @reloadmobdb after a @reloaditemdb to re-link monster drop data
 	for( i = 0; i < MAX_MOB_DB; i++ ) {
 		struct mob_db *entry = mob_db(i);
+		int d, k;
 
 		for(d = 0; d < MAX_MOB_DROP; d++) {
 			struct item_data *id;
@@ -1860,6 +1844,30 @@ void itemdb_reload(void) {
 			id->mob[k].id = i;
 		}
 	}
+}
+
+/**
+* Reload Item DB
+*/
+void itemdb_reload(void) {
+	struct s_mapiterator* iter;
+	struct map_session_data* sd;
+
+	itemdb_group->clear(itemdb_group, itemdb_group_free);
+	itemdb_randomopt->clear(itemdb_randomopt, itemdb_randomopt_free);
+	itemdb->clear(itemdb, itemdb_final_sub);
+	db_clear(itemdb_combo);
+	if (battle_config.feature_roulette)
+		itemdb_roulette_free();
+
+	// read new data
+	itemdb_read();
+	cashshop_reloaddb();
+
+	if (battle_config.feature_roulette)
+		itemdb_parse_roulette_db();
+
+	itemdb_reload_itemmob_data();
 
 	// readjust itemdb pointer cache for each player
 	iter = mapit_geteachpc();

+ 1 - 0
src/map/itemdb.h

@@ -920,6 +920,7 @@ bool itemdb_parse_roulette_db(void);
 
 struct s_random_opt_data *itemdb_randomopt_exists(short id);
 
+void itemdb_reload_itemmob_data(void);
 void itemdb_reload(void);
 
 void do_final_itemdb(void);

+ 2 - 0
src/map/script.c

@@ -16702,6 +16702,7 @@ BUILDIN_FUNC(addmonsterdrop)
 		if(c) { //Fill in the slot with the item and rate
 			mob->dropitem[c].nameid = item_id;
 			mob->dropitem[c].p = (rate > 10000)?10000:rate;
+			itemdb_reload_itemmob_data(); // Reload the mob search data stored in the item_data
 			script_pushint(st,1);
 		} else //No place to put the new drop
 			script_pushint(st,0);
@@ -16747,6 +16748,7 @@ BUILDIN_FUNC(delmonsterdrop)
 			if(mob->dropitem[i].nameid == item_id) {
 				mob->dropitem[i].nameid = 0;
 				mob->dropitem[i].p = 0;
+				itemdb_reload_itemmob_data(); // Reload the mob search data stored in the item_data
 				script_pushint(st,1);
 				return SCRIPT_CMD_SUCCESS;
 			}