Esempio n. 1
0
/*==========================================
 * アイテム使用可能フラグのオーバーライド
 *------------------------------------------*/
static bool itemdb_read_itemavail(char* str[], int columns, int current)
{// <nameid>,<sprite>
	int nameid, sprite;
	struct item_data *id;

	nameid = atoi(str[0]);

	if( ( id = itemdb_exists(nameid) ) == NULL )
	{
		ShowWarning("itemdb_read_itemavail: Invalid item id %d.\n", nameid);
		return false;
	}

	sprite = atoi(str[1]);

	if( sprite > 0 )
	{
		id->flag.available = 1;
		id->view_id = sprite;
	}
	else
	{
		id->flag.available = 0;
	}

	return true;
}
Esempio n. 2
0
/*==========================================
 * Reads item trade restrictions [Skotlex]
 *------------------------------------------*/
static bool itemdb_read_itemtrade(char* str[], int columns, int current)
{// <nameid>,<mask>,<gm level>
	int nameid, flag, gmlv;
	struct item_data *id;

	nameid = atoi(str[0]);

	if( ( id = itemdb_exists(nameid) ) == NULL )
	{
		//ShowWarning("itemdb_read_itemtrade: Invalid item id %d.\n", nameid);
		//return false;
		// FIXME: item_trade.txt contains items, which are commented in item database.
		return true;
	}

	flag = atoi(str[1]);
	gmlv = atoi(str[2]);

	if( flag < 0 || flag >= 128 )
	{//Check range
		ShowWarning("itemdb_read_itemtrade: Invalid trading mask %d for item id %d.\n", flag, nameid);
		return false;
	}

	if( gmlv < 1 )
	{
		ShowWarning("itemdb_read_itemtrade: Invalid override GM level %d for item id %d.\n", gmlv, nameid);
		return false;
	}

	id->flag.trade_restriction = flag;
	id->gm_lv_trade_override = gmlv;

	return true;
}
Esempio n. 3
0
/*==========================================
 * read item group data
 *------------------------------------------*/
static void itemdb_read_itemgroup_sub(const char* filename)
{
	FILE *fp;
	char line[1024];
	int ln=0;
	int groupid,j,k,nameid;
	char *str[3],*p;
	char w1[1024], w2[1024];
	
	if( (fp=fopen(filename,"r"))==NULL ){
		ShowError("can't read %s\n", filename);
		return;
	}

	while(fgets(line, sizeof(line), fp))
	{
		ln++;
		if(line[0]=='/' && line[1]=='/')
			continue;
		if(strstr(line,"import")) {
			if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 &&
				strcmpi(w1, "import") == 0) {
				itemdb_read_itemgroup_sub(w2);
				continue;
			}
		}
		memset(str,0,sizeof(str));
		for(j=0,p=line;j<3 && p;j++){
			str[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(str[0]==NULL)
			continue;
		if (j<3) {
			if (j>1) //Or else it barks on blank lines...
				ShowWarning("itemdb_read_itemgroup: Insufficient fields for entry at %s:%d\n", filename, ln);
			continue;
		}
		groupid = atoi(str[0]);
		if (groupid < 0 || groupid >= MAX_ITEMGROUP) {
			ShowWarning("itemdb_read_itemgroup: Invalid group %d in %s:%d\n", groupid, filename, ln);
			continue;
		}
		nameid = atoi(str[1]);
		if (!itemdb_exists(nameid)) {
			ShowWarning("itemdb_read_itemgroup: Non-existant item %d in %s:%d\n", nameid, filename, ln);
			continue;
		}
		k = atoi(str[2]);
		if (itemgroup_db[groupid].qty+k >= MAX_RANDITEM) {
			ShowWarning("itemdb_read_itemgroup: Group %d is full (%d entries) in %s:%d\n", groupid, MAX_RANDITEM, filename, ln);
			continue;
		}
		for(j=0;j<k;j++)
			itemgroup_db[groupid].nameid[itemgroup_db[groupid].qty++] = nameid;
	}
	fclose(fp);
	return;
}
Esempio n. 4
0
/// check if this item should be logged according the settings
static bool should_log_item(unsigned short nameid, int amount, int refine)
{
	int filter = log_config.filter;
	struct item_data* id;

	if( ( id = itemdb_exists(nameid) ) == NULL )
		return false;

	if( ( filter&LOG_FILTER_ALL ) ||
		( filter&LOG_FILTER_HEALING && id->type == IT_HEALING ) ||
		( filter&LOG_FILTER_ETC_AMMO && ( id->type == IT_ETC || id->type == IT_AMMO ) ) ||
		( filter&LOG_FILTER_USABLE && ( id->type == IT_USABLE || id->type == IT_CASH ) ) ||
		( filter&LOG_FILTER_WEAPON && id->type == IT_WEAPON ) ||
		( filter&LOG_FILTER_ARMOR && id->type == IT_ARMOR ) ||
		( filter&LOG_FILTER_CARD && id->type == IT_CARD ) ||
		( filter&LOG_FILTER_PETITEM && ( id->type == IT_PETEGG || id->type == IT_PETARMOR ) ) ||
		( filter&LOG_FILTER_PRICE && id->value_buy >= log_config.price_items_log ) ||
		( filter&LOG_FILTER_AMOUNT && abs(amount) >= log_config.amount_items_log ) ||
		( filter&LOG_FILTER_REFINE && refine >= log_config.refine_items_log ) ||
		( filter&LOG_FILTER_CHANCE && ( ( id->maxchance != -1 && id->maxchance <= log_config.rare_items_log ) || id->nameid == ITEMID_EMPERIUM ) )
	)
		return true;

	return false;
}
Esempio n. 5
0
/*==========================================
 * Reads item delay amounts [Paradox924X]
 *------------------------------------------*/
static bool itemdb_read_itemdelay(char* str[], int columns, int current)
{// <nameid>,<delay>
	int nameid, delay;
	struct item_data *id;

	nameid = atoi(str[0]);

	if( ( id = itemdb_exists(nameid) ) == NULL )
	{
		ShowWarning("itemdb_read_itemdelay: Invalid item id %d.\n", nameid);
		return false;
	}

	delay = atoi(str[1]);

	if( delay < 0 )
	{
		ShowWarning("itemdb_read_itemdelay: Invalid delay %d for item id %d.\n", delay, nameid);
		return false;
	}

	id->delay = delay;

	return true;
}
Esempio n. 6
0
// Extended Vending System
static bool itemdb_read_vending(char* fields[], int columns, int current)
{
	struct item_data* id;
	int nameid;

	nameid = atoi(fields[0]);

	if( ( id = itemdb_exists(nameid) ) == NULL )
	{
		ShowWarning("itemdb_read_vending: Invalid item id %d.\n", nameid);
		return false;
	}

	if( !itemdb_isstackable2(id) )
	{
		ShowWarning("itemdb_read_vending: Cannot use a non stackable item. ID %d.\n", nameid);
		return false;
	}

	if( id->weight > 0 )
	{
		ShowWarning("itemdb_read_vending: Coins only can have 0 weight. Cannot use ID %d.\n", nameid);
		return false;
	}

	coins_db[current] = nameid;
	return true;
}
Esempio n. 7
0
/*==========================================
 * [Zephyrus] Serial Database
 *------------------------------------------*/
static int itemdb_load_serials(void)
{
	int nameid, count = 0;
	struct item_data *id;
	unsigned int serial;
	char *data;

	if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `nameid`, `serial` FROM `item_serials`") )
	{
		Sql_ShowDebug(mmysql_handle);
		return 0;
	}
	while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
	{
		Sql_GetData(mmysql_handle, 0, &data, NULL); nameid = atoi(data);
		Sql_GetData(mmysql_handle, 1, &data, NULL); serial = atol(data);

		if( (id = itemdb_exists(nameid)) == NULL )
			continue;

		id->last_serial = serial;
		++count;
	}

	// free the query result
	Sql_FreeResult(mmysql_handle);

	ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"item_serials"CL_RESET"'.\n", count);
	return 0;
}
Esempio n. 8
0
/*==========================================
 * ランダムアイテム出現データの読み込み
 *------------------------------------------
 */
