From 5d7c8d9857f096abfc4f205c8771b0b4c91fab2c Mon Sep 17 00:00:00 2001
From: Ibrahim Zidan <brahem@aotsw.com>
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 <brahem@aotsw.com>
---
 db/pre-re/item_db.conf | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'db/pre-re')

diff --git a/db/pre-re/item_db.conf b/db/pre-re/item_db.conf
index c860e0239..3fe2fdacd 100644
--- a/db/pre-re/item_db.conf
+++ b/db/pre-re/item_db.conf
@@ -121,6 +121,8 @@ item_db: (
 	">
 	OnEquipScript: <" OnEquip Script (can also be multi-line) ">
 	OnUnequipScript: <" OnUnequip Script (can also be multi-line) ">
+	OnRentalStartScript: <" On item renting script, gets called after item is created in inventory (can also be multi-line) ">
+	OnRentalEndScript: <" On item rent end/expire script, gets called after item is removed from inventory (can also be multi-line) ">
 },
 **************************************************************************/
 
-- 
cgit v1.2.3-70-g09d2


From 5d8e006fb85df2b3bbc32f2348bbcaad950546ba Mon Sep 17 00:00:00 2001
From: Ibrahim Zidan <brahem@aotsw.com>
Date: Tue, 7 May 2019 08:05:39 +0200
Subject: Remove the hardcoded checks in pc_rental_expire and use
 OnRentalEndScript field in item database for those items instead

Fixes #140

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
---
 db/pre-re/item_db.conf | 55 ++++++++++++++++++++++++++++++++++++-------
 db/re/item_db.conf     | 55 ++++++++++++++++++++++++++++++++++++-------
 src/map/pc.c           | 64 --------------------------------------------------
 3 files changed, 92 insertions(+), 82 deletions(-)

(limited to 'db/pre-re')

diff --git a/db/pre-re/item_db.conf b/db/pre-re/item_db.conf
index 3fe2fdacd..ba9de0dd4 100644
--- a/db/pre-re/item_db.conf
+++ b/db/pre-re/item_db.conf
@@ -69572,7 +69572,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 1; ">
+	Script: <" setfont(1); ">
+	OnRentalEndScript: <"
+		if (getfont() == 1)
+			setfont(0);
+	">
 },
 {
 	Id: 12288
@@ -69589,7 +69593,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 2; ">
+	Script: <" setfont(2); ">
+	OnRentalEndScript: <"
+		if (getfont() == 2)
+			setfont(0);
+	">
 },
 {
 	Id: 12289
@@ -69606,7 +69614,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 3; ">
+	Script: <" setfont(3); ">
+	OnRentalEndScript: <"
+		if (getfont() == 3)
+			setfont(0);
+	">
 },
 {
 	Id: 12290
@@ -69858,7 +69870,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 4; ">
+	Script: <" setfont(4); ">
+	OnRentalEndScript: <"
+		if (getfont() == 4)
+			setfont(0);
+	">
 },
 {
 	Id: 12305
@@ -69875,7 +69891,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 5; ">
+	Script: <" setfont(5); ">
+	OnRentalEndScript: <"
+		if (getfont() == 5)
+			setfont(0);
+	">
 },
 {
 	Id: 12306
@@ -69892,7 +69912,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 6; ">
+	Script: <" setfont(6); ">
+	OnRentalEndScript: <"
+		if (getfont() == 6)
+			setfont(0);
+	">
 },
 {
 	Id: 12307
@@ -69909,7 +69933,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 7; ">
+	Script: <" setfont(7); ">
+	OnRentalEndScript: <"
+		if (getfont() == 7)
+			setfont(0);
+	">
 },
 {
 	Id: 12308
@@ -69926,7 +69954,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 8; ">
+	Script: <" setfont(8); ">
+	OnRentalEndScript: <"
+		if (getfont() == 8)
+			setfont(0);
+	">
 },
 {
 	Id: 12309
@@ -69943,7 +69975,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 9; ">
+	Script: <" setfont(9); ">
+	OnRentalEndScript: <"
+		if (getfont() == 9)
+			setfont(0);
+	">
 },
 {
 	Id: 12310
@@ -73053,6 +73089,7 @@ item_db: (
 		noauction: true
 	}
 	Script: <" setcashmount(); ">
+	OnRentalEndScript: <" sc_end(SC_ALL_RIDING); ">
 },
 {
 	Id: 12701
diff --git a/db/re/item_db.conf b/db/re/item_db.conf
index 9f49c07ef..f9997cb53 100644
--- a/db/re/item_db.conf
+++ b/db/re/item_db.conf
@@ -89228,7 +89228,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 1; ">
+	Script: <" setfont(1); ">
+	OnRentalEndScript: <"
+		if (getfont() == 1)
+			setfont(0);
+	">
 },
 {
 	Id: 12288
@@ -89245,7 +89249,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 2; ">
+	Script: <" setfont(2); ">
+	OnRentalEndScript: <"
+		if (getfont() == 2)
+			setfont(0);
+	">
 },
 {
 	Id: 12289
@@ -89262,7 +89270,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 3; ">
+	Script: <" setfont(3); ">
+	OnRentalEndScript: <"
+		if (getfont() == 3)
+			setfont(0);
+	">
 },
 {
 	Id: 12290
@@ -89514,7 +89526,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 4; ">
+	Script: <" setfont(4); ">
+	OnRentalEndScript: <"
+		if (getfont() == 4)
+			setfont(0);
+	">
 },
 {
 	Id: 12305
@@ -89531,7 +89547,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 5; ">
+	Script: <" setfont(5); ">
+	OnRentalEndScript: <"
+		if (getfont() == 5)
+			setfont(0);
+	">
 },
 {
 	Id: 12306
@@ -89548,7 +89568,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 6; ">
+	Script: <" setfont(6); ">
+	OnRentalEndScript: <"
+		if (getfont() == 6)
+			setfont(0);
+	">
 },
 {
 	Id: 12307
@@ -89565,7 +89589,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 7; ">
+	Script: <" setfont(7); ">
+	OnRentalEndScript: <"
+		if (getfont() == 7)
+			setfont(0);
+	">
 },
 {
 	Id: 12308
@@ -89582,7 +89610,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 8; ">
+	Script: <" setfont(8); ">
+	OnRentalEndScript: <"
+		if (getfont() == 8)
+			setfont(0);
+	">
 },
 {
 	Id: 12309
@@ -89599,7 +89631,11 @@ item_db: (
 		nomail: true
 		noauction: true
 	}
-	Script: <" setfont 9; ">
+	Script: <" setfont(9); ">
+	OnRentalEndScript: <"
+		if (getfont() == 9)
+			setfont(0);
+	">
 },
 {
 	Id: 12310
@@ -93351,6 +93387,7 @@ item_db: (
 		noauction: true
 	}
 	Script: <" setcashmount(); ">
+	OnRentalEndScript: <" sc_end(SC_ALL_RIDING); ">
 },
 {
 	Id: 12623
diff --git a/src/map/pc.c b/src/map/pc.c
index b82eb5dae..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);
-- 
cgit v1.2.3-70-g09d2