summaryrefslogtreecommitdiff
path: root/src/map/itemdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r--src/map/itemdb.c123
1 files changed, 68 insertions, 55 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 2a5fa48de..859b19aac 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -296,8 +296,7 @@ static struct item_data* create_item_data(int nameid)
/*==========================================
* Loads (and creates if not found) an item from the db.
*------------------------------------------*/
-struct item_data* itemdb_load(int nameid)
-{
+struct item_data* itemdb_load(int nameid) {
struct item_data *id;
if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb_array) )
@@ -590,7 +589,7 @@ static void itemdb_read_itemgroup(void)
{
char path[256];
unsigned int count;
- snprintf(path, 255, "%s/"DBPATH"item_group_db.txt", db_path);
+ snprintf(path, 255, "%s/"DBPATH"item_group_db.txt", iMap->db_path);
memset(&itemgroup_db, 0, sizeof(itemgroup_db));
count = itemdb_read_itemgroup_sub(path);
ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, "item_group_db.txt");
@@ -785,7 +784,7 @@ void itemdb_read_combos() {
char path[256];
FILE* fp;
- sprintf(path, "%s/%s", db_path, DBPATH"item_combo_db.txt");
+ sprintf(path, "%s/%s", iMap->db_path, DBPATH"item_combo_db.txt");
if ((fp = fopen(path, "r")) == NULL) {
ShowError("itemdb_read_combos: File not found \"%s\".\n", path);
@@ -967,7 +966,7 @@ void itemdb_re_split_atoi(char *str, int *atk, int *matk) {
/*==========================================
* processes one itemdb entry
*------------------------------------------*/
-static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt) {
+int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt) {
/*
+----+--------------+---------------+------+-----------+------------+--------+--------+---------+-------+-------+------------+-------------+---------------+-----------------+--------------+-------------+------------+------+--------+--------------+----------------+
| 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
@@ -977,12 +976,12 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
*/
int nameid;
struct item_data* id;
+ unsigned char offset = 0;
nameid = atoi(str[0]);
- if( nameid <= 0 )
- {
+ if( nameid <= 0 ) {
ShowWarning("itemdb_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", nameid, line, source);
- return false;
+ return 0;
}
//ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
@@ -1030,39 +1029,47 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
id->weight = atoi(str[6]);
#ifdef RENEWAL
- itemdb_re_split_atoi(str[7],&id->atk,&id->matk);
+ if( iMap->db_use_sqldbs ) {
+ id->atk = atoi(str[7]);
+ id->matk = atoi(str[8]);
+ offset += 1;
+ } else
+ itemdb_re_split_atoi(str[7],&id->atk,&id->matk);
#else
id->atk = atoi(str[7]);
#endif
- id->def = atoi(str[8]);
- id->range = atoi(str[9]);
- id->slot = atoi(str[10]);
+ id->def = atoi(str[8+offset]);
+ id->range = atoi(str[9+offset]);
+ id->slot = atoi(str[10+offset]);
- if (id->slot > MAX_SLOTS)
- {
+ if (id->slot > MAX_SLOTS) {
ShowWarning("itemdb_parse_dbrow: Item %d (%s) specifies %d slots, but the server only supports up to %d. Using %d slots.\n", nameid, id->jname, id->slot, MAX_SLOTS, MAX_SLOTS);
id->slot = MAX_SLOTS;
}
- itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11],NULL,0));
- id->class_upper = atoi(str[12]);
- id->sex = atoi(str[13]);
- id->equip = atoi(str[14]);
+ itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11+offset],NULL,0));
+ id->class_upper = atoi(str[12+offset]);
+ id->sex = atoi(str[13+offset]);
+ id->equip = atoi(str[14+offset]);
- if (!id->equip && itemdb_isequip2(id))
- {
+ if (!id->equip && itemdb_isequip2(id)) {
ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
id->type = IT_ETC;
}
- id->wlv = cap_value(atoi(str[15]), REFINE_TYPE_ARMOR, REFINE_TYPE_MAX);
+ id->wlv = cap_value(atoi(str[15+offset]), REFINE_TYPE_ARMOR, REFINE_TYPE_MAX);
#ifdef RENEWAL
- itemdb_re_split_atoi(str[16],&id->elv,&id->elvmax);
+ if( iMap->db_use_sqldbs ) {
+ id->elv = atoi(str[16+offset]);
+ id->elvmax = atoi(str[17+offset]);
+ offset += 1;
+ } else
+ itemdb_re_split_atoi(str[16],&id->elv,&id->elvmax);
#else
id->elv = atoi(str[16]);
#endif
- id->flag.no_refine = atoi(str[17]) ? 0 : 1; //FIXME: verify this
- id->look = atoi(str[18]);
+ id->flag.no_refine = atoi(str[17+offset]) ? 0 : 1; //FIXME: verify this
+ id->look = atoi(str[18+offset]);
id->flag.available = 1;
id->view_id = 0;
@@ -1081,14 +1088,14 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
id->unequip_script = NULL;
}
- if (*str[19])
- id->script = parse_script(str[19], source, line, scriptopt);
- if (*str[20])
- id->equip_script = parse_script(str[20], source, line, scriptopt);
- if (*str[21])
- id->unequip_script = parse_script(str[21], source, line, scriptopt);
+ if (*str[19+offset])
+ id->script = parse_script(str[19+offset], source, line, scriptopt);
+ if (*str[20+offset])
+ id->equip_script = parse_script(str[20+offset], source, line, scriptopt);
+ if (*str[21+offset])
+ id->unequip_script = parse_script(str[21+offset], source, line, scriptopt);
- return true;
+ return id->nameid;
}
/*==========================================
@@ -1110,7 +1117,7 @@ static int itemdb_readdb(void)
char path[256];
FILE* fp;
- sprintf(path, "%s/%s", db_path, filename[fi]);
+ sprintf(path, "%s/%s", iMap->db_path, filename[fi]);
fp = fopen(path, "r");
if( fp == NULL ) {
ShowWarning("itemdb_readdb: File not found \"%s\", skipping.\n", path);
@@ -1205,7 +1212,7 @@ static int itemdb_readdb(void)
}
}
- if (!itemdb_parse_dbrow(str, path, lines, 0))
+ if (!itemdb->parse_dbrow(str, path, lines, 0))
continue;
count++;
@@ -1218,7 +1225,6 @@ static int itemdb_readdb(void)
return 0;
}
-
/*======================================
* item_db table reading
*======================================*/
@@ -1226,15 +1232,15 @@ static int itemdb_read_sqldb(void) {
const char* item_db_name[] = {
#ifdef RENEWAL
- item_db_re_db,
+ iMap->item_db_re_db,
#else
- item_db_db,
+ iMap->item_db_db,
#endif
- item_db2_db };
+ iMap->item_db2_db };
int fi;
for( fi = 0; fi < ARRAYLENGTH(item_db_name); ++fi ) {
- uint32 lines = 0, count = 0;
+ uint32 count = 0;
// retrieve all rows from the item database
if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) ) {
@@ -1244,17 +1250,16 @@ static int itemdb_read_sqldb(void) {
// process rows one by one
while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format
- char* str[22];
+ char* str[ITEMDB_SQL_COLUMNS];
char* dummy = "";
int i;
- ++lines;
- for( i = 0; i < 22; ++i ) {
+ for( i = 0; i < ITEMDB_SQL_COLUMNS; ++i ) {
SQL->GetData(mmysql_handle, i, &str[i], NULL);
if( str[i] == NULL )
str[i] = dummy; // get rid of NULL columns
}
- if (!itemdb_parse_dbrow(str, item_db_name[fi], lines, SCRIPT_IGNORE_EXTERNAL_BRACKETS))
+ if (!itemdb->parse_dbrow(str, item_db_name[fi], -(atoi(str[0])), SCRIPT_IGNORE_EXTERNAL_BRACKETS))
continue;
++count;
}
@@ -1293,14 +1298,13 @@ uint64 itemdb_unique_id(int8 flag, int64 value) {
return ++item_uid;
}
-int itemdb_uid_load(){
+int itemdb_uid_load() {
char * uid;
- if (SQL_ERROR == SQL->Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'"))
+ if (SQL_ERROR == SQL->Query(mmysql_handle, "SELECT `value` FROM `%s` WHERE `varname`='unique_id'",iMap->interreg_db))
Sql_ShowDebug(mmysql_handle);
- if( SQL_SUCCESS != SQL->NextRow(mmysql_handle) )
- {
+ if( SQL_SUCCESS != SQL->NextRow(mmysql_handle) ) {
ShowError("itemdb_uid_load: Unable to fetch unique_id data\n");
SQL->FreeResult(mmysql_handle);
return -1;
@@ -1318,19 +1322,19 @@ int itemdb_uid_load(){
*------------------------------------*/
static void itemdb_read(void) {
- if (db_use_sqldbs)
+ if (iMap->db_use_sqldbs)
itemdb_read_sqldb();
else
itemdb_readdb();
itemdb_read_combos();
itemdb_read_itemgroup();
- sv->readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail);
- sv->readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
- sv->readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay);
- sv->readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack);
- sv->readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore);
- sv->readdb(db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse);
+ sv->readdb(iMap->db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail);
+ sv->readdb(iMap->db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
+ sv->readdb(iMap->db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay);
+ sv->readdb(iMap->db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack);
+ sv->readdb(iMap->db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore);
+ sv->readdb(iMap->db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse);
itemdb_uid_load();
}
@@ -1435,7 +1439,7 @@ void itemdb_reload(void)
iter = mapit_geteachpc();
for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) {
memset(sd->item_delay, 0, sizeof(sd->item_delay)); // reset item delays
- pc_setinventorydata(sd);
+ pc->setinventorydata(sd);
/* clear combo bonuses */
if( sd->combos.count ) {
aFree(sd->combos.bonus);
@@ -1443,7 +1447,7 @@ void itemdb_reload(void)
sd->combos.bonus = NULL;
sd->combos.id = NULL;
sd->combos.count = 0;
- if( pc_load_combo(sd) > 0 )
+ if( pc->load_combo(sd) > 0 )
status_calc_pc(sd,0);
}
@@ -1472,3 +1476,12 @@ int do_init_itemdb(void) {
return 0;
}
+/* incomplete */
+void itemdb_defaults(void) {
+ itemdb = &itemdb_s;
+
+ itemdb->reload = itemdb_reload;//incomplet=e
+ /* */
+ itemdb->parse_dbrow = itemdb_parse_dbrow;
+ itemdb->exists = itemdb_exists;//incomplete
+}