/*========================================== * Returns an instance map ID using a map name * name : source map * instance_id : where to search * result : mapid of map "name" in this instance *------------------------------------------*/ int instance_mapname2mapid(const char *name, short instance_id) { struct instance_data *im; int m = map_mapname2mapid(name); char iname[MAP_NAME_LENGTH]; int i; if(m < 0) { ShowError("instance_mapname2mapid: map name %s does not exist.\n",name); return m; } strcpy(iname,name); if(instance_id <= 0 || instance_id > MAX_INSTANCE_DATA) return m; im = &instance_data[instance_id]; if(im->state != INSTANCE_BUSY) return m; for(i = 0; i < MAX_MAP_PER_INSTANCE; i++) if(im->map[i].src_m == m) { char alt_name[MAP_NAME_LENGTH]; if((strchr(iname,'@') == NULL) && strlen(iname) > 8) { memmove(iname, iname + (strlen(iname) - 9), strlen(iname)); snprintf(alt_name, sizeof(alt_name),"%d#%s", instance_id, iname); } else snprintf(alt_name, sizeof(alt_name),"%.3d%s", instance_id, iname); return map_mapname2mapid(alt_name); } return m; }
// ギルド城データ変更要求 int guild_castledatasave(int castle_id,int index,int value) { if (index == 1) { //The castle's owner has changed? Update Guardian ownership, too. [Skotlex] struct guild_castle *gc = guild_castle_search(castle_id); int m = -1; if (gc) m = map_mapname2mapid(gc->map_name); if (m != -1) map_foreachinmap(mob_guardian_guildchange, m, BL_MOB); } return intif_guild_castle_datasave(castle_id,index,value); }
/*-------------------------------------- * 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; }
int battleground_countlogin(struct map_session_data *sd, bool check_bat_room) { int c = 0, m = map_mapname2mapid("bat_room"); struct map_session_data* pl_sd; struct s_mapiterator* iter; nullpo_ret(sd); iter = mapit_getallusers(); for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { if( !(pl_sd->qd || map[pl_sd->bl.m].flag.battleground || (check_bat_room && pl_sd->bl.m == m)) ) continue; if( session[sd->fd]->client_addr == session[pl_sd->fd]->client_addr ) c++; } mapit_free(iter); return c; }
/*========================================== * Open shop * data := {<index>.w <amount>.w <value>.l}[count] *------------------------------------------*/ void vending_openvending(struct map_session_data* sd, const char* message, bool flag, const uint8* data, int count) { int i, j, char_id; int vending_skill_lvl; nullpo_retv(sd); if( !flag ) // cancelled return; // nothing to do if (pc_istrading(sd)) return; // can't have 2 shops at once vending_skill_lvl = pc_checkskill(sd, MC_VENDING); // skill level and cart check if( !vending_skill_lvl || !pc_iscarton(sd) ) { clif_skill_fail(sd, MC_VENDING, 0, 0); return; } // check number of items in shop if( count < 1 || count > MAX_VENDING || count > 2 + vending_skill_lvl ) { // invalid item count clif_skill_fail(sd, MC_VENDING, 0, 0); return; } if((sd->bl.m == map_mapname2mapid("mercadores") && ( ((sd->bl.x != 65) && (sd->bl.x != 74) && (sd->bl.x != 85) && (sd->bl.x != 94) && (sd->bl.x != 34) && (sd->bl.x != 25) && (sd->bl.x != 14) && (sd->bl.x != 5) && (sd->bl.x != 44) && (sd->bl.x != 55)) ))) { clif_displaymessage(sd->fd,"Você não pode abrir lojas no meio da Sala."); return; } // filter out invalid items i = 0; for( j = 0; j < count; j++ ) { short index = *(uint16*)(data + 8*j + 0); short amount = *(uint16*)(data + 8*j + 2); unsigned int value = *(uint32*)(data + 8*j + 4); index -= 2; // offset adjustment (client says that the first cart position is 2) if( index < 0 || index >= MAX_CART // invalid position || pc_cartitem_amount(sd, index, amount) < 0 // invalid item or insufficient quantity //NOTE: official server does not do any of the following checks! || !sd->status.cart[index].identify // unidentified item || sd->status.cart[index].attribute == 1 // broken item || sd->status.cart[index].expire_time // It should not be in the cart but just in case || sd->status.cart[index].bound // Can't Trade Account bound items || ( sd->status.cart[index].card[0] == CARD0_CREATE && (char_id = MakeDWord(sd->status.cart[index].card[2],sd->status.cart[index].card[3])) > 0 && ((battle_config.bg_reserved_char_id && char_id == battle_config.bg_reserved_char_id) || (battle_config.ancient_reserved_char_id && char_id == battle_config.ancient_reserved_char_id)) ) || !itemdb_cantrade(&sd->status.cart[index], pc_isGM(sd), pc_isGM(sd)) ) // untradeable item continue; sd->vending[i].index = index; sd->vending[i].amount = amount; sd->vending[i].value = cap_value(value, 0, (unsigned int)battle_config.vending_max_value); i++; // item successfully added } if( i != j ) clif_displaymessage (sd->fd, msg_txt(266)); //"Some of your items cannot be vended and were removed from the shop." if( i == 0 ) { // no valid item found clif_skill_fail(sd, MC_VENDING, 0, 0); // custom reply packet return; } sd->state.vending = true; sd->vender_id = vending_getuid(); sd->vend_num = i; safestrncpy(sd->message, message, MESSAGE_SIZE); pc_stop_walking(sd,1); clif_openvending(sd,sd->bl.id,sd->vending); clif_showvendingboard(&sd->bl,message,0); if( battle_config.channel_announces&0x10 ) { char chat_message[256]; sprintf(chat_message, msg_txt(820), vending_chat_nick, sd->status.name, sd->message, map[sd->bl.m].name, sd->bl.x, sd->bl.y); clif_channel_message(server_channel[CHN_VENDING], chat_message, 27); } if( map[sd->bl.m].flag.vending_cell ) map_setcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_NOBOARDS, false); }
/*-------------------------------------- * Add a map to the instance using src map "name" *--------------------------------------*/ int instance_add_map(const char *name, int instance_id, bool usebasename) { int m = map_mapname2mapid(name), i, im = -1; size_t num_cell, size; if( m < 0 ) return -1; // source map not found if( !instance_is_valid(instance_id) ) { ShowError("instance_add_map: trying to attach '%s' map to non-existing instance %d.\n", name, instance_id); return -1; } if( instance[instance_id].num_map >= MAX_MAP_PER_INSTANCE ) { ShowError("instance_add_map: trying to add '%s' map to instance %d (%s) failed. Please increase MAX_MAP_PER_INSTANCE.\n", name, instance_id, instance[instance_id].name); return -2; } if( map[m].instance_id != 0 ) { // Source map already belong to a Instance. ShowError("instance_add_map: trying to instance already instanced map %s.\n", name); return -4; } ARR_FIND( instance_start, map_num, i, !map[i].name[0] ); // Searching for a Free Map if( i < map_num ) im = i; // Unused map found (old instance) else if( map_num - 1 >= MAX_MAP_PER_SERVER ) { // No more free maps ShowError("instance_add_map: no more free space to create maps on this server.\n"); return -5; } else im = map_num++; // Using next map index memcpy( &map[im], &map[m], sizeof(struct map_data) ); // Copy source map snprintf(map[im].name, MAP_NAME_LENGTH, (usebasename ? "%.3d#%s" : "%.3d%s"), instance_id, name); // Generate Name for Instance Map map[im].index = mapindex_addmap(-1, map[im].name); // Add map index if( !map[im].index ) { map[im].name[0] = '\0'; ShowError("instance_add_map: no more free map indexes.\n"); return -3; // No free map index } // Reallocate cells num_cell = map[im].xs * map[im].ys; CREATE( map[im].cell, struct mapcell, num_cell ); memcpy( map[im].cell, map[m].cell, num_cell * sizeof(struct mapcell) ); size = map[im].bxs * map[im].bys * sizeof(struct block_list*); map[im].block = (struct block_list**)aCalloc(size, 1); map[im].block_mob = (struct block_list**)aCalloc(size, 1); memset(map[im].npc, 0x00, sizeof(map[i].npc)); map[im].npc_num = 0; memset(map[im].moblist, 0x00, sizeof(map[im].moblist)); map[im].mob_delete_timer = INVALID_TIMER; map[im].m = im; map[im].instance_id = instance_id; map[im].instance_src_map = m; map[m].flag.src4instance = 1; // Flag this map as a src map for instances instance[instance_id].map[instance[instance_id].num_map++] = im; // Attach to actual instance map_addmap2db(&map[im]); return im; }