summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-09-23 00:38:52 +0200
committerGitHub <noreply@github.com>2019-09-23 00:38:52 +0200
commitd6dd1e7d1a8701def756d25ceb170674ee88f619 (patch)
tree291a0b3831c3876d13cad7a4488de3e10ad6c8ac /src/map
parenta1b62d431c74c2b805e2b6bd8081c2b7b7a6ff7e (diff)
parentad19056bfcc1e98129bf25e14b58dcd0d438f9f9 (diff)
downloadhercules-d6dd1e7d1a8701def756d25ceb170674ee88f619.tar.gz
hercules-d6dd1e7d1a8701def756d25ceb170674ee88f619.tar.bz2
hercules-d6dd1e7d1a8701def756d25ceb170674ee88f619.tar.xz
hercules-d6dd1e7d1a8701def756d25ceb170674ee88f619.zip
Merge pull request #2462 from hemagx/dehardcoded_rentrals
Dehardcode Rental Expire/Renting item checks
Diffstat (limited to 'src/map')
-rw-r--r--src/map/itemdb.c37
-rw-r--r--src/map/itemdb.h2
-rw-r--r--src/map/pc.c83
-rw-r--r--src/map/script.c46
-rw-r--r--src/map/script.h2
5 files changed, 101 insertions, 69 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);
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 7da7609f1..d1e5973e8 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -516,6 +516,8 @@ struct item_data {
struct script_code *script; ///< Default script for everything.
struct script_code *equip_script; ///< Script executed once when equipping.
struct script_code *unequip_script; ///< Script executed once when unequipping.
+ struct script_code *rental_start_script; ///< Script executed once this item get rented
+ struct script_code *rental_end_script; ///< Script executed once this item rent ends
struct {
unsigned available : 1;
unsigned no_refine : 1; // [celest]
diff --git a/src/map/pc.c b/src/map/pc.c
index 8ac820d79..2cefa7674 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -565,72 +565,8 @@ static int pc_inventory_rental_clear(struct map_session_data *sd)
/* assumes i is valid (from default areas where it is called, it is) */
static void pc_rental_expire(struct map_session_data *sd, int i)
{
- int nameid;
-
nullpo_retv(sd);
Assert_retv(i >= 0 && i < sd->status.inventorySize);
- nameid = sd->status.inventory[i].nameid;
-
- /* Soon to be dropped, we got plans to integrate it with item db */
- switch( nameid ) {
- case ITEMID_BOARDING_HALTER:
- status_change_end(&sd->bl,SC_ALL_RIDING,INVALID_TIMER);
- break;
- case ITEMID_LOVE_ANGEL:
- if( sd->status.font == 1 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_SQUIRREL:
- if( sd->status.font == 2 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_GOGO:
- if( sd->status.font == 3 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_PICTURE_DIARY:
- if( sd->status.font == 4 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_MINI_HEART:
- if( sd->status.font == 5 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_NEWCOMER:
- if( sd->status.font == 6 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_KID:
- if( sd->status.font == 7 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_MAGIC_CASTLE:
- if( sd->status.font == 8 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- case ITEMID_BULGING_HEAD:
- if( sd->status.font == 9 ) {
- sd->status.font = 0;
- clif->font(sd);
- }
- break;
- }
clif->rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_NORMAL, LOG_TYPE_RENTAL);
@@ -4789,13 +4725,15 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data,
pc->equipitem(sd, i, data->equip);
/* rental item check */
- if( item_data->expire_time ) {
- if( time(NULL) > item_data->expire_time ) {
- pc->rental_expire(sd,i);
+ if (item_data->expire_time > 0) {
+ if (time(NULL) > item_data->expire_time) {
+ pc->rental_expire(sd, i);
} else {
- int seconds = (int)( item_data->expire_time - time(NULL) );
+ int seconds = (int)(item_data->expire_time - time(NULL));
clif->rental_time(sd->fd, sd->status.inventory[i].nameid, seconds);
pc->inventory_rental_add(sd, seconds);
+ if (data->rental_start_script != NULL)
+ script->run_item_rental_start_script(sd, data, 0);
}
}
quest->questinfo_refresh(sd);
@@ -4826,12 +4764,21 @@ static int pc_delitem(struct map_session_data *sd, int n, int amount, int type,
sd->status.inventory[n].amount -= amount;
sd->weight -= sd->inventory_data[n]->weight*amount ;
+
+ // It's here because the data would most likely get zeroed in following if [Hemagx]
+ struct item_data *itd = sd->inventory_data[n];
+ bool is_rental = (sd->status.inventory[n].expire_time > 0) ? true : false;
+
if( sd->status.inventory[n].amount <= 0 ){
if(sd->status.inventory[n].equip)
pc->unequipitem(sd, n, PCUNEQUIPITEM_RECALC|PCUNEQUIPITEM_FORCE);
memset(&sd->status.inventory[n],0,sizeof(sd->status.inventory[0]));
sd->inventory_data[n] = NULL;
}
+
+ if (is_rental && itd->rental_end_script != NULL)
+ script->run_item_rental_end_script(sd, itd, 0);
+
if(!(type&1))
clif->delitem(sd,n,amount,reason);
if(!(type&2))
diff --git a/src/map/script.c b/src/map/script.c
index de00f66be..64b794ba0 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -22744,6 +22744,19 @@ static BUILDIN(setfont)
return true;
}
+static BUILDIN(getfont)
+{
+ struct map_session_data *sd = script->rid2sd(st);
+
+ if (sd == NULL) {
+ script_pushint(st, 0);
+ return true;
+ }
+
+ script_pushint(st, sd->status.font);
+ return true;
+}
+
static int buildin_mobuseskill_sub(struct block_list *bl, va_list ap)
{
struct mob_data *md = NULL;
@@ -25891,6 +25904,36 @@ static void script_run_item_unequip_script(struct map_session_data *sd, struct i
script->current_item_id = 0;
}
+static void script_run_item_rental_start_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull(1, 2)));
+
+/**
+ * Run item rental start script
+ * @param sd player session data. Must be correct and checked before.
+ * @param data rental item data. Must be correct and checked before.
+ * @param oid npc id. Can be also 0 or fake npc id.
+ **/
+static void script_run_item_rental_start_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->rental_start_script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
+static void script_run_item_rental_end_script(struct map_session_data *sd, struct item_data *data, int oid) __attribute__((nonnull(1, 2)));
+
+/**
+* Run item rental end script
+* @param sd player session data. Must be correct and checked before.
+* @param data rental item data. Must be correct and checked before.
+* @param oid npc id. Can be also 0 or fake npc id.
+**/
+static void script_run_item_rental_end_script(struct map_session_data *sd, struct item_data *data, int oid)
+{
+ script->current_item_id = data->nameid;
+ script->run(data->rental_end_script, 0, sd->bl.id, oid);
+ script->current_item_id = 0;
+}
+
#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args, false }
#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args, false }
#define BUILDIN_DEF_DEPRECATED(x,args) { buildin_ ## x , #x , args, true }
@@ -26326,6 +26369,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(mercenary_set_faith,"ii"),
BUILDIN_DEF(readbook,"ii"),
BUILDIN_DEF(setfont,"i"),
+ BUILDIN_DEF(getfont, ""),
BUILDIN_DEF(areamobuseskill,"siiiiviiiii"),
BUILDIN_DEF(progressbar,"si"),
BUILDIN_DEF(progressbar_unit,"si?"),
@@ -27443,4 +27487,6 @@ void script_defaults(void)
script->run_use_script = script_run_use_script;
script->run_item_equip_script = script_run_item_equip_script;
script->run_item_unequip_script = script_run_item_unequip_script;
+ script->run_item_rental_start_script = script_run_item_rental_start_script;
+ script->run_item_rental_end_script = script_run_item_rental_end_script;
}
diff --git a/src/map/script.h b/src/map/script.h
index 64e709a27..a75b948ab 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -1049,6 +1049,8 @@ struct script_interface {
void (*run_use_script) (struct map_session_data *sd, struct item_data *data, int oid);
void (*run_item_equip_script) (struct map_session_data *sd, struct item_data *data, int oid);
void (*run_item_unequip_script) (struct map_session_data *sd, struct item_data *data, int oid);
+ void (*run_item_rental_end_script) (struct map_session_data *sd, struct item_data *data, int oid);
+ void (*run_item_rental_start_script) (struct map_session_data *sd, struct item_data *data, int oid);
};
#ifdef HERCULES_CORE