summaryrefslogtreecommitdiff
path: root/src/map/itemdb.c
diff options
context:
space:
mode:
authorIbrahim Zidan <brahem@aotsw.com>2019-05-07 06:37:11 +0200
committerIbrahim Zidan <brahem@aotsw.com>2019-09-22 23:45:38 +0200
commit5d7c8d9857f096abfc4f205c8771b0b4c91fab2c (patch)
treea36b6b0ac2c942e2a18340a715bf256980c1dbec /src/map/itemdb.c
parent92f3ecdcb341b798c93d5c8b0320fb8cb85e759c (diff)
downloadhercules-5d7c8d9857f096abfc4f205c8771b0b4c91fab2c.tar.gz
hercules-5d7c8d9857f096abfc4f205c8771b0b4c91fab2c.tar.bz2
hercules-5d7c8d9857f096abfc4f205c8771b0b4c91fab2c.tar.xz
hercules-5d7c8d9857f096abfc4f205c8771b0b4c91fab2c.zip
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 <brahem@aotsw.com>
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r--src/map/itemdb.c37
1 files changed, 36 insertions, 1 deletions
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);