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.1 by root, Fri Dec 15 19:29:18 2006 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
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
29# we have to special case some special cases :) 19# we have to special case some special cases :)
30sub reject_entry { 20sub reject_entry {
31 my ($pl) = @_; 21 my ($pl) = @_;
32 22
23 my $prev_pos = $pl->ob->{_prev_pos};
24 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
25
33 cf::override; 26 cf::override;
34
35 teleport $pl, "/world/world_105_115", 2, 34
36 unless
37 $pl->ob->map
38 && $pl->ob->map->path !~ /nimbus/
39 && $pl->ob->map->path !~ m%/var/crossfire/players/%;
40} 27}
41 28
42sub update_balance { 29sub update_balance {
43 my ($pl) = @_; 30 my ($pl) = @_;
44 31
60} 47}
61 48
62sub pay_balance { 49sub pay_balance {
63 my ($pl) = @_; 50 my ($pl) = @_;
64 51
52 cf::cede_to_tick;
53
65 update_balance $pl; 54 update_balance $pl;
66 55
67 return unless $pl->{rent}{balance} > 0; 56 return unless $pl->{rent}{balance} > 0;
68 57
69 my $deduct = cf::ceil $pl->{rent}{balance}; 58 my $deduct = cf::ceil $pl->{rent}{balance};
72 61
73 if ($deduct <= $pl->ob->{bank_balance}) { 62 if ($deduct <= $pl->ob->{bank_balance}) {
74 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 63 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
75 $pl->ob->{bank_balance} -= $deduct; 64 $pl->ob->{bank_balance} -= $deduct;
76 $pl->{rent}{balance} -= $deduct; 65 $pl->{rent}{balance} -= $deduct;
77 $pl->ob->reply (undef, "Something whispers into your ear:\n" 66 $pl->ob->reply (undef, "Something whispers into your ear: "
78 . "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.");
79 } else { 68 } else {
80 $pl->ob->reply (undef, "Something whispers into your ear:\n" 69 $pl->ob->reply (undef, "Something whispers into your ear: "
81 . "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. "
82 . "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.");
83 } 72 }
84} 73}
85 74
86sub check_balance { 75sub check_balance {
105 94
106 while (my ($k, $v) = each %apartment) { 95 while (my ($k, $v) = each %apartment) {
107 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 96 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
108 97
109 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 98 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] ("
110 . (cf::cost_string_from_value $v->[0]) . "/hr)") 99 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
111 if $type & $types; 100 if $type & $types;
112 } 101 }
113}; 102};
114 103
115cf::register_script_function "rent::status" => sub { 104cf::register_script_function "rent::status" => sub {
130 119
131 update_balance $pl; 120 update_balance $pl;
132 121
133 $pl->{rent}{apartment}{$apartment} = undef; 122 $pl->{rent}{apartment}{$apartment} = undef;
134 123
135 $pl->ob->reply (undef, "Wonderful decision, sir! " 124 $pl->ob->reply (undef, "Wonderful decision, your highness! "
136 . "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. "
137 . "We are sure you will be satisfied!"); 126 . "We are sure you will be satisfied!");
138}; 127};
139 128
140cf::register_script_function "rent::stop" => sub { 129cf::register_script_function "rent::stop" => sub {
148 delete $pl->{rent}{apartment}{$apartment}; 137 delete $pl->{rent}{apartment}{$apartment};
149 138
150 $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); 139 $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course.");
151}; 140};
152 141
153cf::attach_to_players prio => 100, 142cf::player->attach (
143 prio => 100,
154 on_login => sub { 144 on_login => sub {
155 my ($pl) = @_; 145 my ($pl) = @_;
156 146
157 $pl->{rent}{last_offline_check} ||= time; 147 $pl->{rent}{last_offline_check} ||= time;
158 148
159 if ($pl->{rent}{last_online_check}) { 149 if ($pl->{rent}{last_online_check}) {
160 $pl->{rent}{last_online_check} = time 150 $pl->{rent}{last_online_check} = time
161 - List::Util::min 3600, 151 - List::Util::min 3600,
162 $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};
163 } else { 153 } else {
164 $pl->{rent}{last_online_check} = time; 154 $pl->{rent}{last_online_check} = time;
165 } 155 }
166 156
167 update_balance $pl; 157 update_balance $pl;
168 }; 158 },
159);
169 160
170cf::register_map_attachment rent => 161cf::map::attachment rent =>
171 on_enter => sub { 162 on_enter => sub {
172 my ($map, $pl, $x, $y) = @_; 163 my ($map, $pl, $x, $y) = @_;
173 164
174 # can freely enter homes of other people 165 my $pfx = sprintf "~%s/", $pl->ob->name;
175 {
176 my $path = sprintf "%s/%s/%s/",
177 cf::localdir, cf::playerdir, $pl->ob->name;
178 166
167 # only do something if entering ones own apartment
179 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;
180 } 186 }
181
182 for my $path (keys %{ $pl->{rent}{apartment} }) {
183 $path =~ y/\//_/;
184 $path = sprintf "%s/%s/%s/%s",
185 cf::localdir, cf::playerdir, $pl->ob->name, $path;
186
187 if ($map->path eq $path) {
188 if (check_balance $pl) {
189 $pl->ob->reply (undef, "Welcome to your apartment, sir!");
190 } else {
191 $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first.");
192 reject_entry $pl;
193 }
194
195 return;
196 }
197 }
198
199 $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!");
200 reject_entry $pl;
201 }, 187 },
202; 188;
203 189
204Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { 190our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
205 pay_balance $_ for cf::player::list; 191 pay_balance $_ for cf::player::list;
206}); 192};
207 193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines