Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
static void itemdb_read_itemgroup(void)
{
	char path[256];
	snprintf(path, 255, "%s/"DBPATH"item_group_db.txt", db_path);
	memset(&itemgroup_db, 0, sizeof(itemgroup_db));
	itemdb_read_itemgroup_sub(path);
	return;
}
Ejemplo n.º 3
0
static void itemdb_read_itemgroup(void)
{
    char path[256];
    snprintf(path, 255, "%s/"DBPATH"item_group_db.txt", db_path);
    memset(&itemgroup_db, 0, sizeof(itemgroup_db));
    itemdb_read_itemgroup_sub(path);
    ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n", "item_group_db.txt");
    return;
}
Ejemplo n.º 4
0
static void itemdb_read_itemgroup(void)
{
	char path[256];
#if REMODE
	snprintf(path, 255, "%s/re/item_group_db.txt", db_path);
#else
	snprintf(path, 255, "%s/pre-re/item_group_db.txt", db_path);
#endif
	memset(&itemgroup_db, 0, sizeof(itemgroup_db));
	itemdb_read_itemgroup_sub(path);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n", "item_group_db.txt");
	return;
}
Ejemplo n.º 5
0
static void itemdb_read_itemgroup(void)
{
	char path[256];
	int i;
	const char* groups[] = {
		"Blue Box",
		"Violet Box",
		"Card Album",
		"Gift Box",
		"Scroll Box",
		"Finding Ore",
		"Cookie Bag",
		"Potion",
		"Herbs",
		"Fruits",
		"Meat",
		"Candy",
		"Juice",
		"Fish",
		"Boxes",
		"Gemstone",
		"Jellopy",
		"Ore",
		"Food",
		"Recovery",
		"Minerals",
		"Taming",
		"Scrolls",
		"Quivers",
		"Masks",
		"Accesory",
		"Jewels",
		"Gift Box 1",
		"Gift Box 2",
		"Gift Box 3",
		"Gift Box 4",
		"Egg Boy",
		"Egg Girl",
		"Gift Box China",
		"Lotto Box",
	};
	memset(&itemgroup_db, 0, sizeof(itemgroup_db));
	snprintf(path, 255, "%s/item_group_db.txt", db_path);
	itemdb_read_itemgroup_sub(path);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","item_group_db.txt");
	if (battle_config.etc_log) {
		for (i = 1; i < MAX_ITEMGROUP; i++)
			ShowInfo("Group %s: %d entries.\n", groups[i-1], itemgroup_db[i].qty);
	}
	return;
}
Ejemplo n.º 6
0
/** Read item group data
* Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,GUID,isBound,isNamed}
*/
static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
{
	FILE *fp;
	int ln = 0, entries = 0;
	char line[1024];

	if ((fp=fopen(filename,"r")) == NULL) {
		if(silent == 0) ShowError("Can't read %s\n", filename);
		return;
	}
	
	while (fgets(line,sizeof(line),fp)) {
		DBData data;
		int group_id = -1;
		unsigned int j, prob = 1;
		uint8 rand_group = 1;
		char *str[10], *p;
		struct s_item_group_random *random = NULL;
		struct s_item_group_db *group = NULL;
		struct s_item_group_entry entry;
		bool found = false;

		ln++;
		if (line[0] == '/' && line[1] == '/')
			continue;
		if (strstr(line,"import")) {
			char w1[16], w2[64];

			if (sscanf(line,"%15[^:]: %63[^\r\n]",w1,w2) == 2 &&
				strcmpi(w1,"import") == 0)
			{
				itemdb_read_itemgroup_sub(w2, 0);
				continue;
			}
		}
		memset(str,0,sizeof(str));
		for (j = 0, p = line; j < 9 && p;j++) {
			str[j] = p;
			p = strchr(p,',');
			if (p) *p++=0;
		}
		if (str[0] == NULL) //Empty Group ID
			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;
		}

		memset(&entry, 0, sizeof(entry));
		entry.amount = 1;
		entry.bound = BOUND_NONE;

		// Checking group_id
		trim(str[0]);
		if (ISDIGIT(str[0][0]))
			group_id = atoi(str[0]);
		else // Try reads group id by const
			script_get_constant(trim(str[0]), &group_id);

		if (group_id < 0) {
			ShowWarning("itemdb_read_itemgroup: Invalid Group ID '%s' (%s:%d)\n", str[0], filename, ln);
			continue;
		}

		// Remove from DB
		if (strcmpi(str[1], "clear") == 0 && itemdb_group->remove(itemdb_group, db_ui2key(group_id), &data)) {
			itemdb_group_free(db_ui2key(group_id), &data, 0);
			ShowNotice("Item Group '%s' has been cleared.\n", str[0]);
			continue;
		}

		// Checking sub group
		prob = atoi(str[2]);
		if (str[4] != NULL)
			rand_group = atoi(str[4]);
		if (rand_group < 0 || rand_group > MAX_ITEMGROUP_RANDGROUP) {
			ShowWarning("itemdb_read_itemgroup: Invalid sub group '%d' for group '%s' in %s:%d\n", rand_group, str[0], filename, ln);
			continue;
		}

		if (rand_group != 0 && prob < 1) {
			ShowWarning("itemdb_read_itemgroup: Random item must has probability. Group '%s' in %s:%d\n", str[0], filename, ln);
			continue;
		}

		// Checking item
		trim(str[1]);
		if (ISDIGIT(str[1][0]) && ISDIGIT(str[1][1]) && itemdb_exists((entry.nameid = atoi(str[1]))))
			found = true;
		else {
			struct item_data *id = itemdb_searchname(str[1]);
			if (id) {
				entry.nameid = id->nameid;
				found = true;
			}
		}

		if (!found) {
			ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
			continue;
		}

		if (str[3] != NULL) entry.amount = cap_value(atoi(str[3]),1,MAX_AMOUNT);
		if (str[5] != NULL) entry.isAnnounced= atoi(str[5]);
		if (str[6] != NULL) entry.duration = cap_value(atoi(str[6]),0,UINT16_MAX);
#ifdef ENABLE_ITEM_GUID
		if (str[7] != NULL) entry.GUID = atoi(str[7]);
#endif
		if (str[8] != NULL) entry.bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1);
		if (str[9] != NULL) entry.isNamed = atoi(str[9]);

		if (!(group = (struct s_item_group_db *) uidb_get(itemdb_group, group_id))) {
			CREATE(group, struct s_item_group_db, 1);
			group->id = group_id;
			uidb_put(itemdb_group, group->id, group);
		}

		// Must item (rand_group == 0), place it here
		if (!rand_group) {
			RECREATE(group->must, struct s_item_group_entry, group->must_qty+1);
			group->must[group->must_qty++] = entry;

			// If 'must' item isn't set as random item, skip the next process
			if (!prob) {
				entries++;
				continue;
			}
			rand_group = 0;
		}
