Пример #1
0
/*==========================================
 * Request some info about the instance
 *------------------------------------------*/
int instance_reqinfo(struct map_session_data *sd, short instance_id)
{
	struct instance_data *im;
	struct instance_db *db;

	nullpo_retr(1, sd);

	if(instance_id <= 0 || instance_id > MAX_INSTANCE_DATA)
		return 1;

	im = &instance_data[instance_id];

	if((db = instance_searchtype_db(im->type)) == NULL)
		return 1;

	if(im->state == INSTANCE_IDLE) { // Say it's created if instance is not busy
		int i;

		for(i = 0; i < instance_wait.count; i++) {
			if(instance_wait.id[i] == instance_id) {
				clif_instance_create(sd, StringBuf_Value(db->name), i + 1, 0);
				break;
			}
		}
	} else if(im->state == INSTANCE_BUSY) // Give info on the instance if busy
		clif_instance_status(sd, StringBuf_Value(db->name), im->keep_limit, im->idle_limit, 0);

	return 0;
}
Пример #2
0
/*--------------------------------------
 * 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;
}
Пример #3
0
/*==========================================
 * Creates idle timer
 * Default before instance destroy is 5 minutes
 *------------------------------------------*/
static int instance_startidletimer(struct instance_data *im, short instance_id)
{
	struct instance_db *db;
	struct party_data *p;

	nullpo_retr(1, im);

	// No current timer
	if(im->idle_timer != INVALID_TIMER)
		return 1;

	// Add the timer
	im->idle_limit = (unsigned int)time(NULL) + INSTANCE_LIMIT / 1000;
	im->idle_timer = add_timer(gettick()+INSTANCE_LIMIT, instance_delete_timer, instance_id, 0);

	// Notify party of added instance timer
	if((p = party_search(im->party_id)) != NULL && (db = instance_searchtype_db(im->type)) != NULL)
		clif_instance_status(party_getavailablesd(p), StringBuf_Value(db->name), im->keep_limit, im->idle_limit, 1);

	return 0;
}
Пример #4
0
/*==========================================
 * Adds timer back to party entering instance
 *------------------------------------------*/
static int instance_startkeeptimer(struct instance_data *im, short instance_id)
{
	struct instance_db *db;
	struct party_data *p;

	nullpo_retr(0, im);

	// No timer
	if(im->keep_timer != -1)
		return 1;

	if((db = instance_searchtype_db(im->type)) == NULL)
		return 1;

	// Add timer
	im->keep_limit = (unsigned int)time(NULL) + db->limit;
	im->keep_timer = add_timer(gettick()+db->limit*1000, instance_delete_timer, instance_id, 0);

	// Notify party of the added instance timer
	if( ( p = party_search( im->party_id ) ) != NULL )
		clif_instance_status( party_getavailablesd( p ), db->name, im->keep_limit, im->idle_limit, 1 );

	return 0;
}