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.4 by root, Thu Jan 4 18:39:14 2007 UTC vs.
Revision 1.25 by root, Fri Mar 19 21:37:42 2010 UTC

1#! perl 1#! perl
2 2
3use List::Util; 3use List::Util;
4 4
5my %apartment = ( 5our %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 "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], 9 "/navar_city/apartments/apartment" => [ 250, "navar", "navar"],
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 "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"],
12 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], 13 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"],
14 "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"],
15 "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"],
16 "/celvear_port/tower2/tower2" => [ 300, "celvear", "kevlar"],
17 "/gotischerbereich/towerapartment/tower1" => [10000, "gotisch", "retreat"],
18 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"],
13 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], 19 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"],
14 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"],
15); 20);
16 21
17# we have to special case some special cases :) 22# we have to special case some special cases :)
18sub reject_entry { 23sub reject_entry {
19 my ($pl) = @_; 24 my ($pl) = @_;
20 25
26 my $prev_pos = $pl->ob->{_prev_pos};
27 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
28
21 cf::override; 29 cf::override;
22
23 $pl->goto_map ("/world/world_105_115", 2, 34)
24 unless
25 $pl->ob->map
26 && !$pl->ob->map->{path}{user_rel};
27} 30}
28 31
29sub update_balance { 32sub update_balance {
30 my ($pl) = @_; 33 my ($pl) = @_;
31 34
47} 50}
48 51
49sub pay_balance { 52sub pay_balance {
50 my ($pl) = @_; 53 my ($pl) = @_;
51 54
55 cf::cede_to_tick;
56
52 update_balance $pl; 57 update_balance $pl;
53 58
54 return unless $pl->{rent}{balance} > 0; 59 return unless $pl->{rent}{balance} > 0;
55 60
56 my $deduct = cf::ceil $pl->{rent}{balance}; 61 my $deduct = cf::ceil $pl->{rent}{balance};
59 64
60 if ($deduct <= $pl->ob->{bank_balance}) { 65 if ($deduct <= $pl->ob->{bank_balance}) {
61 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 66 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
62 $pl->ob->{bank_balance} -= $deduct; 67 $pl->ob->{bank_balance} -= $deduct;
63 $pl->{rent}{balance} -= $deduct; 68 $pl->{rent}{balance} -= $deduct;
64 $pl->ob->reply (undef, "Something whispers into your ear:\n" 69 $pl->ob->reply (undef, "Something whispers into your ear: "
65 . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); 70 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
66 } else { 71 } else {
67 $pl->ob->reply (undef, "Something whispers into your ear:\n" 72 $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. " 73 . "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."); 74 . "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 } 75 }
71} 76}
72 77
73sub check_balance { 78sub check_balance {
91 my ($pl, $types) = @_; 96 my ($pl, $types) = @_;
92 97
93 while (my ($k, $v) = each %apartment) { 98 while (my ($k, $v) = each %apartment) {
94 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 99 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
95 100
96 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 101 $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] ("
97 . (cf::cost_string_from_value $v->[0]) . "/hr)") 102 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
98 if $type & $types; 103 if $type & $types;
99 } 104 }
100}; 105};
101 106
102cf::register_script_function "rent::status" => sub { 107cf::register_script_function "rent::status" => sub {
117 122
118 update_balance $pl; 123 update_balance $pl;
119 124
120 $pl->{rent}{apartment}{$apartment} = undef; 125 $pl->{rent}{apartment}{$apartment} = undef;
121 126
122 $pl->ob->reply (undef, "Wonderful decision, sir! " 127 $pl->ob->reply (undef, "Wonderful decision, your highness! "
123 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " 128 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
124 . "We are sure you will be satisfied!"); 129 . "We are sure you will be satisfied!");
125}; 130};
126 131
127cf::register_script_function "rent::stop" => sub { 132cf::register_script_function "rent::stop" => sub {
145 $pl->{rent}{last_offline_check} ||= time; 150 $pl->{rent}{last_offline_check} ||= time;
146 151
147 if ($pl->{rent}{last_online_check}) { 152 if ($pl->{rent}{last_online_check}) {
148 $pl->{rent}{last_online_check} = time 153 $pl->{rent}{last_online_check} = time
149 - List::Util::min 3600, 154 - List::Util::min 3600,
150 $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; 155 $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check};
151 } else { 156 } else {
152 $pl->{rent}{last_online_check} = time; 157 $pl->{rent}{last_online_check} = time;
153 } 158 }
154 159
155 update_balance $pl; 160 update_balance $pl;
158 163
159cf::map::attachment rent => 164cf::map::attachment rent =>
160 on_enter => sub { 165 on_enter => sub {
161 my ($map, $pl, $x, $y) = @_; 166 my ($map, $pl, $x, $y) = @_;
162 167
163 # can freely enter homes of other people 168 return if $pl->ob->flag (cf::FLAG_WIZ);
164 {
165 my $path = sprintf "%s/%s/%s/",
166 cf::localdir, cf::playerdir, $pl->ob->name;
167 169
170 my $pfx = sprintf "~%s/", $pl->ob->name;
171
172 # only do something if entering ones own apartment
168 return if $path ne substr $map->path, 0, length $path; 173 if ($pfx eq substr $map->path, 0, length $pfx) {
174 for my $path (keys %{ $pl->{rent}{apartment} }) {
175 $path = sprintf "~%s%s", $pl->ob->name, $path;
176
177 if ($map->path eq $path) {
178 if (check_balance $pl) {
179 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
180 } else {
181 $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first.");
182 reject_entry $pl;
183 }
184
185 return;
186 }
187 }
188
189 $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!");
190 reject_entry $pl;
169 } 191 }
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 }, 192 },
191; 193;
192 194
193our $RENT_TIMER = Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { 195our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
194 pay_balance $_ for cf::player::list; 196 pay_balance $_ for cf::player::list;
195}); 197};
196 198

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines