/*-------------------------------------- * Adds maps to the instance *--------------------------------------*/ int instance_addmap(short instance_id) { int i, m; int cnt_map = 0; struct instance_data *im; struct instance_db *db; struct party_data *p; if(instance_id <= 0) return 0; im = &instance_data[instance_id]; // If the instance isn't idle, we can't do anything if(im->state != INSTANCE_IDLE) return 0; if((db = instance_searchtype_db(im->type)) == NULL) return 0; // Set to busy, update timers im->state = INSTANCE_BUSY; im->idle_limit = (unsigned int)time(NULL) + INSTANCE_LIMIT / 1000; im->idle_timer = add_timer(gettick() + INSTANCE_LIMIT, instance_delete_timer, instance_id, 0); // Add the maps for(i = 0; i < db->maplist_count; i++) { if(strlen(StringBuf_Value(db->maplist[i])) < 1) continue; else if((m = map_addinstancemap(StringBuf_Value(db->maplist[i]), instance_id)) < 0) { // An error occured adding a map ShowError("instance_addmap: No maps added to instance %d.\n",instance_id); return 0; } else { im->map[cnt_map].m = m; im->map[cnt_map].src_m = map_mapname2mapid(StringBuf_Value(db->maplist[i])); cnt_map++; } } im->cnt_map = cnt_map; // Create NPCs on all maps instance_addnpc(im); // Inform party members of the created instance if((p = party_search(im->party_id)) != NULL) clif_instance_status(party_getavailablesd(p), StringBuf_Value(db->name), im->keep_limit, im->idle_limit, 1); return cnt_map; }
/*========================================== * Reloads the instance in runtime (reloadscript) *------------------------------------------*/ void do_reload_instance(void) { struct instance_data *im; struct instance_db *db; struct s_mapiterator* iter; struct map_session_data *sd; int i; for( i = 1; i < MAX_INSTANCE_DATA; i++ ) { im = &instance_data[i]; if(!im->cnt_map) continue; else { // First we load the NPCs again instance_addnpc(im); // Create new keep timer if((db = instance_searchtype_db(im->type)) != NULL) im->keep_limit = (unsigned int)time(NULL) + db->limit; } } // Reset player to instance beginning iter = mapit_getallusers(); for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) if(sd && map[sd->bl.m].instance_id) { struct party_data *p; if(!(p = party_search(sd->status.party_id)) || p->instance_id != map[sd->bl.m].instance_id) // Someone not in party is on instance map continue; im = &instance_data[p->instance_id]; if((db = instance_searchtype_db(im->type)) != NULL && !instance_enter(sd,db->name)) { // All good clif_displaymessage(sd->fd, msg_txt(sd,515)); // Instance has been reloaded instance_reqinfo(sd,p->instance_id); } else // Something went wrong ShowError("do_reload_instance: Error setting character at instance start: character_id=%d instance=%s.\n",sd->status.char_id,db->name); } mapit_free(iter); }