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.6 by root, Sun Jan 21 21:28:27 2007 UTC vs.
Revision 1.15 by root, Sat Oct 24 11:08:14 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines