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.3 by root, Thu Jan 4 18:38:22 2007 UTC vs.
Revision 1.16 by root, Sat Oct 24 11:10:46 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"],
15 "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"],
13 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], 16 "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"],
14 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], 17 "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"],
15); 18);
16
17sub teleport {
18 my ($pl, $map, $x, $y) = @_;
19
20 my $portal = cf::object::new "exit";
21
22 $portal->slaying ($map);
23 $portal->stats->hp ($x);
24 $portal->stats->sp ($y);
25 $portal->apply ($pl->ob);
26 $portal->destroy;
27}
28 19
29# we have to special case some special cases :) 20# we have to special case some special cases :)
30sub reject_entry { 21sub reject_entry {
31 my ($pl) = @_; 22 my ($pl) = @_;
32 23
24 my $prev_pos = $pl->ob->{_prev_pos};
25 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
26
33 cf::override; 27 cf::override;
34
35 $pl->goto_map ("/world/world_105_115", 2, 34)
36 unless
37 $pl->ob->map
38 && !$pl->ob->map->{path}{user_rel};
39} 28}
40 29
41sub update_balance { 30sub update_balance {
42 my ($pl) = @_; 31 my ($pl) = @_;
43 32
59} 48}
60 49
61sub pay_balance { 50sub pay_balance {
62 my ($pl) = @_; 51 my ($pl) = @_;
63 52
53 cf::cede_to_tick;
54
64 update_balance $pl; 55 update_balance $pl;
65 56
66 return unless $pl->{rent}{balance} > 0; 57 return unless $pl->{rent}{balance} > 0;
67 58
68 my $deduct = cf::ceil $pl->{rent}{balance}; 59 my $deduct = cf::ceil $pl->{rent}{balance};
71 62
72 if ($deduct <= $pl->ob->{bank_balance}) { 63 if ($deduct <= $pl->ob->{bank_balance}) {
73 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 64 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
74 $pl->ob->{bank_balance} -= $deduct; 65 $pl->ob->{bank_balance} -= $deduct;
75 $pl->{rent}{balance} -= $deduct; 66 $pl->{rent}{balance} -= $deduct;
76 $pl->ob->reply (undef, "Something whispers into your ear:\n" 67 $pl->ob->reply (undef, "Something whispers into your ear: "
77 . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); 68 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
78 } else { 69 } else {
79 $pl->ob->reply (undef, "Something whispers into your ear:\n" 70 $pl->ob->reply (undef, "Something whispers into your ear: "
80 . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " 71 . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. "
81 . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); 72 . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment.");
82 } 73 }
83} 74}
84 75
85sub check_balance { 76sub check_balance {
104 95
105 while (my ($k, $v) = each %apartment) { 96 while (my ($k, $v) = each %apartment) {
106 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 97 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
107 98
108 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 99 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] ("
109 . (cf::cost_string_from_value $v->[0]) . "/hr)") 100 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
110 if $type & $types; 101 if $type & $types;
111 } 102 }
112}; 103};
113 104
114cf::register_script_function "rent::status" => sub { 105cf::register_script_function "rent::status" => sub {
129 120
130 update_balance $pl; 121 update_balance $pl;
131 122
132 $pl->{rent}{apartment}{$apartment} = undef; 123 $pl->{rent}{apartment}{$apartment} = undef;
133 124
134 $pl->ob->reply (undef, "Wonderful decision, sir! " 125 $pl->ob->reply (undef, "Wonderful decision, your highness! "
135 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " 126 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
136 . "We are sure you will be satisfied!"); 127 . "We are sure you will be satisfied!");
137}; 128};
138 129
139cf::register_script_function "rent::stop" => sub { 130cf::register_script_function "rent::stop" => sub {
157 $pl->{rent}{last_offline_check} ||= time; 148 $pl->{rent}{last_offline_check} ||= time;
158 149
159 if ($pl->{rent}{last_online_check}) { 150 if ($pl->{rent}{last_online_check}) {
160 $pl->{rent}{last_online_check} = time 151 $pl->{rent}{last_online_check} = time
161 - List::Util::min 3600, 152 - List::Util::min 3600,
162 $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; 153 $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check};
163 } else { 154 } else {
164 $pl->{rent}{last_online_check} = time; 155 $pl->{rent}{last_online_check} = time;
165 } 156 }
166 157
167 update_balance $pl; 158 update_balance $pl;
170 161
171cf::map::attachment rent => 162cf::map::attachment rent =>
172 on_enter => sub { 163 on_enter => sub {
173 my ($map, $pl, $x, $y) = @_; 164 my ($map, $pl, $x, $y) = @_;
174 165
175 # can freely enter homes of other people 166 my $pfx = sprintf "~%s/", $pl->ob->name;
176 {
177 my $path = sprintf "%s/%s/%s/",
178 cf::localdir, cf::playerdir, $pl->ob->name;
179 167
168 # only do something if entering ones own apartment
180 return if $path ne substr $map->path, 0, length $path; 169 if ($pfx eq substr $map->path, 0, length $pfx) {
170 for my $path (keys %{ $pl->{rent}{apartment} }) {
171 $path = sprintf "~%s%s", $pl->ob->name, $path;
172
173 if ($map->path eq $path) {
174 if (check_balance $pl) {
175 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
176 } else {
177 $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first.");
178 reject_entry $pl;
179 }
180
181 return;
182 }
183 }
184
185 $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!");
186 reject_entry $pl;
181 } 187 }
182
183 for my $path (keys %{ $pl->{rent}{apartment} }) {
184 $path =~ y/\//_/;
185 $path = sprintf "%s/%s/%s/%s",
186 cf::localdir, cf::playerdir, $pl->ob->name, $path;
187
188 if ($map->path eq $path) {
189 if (check_balance $pl) {
190 $pl->ob->reply (undef, "Welcome to your apartment, sir!");
191 } else {
192 $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first.");
193 reject_entry $pl;
194 }
195
196 return;
197 }
198 }
199
200 $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!");
201 reject_entry $pl;
202 }, 188 },
203; 189;
204 190
205our $RENT_TIMER = Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { 191our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
206 pay_balance $_ for cf::player::list; 192 pay_balance $_ for cf::player::list;
207}); 193};
208 194

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines