Skip to content

Commit

Permalink
Added Inheritance support for item_db2
Browse files Browse the repository at this point in the history
- If an item is marked as Inherit: true in item_db2, and it already
  exists, in item_db, then any unspecified fields are taken from the
  item_db entry rather than using their default values.
- Special thanks to Ind.

Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Nov 14, 2013
1 parent 091e235 commit d3fe9bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
1 change: 0 additions & 1 deletion db/re/item_db.conf
Expand Up @@ -51804,7 +51804,6 @@ item_db: (
Type: 5
Buy: 20
Weight: 500
Def: -7
Upper: 63
Loc: 256
EquipLv: 40
Expand Down
61 changes: 39 additions & 22 deletions src/map/itemdb.c
Expand Up @@ -1688,8 +1688,8 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
struct item_data id = { 0 };
config_setting_t *t = NULL;
const char *str = NULL;
uint32 ui32 = 0;
int i32 = 0;
bool inherit = false;

/*
* // Mandatory fields
Expand Down Expand Up @@ -1720,37 +1720,55 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
* ">
* OnEquipScript: <" OnEquip Script ">
* OnUnequipScript: <" OnUnequip Script ">
* Inherit: inherit or override
*/
if( !config_setting_lookup_int(it, "Id", &i32) ) {
ShowWarning("itemdb_readdb_libconfig_sub: Invalid or missing id in \"%s\", entry #%d, skipping.\n", source, n);
return 0;
}
id.nameid = (uint16)i32;

if( (t = config_setting_get_member(it, "Inherit")) && (inherit = config_setting_get_bool(t)) ) {
if( !itemdb->exists(id.nameid) ) {
ShowWarning("itemdb_readdb_libconfig_sub: Trying to inherit nonexistent item %d, default values will be used instead.\n", id.nameid);
inherit = false;
} else {
// Use old entry as default
struct item_data *old_entry = itemdb->load(id.nameid);
memcpy(&id, old_entry, sizeof(struct item_data));
}
}

if( !config_setting_lookup_string(it, "AegisName", &str) || !*str ) {
ShowWarning("itemdb_readdb_libconfig_sub: Missing AegisName in item %d of \"%s\", skipping.\n", id.nameid, source);
return 0;
if( !inherit ) {
ShowWarning("itemdb_readdb_libconfig_sub: Missing AegisName in item %d of \"%s\", skipping.\n", id.nameid, source);
return 0;
}
} else {
safestrncpy(id.name, str, sizeof(id.name));
}
safestrncpy(id.name, str, sizeof(id.name));

if( !config_setting_lookup_string(it, "Name", &str) || !*str ) {
ShowWarning("itemdb_readdb_libconfig_sub: Missing Name in item %d of \"%s\", skipping.\n", id.nameid, source);
return 0;
if( !inherit ) {
ShowWarning("itemdb_readdb_libconfig_sub: Missing Name in item %d of \"%s\", skipping.\n", id.nameid, source);
return 0;
}
} else {
safestrncpy(id.jname, str, sizeof(id.jname));
}
safestrncpy(id.jname, str, sizeof(id.jname));

if( config_setting_lookup_int(it, "Type", &i32) )
id.type = i32;
else
else if( !inherit )
id.type = IT_UNKNOWN;

if( config_setting_lookup_int(it, "Buy", &i32) )
id.value_buy = i32;
else
else if( !inherit )
id.value_buy = -1;
if( config_setting_lookup_int(it, "Sell", &i32) )
id.value_sell = i32;
else
else if( !inherit )
id.value_sell = -1;

if( config_setting_lookup_int(it, "Weight", &i32) && i32 >= 0 )
Expand All @@ -1772,19 +1790,18 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
id.slot = i32;

if( config_setting_lookup_int(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0
ui32 = (unsigned int)i32;
else
ui32 = UINT_MAX;
itemdb->jobid2mapid(id.class_base, ui32);
itemdb->jobid2mapid(id.class_base, (unsigned int)i32);
else if( !inherit )
itemdb->jobid2mapid(id.class_base, UINT_MAX);

if( config_setting_lookup_int(it, "Upper", &i32) && i32 >= 0 )
id.class_upper = (unsigned int)i32;
else
else if( !inherit )
id.class_upper = ITEMUPPER_ALL;

if( config_setting_lookup_int(it, "Gender", &i32) && i32 >= 0 )
id.sex = i32;
else
else if( !inherit )
id.sex = 2;

if( config_setting_lookup_int(it, "Loc", &i32) && i32 >= 0 )
Expand All @@ -1810,14 +1827,14 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
if( config_setting_lookup_int(it, "View", &i32) && i32 >= 0 )
id.look = i32;

if( config_setting_lookup_string(it, "Script", &str) && *str )
id.script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
if( config_setting_lookup_string(it, "Script", &str) )
id.script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;

if( config_setting_lookup_string(it, "OnEquipScript", &str) && *str )
id.equip_script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
if( config_setting_lookup_string(it, "OnEquipScript", &str) )
id.equip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;

if( config_setting_lookup_string(it, "OnUnequipScript", &str) && *str )
id.unequip_script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
if( config_setting_lookup_string(it, "OnUnequipScript", &str) )
id.unequip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;

return itemdb->validate_entry(&id, n, source);
}
Expand Down

0 comments on commit d3fe9bb

Please sign in to comment.