Ejemplo n.º 7
0
/** Read item group data
 * Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,isNamed,isBound}
 */
static void itemdb_read_itemgroup_sub(const char* filename)
{
	FILE *fp;
	int ln = 0, entries = 0;
	char line[1024];

	if( (fp = fopen(filename, "r")) == NULL ) {
		ShowError("Can't read %s\n", filename);
		return;
	}

	while( fgets(line, sizeof(line), fp) ) {
		uint16 nameid;
		int j, group_id, prob = 1, amt = 1, rand_group = 1, announced = 0, dur = 0, named = 0, bound = 0;
		char *str[3], *p, w1[1024], w2[1024];
		bool found = false;
		struct s_item_group_random *random;

		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;
			if( j == 2 )
				sscanf(str[j], "%d,%d,%d,%d,%d,%d,%d", &prob, &amt, &rand_group, &announced, &dur, &named, &bound);
			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;
		}

		//Checking group_id
		trim(str[0]);
		if( ISDIGIT(str[0][0]) )
			group_id = atoi(str[0]);
		else //Try reads group id by const
			script_get_constant(trim(str[0]), &group_id);
		if( group_id < 1 || group_id >= MAX_ITEMGROUP ) {
			ShowWarning("itemdb_read_itemgroup: Cannot save '%s' because invalid group id or group db is overflow in %s:%d\n", str[0], filename, ln);
			continue;
		}

		//Checking sub group
		if( rand_group < 0 || rand_group > MAX_ITEMGROUP_RANDGROUP ) {
			ShowWarning("itemdb_read_itemgroup: Invalid sub group %d for group '%s' in %s:%d\n", rand_group, str[0], filename, ln);
			continue;
		}

		if( rand_group && prob < 1 ) {
			ShowWarning("itemdb_read_itemgroup: Invalid probaility for group '%s' sub: %d in %s:%d\n", str[0], rand_group, filename, ln);
			continue;
		}

		//Checking item
		trim(str[1]);
		if( ISDIGIT(str[1][0]) && itemdb_exists((nameid = atoi(str[1]))) )
			found = true;
		else if( itemdb_searchname(str[1]) ) {
			found = true;
			nameid = itemdb_searchname(str[1])->nameid;
		}
		if( !found ) {
			ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
			continue;
		}

		amt = cap_value(amt, 1, MAX_AMOUNT);
		dur = cap_value(dur, 0, UINT16_MAX);
		bound = cap_value(bound, 0, 4);

		//Must item (rand_group == 0), place it here
		if( !rand_group ) {
			uint16 idx = itemgroup_db[group_id].must_qty;

			if( !idx )
				CREATE(itemgroup_db[group_id].must, struct s_item_group, 1);
			else
				RECREATE(itemgroup_db[group_id].must, struct s_item_group, idx + 1);

			itemgroup_db[group_id].must[idx].nameid = nameid;
			itemgroup_db[group_id].must[idx].amount = amt;
			itemgroup_db[group_id].must[idx].isAnnounced = announced;
			itemgroup_db[group_id].must[idx].duration = dur;
			itemgroup_db[group_id].must[idx].isNamed = named;
			itemgroup_db[group_id].must[idx].bound = bound;
			itemgroup_db[group_id].must_qty++;

			//If 'must' item isn't set as random item, skip the next process
			if( !prob ) {
				entries++;
				continue;
			}
			rand_group = 0;
		} else