summaryrefslogtreecommitdiff
path: root/src/map/pc.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/pc.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/pc.c')
-rw-r--r--src/map/pc.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 8ac820d79..b82eb5dae 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4789,13 +4789,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 +4828,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))