static int itemdb_read_randomitem(void)
{
	FILE *fp;
	char line[1024];
	int randomid,nameid,range,i,c;
	char *str[3],*p;
	const char *filename = "db/item_random.txt";

	// 読み込む度、初期化
	memset(&random_item, 0, sizeof(random_item));

	if((fp = fopen(filename, "r")) == NULL) {
		printf("itemdb_read_randomitem: open [%s] failed !\n", filename);
		return 0;
	}

	while(fgets(line,sizeof(line),fp)) {
		if(line[0] == '\0' || line[0] == '\r' || line[0] == '\n')
			continue;
		if(line[0] == '/' && line[1] == '/')
			continue;
		memset(str,0,sizeof(str));
		for(i=0,p=line; i<3 && p; i++) {
			str[i]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(str[0] == NULL || str[1] == NULL || str[2] == NULL)
			continue;

		randomid = atoi(str[0]) - 1;
		if(randomid < 0 || randomid >= MAX_RAND_ITEM_TYPE)
			continue;
		nameid = atoi(str[1]);
		if(nameid < 0 || !itemdb_exists(nameid))
			continue;
		range = atoi(str[2]);
		if(range < 1 || range >= MAX_RAND_ITEM_AMOUNT)
			continue;

		c = random_item[randomid].entry;
		if(c >= MAX_RAND_ITEM_ENTRY)
			continue;
		if(c > 0)
			range += random_item[randomid].data[c-1].qty;

		if(range >= MAX_RAND_ITEM_AMOUNT)
			continue;

		random_item[randomid].data[c].nameid   = nameid;
		random_item[randomid].data[c].qty = range;
		random_item[randomid].entry++;
	}
	fclose(fp);
	printf("read %s done\n", filename);

	return 0;
}
Esempio n. 9
0
/*==========================================
 * ギルド倉庫に入れられるアイテムは1、そうでないアイテムは0
 *------------------------------------------
 */
int itemdb_isguildstorageable(int nameid)
{
	struct item_data *id = itemdb_exists(nameid);

	if(id && !id->flag.guildstorageable)
		return 1;

	return 0;
}
Esempio n. 10
0
/*==========================================
 * 売れるアイテムは1、そうでないアイテムは0
 *------------------------------------------
 */
int itemdb_issellable(int nameid)
{
	struct item_data *id = itemdb_exists(nameid);

	if(id && !id->flag.sellable)
		return 1;

	return 0;
}
Esempio n. 11
0
/*==========================================
 * 買取露店に出せるアイテムは1、そうでないアイテムは0
 *------------------------------------------
 */
int itemdb_isbuyingable(int nameid)
{
	struct item_data *id = itemdb_exists(nameid);

	if(id && id->flag.buyingable)
		return 1;

	return 0;
}
Esempio n. 12
0
/*==========================================
 * 使用しても消費しないアイテムは1、そうでないアイテムは0
 *------------------------------------------
 */
int itemdb_isnonconsume(int nameid)
{
	struct item_data *id = itemdb_exists(nameid);

	if(id && id->flag.nonconsume)
		return 1;

	return 0;
}
Esempio n. 13
0
/*==========================================
 * read item group data
 *------------------------------------------
 */
static int itemdb_read_itemgroup(void)
{
	FILE *fp;
	char line[1024];
	int ln=0;
	int groupid,j,k;
	char *str[31],*p;

	sprintf(line, "%s/item_group_db.txt", db_path);
	if( (fp=fopen(line,"r"))==NULL ){
		ShowError("can't read %s\n", line);
		return -1;
	}

	while(fgets(line,1020,fp)){
		if(line[0]=='/' && line[1]=='/')
			continue;
		memset(str,0,sizeof(str));
		for(j=0,p=line;j<31 && p;j++){
			str[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(str[0]==NULL)
			continue;

		groupid = atoi(str[0]);
		if (groupid < 0 || groupid >= MAX_ITEMGROUP)
			continue;

		for (j=1; j<=30; j++) {
			if (!str[j])
				break;
			k=atoi(str[j]);
			if (k < 0 || k >= 20000 || !itemdb_exists(k))
				continue;
			//printf ("%d[%d] = %d\n", groupid, j-1, k);
			itemgroup_db[groupid].id[j-1] = k;
			itemgroup_db[groupid].qty=j;
		}
		for (j=1; j<30; j++) { //Cleanup the contents. [Skotlex]
			if (itemgroup_db[groupid].id[j-1] == 0 &&
				itemgroup_db[groupid].id[j] != 0) 
			{
				itemgroup_db[groupid].id[j-1] = itemgroup_db[groupid].id[j];
				itemgroup_db[groupid].id[j] = 0;
				itemgroup_db[groupid].qty = j;
			}
		}
		ln++;
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"item_group_db.txt");
	return 0;
}
Esempio n. 14
0
/*==========================================
 * アイテム価格テーブルのオーバーライド
 *------------------------------------------
 */
static int itemdb_read_itemvaluedb(void)
{
	FILE *fp;
	char line[1024];
	int ln=0;
	int nameid,j;
	char *str[7],*p;
	struct item_data *id;
	const char *filename = "db/item_value_db.txt";

	if( (fp = fopen(filename, "r")) == NULL) {
		printf("itemdb_read_itemvaluedb: open [%s] failed !\n", filename);
		return -1;
	}

	while(fgets(line,1020,fp)){
		if(line[0] == '\0' || line[0] == '\r' || line[0] == '\n')
			continue;
		if(line[0]=='/' && line[1]=='/')
			continue;
		memset(str,0,sizeof(str));
		for(j=0,p=line;j<7 && p;j++){
			str[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(str[0] == NULL)
			continue;

		nameid = atoi(str[0]);
		if(nameid <= 0 || !(id = itemdb_exists(nameid)))
			continue;

		ln++;
		// それぞれ記述した個所のみオーバーライト
		if(str[3] != NULL && *str[3]) {
			id->value_buy = atoi(str[3]);
		}
		if(str[4] != NULL && *str[4]) {
			id->value_sell = atoi(str[4]);
		}
		if(str[5] != NULL && *str[5]) {
			id->flag.value_notdc = (atoi(str[5]) == 0)? 0: 1;
		}
		if(str[6] != NULL && *str[6]) {
			id->flag.value_notoc = (atoi(str[6]) == 0)? 0: 1;
		}
	}
	fclose(fp);
	printf("read %s done (count=%d)\n", filename, ln);
	return 0;
}
Esempio n. 15
0
/*******************************************
** Item usage restriction (item_nouse.txt)
********************************************/
static bool itemdb_read_nouse(char* fields[], int columns, int current)
{// <nameid>,<flag>,<override>
	int nameid, flag, override;
	struct item_data* id;

	nameid = atoi(fields[0]);

	if( ( id = itemdb_exists(nameid) ) == NULL ) {
		ShowWarning("itemdb_read_nouse: Invalid item id %d.\n", nameid);
		return false;
	}

	flag = atoi(fields[1]);
	override = atoi(fields[2]);
Esempio n. 16
0
/*==========================================
 * 装備制限ファイル読み出し
 *------------------------------------------*/
static bool itemdb_read_noequip (char *str[], int columns, int current)
{
	// <nameid>,<mode>
	int nameid;
	struct item_data *id;
	nameid = atoi (str[0]);

	if ( (id = itemdb_exists (nameid)) == NULL)
	{
		ShowWarning ("itemdb_read_noequip: Invalid item id %d.\n", nameid);
		return false;
	}

	id->flag.no_equip |= atoi (str[1]);
	return true;
}
Esempio n. 17
0
/*==========================================
 * [Zephyrus] DB de Items con Drop Alterado
 *------------------------------------------*/
static int itemdb_read_customrates(void)
{
	FILE *fp;
	char line[1024];
	int ln=0;
	int nameid,j;
	char *str[3],*p;
	struct item_data *id;

	sprintf(line, "%s/item_customrates.txt", db_path);
	if( (fp = fopen(line,"r")) == NULL )
	{
		ShowError("can't read %s\n", line);
		return -1;
	}

	while( fgets(line, sizeof(line), fp) )
	{
		if( line[0] == '/' && line[1] == '/' )
			continue;

		memset(str, 0, sizeof(str));
		for( j = 0, p = line; j < 3 && p; j++ )
		{
			str[j] = p;
			p = strchr(p,',');
			if( p ) *p++=0;
		}
		if( str[0] == NULL )
			continue;

		nameid = atoi(str[0]);
		if( nameid <= 0 || !(id = itemdb_exists(nameid)) )
			continue;

		id->dropRate = atoi(str[1]);
		id->add_dropRate = atoi(str[2]);
		ln++;
	}
	fclose(fp);
	if( ln > 0 )
		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"item_customrates.txt");

	return 0;
}
Esempio n. 18
0
/*==========================================
 * アイテム使用可能フラグのオーバーライド
 *------------------------------------------
 */
static int itemdb_read_itemavail(void)
{
	FILE *fp;
	char line[1024];
	int ln=0;
	int nameid,j,k;
	char *str[2],*p;
	const char *filename = "db/item_avail.txt";

	if( (fp = fopen(filename, "r")) == NULL ) {
		printf("itemdb_read_itemavail: open [%s] failed !\n", filename);
		return -1;
	}

	while(fgets(line,1020,fp)){
		struct item_data *id=NULL;
		if(line[0] == '\0' || line[0] == '\r' || line[0] == '\n')
			continue;
		if(line[0]=='/' && line[1]=='/')
			continue;
		memset(str,0,sizeof(str));
		for(j=0,p=line;j<2 && p;j++){
			str[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(str[0] == NULL || str[1] == NULL)
			continue;

		nameid = atoi(str[0]);
		if(nameid < 0 || !(id = itemdb_exists(nameid)))
			continue;
		k = atoi(str[1]);
		if(k > 0) {
			id->flag.available = 1;
			id->view_id = k;
		} else {
			id->flag.available = 0;
		}
		ln++;
	}
	fclose(fp);
	printf("read %s done (count=%d)\n", filename, ln);
	return 0;
}
Esempio n. 19
0
/*==========================================
 * アイテム使用可能フラグのオーバーライド
 *------------------------------------------
 */
static int itemdb_read_itemavail(void)
{
	FILE *fp;
	char line[1024];
	int ln = 0;
	int nameid, j, k;
	char *str[10], *p;

	if ((fp = fopen("db/item_avail.txt", "r")) == NULL) {
		printf("can't read db/item_avail.txt.\n");
		return -1;
	}

	while(fgets(line, sizeof(line), fp)) { // fgets reads until maximum one less than size and add '\0' -> so, it's not necessary to add -1
		struct item_data *id;
		if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
			continue;
		// it's not necessary to remove 'carriage return ('\n' or '\r')
		memset(str,0,sizeof(str));
		for(j = 0, p = line; j < 2 && p; j++) {
			str[j] = p;
			p = strchr(p, ',');
			if (p) *p++ = 0;
		}

		if (str[0] == NULL)
			continue;

		nameid = atoi(str[0]);
		if (nameid < 0 || nameid >= 20000 || !(id = itemdb_exists(nameid)))
			continue;
		k = atoi(str[1]);
		if (k > 0) {
			id->flag.available = 1;
			id->view_id = k;
		}
		else
			id->flag.available = 0;
		ln++;
	}
	fclose(fp);
	printf("DB '" CL_WHITE "db/item_avail.txt" CL_RESET "' readed ('" CL_WHITE "%d" CL_RESET "' entrie%s).\n", ln, (ln > 1) ? "s" : "");

	return 0;
}
Esempio n. 20
0
//check if this item should be logged according the settings
int should_log_item(int filter, int nameid, int amount) {
    struct item_data *item_data;
    if ((item_data= itemdb_exists(nameid)) == NULL) return 0;
    if ((filter&1) || // Filter = 1, we log any item
            (filter&2 && item_data->type == IT_HEALING ) ||
            (filter&4 && (item_data->type == IT_ETC || item_data->type == IT_AMMO) ) ||
            (filter&8 && item_data->type == IT_USABLE ) ||
            (filter&16 && item_data->type == IT_WEAPON ) ||
            (filter&32 && item_data->type == IT_ARMOR ) ||
            (filter&64 && item_data->type == IT_CARD ) ||
            (filter&128 && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) ||
            (filter&256 && item_data->value_buy >= log_config.price_items_log ) ||		//expensive items
            (filter&512 && abs(amount) >= log_config.amount_items_log ) ||			//big amount of items
            (filter&2048 && ((item_data->maxchance <= log_config.rare_items_log) || item_data->nameid == 714) ) //Rare items or Emperium
       ) return item_data->nameid;

    return 0;
}
Esempio n. 21
0
void bg_team_getitem(int bg_id, int nameid, int amount)
{
	struct battleground_data *bg;
	struct map_session_data *sd;
	struct item_data *id;
	struct item it;
	int get_amount, i, j, flag, rank = 0;

	if( amount < 1 || (bg = bg_team_search(bg_id)) == NULL || (id = itemdb_exists(nameid)) == NULL )
		return;
	if( nameid != 7828 && nameid != 7829 && nameid != 7773 )
		return;
	if( battle_config.bg_reward_rates != 100 )
		amount = amount * battle_config.bg_reward_rates / 100;

	memset(&it, 0, sizeof(it));
	it.nameid = nameid;
	it.identify = 1;

	for( j = 0; j < MAX_BG_MEMBERS; j++ )
	{
		if( (sd = bg->members[j].sd) == NULL )
			continue;
		if( battle_config.bg_ranking_bonus )
		{
			rank = 0;
			ARR_FIND(0,MAX_FAME_LIST,i,bgrank_fame_list[i].id == sd->status.char_id);
			if( i < MAX_FAME_LIST )
				rank = 1;
			else
			{
				ARR_FIND(0,MAX_FAME_LIST,i,bg_fame_list[i].id == sd->status.char_id);
				if( i < MAX_FAME_LIST )
					rank = 1;
			}
		}

		get_amount = amount;
		if( rank ) get_amount += battle_config.bg_ranking_bonus * get_amount / 100;

		if( (flag = pc_additem(sd,&it,get_amount,LOG_TYPE_SCRIPT)) )
			clif_additem(sd,0,0,flag);
	}
}
Esempio n. 22
0
// === READ ITEM NOTRADE DATABASE ===
// ==================================
static void itemdb_read_notrade(void)
{
	struct item_data *id;
	char line[8];
	int itemid, itemtype;

	FILE *db = fopen("db/item_notrade.txt", "r");

	if(db == NULL)
	{
		printf(CL_WHITE "warning: " CL_RESET "failed to read item notrade database \n");
		return;
	}

	while(fgets(line, 8, db))
	{
		if(line[0] == '/' && line[1] == '/')
			continue;
		if(line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
			continue;

		sscanf(line, "%d %d", &itemid, &itemtype);

		if(!itemid || !itemtype)
			continue;

		if(itemid <= 0 || itemid >= 20000 || !(id = itemdb_exists(itemid)))
			continue;

		if(itemtype < 0)
			itemtype = 0;
		if(itemtype > 2)
			itemtype = 2;

		id->flag.no_trade = itemtype;

//		printf(CL_WHITE "debug: " CL_RESET "item id '%d' notrade flag is %d \n", id->nameid, id->flag.no_trade);
	}

	fclose(db);
	printf(CL_WHITE "status: " CL_RESET "succesfully loaded item notrade database \n");
	return;
}
Esempio n. 23
0
/*==========================================
 * Reads item trade restrictions [Skotlex]
 *------------------------------------------*/
static int itemdb_read_itemtrade(void)
{
	FILE *fp;
	int nameid, j, flag, gmlv, ln = 0;
	char line[1024], *str[10], *p;
	struct item_data *id;

	sprintf(line, "%s/item_trade.txt", db_path);
	if ((fp = fopen(line,"r")) == NULL) {
		ShowError("can't read %s\n", line);
		return -1;
	}

	while(fgets(line, sizeof(line), fp))
	{
		if (line[0] == '/' && line[1] == '/')
			continue;
		memset(str, 0, sizeof(str));
		for (j = 0, p = line; j < 3 && p; j++) {
			str[j] = p;
			p = strchr(p, ',');
			if(p) *p++ = 0;
		}

		if (j < 3 || str[0] == NULL ||
			(nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
			continue;

		flag = atoi(str[1]);
		gmlv = atoi(str[2]);
		
		if (flag > 0 && flag < 128 && gmlv > 0) { //Check range
			id->flag.trade_restriction = flag;
			id->gm_lv_trade_override = gmlv;
			ln++;
		}
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_trade.txt");

	return 0;
}
Esempio n. 24
0
// === READ ITEM NOEQUIP DATABASE ===
// ==================================
static int itemdb_read_noequip(void)
{
	FILE *fp;
	char line[1024];
	int ln = 0;
	int nameid, j;
	char *str[32],*p;
	struct item_data *id;

	if ((fp = fopen("db/item_noequip.txt", "r")) == NULL) {
		printf("can't read db/item_noequip.txt\n");
		return -1;
	}

	while(fgets(line, sizeof(line), fp)) { // fgets reads until maximum one less than size and add '\0' -> so, it's not necessary to add -1
		if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
			continue;
		// it's not necessary to remove 'carriage return ('\n' or '\r')
		memset(str, 0, sizeof(str));
		for(j = 0, p = line; j < 2 && p; j++) {
			str[j] = p;
			p = strchr(p, ',');
			if (p)
				*p++ = 0;
		}
		if (str[0] == NULL)
			continue;

		nameid = atoi(str[0]);
		if (nameid <= 0 || nameid >= 20000 || !(id = itemdb_exists(nameid)))
			continue;

		id->flag.no_equip = atoi(str[1]); // mode = 1- not in PvP, 2- GvG restriction, 3- PvP and GvG which restriction

		ln++;
	}
	fclose(fp);

	printf("DB '" CL_WHITE "db/item_noequip.txt" CL_RESET "' readed ('" CL_WHITE "%d" CL_RESET "' entrie%s).\n", ln, (ln > 1) ? "s" : "");

	return 0;
}
Esempio n. 25
0
/**
 * Pet menu options.
 * @param sd : player requesting
 * @param menunum : menu option chosen
 * @return 0:success, 1:failure
 */
int pet_menu(struct map_session_data *sd,int menunum)
{
	struct item_data *egg_id;
	nullpo_ret(sd);

	if (sd->pd == NULL)
		return 1;

	//You lost the pet already.
	if(!sd->status.pet_id || sd->pd->pet.intimate <= 0 || sd->pd->pet.incubate)
		return 1;

	egg_id = itemdb_exists(sd->pd->petDB->EggID);

	if (egg_id) {
		if ((egg_id->flag.trade_restriction&0x01) && !pc_inventoryblank(sd)) {
			clif_displaymessage(sd->fd, msg_txt(sd, 451)); // You can't return your pet because your inventory is full.
			return 1;
		}
	}

	switch(menunum) {
		case 0:
			clif_send_petstatus(sd);
			break;
		case 1:
			pet_food(sd, sd->pd);
			break;
		case 2:
			pet_performance(sd, sd->pd);
			break;
		case 3:
			pet_return_egg(sd, sd->pd);
			break;
		case 4:
			pet_unequipitem(sd, sd->pd);
			break;
	}

	return 0;
}
Esempio n. 26
0
/*==========================================
 * アイテム使用可能フラグのオーバーライド
 *------------------------------------------*/
static int itemdb_read_itemavail (void)
{
	FILE *fp;
	int nameid, j, k, ln = 0;
	char line[1024], *str[10], *p;
	struct item_data *id;

	sprintf(line, "%s/item_avail.txt", db_path);
	if ((fp = fopen(line,"r")) == NULL) {
		ShowError("can't read %s\n", line);
		return -1;
	}

	while(fgets(line, sizeof(line), fp))
	{
		if (line[0] == '/' && line[1] == '/')
			continue;
		memset(str, 0, sizeof(str));
		for (j = 0, p = line; j < 2 && p; j++) {
			str[j] = p;
			p = strchr(p, ',');
			if(p) *p++ = 0;
		}

		if (j < 2 || str[0] == NULL ||
			(nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
			continue;

		k = atoi(str[1]);
		if (k > 0) {
			id->flag.available = 1;
			id->view_id = k;
		} else
			id->flag.available = 0;
		ln++;
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_avail.txt");

	return 0;
}
Esempio n. 27
0
/*==========================================
 * アイテムの名前テーブルを読み込む
 *------------------------------------------
 */
static int itemdb_read_itemnametable(void)
{
	char *buf,*p;
	int s;

	buf = grfio_reads("data\\idnum2itemdisplaynametable.txt",&s);

	if (buf == NULL)
		return -1;

	buf[s] = 0;
	p = buf;
	while(p - buf < s) {
		int nameid;
		char buf2[64];

		if (sscanf(p, "%d#%[^#]#", &nameid, buf2) == 2) {

#ifdef ITEMDB_OVERRIDE_NAME_VERBOSE
			if (itemdb_exists(nameid) &&
			    strncmp(itemdb_search(nameid)->jname, buf2, 24) != 0) {
				printf("[override] %d %s => %s\n", nameid, itemdb_search(nameid)->jname, buf2);
			}
#endif

			memset(itemdb_search(nameid)->jname, 0, sizeof(itemdb_search(nameid)->jname));
			strncpy(itemdb_search(nameid)->jname, buf2, 24);
		}

		p = strchr(p, 10);
		if (!p)
			break;
		p++;
	}
	FREE(buf);

	printf("File '" CL_WHITE "data\\idnum2itemdisplaynametable.txt" CL_RESET "' readed.\n");

	return 0;
}
Esempio n. 28
0
/// Reads items allowed to be sold in buying stores
static bool itemdb_read_buyingstore (char *fields[], int columns, int current)
{
	// <nameid>
	int nameid;
	struct item_data *id;
	nameid = atoi (fields[0]);

	if ( (id = itemdb_exists (nameid)) == NULL)
	{
		ShowWarning ("itemdb_read_buyingstore: Invalid item id %d.\n", nameid);
		return false;
	}

	if (!itemdb_isstackable2 (id))
	{
		ShowWarning ("itemdb_read_buyingstore: Non-stackable item id %d cannot be enabled for buying store.\n", nameid);
		return false;
	}

	id->flag.buyingstore = true;
	return true;
}
Esempio n. 29
0
/**
 * Attempt to add an item in guild storage, then refresh i
 * @param stor : guild_storage
 * @param item : item to add
 * @param amount : number of item to add
 * @return True : success, False : fail
 */
bool gstorage_additem2(struct guild_storage *stor, struct item* item, int amount)
{
	struct item_data *id;
	int i;

	nullpo_retr(false, stor);
	nullpo_retr(false, item);

	if (item->nameid == 0 || amount <= 0 || !(id = itemdb_exists(item->nameid)))
		return false;

	if (item->expire_time)
		return false;

	if (itemdb_isstackable2(id)) { //Stackable
		for (i = 0; i < MAX_GUILD_STORAGE; i++) {
			if (compare_item(&stor->items[i], item)) {
				//Set the amount, make it fit with max amount
				amount = min(amount, ((id->stack.guildstorage) ? id->stack.amount : MAX_AMOUNT) - stor->items[i].amount);
				if (amount != item->amount)
					ShowWarning("gstorage_additem2: Stack limit reached! Altered amount of item \""CL_WHITE"%s"CL_RESET"\" (%d). '"CL_WHITE"%d"CL_RESET"' -> '"CL_WHITE"%d"CL_RESET"'.\n", id->name, id->nameid, item->amount, amount);
				stor->items[i].amount += amount;
				stor->dirty = true;
				return true;
			}
		}
	}

	//Add the item
	for (i = 0; i < MAX_GUILD_STORAGE && stor->items[i].nameid; i++);
	if (i >= MAX_GUILD_STORAGE)
		return false;

	memcpy(&stor->items[i], item, sizeof(stor->items[0]));
	stor->items[i].amount = amount;
	stor->storage_amount++;
	stor->dirty = true;
	return true;
}
Esempio n. 30
0
/*==========================================
 * アイテムの名前テーブルを読み込む
 *------------------------------------------
 */
static int itemdb_read_itemnametable(void)
{
	char *buf,*p;
	int s;

	buf=(char *) grfio_reads("data\\idnum2itemdisplaynametable.txt",&s);

	if(buf==NULL)
		return -1;

	buf[s]=0;
	for(p=buf;p-buf<s;){
		int nameid;
		char buf2[64]; //Why 64? What's this for, other than holding an item's name? [Skotlex]

		if(	sscanf(p,"%d#%[^#]#",&nameid,buf2)==2 ){

#ifdef ITEMDB_OVERRIDE_NAME_VERBOSE
			if( itemdb_exists(nameid) &&
				strncmp(itemdb_search(nameid)->jname,buf2,ITEM_NAME_LENGTH)!=0 ){
				ShowNotice("[override] %d %s => %s\n",nameid
					,itemdb_search(nameid)->jname,buf2);
			}
#endif

			strncpy(itemdb_search(nameid)->jname,buf2,ITEM_NAME_LENGTH-1);
		}

		p=strchr(p,10);
		if(!p) break;
		p++;
	}
	aFree(buf);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","data\\idnum2itemdisplaynametable.txt");

	return 0;
}