ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/rent.ext
(Generate patch)

Comparing deliantra/server/ext/rent.ext (file contents):
Revision 1.7 by root, Thu Feb 15 03:19:02 2007 UTC vs.
Revision 1.14 by elmex, Thu Jul 17 09:13:09 2008 UTC

10 "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], 10 "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"],
11 "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], 11 "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"],
12 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], 12 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"],
13 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], 13 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"],
14 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], 14 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"],
15 "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"],
15); 16);
16 17
17# we have to special case some special cases :) 18# we have to special case some special cases :)
18sub reject_entry { 19sub reject_entry {
19 my ($pl) = @_; 20 my ($pl) = @_;
20 21
21 my $prev_pos = $pl->ob->{_prev_pos}; 22 my $prev_pos = $pl->ob->{_prev_pos};
22 $pl->ob->goto ($prev_pos ? @$prev_pos : "/world/world_105_115", 2, 34); 23 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
23 24
24 cf::override; 25 cf::override;
25} 26}
26 27
27sub update_balance { 28sub update_balance {
45} 46}
46 47
47sub pay_balance { 48sub pay_balance {
48 my ($pl) = @_; 49 my ($pl) = @_;
49 50
51 cf::cede_to_tick;
52
50 update_balance $pl; 53 update_balance $pl;
51 54
52 return unless $pl->{rent}{balance} > 0; 55 return unless $pl->{rent}{balance} > 0;
53 56
54 my $deduct = cf::ceil $pl->{rent}{balance}; 57 my $deduct = cf::ceil $pl->{rent}{balance};
57 60
58 if ($deduct <= $pl->ob->{bank_balance}) { 61 if ($deduct <= $pl->ob->{bank_balance}) {
59 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 62 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
60 $pl->ob->{bank_balance} -= $deduct; 63 $pl->ob->{bank_balance} -= $deduct;
61 $pl->{rent}{balance} -= $deduct; 64 $pl->{rent}{balance} -= $deduct;
62 $pl->ob->reply (undef, "Something whispers into your ear:\n" 65 $pl->ob->reply (undef, "Something whispers into your ear: "
63 . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); 66 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
64 } else { 67 } else {
65 $pl->ob->reply (undef, "Something whispers into your ear:\n" 68 $pl->ob->reply (undef, "Something whispers into your ear: "
66 . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " 69 . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. "
67 . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); 70 . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment.");
68 } 71 }
69} 72}
70 73
71sub check_balance { 74sub check_balance {
90 93
91 while (my ($k, $v) = each %apartment) { 94 while (my ($k, $v) = each %apartment) {
92 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 95 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
93 96
94 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 97 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] ("
95 . (cf::cost_string_from_value $v->[0]) . "/hr)") 98 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
96 if $type & $types; 99 if $type & $types;
97 } 100 }
98}; 101};
99 102
100cf::register_script_function "rent::status" => sub { 103cf::register_script_function "rent::status" => sub {
115 118
116 update_balance $pl; 119 update_balance $pl;
117 120
118 $pl->{rent}{apartment}{$apartment} = undef; 121 $pl->{rent}{apartment}{$apartment} = undef;
119 122
120 $pl->ob->reply (undef, "Wonderful decision, sir! " 123 $pl->ob->reply (undef, "Wonderful decision, your highness! "
121 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " 124 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
122 . "We are sure you will be satisfied!"); 125 . "We are sure you will be satisfied!");
123}; 126};
124 127
125cf::register_script_function "rent::stop" => sub { 128cf::register_script_function "rent::stop" => sub {
143 $pl->{rent}{last_offline_check} ||= time; 146 $pl->{rent}{last_offline_check} ||= time;
144 147
145 if ($pl->{rent}{last_online_check}) { 148 if ($pl->{rent}{last_online_check}) {
146 $pl->{rent}{last_online_check} = time 149 $pl->{rent}{last_online_check} = time
147 - List::Util::min 3600, 150 - List::Util::min 3600,
148 $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; 151 $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check};
149 } else { 152 } else {
150 $pl->{rent}{last_online_check} = time; 153 $pl->{rent}{last_online_check} = time;
151 } 154 }
152 155
153 update_balance $pl; 156 update_balance $pl;
165 for my $path (keys %{ $pl->{rent}{apartment} }) { 168 for my $path (keys %{ $pl->{rent}{apartment} }) {
166 $path = sprintf "~%s%s", $pl->ob->name, $path; 169 $path = sprintf "~%s%s", $pl->ob->name, $path;
167 170
168 if ($map->path eq $path) { 171 if ($map->path eq $path) {
169 if (check_balance $pl) { 172 if (check_balance $pl) {
170 $pl->ob->reply (undef, "Welcome to your apartment, sir!"); 173 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
171 } else { 174 } else {
172 $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); 175 $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first.");
173 reject_entry $pl; 176 reject_entry $pl;
174 } 177 }
175 178
176 return; 179 return;
177 } 180 }
178 } 181 }
179 182
180 $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); 183 $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!");
181 reject_entry $pl; 184 reject_entry $pl;
182 } 185 }
183 }, 186 },
184; 187;
185 188
186our $RENT_TIMER = Event->timer ( 189our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
187 reentrant => 0,
188 after => 60,
189 interval => 3600,
190 data => cf::WF_AUTOCANCEL,
191 cb => sub {
192 pay_balance $_ for cf::player::list; 190 pay_balance $_ for cf::player::list;
193 }, 191};
194);
195 192

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines