From 5d7c8d9857f096abfc4f205c8771b0b4c91fab2c Mon Sep 17 00:00:00 2001 From: Ibrahim Zidan Date: Tue, 7 May 2019 06:37:11 +0200 Subject: Implement new script fields for items triggered on rentral status changes - OnRentalStartScript triggered when a rental item is added to inventory - OnRentalEndScript triggered when a rental period end/expire of the item Related #140 Signed-off-by: Ibrahim Zidan --- src/map/itemdb.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/map/itemdb.c') diff --git a/src/map/itemdb.c b/src/map/itemdb.c index bb2732b17..204d0ead5 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1726,6 +1726,14 @@ static int itemdb_validate_entry(struct item_data *entry, int n, const char *sou script->free_code(entry->unequip_script); entry->unequip_script = NULL; } + if (entry->rental_start_script != NULL) { + script->free_code(entry->rental_start_script); + entry->rental_start_script = NULL; + } + if (entry->rental_end_script != NULL) { + script->free_code(entry->rental_end_script); + entry->rental_end_script = NULL; + } return 0; #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114 } @@ -1756,6 +1764,14 @@ static int itemdb_validate_entry(struct item_data *entry, int n, const char *sou script->free_code(entry->unequip_script); entry->unequip_script = NULL; } + if (entry->rental_start_script != NULL) { + script->free_code(entry->rental_start_script); + entry->rental_start_script = NULL; + } + if (entry->rental_end_script != NULL) { + script->free_code(entry->rental_end_script); + entry->rental_end_script = NULL; + } return 0; } } @@ -1883,7 +1899,14 @@ static int itemdb_validate_entry(struct item_data *entry, int n, const char *sou script->free_code(item->unequip_script); item->unequip_script = NULL; } - + if (item->rental_start_script != NULL && item->rental_start_script != entry->rental_start_script) { // Don't free if it's inheriting the same script + script->free_code(item->rental_start_script); + item->rental_start_script = NULL; + } + if (item->rental_end_script != NULL && item->rental_end_script != entry->rental_end_script) { // Don't free if it's inheriting the same script + script->free_code(item->rental_end_script); + item->rental_end_script = NULL; + } *item = *entry; return item->nameid; } @@ -1999,6 +2022,8 @@ static int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const * "> * OnEquipScript: <" OnEquip Script "> * OnUnequipScript: <" OnUnequip Script "> + * OnRentalStartScript: <" on renting script "> + * OnRentalEndScript: <" on renting end script "> * Inherit: inherit or override */ if( !itemdb->lookup_const(it, "Id", &i32) ) { @@ -2276,6 +2301,12 @@ static int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const if( libconfig->setting_lookup_string(it, "OnUnequipScript", &str) ) id.unequip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; + if (libconfig->setting_lookup_string(it, "OnRentalStartScript", &str) != CONFIG_FALSE) + id.rental_start_script = (*str != '\0') ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; + + if (libconfig->setting_lookup_string(it, "OnRentalEndScript", &str) != CONFIG_FALSE) + id.rental_end_script = (*str != '\0') ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL; + return itemdb->validate_entry(&id, n, source); } @@ -2519,6 +2550,10 @@ static void destroy_item_data(struct item_data *self, int free_self) script->free_code(self->equip_script); if( self->unequip_script ) script->free_code(self->unequip_script); + if (self->rental_start_script != NULL) + script->free_code(self->rental_start_script); + if (self->rental_end_script != NULL) + script->free_code(self->rental_end_script); if( self->combos ) aFree(self->combos); HPM->data_store_destroy(&self->hdata); -- cgit v1.2.3-70-g09d2