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!
This commit is contained in:
aleos 2017-04-06 18:42:10 -04:00
parent 39e54d65bb
commit d6594eefda
3 changed files with 34 additions and 23 deletions

View File

@ -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;
* 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;
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();
//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();

View File

@ -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);

View File

@ -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;
}