/** Open buyingstore for Autotrader * @param sd Player as autotrader */ void buyingstore_reopen(struct map_session_data* sd) { // Ready to open buyingstore for this char if( sd && autotrader_count > 0 && autotraders ) { uint16 i; uint8 *data, *p; uint16 j, count; ARR_FIND(0, autotrader_count, i, autotraders[i] && autotraders[i]->char_id == sd->status.char_id); if( i >= autotrader_count ) return; // Init buyingstore data for autotrader CREATE(data, uint8, autotraders[i]->count * 8); for( j = 0, p = data, count = autotraders[i]->count; j < autotraders[i]->count; j++ ) { struct s_autotrade_entry *entry = autotraders[i]->entries[j]; uint16 *item_id = (uint16*)(p + 0); uint16 *amount = (uint16*)(p + 2); uint32 *price = (uint32*)(p + 4); *item_id = entry->item_id; *amount = entry->amount; *price = entry->price; p += 8; } // Open the buyingstore again if( buyingstore_setup(sd, (unsigned char)autotraders[i]->count) && buyingstore_create(sd, autotraders[i]->limit, 1, autotraders[i]->title, data, autotraders[i]->count) ) { ShowInfo("Loaded autotrade buyingstore data for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n", sd->status.name, count, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y); // Set him to autotrade if( Sql_Query(mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", buyingstore_db, sd->buyer_id) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); // Make him look perfect unit_setdir(&sd->bl, battle_config.feature_autotrade_direction); if( battle_config.feature_autotrade_sit ) pc_setsit(sd); } else { // Failed to open the buyingstore, set him offline ShowWarning("Failed to load autotrade buyingstore data for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items\n", sd->status.name, count); map_quit(sd); } aFree(data); // If the last autotrade is loaded, clear autotraders [Cydh] if( i + 1 >= autotrader_count ) do_final_buyingstore_autotrade(); } }
/** Open vending for Autotrader * @param sd Player as autotrader */ void vending_reopen( struct map_session_data* sd ){ // Ready to open vending for this char if ( sd && autotrader_count > 0 && autotraders){ uint16 i; uint8 *data, *p; uint16 j, count; ARR_FIND(0,autotrader_count,i,autotraders[i] && autotraders[i]->char_id == sd->status.char_id); if (i >= autotrader_count) { return; } // Init vending data for autotrader CREATE(data, uint8, autotraders[i]->count * 8); for (j = 0, p = data, count = autotraders[i]->count; j < autotraders[i]->count; j++) { struct s_autotrade_entry *entry = autotraders[i]->entries[j]; uint16 *index = (uint16*)(p + 0); uint16 *amount = (uint16*)(p + 2); uint32 *value = (uint32*)(p + 4); // Find item position in cart ARR_FIND(0, MAX_CART, entry->index, sd->status.cart[entry->index].id == entry->cartinventory_id); if (entry->index == MAX_CART) { count--; continue; } *index = entry->index + 2; *amount = entry->amount; *value = entry->price; p += 8; } // Set him into a hacked prevend state sd->state.prevend = 1; // Open the vending again if( vending_openvending(sd, autotraders[i]->title, data, count) ){ // Set him to autotrade if (Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", vendings_db, sd->vender_id ) != SQL_SUCCESS ) { Sql_ShowDebug( mmysql_handle ); } // Make him look perfect unit_setdir(&sd->bl,battle_config.feature_autotrade_direction); if( battle_config.feature_autotrade_sit ) pc_setsit(sd); ShowInfo("Loaded autotrade vending data for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n", sd->status.name,count,mapindex_id2name(sd->mapindex),sd->bl.x,sd->bl.y); }else{ // Failed to open the vending, set him offline ShowWarning("Failed to load autotrade vending data for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items\n", sd->status.name, count ); map_quit( sd ); } aFree(data); //If the last autotrade is loaded, clear autotraders [Cydh] if (i+1 >= autotrader_count) do_final_vending_autotrade(); } }