ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/rent.ext
Revision: 1.30
Committed: Mon Apr 26 12:09:03 2010 UTC (14 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.29: +2 -0 lines
Log Message:
added heaven and st. batholomew apartments.

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     use List::Util;
4    
5 root 1.20 our %apartment = (
6 root 1.1 "/scorn/apartment/apartments" => [ 1, "scorn", "skorn"],
7     "/santo_dominion/sdomino_appartment" => [ 10, "santo dominion", "domino"],
8     "/darcap/darcap/apartment" => [ 30, "darcap", "thecap"],
9 elmex 1.26 "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"],
10 root 1.1 "/navar_city/apartments/apartment" => [ 250, "navar", "navar"],
11 elmex 1.26 "/celvear_port/tower2/tower2" => [ 300, "celvear port", "kevlar"],
12 root 1.1 "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"],
13     "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"],
14 elmex 1.30 "/mlab/mountpermapartment" => [ 400, "st. bartholomew", "barth"],
15 elmex 1.28 "/valleynoy/jewelertown/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"],
16 elmex 1.30 "/heaven/apartment" => [ 1500, "heaven town", "heaven"],
17 root 1.1 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"],
18 root 1.16 "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"],
19 root 1.21 "/gotischerbereich/towerapartment/tower1" => [10000, "gotisch", "retreat"],
20 root 1.27 "/lake_country/Butakis/apartment" => [25000, "castle butakis", "expandor"],
21 root 1.18 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"],
22 root 1.1 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"],
23     );
24    
25     # we have to special case some special cases :)
26     sub reject_entry {
27     my ($pl) = @_;
28    
29 root 1.7 my $prev_pos = $pl->ob->{_prev_pos};
30 root 1.8 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
31 root 1.7
32 root 1.1 cf::override;
33     }
34    
35     sub update_balance {
36     my ($pl) = @_;
37    
38     my $NOW = time;
39    
40     # 1 silver per day per level per apartment of kingdom tax
41     my $offline = (List::Util::min 30, ($NOW - $pl->{rent}{last_offline_check}) / 86400)
42     * (cf::exp_to_level $pl->ob->stats->exp)
43     * scalar keys %{ $pl->{rent}{apartment} };
44    
45     # once per hour per map rented
46     my $online = ($NOW - $pl->{rent}{last_online_check}) / 3600
47     * List::Util::sum map $apartment{$_}[0], keys %{ $pl->{rent}{apartment} };
48    
49     $pl->{rent}{last_offline_check} = $NOW;
50     $pl->{rent}{last_online_check} = $NOW;
51    
52     $pl->{rent}{balance} += $offline + $online;
53     }
54    
55     sub pay_balance {
56     my ($pl) = @_;
57    
58 root 1.11 cf::cede_to_tick;
59    
60 root 1.1 update_balance $pl;
61    
62     return unless $pl->{rent}{balance} > 0;
63    
64     my $deduct = cf::ceil $pl->{rent}{balance};
65    
66     my $deduct_string = cf::cost_string_from_value $deduct;
67    
68     if ($deduct <= $pl->ob->{bank_balance}) {
69     cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
70     $pl->ob->{bank_balance} -= $deduct;
71     $pl->{rent}{balance} -= $deduct;
72 root 1.10 $pl->ob->reply (undef, "Something whispers into your ear: "
73 root 1.9 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
74 root 1.1 } else {
75 root 1.10 $pl->ob->reply (undef, "Something whispers into your ear: "
76 root 1.9 . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. "
77 root 1.1 . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment.");
78     }
79     }
80    
81     sub check_balance {
82     my ($pl) = @_;
83    
84     pay_balance $pl if $pl->{rent}{balance} > 0;
85    
86     $pl->{rent}{balance} <= 0
87     }
88    
89     sub find_apartment {
90     my ($pl, $name) = @_;
91    
92     my $apartment = (grep $apartment{$_}[2] eq $name, keys %apartment)[0]
93     or $pl->ob->reply (undef, "Sorry, but we do not offer model '$name' for rent.");
94    
95     $apartment
96     }
97    
98     cf::register_script_function "rent::overview" => sub {
99     my ($pl, $types) = @_;
100    
101     while (my ($k, $v) = each %apartment) {
102     my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
103    
104 root 1.17 $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] ("
105 root 1.10 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
106 root 1.1 if $type & $types;
107     }
108     };
109    
110     cf::register_script_function "rent::status" => sub {
111     my ($pl, $types) = @_;
112    
113     if ($pl->{rent}{balance} <= 0) {
114     $pl->ob->reply (undef, "You have no debts to pay.");
115     } else {
116     $pl->ob->reply (undef, "You owe us " . (cf::cost_string_from_value $pl->{rent}{balance}) . ".");
117     }
118     };
119    
120     cf::register_script_function "rent::rent" => sub {
121     my ($pl, $apartment) = @_;
122    
123     $apartment = find_apartment $pl, $apartment
124     or return;
125    
126     update_balance $pl;
127    
128     $pl->{rent}{apartment}{$apartment} = undef;
129    
130 root 1.9 $pl->ob->reply (undef, "Wonderful decision, your highness! "
131 root 1.1 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
132     . "We are sure you will be satisfied!");
133     };
134    
135     cf::register_script_function "rent::stop" => sub {
136     my ($pl, $apartment) = @_;
137    
138     $apartment = find_apartment $pl, $apartment
139     or return;
140    
141     update_balance $pl;
142    
143     delete $pl->{rent}{apartment}{$apartment};
144    
145     $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course.");
146     };
147    
148 root 1.2 cf::player->attach (
149     prio => 100,
150 root 1.1 on_login => sub {
151     my ($pl) = @_;
152    
153     $pl->{rent}{last_offline_check} ||= time;
154    
155     if ($pl->{rent}{last_online_check}) {
156     $pl->{rent}{last_online_check} = time
157     - List::Util::min 3600,
158 root 1.13 $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check};
159 root 1.1 } else {
160     $pl->{rent}{last_online_check} = time;
161     }
162    
163     update_balance $pl;
164 root 1.2 },
165     );
166 root 1.1
167 root 1.2 cf::map::attachment rent =>
168 root 1.1 on_enter => sub {
169     my ($map, $pl, $x, $y) = @_;
170    
171 root 1.25 return if $pl->ob->flag (cf::FLAG_WIZ);
172    
173 root 1.7 my $pfx = sprintf "~%s/", $pl->ob->name;
174 root 1.1
175 root 1.7 # only do something if entering ones own apartment
176     if ($pfx eq substr $map->path, 0, length $pfx) {
177     for my $path (keys %{ $pl->{rent}{apartment} }) {
178     $path = sprintf "~%s%s", $pl->ob->name, $path;
179    
180     if ($map->path eq $path) {
181     if (check_balance $pl) {
182 root 1.9 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
183 root 1.7 } else {
184 root 1.29 $pl->failmsg ("We are sorry, your highness, you have to pay your rent first.");
185 root 1.7 reject_entry $pl;
186     }
187 root 1.1
188 root 1.7 return;
189 root 1.1 }
190 root 1.7 }
191 root 1.1
192 root 1.29 $pl->failmsg ("Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!");
193 root 1.7 reject_entry $pl;
194 root 1.1 }
195     },
196     ;
197    
198 root 1.12 our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
199     pay_balance $_ for cf::player::list;
200     };
201 root 1.1