From 96a4c962d34cbd759746cf932247c7911047ae34 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 5 Mar 2019 00:26:53 -0300 Subject: This is the first working version of Real Estate. You can change beds! --- npc/012-1/estate.txt | 2 +- npc/012-8/doorbell.txt | 19 ++++++++++--------- npc/functions/estate.txt | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/npc/012-1/estate.txt b/npc/012-1/estate.txt index e6d417d13..a457744ec 100644 --- a/npc/012-1/estate.txt +++ b/npc/012-1/estate.txt @@ -7,7 +7,7 @@ // ID: 1 // $ESTATE_OWNER[.id] → Account ID owner of the Real Estate // $ESTATE_OWNERNAME$[.id] → Human readable name of Real Estate owner -// $ESTATE_RENTTIME → When the rent will expire +// $ESTATE_RENTTIME[.id] → When the rent will expire // $ESTATE_MOBILIA_2[.id] → Bitmask of mobilia currently purchased on Yellow Collision (4) // $ESTATE_MOBILIA_4[.id] → Bitmask of mobilia currently purchased on Air Collision (2) // $ESTATE_MOBILIA_8[.id] → Bitmask of mobilia currently purchased on Water Collision (3) diff --git a/npc/012-8/doorbell.txt b/npc/012-8/doorbell.txt index 51218685e..ad3a9d4d9 100644 --- a/npc/012-8/doorbell.txt +++ b/npc/012-8/doorbell.txt @@ -10,7 +10,7 @@ // ID: 1 // $ESTATE_OWNER[.id] → Account ID owner of the Real Estate // $ESTATE_OWNERNAME$[.id] → Human readable name of Real Estate owner -// $ESTATE_RENTTIME → When the rent will expire +// $ESTATE_RENTTIME[.id] → When the rent will expire // $ESTATE_MOBILIA_2[.id] → Bitmask of mobilia currently purchased on Yellow Collision (4) // $ESTATE_MOBILIA_4[.id] → Bitmask of mobilia currently purchased on Air Collision (2) // $ESTATE_MOBILIA_8[.id] → Bitmask of mobilia currently purchased on Water Collision (3) @@ -106,7 +106,6 @@ L_Furniture: mesc ".:: "+ l("Furniture Menu") + " ::."; .@gp=REAL_ESTATE_CREDITS+Zeny; - .@dl=$ESTATE_RENTTIME[.id]/(60*60*24); mesc l("Total Credits and GP: @@", format_number(.@gp)); next; @@ -126,20 +125,20 @@ L_Furniture: case 2: mesc l("Beds"), 3; @re_col=1; // Collision layer to look up - @daysleft=$ESTATE_RENTTIME/86400; // Number of days left of rent + @daysleft=$ESTATE_RENTTIME[.id]/86400; // Number of days left of rent .@gp=REAL_ESTATE_CREDITS+Zeny; // How much you have //@valid_ids=0; // Array of valid entries deletearray @valid_ids; for (.@i=0; .@i < getarraysize(.layer); .@i++) { - debugmes "Found object ID %d named %s on layer %s coords (%d,%d) - Looking for layer %d", .@i, .name$[.@i], .layer[.@i], .x1[.@i], .y1[.@i], @re_col; + //debugmes "Found object ID %d named %s on layer %s coords (%d,%d) - Looking for layer %d", .@i, .name$[.@i], .layer[.@i], .x1[.@i], .y1[.@i], @re_col; if (.layer[.@i] == @re_col) { // We have a valid object // So we can populate a second array? // Allow to buy/sell and also setcells with params // Maybe an htable would work better (name$, .@id) array_push(@valid_ids, .@i); - debugmes "Pushing"; + //debugmes "Pushing"; } } debugmes "Found %d valid objects", getarraysize(@valid_ids); @@ -149,9 +148,9 @@ L_Furniture: for (.@j=0; .@j < getarraysize(@valid_ids); .@j++) { .@i=@valid_ids[.@j]; if ($ESTATE_MOBILIA_2[.id] & .objid[.@i]) - @menuentries$+=("Sell ")+.name$[.@i]+l(" for ") + format_number(.price[.@i]/max(1,60-@daysleft)) +":"; + @menuentries$+=("Sell ")+.name$[.@i]+l(" for ") + format_number( realestate_sellprice(.id,.price[.@i]) ) +":"; else - @menuentries$+=("Purchase ")+.name$[.@i]+(" for ") + format_number(.price[.@i])+":"; + @menuentries$+=("Purchase ")+.name$[.@i]+(" for ") + format_number( .price[.@i] )+":"; } select (@menuentries$); mes ""; @@ -162,9 +161,10 @@ L_Furniture: if ($ESTATE_MOBILIA_2[.id] & .objid[.@id]) { // If you have the mobilia, you're selling it for Mobiliary Credits - .@price=.price[.@i]/max(1,60-@daysleft); + .@price=realestate_sellprice(.id,.price[.@i]); $ESTATE_MOBILIA_2[.id]=$ESTATE_MOBILIA_2[.id] ^ .objid[.@id]; REAL_ESTATE_CREDITS+=.@price; + delcells realestate_cellname(.id, .@id); mesc l("Sale successful!"); next; } else { @@ -173,7 +173,7 @@ L_Furniture: if (.@gp > .@price) { realestate_payment(.@price); $ESTATE_MOBILIA_2[.id]=$ESTATE_MOBILIA_2[.id] | .objid[.@id]; - + setcells .mapa$, .x1[.@id], .y1[.@id], .x2[.@id], .y2[.@id], .layer[.@id], realestate_cellname(.id, .@id); mesc l("Purchase successful!"); next; } else { @@ -203,6 +203,7 @@ OnInit: .id=1; // Estate ID .delay=15; // Forced wait between rings .dpost=0; // Last doorbell ring + .mapa$="012-8"; // Arrays // We go element by element on the array building the menu diff --git a/npc/functions/estate.txt b/npc/functions/estate.txt index c6a5508a4..b9dae84b6 100644 --- a/npc/functions/estate.txt +++ b/npc/functions/estate.txt @@ -17,3 +17,22 @@ function script realestate_payment { return; } +// Generate unique name for setcells +// realestate_cellname ( estate_id, object_id ) +function script realestate_cellname { + return "RESObj_"+getarg(0)+"_"+getarg(1); +} + +// Generate sell price for furniture based on original price and estate ID +// realestate_sellprice ( estate_id, price ) +function script realestate_sellprice { + .@timeleft=$ESTATE_RENTTIME[getarg(0)]-gettimetick(2); // Number of seconds + .@daysleft=.@timeleft/86400; // Number of days left of rent + .@weeksleft=.@timeleft/604800; // Number of weeks left of rent + + //debugmes "Your contract is valid for %d weeks more - %d days", .@weeksleft, .@daysleft; + //debugmes "The divisor is %d", max(1, 8-.@weeksleft); + + return (getarg(1)/max(1, 8-.@weeksleft)) - max(0, 60-.@daysleft); +} + -- cgit v1.2.3-60-g2f50